@plaudit/webpack-extensions 2.64.0 → 2.65.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.
Files changed (32) hide show
  1. package/build/plugins/{AbstractMultiPhaseLibraryAndEntryPlugin.d.ts → AbstractBiPhasicGroupAndEntryPlugin.d.ts} +7 -6
  2. package/build/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +85 -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 +2 -2
  6. package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +3 -3
  7. package/build/plugins/EnhancedDynamicEntryPlugin.js +3 -3
  8. package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +9 -8
  9. package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +103 -93
  10. package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +6 -7
  11. package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +10 -17
  12. package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +6 -7
  13. package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +15 -16
  14. package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +5 -5
  15. package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +7 -6
  16. package/build/plugins/SpecialAssetHandlingPlugin.d.ts +5 -5
  17. package/build/plugins/SpecialAssetHandlingPlugin.js +44 -47
  18. package/build/plugins/UnifiedLoaderGenerator.d.ts +8 -8
  19. package/build/plugins/UnifiedLoaderGenerator.js +54 -69
  20. package/build/plugins/WPMLConfigBuilder.d.ts +2 -2
  21. package/build/shared.d.ts +4 -3
  22. package/build/shared.js +19 -3
  23. package/build/utils/common-config-helpers.d.ts +3 -3
  24. package/build/utils/common-config-helpers.js +2 -2
  25. package/build/utils/json-to-php-but-with-__-injection.js +1 -1
  26. package/build/utils/pseduo-semaphore.d.ts +2 -3
  27. package/build/utils/pseduo-semaphore.js +9 -5
  28. package/build/wordpress-scripts-wrapper.js +13 -7
  29. package/package.json +1 -1
  30. package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.js +0 -113
  31. package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +0 -17
  32. package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +0 -44
