@plaudit/webpack-extensions 2.66.4 → 2.66.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.
@@ -68,6 +68,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
68
68
  const blockSlug = match[1], assetType = match[2];
69
69
  if (blockSlug && assetType) {
70
70
  const key = assetType.replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
71
+ //TODO: Handle deduplicating handles in the same way that PlainEntrypointsStyleBlockJSONPlugin does
71
72
  const handle = `${handlePrefix}_${blockSlug}-${assetType}`;
72
73
  const isCss = (0, shared_1.isStyleField)(assetType);
73
74
  const handleGroup = isCss ? 'styleHandles'
@@ -98,7 +99,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
98
99
  })
99
100
  .toSorted(([a], [b]) => a.localeCompare(b)));
100
101
  new php_writer_1.PHPWriter()
101
- .call("Plaudit\\Common\\Lib\\GutenbergUtils::loadExtensionsV3", [new php_writer_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, false)), php_writer_1.Expr.call("trailingslashit", [php_writer_1.Constants.__DIR__]),
102
+ .call("Plaudit\\Common\\Lib\\GutenbergUtils::loadExtensionsV3", [new php_writer_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, false)), php_writer_1.Op.concat(php_writer_1.Constants.__DIR__, '/'),
102
103
  php_writer_1.Expr.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.Constants.__DIR__])])
103
104
  .emitAsset(compilation, node_path_1.default.join(this.dest.destination, "extensions-loader.php"));
104
105
  }
@@ -1,8 +1,18 @@
1
1
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
- import { ParsedAssetsJson, BlockEntrypointInfo } from "../shared";
2
+ import { ParsedAssetsJson, BlockEntrypointInfo, FileSegmentBlockEntrypointInfo } from "../shared";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
4
  import { Compilation } from "webpack";
5
5
  import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
6
+ type WorkableBlockEntrypointInfo = Omit<FileSegmentBlockEntrypointInfo, 'originalValue'> & Partial<Pick<FileSegmentBlockEntrypointInfo, 'originalValue'>> & {
7
+ outputPath: string;
8
+ assetData: ParsedAssetsJson[string];
9
+ hash: string;
10
+ };
11
+ type CollatedWorkableBlockInfo = Record<string, {
12
+ sourcePath?: string;
13
+ workableBlockEntrypointsInfo: WorkableBlockEntrypointInfo[];
14
+ blockJsonText?: string;
15
+ }>;
6
16
  export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
7
17
  private readonly blocksDest;
8
18
  private readonly webpackRemoveEmptyScriptsPlugin;
@@ -23,4 +33,6 @@ export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhas
23
33
  private static normalizeRenderTemplate;
24
34
  protected attachUniquePhase(compilation: Compilation): void;
25
35
  protected attachStandardPhase(compilation: Compilation): void;
36
+ protected deduplicateEntrypointHandles(workableBlockInfo: CollatedWorkableBlockInfo): CollatedWorkableBlockInfo;
26
37
  }
38
+ export {};
@@ -70,9 +70,10 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
70
70
  .map(([file, assetType]) => {
71
71
  const wasOriginallyAStyleField = (0, shared_1.isStyleField)(metadata.entrypointField);
72
72
  if (wasOriginallyAStyleField !== (assetType === "style")) { // This means that the file is extracted
73
+ const entrypointField = (0, shared_1.convertEntrypointFieldForAssetType)(metadata.entrypointField, assetType);
73
74
  return {
74
75
  ...metadata, outputPath: file, assetData, originalValue: undefined, hash: entrypointChunk.hash ?? "",
75
- entrypointField: (0, shared_1.convertEntrypointFieldForAssetType)(metadata.entrypointField, assetType)
76
+ entrypointField, handleGroup: (0, shared_1.getHandleGroup)(entrypointField)
76
77
  };
77
78
  }
78
79
  return ({ ...metadata, outputPath: file, assetData, hash: entrypointChunk.hash ?? "" });
@@ -155,7 +156,9 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
155
156
  scriptModuleHandles: Object.fromEntries(PlainEntrypointsStyleBlockJSONPlugin
156
157
  .convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && (0, shared_1.isScriptModuleField)(hd.entrypointField)))),
157
158
  styleHandles: Object.fromEntries(handleData.filter(hd => (0, shared_1.isStyleField)(hd.entrypointField))
158
- .map(hd => [hd.handle, { src: hd.outputPath, rest: [hd.assetData.dependencies, hd.assetData.version] }]))
159
+ .map(hd => {
160
+ return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version] }];
161
+ }))
159
162
  },
160
163
  ...Object.fromEntries(Object.entries(blockData).sort((a, b) => a[0].localeCompare(b[0])))
161
164
  };
@@ -166,8 +169,8 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
166
169
  }
