@plaudit/webpack-extensions 2.61.2 → 2.62.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.
@@ -0,0 +1,14 @@
1
+ import { Compilation, Compiler, type WebpackPluginInstance } from "webpack";
2
+ import { PseudoSemaphore } from "../utils/pseduo-semaphore";
3
+ export declare abstract class AbstractMultiPhaseLibraryPlugin implements WebpackPluginInstance {
4
+ readonly libraryType: string;
5
+ private readonly semaphores;
6
+ protected static readonly phaseTwoAttached: {
7
+ [key in string]: any;
8
+ };
9
+ protected readonly id: string;
10
+ protected constructor(libraryType: string, semaphores: PseudoSemaphore<any>[]);
11
+ apply(compiler: Compiler): void;
12
+ protected resetSemaphores(): void;
13
+ protected abstract attachSecondPhase(compilation: Compilation): void;
14
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractMultiPhaseLibraryPlugin = void 0;
4
+ const webpack_1 = require("webpack");
5
+ class AbstractMultiPhaseLibraryPlugin {
6
+ libraryType;
7
+ semaphores;
8
+ static phaseTwoAttached = {};
9
+ id;
10
+ constructor(libraryType, semaphores) {
11
+ this.libraryType = libraryType;
12
+ this.semaphores = semaphores;
13
+ this.id = Math.random().toString();
14
+ }
15
+ apply(compiler) {
16
+ webpack_1.library.EnableLibraryPlugin.setEnabled(compiler, this.libraryType);
17
+ for (const semaphore of this.semaphores) {
18
+ semaphore.register(this.id);
19
+ }
20
+ compiler.hooks.compilation.tap(this.constructor.name, compilation => {
21
+ AbstractMultiPhaseLibraryPlugin.phaseTwoAttached[this.libraryType] = false;
22
+ this.resetSemaphores();
23
+ compilation.hooks.beforeChunkIds.tap(this.constructor.name, () => {
24
+ if (!AbstractMultiPhaseLibraryPlugin.phaseTwoAttached[this.libraryType]) {
25
+ AbstractMultiPhaseLibraryPlugin.phaseTwoAttached[this.libraryType] = this;
26
+ this.attachSecondPhase(compilation);
27
+ }
28
+ });
29
+ });
30
+ // compiler.hooks.compilation.tap(
31
+ // this.constructor.name,
32
+ // (compilation, { normalModuleFactory }) => {
33
+ // const dummyEntry = EntryPlugin.createDependency("", "");
34
+ // compilation.dependencyFactories.set(
35
+ // dummyEntry.constructor as any,
36
+ // normalModuleFactory
37
+ // );
38
+ // }
39
+ // );
40
+ //
41
+ // compiler.hooks.make.tapPromise(this.constructor.name, (compilation) =>
42
+ // Promise.resolve(this.entry())
43
+ // .then((entry) => {
44
+ // const promises = [];
45
+ // for (const name of Object.keys(entry)) {
46
+ // const desc = entry[name];
47
+ // const options = EntryOptionPlugin.entryDescriptionToOptions(
48
+ // compiler,
49
+ // name,
50
+ // desc
51
+ // );
52
+ // for (const entry of /** @type {NonNullable<EntryDescriptionNormalized["import"]>} */ (
53
+ // desc.import
54
+ // )) {
55
+ // promises.push(
56
+ // new Promise(
57
+ // /**
58
+ // * @param {(value?: undefined) => void} resolve resolve
59
+ // * @param {(reason?: Error) => void} reject reject
60
+ // */
61
+ // (resolve, reject) => {
62
+ // compilation.addEntry(
63
+ // this.context,
64
+ // EntryPlugin.createDependency(entry, options),
65
+ // options,
66
+ // (err) => {
67
+ // if (err) return reject(err);
68
+ // resolve();
69
+ // }
70
+ // );
71
+ // }
72
+ // )
73
+ // );
74
+ // }
75
+ // }
76
+ // return Promise.all(promises);
77
+ // })
78
+ // .then(() => {})
79
+ // );
80
+ }
81
+ // protected abstract generateEntries(compiler: Compiler, context: string, entry: EntryStaticNormalized): void;
82
+ resetSemaphores() {
83
+ for (const semaphore of this.semaphores) {
84
+ semaphore.reset(this.id);
85
+ }
86
+ }
87
+ }
88
+ exports.AbstractMultiPhaseLibraryPlugin = AbstractMultiPhaseLibraryPlugin;
@@ -1,15 +1,14 @@
1
- import { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
2
- import { type Compiler, type WebpackPluginInstance } from "webpack";
3
- export declare class ExtensionsConfigFileGeneratorPlugin implements WebpackPluginInstance {
1
+ import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
2
+ import { Compilation, type Compiler } from "webpack";
3
+ import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
4
+ export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugin {
4
5
  private readonly config;
5
6
  private readonly extensionsPath;
6
7
  private readonly extensionsDest;
7
8
  private static readonly semaphore;
8
- private static phaseTwoAttached;
9
- private readonly id;
10
9
  constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsPath: string, extensionsDest: string);
11
10
  apply(compiler: Compiler): void;
12
11
  private generateVersionTwoConfigFile;
13
- private makeVersionOneAfterProcessAssets;
14
12
  private stripExtensionsDest;
13
+ protected attachSecondPhase(compilation: Compilation): void;
15
14
  }
@@ -8,26 +8,23 @@ const promises_1 = __importDefault(require("node:fs/promises"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
10
10
  const shared_1 = require("../shared");
11
- const php_serializer_1 = require("../utils/php-serializer");
12
11
  const php_writer_1 = require("../utils/php-writer");
13
12
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
14
13
  const webpack_1 = require("webpack");
15
- class ExtensionsConfigFileGeneratorPlugin {
14
+ const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
15
+ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
16
16
  config;
17
17
  extensionsPath;
18
18
  extensionsDest;
19
19
  static semaphore = new pseduo_semaphore_1.PseudoSemaphore({ assets: [], setupFiles: [] }, "Extensions");
20
- static phaseTwoAttached = false;
21
- id;
22
20
  constructor(config, extensionsPath, extensionsDest) {
21
+ super(`extensions-v2-${extensionsDest}`, [ExtensionsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
23
22
  this.config = config;
24
23
  this.extensionsPath = extensionsPath;
25
24
  this.extensionsDest = extensionsDest;
26
- this.id = Math.random().toString();
27
- ExtensionsConfigFileGeneratorPlugin.semaphore.register(this.id);
28
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.register(this.id);
29
25
  }
30
26
  apply(compiler) {
27
+ super.apply(compiler);
31
28
  compiler.hooks.make.tapPromise(this.constructor.name, async (compilation) => {
32
29
  if (!compilation.contextDependencies.has(this.extensionsPath)) {
33
30
  compilation.contextDependencies.add(this.extensionsPath);
@@ -44,107 +41,76 @@ class ExtensionsConfigFileGeneratorPlugin {
44
41
  }
45
42
  await Promise.all(emissionPromises);
46
43
  });
47
- if (this.config.extensionsVersion === 2) {
48
- compiler.hooks.compilation.tap(this.constructor.name, compilation => {
49
- ExtensionsConfigFileGeneratorPlugin.phaseTwoAttached = false;
50
- ExtensionsConfigFileGeneratorPlugin.semaphore.reset(this.id);
51
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reset(this.id);
52
- compilation.hooks.beforeChunkIds.tap(this.constructor.name, () => {
53
- if (!ExtensionsConfigFileGeneratorPlugin.phaseTwoAttached) {
54
- ExtensionsConfigFileGeneratorPlugin.phaseTwoAttached = true;
55
- compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_GenerateConfigFile`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
56
- const combinedExtensionData = (await ExtensionsConfigFileGeneratorPlugin.semaphore.wait())
57
- .reduce((main, { assets, setupFiles }) => {
58
- main.assets.push(...assets);
59
- main.setupFiles.push(...setupFiles);
60
- return main;
61
- }, { assets: [], setupFiles: [] });
62
- if (combinedExtensionData.assets.length > 0 || combinedExtensionData.setupFiles.length > 0 || !this.config.useUnifiedLoader) {
63
- this.generateVersionTwoConfigFile(compilation, combinedExtensionData);
64
- }
65
- });
44
+ compiler.hooks.compilation.tap(this.constructor.name, compilation => {
45
+ compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, additionalAssets: true }, async (assets) => {
46
+ if (!("assets.json" in assets)) {
47
+ return;
48
+ }
49
+ try {
50
+ //TODO: It should be possible to use EntryPoints to determine the "original" file
51
+ //TODO: There is no reason to not use basically the exact same logic to implement support for this in plain file contexts
52
+ const myCacheData = { assets: [], setupFiles: [] };
53
+ for (const asset of Object.keys(compilation.assets).map(asset => this.stripExtensionsDest(asset))) {
54
+ const blockSlug = /^(.+?)-setup.php$/i.exec(asset)?.[1];
55
+ if (blockSlug) {
56
+ myCacheData.setupFiles.push([blockSlug, asset]);
57
+ }
66
58
  }
67
- });
68
- compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, additionalAssets: true }, async (assets) => {
69
- if (!("assets.json" in assets)) {
59
+ const rawAssetDataSource = assets["assets.json"]?.source();
60
+ if (typeof rawAssetDataSource !== 'string') {
61
+ ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
62
+ compilation.errors.push(new Error("assets.json is unexpectedly missing or not a string"));
70
63
  return;
71
64
  }
72
- try {
73
- //TODO: It should be possible to use EntryPoints to determine the "original" file
74
- //TODO: There is no reason to not use basically the exact same logic to implement support for this in plain file contexts
75
- //TODO: BlockJSONManagingPlugin should be rewritten from scratch to use this method instead of its 15 layers of tracking + syncing
76
- const myCacheData = { assets: [], setupFiles: [] };
77
- for (const asset of Object.keys(compilation.assets).map(asset => this.stripExtensionsDest(asset))) {
78
- const blockSlug = /^(.+?)-setup.php$/i.exec(asset)?.[1];
79
- if (blockSlug) {
80
- myCacheData.setupFiles.push([blockSlug, asset]);
81
- }
82
- }
83
- const rawAssetDataSource = assets["assets.json"]?.source();
84
- if (typeof rawAssetDataSource !== 'string') {
85
- ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
86
- compilation.errors.push(new Error("assets.json is unexpectedly missing or not a string"));
87
- return;
88
- }
89
- const assetDataSource = JSON.parse(rawAssetDataSource);
90
- if (!(0, shared_1.isRawAssetData)(assetDataSource)) {
91
- ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
92
- compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
93
- return;
94
- }
95
- myCacheData.assets.push(assetDataSource);
96
- compilation.deleteAsset("assets.json");
97
- ExtensionsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myCacheData);
98
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myCacheData.setupFiles.length > 0 || myCacheData.assets.length > 0 ? {
99
- group: `extensions-config-v2-${this.extensionsDest}`,
100
- requiresBaseURI: true,
101
- action: writer => {
102
- let finalExtensionsDest = this.extensionsDest.endsWith("/") ? this.extensionsDest : this.extensionsDest + "/";
103
- if (!finalExtensionsDest.startsWith("/")) {
104
- finalExtensionsDest = "/" + finalExtensionsDest;
105
- }
106
- writer
107
- .use("Plaudit\\Common\\Lib\\GutenbergUtils")
108
- .withScope(writer => writer
109
- .assign("$filePathPrefix", new php_writer_1.Expr(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest)}`))
110
- .call("plaudit_webpack_extensions__resolve_base_uri", [new php_writer_1.Expr("$filePathPrefix")], { assignTo: "$fileUriPrefix" })
111
- .call("GutenbergUtils::loadExtensionsV2", [
112
- new php_writer_1.Expr(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest + "mapping.config.php")}`),
113
- new php_writer_1.Expr(`$filePathPrefix`), new php_writer_1.Expr("$fileUriPrefix"),
114
- `${this.config.plainEntrypointsHandlePrefix || node_path_1.default.basename(process.cwd())}_extension_`
115
- ]));
116
- }
117
- } : undefined);
118
- }
119
- catch (e) {
65
+ const assetDataSource = JSON.parse(rawAssetDataSource);
66
+ if (!(0, shared_1.isRawAssetData)(assetDataSource)) {
120
67
  ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
121
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reject(this.id);
122
- if (e instanceof Error) {
123
- compilation.errors.push(e);
124
- return;
125
- }
126
- throw e;
68
+ compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
69
+ return;
127
70
  }
128
- });
129
- });
130
- }
131
- else {
132
- compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
133
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reset(this.id);
134
- compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
135
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, { group: `extensions-config-v1-${this.extensionsDest}`, requiresBaseURI: false, action: writer => {
71
+ myCacheData.assets.push(assetDataSource);
72
+ compilation.deleteAsset("assets.json");
73
+ ExtensionsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myCacheData);
74
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myCacheData.setupFiles.length > 0 || myCacheData.assets.length > 0 ? {
75
+ group: this.libraryType,
76
+ requiresBaseURI: true,
77
+ action: writer => {
78
+ let finalExtensionsDest = this.extensionsDest.endsWith("/") ? this.extensionsDest : this.extensionsDest + "/";
79
+ if (!finalExtensionsDest.startsWith("/")) {
80
+ finalExtensionsDest = "/" + finalExtensionsDest;
81
+ }
82
+ const filePathPrefixVar = new php_writer_1.Var("filePathPrefix");
83
+ const fileUriPrefixVar = new php_writer_1.Var("fileUriPrefix");
136
84
  writer
137
85
  .use("Plaudit\\Common\\Lib\\GutenbergUtils")
138
- .call("GutenbergUtils::installExtensionsSupport", [new php_writer_1.Expr(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(this.extensionsDest)}`)]);
139
- } });
140
- });
141
- compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_AfterProcessAssets`, this.makeVersionOneAfterProcessAssets(compilation));
86
+ .withScope(writer => writer
87
+ .assign(filePathPrefixVar, new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest)}`))
88
+ .call("plaudit_webpack_extensions__resolve_base_uri", [filePathPrefixVar], { assignTo: fileUriPrefixVar })
89
+ .call("GutenbergUtils::loadExtensionsV2", [
90
+ new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest + "mapping.config.php")}`),
91
+ filePathPrefixVar, fileUriPrefixVar,
92
+ `${this.config.plainEntrypointsHandlePrefix || node_path_1.default.basename(process.cwd())}_extension_`
93
+ ]));
94
+ }
95
+ } : undefined);
96
+ }
97
+ catch (e) {
98
+ ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
99
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reject(this.id);
100
+ if (e instanceof Error) {
101
+ compilation.errors.push(e);
102
+ return;
103
+ }
104
+ throw e;
105
+ }
142
106
  });
143
- }
107
+ });
144
108
  }
145
109
  generateVersionTwoConfigFile(compilation, combinedExtensionData) {
146
110
  const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
147
- const blockExtensionsConfig = { metadata: { version: this.config.extensionsVersion }, scriptHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {} };
111
+ const blockExtensionsConfig = {
112
+ metadata: { version: this.config.extensionsVersion }, scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {}
113
+ };
148
114
  for (const assetDataSource of combinedExtensionData.assets) {
149
115
  const normalizedAssetData = Object.entries(assetDataSource)
150
116
  .map(entry => {
@@ -161,8 +127,10 @@ class ExtensionsConfigFileGeneratorPlugin {
161
127
  if (blockSlug && assetType) {
162
128
  const key = assetType.replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
163
129
  const handle = `plaudit_block-extension_${blockSlug}-${assetType}`;
164
- const isCss = assetType.endsWith("tyle");
165
- blockExtensionsConfig[isCss ? 'styleHandles' : 'scriptHandles'][handle] = {
130
+ const isCss = (0, shared_1.isStyleField)(assetType);
131
+ const handleGroup = isCss ? 'styleHandles'
132
+ : ((0, shared_1.isScriptModuleField)(assetType) ? 'scriptModuleHandles' : 'scriptHandles');
133
+ blockExtensionsConfig[handleGroup][handle] = {
166
134
  src: isCss ? assetPath.replace(/\.js$/, ".css") : assetPath,
167
135
  rest: isCss || key.startsWith("editor")
168
136
  ? [assetData.dependencies, assetData.version]
@@ -177,6 +145,8 @@ class ExtensionsConfigFileGeneratorPlugin {
177
145
  }
178
146
  blockExtensionsConfig.scriptHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptHandles)
179
147
  .toSorted(([a], [b]) => a.localeCompare(b)));
148
+ blockExtensionsConfig.scriptModuleHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptModuleHandles)
149
+ .toSorted(([a], [b]) => a.localeCompare(b)));
180
150
  blockExtensionsConfig.styleHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.styleHandles)
181
151
  .toSorted(([a], [b]) => a.localeCompare(b)));
182
152
  blockExtensionsConfig.setupFiles = Object.fromEntries(Object.entries(blockExtensionsConfig.setupFiles)
@@ -186,28 +156,23 @@ class ExtensionsConfigFileGeneratorPlugin {
186
156
  return [block[0], Object.fromEntries(Object.entries(block[1]).toSorted(([a], [b]) => a.localeCompare(b)))];
187
157
  })
188
158
  .toSorted(([a], [b]) => a.localeCompare(b)));
189
- compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig)));
190
- }
191
- makeVersionOneAfterProcessAssets(compilation) {
192
- return compilationAssets => {
193
- const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
194
- const mapping = {};
195
- for (const asset of Object.keys(compilationAssets)) {
196
- let match;
197
- if ((match = /^(.+?)-setup.php$/i.exec(asset)) && match[1]) {
198
- (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[1] = `${asset}`;
199
- }
200
- else if ((match = regex.exec(asset)) && match[1] && match[2]) {
201
- const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
202
- const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
203
- (resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset]);
204
- }
205
- }
206
- compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config"), new webpack_1.sources.RawSource((0, php_serializer_1.phpSerialize)(mapping)));
207
- };
159
+ compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, true)));
208
160
  }
209
161
  stripExtensionsDest(item) {
210
162
  return this.extensionsDest && item.startsWith(this.extensionsDest + "/") ? item.substring(this.extensionsDest.length + 1 /* we also need to drop the "/" */) : item;
211
163
  }
164
+ attachSecondPhase(compilation) {
165
+ compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_GenerateConfigFile`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
166
+ const combinedExtensionData = (await ExtensionsConfigFileGeneratorPlugin.semaphore.wait())
167
+ .reduce((main, { assets, setupFiles }) => {
168
+ main.assets.push(...assets);
169
+ main.setupFiles.push(...setupFiles);
170
+ return main;
171
+ }, { assets: [], setupFiles: [] });
172
+ if (combinedExtensionData.assets.length > 0 || combinedExtensionData.setupFiles.length > 0 || !this.config.useUnifiedLoader) {
173
+ this.generateVersionTwoConfigFile(compilation, combinedExtensionData);
174
+ }
175
+ });
176
+ }
212
177
  }
