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) { diff --git a/package.json b/package.json index 013df9a..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": [ @@ -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/tests/base.test.js b/tests/base.test.js index 5c4fb26..bfc7f27 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; @@ -773,4 +773,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, + ); + }); }); 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. */