@@ -1,21 +1,22 @@
1
- import { RawAssetData } from "../shared";
1
+ import { ParsedAssetsJson } from "../shared";
2
2
  import type { ExtensibleEntryObject, VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
3
3
  import { PseudoSemaphore } from "../utils/pseduo-semaphore";
4
- import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
4
+ import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
5
5
  import { Compilation, Compiler, Entrypoint } from "webpack";
6
6
  export type EntryProvider<M> = () => ExtensibleEntryObject<M> | Promise<ExtensibleEntryObject<M>>;
7
- export declare abstract class AbstractMultiPhaseLibraryAndEntryPlugin<M> extends AbstractMultiPhaseLibraryPlugin {
7
+ export declare abstract class AbstractBiPhasicGroupAndEntryPlugin<M> extends AbstractBiPhasicGroupPlugin {
8
8
  private readonly context;
9
9
  private readonly entry;
10
10
  private static readonly configuredCompilations;
11
11
  private readonly entryMetadataRecord;
12
- protected constructor(config: VerifiedPlauditWordpressWebpackConfig, libraryType: string, semaphores: PseudoSemaphore<any>[], context: string, entry: EntryProvider<M>);
12
+ protected constructor(config: VerifiedPlauditWordpressWebpackConfig, group: string, semaphores: PseudoSemaphore<any>[], context: string, entry: EntryProvider<M>);
13
13
  apply(compiler: Compiler): void;
14
+ protected attachStandardPhase(compilation: Compilation): void;
14
15
  getRelevantEntrypoints(compilation: Compilation): {
15
16
  entrypoint: Entrypoint;
16
17
  srcPath: string;
17
18
  metadata: M;
18
19
  }[];
19
- protected abstract processAssets(compilation: Compilation, rawAssetData: RawAssetData): Promise<void> | void;
20
- protected extractRelevantAssetData(compilation: Compilation, rawAssetData: RawAssetData): RawAssetData;
20
+ protected abstract processAssets(compilation: Compilation, parsedAssetsJson: ParsedAssetsJson): Promise<void> | void;
21
+ protected extractRelevantAssetData(compilation: Compilation, parsedAssetsJson: ParsedAssetsJson): ParsedAssetsJson;
21
22
  }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractBiPhasicGroupAndEntryPlugin = void 0;
4
+ const shared_1 = require("../shared");
5
+ const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
6
+ const webpack_1 = require("webpack");
7
+ class AbstractBiPhasicGroupAndEntryPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
8
+ context;
9
+ entry;
10
+ static configuredCompilations = new WeakSet();
11
+ entryMetadataRecord = {};
12
+ constructor(config, group, semaphores, context, entry) {
13
+ super(config, group, semaphores);
14
+ this.context = context;
15
+ this.entry = entry;
16
+ }
17
+ apply(compiler) {
18
+ super.apply(compiler);
19
+ compiler.hooks.compilation.tap(this.constructor.name, (compilation, { normalModuleFactory }) => {
20
+ if (!AbstractBiPhasicGroupAndEntryPlugin.configuredCompilations.has(compilation)) {
21
+ AbstractBiPhasicGroupAndEntryPlugin.configuredCompilations.add(compilation);
22
+ const dummyEntry = webpack_1.EntryPlugin.createDependency("", "");
23
+ compilation.dependencyFactories.set(dummyEntry.constructor, normalModuleFactory);
24
+ }
25
+ });
26
+ compiler.hooks.make.tapPromise(this.constructor.name, async (compilation) => {
27
+ const entry = await this.entry();
28
+ const promises = [];
29
+ for (const [name, { plauditMetadata, ...desc }] of Object.entries(entry)) {
30
+ const options = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, name, desc);
31
+ this.entryMetadataRecord[name] = plauditMetadata;
32
+ for (const entry of desc.import) {
33
+ promises.push(new Promise((resolve, reject) => {
34
+ compilation.addEntry(this.context, webpack_1.EntryPlugin.createDependency(entry, options), options, err => {
35
+ if (err) {
36
+ return reject(err);
37
+ }
38
+ resolve();
39
+ });
40
+ }));
41
+ }
42
+ }
43
+ await Promise.all(promises);
44
+ });
45
+ }
46
+ attachStandardPhase(compilation) {
47
+ this.tapWithParsedAssetsJson(compilation, async (parsedAssetsJson) => {
48
+ await this.processAssets(compilation, parsedAssetsJson);
49
+ });
50
+ }
51
+ getRelevantEntrypoints(compilation) {
52
+ return compilation.entrypoints.values()
53
+ .map(entrypoint => {
54
+ const name = entrypoint.name;
55
+ if (!name) {
56
+ return undefined;
57
+ }
58
+ const metadata = this.entryMetadataRecord[name];
59
+ if (metadata === undefined) {
60
+ return undefined;
61
+ }
62
+ const srcPath = entrypoint.origins[0]?.request;
63
+ if (!srcPath) {
64
+ return undefined;
65
+ }
66
+ return { entrypoint, srcPath, metadata };
67
+ })
68
+ .filter(item => item !== undefined)
69
+ .toArray();
70
+ }
71
+ extractRelevantAssetData(compilation, parsedAssetsJson) {
72
+ const relevantAssetData = {};
73
+ const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
74
+ for (const { entrypoint, srcPath } of relevantEntrypoints) {
75
+ const fileWithAssetData = entrypoint.getEntrypointChunk().files.values().find(file => parsedAssetsJson[file]);
76
+ if (!fileWithAssetData) {
77
+ compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
78
+ continue;
79
+ }
80
+ relevantAssetData[fileWithAssetData] = parsedAssetsJson[fileWithAssetData];
81
+ }
82
+ return relevantAssetData;
83
+ }
84
+ }
85
+ exports.AbstractBiPhasicGroupAndEntryPlugin = AbstractBiPhasicGroupAndEntryPlugin;
@@ -0,0 +1,33 @@
1
+ import { Compilation, Compiler, type WebpackPluginInstance } from "webpack";
2
+ import { PseudoSemaphore } from "../utils/pseduo-semaphore";
3
+ import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
+ import { ParsedAssetsJson } from "../shared";
5
+ type TapWithAssetsJsonOptions = {
6
+ name?: string;
7
+ stage?: (typeof Compilation.PROCESS_ASSETS_STAGE_REPORT) | (typeof Compilation.PROCESS_ASSETS_STAGE_ANALYSE);
8
+ additionalAssets?: any;
9
+ };
10
+ type TapWithAssetsJsonFn = Parameters<Compilation['hooks']['processAssets']['tapPromise']>[1];
11
+ type TapWithParsedAssetsJsonFn = (parsedAssetsJson: ParsedAssetsJson, assets: Parameters<TapWithAssetsJsonFn>[0]) => Promise<void> | void;
12
+ export declare abstract class AbstractBiPhasicGroupPlugin implements WebpackPluginInstance {
13
+ protected readonly config: VerifiedPlauditWordpressWebpackConfig;
14
+ readonly group: string;
15
+ private readonly semaphores;
16
+ protected static readonly uniquePhaseAttached: {
17
+ [key in string]: any;
18
+ };
19
+ protected readonly id: string;
20
+ protected constructor(config: VerifiedPlauditWordpressWebpackConfig, group: string, semaphores: PseudoSemaphore<any>[]);
21
+ apply(compiler: Compiler): void;
22
+ protected resetSemaphores(): void;
23
+ protected rejectSemaphores(): void;
24
+ protected abstract attachStandardPhase(compilation: Compilation): void;
25
+ protected abstract attachUniquePhase(compilation: Compilation): void;
26
+ protected tapRequiringAssetsJson(compilation: Compilation, fnOrOptions: TapWithAssetsJsonFn): void;
27
+ protected tapRequiringAssetsJson(compilation: Compilation, fnOrOptions: TapWithAssetsJsonOptions, fnIfOptions: TapWithAssetsJsonFn): void;
28
+ protected tapWithParsedAssetsJson(compilation: Compilation, fnOrOptions: TapWithParsedAssetsJsonFn): void;
29
+ protected tapWithParsedAssetsJson(compilation: Compilation, fnOrOptions: TapWithAssetsJsonOptions, fnIfOptions: TapWithParsedAssetsJsonFn): void;
30
+ private sharedTapLogicForAssetsJsonHelpers;
31
+ private extractTapAndFunction;
32
+ }
33
+ export {};
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractBiPhasicGroupPlugin = void 0;
4
+ const webpack_1 = require("webpack");
5
+ const shared_1 = require("../shared");
6
+ class AbstractBiPhasicGroupPlugin {
7
+ config;
8
+ group;
9
+ semaphores;
10
+ static uniquePhaseAttached = {};
11
+ id;
12
+ constructor(config, group, semaphores) {
13
+ this.config = config;
14
+ this.group = group;
15
+ this.semaphores = semaphores;
16
+ this.id = Math.random().toString();
17
+ }
18
+ apply(compiler) {
19
+ webpack_1.library.EnableLibraryPlugin.setEnabled(compiler, this.group);
20
+ for (const semaphore of this.semaphores) {
21
+ semaphore.register(this.id);
22
+ }
23
+ compiler.hooks.compilation.tap(this.constructor.name, compilation => {
24
+ AbstractBiPhasicGroupPlugin.uniquePhaseAttached[this.group] = false;
25
+ this.resetSemaphores();
26
+ compilation.hooks.beforeChunkIds.tap(this.constructor.name, () => {
27
+ if (!AbstractBiPhasicGroupPlugin.uniquePhaseAttached[this.group]) {
28
+ AbstractBiPhasicGroupPlugin.uniquePhaseAttached[this.group] = this;
29
+ this.attachUniquePhase(compilation);
30
+ }
31
+ });
32
+ this.attachStandardPhase(compilation);
33
+ });
34
+ }
35
+ resetSemaphores() {
36
+ for (const semaphore of this.semaphores) {
37
+ semaphore.reset(this.id);
38
+ }
39
+ }
40
+ rejectSemaphores() {
41
+ for (const semaphore of this.semaphores) {
42
+ semaphore.reject(this.id);
43
+ }
44
+ }
45
+ tapRequiringAssetsJson(compilation, fnOrOptions, fnIfOptions) {
46
+ this.sharedTapLogicForAssetsJsonHelpers(compilation, this.extractTapAndFunction(fnOrOptions, fnIfOptions));
47
+ }
48
+ tapWithParsedAssetsJson(compilation, fnOrOptions, fnIfOptions) {
49
+ const { tap, earlyStage, fn } = this.extractTapAndFunction(fnOrOptions, fnIfOptions);
50
+ this.sharedTapLogicForAssetsJsonHelpers(compilation, { tap, earlyStage, fn: async (assets) => {
51
+ try {
52
+ await fn((0, shared_1.getAssetsJson)(compilation), assets);
53
+ }
54
+ catch (e) {
55
+ console.error(e);
56
+ this.rejectSemaphores();
57
+ if (e instanceof Error) {
58
+ compilation.errors.push(e);
59
+ }
60
+ else {
61
+ throw e;
62
+ }
63
+ }
64
+ } });
65
+ }
66
+ sharedTapLogicForAssetsJsonHelpers(compilation, { tap, earlyStage, fn }) {
67
+ compilation.hooks.processAssets.tapPromise({ ...tap, additionalAssets: true }, async (assets, ...args) => {
68
+ if (!earlyStage || "assets.json" in assets) {
69
+ await fn(assets, ...args);
70
+ }
71
+ });
72
+ }
73
+ extractTapAndFunction(fnOrOptions, fnIfOptions) {
74
+ let tap = { name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE };
75
+ let fn;
76
+ if (typeof fnOrOptions === 'function') {
77
+ fn = fnOrOptions;
78
+ }
79
+ else if (!fnIfOptions) {
80
+ throw new Error("Somehow reached an impossible state. Make sure that you're using TypeScript.");
81
+ }
82
+ else {
83
+ tap = { ...tap, ...fnOrOptions };
84
+ fn = fnIfOptions;
85
+ }
86
+ const earlyStage = tap.stage === webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE;
87
+ if (earlyStage && tap.additionalAssets === undefined) {
88
+ tap.additionalAssets = true;
89
+ }
90
+ return { tap, earlyStage, fn };
91
+ }
92
+ }
93
+ exports.AbstractBiPhasicGroupPlugin = AbstractBiPhasicGroupPlugin;
@@ -1,10 +1,10 @@
1
1
  import { type Compiler, type WebpackPluginInstance } from "webpack";
