@plaudit/webpack-extensions 2.63.2 → 2.64.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 (26) hide show
  1. package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.d.ts +8 -6
  2. package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.js +53 -2
  3. package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +4 -1
  4. package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +8 -1
  5. package/build/plugins/AdditionalDependencyInjectorPlugin.d.ts +3 -1
  6. package/build/plugins/AdditionalDependencyInjectorPlugin.js +5 -3
  7. package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +8 -0
  8. package/build/plugins/EnhancedDynamicEntryPlugin.js +12 -0
  9. package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +4 -4
  10. package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +46 -90
  11. package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +7 -4
  12. package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +18 -21
  13. package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +5 -4
  14. package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +45 -75
  15. package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +3 -4
  16. package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +72 -102
  17. package/build/plugins/SpecialAssetHandlingPlugin.d.ts +0 -1
  18. package/build/plugins/SpecialAssetHandlingPlugin.js +2 -5
  19. package/build/plugins/UnifiedLoaderGenerator.js +28 -0
  20. package/build/plugins/WPMLConfigBuilder.d.ts +3 -1
  21. package/build/plugins/WPMLConfigBuilder.js +7 -4
  22. package/build/shared.d.ts +3 -2
  23. package/build/utils/common-config-helpers.d.ts +5 -3
  24. package/build/utils/common-config-helpers.js +9 -30
  25. package/build/wordpress-scripts-wrapper.js +106 -102
  26. package/package.json +1 -2
@@ -1,19 +1,21 @@
1
+ import { RawAssetData } from "../shared";
2
+ import type { ExtensibleEntryObject, VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
1
3
  import { PseudoSemaphore } from "../utils/pseduo-semaphore";
2
- import type { ExtensibleEntryObject } from "../utils/common-config-helpers";
3
4
  import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
4
5
  import { Compilation, Compiler, Entrypoint } from "webpack";
5
6
  export type EntryProvider<M> = () => ExtensibleEntryObject<M> | Promise<ExtensibleEntryObject<M>>;
6
7
  export declare abstract class AbstractMultiPhaseLibraryAndEntryPlugin<M> extends AbstractMultiPhaseLibraryPlugin {
7
8
  private readonly context;
8
9
  private readonly entry;
9
- protected readonly entryMetadataRecord: {
10
- [entryName: string]: M;
11
- };
12
- protected constructor(libraryType: string, semaphores: PseudoSemaphore<any>[], context: string, entry: EntryProvider<M>);
10
+ private static readonly configuredCompilations;
11
+ private readonly entryMetadataRecord;
12
+ protected constructor(config: VerifiedPlauditWordpressWebpackConfig, libraryType: string, semaphores: PseudoSemaphore<any>[], context: string, entry: EntryProvider<M>);
13
13
  apply(compiler: Compiler): void;
14
- protected getRelevantEntrypoints(compilation: Compilation): {
14
+ getRelevantEntrypoints(compilation: Compilation): {
15
15
  entrypoint: Entrypoint;
16
16
  srcPath: string;
17
17
  metadata: M;
18
18
  }[];
19
+ protected abstract processAssets(compilation: Compilation, rawAssetData: RawAssetData): Promise<void> | void;
20
+ protected extractRelevantAssetData(compilation: Compilation, rawAssetData: RawAssetData): RawAssetData;
19
21
  }
@@ -1,20 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractMultiPhaseLibraryAndEntryPlugin = void 0;
4
+ const shared_1 = require("../shared");
4
5
  const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
5
6
  const webpack_1 = require("webpack");
6
7
  class AbstractMultiPhaseLibraryAndEntryPlugin extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
7
8
  context;
8
9
  entry;
10
+ static configuredCompilations = new WeakSet();
9
11
  entryMetadataRecord = {};
10
- constructor(libraryType, semaphores, context, entry) {
11
- super(libraryType, semaphores);
12
+ constructor(config, libraryType, semaphores, context, entry) {
13
+ super(config, libraryType, semaphores);
12
14
  this.context = context;
13
15
  this.entry = entry;
14
16
  }
15
17
  apply(compiler) {
16
18
  super.apply(compiler);
17
19
  compiler.hooks.compilation.tap(this.constructor.name, (compilation, { normalModuleFactory }) => {
20
+ if (AbstractMultiPhaseLibraryAndEntryPlugin.configuredCompilations.has(compilation)) {
21
+ return;
22
+ }
23
+ AbstractMultiPhaseLibraryAndEntryPlugin.configuredCompilations.add(compilation);
18
24
  const dummyEntry = webpack_1.EntryPlugin.createDependency("", "");
19
25
  compilation.dependencyFactories.set(dummyEntry.constructor, normalModuleFactory);
20
26
  });
@@ -37,6 +43,38 @@ class AbstractMultiPhaseLibraryAndEntryPlugin extends AbstractMultiPhaseLibraryP
37
43
  }
38
44
  await Promise.all(promises);
39
45
  });
46
+ compiler.hooks.compilation.tap(this.constructor.name, compilation => {
47
+ compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, additionalAssets: true }, async (assets) => {
48
+ if (!("assets.json" in assets)) {
49
+ return;
50
+ }
51
+ try {
52
+ //TODO: It should be possible to use EntryPoints to determine the "original" file
53
+ //TODO: There is no reason to not use basically the exact same logic to implement support for this in plain file contexts
54
+ const rawAssetDataSource = assets["assets.json"]?.source();
55
+ if (typeof rawAssetDataSource !== 'string') {
56
+ this.rejectSemaphores();
57
+ compilation.errors.push(new Error("assets.json is unexpectedly missing or not a string"));
58
+ return;
59
+ }
60
+ const rawAssetData = JSON.parse(rawAssetDataSource);
61
+ if (!(0, shared_1.isRawAssetData)(rawAssetData)) {
62
+ this.rejectSemaphores();
63
+ compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
64
+ return;
65
+ }
66
+ await this.processAssets(compilation, rawAssetData);
67
+ }
68
+ catch (e) {
69
+ this.rejectSemaphores();
70
+ if (e instanceof Error) {
71
+ compilation.errors.push(e);
72
+ return;
73
+ }
74
+ throw e;
75
+ }
76
+ });
77
+ });
40
78
  }