167
170
  static convertToScriptHandles(handleData) {
168
171
  return handleData.map(hd => {
169
- return [hd.handle, { src: hd.outputPath, rest: hd.entrypointField.startsWith("editor")
170
- ? [hd.assetData.dependencies, hd.assetData.version] : [hd.assetData.dependencies, hd.assetData.version, { strategy: "defer" }] }];
172
+ const deps = hd.originalValue !== undefined ? hd.assetData.dependencies : [];
173
+ return [hd.handle, { src: hd.outputPath, rest: hd.entrypointField.startsWith("editor") ? [deps, hd.assetData.version] : [deps, hd.assetData.version, { strategy: "defer" }] }];
171
174
  });
172
175
  }
173
176
  static doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, getter) {
@@ -368,7 +371,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
368
371
  }
369
372
  return acc;
370
373
  }, {});
371
- const blockData = this.transformBlocks(compilation, workableBlockInfo, semaphoreData.some(sd => sd.emittingWpmlXml));
374
+ const blockData = this.transformBlocks(compilation, this.deduplicateEntrypointHandles(workableBlockInfo), semaphoreData.some(sd => sd.emittingWpmlXml));
372
375
  this.emitBlockLoaderFile(compilation, blockData);
373
376
  });
374
377
  }
@@ -389,5 +392,28 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
389
392
  }
390
393
  });
391
394
  }
395
+ deduplicateEntrypointHandles(workableBlockInfo) {
396
+ const handleRecords = { scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {} };
397
+ for (const { workableBlockEntrypointsInfo } of Object.values(workableBlockInfo)) {
398
+ for (const { handleGroup, handle, originalValue, outputPath } of workableBlockEntrypointsInfo) {
399
+ if (originalValue !== undefined) {
400
+ handleRecords[handleGroup][handle] = outputPath;
401
+ }
402
+ }
403
+ }
404
+ return Object.fromEntries(Object.entries(workableBlockInfo).map((e) => {
405
+ const deduplicatedWorkableBlockEntrypointsInfo = e[1].workableBlockEntrypointsInfo.map(bei => {
406
+ if (handleRecords[bei.handleGroup][bei.handle] === bei.outputPath) {
407
+ return bei;
408
+ }
409
+ for (let count = 1, handle = `${bei.handle}_${count}`;; handle = `${bei.handle}_${++count}`) {
410
+ if (!handleRecords[bei.handleGroup][handle] || handleRecords[bei.handleGroup][handle] === bei.outputPath) {
411
+ return { ...bei, handle };
412
+ }
413
+ }
414
+ });
415
+ return [e[0], { ...e[1], workableBlockEntrypointsInfo: deduplicatedWorkableBlockEntrypointsInfo }];
416
+ }));
417
+ }
392
418
  }
393
419
  exports.PlainEntrypointsStyleBlockJSONPlugin = PlainEntrypointsStyleBlockJSONPlugin;
