@plaudit/webpack-extensions 2.64.0 → 2.65.1

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.
Files changed (34) hide show
  1. package/build/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +33 -0
  2. package/build/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +86 -0
  3. package/build/plugins/AbstractBiPhasicGroupPlugin.d.ts +33 -0
  4. package/build/plugins/AbstractBiPhasicGroupPlugin.js +93 -0
  5. package/build/plugins/AdditionalDependencyInjectorPlugin.d.ts +8 -6
  6. package/build/plugins/AdditionalDependencyInjectorPlugin.js +37 -39
  7. package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +4 -5
  8. package/build/plugins/EnhancedDynamicEntryPlugin.js +3 -3
  9. package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +9 -8
  10. package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +103 -93
  11. package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +7 -8
  12. package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +10 -17
  13. package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +6 -7
  14. package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +15 -16
  15. package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +6 -6
  16. package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +10 -9
  17. package/build/plugins/SpecialAssetHandlingPlugin.d.ts +5 -5
  18. package/build/plugins/SpecialAssetHandlingPlugin.js +44 -47
  19. package/build/plugins/UnifiedLoaderGenerator.d.ts +8 -8
  20. package/build/plugins/UnifiedLoaderGenerator.js +54 -69
  21. package/build/plugins/WPMLConfigBuilder.d.ts +2 -2
  22. package/build/shared.d.ts +10 -14
  23. package/build/shared.js +19 -23
  24. package/build/utils/common-config-helpers.d.ts +6 -6
  25. package/build/utils/common-config-helpers.js +11 -8
  26. package/build/utils/json-to-php-but-with-__-injection.js +1 -1
  27. package/build/utils/pseduo-semaphore.d.ts +2 -3
  28. package/build/utils/pseduo-semaphore.js +9 -5
  29. package/build/wordpress-scripts-wrapper.js +21 -15
  30. package/package.json +3 -3
  31. package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.d.ts +0 -21
  32. package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.js +0 -113
  33. package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +0 -17
  34. package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +0 -44
@@ -8,59 +8,54 @@ const node_path_1 = __importDefault(require("node:path"));
8
8
  const shared_1 = require("../shared");
9
9
  const php_writer_1 = require("../utils/php-writer");
10
10
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
11
- const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
11
+ const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
12
12
  const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
13
13
  const webpack_1 = require("webpack");
14
- class SpecialAssetHandlingPlugin extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
15
- static semaphore = new pseduo_semaphore_1.PseudoSemaphore({}, "Special");
14
+ class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
15
+ static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Special");
16
16
  static validPathname = undefined;
