From c20b75252b7e8cea1c603421629349784300a19d Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Tue, 12 May 2020 22:50:55 +0200 Subject: [PATCH] Add --build-only parameter to filter build outputs Also, don't generate test bundle by default, but provide `npm run build-test` instead. --- package.json | 2 ++ rollup.config.js | 14 ++++++++++++-- travis.sh | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 955dce86..c63312f3 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,11 @@ ], "scripts": { "build": "rollup --config", + "build-test": "npm run build --build-only=test", "prepare": "npm run build", "test": "mocha --timeout 120000 test/unittests.js", "start": "http-server", + "prebrowsertest": "npm run build-test", "browsertest": "npm start -- -o test/unittests.html", "coverage": "nyc npm test", "lint": "eslint 'src/**/*.js' 'test/crypto/**/*.js'", diff --git a/rollup.config.js b/rollup.config.js index 5a668d9e..4fa16b21 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -23,7 +23,7 @@ const terserOptions = { } }; -export default [ +export default Object.assign([ { input: 'src/index.js', output: [ @@ -100,4 +100,14 @@ export default [ }) ] } -]; +].filter(config => { + config.output = config.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. + ); + }); + return config.output.length; +}), { + allow_empty: true // Fake option to trick rollup into accepting empty config array when filtered above. +}); diff --git a/travis.sh b/travis.sh index 7824a171..2cfa3cb3 100755 --- a/travis.sh +++ b/travis.sh @@ -14,6 +14,7 @@ elif [ $OPENPGPJSTEST = "unit" ]; then elif [ $OPENPGPJSTEST = "browserstack" ]; then echo "Running OpenPGP.js browser unit tests on Browserstack." + npm run build-test echo -n "Using config: " echo "{\"browsers\": [$BROWSER], \"test_framework\": \"mocha\", \"test_path\": [\"test/unittests.html?ci=true${LIGHTWEIGHT+&lightweight=true&grep=lightweight}\"], \"timeout\": 1800, \"exit_with_fail\": true, \"project\": \"openpgpjs/${TRAVIS_EVENT_TYPE:-push}${LIGHTWEIGHT:+/lightweight}\"}" > browserstack.json cat browserstack.json