2
- import { AbstractMultiPhaseLibraryAndEntryPlugin } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
2
+ import { AbstractBiPhasicGroupAndEntryPlugin } from "./AbstractBiPhasicGroupAndEntryPlugin";
3
3
  export declare class AdditionalDependencyInjectorPlugin implements WebpackPluginInstance {
4
4
  private readonly entrypointAdditionalDependencies;
5
5
  private readonly processingModules;
6
6
  private readonly addExternalizedDep;
7
7
  private readonly referencePlugin;
8
- constructor(entrypointAdditionalDependencies: string[], processingModules: boolean, addExternalizedDep: (dep: string) => void, referencePlugin: AbstractMultiPhaseLibraryAndEntryPlugin<any>);
8
+ constructor(entrypointAdditionalDependencies: string[], processingModules: boolean, addExternalizedDep: (dep: string) => void, referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>);
9
9
  apply(compiler: Compiler): void;
10
10
  }
@@ -1,8 +1,8 @@
1
- import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
1
+ import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
2
  import type { UnpackedBlockEntrypointInfo } from "../shared";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
- export declare class EnhancedDynamicEntryPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
4
+ export declare class EnhancedDynamicEntryPlugin extends AbstractBiPhasicGroupAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
5
5
  constructor(config: VerifiedPlauditWordpressWebpackConfig, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
6
- protected attachSecondPhase(): void;
6
+ protected attachUniquePhase(): void;
7
7
  protected processAssets(): void;
8
8
  }
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EnhancedDynamicEntryPlugin = void 0;
4
- const AbstractMultiPhaseLibraryAndEntryPlugin_1 = require("./AbstractMultiPhaseLibraryAndEntryPlugin");
5
- class EnhancedDynamicEntryPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin_1.AbstractMultiPhaseLibraryAndEntryPlugin {
4
+ const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
5
+ class EnhancedDynamicEntryPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
6
6
  constructor(config, context, entry) {
7
7
  super(config, `enhanced-dynamic-entries`, [], context, entry);
8
8
  }
9
- attachSecondPhase() { }
9
+ attachUniquePhase() { }
10
10
  processAssets() { }
11
11
  }
