From 84e5dc75ec3e44ecd8d99030fa62219b93ffe605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Juvenal?= Date: Fri, 1 Dec 2023 12:15:30 -0300 Subject: [PATCH 1/5] Fix auto publicPath --- lib/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 7ba1797..147bd9e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -181,7 +181,11 @@ class BundleTrackerPlugin { } if (this.options.publicPath) { - fileInfo.publicPath = this.options.publicPath + assetName; + if (this.options.publicPath === 'auto') { + fileInfo.publicPath = 'auto'; + } else { + fileInfo.publicPath = this.options.publicPath + assetName; + } } if (this.options.relativePath === true) { From 10377f38d02646f5ed94ab2beddfd3555713d1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Juvenal?= Date: Fri, 1 Dec 2023 13:18:55 -0300 Subject: [PATCH 2/5] Fix tests --- .circleci/config.yml | 4 ++-- package.json | 8 ++++---- tsconfig.json | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cbd4531..db9033e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,11 +25,11 @@ jobs: NODE_OPTIONS: --openssl-legacy-provider steps: - checkout - - run: | + - run: | # --openssl-legacy-provider is required for Webpack 4 echo "Node version: $(node --version)" echo "NPM version: $(npm --version)" npm install - npm run ci + NODE_OPTIONS=--openssl-legacy-provider npm run ci workflows: all-tests: diff --git a/package.json b/package.json index 013df9a..0ff2ab4 100644 --- a/package.json +++ b/package.json @@ -59,17 +59,17 @@ "cz-conventional-changelog": "3.3.0", "eslint": "^6.8.0", "file-loader": "^5.1.0", - "jest": "^25.5.4", + "jest": "^29.7.0", "jest-extended": "^0.11.5", "mini-css-extract-plugin": "^1.6.2", "prettier": "^1.19.1", "standard-version": "^9.5.0", "style-loader": "^1.3.0", "tslint": "^6.1.0", - "typescript": "^3.9.10", - "webpack": "^4.46.0", + "typescript": "^5.3.2", + "webpack": "^4.47.0", "webpack-cli": "^4.10.0", - "webpack5": "npm:webpack@^5.83.1" + "webpack5": "npm:webpack@^5.89.0" }, "config": { "commitizen": { diff --git a/tsconfig.json b/tsconfig.json index a26d272..ca34c20 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "checkJs": true, /* Report errors in .js files. */ "noEmit": true, /* Do not emit outputs. */ "lib": ["es2017"], + "skipLibCheck": true, /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ From 800c78ddd0c28eec4445f8a1c01710ac4fd17bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Juvenal?= Date: Fri, 1 Dec 2023 15:39:09 -0300 Subject: [PATCH 3/5] NODE_OPTIONS=--openssl-legacy-provider due to Webpack 4 --- .circleci/config.yml | 4 ++-- package.json | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index db9033e..cbd4531 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,11 +25,11 @@ jobs: NODE_OPTIONS: --openssl-legacy-provider steps: - checkout - - run: | # --openssl-legacy-provider is required for Webpack 4 + - run: | echo "Node version: $(node --version)" echo "NPM version: $(npm --version)" npm install - NODE_OPTIONS=--openssl-legacy-provider npm run ci + npm run ci workflows: all-tests: diff --git a/package.json b/package.json index 0ff2ab4..bda3921 100644 --- a/package.json +++ b/package.json @@ -20,11 +20,11 @@ "pretty": "prettier --loglevel warn --write lib/*.js tests/*.js", "pretty-lint": "prettier --check lib/*.js tests/*.js", "pretest": "npm run pretty-lint", - "test": "jest --runInBand --env node", - "test-debug": "node --inspect-brk=0.0.0.0 node_modules/jest/bin/jest --runInBand --env node", + "test": "NODE_OPTIONS=--openssl-legacy-provider jest --runInBand --env node", + "test-debug": "NODE_OPTIONS=--openssl-legacy-provider node --inspect-brk=0.0.0.0 node_modules/jest/bin/jest --runInBand --env node", "posttest": "tsc", "test-watch": "jest --runInBand --env node --watchAll", - "ci": "npm run pretest && jest --runInBand --coverage --env node && npm run posttest" + "ci": "NODE_OPTIONS=--openssl-legacy-provider npm run pretest && jest --runInBand --coverage --env node && npm run posttest" }, "jest": { "setupFilesAfterEnv": [ From c4abe626a9a0858214a4ea643baf23061197fe0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Juvenal?= Date: Fri, 1 Dec 2023 15:45:24 -0300 Subject: [PATCH 4/5] Fix tests --- .circleci/config.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cbd4531..2662bbf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,19 +1,6 @@ version: 2.1 jobs: - # This job is built separately because node <= 16 doesn't require - # (and will crash) if we use NODE_OPTIONS=--openssl-legacy-provider - # which is required for tests in more recent versions to work - test-node-16: - docker: - - image: cimg/node:16.20 - steps: - - checkout - - run: | - echo "Node version: $(node --version)" - echo "NPM version: $(npm --version)" - npm install - npm run ci test: parameters: node-version: @@ -41,6 +28,3 @@ workflows: - "current" - "lts" name: test-on-node-<< matrix.node-version >> - - test-node-16: - # Oldest maintenance LTS, End-of-Life 2023-09-11 - name: test-on-node-16.20 From 8d761d9cfb6c7f9a35ace90baba1fb02fbdc717e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Juvenal?= Date: Fri, 1 Dec 2023 16:05:59 -0300 Subject: [PATCH 5/5] Tests for publicPath: 'auto' --- tests/base.test.js | 44 +++++++++++++++++++++++++++++++++++++++++- tests/utils.js | 4 ++-- tests/webpack5.test.js | 44 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 88 insertions(+), 4 deletions(-) diff --git a/tests/base.test.js b/tests/base.test.js index a3383d6..bca6736 100644 --- a/tests/base.test.js +++ b/tests/base.test.js @@ -14,7 +14,7 @@ const CompressionPlugin = require('compression-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const BundleTrackerPlugin = require('../lib/index.js'); -jest.setTimeout(120000); +jest.setTimeout(30000); process.on('unhandledRejection', r => console.log(r)); process.traceDeprecation = true; @@ -772,4 +772,46 @@ describe('BundleTrackerPlugin bases tests', () => { expectWarnings, ); }); + + it('It should support publicPath: "auto"', done => { + const expectErrors = null; + const expectWarnings = getWebpack4WarningMessage(); + + testPlugin( + webpack, + { + context: __dirname, + entry: path.resolve(__dirname, 'fixtures', 'index.js'), + output: { + path: OUTPUT_DIR, + filename: 'js/[name].js', + publicPath: 'auto', + }, + plugins: [ + new BundleTrackerPlugin({ + path: OUTPUT_DIR, + filename: 'webpack-stats.json', + }), + ], + }, + { + status: 'done', + publicPath: 'auto', + chunks: { + main: ['js/main.js'], + }, + assets: { + 'js/main.js': { + name: 'js/main.js', + path: OUTPUT_DIR + '/js/main.js', + publicPath: 'auto', + }, + }, + }, + 'webpack-stats.json', + done, + expectErrors, + expectWarnings, + ); + }); }); diff --git a/tests/utils.js b/tests/utils.js index 2bc5443..e8ca684 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -10,8 +10,8 @@ const OUTPUT_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'wbt-tests-')); function testPlugin(webpack, webpackConfig, expectedResults, outputFile, done, expectErrors, expectWarnings) { webpack(webpackConfig, (err, stats) => { - const compilationErrors = (stats.compilation.errors || []).join('\n'); - const compilationWarnings = (stats.compilation.warnings || []).join('\n'); + const compilationErrors = (stats?.compilation?.errors || []).join('\n'); + const compilationWarnings = (stats?.compilation?.warnings || []).join('\n'); expect(err).toBeFalsy(); diff --git a/tests/webpack5.test.js b/tests/webpack5.test.js index 87caa80..f32ea1d 100644 --- a/tests/webpack5.test.js +++ b/tests/webpack5.test.js @@ -14,7 +14,7 @@ const CompressionPlugin = require('compression-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const BundleTrackerPlugin = require('../lib/index.js'); -jest.setTimeout(120000); +jest.setTimeout(30000); process.on('unhandledRejection', r => console.log(r)); process.traceDeprecation = true; @@ -772,4 +772,46 @@ describe('BundleTrackerPlugin bases tests', () => { expectWarnings, ); }); + + it('It should support publicPath: "auto"', done => { + const expectErrors = null; + const expectWarnings = getWebpack5WarningMessage(); + + testPlugin( + webpack5, + { + context: __dirname, + entry: path.resolve(__dirname, 'fixtures', 'index.js'), + output: { + path: OUTPUT_DIR, + filename: 'js/[name].js', + publicPath: 'auto', + }, + plugins: [ + new BundleTrackerPlugin({ + path: OUTPUT_DIR, + filename: 'webpack-stats.json', + }), + ], + }, + { + status: 'done', + publicPath: 'auto', + chunks: { + main: ['js/main.js'], + }, + assets: { + 'js/main.js': { + name: 'js/main.js', + path: OUTPUT_DIR + '/js/main.js', + publicPath: 'auto', + }, + }, + }, + 'webpack-stats.json', + done, + expectErrors, + expectWarnings, + ); + }); });