213
178
  exports.ExtensionsConfigFileGeneratorPlugin = ExtensionsConfigFileGeneratorPlugin;
@@ -0,0 +1,8 @@
1
+ import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
2
+ import { Compilation, type Compiler } from "webpack";
3
+ export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryPlugin {
4
+ private readonly extensionsDest;
5
+ constructor(extensionsDest: string);
6
+ apply(compiler: Compiler): void;
7
+ protected attachSecondPhase(compilation: Compilation): void;
8
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ExtensionsConfigFileGeneratorPluginV1 = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
9
+ const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
10
+ const php_serializer_1 = require("../utils/php-serializer");
11
+ const php_writer_1 = require("../utils/php-writer");
12
+ const webpack_1 = require("webpack");
13
+ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
14
+ extensionsDest;
15
+ constructor(extensionsDest) {
16
+ super(`extensions-v1-${extensionsDest}`, [UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
17
+ this.extensionsDest = extensionsDest;
18
+ }
19
+ apply(compiler) {
20
+ super.apply(compiler);
21
+ compiler.hooks.compilation.tap(this.constructor.name, compilation => {
22
+ compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
23
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, { group: `extensions-config-v1-${this.extensionsDest}`, requiresBaseURI: false, action: writer => {
24
+ writer
25
+ .use("Plaudit\\Common\\Lib\\GutenbergUtils")
26
+ .call("GutenbergUtils::installExtensionsSupport", [php_writer_1.Op.join(php_writer_1.Constants.__DIR__, this.extensionsDest)]);
27
+ } });
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
+ });
46
+ }
47
+ attachSecondPhase(compilation) { }
48
+ }
49
+ exports.ExtensionsConfigFileGeneratorPluginV1 = ExtensionsConfigFileGeneratorPluginV1;
@@ -1,23 +1,18 @@
1
1
  import { UsageLocations } from "../shared";
2
- import { PHPWriter } from "../utils/php-writer";
3
- import { type Compiler, type WebpackPluginInstance } from "webpack";
4
- export declare class PlainEntrypointsConfigFileGeneratorPlugin implements WebpackPluginInstance {
2
+ import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
3
+ import { Compilation, type Compiler } from "webpack";
4
+ export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugin {
5
5
  private readonly buildRoot;
6
6
  private readonly outputDir;
7
7
  private readonly usageLocations;
8
8
  private readonly handlePrefix;
9
9
  private readonly useUnifiedLoader;
10
10
  private static readonly semaphore;
11
- private static phaseTwoAttached;
12
- private readonly id;
13
11
  constructor(buildRoot: string, outputDir: string, usageLocations: UsageLocations, handlePrefix: string, useUnifiedLoader: boolean);
14
12
  apply(compiler: Compiler): void;
15
- private afterProcessAssets;
13
+ private generatePlainEntrypointsLoader;
16
14
  private static addHandlesToHandleLists;
17
15
  private static appendEnqueuingHandleLists;
18
16
  private static separateHandleListByPriority;
19
- /**
20
- * 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
21
- */
22
- static emitResolveBaseUriFunction(writer: PHPWriter): void;
17
+ protected attachSecondPhase(compilation: Compilation): void;
23
18
  }