From 773b6c73642ab73da8129a47b9b5e1a62821d1fe Mon Sep 17 00:00:00 2001 From: larabr <7375870+larabr@users.noreply.github.com> Date: Tue, 6 May 2025 19:47:47 +0200 Subject: [PATCH] CI: fix "unknown cli/env config" warnings from npm v11 npm v12 will drop support for unknown config options. --- .github/workflows/tests.yml | 4 ++-- package.json | 2 +- rollup.config.js | 30 ++++++++++++++++++++---------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8380ae50..d2afd580 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -114,7 +114,7 @@ jobs: - name: Run browser tests (lightweight) # overwrite test/lib run: | - npm run build-test --lightweight + npm run build-test -- --configTestLightweightBuild npm run test-browser:ci -- --static-logging test-browsers-compatibility: @@ -162,7 +162,7 @@ jobs: - name: Run browserstack tests (lightweight) # overwrite test/lib run: | - npm run build-test --lightweight + npm run build-test -- --configTestLightweightBuild npm run test-browserstack -- --static-logging env: LIGHTWEIGHT: true diff --git a/package.json b/package.json index a68bde97..0a42fb2a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ ], "scripts": { "build": "rollup --config", - "build-test": "npm run build --build-only=test", + "build-test": "npm run build -- --configBuildOnly=test", "prepare": "npm run build", "test": "mocha --timeout 120000 test/unittests.js", "test-type-definitions": "tsx test/typescript/definitions.ts", diff --git a/rollup.config.js b/rollup.config.js index f61c53cc..b2c72fdf 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -136,7 +136,7 @@ const lightweightBrowserBuild = { ] }; -const testBuild = { +const getBrowserTestBuild = useLightweightBuild => ({ input: 'test/unittests.js', output: [ { file: 'test/lib/unittests-bundle.js', format: 'es', intro, sourcemap: true, inlineDynamicImports: true } @@ -145,7 +145,7 @@ const testBuild = { plugins: [ alias({ entries: { - openpgp: `./dist/${process.env.npm_config_lightweight ? 'lightweight/' : ''}openpgp.mjs` + openpgp: `./dist/${useLightweightBuild ? 'lightweight/' : ''}openpgp.mjs` } }), resolve({ @@ -164,21 +164,31 @@ const testBuild = { }), wasm(wasmOptions.browser) ] -}; +}); -export default Object.assign([ +/** + * Rollup CLI supports custom options; their name must start with `config`, + * e.g. see `--configDebug` example at + * https://rollupjs.org/command-line-interface/#configuration-files + * + * The custom options we support are: + * @param commandLineArgs.configBuildOnly {'dist'|'node'|'lightweight'|'test'} to specify a build target; + * defaults to 'dist', which does not build tests. + * @param commandLineArgs.configTestLightweightBuild {Boolean}: in the context of building browser tests, + * whether the lightweight build should be included instead of the standard one + */ +export default commandLineArgs => Object.assign([ nodeBuild, fullBrowserBuild, lightweightBrowserBuild, - testBuild -].filter(config => { - config.output = config.output.filter(output => { + getBrowserTestBuild(commandLineArgs.configTestLightweightBuild) +].filter(rollupConfig => { + rollupConfig.output = rollupConfig.output.filter(output => { return (output.file || output.dir + '/' + output.entryFileNames).includes( - process.env.npm_config_build_only || // E.g. `npm install --build-only=lightweight`. - 'dist' // Don't build test bundle by default. + commandLineArgs.configBuildOnly || 'dist' // Don't build test bundle by default. ); }); - return config.output.length; + return rollupConfig.output.length; }), { allow_empty: true // Fake option to trick rollup into accepting empty config array when filtered above. });