@plaudit/webpack-extensions 2.45.0 → 2.46.0

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.
@@ -404,7 +404,7 @@ class BlockJSONManagingPlugin {
404
404
  if (Array.isArray(cfg)) {
405
405
  for (let i = 0; i < cfg.length; i++) {
406
406
  const assetDetails = BlockJSONManagingPlugin
407
- .getAssetDetails(blockFolder, cfg[i], rawAssetData, derivedFilesMap, mappableKey, usedHandles);
407
+ .getAssetDetails(blockFolder, config["name"], cfg[i], rawAssetData, derivedFilesMap, mappableKey, usedHandles);
408
408
  if (assetDetails) {
409
409
  (assetDetails.isCss ? styleHandles : scriptHandles)[assetDetails.handle] = assetDetails.handleData;
410
410
  cfg[i] = assetDetails.handle;
@@ -413,7 +413,7 @@ class BlockJSONManagingPlugin {
413
413
  }
414
414
  else {
415
415
  const assetDetails = BlockJSONManagingPlugin
416
- .getAssetDetails(blockFolder, cfg, rawAssetData, derivedFilesMap, mappableKey, usedHandles);
416
+ .getAssetDetails(blockFolder, config["name"], cfg, rawAssetData, derivedFilesMap, mappableKey, usedHandles);
417
417
  if (assetDetails) {
418
418
  (assetDetails.isCss ? styleHandles : scriptHandles)[assetDetails.handle] = assetDetails.handleData;
419
419
  config[mappableKey] = assetDetails.handle;
@@ -509,7 +509,7 @@ class BlockJSONManagingPlugin {
509
509
  });
510
510
  return res;
511
511
  }
512
- static getAssetDetails(blockFolder, asset, rawAssetData, derivedFilesMap, mappableKey, usedHandles) {
512
+ static getAssetDetails(blockFolder, blockName, asset, rawAssetData, derivedFilesMap, mappableKey, usedHandles) {
513
513
  if (!asset.startsWith("file:./")) {
514
514
  return undefined;
515
515
  }
@@ -541,6 +541,9 @@ class BlockJSONManagingPlugin {
541
541
  return undefined;
542
542
  }
543
543
  let handle = src.substring(0, src.length - (isCss ? 4 : 3));
544
+ if (blockName && handle.startsWith(blockName.substring(blockName.indexOf("/") + 1) + "/")) {
545
+ handle = blockName + handle.substring(handle.indexOf("/"));
546
+ }
544
547
  if (usedHandles[isCss ? 'css' : 'js'][handle] !== undefined) {
545
548
  handle += "-" + (++usedHandles[isCss ? 'css' : 'js'][handle]);
546
549
  }
@@ -29,40 +29,18 @@ class ExtensionsConfigFileGeneratorPlugin {
29
29
  await Promise.all(emissionPromises);
30
30
  });
31
31
  compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
32
- compilation.hooks.processAssets.tap({
33
- name: `${this.constructor.name}_ProcessAssets`,
34
- stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE
35
- }, compilationAssets => {
36
- const stats = compilation.getStats().toJson({
37
- hash: true,
38
- publicPath: true,
39
- assets: true,
40
- chunks: true,
41
- modules: true,
42
- source: true,
43
- errorDetails: false,
44
- timings: false
45
- });
46
- if (!stats.assets) {
47
- throw new Error("Stats did not include assets despite them being requested");
48
- }
49
- if (!stats.modules) {
50
- throw new Error("Stats did not include modules despite them being requested");
51
- }
32
+ compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_ProcessAssets`, compilationAssets => {
52
33
  const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
53
34
  const mapping = {};
54
- for (const asset of stats.assets) {
55
- if ((asset.chunks?.length ?? -1) > 1 || !asset.size) {
56
- continue;
57
- }
35
+ for (const asset of Object.keys(compilationAssets)) {
58
36
  let match;
59
- if ((match = /^(.+?)-setup.php$/i.exec(asset.name)) && match[1]) {
60
- (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[1] = `${asset.name}`;
37
+ if ((match = /^(.+?)-setup.php$/i.exec(asset)) && match[1]) {
38
+ (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[1] = `${asset}`;
61
39
  }
62
- else if ((match = regex.exec(asset.name)) && match[1] && match[2]) {
40
+ else if ((match = regex.exec(asset)) && match[1] && match[2]) {
63
41
  const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
64
42
  const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
65
- (resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset.name]);
43
+ (resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset]);
66
44
  }
67
45
  }
68
46
  compilation.emitAsset("mapping.config", new webpack_1.sources.RawSource((0, php_serializer_1.default)(mapping)));
@@ -538,7 +538,9 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
538
538
  name(_, chunks, cacheGroupKey) {
539
539
  const chunkName = chunks.find(chunk => chunk.name)?.name;
540
540
  // We use "__${cacheGroupKey}__" instead of "${cacheGroupKey}-" to make it easier to remove when generating the filename
541
- return `${node_path_1.default.dirname(chunkName)}/__${cacheGroupKey}__${node_path_1.default.basename(chunkName)}`;
541
+ const filename = `__${cacheGroupKey}__${node_path_1.default.basename(chunkName)}`;
542
+ const dirname = node_path_1.default.dirname(chunkName);
543
+ return dirname === '.' ? filename : `${dirname}/${filename}`;
542
544
  }
543
545
  },
544
546
  default: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.45.0",
3
+ "version": "2.46.0",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "/build"
@@ -18,7 +18,7 @@
18
18
  "devDependencies": {
19
19
  "@plaudit/gutenberg-api-extensions": "^2.66.1",
20
20
  "@types/browser-sync-webpack-plugin": "^2.2.5",
21
- "@types/node": "^22.14.1",
21
+ "@types/node": "^22.15.3",
22
22
  "@types/postcss-functions": "^4.0.4",
23
23
  "@types/tapable": "^2.2.7",
24
24
  "@types/webpack": "^5.28.5",
@@ -62,7 +62,7 @@
62
62
  "postcss-url": "^10.1.3",
63
63
  "react": "^18.3.1",
64
64
  "react-dom": "^18.3.1",
65
- "webpack": "^5.99.6",
65
+ "webpack": "^5.99.7",
66
66
  "webpack-remove-empty-scripts": "^1.0.4",
67
67
  "xml-formatter": "^3.6.5"
68
68
  },