From f41629749a66b8e07d8f2fd6c5616c2abc625b35 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Feb 2021 16:55:38 +0100 Subject: [PATCH] Build minified for production (#155) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Build minified for production And use dev build in CI Signed-off-by: Jérôme Benoit * Rename scripts: nothing -> default dev build :prod -> production build Signed-off-by: Jérôme Benoit * Trigger build analysis output on demand via an env variable Signed-off-by: Jérôme Benoit * Always register source map support. Signed-off-by: Jérôme Benoit * Revert to one build output for coverage on sonar cloud. Signed-off-by: Jérôme Benoit * Revert "Revert to one build output for coverage on sonar cloud." This reverts commit f3d990ba9878e4e6f097844cacba9e8e4b4c9121. * Try with sourcemap: false Signed-off-by: Jérôme Benoit * Build with sourcemap: true Signed-off-by: Jérôme Benoit * Go back to previous sourcemap setting. Signed-off-by: Jérôme Benoit * Change sonar sources Co-authored-by: Alessandro Pio Ardizio --- .eslintignore | 1 - .github/workflows/npmpublish.yml | 2 +- .gitignore | 1 - .prettierignore | 1 - .vscode/launch.json | 8 ++++---- .vscode/tasks.json | 7 ++++++- package.json | 16 ++++++++-------- rollup.config.mjs | 28 +++++++++++----------------- sonar-project.properties | 2 +- 9 files changed, 31 insertions(+), 35 deletions(-) diff --git a/.eslintignore b/.eslintignore index b7d3d591..c3af8579 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1 @@ lib/ -lib.min/ diff --git a/.github/workflows/npmpublish.yml b/.github/workflows/npmpublish.yml index 31b02ef4..0692856d 100644 --- a/.github/workflows/npmpublish.yml +++ b/.github/workflows/npmpublish.yml @@ -18,7 +18,7 @@ jobs: node-version: 12 - run: npm ci - run: npm run lint - - run: npm run test + - run: npm run test:prod - run: npm run coverage publish-npm: diff --git a/.gitignore b/.gitignore index c918d5dd..2e2848ad 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,3 @@ jspm_packages .history/ .scannerwork lib -lib.min diff --git a/.prettierignore b/.prettierignore index f5df3469..e40d57b1 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,3 @@ .nyc_output/ coverage/ lib/ -lib.min/ diff --git a/.vscode/launch.json b/.vscode/launch.json index c2c4c33f..f62ecf67 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,9 +9,9 @@ "request": "launch", "name": "Launch Test Debug", "cwd": "${workspaceFolder}", - "preLaunchTask": "Development build", + // "preLaunchTask": "Development build", "runtimeExecutable": "npm", - "runtimeArgs": ["run-script", "test:debug:vscode"], + "runtimeArgs": ["run-script", "test:debug"], "skipFiles": ["/**"], "stopOnEntry": true }, @@ -20,9 +20,9 @@ "request": "launch", "name": "Launch Benchmark Debug", "cwd": "${workspaceFolder}", - "preLaunchTask": "Development build", + // "preLaunchTask": "Development build", "runtimeExecutable": "npm", - "runtimeArgs": ["run-script", "benchmark:debug:vscode"], + "runtimeArgs": ["run-script", "benchmark:debug"], "skipFiles": ["/**"], "stopOnEntry": true } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ed157770..a6d60cd7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,10 +1,15 @@ { "version": "2.0.0", "tasks": [ + { + "label": "Build", + "type": "npm", + "script": "build:prod" + }, { "label": "Development build", "type": "npm", - "script": "build:dev" + "script": "build" } ] } diff --git a/package.json b/package.json index 37d39f32..4e5b8572 100644 --- a/package.json +++ b/package.json @@ -4,14 +4,14 @@ "description": "Library on top of node js worker threads that implement various worker pools type", "main": "lib/index.js", "scripts": { - "build": "rollup --config", - "build:dev": "rollup --config --environment BUILD:development", - "benchmark": "npm run build && node benchmarks/bench.js", - "benchmark:debug": "npm run build:dev && node -r source-map-support/register --inspect-brk benchmarks/bench.js", - "benchmark:debug:vscode": "node -r source-map-support/register benchmarks/bench.js", - "test": "npm run build && nyc mocha --exit --timeout 20000 tests/**/*.test.js", - "test:debug": "npm run build:dev && mocha -r source-map-support/register --inspect-brk --exit tests/**/*.test.js", - "test:debug:vscode": "mocha -r source-map-support/register --exit tests/**/*.test.js", + "build": "rollup --config --environment BUILD:development", + "build:prod": "rollup --config", + "benchmark": "npm run build && node -r source-map-support/register benchmarks/bench.js", + "benchmark:debug": "npm run build && node -r source-map-support/register --inspect benchmarks/bench.js", + "benchmark:prod": "npm run build:prod && node -r source-map-support/register benchmarks/bench.js", + "test": "npm run build && nyc mocha -r source-map-support/register --exit --timeout 20000 tests/**/*.test.js", + "test:debug": "npm run build && mocha -r source-map-support/register --inspect --exit --timeout 20000 tests/**/*.test.js", + "test:prod": "npm run build:prod && nyc mocha -r source-map-support/register --exit --timeout 20000 tests/**/*.test.js", "sonar": "sonar-scanner", "coverage": "nyc report --reporter=lcov --check-coverage --lines 80", "coverage:html": "nyc report --reporter=html --check-coverage --lines 80", diff --git a/rollup.config.mjs b/rollup.config.mjs index 8afbc006..bac8f614 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -4,24 +4,18 @@ import { terser } from 'rollup-plugin-terser' import del from 'rollup-plugin-delete' const isDevelopmentBuild = process.env.BUILD === 'development' +const isAnalyze = process.env.ANALYZE export default { input: 'src/index.ts', - output: [ - { - dir: 'lib', - format: 'cjs', - sourcemap: !!isDevelopmentBuild, - preserveModules: true, - preserveModulesRoot: 'src' - }, - isDevelopmentBuild && { - file: 'lib.min/index.js', - format: 'cjs', - sourcemap: !!isDevelopmentBuild, - plugins: [terser({ numWorkers: 2 })] - } - ], + output: { + ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.js' }), + format: 'cjs', + sourcemap: !!isDevelopmentBuild, + ...(isDevelopmentBuild && { preserveModules: true }), + ...(isDevelopmentBuild && { preserveModulesRoot: 'src' }), + ...(!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] }) + }, external: ['async_hooks', 'cluster', 'events', 'worker_threads'], plugins: [ typescript({ @@ -30,8 +24,8 @@ export default { : 'tsconfig.json' }), del({ - targets: ['lib/*', 'lib.min/*'] + targets: ['lib/*'] }), - isDevelopmentBuild && analyze() + isAnalyze && analyze() ] } diff --git a/sonar-project.properties b/sonar-project.properties index 846b8a5a..4bd411a0 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -4,7 +4,7 @@ sonar.javascript.lcov.reportPaths=coverage/lcov.info sonar.projectName=poolifier sonar.projectVersion=2.0.0 sonar.host.url=https://sonarcloud.io -sonar.sources=lib +sonar.sources=src sonar.tests=tests # sonar.login=TOKEN #To use for local troubleshooting sonar.verbose=false -- 2.34.1