@plaudit/webpack-extensions 2.66.4 → 2.66.5

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 ?? "" });
@@ -368,7 +369,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
368
369
  }
369
370
  return acc;
370
371
  }, {});
371
- const blockData = this.transformBlocks(compilation, workableBlockInfo, semaphoreData.some(sd => sd.emittingWpmlXml));
372
+ const blockData = this.transformBlocks(compilation, this.deduplicateEntrypointHandles(workableBlockInfo), semaphoreData.some(sd => sd.emittingWpmlXml));
372
373
  this.emitBlockLoaderFile(compilation, blockData);
373
374
  });
374
375
  }
@@ -389,5 +390,28 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
389
390
  }
390
391
  });
391
392
  }
393
+ deduplicateEntrypointHandles(workableBlockInfo) {
394
+ const handleRecords = { scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {} };
395
+ for (const { workableBlockEntrypointsInfo } of Object.values(workableBlockInfo)) {
396
+ for (const { handleGroup, handle, originalValue, outputPath } of workableBlockEntrypointsInfo) {
397
+ if (originalValue !== undefined) {
398
+ handleRecords[handleGroup][handle] = outputPath;
399
+ }
400
+ }
401
+ }
402
+ return Object.fromEntries(Object.entries(workableBlockInfo).map((e) => {
403
+ const deduplicatedWorkableBlockEntrypointsInfo = e[1].workableBlockEntrypointsInfo.map(bei => {
404
+ if (handleRecords[bei.handleGroup][bei.handle] === bei.outputPath) {
405
+ return bei;
406
+ }
407
+ for (let count = 1, handle = `${bei.handle}_${count}`;; handle = `${bei.handle}_${++count}`) {
408
+ if (!handleRecords[bei.handleGroup][handle] || handleRecords[bei.handleGroup][handle] === bei.outputPath) {
409
+ return { ...bei, handle };
410
+ }
411
+ }
412
+ });
413
+ return [e[0], { ...e[1], workableBlockEntrypointsInfo: deduplicatedWorkableBlockEntrypointsInfo }];
414
+ }));
415
+ }
392
416
  }
393
417
  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.5",
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.1",
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",