41
79
  getRelevantEntrypoints(compilation) {
42
80
  return compilation.entrypoints.values()
@@ -58,5 +96,18 @@ class AbstractMultiPhaseLibraryAndEntryPlugin extends AbstractMultiPhaseLibraryP
58
96
  .filter(item => item !== undefined)
59
97
  .toArray();
60
98
  }
99
+ extractRelevantAssetData(compilation, rawAssetData) {
100
+ const relevantAssetData = {};
101
+ const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
102
+ for (const { entrypoint, srcPath } of relevantEntrypoints) {
103
+ const fileWithAssetData = entrypoint.getEntrypointChunk().files.values().find(file => rawAssetData[file]);
104
+ if (!fileWithAssetData) {
105
+ compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
106
+ continue;
107
+ }
108
+ relevantAssetData[fileWithAssetData] = rawAssetData[fileWithAssetData];
109
+ }
110
+ return relevantAssetData;
111
+ }
61
112
  }
62
113
  exports.AbstractMultiPhaseLibraryAndEntryPlugin = AbstractMultiPhaseLibraryAndEntryPlugin;
@@ -1,14 +1,17 @@
1
1
  import { Compilation, Compiler, type WebpackPluginInstance } from "webpack";
2
2
  import { PseudoSemaphore } from "../utils/pseduo-semaphore";
3
+ import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
3
4
  export declare abstract class AbstractMultiPhaseLibraryPlugin implements WebpackPluginInstance {
5
+ protected readonly config: VerifiedPlauditWordpressWebpackConfig;
4
6
  readonly libraryType: string;
5
7
  private readonly semaphores;
6
8
  protected static readonly phaseTwoAttached: {
7
9
  [key in string]: any;
8
10
  };
9
11
  protected readonly id: string;
10
- protected constructor(libraryType: string, semaphores: PseudoSemaphore<any>[]);
12
+ protected constructor(config: VerifiedPlauditWordpressWebpackConfig, libraryType: string, semaphores: PseudoSemaphore<any>[]);
11
13
  apply(compiler: Compiler): void;
12
14
  protected resetSemaphores(): void;
15
+ protected rejectSemaphores(): void;
13
16
  protected abstract attachSecondPhase(compilation: Compilation): void;
14
17
  }
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractMultiPhaseLibraryPlugin = void 0;
4
4
  const webpack_1 = require("webpack");
