@plaudit/webpack-extensions 2.44.5 → 2.44.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -33,4 +33,9 @@ export default class BlockJSONManagingPlugin implements WebpackPluginInstance {
|
|
|
33
33
|
private registerBlockJsonProcessor;
|
|
34
34
|
private static normalizeRenderTemplate;
|
|
35
35
|
private static getSyncs;
|
|
36
|
+
private static makeSync;
|
|
37
|
+
private static getAssetDetails;
|
|
38
|
+
private static getAssetDataAccountingForCSS;
|
|
39
|
+
private static findFirstChunkFileWithExtension;
|
|
40
|
+
private static getChunkFilesByRuntimeName;
|
|
36
41
|
}
|
|
@@ -169,20 +169,20 @@ class BlockJSONManagingPlugin {
|
|
|
169
169
|
if (value.startsWith("file:")) {
|
|
170
170
|
const sourceDir = BlockJSONManagingPlugin.blockJSONAssetSourceDirs.get(name) ?? node_path_1.default.dirname(name);
|
|
171
171
|
const inputPath = node_path_1.default.normalize(node_path_1.default.join(sourceDir, value.substring(5)));
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
const {
|
|
172
|
+
const outputAndDerivedFiles = BlockJSONManagingPlugin.blockJsonToEntrypointsMap.get(name)?.get(inputPath);
|
|
173
|
+
if (outputAndDerivedFiles !== undefined) {
|
|
174
|
+
const { entryMeta, derivedFiles } = outputAndDerivedFiles;
|
|
175
175
|
const prefix = value.startsWith("./", 5) ? "./" : "";
|
|
176
|
-
const relativePath = node_path_1.default.relative(node_path_1.default.dirname(name),
|
|
177
|
-
const res = [`file:${prefix}${relativePath}`,
|
|
178
|
-
if (BlockJSONManagingPlugin.styleExtensionPattern.test(
|
|
176
|
+
const relativePath = node_path_1.default.relative(node_path_1.default.dirname(name), entryMeta.path);
|
|
177
|
+
const res = [`file:${prefix}${relativePath}`, entryMeta.hash];
|
|
178
|
+
if (BlockJSONManagingPlugin.styleExtensionPattern.test(entryMeta.path)) {
|
|
179
179
|
return [res,
|
|
180
|
-
|
|
181
|
-
.map(
|
|
180
|
+
derivedFiles.filter(derivedFile => !BlockJSONManagingPlugin.scriptExtensionPattern.test(derivedFile))
|
|
181
|
+
.map(derivedFile => `file:./${node_path_1.default.relative(node_path_1.default.dirname(name), derivedFile)}`)
|
|
182
182
|
];
|
|
183
183
|
}
|
|
184
184
|
else {
|
|
185
|
-
return [res,
|
|
185
|
+
return [res, derivedFiles.map(derivedFile => `file:./${node_path_1.default.relative(node_path_1.default.dirname(name), derivedFile)}`)];
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
}
|
|
@@ -294,30 +294,16 @@ class BlockJSONManagingPlugin {
|
|
|
294
294
|
continue;
|
|
295
295
|
}
|
|
296
296
|
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
additionalFiles = new Set([...compilation.chunks]
|
|
301
|
-
.filter(chunk => typeof chunk.runtime === 'string' ? chunk.runtime === entrypointChunk.name : chunk.runtime?.has(runtimeName))
|
|
302
|
-
.flatMap(chunk => [...chunk.files])
|
|
303
|
-
.filter(file => !file.endsWith(".asset.php")));
|
|
304
|
-
additionalFiles.delete(destPath);
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
additionalFiles = new Set();
|
|
308
|
-
for (const entrypointChunkFile of entrypointChunk.files) {
|
|
309
|
-
if (!entrypointChunkFile.endsWith(".asset.php") && entrypointChunkFile !== destPath) {
|
|
310
|
-
additionalFiles.add(entrypointChunkFile);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
297
|
+
const derivedFiles = entrypointChunk.name
|
|
298
|
+
? BlockJSONManagingPlugin.getChunkFilesByRuntimeName(entrypointChunk.name, compilation).filter(file => file !== destPath)
|
|
299
|
+
: [...entrypointChunk.files].filter(file => !file.endsWith(".asset.php") && file !== destPath);
|
|
314
300
|
const entryMeta = { hash: entrypointChunk.hash ?? destPath, path: destPath };
|
|
315
301
|
const currentEntrypoints = BlockJSONManagingPlugin.blockJsonToEntrypointsMap.get(name);
|
|
316
302
|
if (currentEntrypoints) {
|
|
317
|
-
currentEntrypoints.set(srcPath, {
|
|
303
|
+
currentEntrypoints.set(srcPath, { entryMeta, derivedFiles });
|
|
318
304
|
}
|
|
319
305
|
else {
|
|
320
|
-
BlockJSONManagingPlugin.blockJsonToEntrypointsMap.set(name, new Map([[srcPath, {
|
|
306
|
+
BlockJSONManagingPlugin.blockJsonToEntrypointsMap.set(name, new Map([[srcPath, { entryMeta, derivedFiles }]]));
|
|
321
307
|
}
|
|
322
308
|
}
|
|
323
309
|
}
|
|
@@ -390,42 +376,47 @@ class BlockJSONManagingPlugin {
|
|
|
390
376
|
const blockDirConfigs = Object.entries(blockDirConfigData).sort(([a], [b]) => a.localeCompare(b));
|
|
391
377
|
const rawAssetDataSource = compilation.assets["assets.json"]?.source();
|
|
392
378
|
if (typeof rawAssetDataSource === 'string') {
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
379
|
+
const derivedFilesMap = new Map();
|
|
380
|
+
for (const epMap of BlockJSONManagingPlugin.blockJsonToEntrypointsMap.values()) { // For each block.json file's entry point map
|
|
381
|
+
for (const epMapValue of epMap.values()) { // For each recorded entry point
|
|
382
|
+
const progenitorFile = epMapValue.entryMeta.path;
|
|
383
|
+
for (const derivedFile of epMapValue.derivedFiles) { // For each derived (non-auxiliary) file generated by that entry point
|
|
384
|
+
derivedFilesMap.set(derivedFile, progenitorFile); // Record a mapping from each derived file to its progenitor
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
401
388
|
const rawAssetData = JSON.parse(rawAssetDataSource);
|
|
402
389
|
for (const chunk of compilation.chunks) {
|
|
403
390
|
if (compilation.chunkGraph.getChunkModulesIterableBySourceType(chunk, 'css/mini-extract')) {
|
|
404
|
-
const output =
|
|
391
|
+
const output = BlockJSONManagingPlugin.findFirstChunkFileWithExtension(chunk, ".css");
|
|
405
392
|
if (output) {
|
|
406
393
|
rawAssetData[output] = { dependencies: [], version: chunk.contentHash['css/mini-extract'] ?? chunk.hash ?? "" };
|
|
407
394
|
}
|
|
408
395
|
}
|
|
409
396
|
}
|
|
410
|
-
const
|
|
397
|
+
const scriptHandles = {};
|
|
398
|
+
const styleHandles = {};
|
|
399
|
+
const usedHandles = { css: {}, js: {} };
|
|
411
400
|
for (const [blockFolder, config] of blockDirConfigs) {
|
|
412
401
|
for (const mappableKey of BlockJSONManagingPlugin.mappableKeys) {
|
|
413
402
|
const cfg = config[mappableKey];
|
|
414
403
|
if (cfg) {
|
|
415
404
|
if (Array.isArray(cfg)) {
|
|
416
405
|
for (let i = 0; i < cfg.length; i++) {
|
|
417
|
-
const assetDetails =
|
|
406
|
+
const assetDetails = BlockJSONManagingPlugin
|
|
407
|
+
.getAssetDetails(blockFolder, cfg[i], rawAssetData, derivedFilesMap, mappableKey, usedHandles);
|
|
418
408
|
if (assetDetails) {
|
|
419
|
-
(assetDetails
|
|
420
|
-
cfg[i] = assetDetails
|
|
409
|
+
(assetDetails.isCss ? styleHandles : scriptHandles)[assetDetails.handle] = assetDetails.handleData;
|
|
410
|
+
cfg[i] = assetDetails.handle;
|
|
421
411
|
}
|
|
422
412
|
}
|
|
423
413
|
}
|
|
424
414
|
else {
|
|
425
|
-
const assetDetails =
|
|
415
|
+
const assetDetails = BlockJSONManagingPlugin
|
|
416
|
+
.getAssetDetails(blockFolder, cfg, rawAssetData, derivedFilesMap, mappableKey, usedHandles);
|
|
426
417
|
if (assetDetails) {
|
|
427
|
-
(assetDetails
|
|
428
|
-
config[mappableKey] = assetDetails
|
|
418
|
+
(assetDetails.isCss ? styleHandles : scriptHandles)[assetDetails.handle] = assetDetails.handleData;
|
|
419
|
+
config[mappableKey] = assetDetails.handle;
|
|
429
420
|
}
|
|
430
421
|
}
|
|
431
422
|
}
|
|
@@ -507,61 +498,90 @@ class BlockJSONManagingPlugin {
|
|
|
507
498
|
if (res) {
|
|
508
499
|
return res;
|
|
509
500
|
}
|
|
510
|
-
BlockJSONManagingPlugin.blockJsonAssetKeyReadinessMapping.set(name, { nonModule: makeSync(), module: makeSync() });
|
|
501
|
+
BlockJSONManagingPlugin.blockJsonAssetKeyReadinessMapping.set(name, { nonModule: BlockJSONManagingPlugin.makeSync(), module: BlockJSONManagingPlugin.makeSync() });
|
|
511
502
|
return BlockJSONManagingPlugin.blockJsonAssetKeyReadinessMapping.get(name);
|
|
512
503
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
res
|
|
520
|
-
});
|
|
521
|
-
return res;
|
|
522
|
-
}
|
|
523
|
-
function getAssetDetails(blockFolder, asset, rawAssetData, additionalFilesMap, mappableKey, usedHandles) {
|
|
524
|
-
if (!asset.startsWith("file:./")) {
|
|
525
|
-
return undefined;
|
|
526
|
-
}
|
|
527
|
-
const src = `${blockFolder}/${asset.substring(7)}`;
|
|
528
|
-
const isCss = src.endsWith(".css");
|
|
529
|
-
let assetData;
|
|
530
|
-
if (rawAssetData[src]) {
|
|
531
|
-
assetData = rawAssetData[src];
|
|
504
|
+
static makeSync() {
|
|
505
|
+
const res = { done: false };
|
|
506
|
+
res.sync = new Promise((resolve, reject) => {
|
|
507
|
+
res.resolve = (v) => resolve(v);
|
|
508
|
+
res.reject = () => reject();
|
|
509
|
+
});
|
|
510
|
+
return res;
|
|
532
511
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
512
|
+
static getAssetDetails(blockFolder, asset, rawAssetData, derivedFilesMap, mappableKey, usedHandles) {
|
|
513
|
+
if (!asset.startsWith("file:./")) {
|
|
514
|
+
return undefined;
|
|
515
|
+
}
|
|
516
|
+
const src = `${blockFolder}/${asset.substring(7)}`;
|
|
517
|
+
const isCss = src.endsWith(".css");
|
|
518
|
+
let assetData;
|
|
519
|
+
if (rawAssetData[src]) {
|
|
520
|
+
assetData = rawAssetData[src];
|
|
538
521
|
}
|
|
539
522
|
else {
|
|
540
|
-
|
|
523
|
+
const progenitorSrc = derivedFilesMap.get(src);
|
|
524
|
+
if (progenitorSrc) {
|
|
525
|
+
const tempAssetData = BlockJSONManagingPlugin.getAssetDataAccountingForCSS(progenitorSrc, rawAssetData);
|
|
526
|
+
if (tempAssetData) {
|
|
527
|
+
assetData = progenitorSrc.endsWith(".css") === isCss
|
|
528
|
+
? tempAssetData
|
|
529
|
+
: { ...tempAssetData, dependencies: [] }; // derived files cannot inherit dependencies from their progenitors if they are of a different type
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
assetData = undefined;
|
|
533
|
+
}
|
|
534
|
+
assetData = tempAssetData ? { ...tempAssetData, dependencies: [] } : undefined;
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
assetData = BlockJSONManagingPlugin.getAssetDataAccountingForCSS(src, rawAssetData);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (!assetData) {
|
|
541
|
+
return undefined;
|
|
542
|
+
}
|
|
543
|
+
let handle = src.substring(0, src.length - (isCss ? 4 : 3));
|
|
544
|
+
if (usedHandles[isCss ? 'css' : 'js'][handle] !== undefined) {
|
|
545
|
+
handle += "-" + (++usedHandles[isCss ? 'css' : 'js'][handle]);
|
|
541
546
|
}
|
|
547
|
+
else {
|
|
548
|
+
usedHandles[isCss ? 'css' : 'js'][handle] = 0;
|
|
549
|
+
}
|
|
550
|
+
const rest = isCss || mappableKey.startsWith("editor")
|
|
551
|
+
? [assetData.dependencies, assetData.version]
|
|
552
|
+
: [assetData.dependencies, assetData.version, { strategy: 'defer' }];
|
|
553
|
+
return { isCss, handle, handleData: { src, rest } };
|
|
542
554
|
}
|
|
543
|
-
|
|
555
|
+
static getAssetDataAccountingForCSS(src, rawAssetData) {
|
|
556
|
+
if (rawAssetData[src]) {
|
|
557
|
+
return rawAssetData[src];
|
|
558
|
+
}
|
|
559
|
+
if (src.endsWith(".css")) {
|
|
560
|
+
return rawAssetData[src.substring(0, src.length - 3) + "js"] // A simple style dependency that isn't named "style"
|
|
561
|
+
?? rawAssetData[src.substring(0, src.length - 3).replace("style-style", "style") + "js"]; // A simple style dependency that IS named style
|
|
562
|
+
}
|
|
544
563
|
return undefined;
|
|
545
564
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
return [
|
|
554
|
-
isCss, handle,
|
|
555
|
-
{ src, rest: isCss || mappableKey.startsWith("editor") ? [assetData.dependencies, assetData.version] : [assetData.dependencies, assetData.version, { strategy: 'defer' }] }
|
|
556
|
-
];
|
|
557
|
-
}
|
|
558
|
-
function getAssetDataAccountingForCSS(src, rawAssetData) {
|
|
559
|
-
if (rawAssetData[src]) {
|
|
560
|
-
return rawAssetData[src];
|
|
565
|
+
static findFirstChunkFileWithExtension(chunk, extension) {
|
|
566
|
+
for (const file of chunk.files) {
|
|
567
|
+
if (file.endsWith(extension)) {
|
|
568
|
+
return file;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return undefined;
|
|
561
572
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
573
|
+
static getChunkFilesByRuntimeName(runtimeName, compilation) {
|
|
574
|
+
const files = new Set();
|
|
575
|
+
for (const chunk of compilation.chunks) {
|
|
576
|
+
if (typeof chunk.runtime === 'string' ? chunk.runtime === runtimeName : chunk.runtime?.has(runtimeName)) {
|
|
577
|
+
for (const file of chunk.files) {
|
|
578
|
+
if (!file.endsWith(".asset.php")) {
|
|
579
|
+
files.add(file);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return [...files];
|
|
565
585
|
}
|
|
566
|
-
return undefined;
|
|
567
586
|
}
|
|
587
|
+
exports.default = BlockJSONManagingPlugin;
|
|
@@ -279,7 +279,20 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
|
279
279
|
}
|
|
280
280
|
const copyFiles = srcIsDirectory && src !== dest;
|
|
281
281
|
const plugins = webpackConfig.plugins?.filter(v => !!v)
|
|
282
|
-
.filter(plugin => plugin.constructor.name !== 'RtlCssPlugin')
|
|
282
|
+
.filter(plugin => plugin.constructor.name !== 'RtlCssPlugin')
|
|
283
|
+
.map(plugin => {
|
|
284
|
+
if (plugin.constructor.name === 'MiniCssExtractPlugin') {
|
|
285
|
+
return new plugin.constructor({
|
|
286
|
+
filename(pd) {
|
|
287
|
+
const name = pd.chunk?.name?.replaceAll(/__[a-zA-Z0-9]+__/g, ""); // This removes the prefix that the cache group adds
|
|
288
|
+
return name ? `${name}.css` : "[name].css";
|
|
289
|
+
},
|
|
290
|
+
layer: ""
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return plugin;
|
|
294
|
+
})
|
|
295
|
+
?? [];
|
|
283
296
|
if (process.env["NO_TS_CHECKER"] !== "true") {
|
|
284
297
|
const include = (Array.isArray(srcRoot) ? srcRoot : [srcRoot])
|
|
285
298
|
.filter(sr => node_path_1.default.extname(sr).length === 0 || scriptOrStyleTest(sr, scriptExtension) === "script")
|
|
@@ -516,6 +529,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
|
516
529
|
optimization: {
|
|
517
530
|
...webpackConfig.optimization,
|
|
518
531
|
splitChunks: {
|
|
532
|
+
...(webpackConfig.optimization?.splitChunks || {}),
|
|
519
533
|
cacheGroups: {
|
|
520
534
|
style: {
|
|
521
535
|
// This is a flagrant abuse of cache groups, but it fixes a persistent problem wherein the dependencies and versions of scripts and styles were bleeding into each-other
|
|
@@ -524,11 +538,12 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
|
524
538
|
enforce: true,
|
|
525
539
|
name(_, chunks, cacheGroupKey) {
|
|
526
540
|
const chunkName = chunks.find(chunk => chunk.name)?.name;
|
|
527
|
-
|
|
528
|
-
|
|
541
|
+
// We use "__${cacheGroupKey}__" instead of "${cacheGroupKey}-" to make it easier to remove when generating the filename
|
|
542
|
+
return `${node_path_1.default.dirname(chunkName)}/__${cacheGroupKey}__${node_path_1.default.basename(chunkName)}`;
|
|
543
|
+
}
|
|
529
544
|
},
|
|
530
|
-
default: false
|
|
531
|
-
}
|
|
545
|
+
default: false
|
|
546
|
+
}
|
|
532
547
|
}
|
|
533
548
|
},
|
|
534
549
|
module: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.44.
|
|
3
|
+
"version": "2.44.6",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"clean-webpack-plugin": "^4.0.0",
|
|
46
46
|
"copy-webpack-plugin": "^10.2.4",
|
|
47
47
|
"cssnano": "^6.1.2",
|
|
48
|
-
"eslint": "^8.57.1",
|
|
49
48
|
"eslint-plugin-jsdoc": "^48.11.0",
|
|
50
49
|
"fork-ts-checker-webpack-plugin": "^9.1.0",
|
|
51
50
|
"http-proxy-middleware": "^3.0.5",
|