17
17
  constructor(config) {
18
18
  super(config, "special-assets", [SpecialAssetHandlingPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
19
19
  }
20
- apply(compiler) {
21
- if (!this.config.useWebpackResourceFiltering) {
22
- return;
23
- }
24
- super.apply(compiler);
25
- compiler.hooks.compilation.tap(this.constructor.name, compilation => {
26
- compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE }, async (assets) => {
27
- try {
28
- const specialAssetData = {};
29
- for (const pathname of Object.keys(assets)) {
30
- if (!SpecialAssetHandlingPlugin.validPathname) {
31
- SpecialAssetHandlingPlugin.validPathname = pathname;
32
- }
33
- const assetInfo = compilation.assetsInfo.get(pathname);
34
- if (!assetInfo?.sourceFilename) {
35
- continue;
36
- }
37
- const filename = node_path_1.default.join(node_path_1.default.basename(node_path_1.default.dirname(pathname)), node_path_1.default.basename(pathname));
38
- const queryStart = assetInfo.sourceFilename.indexOf('?');
39
- if (queryStart < 0) {
40
- continue;
41
- }
42
- const params = new URLSearchParams(assetInfo.sourceFilename.substring(queryStart + 1)
43
- .replace(/(?:fetchPriority|crossOrigin)=/gi, str => str.toLowerCase()) //This ensures consistent capitalization of the fetchPriority parameter
44
- );
45
- if (params.has("preload")) {
46
- SpecialAssetHandlingPlugin.validPathname = pathname;
47
- specialAssetData[filename] = {
48
- preload: true,
49
- fetchpriority: params.get("fetchpriority"),
50
- crossorigin: params.get("crossorigin")
51
- };
52
- }
20
+ attachStandardPhase(compilation) {
21
+ compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE }, async (assets) => {
22
+ try {
23
+ const specialAssetData = {};
24
+ for (const pathname of Object.keys(assets)) {
25
+ if (!SpecialAssetHandlingPlugin.validPathname) {
26
+ SpecialAssetHandlingPlugin.validPathname = pathname;
27
+ }
28
+ const assetInfo = compilation.assetsInfo.get(pathname);
29
+ if (!assetInfo?.sourceFilename) {
30
+ continue;
31
+ }
32
+ const filename = node_path_1.default.join(node_path_1.default.basename(node_path_1.default.dirname(pathname)), node_path_1.default.basename(pathname));
33
+ const queryStart = assetInfo.sourceFilename.indexOf('?');
34
+ if (queryStart < 0) {
35
+ continue;
36
+ }
37
+ const params = new URLSearchParams(assetInfo.sourceFilename.substring(queryStart + 1)
38
+ .replace(/(?:fetchPriority|crossOrigin)=/gi, str => str.toLowerCase()) //This ensures consistent capitalization of the fetchPriority parameter
39
+ );
40
+ if (params.has("preload")) {
41
+ SpecialAssetHandlingPlugin.validPathname = pathname;
42
+ specialAssetData[filename] = {
43
+ preload: true,
44
+ fetchpriority: params.get("fetchpriority"),
45
+ crossorigin: params.get("crossorigin")
46
+ };
53
47
  }
54
- SpecialAssetHandlingPlugin.semaphore.resolve(this.id, specialAssetData);
55
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(specialAssetData).length > 0
56
- ? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/special-assets.php';") }
57
- : undefined);
58
- }
59
- catch (e) {
60
- this.rejectSemaphores();
61
- throw e;
62
48
  }
63
- });
49
+ SpecialAssetHandlingPlugin.semaphore.resolve(this.id, specialAssetData);
50
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(specialAssetData).length > 0
51
+ ? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/special-assets.php';") }
52
+ : undefined);
53
+ }
54
+ catch (e) {
55
+ console.error(e);
56
+ this.rejectSemaphores();
57
+ throw e;
58
+ }
64
59
  });
65
60
  }
66
61
  async collateAssets(compilation) {
@@ -127,8 +122,10 @@ class SpecialAssetHandlingPlugin extends AbstractMultiPhaseLibraryPlugin_1.Abstr
127
122
  });
128
123
  writer.emitAsset(compilation, outputFile);
129
124
  }
130
- attachSecondPhase(compilation) {
131
- compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, () => this.collateAssets(compilation));
125
+ attachUniquePhase(compilation) {
126
+ compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
127
+ await this.collateAssets(compilation);
128
+ });
132
129
  }
133
130
  }
134
131
  exports.SpecialAssetHandlingPlugin = SpecialAssetHandlingPlugin;
@@ -1,19 +1,19 @@
1
+ import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
1
2
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
2
- import { PseudoSemaphore } from "../utils/pseduo-semaphore";
3
3
  import { PHPWriter } from "../utils/php-writer";
4
- import { Compiler, WebpackPluginInstance } from "webpack";
4
+ import { PseudoSemaphore } from "../utils/pseduo-semaphore";
5
+ import { Compilation } from "webpack";
5
6
  type LoaderInfo = {
6
7
  group: string;
7
8
  action(writer: PHPWriter): void;
8
9
  requiresBaseURI: boolean;
10
+ staticallyLoadedEntrypoints?: string[];
9
11
  priority?: number;
10
12
  };