5
5
  class AbstractMultiPhaseLibraryPlugin {
6
+ config;
6
7
  libraryType;
7
8
  semaphores;
8
9
  static phaseTwoAttached = {};
9
10
  id;
10
- constructor(libraryType, semaphores) {
11
+ constructor(config, libraryType, semaphores) {
12
+ this.config = config;
11
13
  this.libraryType = libraryType;
12
14
  this.semaphores = semaphores;
13
15
  this.id = Math.random().toString();
@@ -33,5 +35,10 @@ class AbstractMultiPhaseLibraryPlugin {
33
35
  semaphore.reset(this.id);
34
36
  }
35
37
  }
38
+ rejectSemaphores() {
39
+ for (const semaphore of this.semaphores) {
40
+ semaphore.reject(this.id);
41
+ }
42
+ }
36
43
  }
37
44
  exports.AbstractMultiPhaseLibraryPlugin = AbstractMultiPhaseLibraryPlugin;
@@ -1,8 +1,10 @@
1
1
  import { type Compiler, type WebpackPluginInstance } from "webpack";
2
+ import { AbstractMultiPhaseLibraryAndEntryPlugin } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
2
3
  export declare class AdditionalDependencyInjectorPlugin implements WebpackPluginInstance {
3
4
  private readonly entrypointAdditionalDependencies;
4
5
  private readonly processingModules;
5
6
  private readonly addExternalizedDep;
6
- constructor(entrypointAdditionalDependencies: string[], processingModules: boolean, addExternalizedDep: (dep: string) => void);
7
+ private readonly referencePlugin;
8
+ constructor(entrypointAdditionalDependencies: string[], processingModules: boolean, addExternalizedDep: (dep: string) => void, referencePlugin: AbstractMultiPhaseLibraryAndEntryPlugin<any>);
7
9
  apply(compiler: Compiler): void;
8
10
  }
@@ -10,10 +10,12 @@ class AdditionalDependencyInjectorPlugin {
10
10
  entrypointAdditionalDependencies;
11
11
  processingModules;
12
12
  addExternalizedDep;
13
- constructor(entrypointAdditionalDependencies, processingModules, addExternalizedDep) {
13
+ referencePlugin;
14
+ constructor(entrypointAdditionalDependencies, processingModules, addExternalizedDep, referencePlugin) {
14
15
  this.entrypointAdditionalDependencies = entrypointAdditionalDependencies;
15
16
  this.processingModules = processingModules;
16
17
  this.addExternalizedDep = addExternalizedDep;
18
+ this.referencePlugin = referencePlugin;
17
19
  }
18
20
  apply(compiler) {
19
21
  compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
@@ -22,7 +24,7 @@ class AdditionalDependencyInjectorPlugin {
22
24
  stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
23
25
  }, () => {
24
26
  const usableEntrypointTest = this.processingModules ? /\.m[jt]sx?$/i : /\.[jt]sx?$/i;
25
- for (const entrypoint of compilation.entrypoints.values()) {
27
+ for (const { entrypoint } of this.referencePlugin.getRelevantEntrypoints(compilation)) {
26
28
  const req = entrypoint.origins.filter(origin => usableEntrypointTest.test(origin.request))[0]?.request;
27
29
  if (!req) {
28
30
  continue;
@@ -43,7 +45,7 @@ class AdditionalDependencyInjectorPlugin {
43
45
  name: `${this.constructor.name}_ProcessAssets_RemoveFakeModules`,
44
46
  stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT
45
47
  }, () => {
46
- for (const entrypoint of compilation.entrypoints.values()) {
48
+ for (const { entrypoint } of this.referencePlugin.getRelevantEntrypoints(compilation)) {
47
49
  const entrypointChunk = entrypoint.getEntrypointChunk();
48
50
  for (const module of compilation.chunkGraph.getChunkModules(entrypointChunk)) {
49
51
  if (module instanceof webpack_1.ExternalModule && module.request === '__REMOVE_ME__') {
@@ -0,0 +1,8 @@
1
+ import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
2
+ import type { UnpackedBlockEntrypointInfo } from "../shared";
3
+ import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
+ export declare class EnhancedDynamicEntryPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
5
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
6
+ protected attachSecondPhase(): void;
7
+ protected processAssets(): void;
8
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnhancedDynamicEntryPlugin = void 0;
4
+ const AbstractMultiPhaseLibraryAndEntryPlugin_1 = require("./AbstractMultiPhaseLibraryAndEntryPlugin");
5
+ class EnhancedDynamicEntryPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin_1.AbstractMultiPhaseLibraryAndEntryPlugin {
6
+ constructor(config, context, entry) {
7
+ super(config, `enhanced-dynamic-entries`, [], context, entry);
8
+ }
9
+ attachSecondPhase() { }
10
+ processAssets() { }
11
+ }
12
+ exports.EnhancedDynamicEntryPlugin = EnhancedDynamicEntryPlugin;
@@ -1,15 +1,15 @@
1
1
  import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
2
- import { UnpackedBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
2
+ import { RawAssetData, 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<UnpackedBlockEntrypointInfo | string> {
6
- private readonly config;
5
+ export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin<string> {
7
6
  private readonly extensionsPath;
8
7
  private readonly dest;
9
8
  private static readonly semaphore;
10
9
  private static readonly perLibraryTypeSetupFilePaths;
11
- constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
10
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider<string>);
12
11
  apply(compiler: Compiler): void;
13
12
  private generateVersionTwoConfigFile;
14
13
  protected attachSecondPhase(compilation: Compilation): void;
14
+ protected processAssets(compilation: Compilation, rawAssetData: RawAssetData): void;
15
15
  }
@@ -13,14 +13,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
15
  class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin_1.AbstractMultiPhaseLibraryAndEntryPlugin {
16
- config;
17
16
  extensionsPath;
18
17
  dest;
19
18
  static semaphore = new pseduo_semaphore_1.PseudoSemaphore({ libraryType: "", assets: [], setupFiles: [] }, "Extensions");
20
19
  static perLibraryTypeSetupFilePaths = {};
21
20
  constructor(config, extensionsPath, dest, context, entry) {
22
- super(`extensions-v2-${dest.destination}`, [ExtensionsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
23
- this.config = config;
21
+ super(config, `extensions-v2-${dest.destination}`, [ExtensionsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
24
22
  this.extensionsPath = extensionsPath;
25
23
  this.dest = dest;
26
24
  }
@@ -45,93 +43,6 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEn
45
43
  ExtensionsConfigFileGeneratorPlugin.perLibraryTypeSetupFilePaths[this.libraryType] = (await Promise.all(emissionPromises))
46
44
  .filter((item) => item[0] !== undefined).sort((a, b) => a[0].localeCompare(b[0]));
47
45
  });
48
- compiler.hooks.compilation.tap(this.constructor.name, compilation => {
49
- compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, additionalAssets: true }, async (assets) => {
50
- if (!("assets.json" in assets)) {
51
- return;
52
- }
53
- try {
54
- //TODO: It should be possible to use EntryPoints to determine the "original" file
55
- //TODO: There is no reason to not use basically the exact same logic to implement support for this in plain file contexts
56
- const myCacheData = { libraryType: this.libraryType, assets: [],
57
- setupFiles: ExtensionsConfigFileGeneratorPlugin.perLibraryTypeSetupFilePaths[this.libraryType] ?? [] };
58
- const rawAssetDataSource = assets["assets.json"]?.source();
59
- if (typeof rawAssetDataSource !== 'string') {
60
- ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
61
- compilation.errors.push(new Error("assets.json is unexpectedly missing or not a string"));
62
- return;
63
- }
64
- const assetDataSource = JSON.parse(rawAssetDataSource);
65
- if (!(0, shared_1.isRawAssetData)(assetDataSource)) {
66
- ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
67
- compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
68
- return;
69
- }
70
- const relevantAssetData = {};
71
- const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
72
- for (const { entrypoint, srcPath } of relevantEntrypoints) {
73
- const fileWithAssetData = entrypoint.getEntrypointChunk().files.values().find(file => assetDataSource[file]);
74
- if (!fileWithAssetData) {
75
- compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
76
- continue;
77
- }
78
- relevantAssetData[fileWithAssetData] = assetDataSource[fileWithAssetData];
79
- }
80
- myCacheData.assets.push(relevantAssetData);
81
- compilation.deleteAsset("assets.json");
82
- ExtensionsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myCacheData);
83
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myCacheData.setupFiles.length > 0 || myCacheData.assets.length > 0 ? {
84
- group: this.libraryType,
85
- requiresBaseURI: true,
86
- action: writer => {
87
- const generateLoader = (writer) => {
88
- let finalExtensionsDest = this.dest.destination.endsWith("/") ? this.dest.destination : this.dest.destination + "/";
89
- if (!finalExtensionsDest.startsWith("/")) {
90
- finalExtensionsDest = "/" + finalExtensionsDest;
91
- }
92
- const filePathPrefixVar = new php_writer_1.Var("filePathPrefix");
93
- const fileUriPrefixVar = new php_writer_1.Var("fileUriPrefix");
94
- writer
95
- .assign(filePathPrefixVar, new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest)}`))
96
- .call("plaudit_webpack_extensions__resolve_base_uri", [filePathPrefixVar], { assignTo: fileUriPrefixVar })
97
- .call("GutenbergUtils::loadExtensionsV2", [
98
- new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest + "mapping.config.php")}`),
99
- filePathPrefixVar, fileUriPrefixVar,
100
- `${this.config.plainEntrypointsHandlePrefix || node_path_1.default.basename(process.cwd())}_extension_`
101
- ]);
102
- };
103
- writer.use("Plaudit\\Common\\Lib\\GutenbergUtils");
104
- const potentialHandle = this.dest.locations?.handle;
105
- if (potentialHandle) {
106
- if (typeof potentialHandle === 'string') {
107
- try {
108
- //TODO: Generate a function
109
- writer.function(potentialHandle, [], generateLoader, { returnType: 'void' });
110
- return;
111
- }
112
- catch (e) {
113
- compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for dynamically loading extensions", { cause: e }], this.extensionsPath));
114
- }
115
- }
116
- else {
117
- compilation.errors.push(new Error("The extensions directoryLayout's handle support is limited to static strings"));
118
- }
119
- }
120
- writer.withScope(generateLoader);
121
- }
122
- } : undefined);
123
- }
124
- catch (e) {
125
- ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
126
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reject(this.id);
127
- if (e instanceof Error) {
128
- compilation.errors.push(e);
129
- return;
130
- }
131
- throw e;
132
- }
133
- });
134
- });
135
46
  }
136
47
  generateVersionTwoConfigFile(compilation, combinedExtensionData) {
137
48
  const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
@@ -198,5 +109,50 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEn
198
109
  }
199
110
  });
200
111
  }
112
+ 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
+ }
152
+ }
153
+ writer.withScope(generateLoader);
154
+ }
155
+ } : undefined);
156
+ }
201
157
  }
