Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto publicPath #119

Merged
merged 6 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": {
Expand Down
44 changes: 43 additions & 1 deletion tests/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
);
});
});
4 changes: 2 additions & 2 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
44 changes: 43 additions & 1 deletion tests/webpack5.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
);
});
});
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down