11
- export declare class UnifiedLoaderGenerator implements WebpackPluginInstance {
12
- private readonly config;
13
- static readonly semaphore: PseudoSemaphore<LoaderInfo | undefined>;
14
- private static attached;
15
- private readonly id;
13
+ export declare class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin {
14
+ static readonly semaphore: PseudoSemaphore<LoaderInfo>;
16
15
  constructor(config: VerifiedPlauditWordpressWebpackConfig);
17
- apply(compiler: Compiler): void;
16
+ protected attachStandardPhase(compilation: Compilation): void;
17
+ protected attachUniquePhase(compilation: Compilation): void;
18
18
  }
19
19
  export {};
@@ -5,84 +5,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.UnifiedLoaderGenerator = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
+ const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
8
9
  const shared_1 = require("../shared");
9
- const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
10
+ const json_to_php_but_with____injection_1 = __importDefault(require("../utils/json-to-php-but-with-__-injection"));
10
11
  const php_writer_1 = require("../utils/php-writer");
12
+ const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
11
13
  const webpack_1 = require("webpack");
12
- class UnifiedLoaderGenerator {
13
- config;
14
- static semaphore = new pseduo_semaphore_1.PseudoSemaphore(undefined, "Unified");
15
- static attached = false;
16
- id;
14
+ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
15
+ static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Unified");
17
16
  constructor(config) {
18
- this.config = config;
19
- this.id = Math.random().toString();
17
+ super(config, "unified-loader", []);
20
18
  }
21
- apply(compiler) {
22
- compiler.hooks.compilation.tap(`${this.constructor.name}_Cleanup`, compilation => {
23
- compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
24
- if (!this.config.useUnifiedLoader) {
25
- const rawAssetDataSource = compilation.assets["assets.json"]?.source();
26
- if (typeof rawAssetDataSource !== 'string') {
27
- compilation.errors.push(new Error("assets.json is unexpectedly missing or not a string"));
28
- return;
29
- }
30
- const rawAssetData = JSON.parse(rawAssetDataSource);
31
- if (!(0, shared_1.isRawAssetData)(rawAssetData)) {
32
- compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
33
- return;
34
- }
35
- for (const [file, assetData] of Object.entries(rawAssetData)) {
36
- const escapedDependencies = assetData.dependencies.map(php_writer_1.Expr.convertJsonToPHP).join(", ");
37
- const contents = `<?php return ['dependencies' => [${escapedDependencies}], 'version' => ${php_writer_1.Expr.convertJsonToPHP(assetData.version)}];\n`;
38
- const parsedPath = node_path_1.default.parse(file);
39
- const assetPHPFile = node_path_1.default.join(parsedPath.dir, parsedPath.name) + ".asset.php";
40
- compilation.emitAsset(assetPHPFile, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
41
- }
42
- }
43
- compilation.deleteAsset("assets.json");
44
- });
19
+ attachStandardPhase(compilation) {
20
+ compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
21
+ compilation.deleteAsset("assets.json");
45
22
  });
46
- if (!this.config.useUnifiedLoader) {
47
- return;
48
- }
49
- UnifiedLoaderGenerator.semaphore.register(this.id);
50
- const tapName = { name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT };
51
- compiler.hooks.compilation.tap(this.constructor.name, compilation => {
52
- UnifiedLoaderGenerator.attached = false;
53
- UnifiedLoaderGenerator.semaphore.reset(this.id);
54
- compilation.hooks.processAssets.tapPromise(tapName, async () => {
55
- try {
56
- UnifiedLoaderGenerator.semaphore.resolve(this.id, undefined);
57
- if (!UnifiedLoaderGenerator.attached) {
58
- UnifiedLoaderGenerator.attached = true;
59
- const alreadyAllocatedGroups = new Set();
60
- const writerCallbacks = (await UnifiedLoaderGenerator.semaphore.wait())
61
- .filter((a) => a !== undefined)
62
- .sort((a, b) => {
63
- const ap = a.priority ?? 0, bp = b.priority ?? 0;
64
- return ap === bp ? a.group.localeCompare(b.group) : bp - ap;
65
- })
66
- .filter(a => !alreadyAllocatedGroups.has(a.group) && alreadyAllocatedGroups.add(a.group));
67
- if (writerCallbacks.length > 0) {
68
- compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
69
- const writer = new php_writer_1.PHPWriter();
70
- if (writerCallbacks.some(wc => wc.requiresBaseURI)) {
71
- (0, shared_1.emitResolveBaseUriFunction)(writer);
72
- }
73
- for (const writerCallback of writerCallbacks) {
74
- writerCallback.action(writer);
75
- }
76
- writer.emitAsset(compilation, "unified-loader.php");
77
- });
78
- }
79
- }
23
+ }
24
+ attachUniquePhase(compilation) {
25
+ this.tapWithParsedAssetsJson(compilation, { stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async (parsedAssetsJson) => {
26
+ const groupedLoaderInfo = Object.values((await UnifiedLoaderGenerator.semaphore.wait())
27
+ .reduce((acc, cur) => {
28
+ const accValue = acc[cur.group];
29
+ if (accValue === undefined) {
30
+ acc[cur.group] = { ...cur, priority: cur.priority ?? 0, staticallyLoadedEntrypoints: cur.staticallyLoadedEntrypoints?.length ? [...cur.staticallyLoadedEntrypoints] : [] };
31
+ return acc;
32
+ }
33
+ if (cur.priority && accValue.priority < cur.priority) {
34
+ accValue.priority = cur.priority;
35
+ accValue.action = cur.action;
36
+ accValue.requiresBaseURI = cur.requiresBaseURI;
37
+ }
38
+ else if (cur.requiresBaseURI && !accValue.requiresBaseURI) {
39
+ accValue.requiresBaseURI = cur.requiresBaseURI;
80
40
  }
81
- catch (e) {
82
- UnifiedLoaderGenerator.semaphore.reject(this.id);
83
- throw e;
41
+ if (cur.staticallyLoadedEntrypoints?.length) {
42
+ accValue.staticallyLoadedEntrypoints.push(...cur.staticallyLoadedEntrypoints);
84
43
  }
44
+ return acc;
45
+ }, {}))
46
+ .sort((a, b) => {
47
+ const ap = a.priority ?? 0, bp = b.priority ?? 0;
48
+ return ap === bp ? a.group.localeCompare(b.group) : bp - ap;
85
49
  });
50
+ const staticallyLoadedEntrypoints = new Set(groupedLoaderInfo.flatMap(lig => lig.staticallyLoadedEntrypoints));
51
+ for (const [file, assetData] of Object.entries(parsedAssetsJson)) {
52
+ if (staticallyLoadedEntrypoints.has(file)) {
53
+ continue;
54
+ }
55
+ const parsedPath = node_path_1.default.parse(file);
56
+ const contents = `<?php return ${(0, json_to_php_but_with____injection_1.default)(assetData)};\n`;
57
+ compilation.emitAsset(node_path_1.default.join(parsedPath.dir, parsedPath.name) + ".asset.php", new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
58
+ }
59
+ if (this.config.useUnifiedLoader) {
60
+ compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
61
+ const writer = new php_writer_1.PHPWriter();
62
+ if (groupedLoaderInfo.some(wc => wc.requiresBaseURI)) {
63
+ (0, shared_1.emitResolveBaseUriFunction)(writer);
64
+ }
65
+ for (const { action } of groupedLoaderInfo) {
66
+ action(writer);
67
+ }
68
+ writer.emitAsset(compilation, "unified-loader.php");
69
+ });
70
+ }
86
71
  });
87
72
  }
88
73
  }
@@ -1,4 +1,4 @@
1
- import { AbstractMultiPhaseLibraryAndEntryPlugin } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
1
+ import { AbstractBiPhasicGroupAndEntryPlugin } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
2
  import { type Compiler, type WebpackPluginInstance } from "webpack";
3
3
  export declare class WPMLConfigBuilderPlugin implements WebpackPluginInstance {
4
4
  private readonly destDir;
@@ -7,7 +7,7 @@ export declare class WPMLConfigBuilderPlugin implements WebpackPluginInstance {
7
7
  private static domParser?;
8
8
  private static xmlSerializer?;
9
9
  private readonly parsedDocumentsCache;
10
- constructor(destDir: string, referencePlugin: AbstractMultiPhaseLibraryAndEntryPlugin<any>);
10
+ constructor(destDir: string, referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>);
11
11
  apply(compiler: Compiler): void;
12
12
  private static getJSDOMInstance;
13
13
  private static getDOMParser;
package/build/shared.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { PHPWriter } from "./utils/php-writer";
2
2
  import type { Options as PostcssFunctionsOptions } from "postcss-functions";
3
- import { type Configuration, type EntryOptions, WebpackError } from "webpack";
4
- export type RawAssetData = Record<string, {
3
+ import { Compilation, type Configuration, WebpackError } from "webpack";
4
+ export type ParsedAssetsJson = Record<string, {
5
5
  dependencies: string[];
6
6
  version: string;
7
7
  }>;
8
- export declare function isRawAssetData(thing: any): thing is RawAssetData;
8
+ export declare function isParsedAssetsJson(thing: any): thing is ParsedAssetsJson;
9
9
  type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
10
10
  export type HandleData = {
11
11
  src: string;
@@ -75,23 +75,18 @@ export type PlauditWordpressWebpackConfig = {
75
75
  srcPrefixes?: string[];
76
76
  useUnifiedLoader?: boolean;
77
77
  };
78
- export type SmuggledBlockEntrypointInfo = [
79
- string,
80
- EntrypointFields[number],
81
- string,
82
- string,
83
- string
84
- ];
85
- export type UnpackedBlockEntrypointInfo = {
78
+ export type FileSegmentBlockEntrypointInfo = {
86
79
  blockJsonOrigin: string;
87
80
  entrypointField: EntrypointFields[number];
88
81
  originalValue: string;
89
82
  entrypointName: string;
90
83
  handle: string;
84
+ dest: VerifiedAdvancedOutputConfig;
85
+ };
86
+ export type BlockEntrypointInfo = FileSegmentBlockEntrypointInfo | {
87
+ dest: VerifiedAdvancedOutputConfig;
88
+ purpose: string;
91
89
  };
92
- export declare function packBlockEntrypointInfoForSmuggling(info: UnpackedBlockEntrypointInfo): SmuggledBlockEntrypointInfo;
93
- export declare function unpackSmuggledBlockEntrypointInfo(library: EntryOptions['library'], allowedEndings?: string[] | false): UnpackedBlockEntrypointInfo | undefined;
94
- export declare function isSmuggledLibraryInfo(libraryName: NonNullable<EntryOptions['library']>['name'] | undefined, allowedEndings?: string[] | false): libraryName is SmuggledBlockEntrypointInfo;
95
90
  export declare function convertUsageLocationsHandleToEmittableHandle(handle: UsageLocations['handle'], generatedHandle: string): string;
96
91
  export declare function makeEmittableConfigPHP(data: any, asFullFile: boolean, parentIndent?: string): string;
97
92
  export type EntrypointFields = ["viewScriptModule", "scriptModule"] | ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script"];
@@ -117,4 +112,5 @@ export declare function newWebpackErrorForFile(error: string | ConstructorParame
117
112
  * The primary benefit of emitting a function instead of baking its contents into each function that uses it is that it allows us to avoid recomputing the base uri multiple times
118
113
  */
119
114
  export declare function emitResolveBaseUriFunction(writer: PHPWriter): void;
115
+ export declare function getAssetsJson(compilation: Compilation): ParsedAssetsJson;
120
116
  export {};
package/build/shared.js CHANGED
@@ -4,11 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.styleExtension = exports.scriptWithModuleExtension = exports.scriptWithoutModuleExtension = exports.scriptExtension = exports.entrypointFields = exports.standardLocationNames = void 0;
7
- exports.isRawAssetData = isRawAssetData;
7
+ exports.isParsedAssetsJson = isParsedAssetsJson;
8
8
  exports.determineCurrentSourceType = determineCurrentSourceType;
9
- exports.packBlockEntrypointInfoForSmuggling = packBlockEntrypointInfoForSmuggling;
10
- exports.unpackSmuggledBlockEntrypointInfo = unpackSmuggledBlockEntrypointInfo;
11
- exports.isSmuggledLibraryInfo = isSmuggledLibraryInfo;
12
9
  exports.convertUsageLocationsHandleToEmittableHandle = convertUsageLocationsHandleToEmittableHandle;
13
10
  exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
14
11
  exports.convertEntrypointFieldForAssetType = convertEntrypointFieldForAssetType;
@@ -23,11 +20,12 @@ exports.loadEnvFile = loadEnvFile;
23
20
  exports.parseEnvFile = parseEnvFile;
24
21
  exports.newWebpackErrorForFile = newWebpackErrorForFile;
25
22
  exports.emitResolveBaseUriFunction = emitResolveBaseUriFunction;
23
+ exports.getAssetsJson = getAssetsJson;
26
24
  const promises_1 = __importDefault(require("node:fs/promises"));
27
25
  const json_to_php_but_with____injection_1 = __importDefault(require("./utils/json-to-php-but-with-__-injection"));
28
26
  const php_writer_1 = require("./utils/php-writer");
29
27
  const webpack_1 = require("webpack");
30
- function isRawAssetData(thing) {
28
+ function isParsedAssetsJson(thing) {
31
29
  if (!thing || typeof thing !== 'object') {
32
30
  return false;
33
31
  }
@@ -57,23 +55,6 @@ function determineCurrentSourceType(dest, srcIsDirectory) {
57
55
  return dest.directoryLayout;
58
56
  }
59
57
  }
60
- function packBlockEntrypointInfoForSmuggling(info) {
61
- return [info.blockJsonOrigin, info.entrypointField, info.originalValue, info.entrypointName, info.handle];
62
- }
63
- const defaultAllowedEndings = ["/block.json", "/entrypoints.json", "/package.json"];
64
- function unpackSmuggledBlockEntrypointInfo(library, allowedEndings) {
65
- const libraryName = library?.name;
66
- if (!isSmuggledLibraryInfo(libraryName, allowedEndings)) {
67
- return undefined;
68
- }
69
- return { blockJsonOrigin: libraryName[0], entrypointField: libraryName[1], originalValue: libraryName[2], entrypointName: libraryName[3], handle: libraryName[4] };
70
- }
71
- function isSmuggledLibraryInfo(libraryName, allowedEndings = defaultAllowedEndings) {
72
- if (!Array.isArray(libraryName) || !arrayIsLength(libraryName, 5) || libraryName.some(item => typeof item !== 'string')) {
73
- return false;
74
- }
75
- return (!allowedEndings || allowedEndings.some(s => libraryName[0].endsWith(s))) && exports.entrypointFields.includes(libraryName[1]);
76
- }
77
58
  function convertUsageLocationsHandleToEmittableHandle(handle, generatedHandle) {
78
59
  const emittableHandle = typeof handle === 'string' ? handle : handle?.(generatedHandle) ?? generatedHandle;
79
60
  return emittableHandle.replaceAll("{basename}", generatedHandle);
@@ -110,7 +91,7 @@ function isScriptModuleField(field) {
110
91
  return field.includes("odule");
111
92
  }
112
93
  function hasAtLeastOneItem(list) {
113
- return list.length > 0;
94
+ return list.length > 0 && list[0] !== undefined && list[0] !== null;
114
95
  }
115
96
  function arrayIsLength(arr, length) {
116
97
  return !!arr && arr.length === length;
@@ -160,3 +141,18 @@ function emitResolveBaseUriFunction(writer) {
160
141
  .call("trailingslashit", [php_writer_1.Expr.call("home_url", [path])], { return: true, assignTo: assignmentTarget });
161
142
  }, { returnType: "string", includeExistenceCheck: true });
162
143
  }
144
+ function getAssetsJson(compilation) {
145
+ const asset = compilation.getAsset("assets.json");
146
+ if (!asset) {
147
+ throw new Error("assets.json is unexpectedly missing");
148
+ }
149
+ if (isParsedAssetsJson(asset.info["parsed-assets-json"])) {
150
+ return asset.info["parsed-assets-json"];
151
+ }
152
+ const parsedAssetJson = JSON.parse(asset.source.source().toString('utf-8'));
153
+ if (!isParsedAssetsJson(parsedAssetJson)) {
154
+ throw new Error("assets.json is does not match the RawAssetData format");
155
+ }
156
+ compilation.updateAsset("assets.json", s => s, a => ({ ...a, "parsed-assets-json": parsedAssetJson }));
157
+ return parsedAssetJson;
158
+ }
@@ -1,6 +1,6 @@
1
- import type { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "../plugins/AbstractMultiPhaseLibraryAndEntryPlugin";
1
+ import type { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "../plugins/AbstractBiPhasicGroupAndEntryPlugin";
2
2
  import type { AdditionalDependencyInjectorPlugin } from "../plugins/AdditionalDependencyInjectorPlugin";
3
- import { EntrypointFields, PlauditWordpressWebpackConfig, UnpackedBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
3
+ import { EntrypointFields, PlauditWordpressWebpackConfig, BlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
4
4
  import type { Compiler, Configuration, DynamicEntryPlugin, WebpackPluginInstance } from "webpack";
5
5
  import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
6
6
  export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpressWebpackConfig, 'variables' | 'src' | 'externals'>> & {
@@ -10,7 +10,7 @@ export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpre
10
10
  export type CommonPluginConfig = {
11
11
  plugins: (WebpackPluginInstance | ((this: Compiler, compiler: Compiler) => void))[];
12
12
  removeEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin;
13
- makeAdditionalDependencyInjectorPlugin(referencePlugin: AbstractMultiPhaseLibraryAndEntryPlugin<any>): AdditionalDependencyInjectorPlugin;
13
+ makeAdditionalDependencyInjectorPlugin(referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>): AdditionalDependencyInjectorPlugin;
14
14
  };
15
15
  export type CommonConfigProcessingResult = {
16
16
  entrypointFields: EntrypointFields;
@@ -21,12 +21,12 @@ export type CommonConfigProcessingResult = {
21
21
  };
22
22
  export declare function joinPossiblyAbsolutePaths(...paths: (string | undefined)[]): string;
23
23
  export declare function groupEntrypointsByAssetFile<T>(entrypoints: T[], entrypointNameExtractor: (t: T) => string): Map<string, T[]>;
24
- export type BlockJsonExtensibleEntryObject = ExtensibleEntryObject<UnpackedBlockEntrypointInfo | string>;
24
+ export type BlockJsonExtensibleEntryObject = ExtensibleEntryObject<BlockEntrypointInfo>;
25
25
  export type EntryStaticNormalized = Awaited<ReturnType<ConstructorParameters<typeof DynamicEntryPlugin>[1]>>;
26
26
  export type ExtensibleEntryObject<M> = {
27
27
  [index: string]: Omit<EntryStaticNormalized[string], 'import'> & Required<NonNullable<Pick<EntryStaticNormalized[string], 'import'>>> & {
28
28
  plauditMetadata: M;
29
29
  };
30
30
  };
31
- export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): EntryProvider<UnpackedBlockEntrypointInfo | string>;
32
- export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration, externalize: VerifiedAdvancedOutputConfig['externalize'], plugins: CommonPluginConfig['plugins']): Configuration;
31
+ export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): EntryProvider<BlockEntrypointInfo>;
32
+ export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration, externalize: VerifiedAdvancedOutputConfig['externalize'], plugins: CommonPluginConfig['plugins'], canClean: boolean): Configuration;
@@ -44,7 +44,8 @@ function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
44
44
  entrypointField: shared_1.styleExtension.test(ep) ? 'style' : shared_1.scriptWithModuleExtension.test(ep) ? 'scriptModule' : 'script',
45
45
  originalValue: ep,
46
46
  entrypointName: parsedEntrypoint.name,
47
- handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name)
47
+ handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name),
48
+ dest
48
49
  };
49
50
  return [joinPossiblyAbsolutePaths(dest.destination, node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name),
50
51
  { import: [ep], plauditMetadata: fakeEntrypointInfo }];
@@ -168,7 +169,8 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
168
169
  if (!entrypointNamesWithEffectiveDuplicates[presentEntrypoint.entrypointName]) {
169
170
  return {
170
171
  blockJsonOrigin, ...presentEntrypoint,
171
- handle: `${handlePrefix}/${handleSuffix}`
172
+ handle: `${handlePrefix}/${handleSuffix}`,
173
+ dest
172
174
  };
173
175
  }
174
176
  const baseSuffix = `_${(0, shared_1.isStyleField)(presentEntrypoint.entrypointField) ? "style" : "script"}`;
@@ -184,7 +186,8 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
184
186
  ...presentEntrypoint,
185
187
  entrypointName: deduplicatedEntrypointName,
186
188
  extensionlessExpectedSrc: deduplicatedExtensionlessExpectedSrc,
187
- handle: `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`
189
+ handle: `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`,
190
+ dest
188
191
  };
189
192
  });
190
193
  rawEntrypoints.push(...resolvedBlockEntrypoints
@@ -197,7 +200,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
197
200
  }
198
201
  ];
199
202
  }));
200
- rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: "block-json-inclusion-assurance" }]);
203
+ rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: { purpose: "block-json-inclusion-assurance", dest } }]);
201
204
  wpmlFiles.push(node_path_1.default.join(dir, 'block.json'));