202
158
  exports.ExtensionsConfigFileGeneratorPlugin = ExtensionsConfigFileGeneratorPlugin;
@@ -1,8 +1,11 @@
1
- import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
1
+ import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
2
+ import { RawAssetData } from "../shared";
3
+ import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
2
4
  import { Compilation, type Compiler } from "webpack";
3
- export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryPlugin {
5
+ export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryAndEntryPlugin<string> {
4
6
  private readonly extensionsDest;
5
- constructor(extensionsDest: string);
7
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsDest: string, context: string, entry: EntryProvider<string>);
6
8
  apply(compiler: Compiler): void;
7
- protected attachSecondPhase(compilation: Compilation): void;
9
+ protected attachSecondPhase(): void;
10
+ protected processAssets(compilation: Compilation, rawAssetData: RawAssetData): void;
8
11
  }
@@ -5,15 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ExtensionsConfigFileGeneratorPluginV1 = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
- const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
8
+ const AbstractMultiPhaseLibraryAndEntryPlugin_1 = require("./AbstractMultiPhaseLibraryAndEntryPlugin");
9
9
  const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
10
10
  const php_serializer_1 = require("../utils/php-serializer");
11
11
  const php_writer_1 = require("../utils/php-writer");
12
12
  const webpack_1 = require("webpack");
