@plaudit/webpack-extensions 2.62.0 → 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.
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +14 -0
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +88 -0
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +4 -5
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +73 -113
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +8 -0
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +49 -0
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +5 -5
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +18 -23
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +4 -5
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +53 -59
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +4 -4
- package/build/plugins/SpecialAssetHandlingPlugin.js +11 -17
- package/build/shared.d.ts +0 -15
- package/build/shared.js +15 -31
- package/build/utils/php-writer.d.ts +129 -18
- package/build/utils/php-writer.js +261 -43
- package/build/wordpress-scripts-wrapper.js +8 -15
- package/package.json +1 -1
|
@@ -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
1
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
-
|
|
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,102 +41,70 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
44
41
|
}
|
|
45
42
|
await Promise.all(emissionPromises);
|
|
46
43
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
//TODO: There is no reason to not use basically the exact same logic to implement support for this in plain file contexts
|
|
75
|
-
const myCacheData = { assets: [], setupFiles: [] };
|
|
76
|
-
for (const asset of Object.keys(compilation.assets).map(asset => this.stripExtensionsDest(asset))) {
|
|
77
|
-
const blockSlug = /^(.+?)-setup.php$/i.exec(asset)?.[1];
|
|
78
|
-
if (blockSlug) {
|
|
79
|
-
myCacheData.setupFiles.push([blockSlug, asset]);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const rawAssetDataSource = assets["assets.json"]?.source();
|
|
83
|
-
if (typeof rawAssetDataSource !== 'string') {
|
|
84
|
-
ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
|
|
85
|
-
compilation.errors.push(new Error("assets.json is unexpectedly missing or not a string"));
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const assetDataSource = JSON.parse(rawAssetDataSource);
|
|
89
|
-
if (!(0, shared_1.isRawAssetData)(assetDataSource)) {
|
|
90
|
-
ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
|
|
91
|
-
compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
myCacheData.assets.push(assetDataSource);
|
|
95
|
-
compilation.deleteAsset("assets.json");
|
|
96
|
-
ExtensionsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myCacheData);
|
|
97
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myCacheData.setupFiles.length > 0 || myCacheData.assets.length > 0 ? {
|
|
98
|
-
group: `extensions-config-v2-${this.extensionsDest}`,
|
|
99
|
-
requiresBaseURI: true,
|
|
100
|
-
action: writer => {
|
|
101
|
-
let finalExtensionsDest = this.extensionsDest.endsWith("/") ? this.extensionsDest : this.extensionsDest + "/";
|
|
102
|
-
if (!finalExtensionsDest.startsWith("/")) {
|
|
103
|
-
finalExtensionsDest = "/" + finalExtensionsDest;
|
|
104
|
-
}
|
|
105
|
-
writer
|
|
106
|
-
.use("Plaudit\\Common\\Lib\\GutenbergUtils")
|
|
107
|
-
.withScope(writer => writer
|
|
108
|
-
.assign("$filePathPrefix", new php_writer_1.Expr(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest)}`))
|
|
109
|
-
.call("plaudit_webpack_extensions__resolve_base_uri", [new php_writer_1.Expr("$filePathPrefix")], { assignTo: "$fileUriPrefix" })
|
|
110
|
-
.call("GutenbergUtils::loadExtensionsV2", [
|
|
111
|
-
new php_writer_1.Expr(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest + "mapping.config.php")}`),
|
|
112
|
-
new php_writer_1.Expr(`$filePathPrefix`), new php_writer_1.Expr("$fileUriPrefix"),
|
|
113
|
-
`${this.config.plainEntrypointsHandlePrefix || node_path_1.default.basename(process.cwd())}_extension_`
|
|
114
|
-
]));
|
|
115
|
-
}
|
|
116
|
-
} : undefined);
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
65
|
+
const assetDataSource = JSON.parse(rawAssetDataSource);
|
|
66
|
+
if (!(0, shared_1.isRawAssetData)(assetDataSource)) {
|
|
119
67
|
ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
compilation.errors.push(e);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
throw e;
|
|
68
|
+
compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
|
|
69
|
+
return;
|
|
126
70
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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");
|
|
135
84
|
writer
|
|
136
85
|
.use("Plaudit\\Common\\Lib\\GutenbergUtils")
|
|
137
|
-
.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
+
}
|
|
141
106
|
});
|
|
142
|
-
}
|
|
107
|
+
});
|
|
143
108
|
}
|
|
144
109
|
generateVersionTwoConfigFile(compilation, combinedExtensionData) {
|
|
145
110
|
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
@@ -193,26 +158,21 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
193
158
|
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
194
159
|
compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, true)));
|
|
195
160
|
}
|
|
196
|
-
makeVersionOneAfterProcessAssets(compilation) {
|
|
197
|
-
return compilationAssets => {
|
|
198
|
-
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
199
|
-
const mapping = {};
|
|
200
|
-
for (const asset of Object.keys(compilationAssets)) {
|
|
201
|
-
let match;
|
|
202
|
-
if ((match = /^(.+?)-setup.php$/i.exec(asset)) && match[1]) {
|
|
203
|
-
(mapping[match[1]] ?? (mapping[match[1]] = [{}]))[1] = `${asset}`;
|
|
204
|
-
}
|
|
205
|
-
else if ((match = regex.exec(asset)) && match[1] && match[2]) {
|
|
206
|
-
const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
|
|
207
|
-
const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
|
|
208
|
-
(resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset]);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config"), new webpack_1.sources.RawSource((0, php_serializer_1.phpSerialize)(mapping)));
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
161
|
stripExtensionsDest(item) {
|
|
215
162
|
return this.extensionsDest && item.startsWith(this.extensionsDest + "/") ? item.substring(this.extensionsDest.length + 1 /* we also need to drop the "/" */) : item;
|
|
216
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
|
+
}
|
|
217
177
|
}
|
|
218
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,18 +1,18 @@
|
|
|
1
1
|
import { UsageLocations } from "../shared";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
|
|
3
|
+
import { Compilation, type Compiler } from "webpack";
|
|
4
|
+
export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugin {
|
|
4
5
|
private readonly buildRoot;
|
|
5
6
|
private readonly outputDir;
|
|
6
7
|
private readonly usageLocations;
|
|
7
8
|
private readonly handlePrefix;
|
|
8
9
|
private readonly useUnifiedLoader;
|
|
9
10
|
private static readonly semaphore;
|
|
10
|
-
private static phaseTwoAttached;
|
|
11
|
-
private readonly id;
|
|
12
11
|
constructor(buildRoot: string, outputDir: string, usageLocations: UsageLocations, handlePrefix: string, useUnifiedLoader: boolean);
|
|
13
12
|
apply(compiler: Compiler): void;
|
|
14
|
-
private
|
|
13
|
+
private generatePlainEntrypointsLoader;
|
|
15
14
|
private static addHandlesToHandleLists;
|
|
16
15
|
private static appendEnqueuingHandleLists;
|
|
17
16
|
private static separateHandleListByPriority;
|
|
17
|
+
protected attachSecondPhase(compilation: Compilation): void;
|
|
18
18
|
}
|
|
@@ -8,40 +8,27 @@ 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
|
|
11
|
+
const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
|
|
12
12
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
13
|
-
|
|
13
|
+
const webpack_1 = require("webpack");
|
|
14
|
+
class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
|
|
14
15
|
buildRoot;
|
|
15
16
|
outputDir;
|
|
16
17
|
usageLocations;
|
|
17
18
|
handlePrefix;
|
|
18
19
|
useUnifiedLoader;
|
|
19
20
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore([], "Plain");
|
|
20
|
-
static phaseTwoAttached = false;
|
|
21
|
-
id;
|
|
22
21
|
constructor(buildRoot, outputDir, usageLocations, handlePrefix, useUnifiedLoader) {
|
|
22
|
+
super("plain-entrypoints-v2", [PlainEntrypointsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
23
23
|
this.buildRoot = buildRoot;
|
|
24
24
|
this.outputDir = outputDir;
|
|
25
25
|
this.usageLocations = usageLocations;
|
|
26
26
|
this.handlePrefix = handlePrefix;
|
|
27
27
|
this.useUnifiedLoader = useUnifiedLoader;
|
|
28
|
-
this.id = Math.random().toString();
|
|
29
|
-
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.register(this.id);
|
|
30
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.register(this.id);
|
|
31
28
|
}
|
|
32
29
|
apply(compiler) {
|
|
30
|
+
super.apply(compiler);
|
|
33
31
|
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
34
|
-
PlainEntrypointsConfigFileGeneratorPlugin.phaseTwoAttached = false;
|
|
35
|
-
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.reset(this.id);
|
|
36
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reset(this.id);
|
|
37
|
-
compilation.hooks.beforeChunkIds.tap(this.constructor.name, () => {
|
|
38
|
-
if (!PlainEntrypointsConfigFileGeneratorPlugin.phaseTwoAttached) {
|
|
39
|
-
PlainEntrypointsConfigFileGeneratorPlugin.phaseTwoAttached = true;
|
|
40
|
-
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
41
|
-
this.afterProcessAssets(compilation, (await PlainEntrypointsConfigFileGeneratorPlugin.semaphore.wait()).flat());
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
32
|
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, additionalAssets: true }, async (assets) => {
|
|
46
33
|
if (!("assets.json" in assets)) {
|
|
47
34
|
return;
|
|
@@ -101,10 +88,9 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
|
|
|
101
88
|
handlePrefix: this.handlePrefix
|
|
102
89
|
});
|
|
103
90
|
}
|
|
104
|
-
compilation.deleteAsset("assets.json");
|
|
105
91
|
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myAssetHandles);
|
|
106
92
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myAssetHandles.length
|
|
107
|
-
? { group:
|
|
93
|
+
? { group: this.libraryType, requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';") }
|
|
108
94
|
: undefined);
|
|
109
95
|
}
|
|
110
96
|
catch (e) {
|
|
@@ -113,9 +99,12 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
|
|
|
113
99
|
throw e;
|
|
114
100
|
}
|
|
115
101
|
});
|
|
102
|
+
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
103
|
+
compilation.deleteAsset("assets.json");
|
|
104
|
+
});
|
|
116
105
|
});
|
|
117
106
|
}
|
|
118
|
-
|
|
107
|
+
generatePlainEntrypointsLoader(compilation, assets) {
|
|
119
108
|
const emitDir = node_path_1.default.join(this.buildRoot, this.outputDir);
|
|
120
109
|
const handleLists = {
|
|
121
110
|
register: [],
|
|
@@ -175,11 +164,12 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
|
|
|
175
164
|
if (!this.useUnifiedLoader) {
|
|
176
165
|
(0, shared_1.emitResolveBaseUriFunction)(writer);
|
|
177
166
|
}
|
|
167
|
+
const baseUriVar = new php_writer_1.Var("base_uri");
|
|
178
168
|
for (const [priority, prioritizedHandleList] of PlainEntrypointsConfigFileGeneratorPlugin.separateHandleListByPriority(handleLists.register)) {
|
|
179
169
|
writer.action("init", writer => {
|
|
180
|
-
writer.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.
|
|
170
|
+
writer.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.Constants.__DIR__], { assignTo: baseUriVar });
|
|
181
171
|
for (const { handle, type, data } of prioritizedHandleList) {
|
|
182
|
-
writer.call(`wp_register_${type}`, [handle,
|
|
172
|
+
writer.call(`wp_register_${type}`, [handle, php_writer_1.Op.join(baseUriVar, node_path_1.default.relative(emitDir, data.src)), ...data.rest]);
|
|
183
173
|
}
|
|
184
174
|
}, { priority, accountForAlreadyDoing: true });
|
|
185
175
|
}
|
|
@@ -248,5 +238,10 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
|
|
|
248
238
|
}
|
|
249
239
|
return lists.entries().toArray().sort((a, b) => a[0] - b[0]);
|
|
250
240
|
}
|
|
241
|
+
attachSecondPhase(compilation) {
|
|
242
|
+
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
243
|
+
this.generatePlainEntrypointsLoader(compilation, (await PlainEntrypointsConfigFileGeneratorPlugin.semaphore.wait()).flat());
|
|
244
|
+
});
|
|
245
|
+
}
|
|
251
246
|
}
|
|
252
247
|
exports.PlainEntrypointsConfigFileGeneratorPlugin = PlainEntrypointsConfigFileGeneratorPlugin;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
|
|
1
2
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
2
|
-
import {
|
|
3
|
+
import { Compilation, type Compiler } from "webpack";
|
|
3
4
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
4
|
-
export declare class PlainEntrypointsStyleBlockJSONPlugin
|
|
5
|
+
export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryPlugin {
|
|
5
6
|
private readonly config;
|
|
6
7
|
private readonly blocksDest;
|
|
7
8
|
private readonly webpackRemoveEmptyScriptsPlugin;
|
|
8
9
|
private static readonly semaphore;
|
|
9
|
-
private static readonly phaseTwoAttached;
|
|
10
|
-
private readonly id;
|
|
11
|
-
private readonly libraryType;
|
|
12
10
|
constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin);
|
|
13
11
|
apply(compiler: Compiler): void;
|
|
14
12
|
private emitBlockLoaderFile;
|
|
@@ -23,4 +21,5 @@ export declare class PlainEntrypointsStyleBlockJSONPlugin implements WebpackPlug
|
|
|
23
21
|
static findRelativeRouteBetween(path1: string, path2: string): string;
|
|
24
22
|
private static remapReferencedPHPFilesOnKey;
|
|
25
23
|
private static normalizeRenderTemplate;
|
|
24
|
+
protected attachSecondPhase(compilation: Compilation): void;
|
|
26
25
|
}
|