package/build/shared.d.ts CHANGED
@@ -79,6 +79,7 @@ export type PlauditWordpressWebpackConfig = {
79
79
  export type FileSegmentBlockEntrypointInfo = {
80
80
  blockJsonOrigin: string;
81
81
  entrypointField: EntrypointFields[number];
82
+ handleGroup: ReturnType<typeof getHandleGroup>;
82
83
  originalValue: string;
83
84
  entrypointName: string;
84
85
  handle: string;
@@ -99,8 +100,9 @@ export declare const scriptWithoutModuleExtension: RegExp;
99
100
  export declare const scriptWithModuleExtension: RegExp;
100
101
  export declare const styleExtension: RegExp;
101
102
  export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "" | "style" | "script";
102
- export declare function isStyleField(field: string): boolean;
103
- export declare function isScriptModuleField(field: string): boolean;
103
+ export declare function isStyleField(field: string): field is 'style' | 'viewStyle' | 'editorStyle';
104
+ export declare function isScriptModuleField(field: string): field is 'scriptModule' | 'viewScriptModule';
105
+ export declare function getHandleGroup(field: string): 'styleHandles' | 'scriptHandles' | 'scriptModuleHandles';
104
106
  export declare function hasAtLeastOneItem<T>(list: T[]): list is [T, ...T[]];
105
107
  export type TupleOf<T, N extends number> = N extends N ? number extends N ? T[] : _TupleOf<T, N, []> : never;
106
108
  type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, [T, ...R]>;
package/build/shared.js CHANGED
@@ -13,6 +13,7 @@ exports.leadingSlashIt = leadingSlashIt;
13
13
  exports.scriptOrStyleTest = scriptOrStyleTest;
14
14
  exports.isStyleField = isStyleField;
15
15
  exports.isScriptModuleField = isScriptModuleField;
16
+ exports.getHandleGroup = getHandleGroup;
16
17
  exports.hasAtLeastOneItem = hasAtLeastOneItem;
17
18
  exports.arrayIsLength = arrayIsLength;
18
19
  exports.kebabCase = kebabCase;
@@ -90,6 +91,15 @@ function isStyleField(field) {
90
91
  function isScriptModuleField(field) {
91
92
  return field.includes("odule");
92
93
  }
94
+ function getHandleGroup(field) {
95
+ if (isStyleField(field)) {
96
+ return 'styleHandles';
97
+ }
98
+ if (isScriptModuleField(field)) {
99
+ return 'scriptModuleHandles';
100
+ }
101
+ return 'scriptHandles';
102
+ }
93
103
  function hasAtLeastOneItem(list) {
94
104
  return list.length > 0 && list[0] !== undefined && list[0] !== null;
95
105
  }
@@ -39,12 +39,14 @@ function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
39
39
  .filter(ep => supportedExtensions(ep) && node_fs_1.default.statSync(ep, { throwIfNoEntry: false })?.isFile())
40
40
  .map(ep => {
41
41
  const parsedEntrypoint = node_path_1.default.parse(ep);
42
+ const entrypointField = shared_1.styleExtension.test(ep) ? 'style' : shared_1.scriptWithModuleExtension.test(ep) ? 'scriptModule' : 'script';
42
43
  const fakeEntrypointInfo = {
43
44
  blockJsonOrigin: args.entrypointJsonOrigin,
44
- entrypointField: shared_1.styleExtension.test(ep) ? 'style' : shared_1.scriptWithModuleExtension.test(ep) ? 'scriptModule' : 'script',
45
+ entrypointField,
45
46
  originalValue: ep,
46
47
  entrypointName: parsedEntrypoint.name,
47
48
  handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name),
49
+ handleGroup: (0, shared_1.getHandleGroup)(entrypointField),
48
50
  dest
49
51
  };
50
52
  return [joinPossiblyAbsolutePaths(dest.destination, node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name),
@@ -166,12 +168,9 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
166
168
  const overallSource = node_path_1.default.dirname(blockJsonOrigin);
167
169
  const overallSourceRelativeName = node_path_1.default.relative(overallSource, node_path_1.default.normalize(node_path_1.default.join(blockJsonOrigin, node_path_1.default.relative(overallSource, presentEntrypoint.extensionlessExpectedSrc))));
168
170
  const handleSuffix = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, overallSourceRelativeName);
171
+ const handleGroup = (0, shared_1.getHandleGroup)(presentEntrypoint.entrypointField);
169
172
  if (!entrypointNamesWithEffectiveDuplicates[presentEntrypoint.entrypointName]) {
170
- return {
171
- blockJsonOrigin, ...presentEntrypoint,
172
- handle: `${handlePrefix}/${handleSuffix}`,
173
- dest
174
- };
173
+ return { blockJsonOrigin, ...presentEntrypoint, handle: `${handlePrefix}/${handleSuffix}`, dest, handleGroup };
175
174
  }
176
175
  const baseSuffix = `_${(0, shared_1.isStyleField)(presentEntrypoint.entrypointField) ? "style" : "script"}`;
177
176
  let count = 0, suffix = baseSuffix, deduplicatedEntrypointName;
@@ -186,7 +185,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
186
185
  ...presentEntrypoint,
187
186
  entrypointName: deduplicatedEntrypointName,
188
187
  extensionlessExpectedSrc: deduplicatedExtensionlessExpectedSrc,
189
- handle: `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`,
188
+ handle: `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`, handleGroup,
190
189
  dest
191
190
  };
192
191
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.66.4",
3
+ "version": "2.66.6",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build"
@@ -16,9 +16,9 @@
16
16
  }
17
17
  },
18
18
  "devDependencies": {
19
- "@plaudit/gutenberg-api-extensions": "^2.76.1",
19
+ "@plaudit/gutenberg-api-extensions": "^2.77.0",
20
20
  "@types/browser-sync-webpack-plugin": "^2.2.5",
21
- "@types/node": "^24.4.0",
21
+ "@types/node": "^24.5.2",
22
22
  "@types/postcss-functions": "^4.0.4",
23
23
  "@types/tapable": "^2.2.7",
24
24
  "@types/webpack": "^5.28.5",
@@ -35,8 +35,8 @@
35
35
  "@plaudit/postcss-silent-extend": "^3.0.0",
36
36
  "@plaudit/postcss-strip-units": "^3.0.0",
37
37
  "@plaudit/postcss-variables": "^1.1.0",
38
- "@wordpress/dependency-extraction-webpack-plugin": "^6.30.0",
39
- "@wordpress/scripts": "^30.23.0",
38
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.31.0",
39
+ "@wordpress/scripts": "^30.24.0",
40
40
  "autoprefixer": "^10.4.21",
41
41
  "browser-sync": "^3.0.4",
42
42
  "copy-webpack-plugin": "^10.2.4",
@@ -64,7 +64,7 @@
64
64
  "react-dom": "^18.3.1",
65
65
  "webpack": "^5.101.3",
66
66
  "webpack-remove-empty-scripts": "^1.1.1",
67
- "xml-formatter": "^3.6.6"
67
+ "xml-formatter": "^3.6.7"
68
68
  },
69
69
  "engines": {
70
70
  "node": ">=20"