From 29734853216a7d574975fb66ee1bf50225718a81 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 4 Jun 2022 19:12:25 +0200 Subject: [PATCH] Replace npm and lerna with pnpm Save disk space, time and sanity by replacing npm and lerna with pnpm. This is more performant and doesn't have developer experience ruining bugs like npm link removing all previous links before creating the requested one. --- .github/workflows/node.js.yml | 14 ++++++-------- .gitignore | 2 +- Dockerfile | 15 ++++++--------- docs/contributing.md | 18 ++++++++++-------- external_plugins/.gitignore | 3 +++ external_plugins/README.md | 4 ++++ lerna.json | 8 -------- package.json | 9 ++++----- packages/lib/package.json | 1 + packages/master/package.json | 7 +++---- packages/web_ui/package.json | 3 ++- pnpm-workspace.yaml | 5 +++++ 12 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 external_plugins/.gitignore create mode 100644 external_plugins/README.md delete mode 100644 lerna.json create mode 100644 pnpm-workspace.yaml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 0d68d7d9..30035ee2 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -21,18 +21,17 @@ jobs: uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - - run: npm i --no-optional + - run: pnpm i --no-optional - run: wget -q -O factorio.tar.gz https://www.factorio.com/get-download/latest/headless/linux64 && tar -xf factorio.tar.gz && rm factorio.tar.gz - - run: npx lerna bootstrap --hoist - run: node packages/lib/build_mod --source-dir packages/slave/lua/clusterio_lib --output-dir temp/test/sharedMods - run: wget -q -O temp/test/sharedMods/subspace_storage_1.99.8.zip -L https://github.com/clusterio/subspace_storage/releases/download/1.99.6/subspace_storage_1.99.8.zip - - run: npx lerna run build + - run: pnpm run -r --if-present build - name: Run tests if: ${{ matrix.node-version != '12.x' }} - run: npm test + run: pnpm test - name: Run coverage if: ${{ matrix.node-version == '12.x' }} - run: npm run ci-cover + run: pnpm run ci-cover - name : Upload coverage to Codecov if: ${{ matrix.node-version == '12.x' }} uses: codecov/codecov-action@v2 @@ -46,6 +45,5 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16.x - - run: npm i --no-optional - - run: npx lerna bootstrap --hoist - - run: npm run lint + - run: pnpm i --no-optional + - run: pnpm run lint diff --git a/.gitignore b/.gitignore index e05a2f70..72a782e6 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,7 @@ Factorio* /config-master.json /config-control.json /config-slave.json -package-lock.json +pnpm-lock.yaml mod_cache.json static/export saves diff --git a/Dockerfile b/Dockerfile index 50ded523..8f991b32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,18 +15,17 @@ RUN wget -q -O factorio.tar.gz https://www.factorio.com/get-download/latest/head # Copy project files into the container COPY . . -RUN npm install \ -&& npx lerna bootstrap --hoist +RUN pnpm install # Install plugins. This is intended as a reasonable default, enabling plugins to make for fun gameplay. # If you want a different set of plugins, consider using this as the base image for your own. -#RUN npm install @clusterio/plugin-subspace_storage +#RUN pnpm install @clusterio/plugin-subspace_storage #RUN npx clusteriomaster plugin add @clusterio/plugin-subspace_storage COPY --from=subspace_storage_builder /subspace_storage/dist/ /clusterio/sharedMods/ # Build submodules (web UI, libraries, plugins etc) -RUN npx lerna run build +RUN pnpm run -r --if-present build # Build Lua library mod RUN node packages/lib/build_mod --build --source-dir packages/slave/lua/clusterio_lib \ && mv dist/* sharedMods/ \ @@ -46,8 +45,7 @@ COPY --from=clusterio_builder /clusterio /clusterio WORKDIR /clusterio # Install runtime dependencies -RUN npm install --production -RUN npx lerna bootstrap -- --production --no-optional +RUN pnpm install --production LABEL maintainer "danielv@danielv.no" FROM frolvlad/alpine-glibc AS clusterio_testing @@ -58,6 +56,5 @@ COPY --from=clusterio_builder /clusterio /clusterio WORKDIR /clusterio # Install runtime dependencies -RUN npm install -RUN npx lerna bootstrap -RUN npm install chalk semver +RUN pnpm install +RUN pnpm install chalk semver diff --git a/docs/contributing.md b/docs/contributing.md index 62eeeb5f..0d76e877 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -49,12 +49,11 @@ Do not run `git pull upstream` it will mess thing up! ### Setting up the Development Environment -The project is organized into several packages that are all managed through Lerna. +The project is organized into several packages that are all tied together using pnpm's workspace feature. In order to get the development environment up and running you will need to run the following commands: - npm install - npx lerna bootstrap --hoist - npx lerna run build + pnpm install + pnpm run -r --if-present build This installs dependencies needed by tests and links the packages up so they work from the git work tree. To start a cluster from the repo you will first need to initialize it, this can be done using the installer: @@ -80,14 +79,15 @@ Note that to use `clusterioctl` you will have to create a control config first: Once you've set up the cluster you can use `node packages/master run` to run the master server and `node packages/slave run` to run the slave which connects to the master server. -For web development on the master there are also the following flags. +For web development on the master there are also the following flags: `--dev` - Recompile the `web_ui` package on the fly providing live reloading of it. `--dev-plugin [name]` - Recompile the web module for the given plugin on the fly proving live reloading of it. These options can be combined and multiple plugins can be actived for dev mode. -Note that webpack is configured to delete the web interface build when using these options, so you will have to run `npx lerna run build` before you start the master without these flags again. +Keep in mind if you're working on external plugins the `--dev-plugin` option is likely to only work if the plugin is placed inside the `external_plugins` directory and its dependencies are installed with pnpm as part of the clusterio repository workspace. +Note that webpack is configured to delete the web interface build when using these options, so you will have to run `pnpm run -r --if-present build` before you start the master without these flags again. ### Starting a Feature Branch @@ -113,8 +113,8 @@ But it's nice to have its name be somewhat descriptive of what it implements. There's automated tests and linting setup for the project. Please do add tests for any code you add and run both: - npm run test - npm run lint + pnpm run test + pnpm run lint To check that your changes pass the integration tests as well as the ESLint rules set up for the project. @@ -272,6 +272,8 @@ Headings use the `# heading` format. ## Pushing releases to npm +***Warning: This workflow is outdated due to lerna having been removed from the project.**** + The releases are done by creating a new release tag with lerna and then uploading that with lerna. You will need commit access to the repository as well publish access to the @clusterio org on npm to do this. diff --git a/external_plugins/.gitignore b/external_plugins/.gitignore new file mode 100644 index 00000000..7c9d611b --- /dev/null +++ b/external_plugins/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!README.md diff --git a/external_plugins/README.md b/external_plugins/README.md new file mode 100644 index 00000000..96bed976 --- /dev/null +++ b/external_plugins/README.md @@ -0,0 +1,4 @@ +# External plugins directory + +Plugins placed here will have their npm dependencies incorporated in the shared pnpm storage for this repository when `pnpm install` is invoked. +Use this to enable `--dev-plugin` to work with plugins developed outside of the Clusterio repository. diff --git a/lerna.json b/lerna.json deleted file mode 100644 index 6c074e5e..00000000 --- a/lerna.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "packages": [ - "packages/*", - "plugins/*", - "test" - ], - "version": "2.0.0-alpha.12" -} diff --git a/package.json b/package.json index d4e94e05..a2ded9b9 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,10 @@ "private": true, "scripts": { "test": "mocha --check-leaks -R spec --exclude \"**/node_modules/**\" --recursive test plugins/global_chat/test plugins/research_sync/test plugins/statistics_exporter/test plugins/subspace_storage/test plugins/player_auth/test", - "fast-test": "FAST_TEST=y npm test", - "cover": "nyc npm test", - "fast-cover": "FAST_TEST=y nyc npm test", - "ci-cover": "nyc --reporter=lcovonly npm run-script test", + "fast-test": "FAST_TEST=y pnpm test", + "cover": "nyc pnpm test", + "fast-cover": "FAST_TEST=y nyc pnpm test", + "ci-cover": "nyc --reporter=lcovonly pnpm run-script test", "lint": "eslint \"*.js\" packages plugins test", "docs": "jsdoc --configure docs/jsdoc.json", "bundle-dependencies": "bundle-dependencies" @@ -24,7 +24,6 @@ "eslint": "^7.25.0", "eslint-plugin-node": "^11.1.0", "jsdoc": "^3.6.6", - "lerna": "^4.0.0", "mocha": "^8.4.0", "nyc": "^15.1.0" } diff --git a/packages/lib/package.json b/packages/lib/package.json index ce8eec40..aa85d179 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -14,6 +14,7 @@ "dependencies": { "ajv": "^6.12.6", "chalk": "^4.1.0", + "fast-deep-equal": "^3.1.3", "fs-extra": "^8.1.0", "isomorphic-ws": "^4.0.1", "jimp": "^0.12.1", diff --git a/packages/master/package.json b/packages/master/package.json index 3d826b41..ca546de1 100644 --- a/packages/master/package.json +++ b/packages/master/package.json @@ -27,6 +27,7 @@ "jsonwebtoken": "^8.2.1", "jszip": "^3.2.2", "set-blocking": "^2.0.0", + "webpack-cli": "^4.9.2", "winston": "^3.3.3", "winston-daily-rotate-file": "^4.5.5", "ws": "^7.2.3", @@ -34,13 +35,11 @@ }, "devDependencies": { "@clusterio/web_ui": "^2.0.0-alpha.12", - "fast-deep-equal": "^3.1.3", "react": "^16.13.1", "react-dom": "^16.13.1", "react-router-dom": "^5.2.0", - "webpack": "^5.36.2", - "webpack-cli": "^4.7.0", - "webpack-dev-middleware": "^4.1.0", + "webpack": "^5.73.0", + "webpack-dev-middleware": "^5.3.1", "webpack-merge": "^5.2.0" }, "publishConfig": { diff --git a/packages/web_ui/package.json b/packages/web_ui/package.json index 18335ad4..de2910ed 100644 --- a/packages/web_ui/package.json +++ b/packages/web_ui/package.json @@ -38,7 +38,8 @@ "stream-browserify": "^3.0.0", "style-loader": "^2.0.0", "util": "^0.12.3", - "webpack": "^5.36.2" + "webpack": "^5.73.0", + "webpack-cli": "^4.9.2" }, "publishConfig": { "access": "public" diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 00000000..a74adfca --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,5 @@ +packages: + - "packages/*" + - "plugins/*" + - "external_plugins/*" + - "test/"