202
205
  }
203
206
  catch (e) {
@@ -251,19 +254,19 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
251
254
  const wpmlEntrypointFiles = allEntrypoints.flatMap(e => e[1]);
252
255
  try {
253
256
  await promises_1.default.access(node_path_1.default.join(srcRoot, "wpml-config.xml"));
254
- currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: "wpml-config-xml" };
257
+ currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: { purpose: "wpml-config-xml", dest } };
255
258
  }
256
259
  catch (e) {
257
260
  // If the wpml-config.xml file does not exist, just "import" the other files that will be used to build the emitted version
258
261
  if (wpmlEntrypointFiles.length) {
259
- currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: "wpml-config-xml" };
262
+ currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: { purpose: "wpml-config-xml", dest } };
260
263
  }
261
264
  }
262
265
  }
263
266
  return currentEntry;
264
267
  };
265
268
  }
266
- function commonMakeWebpackConfig(config, commonConfig, webpackConfig, externalize, plugins) {
269
+ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, externalize, plugins, canClean) {
267
270
  const { variablesFilePath } = config;
268
271
  const { fixedRules, processingModules, updateCurrentVariables } = commonConfig;
269
272
  const outPath = joinPossiblyAbsolutePaths(process.cwd(), config.outputDir);
@@ -327,7 +330,7 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, externaliz
327
330
  chunkFilename: 'webpack-chunks/[id].js',
328
331
  publicPath: publicPath,
329
332
  library: outputLibrary,
330
- clean: false
333
+ clean: canClean ? webpackConfig.output?.clean : false
331
334
  },
