@plaudit/webpack-extensions 2.64.0 → 2.65.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/AbstractBiPhasicGroupAndEntryPlugin.d.ts +33 -0
- package/build/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +86 -0
- package/build/plugins/AbstractBiPhasicGroupPlugin.d.ts +33 -0
- package/build/plugins/AbstractBiPhasicGroupPlugin.js +93 -0
- package/build/plugins/AdditionalDependencyInjectorPlugin.d.ts +8 -6
- package/build/plugins/AdditionalDependencyInjectorPlugin.js +37 -39
- package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +4 -5
- package/build/plugins/EnhancedDynamicEntryPlugin.js +3 -3
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +9 -8
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +103 -93
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +7 -8
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +10 -17
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +6 -7
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +15 -16
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +6 -6
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +10 -9
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +5 -5
- package/build/plugins/SpecialAssetHandlingPlugin.js +44 -47
- package/build/plugins/UnifiedLoaderGenerator.d.ts +8 -8
- package/build/plugins/UnifiedLoaderGenerator.js +54 -69
- package/build/plugins/WPMLConfigBuilder.d.ts +2 -2
- package/build/shared.d.ts +10 -14
- package/build/shared.js +19 -23
- package/build/utils/common-config-helpers.d.ts +6 -6
- package/build/utils/common-config-helpers.js +11 -8
- package/build/utils/json-to-php-but-with-__-injection.js +1 -1
- package/build/utils/pseduo-semaphore.d.ts +2 -3
- package/build/utils/pseduo-semaphore.js +9 -5
- package/build/wordpress-scripts-wrapper.js +21 -15
- package/package.json +3 -3
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.d.ts +0 -21
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.js +0 -113
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +0 -17
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +0 -44
|
@@ -6,32 +6,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ExtensionsConfigFileGeneratorPlugin = void 0;
|
|
7
7
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const
|
|
9
|
+
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
10
10
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
11
11
|
const shared_1 = require("../shared");
|
|
12
12
|
const php_writer_1 = require("../utils/php-writer");
|
|
13
13
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
14
14
|
const webpack_1 = require("webpack");
|
|
15
|
-
class ExtensionsConfigFileGeneratorPlugin extends
|
|
16
|
-
|
|
15
|
+
class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
16
|
+
extensionsSrcPath;
|
|
17
17
|
dest;
|
|
18
|
-
static semaphore = new pseduo_semaphore_1.PseudoSemaphore(
|
|
19
|
-
|
|
20
|
-
constructor(config,
|
|
18
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Extensions");
|
|
19
|
+
setupFiles = [];
|
|
20
|
+
constructor(config, extensionsSrcPath, dest, context, entry) {
|
|
21
21
|
super(config, `extensions-v2-${dest.destination}`, [ExtensionsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
22
|
-
this.
|
|
22
|
+
this.extensionsSrcPath = extensionsSrcPath;
|
|
23
23
|
this.dest = dest;
|
|
24
24
|
}
|
|
25
|
+
get extensionsDestPath() {
|
|
26
|
+
let extensionsDestPath = this.dest.destination.endsWith("/") ? this.dest.destination : this.dest.destination + "/";
|
|
27
|
+
return !extensionsDestPath.startsWith("/") ? "/" + extensionsDestPath : extensionsDestPath;
|
|
28
|
+
}
|
|
25
29
|
apply(compiler) {
|
|
26
30
|
super.apply(compiler);
|
|
27
31
|
compiler.hooks.make.tapPromise(this.constructor.name, async (compilation) => {
|
|
28
|
-
if (!compilation.contextDependencies.has(this.
|
|
29
|
-
compilation.contextDependencies.add(this.
|
|
32
|
+
if (!compilation.contextDependencies.has(this.extensionsSrcPath)) {
|
|
33
|
+
compilation.contextDependencies.add(this.extensionsSrcPath);
|
|
30
34
|
}
|
|
31
35
|
const emissionPromises = [];
|
|
32
|
-
for await (const { name: setupFilePath } of await promises_1.default.opendir(this.
|
|
36
|
+
for await (const { name: setupFilePath } of await promises_1.default.opendir(this.extensionsSrcPath, { encoding: 'utf-8' })) {
|
|
33
37
|
if (setupFilePath.endsWith("-setup.php")) {
|
|
34
|
-
const setupFileSourcePath = node_path_1.default.join(this.
|
|
38
|
+
const setupFileSourcePath = node_path_1.default.join(this.extensionsSrcPath, setupFilePath);
|
|
35
39
|
compilation.fileDependencies.add(setupFileSourcePath);
|
|
36
40
|
emissionPromises.push(promises_1.default.readFile(setupFileSourcePath).then(contents => {
|
|
37
41
|
compilation.emitAsset(node_path_1.default.join(this.dest.destination, setupFilePath), new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
@@ -40,47 +44,45 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEn
|
|
|
40
44
|
}));
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
|
-
|
|
47
|
+
this.setupFiles = (await Promise.all(emissionPromises))
|
|
44
48
|
.filter((item) => item[0] !== undefined).sort((a, b) => a[0].localeCompare(b[0]));
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
|
-
generateVersionTwoConfigFile(compilation,
|
|
51
|
+
generateVersionTwoConfigFile(compilation, relevantAssetData, setupFilePaths) {
|
|
48
52
|
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
49
53
|
const blockExtensionsConfig = {
|
|
50
54
|
metadata: { version: this.config.extensionsVersion }, scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {}
|
|
51
55
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const blockSlug = match[1], assetType = match[2];
|
|
65
|
-
if (blockSlug && assetType) {
|
|
66
|
-
const key = assetType.replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
|
|
67
|
-
const handle = `plaudit_block-extension_${blockSlug}-${assetType}`;
|
|
68
|
-
const isCss = (0, shared_1.isStyleField)(assetType);
|
|
69
|
-
const handleGroup = isCss ? 'styleHandles'
|
|
70
|
-
: ((0, shared_1.isScriptModuleField)(assetType) ? 'scriptModuleHandles' : 'scriptHandles');
|
|
71
|
-
blockExtensionsConfig[handleGroup][handle] = {
|
|
72
|
-
src: isCss ? assetPath.replace(/\.js$/, ".css") : assetPath,
|
|
73
|
-
rest: isCss || key.startsWith("editor")
|
|
74
|
-
? [assetData.dependencies, assetData.version]
|
|
75
|
-
: [assetData.dependencies, assetData.version, { strategy: 'defer' }]
|
|
76
|
-
};
|
|
77
|
-
(blockExtensionsConfig.blocks[blockSlug] ?? (blockExtensionsConfig.blocks[blockSlug] = {}))[key] = handle;
|
|
78
|
-
}
|
|
56
|
+
const normalizedAssetData = Object.entries(relevantAssetData)
|
|
57
|
+
.map(entry => {
|
|
58
|
+
const assetPath = this.dest.destination && entry[0].startsWith(this.dest.destination + "/")
|
|
59
|
+
? entry[0].substring(this.dest.destination.length + 1) : entry[0];
|
|
60
|
+
return [assetPath, entry[1]];
|
|
61
|
+
});
|
|
62
|
+
for (const [assetPath, assetData] of normalizedAssetData) {
|
|
63
|
+
const match = regex.exec(assetPath);
|
|
64
|
+
if (!match) {
|
|
65
|
+
continue;
|
|
79
66
|
}
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
const blockSlug = match[1], assetType = match[2];
|
|
68
|
+
if (blockSlug && assetType) {
|
|
69
|
+
const key = assetType.replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
|
|
70
|
+
const handle = `plaudit_block-extension_${blockSlug}-${assetType}`;
|
|
71
|
+
const isCss = (0, shared_1.isStyleField)(assetType);
|
|
72
|
+
const handleGroup = isCss ? 'styleHandles'
|
|
73
|
+
: ((0, shared_1.isScriptModuleField)(assetType) ? 'scriptModuleHandles' : 'scriptHandles');
|
|
74
|
+
blockExtensionsConfig[handleGroup][handle] = {
|
|
75
|
+
src: isCss ? assetPath.replace(/\.js$/, ".css") : assetPath,
|
|
76
|
+
rest: isCss || key.startsWith("editor")
|
|
77
|
+
? [assetData.dependencies, assetData.version]
|
|
78
|
+
: [assetData.dependencies, assetData.version, { strategy: 'defer' }]
|
|
79
|
+
};
|
|
80
|
+
(blockExtensionsConfig.blocks[blockSlug] ?? (blockExtensionsConfig.blocks[blockSlug] = {}))[key] = handle;
|
|
82
81
|
}
|
|
83
82
|
}
|
|
83
|
+
for (const [blockSlug, asset] of setupFilePaths) {
|
|
84
|
+
blockExtensionsConfig.setupFiles[blockSlug] = asset;
|
|
85
|
+
}
|
|
84
86
|
blockExtensionsConfig.scriptHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptHandles)
|
|
85
87
|
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
86
88
|
blockExtensionsConfig.scriptModuleHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptModuleHandles)
|
|
@@ -96,63 +98,71 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEn
|
|
|
96
98
|
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
97
99
|
compilation.emitAsset(node_path_1.default.join(this.dest.destination, "mapping.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, true)));
|
|
98
100
|
}
|
|
99
|
-
|
|
100
|
-
compilation.hooks.processAssets.tapPromise({ name:
|
|
101
|
-
const
|
|
102
|
-
.reduce((
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
attachUniquePhase(compilation) {
|
|
102
|
+
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
103
|
+
const plugins = Object.values((await ExtensionsConfigFileGeneratorPlugin.semaphore.wait())
|
|
104
|
+
.reduce((acc, cur) => {
|
|
105
|
+
const accValue = acc[cur.plugin.group];
|
|
106
|
+
if (accValue === undefined) {
|
|
107
|
+
acc[cur.plugin.group] = { ...cur, setupFiles: cur.setupFiles?.length ? [...cur.setupFiles] : [] };
|
|
108
|
+
return acc;
|
|
109
|
+
}
|
|
110
|
+
if (cur.relevantAssetData) {
|
|
111
|
+
accValue.relevantAssetData = { ...accValue.relevantAssetData, ...cur.relevantAssetData };
|
|
112
|
+
}
|
|
113
|
+
if (cur.setupFiles?.length) {
|
|
114
|
+
accValue.setupFiles.push(...cur.setupFiles);
|
|
115
|
+
}
|
|
116
|
+
return acc;
|
|
117
|
+
}, {}))
|
|
118
|
+
.sort((a, b) => a.plugin.group.localeCompare(b.plugin.group));
|
|
119
|
+
for (const { plugin, relevantAssetData, setupFiles } of plugins) {
|
|
120
|
+
plugin.generateVersionTwoConfigFile(compilation, relevantAssetData, setupFiles);
|
|
109
121
|
}
|
|
110
122
|
});
|
|
111
123
|
}
|
|
112
124
|
processAssets(compilation, rawAssetData) {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
]);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const potentialHandle = this.dest.locations?.handle;
|
|
139
|
-
if (potentialHandle) {
|
|
140
|
-
if (typeof potentialHandle === 'string') {
|
|
141
|
-
try {
|
|
142
|
-
writer.function(potentialHandle, [], generateLoader, { returnType: 'void' });
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for dynamically loading extensions", { cause: e }], this.extensionsPath));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
compilation.errors.push(new Error("The extensions directoryLayout's handle support is limited to static strings"));
|
|
151
|
-
}
|
|
125
|
+
const relevantAssetData = this.extractRelevantAssetData(compilation, rawAssetData);
|
|
126
|
+
const staticallyLoadedEntrypoints = Object.keys(relevantAssetData);
|
|
127
|
+
const generateLoader = (writer) => {
|
|
128
|
+
const filePathPrefixVar = new php_writer_1.Var("filePathPrefix");
|
|
129
|
+
const fileUriPrefixVar = new php_writer_1.Var("fileUriPrefix");
|
|
130
|
+
writer
|
|
131
|
+
.assign(filePathPrefixVar, new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(this.extensionsDestPath)}`))
|
|
132
|
+
.call("plaudit_webpack_extensions__resolve_base_uri", [filePathPrefixVar], { assignTo: fileUriPrefixVar })
|
|
133
|
+
.call("GutenbergUtils::loadExtensionsV2", [
|
|
134
|
+
new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(this.extensionsDestPath + "mapping.config.php")}`),
|
|
135
|
+
filePathPrefixVar, fileUriPrefixVar,
|
|
136
|
+
`${this.config.plainEntrypointsHandlePrefix || node_path_1.default.basename(process.cwd())}_extension_`
|
|
137
|
+
]);
|
|
138
|
+
};
|
|
139
|
+
let action;
|
|
140
|
+
const potentialHandle = this.dest.locations?.handle;
|
|
141
|
+
if (potentialHandle) {
|
|
142
|
+
if (typeof potentialHandle === 'string') {
|
|
143
|
+
try {
|
|
144
|
+
action = writer => writer.use("Plaudit\\Common\\Lib\\GutenbergUtils").function(potentialHandle, [], generateLoader, { returnType: 'void' });
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for dynamically loading extensions", { cause: e }], this.extensionsSrcPath));
|
|
148
|
+
this.rejectSemaphores();
|
|
149
|
+
return;
|
|
152
150
|
}
|
|
153
|
-
writer.withScope(generateLoader);
|
|
154
151
|
}
|
|
155
|
-
|
|
152
|
+
else {
|
|
153
|
+
compilation.errors.push(new Error("The extensions directoryLayout's handle support is limited to static strings"));
|
|
154
|
+
this.rejectSemaphores();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
action = writer => writer.use("Plaudit\\Common\\Lib\\GutenbergUtils").withScope(generateLoader);
|
|
160
|
+
}
|
|
161
|
+
const myCacheData = { plugin: this, setupFiles: this.setupFiles, relevantAssetData };
|
|
162
|
+
ExtensionsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myCacheData);
|
|
163
|
+
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, this.setupFiles.length > 0 || staticallyLoadedEntrypoints.length > 0
|
|
164
|
+
? { group: this.group, requiresBaseURI: true, action, staticallyLoadedEntrypoints }
|
|
165
|
+
: undefined);
|
|
156
166
|
}
|
|
157
167
|
}
|
|
158
168
|
exports.ExtensionsConfigFileGeneratorPlugin = ExtensionsConfigFileGeneratorPlugin;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
+
import type { ParsedAssetsJson } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
|
-
import { Compilation
|
|
5
|
-
export declare class ExtensionsConfigFileGeneratorPluginV1 extends
|
|
4
|
+
import { Compilation } from "webpack";
|
|
5
|
+
export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin {
|
|
6
6
|
private readonly extensionsDest;
|
|
7
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsDest: string, context: string, entry: EntryProvider
|
|
8
|
-
|
|
9
|
-
protected
|
|
10
|
-
protected processAssets(compilation: Compilation, rawAssetData: RawAssetData): void;
|
|
7
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsDest: string, context: string, entry: EntryProvider);
|
|
8
|
+
protected attachUniquePhase(): void;
|
|
9
|
+
protected processAssets(compilation: Compilation, assetsJson: ParsedAssetsJson): void;
|
|
11
10
|
}
|
|
@@ -5,34 +5,22 @@ 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
|
|
8
|
+
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
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
|
|
13
|
+
class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
14
14
|
extensionsDest;
|
|
15
15
|
constructor(config, extensionsDest, context, entry) {
|
|
16
16
|
super(config, `extensions-v1-${extensionsDest}`, [UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
17
17
|
this.extensionsDest = extensionsDest;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
});
|
|
30
|
-
}
|
|
31
|
-
attachSecondPhase() { }
|
|
32
|
-
processAssets(compilation, rawAssetData) {
|
|
19
|
+
attachUniquePhase() { }
|
|
20
|
+
processAssets(compilation, assetsJson) {
|
|
33
21
|
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
34
22
|
const mapping = {};
|
|
35
|
-
for (const fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation,
|
|
23
|
+
for (const fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation, assetsJson))) {
|
|
36
24
|
let match;
|
|
37
25
|
if ((match = regex.exec(fileWithAssetData)) && match[1] && match[2]) {
|
|
38
26
|
const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
|
|
@@ -41,6 +29,11 @@ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryAnd
|
|
|
41
29
|
}
|
|
42
30
|
}
|
|
43
31
|
compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config"), new webpack_1.sources.RawSource((0, php_serializer_1.phpSerialize)(mapping)));
|
|
32
|
+
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, { group: `extensions-config-v1-${this.extensionsDest}`, requiresBaseURI: false, action: writer => {
|
|
33
|
+
writer
|
|
34
|
+
.use("Plaudit\\Common\\Lib\\GutenbergUtils")
|
|
35
|
+
.call("GutenbergUtils::installExtensionsSupport", [php_writer_1.Op.join(php_writer_1.Constants.__DIR__, this.extensionsDest)]);
|
|
36
|
+
} });
|
|
44
37
|
}
|
|
45
38
|
}
|
|
46
39
|
exports.ExtensionsConfigFileGeneratorPluginV1 = ExtensionsConfigFileGeneratorPluginV1;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParsedAssetsJson, BlockEntrypointInfo, UsageLocations } from "../shared";
|
|
2
2
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
3
|
-
import {
|
|
3
|
+
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
4
4
|
import { Compilation } from "webpack";
|
|
5
|
-
export declare class PlainEntrypointsConfigFileGeneratorPlugin extends
|
|
5
|
+
export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
|
|
6
6
|
private readonly buildRoot;
|
|
7
7
|
private readonly outputDir;
|
|
8
8
|
private readonly usageLocations;
|
|
9
|
-
private readonly handlePrefix;
|
|
10
9
|
private readonly useUnifiedLoader;
|
|
11
10
|
private static readonly semaphore;
|
|
12
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: UsageLocations,
|
|
11
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: UsageLocations, useUnifiedLoader: boolean, context: string, entry: EntryProvider<BlockEntrypointInfo>);
|
|
13
12
|
private generatePlainEntrypointsLoader;
|
|
14
13
|
private static addHandlesToHandleLists;
|
|
15
14
|
private static appendEnqueuingHandleLists;
|
|
16
15
|
private static separateHandleListByPriority;
|
|
17
|
-
protected
|
|
18
|
-
protected processAssets(compilation: Compilation,
|
|
16
|
+
protected attachUniquePhase(compilation: Compilation): void;
|
|
17
|
+
protected processAssets(compilation: Compilation, assetsJson: ParsedAssetsJson): void;
|
|
19
18
|
}
|
|
@@ -8,22 +8,20 @@ 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 AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
12
12
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
13
13
|
const webpack_1 = require("webpack");
|
|
14
|
-
class PlainEntrypointsConfigFileGeneratorPlugin extends
|
|
14
|
+
class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
15
15
|
buildRoot;
|
|
16
16
|
outputDir;
|
|
17
17
|
usageLocations;
|
|
18
|
-
handlePrefix;
|
|
19
18
|
useUnifiedLoader;
|
|
20
|
-
static semaphore = new pseduo_semaphore_1.PseudoSemaphore(
|
|
21
|
-
constructor(config, buildRoot, outputDir, usageLocations,
|
|
19
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Plain");
|
|
20
|
+
constructor(config, buildRoot, outputDir, usageLocations, useUnifiedLoader, context, entry) {
|
|
22
21
|
super(config, "plain-entrypoints-v2", [PlainEntrypointsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
23
22
|
this.buildRoot = buildRoot;
|
|
24
23
|
this.outputDir = outputDir;
|
|
25
24
|
this.usageLocations = usageLocations;
|
|
26
|
-
this.handlePrefix = handlePrefix;
|
|
27
25
|
this.useUnifiedLoader = useUnifiedLoader;
|
|
28
26
|
}
|
|
29
27
|
generatePlainEntrypointsLoader(compilation, assets) {
|
|
@@ -160,18 +158,19 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibrar
|
|
|
160
158
|
}
|
|
161
159
|
return lists.entries().toArray().sort((a, b) => a[0] - b[0]);
|
|
162
160
|
}
|
|
163
|
-
|
|
164
|
-
compilation.hooks.processAssets.tapPromise({ name:
|
|
161
|
+
attachUniquePhase(compilation) {
|
|
162
|
+
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
165
163
|
this.generatePlainEntrypointsLoader(compilation, (await PlainEntrypointsConfigFileGeneratorPlugin.semaphore.wait()).flat());
|
|
166
164
|
});
|
|
167
165
|
}
|
|
168
|
-
processAssets(compilation,
|
|
166
|
+
processAssets(compilation, assetsJson) {
|
|
169
167
|
const isScriptRegex = /\.m?[jt]sx?(\?|$)/i;
|
|
170
168
|
const myAssetHandles = [];
|
|
171
|
-
|
|
169
|
+
const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
|
|
170
|
+
for (const { entrypoint, srcPath } of relevantEntrypoints) {
|
|
172
171
|
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
173
172
|
const assetData = entrypointChunk.files.values()
|
|
174
|
-
.map(file =>
|
|
173
|
+
.map(file => assetsJson[file]).find(v => v !== undefined);
|
|
175
174
|
if (!assetData) {
|
|
176
175
|
continue;
|
|
177
176
|
}
|
|
@@ -198,14 +197,14 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibrar
|
|
|
198
197
|
handleName: useHandleName ? this.usageLocations.handle : undefined,
|
|
199
198
|
});
|
|
200
199
|
}
|
|
201
|
-
myAssetHandles.push({
|
|
202
|
-
handles,
|
|
203
|
-
handlePrefix: this.handlePrefix
|
|
204
|
-
});
|
|
200
|
+
myAssetHandles.push({ handles, handlePrefix: this.config.plainEntrypointsHandlePrefix });
|
|
205
201
|
}
|
|
206
202
|
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myAssetHandles);
|
|
207
203
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myAssetHandles.length
|
|
208
|
-
? {
|
|
204
|
+
? {
|
|
205
|
+
group: this.group, requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';"),
|
|
206
|
+
staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray())
|
|
207
|
+
}
|
|
209
208
|
: undefined);
|
|
210
209
|
}
|
|
211
210
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
+
import { ParsedAssetsJson, BlockEntrypointInfo } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
4
|
import { Compilation } from "webpack";
|
|
5
5
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
6
|
-
export declare class PlainEntrypointsStyleBlockJSONPlugin extends
|
|
6
|
+
export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
|
|
7
7
|
private readonly blocksDest;
|
|
8
8
|
private readonly webpackRemoveEmptyScriptsPlugin;
|
|
9
9
|
private static readonly semaphore;
|
|
10
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<
|
|
11
|
-
protected processAssets(compilation: Compilation, rawAssetData:
|
|
10
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<BlockEntrypointInfo>);
|
|
11
|
+
protected processAssets(compilation: Compilation, rawAssetData: ParsedAssetsJson): Promise<void>;
|
|
12
12
|
private emitBlockLoaderFile;
|
|
13
13
|
private transformBlocks;
|
|
14
14
|
private static extractAssetSource;
|
|
@@ -21,5 +21,5 @@ export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiP
|
|
|
21
21
|
static findRelativeRouteBetween(path1: string, path2: string): string;
|
|
22
22
|
private static remapReferencedPHPFilesOnKey;
|
|
23
23
|
private static normalizeRenderTemplate;
|
|
24
|
-
protected
|
|
24
|
+
protected attachUniquePhase(compilation: Compilation): void;
|
|
25
25
|
}
|
|
@@ -7,17 +7,17 @@ exports.PlainEntrypointsStyleBlockJSONPlugin = void 0;
|
|
|
7
7
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
-
const
|
|
10
|
+
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
11
11
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
12
12
|
const shared_1 = require("../shared");
|
|
13
13
|
const php_writer_1 = require("../utils/php-writer");
|
|
14
14
|
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
|
-
class PlainEntrypointsStyleBlockJSONPlugin extends
|
|
17
|
+
class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
18
18
|
blocksDest;
|
|
19
19
|
webpackRemoveEmptyScriptsPlugin;
|
|
20
|
-
static semaphore = new pseduo_semaphore_1.PseudoSemaphore(
|
|
20
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Block JSON v3");
|
|
21
21
|
constructor(config, blocksDest, webpackRemoveEmptyScriptsPlugin, context, entry) {
|
|
22
22
|
super(config, `block-json-${blocksDest}`, [PlainEntrypointsStyleBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
23
23
|
this.blocksDest = blocksDest;
|
|
@@ -26,9 +26,9 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
26
26
|
async processAssets(compilation, rawAssetData) {
|
|
27
27
|
const applicableBlockJsonFiles = {};
|
|
28
28
|
const blockJsonOriginToOutputMapping = {};
|
|
29
|
-
const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
|
|
29
|
+
const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
|
|
30
30
|
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
31
|
-
if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || metadata !== "block-json-inclusion-assurance") {
|
|
31
|
+
if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
34
|
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
@@ -54,7 +54,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
57
|
-
if (node_path_1.default.basename(srcPath).toLowerCase() === "block.json" ||
|
|
57
|
+
if (node_path_1.default.basename(srcPath).toLowerCase() === "block.json" || 'purpose' in metadata) {
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
60
|
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
@@ -96,8 +96,9 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
96
96
|
emittingWpmlXml: compilation.getAsset(node_path_1.default.join(this.blocksDest, "wpml-config.xml")) !== undefined
|
|
97
97
|
});
|
|
98
98
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(applicableBlockJsonFiles).length ? {
|
|
99
|
-
group: this.
|
|
99
|
+
group: this.group,
|
|
100
100
|
requiresBaseURI: false,
|
|
101
|
+
staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray()),
|
|
101
102
|
action: writer => writer.append(`require_once __DIR__.${php_writer_1.Expr.convertJsonToPHP("/" + node_path_1.default.join(this.blocksDest, "blockdir-loader.php"))};`)
|
|
102
103
|
} : undefined);
|
|
103
104
|
}
|
|
@@ -136,7 +137,6 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
136
137
|
const pathsNeedRemapping = !this.config.standaloneBlocks && blockJson["plaudit"] !== "simple";
|
|
137
138
|
PlainEntrypointsStyleBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "setup", pathsNeedRemapping, sourceDir, outputDir, compilation, true);
|
|
138
139
|
PlainEntrypointsStyleBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "variations", pathsNeedRemapping, sourceDir, outputDir, compilation, false);
|
|
139
|
-
PlainEntrypointsStyleBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
|
|
140
140
|
const hashForVersion = PlainEntrypointsStyleBlockJSONPlugin
|
|
141
141
|
.hashThingForAsset([blockJsonText, ...workableBlockEntrypointsInfo.map(bi => bi.hash)].join("~"));
|
|
142
142
|
if (blockJson["version"]) {
|
|
@@ -145,6 +145,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
145
145
|
else {
|
|
146
146
|
blockJson["version"] = hashForVersion;
|
|
147
147
|
}
|
|
148
|
+
PlainEntrypointsStyleBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
|
|
148
149
|
const blockDirName = node_path_1.default.dirname(node_path_1.default.relative(this.blocksDest, blockJsonAssetName));
|
|
149
150
|
blockData[blockDirName] = PlainEntrypointsStyleBlockJSONPlugin
|
|
150
151
|
.doFileOrHandleReplacements(compilation, Object.fromEntries(Object.entries(blockJson).filter(([k]) => k !== '$schema')), workableBlockEntrypointsInfo, epi => epi.handle);
|
|
@@ -343,7 +344,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
343
344
|
}
|
|
344
345
|
}
|
|
345
346
|
}
|
|
346
|
-
|
|
347
|
+
attachUniquePhase(compilation) {
|
|
347
348
|
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
348
349
|
const allSemaphoreData = (await PlainEntrypointsStyleBlockJSONPlugin.semaphore.wait())
|
|
349
350
|
.reduce((acc, cur) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
2
|
-
import {
|
|
3
|
-
import { Compilation
|
|
4
|
-
export declare class SpecialAssetHandlingPlugin extends
|
|
2
|
+
import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
|
|
3
|
+
import { Compilation } from "webpack";
|
|
4
|
+
export declare class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin {
|
|
5
5
|
private static readonly semaphore;
|
|
6
6
|
private static validPathname?;
|
|
7
7
|
constructor(config: VerifiedPlauditWordpressWebpackConfig);
|
|
8
|
-
|
|
8
|
+
protected attachStandardPhase(compilation: Compilation): void;
|
|
9
9
|
private collateAssets;
|
|
10
|
-
protected
|
|
10
|
+
protected attachUniquePhase(compilation: Compilation): void;
|
|
11
11
|
}
|