Skip to content

Commit 3b65403

Browse files
committed
Fixing entrypoints.json so that it points to the unversioned filename
The id that the user will first find the entry filenames in entrypoints.json and THEN use manifest.json to find the final path
1 parent eaebb31 commit 3b65403

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

lib/webpack/entry-files-manifest-plugin.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ function extractFiles(entryPoint) {
2626
jsFiles: [],
2727
cssFiles: [],
2828
};
29-
for (let filename of entryPoint.getFiles()) {
30-
if (/\.js$/.test(filename)) {
31-
files.jsFiles.push(filename);
32-
} else if (/\.css$/.test(filename)) {
33-
files.cssFiles.push(filename);
34-
} else {
35-
logger.debug(`Unable to determine file type for entry ${filename}. This is possibly a bug, but will not impact your setup unless you use the entrypoints.json file.`);
29+
30+
for (let chunk of entryPoint.chunks) {
31+
for (let filename of chunk.files) {
32+
if (/\.js$/.test(filename)) {
33+
// use the chunk id because we do not want the versioned filename
34+
files.jsFiles.push(`${chunk.id}.js`);
35+
} else if (/\.css$/.test(filename)) {
36+
files.cssFiles.push(`${chunk.id}.css`);
37+
} else {
38+
logger.debug(`Unable to determine file type for entry ${filename}. This is possibly a bug, but will not impact your setup unless you use the entrypoints.json file. To be super awesome, please report this as an issue.`);
39+
}
3640
}
3741
}
3842

test/functional.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,8 @@ module.exports = {
12471247
config.addEntry('main', ['./css/roboto_font.css', './js/no_require', 'vue']);
12481248
config.addEntry('other', ['./css/roboto_font.css', 'vue']);
12491249
config.setPublicPath('/build');
1250+
// enable versioning to make sure entrypoints.json is not affected
1251+
config.enableVersioning();
12501252
config.configureSplitChunks((splitChunks) => {
12511253
splitChunks.chunks = 'all';
12521254
splitChunks.minSize = 0;
@@ -1264,6 +1266,39 @@ module.exports = {
12641266
},
12651267
});
12661268

1269+
// make split chunks are correct in manifest
1270+
webpackAssert.assertManifestKeyExists('build/vendors~main~other.js');
1271+
1272+
done();
1273+
});
1274+
});
1275+
1276+
it('Custom public path does not affect entrypoints.json or manifest.json', (done) => {
1277+
const config = createWebpackConfig('web/build', 'dev');
1278+
config.addEntry('main', ['./css/roboto_font.css', './js/no_require', 'vue']);
1279+
config.addEntry('other', ['./css/roboto_font.css', 'vue']);
1280+
config.setPublicPath('http://localhost:8080/build');
1281+
config.setManifestKeyPrefix('custom_prefix');
1282+
config.configureSplitChunks((splitChunks) => {
1283+
splitChunks.chunks = 'all';
1284+
splitChunks.minSize = 0;
1285+
});
1286+
1287+
testSetup.runWebpack(config, (webpackAssert) => {
1288+
webpackAssert.assertOutputJsonFileMatches('entrypoints.json', {
1289+
main: {
1290+
js: ['vendors~main~other.js', 'main~other.js', 'main.js'],
1291+
css: ['main~other.css']
1292+
},
1293+
other: {
1294+
js: ['vendors~main~other.js', 'main~other.js', 'other.js'],
1295+
css: ['main~other.css']
1296+
},
1297+
});
1298+
1299+
// make split chunks are correct in manifest
1300+
webpackAssert.assertManifestKeyExists('custom_prefix/vendors~main~other.js');
1301+
12671302
done();
12681303
});
12691304
});

test/helpers/assert.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,21 @@ class Assert {
100100
assertManifestPath(sourcePath, expectedDestinationPath) {
101101
const manifestData = loadManifest(this.webpackConfig);
102102

103-
if (!manifestData[sourcePath]) {
104-
throw new Error(`No ${sourcePath} key found in manifest ${JSON.stringify(manifestData)}`);
105-
}
103+
this.assertManifestKeyExists(sourcePath);
106104

107105
if (manifestData[sourcePath] !== expectedDestinationPath) {
108106
throw new Error(`source path ${sourcePath} expected to be set to ${expectedDestinationPath}, was actually ${manifestData[sourcePath]}`);
109107
}
110108
}
111109

110+
assertManifestKeyExists(key) {
111+
const manifestData = loadManifest(this.webpackConfig);
112+
113+
if (!manifestData[key]) {
114+
throw new Error(`No ${key} key found in manifest ${JSON.stringify(manifestData)}`);
115+
}
116+
}
117+
112118
assertManifestPathDoesNotExist(sourcePath) {
113119
const manifestData = loadManifest(this.webpackConfig);
114120

test/package-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('package-helper', () => {
7373
expect(packageRecommendations.installCommand).to.contain('yarn add foo@^0.1.0 bar');
7474
});
7575

76-
it.only('Recommends correct install with a more complex constraint', () => {
76+
it('Recommends correct install with a more complex constraint', () => {
7777
// e.g. ^7.0|^8.0
7878
const packageRecommendations = packageHelper.getMissingPackageRecommendations([
7979
{ name: 'foo', version: '^7.0|^8.0' },

0 commit comments

Comments
 (0)