13
- class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
13
+ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryAndEntryPlugin_1.AbstractMultiPhaseLibraryAndEntryPlugin {
14
14
  extensionsDest;
15
- constructor(extensionsDest) {
16
- super(`extensions-v1-${extensionsDest}`, [UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
15
+ constructor(config, extensionsDest, context, entry) {
16
+ super(config, `extensions-v1-${extensionsDest}`, [UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
17
17
  this.extensionsDest = extensionsDest;
18
18
  }
19
19
  apply(compiler) {
@@ -26,24 +26,21 @@ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryPlu
26
26
  .call("GutenbergUtils::installExtensionsSupport", [php_writer_1.Op.join(php_writer_1.Constants.__DIR__, this.extensionsDest)]);
27
27
  } });
28
28
  });
29
- compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_AfterProcessAssets`, compilationAssets => {
30
- const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
31
- const mapping = {};
32
- for (const asset of Object.keys(compilationAssets)) {
33
- let match;
34
- if ((match = /^(.+?)-setup.php$/i.exec(asset)) && match[1]) {
35
- (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[1] = `${asset}`;
36
- }
37
- else if ((match = regex.exec(asset)) && match[1] && match[2]) {
38
- const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
39
- const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
40
- (resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset]);
41
- }
42
- }
43
- compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config"), new webpack_1.sources.RawSource((0, php_serializer_1.phpSerialize)(mapping)));
44
- });
45
29
  });
46
30
  }
47
- attachSecondPhase(compilation) { }
31
+ attachSecondPhase() { }
32
+ processAssets(compilation, rawAssetData) {
33
+ const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
34
+ const mapping = {};
35
+ for (const fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation, rawAssetData))) {
36
+ let match;
37
+ if ((match = regex.exec(fileWithAssetData)) && match[1] && match[2]) {
38
+ const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
39
+ const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
40
+ (resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, fileWithAssetData]);
41
+ }
42
+ }
43
+ compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config"), new webpack_1.sources.RawSource((0, php_serializer_1.phpSerialize)(mapping)));
44
+ }
48
45
  }
49
46
  exports.ExtensionsConfigFileGeneratorPluginV1 = ExtensionsConfigFileGeneratorPluginV1;
@@ -1,6 +1,7 @@
1
- import { UnpackedBlockEntrypointInfo, UsageLocations } from "../shared";
1
+ import { RawAssetData, UnpackedBlockEntrypointInfo, UsageLocations } from "../shared";
2
+ import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
2
3
  import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
3
- import { Compilation, type Compiler } from "webpack";
4
+ import { Compilation } from "webpack";
4
5
  export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
5
6
  private readonly buildRoot;
6
7
  private readonly outputDir;
@@ -8,11 +9,11 @@ export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractM
8
9
  private readonly handlePrefix;
9
10
  private readonly useUnifiedLoader;
10
11
  private static readonly semaphore;
11
- constructor(buildRoot: string, outputDir: string, usageLocations: UsageLocations, handlePrefix: string, useUnifiedLoader: boolean, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
12
- apply(compiler: Compiler): void;
12
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: UsageLocations, handlePrefix: string, useUnifiedLoader: boolean, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
13
13
  private generatePlainEntrypointsLoader;
14
14
  private static addHandlesToHandleLists;
15
15
  private static appendEnqueuingHandleLists;
16
16
  private static separateHandleListByPriority;
17
17
  protected attachSecondPhase(compilation: Compilation): void;
18
+ protected processAssets(compilation: Compilation, rawAssetData: RawAssetData): void;
18
19
  }