12
12
  exports.EnhancedDynamicEntryPlugin = EnhancedDynamicEntryPlugin;
@@ -1,15 +1,16 @@
1
- import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
2
- import { RawAssetData, VerifiedAdvancedOutputConfig } from "../shared";
1
+ import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
+ import { ParsedAssetsJson, VerifiedAdvancedOutputConfig } from "../shared";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
4
  import { Compilation, type Compiler } from "webpack";
5
- export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin<string> {
6
- private readonly extensionsPath;
5
+ export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<string> {
6
+ private readonly extensionsSrcPath;
7
7
  private readonly dest;
8
8
  private static readonly semaphore;
9
- private static readonly perLibraryTypeSetupFilePaths;
10
- constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider<string>);
9
+ private setupFiles;
10
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsSrcPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider<string>);
11
+ get extensionsDestPath(): string;
11
12
  apply(compiler: Compiler): void;
12
13
  private generateVersionTwoConfigFile;
13
- protected attachSecondPhase(compilation: Compilation): void;
14
- protected processAssets(compilation: Compilation, rawAssetData: RawAssetData): void;
14
+ protected attachUniquePhase(compilation: Compilation): void;
15
+ protected processAssets(compilation: Compilation, rawAssetData: ParsedAssetsJson): void;
15
16
  }