332
335
  optimization: {
333
336
  ...webpackConfig.optimization,
@@ -5,7 +5,7 @@ const make = (props = {}) => {
5
5
  const linebreak = props.linebreak ?? '';
6
6
  const indent = props.indent ?? '';
7
7
  const stripSpaces = props.stripSpaces ?? false;
8
- const shortArraySyntax = props.shortArraySyntax ?? false;
8
+ const shortArraySyntax = props.shortArraySyntax ?? true;
9
9
  const arrOpen = shortArraySyntax ? '[' : 'array(';
10
10
  const arrClose = shortArraySyntax ? ']' : ')';
11
11
  const arrow = stripSpaces ? '=>' : ' => ';
@@ -1,12 +1,11 @@
1
1
  export declare class PseudoSemaphore<T> {
2
- private readonly defaultValue;
3
2
  private readonly name;
4
3
  private flagSet;
5
4
  private readonly flags;
6
5
  private readonly debugMode;
7
- constructor(defaultValue: T, name: string);
6
+ constructor(name: string);
8
7
  register(id: string): void;
9
- resolve(id: string, value: T): void;
8
+ resolve(id: string, value: T | undefined): void;
10
9
  reject(id: string): void;
11
10
  reset(id: string): void;
12
11
  private getFlag;
@@ -2,13 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PseudoSemaphore = void 0;
4
4
  class PseudoSemaphore {
5
- defaultValue;
6
5
  name;
7
6
  flagSet = 0;
8
7
  flags = new Map();
9
8
  debugMode = false;
10
- constructor(defaultValue, name) {
11
- this.defaultValue = defaultValue;
9
+ constructor(name) {
12
10
  this.name = name;
13
11
  }
14
12
  register(id) {
@@ -16,7 +14,7 @@ class PseudoSemaphore {
16
14
  throw new Error();
17
15
  }
18
16
  this.initializeFlag(id);
19
- this.resolve(id, this.defaultValue);
17
+ this.resolve(id, undefined);
20
18
  }
21
19
  resolve(id, value) {
22
20
  if (this.debugMode) {
@@ -67,7 +65,13 @@ class PseudoSemaphore {
67
65
  let res;
68
66
  do {
69
67
  currentFlagSet = this.flagSet;
70
- res = await Promise.all(this.flags.values().map(flag => flag[0]));
68
+ if (this.debugMode) {
69
+ console.log("WAITING FOR:", this.name, currentFlagSet);
70
+ }
71
+ res = (await Promise.all(this.flags.values().map(flag => flag[0]))).filter(r => r !== undefined);
72
+ if (this.debugMode) {
73
+ console.log("POSSIBLY FINISHED WAITING FOR:", this.name, currentFlagSet);
74
+ }
71
75
  } while (currentFlagSet !== this.flagSet);
72
76
  return res;
73
77
  }