@plaudit/webpack-extensions 2.63.1 → 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.
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.d.ts +8 -6
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.js +53 -2
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +4 -1
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +8 -1
- package/build/plugins/AdditionalDependencyInjectorPlugin.d.ts +3 -1
- package/build/plugins/AdditionalDependencyInjectorPlugin.js +5 -3
- package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +8 -0
- package/build/plugins/EnhancedDynamicEntryPlugin.js +12 -0
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +4 -4
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +46 -90
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +7 -4
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +18 -21
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +5 -4
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +45 -75
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +3 -4
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +72 -102
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +0 -1
- package/build/plugins/SpecialAssetHandlingPlugin.js +2 -5
- package/build/plugins/UnifiedLoaderGenerator.js +28 -0
- package/build/plugins/WPMLConfigBuilder.d.ts +3 -1
- package/build/plugins/WPMLConfigBuilder.js +7 -4
- package/build/shared.d.ts +3 -2
- package/build/utils/common-config-helpers.d.ts +5 -3
- package/build/utils/common-config-helpers.js +11 -31
- package/build/wordpress-scripts-wrapper.js +106 -102
- package/package.json +1 -2
|
@@ -18,87 +18,14 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibrar
|
|
|
18
18
|
handlePrefix;
|
|
19
19
|
useUnifiedLoader;
|
|
20
20
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore([], "Plain");
|
|
21
|
-
constructor(buildRoot, outputDir, usageLocations, handlePrefix, useUnifiedLoader, context, entry) {
|
|
22
|
-
super("plain-entrypoints-v2", [PlainEntrypointsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
21
|
+
constructor(config, buildRoot, outputDir, usageLocations, handlePrefix, useUnifiedLoader, context, entry) {
|
|
22
|
+
super(config, "plain-entrypoints-v2", [PlainEntrypointsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
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
28
|
}
|
|
29
|
-
apply(compiler) {
|
|
30
|
-
super.apply(compiler);
|
|
31
|
-
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
32
|
-
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, additionalAssets: true }, async (assets) => {
|
|
33
|
-
if (!("assets.json" in assets)) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const rawAssetDataSource = assets["assets.json"]?.source();
|
|
38
|
-
if (typeof rawAssetDataSource !== 'string') {
|
|
39
|
-
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.reject(this.id);
|
|
40
|
-
compilation.errors.push(new Error("assets.json is unexpectedly missing or not a string"));
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const assetDataSource = JSON.parse(rawAssetDataSource);
|
|
44
|
-
if (!(0, shared_1.isRawAssetData)(assetDataSource)) {
|
|
45
|
-
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.reject(this.id);
|
|
46
|
-
compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const isScriptRegex = /\.m?[jt]sx?(\?|$)/i;
|
|
50
|
-
const myAssetHandles = [];
|
|
51
|
-
for (const { entrypoint, srcPath } of this.getRelevantEntrypoints(compilation)) {
|
|
52
|
-
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
53
|
-
const assetData = entrypointChunk.files.values()
|
|
54
|
-
.map(file => assetDataSource[file]).find(v => v !== undefined);
|
|
55
|
-
if (!assetData) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
const handles = [];
|
|
59
|
-
const entrypointChunkIsScript = isScriptRegex.test(srcPath);
|
|
60
|
-
const chunkFiles = entrypoint.chunks.flatMap(chunk => {
|
|
61
|
-
return [...chunk.files].filter(file => entrypointChunkIsScript || !isScriptRegex.test(file))
|
|
62
|
-
.map(file => [file, chunk === entrypointChunk]);
|
|
63
|
-
});
|
|
64
|
-
if (chunkFiles.length === 1) {
|
|
65
|
-
chunkFiles[0][1] = true;
|
|
66
|
-
}
|
|
67
|
-
for (const [file, useHandleName] of chunkFiles) {
|
|
68
|
-
const extension = node_path_1.default.extname(file).toLowerCase();
|
|
69
|
-
const type = extension === ".js" ? 'script' : (extension === ".mjs" ? 'script_module' : 'style');
|
|
70
|
-
const isScript = type !== 'style';
|
|
71
|
-
const dependencies = isScript === entrypointChunkIsScript ? assetData.dependencies : [];
|
|
72
|
-
const rest = isScript && this.usageLocations.registerScriptArgs !== undefined
|
|
73
|
-
? [dependencies, assetData.version, this.usageLocations.registerScriptArgs] : [dependencies, assetData.version];
|
|
74
|
-
const destPath = node_path_1.default.join(compilation.outputOptions.path, file);
|
|
75
|
-
handles.push({
|
|
76
|
-
src: destPath, rest, type,
|
|
77
|
-
locations: this.usageLocations,
|
|
78
|
-
handleName: useHandleName ? this.usageLocations.handle : undefined,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
myAssetHandles.push({
|
|
82
|
-
handles,
|
|
83
|
-
handlePrefix: this.handlePrefix
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myAssetHandles);
|
|
87
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myAssetHandles.length
|
|
88
|
-
? { group: this.libraryType, requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';") }
|
|
89
|
-
: undefined);
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
|
-
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.reject(this.id);
|
|
93
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reject(this.id);
|
|
94
|
-
throw e;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
98
|
-
compilation.deleteAsset("assets.json");
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
29
|
generatePlainEntrypointsLoader(compilation, assets) {
|
|
103
30
|
const emitDir = node_path_1.default.join(this.buildRoot, this.outputDir);
|
|
104
31
|
const handleLists = {
|
|
@@ -238,5 +165,48 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibrar
|
|
|
238
165
|
this.generatePlainEntrypointsLoader(compilation, (await PlainEntrypointsConfigFileGeneratorPlugin.semaphore.wait()).flat());
|
|
239
166
|
});
|
|
240
167
|
}
|
|
168
|
+
processAssets(compilation, rawAssetData) {
|
|
169
|
+
const isScriptRegex = /\.m?[jt]sx?(\?|$)/i;
|
|
170
|
+
const myAssetHandles = [];
|
|
171
|
+
for (const { entrypoint, srcPath } of this.getRelevantEntrypoints(compilation)) {
|
|
172
|
+
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
173
|
+
const assetData = entrypointChunk.files.values()
|
|
174
|
+
.map(file => rawAssetData[file]).find(v => v !== undefined);
|
|
175
|
+
if (!assetData) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const handles = [];
|
|
179
|
+
const entrypointChunkIsScript = isScriptRegex.test(srcPath);
|
|
180
|
+
const chunkFiles = entrypoint.chunks.flatMap(chunk => {
|
|
181
|
+
return [...chunk.files].filter(file => entrypointChunkIsScript || !isScriptRegex.test(file))
|
|
182
|
+
.map(file => [file, chunk === entrypointChunk]);
|
|
183
|
+
});
|
|
184
|
+
if (chunkFiles.length === 1) {
|
|
185
|
+
chunkFiles[0][1] = true;
|
|
186
|
+
}
|
|
187
|
+
for (const [file, useHandleName] of chunkFiles) {
|
|
188
|
+
const extension = node_path_1.default.extname(file).toLowerCase();
|
|
189
|
+
const type = extension === ".js" ? 'script' : (extension === ".mjs" ? 'script_module' : 'style');
|
|
190
|
+
const isScript = type !== 'style';
|
|
191
|
+
const dependencies = isScript === entrypointChunkIsScript ? assetData.dependencies : [];
|
|
192
|
+
const rest = isScript && this.usageLocations.registerScriptArgs !== undefined
|
|
193
|
+
? [dependencies, assetData.version, this.usageLocations.registerScriptArgs] : [dependencies, assetData.version];
|
|
194
|
+
const destPath = node_path_1.default.join(compilation.outputOptions.path, file);
|
|
195
|
+
handles.push({
|
|
196
|
+
src: destPath, rest, type,
|
|
197
|
+
locations: this.usageLocations,
|
|
198
|
+
handleName: useHandleName ? this.usageLocations.handle : undefined,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
myAssetHandles.push({
|
|
202
|
+
handles,
|
|
203
|
+
handlePrefix: this.handlePrefix
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myAssetHandles);
|
|
207
|
+
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myAssetHandles.length
|
|
208
|
+
? { group: this.libraryType, requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';") }
|
|
209
|
+
: undefined);
|
|
210
|
+
}
|
|
241
211
|
}
|
|
242
212
|
exports.PlainEntrypointsConfigFileGeneratorPlugin = PlainEntrypointsConfigFileGeneratorPlugin;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
|
|
2
|
-
import { UnpackedBlockEntrypointInfo } from "../shared";
|
|
2
|
+
import { RawAssetData, UnpackedBlockEntrypointInfo } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
|
-
import { Compilation
|
|
4
|
+
import { Compilation } from "webpack";
|
|
5
5
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
6
6
|
export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
|
|
7
|
-
private readonly config;
|
|
8
7
|
private readonly blocksDest;
|
|
9
8
|
private readonly webpackRemoveEmptyScriptsPlugin;
|
|
10
9
|
private static readonly semaphore;
|
|
11
10
|
constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
|
|
12
|
-
|
|
11
|
+
protected processAssets(compilation: Compilation, rawAssetData: RawAssetData): Promise<void>;
|
|
13
12
|
private emitBlockLoaderFile;
|
|
14
13
|
private transformBlocks;
|
|
15
14
|
private static extractAssetSource;
|
|
@@ -15,121 +15,91 @@ const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
|
15
15
|
const webpack_1 = require("webpack");
|
|
16
16
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
17
17
|
class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin_1.AbstractMultiPhaseLibraryAndEntryPlugin {
|
|
18
|
-
config;
|
|
19
18
|
blocksDest;
|
|
20
19
|
webpackRemoveEmptyScriptsPlugin;
|
|
21
20
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore({ collatableWorkableBlockInfo: {}, blocksDest: "", emittingWpmlXml: false }, "Block JSON v3");
|
|
22
21
|
constructor(config, blocksDest, webpackRemoveEmptyScriptsPlugin, context, entry) {
|
|
23
|
-
super(`block-json-${blocksDest}`, [PlainEntrypointsStyleBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
24
|
-
this.config = config;
|
|
22
|
+
super(config, `block-json-${blocksDest}`, [PlainEntrypointsStyleBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
25
23
|
this.blocksDest = blocksDest;
|
|
26
24
|
this.webpackRemoveEmptyScriptsPlugin = webpackRemoveEmptyScriptsPlugin;
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
async processAssets(compilation, rawAssetData) {
|
|
27
|
+
const applicableBlockJsonFiles = {};
|
|
28
|
+
const blockJsonOriginToOutputMapping = {};
|
|
29
|
+
const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
|
|
30
|
+
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
31
|
+
if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || metadata !== "block-json-inclusion-assurance") {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
35
|
+
for (const danglingBlockJsFile of [...entrypointChunk.files, ...entrypointChunk.auxiliaryFiles]) {
|
|
36
|
+
if (!danglingBlockJsFile.endsWith("block.json")) {
|
|
37
|
+
compilation.deleteAsset(danglingBlockJsFile);
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const applicableBlockJsonFiles = {};
|
|
49
|
-
const blockJsonOriginToOutputMapping = {};
|
|
50
|
-
const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
|
|
51
|
-
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
52
|
-
if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || metadata !== "block-json-inclusion-assurance") {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
56
|
-
for (const danglingBlockJsFile of [...entrypointChunk.files, ...entrypointChunk.auxiliaryFiles]) {
|
|
57
|
-
if (!danglingBlockJsFile.endsWith("block.json")) {
|
|
58
|
-
compilation.deleteAsset(danglingBlockJsFile);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypointChunk)][0]?.originalSource();
|
|
62
|
-
if (asset) {
|
|
63
|
-
//TODO: Can we guarantee that entrypoint.name is always non-null?
|
|
64
|
-
const epBlockJson = entrypoint.name + ".json";
|
|
65
|
-
if (!applicableBlockJsonFiles[epBlockJson]) {
|
|
66
|
-
const blockJsonText = PlainEntrypointsStyleBlockJSONPlugin.extractAssetSource(compilation, epBlockJson)
|
|
67
|
-
?? await promises_1.default.readFile(srcPath, 'utf-8');
|
|
68
|
-
if (!blockJsonText) {
|
|
69
|
-
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`Unable to extract the source for ${epBlockJson}`, srcPath));
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
applicableBlockJsonFiles[epBlockJson] = { sourcePath: srcPath, workableBlockEntrypointsInfo: [], blockJsonText };
|
|
73
|
-
}
|
|
74
|
-
blockJsonOriginToOutputMapping[srcPath] = epBlockJson;
|
|
75
|
-
}
|
|
39
|
+
}
|
|
40
|
+
const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypointChunk)][0]?.originalSource();
|
|
41
|
+
if (asset) {
|
|
42
|
+
//TODO: Can we guarantee that entrypoint.name is always non-null?
|
|
43
|
+
const epBlockJson = entrypoint.name + ".json";
|
|
44
|
+
if (!applicableBlockJsonFiles[epBlockJson]) {
|
|
45
|
+
const blockJsonText = PlainEntrypointsStyleBlockJSONPlugin.extractAssetSource(compilation, epBlockJson)
|
|
46
|
+
?? await promises_1.default.readFile(srcPath, 'utf-8');
|
|
47
|
+
if (!blockJsonText) {
|
|
48
|
+
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`Unable to extract the source for ${epBlockJson}`, srcPath));
|
|
49
|
+
continue;
|
|
76
50
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
applicableBlockJsonFiles[epBlockJson] = { sourcePath: workableBlockEntrypointsInfo[0]?.blockJsonOrigin, workableBlockEntrypointsInfo };
|
|
112
|
-
}
|
|
113
|
-
}
|
|
51
|
+
applicableBlockJsonFiles[epBlockJson] = { sourcePath: srcPath, workableBlockEntrypointsInfo: [], blockJsonText };
|
|
52
|
+
}
|
|
53
|
+
blockJsonOriginToOutputMapping[srcPath] = epBlockJson;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
57
|
+
if (node_path_1.default.basename(srcPath).toLowerCase() === "block.json" || typeof metadata === 'string') {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
61
|
+
const epBlockJson = entrypointChunk.auxiliaryFiles.values().find(auxFile => node_path_1.default.basename(auxFile) === "block.json")
|
|
62
|
+
?? blockJsonOriginToOutputMapping[metadata.blockJsonOrigin];
|
|
63
|
+
if (epBlockJson) {
|
|
64
|
+
//TODO: Do we need to handle a single entrypoint potentially emitting multiple primary files?
|
|
65
|
+
const assetData = entrypointChunk.files.values().map(file => rawAssetData[file])
|
|
66
|
+
.find(assetData => assetData !== undefined);
|
|
67
|
+
if (!assetData) {
|
|
68
|
+
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const workableBlockEntrypointsInfo = entrypoint.getFiles()
|
|
72
|
+
.map(file => this.stripOffBlocksDestPrefix(file))
|
|
73
|
+
.filter(file => !this.webpackRemoveEmptyScriptsPlugin['trash'].includes(node_path_1.default.join(this.blocksDest, file)))
|
|
74
|
+
.map(file => [file, (0, shared_1.scriptOrStyleTest)(file, shared_1.scriptExtension)])
|
|
75
|
+
.filter((item) => item[1] !== '')
|
|
76
|
+
.map(([file, assetType]) => {
|
|
77
|
+
const wasOriginallyAStyleField = (0, shared_1.isStyleField)(metadata.entrypointField);
|
|
78
|
+
if (wasOriginallyAStyleField !== (assetType === "style")) { // This means that the file is extracted
|
|
79
|
+
return {
|
|
80
|
+
...metadata, outputPath: file, assetData, originalValue: undefined, hash: entrypointChunk.hash ?? "",
|
|
81
|
+
entrypointField: (0, shared_1.convertEntrypointFieldForAssetType)(metadata.entrypointField, assetType)
|
|
82
|
+
};
|
|
114
83
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(applicableBlockJsonFiles).length ? {
|
|
121
|
-
group: this.libraryType,
|
|
122
|
-
requiresBaseURI: false,
|
|
123
|
-
action: writer => writer.append(`require_once __DIR__.${php_writer_1.Expr.convertJsonToPHP("/" + node_path_1.default.join(this.blocksDest, "blockdir-loader.php"))};`)
|
|
124
|
-
} : undefined);
|
|
84
|
+
return ({ ...metadata, outputPath: file, assetData, hash: entrypointChunk.hash ?? "" });
|
|
85
|
+
});
|
|
86
|
+
if (applicableBlockJsonFiles[epBlockJson]) {
|
|
87
|
+
applicableBlockJsonFiles[epBlockJson].workableBlockEntrypointsInfo.push(...workableBlockEntrypointsInfo);
|
|
125
88
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reject(this.id);
|
|
129
|
-
throw e;
|
|
89
|
+
else {
|
|
90
|
+
applicableBlockJsonFiles[epBlockJson] = { sourcePath: workableBlockEntrypointsInfo[0]?.blockJsonOrigin, workableBlockEntrypointsInfo };
|
|
130
91
|
}
|
|
131
|
-
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
PlainEntrypointsStyleBlockJSONPlugin.semaphore.resolve(this.id, {
|
|
95
|
+
collatableWorkableBlockInfo: applicableBlockJsonFiles, blocksDest: this.blocksDest,
|
|
96
|
+
emittingWpmlXml: compilation.getAsset(node_path_1.default.join(this.blocksDest, "wpml-config.xml")) !== undefined
|
|
132
97
|
});
|
|
98
|
+
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(applicableBlockJsonFiles).length ? {
|
|
99
|
+
group: this.libraryType,
|
|
100
|
+
requiresBaseURI: false,
|
|
101
|
+
action: writer => writer.append(`require_once __DIR__.${php_writer_1.Expr.convertJsonToPHP("/" + node_path_1.default.join(this.blocksDest, "blockdir-loader.php"))};`)
|
|
102
|
+
} : undefined);
|
|
133
103
|
}
|
|
134
104
|
emitBlockLoaderFile(compilation, blockData) {
|
|
135
105
|
if (this.config.useUnifiedLoader) {
|
|
@@ -2,7 +2,6 @@ import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-conf
|
|
|
2
2
|
import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
|
|
3
3
|
import { Compilation, type Compiler } from "webpack";
|
|
4
4
|
export declare class SpecialAssetHandlingPlugin extends AbstractMultiPhaseLibraryPlugin {
|
|
5
|
-
private readonly config;
|
|
6
5
|
private static readonly semaphore;
|
|
7
6
|
private static validPathname?;
|
|
8
7
|
constructor(config: VerifiedPlauditWordpressWebpackConfig);
|
|
@@ -12,12 +12,10 @@ const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPl
|
|
|
12
12
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
13
13
|
const webpack_1 = require("webpack");
|
|
14
14
|
class SpecialAssetHandlingPlugin extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
|
|
15
|
-
config;
|
|
16
15
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore({}, "Special");
|
|
17
16
|
static validPathname = undefined;
|
|
18
17
|
constructor(config) {
|
|
19
|
-
super("special-assets", [SpecialAssetHandlingPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
20
|
-
this.config = config;
|
|
18
|
+
super(config, "special-assets", [SpecialAssetHandlingPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
21
19
|
}
|
|
22
20
|
apply(compiler) {
|
|
23
21
|
if (!this.config.useWebpackResourceFiltering) {
|
|
@@ -59,8 +57,7 @@ class SpecialAssetHandlingPlugin extends AbstractMultiPhaseLibraryPlugin_1.Abstr
|
|
|
59
57
|
: undefined);
|
|
60
58
|
}
|
|
61
59
|
catch (e) {
|
|
62
|
-
|
|
63
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reject(this.id);
|
|
60
|
+
this.rejectSemaphores();
|
|
64
61
|
throw e;
|
|
65
62
|
}
|
|
66
63
|
});
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.UnifiedLoaderGenerator = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
4
8
|
const shared_1 = require("../shared");
|
|
5
9
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
6
10
|
const php_writer_1 = require("../utils/php-writer");
|
|
@@ -15,6 +19,30 @@ class UnifiedLoaderGenerator {
|
|
|
15
19
|
this.id = Math.random().toString();
|
|
16
20
|
}
|
|
17
21
|
apply(compiler) {
|
|
22
|
+
compiler.hooks.compilation.tap(`${this.constructor.name}_Cleanup`, compilation => {
|
|
23
|
+
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
24
|
+
if (!this.config.useUnifiedLoader) {
|
|
25
|
+
const rawAssetDataSource = compilation.assets["assets.json"]?.source();
|
|
26
|
+
if (typeof rawAssetDataSource !== 'string') {
|
|
27
|
+
compilation.errors.push(new Error("assets.json is unexpectedly missing or not a string"));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const rawAssetData = JSON.parse(rawAssetDataSource);
|
|
31
|
+
if (!(0, shared_1.isRawAssetData)(rawAssetData)) {
|
|
32
|
+
compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const [file, assetData] of Object.entries(rawAssetData)) {
|
|
36
|
+
const escapedDependencies = assetData.dependencies.map(php_writer_1.Expr.convertJsonToPHP).join(", ");
|
|
37
|
+
const contents = `<?php return ['dependencies' => [${escapedDependencies}], 'version' => ${php_writer_1.Expr.convertJsonToPHP(assetData.version)}];\n`;
|
|
38
|
+
const parsedPath = node_path_1.default.parse(file);
|
|
39
|
+
const assetPHPFile = node_path_1.default.join(parsedPath.dir, parsedPath.name) + ".asset.php";
|
|
40
|
+
compilation.emitAsset(assetPHPFile, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
compilation.deleteAsset("assets.json");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
18
46
|
if (!this.config.useUnifiedLoader) {
|
|
19
47
|
return;
|
|
20
48
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { AbstractMultiPhaseLibraryAndEntryPlugin } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
|
|
1
2
|
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
2
3
|
export declare class WPMLConfigBuilderPlugin implements WebpackPluginInstance {
|
|
3
4
|
private readonly destDir;
|
|
5
|
+
private readonly referencePlugin;
|
|
4
6
|
private static jsdomInstance?;
|
|
5
7
|
private static domParser?;
|
|
6
8
|
private static xmlSerializer?;
|
|
7
9
|
private readonly parsedDocumentsCache;
|
|
8
|
-
constructor(destDir: string);
|
|
10
|
+
constructor(destDir: string, referencePlugin: AbstractMultiPhaseLibraryAndEntryPlugin<any>);
|
|
9
11
|
apply(compiler: Compiler): void;
|
|
10
12
|
private static getJSDOMInstance;
|
|
11
13
|
private static getDOMParser;
|
|
@@ -12,26 +12,29 @@ const webpack_1 = require("webpack");
|
|
|
12
12
|
const xml_formatter_1 = __importDefault(require("xml-formatter"));
|
|
13
13
|
class WPMLConfigBuilderPlugin {
|
|
14
14
|
destDir;
|
|
15
|
+
referencePlugin;
|
|
15
16
|
static jsdomInstance;
|
|
16
17
|
static domParser;
|
|
17
18
|
static xmlSerializer;
|
|
18
19
|
parsedDocumentsCache = new Map();
|
|
19
|
-
constructor(destDir) {
|
|
20
|
+
constructor(destDir, referencePlugin) {
|
|
20
21
|
this.destDir = destDir;
|
|
22
|
+
this.referencePlugin = referencePlugin;
|
|
21
23
|
}
|
|
22
24
|
apply(compiler) {
|
|
23
|
-
//TODO: Filter by library here as well
|
|
24
25
|
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
25
26
|
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}__processXML`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, async (assets) => {
|
|
26
27
|
const entrypoint = compilation.entrypoints.get("wpml-config.xml");
|
|
27
28
|
if (!entrypoint) {
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
31
|
+
const blockJsonFiles = this.referencePlugin.getRelevantEntrypoints(compilation)
|
|
32
|
+
.map(ep => ep.srcPath)
|
|
33
|
+
.filter(srcPath => srcPath.endsWith("block.json"));
|
|
30
34
|
const files = Promise.all([
|
|
31
35
|
Promise.all(entrypoint.origins.map(origin => origin.request).filter(request => request.endsWith("wpml-config.xml"))
|
|
32
36
|
.map(async (request) => this.loadWPMLConfigXML(request, compilation))),
|
|
33
|
-
Promise.all(
|
|
34
|
-
.map(async (request) => JSON.parse(await promises_1.default.readFile(request, 'utf8'))))
|
|
37
|
+
Promise.all(blockJsonFiles.map(async (request) => JSON.parse(await promises_1.default.readFile(request, 'utf8'))))
|
|
35
38
|
]);
|
|
36
39
|
const wpmlEmitPath = node_path_1.default.join(this.destDir, "wpml-config.xml");
|
|
37
40
|
for (const name of Object.keys(assets)) {
|
package/build/shared.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export type Externals = {
|
|
|
41
41
|
};
|
|
42
42
|
export type AdvancedOutputConfig = {
|
|
43
43
|
destination?: string;
|
|
44
|
-
withLegacyBlocksIn?: string | undefined;
|
|
44
|
+
withLegacyBlocksIn?: string | undefined | false;
|
|
45
45
|
additionalDependencies?: string[];
|
|
46
46
|
directoryLayout?: SourceType;
|
|
47
47
|
assumeGlobalizedPlauditLibraries?: boolean;
|
|
@@ -49,7 +49,8 @@ export type AdvancedOutputConfig = {
|
|
|
49
49
|
bundleAnalyzer?: boolean;
|
|
50
50
|
locations?: UsageLocations | UsageLocations['handle'];
|
|
51
51
|
};
|
|
52
|
-
|
|
52
|
+
type OptionalCfgFields = 'directoryLayout' | 'externalize';
|
|
53
|
+
export type VerifiedAdvancedOutputConfig = Required<Omit<AdvancedOutputConfig, 'locations' | OptionalCfgFields>> & Pick<AdvancedOutputConfig, OptionalCfgFields> & {
|
|
53
54
|
locations: UsageLocations;
|
|
54
55
|
};
|
|
55
56
|
export type PlauditWordpressWebpackConfig = {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { EntryProvider } from "../plugins/AbstractMultiPhaseLibraryAndEntryPlugin";
|
|
1
|
+
import type { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "../plugins/AbstractMultiPhaseLibraryAndEntryPlugin";
|
|
2
|
+
import type { AdditionalDependencyInjectorPlugin } from "../plugins/AdditionalDependencyInjectorPlugin";
|
|
2
3
|
import { EntrypointFields, PlauditWordpressWebpackConfig, UnpackedBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
|
|
3
|
-
import type { Compiler, Configuration, DynamicEntryPlugin,
|
|
4
|
+
import type { Compiler, Configuration, DynamicEntryPlugin, WebpackPluginInstance } from "webpack";
|
|
4
5
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
5
6
|
export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpressWebpackConfig, 'variables' | 'src' | 'externals'>> & {
|
|
6
7
|
variablesFilePath?: string;
|
|
@@ -9,6 +10,7 @@ export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpre
|
|
|
9
10
|
export type CommonPluginConfig = {
|
|
10
11
|
plugins: (WebpackPluginInstance | ((this: Compiler, compiler: Compiler) => void))[];
|
|
11
12
|
removeEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin;
|
|
13
|
+
makeAdditionalDependencyInjectorPlugin(referencePlugin: AbstractMultiPhaseLibraryAndEntryPlugin<any>): AdditionalDependencyInjectorPlugin;
|
|
12
14
|
};
|
|
13
15
|
export type CommonConfigProcessingResult = {
|
|
14
16
|
entrypointFields: EntrypointFields;
|
|
@@ -27,4 +29,4 @@ export type ExtensibleEntryObject<M> = {
|
|
|
27
29
|
};
|
|
28
30
|
};
|
|
29
31
|
export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): EntryProvider<UnpackedBlockEntrypointInfo | string>;
|
|
30
|
-
export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration,
|
|
32
|
+
export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration, externalize: VerifiedAdvancedOutputConfig['externalize'], plugins: CommonPluginConfig['plugins']): Configuration;
|