@@ -6,32 +6,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ExtensionsConfigFileGeneratorPlugin = void 0;
7
7
  const promises_1 = __importDefault(require("node:fs/promises"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
- const AbstractMultiPhaseLibraryAndEntryPlugin_1 = require("./AbstractMultiPhaseLibraryAndEntryPlugin");
9
+ const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
10
10
  const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
11
11
  const shared_1 = require("../shared");
12
12
  const php_writer_1 = require("../utils/php-writer");
13
13
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
14
14
  const webpack_1 = require("webpack");
15
- class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin_1.AbstractMultiPhaseLibraryAndEntryPlugin {
16
- extensionsPath;
15
+ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
16
+ extensionsSrcPath;
17
17
  dest;
18
- static semaphore = new pseduo_semaphore_1.PseudoSemaphore({ libraryType: "", assets: [], setupFiles: [] }, "Extensions");
19
- static perLibraryTypeSetupFilePaths = {};
20
- constructor(config, extensionsPath, dest, context, entry) {
18
+ static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Extensions");
19
+ setupFiles = [];
20
+ constructor(config, extensionsSrcPath, dest, context, entry) {
21
21
  super(config, `extensions-v2-${dest.destination}`, [ExtensionsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
22
- this.extensionsPath = extensionsPath;
22
+ this.extensionsSrcPath = extensionsSrcPath;
23
23
  this.dest = dest;
24
24
  }
25
+ get extensionsDestPath() {
26
+ let extensionsDestPath = this.dest.destination.endsWith("/") ? this.dest.destination : this.dest.destination + "/";
27
+ return !extensionsDestPath.startsWith("/") ? "/" + extensionsDestPath : extensionsDestPath;
28
+ }
25
29
  apply(compiler) {
26
30
  super.apply(compiler);
27
31
  compiler.hooks.make.tapPromise(this.constructor.name, async (compilation) => {
28
- if (!compilation.contextDependencies.has(this.extensionsPath)) {
29
- compilation.contextDependencies.add(this.extensionsPath);
32
+ if (!compilation.contextDependencies.has(this.extensionsSrcPath)) {
33
+ compilation.contextDependencies.add(this.extensionsSrcPath);
30
34
  }
31
35
  const emissionPromises = [];
32
- for await (const { name: setupFilePath } of await promises_1.default.opendir(this.extensionsPath, { encoding: 'utf-8' })) {
36
+ for await (const { name: setupFilePath } of await promises_1.default.opendir(this.extensionsSrcPath, { encoding: 'utf-8' })) {
33
37
  if (setupFilePath.endsWith("-setup.php")) {
34
- const setupFileSourcePath = node_path_1.default.join(this.extensionsPath, setupFilePath);
38
+ const setupFileSourcePath = node_path_1.default.join(this.extensionsSrcPath, setupFilePath);
35
39
  compilation.fileDependencies.add(setupFileSourcePath);
36
40
  emissionPromises.push(promises_1.default.readFile(setupFileSourcePath).then(contents => {
37
41
  compilation.emitAsset(node_path_1.default.join(this.dest.destination, setupFilePath), new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
@@ -40,47 +44,45 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEn
40
44
  }));
41
45
  }
42
46
  }
43
- ExtensionsConfigFileGeneratorPlugin.perLibraryTypeSetupFilePaths[this.libraryType] = (await Promise.all(emissionPromises))
47
+ this.setupFiles = (await Promise.all(emissionPromises))
44
48
  .filter((item) => item[0] !== undefined).sort((a, b) => a[0].localeCompare(b[0]));
45
49
  });
46
50
  }
47
- generateVersionTwoConfigFile(compilation, combinedExtensionData) {
51
+ generateVersionTwoConfigFile(compilation, relevantAssetData, setupFilePaths) {
48
52
  const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
49
53
  const blockExtensionsConfig = {
50
54
  metadata: { version: this.config.extensionsVersion }, scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {}
51
55
  };
52
- for (const assetDataSource of combinedExtensionData.assets) {
53
- const normalizedAssetData = Object.entries(assetDataSource)
54
- .map(entry => {
55
- const assetPath = this.dest.destination && entry[0].startsWith(this.dest.destination + "/")
56
- ? entry[0].substring(this.dest.destination.length + 1) : entry[0];
57
- return [assetPath, entry[1]];
58
- });
59
- for (const [assetPath, assetData] of normalizedAssetData) {
60
- const match = regex.exec(assetPath);
61
- if (!match) {
62
- continue;
63
- }
64
- const blockSlug = match[1], assetType = match[2];
65
- if (blockSlug && assetType) {
66
- const key = assetType.replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
67
- const handle = `plaudit_block-extension_${blockSlug}-${assetType}`;
68
- const isCss = (0, shared_1.isStyleField)(assetType);
69
- const handleGroup = isCss ? 'styleHandles'
70
- : ((0, shared_1.isScriptModuleField)(assetType) ? 'scriptModuleHandles' : 'scriptHandles');
71
- blockExtensionsConfig[handleGroup][handle] = {
72
- src: isCss ? assetPath.replace(/\.js$/, ".css") : assetPath,
73
- rest: isCss || key.startsWith("editor")
74
- ? [assetData.dependencies, assetData.version]
75
- : [assetData.dependencies, assetData.version, { strategy: 'defer' }]
76
- };
77
- (blockExtensionsConfig.blocks[blockSlug] ?? (blockExtensionsConfig.blocks[blockSlug] = {}))[key] = handle;
78
- }
56
+ const normalizedAssetData = Object.entries(relevantAssetData)
57
+ .map(entry => {
58
+ const assetPath = this.dest.destination && entry[0].startsWith(this.dest.destination + "/")
59
+ ? entry[0].substring(this.dest.destination.length + 1) : entry[0];
60
+ return [assetPath, entry[1]];
61
+ });
62
+ for (const [assetPath, assetData] of normalizedAssetData) {
63
+ const match = regex.exec(assetPath);
64
+ if (!match) {
65
+ continue;
79
66
  }
80
- for (const [blockSlug, asset] of combinedExtensionData.setupFiles) {
81
- blockExtensionsConfig.setupFiles[blockSlug] = asset;
67
+ const blockSlug = match[1], assetType = match[2];
68
+ if (blockSlug && assetType) {
69
+ const key = assetType.replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
70
+ const handle = `plaudit_block-extension_${blockSlug}-${assetType}`;
71
+ const isCss = (0, shared_1.isStyleField)(assetType);
72
+ const handleGroup = isCss ? 'styleHandles'
73
+ : ((0, shared_1.isScriptModuleField)(assetType) ? 'scriptModuleHandles' : 'scriptHandles');
74
+ blockExtensionsConfig[handleGroup][handle] = {
75
+ src: isCss ? assetPath.replace(/\.js$/, ".css") : assetPath,
76
+ rest: isCss || key.startsWith("editor")
77
+ ? [assetData.dependencies, assetData.version]
78
+ : [assetData.dependencies, assetData.version, { strategy: 'defer' }]
79
+ };
80
+ (blockExtensionsConfig.blocks[blockSlug] ?? (blockExtensionsConfig.blocks[blockSlug] = {}))[key] = handle;
82
81
  }
83
82
  }
83
+ for (const [blockSlug, asset] of setupFilePaths) {
84
+ blockExtensionsConfig.setupFiles[blockSlug] = asset;
85
+ }
84
86
  blockExtensionsConfig.scriptHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptHandles)
85
87
  .toSorted(([a], [b]) => a.localeCompare(b)));
86
88
  blockExtensionsConfig.scriptModuleHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptModuleHandles)
@@ -96,63 +98,71 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEn
96
98
  .toSorted(([a], [b]) => a.localeCompare(b)));
97
99
  compilation.emitAsset(node_path_1.default.join(this.dest.destination, "mapping.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, true)));
98
100
  }
99
- attachSecondPhase(compilation) {
100
- compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_GenerateConfigFile`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
101
- const combinedExtensionData = (await ExtensionsConfigFileGeneratorPlugin.semaphore.wait())
102
- .reduce((main, { assets, setupFiles }) => {
103
- main.assets.push(...assets);
104
- main.setupFiles.push(...setupFiles);
105
- return main;
106
- }, { assets: [], setupFiles: [], libraryType: "" });
107
- if (combinedExtensionData.assets.length > 0 || combinedExtensionData.setupFiles.length > 0 || !this.config.useUnifiedLoader) {
108
- this.generateVersionTwoConfigFile(compilation, combinedExtensionData);
101
+ attachUniquePhase(compilation) {
102
+ compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
103
+ const plugins = Object.values((await ExtensionsConfigFileGeneratorPlugin.semaphore.wait())
104
+ .reduce((acc, cur) => {
105
+ const accValue = acc[cur.plugin.group];
106
+ if (accValue === undefined) {
107
+ acc[cur.plugin.group] = { ...cur, setupFiles: cur.setupFiles?.length ? [...cur.setupFiles] : [] };
108
+ return acc;
109
+ }
110
+ if (cur.relevantAssetData) {
111
+ accValue.relevantAssetData = { ...accValue.relevantAssetData, ...cur.relevantAssetData };
112
+ }
113
+ if (cur.setupFiles?.length) {
114
+ accValue.setupFiles.push(...cur.setupFiles);
115
+ }
116
+ return acc;
117
+ }, {}))
118
+ .sort((a, b) => a.plugin.group.localeCompare(b.plugin.group));
119
+ for (const { plugin, relevantAssetData, setupFiles } of plugins) {
120
+ plugin.generateVersionTwoConfigFile(compilation, relevantAssetData, setupFiles);
109
121
  }
110
122
  });
111
123
  }
112
124
  processAssets(compilation, rawAssetData) {
113
- const myCacheData = { libraryType: this.libraryType, assets: [],
114
- setupFiles: ExtensionsConfigFileGeneratorPlugin.perLibraryTypeSetupFilePaths[this.libraryType] ?? [] };
115
- myCacheData.assets.push(this.extractRelevantAssetData(compilation, rawAssetData));
116
- ExtensionsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myCacheData);
117
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myCacheData.setupFiles.length > 0 || myCacheData.assets.length > 0 ? {
118
- group: this.libraryType,
119
- requiresBaseURI: true,
120
- action: writer => {
121
- const generateLoader = (writer) => {
122
- let finalExtensionsDest = this.dest.destination.endsWith("/") ? this.dest.destination : this.dest.destination + "/";
123
- if (!finalExtensionsDest.startsWith("/")) {
124
- finalExtensionsDest = "/" + finalExtensionsDest;
125
- }
126
- const filePathPrefixVar = new php_writer_1.Var("filePathPrefix");
127
- const fileUriPrefixVar = new php_writer_1.Var("fileUriPrefix");
128
- writer
129
- .assign(filePathPrefixVar, new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest)}`))
130
- .call("plaudit_webpack_extensions__resolve_base_uri", [filePathPrefixVar], { assignTo: fileUriPrefixVar })
131
- .call("GutenbergUtils::loadExtensionsV2", [
132
- new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest + "mapping.config.php")}`),
133
- filePathPrefixVar, fileUriPrefixVar,
134
- `${this.config.plainEntrypointsHandlePrefix || node_path_1.default.basename(process.cwd())}_extension_`
135
- ]);
136
- };
137
- writer.use("Plaudit\\Common\\Lib\\GutenbergUtils");
138
- const potentialHandle = this.dest.locations?.handle;
139
- if (potentialHandle) {
140
- if (typeof potentialHandle === 'string') {
141
- try {
142
- writer.function(potentialHandle, [], generateLoader, { returnType: 'void' });
143
- return;
144
- }
145
- catch (e) {
146
- compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for dynamically loading extensions", { cause: e }], this.extensionsPath));
147
- }
148
- }
149
- else {
150
- compilation.errors.push(new Error("The extensions directoryLayout's handle support is limited to static strings"));
151
- }
125
+ const relevantAssetData = this.extractRelevantAssetData(compilation, rawAssetData);
126
+ const staticallyLoadedEntrypoints = Object.keys(relevantAssetData);
127
+ const generateLoader = (writer) => {
128
+ const filePathPrefixVar = new php_writer_1.Var("filePathPrefix");
129
+ const fileUriPrefixVar = new php_writer_1.Var("fileUriPrefix");
130
+ writer
131
+ .assign(filePathPrefixVar, new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(this.extensionsDestPath)}`))
132
+ .call("plaudit_webpack_extensions__resolve_base_uri", [filePathPrefixVar], { assignTo: fileUriPrefixVar })
133
+ .call("GutenbergUtils::loadExtensionsV2", [
134
+ new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(this.extensionsDestPath + "mapping.config.php")}`),
135
+ filePathPrefixVar, fileUriPrefixVar,
136
+ `${this.config.plainEntrypointsHandlePrefix || node_path_1.default.basename(process.cwd())}_extension_`
137
+ ]);
138
+ };
139
+ let action;
140
+ const potentialHandle = this.dest.locations?.handle;
141
+ if (potentialHandle) {
142
+ if (typeof potentialHandle === 'string') {
143
+ try {
144
+ action = writer => writer.use("Plaudit\\Common\\Lib\\GutenbergUtils").function(potentialHandle, [], generateLoader, { returnType: 'void' });
145
+ }
146
+ catch (e) {
147
+ compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for dynamically loading extensions", { cause: e }], this.extensionsSrcPath));
148
+ this.rejectSemaphores();
149
+ return;
152
150
  }
153
- writer.withScope(generateLoader);
154
151
  }
155
- } : undefined);
152
+ else {
153
+ compilation.errors.push(new Error("The extensions directoryLayout's handle support is limited to static strings"));
154
+ this.rejectSemaphores();
155
+ return;
156
+ }
157
+ }
158
+ else {
159
+ action = writer => writer.use("Plaudit\\Common\\Lib\\GutenbergUtils").withScope(generateLoader);
160
+ }
161
+ const myCacheData = { plugin: this, setupFiles: this.setupFiles, relevantAssetData };
162
+ ExtensionsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myCacheData);
163
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, this.setupFiles.length > 0 || staticallyLoadedEntrypoints.length > 0
164
+ ? { group: this.group, requiresBaseURI: true, action, staticallyLoadedEntrypoints }
165
+ : undefined);
156
166
  }
157
167
  }
158
168
  exports.ExtensionsConfigFileGeneratorPlugin = ExtensionsConfigFileGeneratorPlugin;
@@ -1,11 +1,10 @@
1
- import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
2
- import { RawAssetData } from "../shared";
1
+ import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
+ import type { ParsedAssetsJson } from "../shared";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
- import { Compilation, type Compiler } from "webpack";
5
- export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryAndEntryPlugin<string> {
4
+ import { Compilation } from "webpack";
5
+ export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin<string> {
6
6
  private readonly extensionsDest;
7
7
  constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsDest: string, context: string, entry: EntryProvider<string>);
8
- apply(compiler: Compiler): void;
9
- protected attachSecondPhase(): void;
10
- protected processAssets(compilation: Compilation, rawAssetData: RawAssetData): void;
8
+ protected attachUniquePhase(): void;
9
+ protected processAssets(compilation: Compilation, assetsJson: ParsedAssetsJson): void;
11
10
  }