@plaudit/webpack-extensions 2.61.1 → 2.62.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/ExtensionsConfigFileGeneratorPlugin.d.ts +1 -1
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +10 -5
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +0 -5
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +20 -41
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +26 -0
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +440 -0
- package/build/plugins/SpecialAssetHandlingPlugin.js +4 -4
- package/build/plugins/UnifiedLoaderGenerator.js +2 -2
- package/build/plugins/WPMLConfigBuilder.d.ts +1 -3
- package/build/plugins/WPMLConfigBuilder.js +14 -22
- package/build/shared.d.ts +34 -3
- package/build/shared.js +78 -9
- package/build/utils/common-config-helpers.d.ts +2 -2
- package/build/utils/common-config-helpers.js +84 -27
- package/build/utils/php-writer.d.ts +2 -0
- package/build/utils/php-writer.js +3 -1
- package/build/wordpress-scripts-wrapper.js +17 -6
- package/package.json +1 -1
- package/build/plugins/BlockJSONManagingPlugin.d.ts +0 -40
- package/build/plugins/BlockJSONManagingPlugin.js +0 -594
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
1
|
+
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
2
2
|
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
3
3
|
export declare class ExtensionsConfigFileGeneratorPlugin implements WebpackPluginInstance {
|
|
4
4
|
private readonly config;
|
|
@@ -72,7 +72,6 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
72
72
|
try {
|
|
73
73
|
//TODO: It should be possible to use EntryPoints to determine the "original" file
|
|
74
74
|
//TODO: There is no reason to not use basically the exact same logic to implement support for this in plain file contexts
|
|
75
|
-
//TODO: BlockJSONManagingPlugin should be rewritten from scratch to use this method instead of its 15 layers of tracking + syncing
|
|
76
75
|
const myCacheData = { assets: [], setupFiles: [] };
|
|
77
76
|
for (const asset of Object.keys(compilation.assets).map(asset => this.stripExtensionsDest(asset))) {
|
|
78
77
|
const blockSlug = /^(.+?)-setup.php$/i.exec(asset)?.[1];
|
|
@@ -144,7 +143,9 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
144
143
|
}
|
|
145
144
|
generateVersionTwoConfigFile(compilation, combinedExtensionData) {
|
|
146
145
|
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
147
|
-
const blockExtensionsConfig = {
|
|
146
|
+
const blockExtensionsConfig = {
|
|
147
|
+
metadata: { version: this.config.extensionsVersion }, scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {}
|
|
148
|
+
};
|
|
148
149
|
for (const assetDataSource of combinedExtensionData.assets) {
|
|
149
150
|
const normalizedAssetData = Object.entries(assetDataSource)
|
|
150
151
|
.map(entry => {
|
|
@@ -161,8 +162,10 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
161
162
|
if (blockSlug && assetType) {
|
|
162
163
|
const key = assetType.replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
|
|
163
164
|
const handle = `plaudit_block-extension_${blockSlug}-${assetType}`;
|
|
164
|
-
const isCss =
|
|
165
|
-
|
|
165
|
+
const isCss = (0, shared_1.isStyleField)(assetType);
|
|
166
|
+
const handleGroup = isCss ? 'styleHandles'
|
|
167
|
+
: ((0, shared_1.isScriptModuleField)(assetType) ? 'scriptModuleHandles' : 'scriptHandles');
|
|
168
|
+
blockExtensionsConfig[handleGroup][handle] = {
|
|
166
169
|
src: isCss ? assetPath.replace(/\.js$/, ".css") : assetPath,
|
|
167
170
|
rest: isCss || key.startsWith("editor")
|
|
168
171
|
? [assetData.dependencies, assetData.version]
|
|
@@ -177,6 +180,8 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
177
180
|
}
|
|
178
181
|
blockExtensionsConfig.scriptHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptHandles)
|
|
179
182
|
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
183
|
+
blockExtensionsConfig.scriptModuleHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptModuleHandles)
|
|
184
|
+
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
180
185
|
blockExtensionsConfig.styleHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.styleHandles)
|
|
181
186
|
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
182
187
|
blockExtensionsConfig.setupFiles = Object.fromEntries(Object.entries(blockExtensionsConfig.setupFiles)
|
|
@@ -186,7 +191,7 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
186
191
|
return [block[0], Object.fromEntries(Object.entries(block[1]).toSorted(([a], [b]) => a.localeCompare(b)))];
|
|
187
192
|
})
|
|
188
193
|
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
189
|
-
compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig)));
|
|
194
|
+
compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, true)));
|
|
190
195
|
}
|
|
191
196
|
makeVersionOneAfterProcessAssets(compilation) {
|
|
192
197
|
return compilationAssets => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { UsageLocations } from "../shared";
|
|
2
|
-
import { PHPWriter } from "../utils/php-writer";
|
|
3
2
|
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
4
3
|
export declare class PlainEntrypointsConfigFileGeneratorPlugin implements WebpackPluginInstance {
|
|
5
4
|
private readonly buildRoot;
|
|
@@ -16,8 +15,4 @@ export declare class PlainEntrypointsConfigFileGeneratorPlugin implements Webpac
|
|
|
16
15
|
private static addHandlesToHandleLists;
|
|
17
16
|
private static appendEnqueuingHandleLists;
|
|
18
17
|
private static separateHandleListByPriority;
|
|
19
|
-
/**
|
|
20
|
-
* The primary benefit of emitting a function instead of baking its contents into each function that uses it is that it allows us to avoid recomputing the base uri multiple times
|
|
21
|
-
*/
|
|
22
|
-
static emitResolveBaseUriFunction(writer: PHPWriter): void;
|
|
23
18
|
}
|
|
@@ -82,17 +82,17 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
|
|
|
82
82
|
chunkFiles[0][1] = true;
|
|
83
83
|
}
|
|
84
84
|
for (const [file, useHandleName] of chunkFiles) {
|
|
85
|
-
const
|
|
85
|
+
const extension = node_path_1.default.extname(file).toLowerCase();
|
|
86
|
+
const type = extension === ".js" ? 'script' : (extension === ".mjs" ? 'script_module' : 'style');
|
|
87
|
+
const isScript = type !== 'style';
|
|
86
88
|
const dependencies = isScript === entrypointChunkIsScript ? assetData.dependencies : [];
|
|
87
89
|
const rest = isScript && this.usageLocations.registerScriptArgs !== undefined
|
|
88
90
|
? [dependencies, assetData.version, this.usageLocations.registerScriptArgs] : [dependencies, assetData.version];
|
|
89
91
|
const destPath = node_path_1.default.join(compilation.outputOptions.path, file);
|
|
90
92
|
handles.push({
|
|
91
|
-
src: destPath,
|
|
92
|
-
rest,
|
|
93
|
+
src: destPath, rest, type,
|
|
93
94
|
locations: this.usageLocations,
|
|
94
|
-
|
|
95
|
-
handleName: useHandleName ? this.usageLocations.handle : undefined
|
|
95
|
+
handleName: useHandleName ? this.usageLocations.handle : undefined,
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
myAssetHandles.push({
|
|
@@ -130,15 +130,13 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
|
|
|
130
130
|
.flatMap(({ handles }) => handles)
|
|
131
131
|
.filter((handle) => !!handle.handleName)
|
|
132
132
|
.sort((a, b) => a.src.localeCompare(b.src));
|
|
133
|
-
const
|
|
134
|
-
.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.map(handle => [handle.handleName, handle.src]));
|
|
139
|
-
const plainEntrypointsConfig = { scriptHandles: {}, styleHandles: {} };
|
|
133
|
+
const usedHandleNames = Object.fromEntries(['script', 'script_module', 'style']
|
|
134
|
+
.map(type => [type, Object.fromEntries(allNamedHandles
|
|
135
|
+
.filter(handle => handle.type === 'script')
|
|
136
|
+
.map(handle => [handle.handleName, handle.src]))]));
|
|
137
|
+
const plainEntrypointsConfig = { scriptHandles: {}, script_moduleHandles: {}, styleHandles: {} };
|
|
140
138
|
for (const { handles, handlePrefix } of assets) {
|
|
141
|
-
for (const { src, rest, locations,
|
|
139
|
+
for (const { src, rest, locations, type, handleName } of handles) {
|
|
142
140
|
let finalHandleName;
|
|
143
141
|
if (handleName) {
|
|
144
142
|
finalHandleName = handleName;
|
|
@@ -146,46 +144,47 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
|
|
|
146
144
|
else {
|
|
147
145
|
const basename = node_path_1.default.basename(src).replace(/_(?:script(?:-\d+)?\.js|style(?:-\d+)?\.css)$|(?<!_(script|style))\.(js|css)$/, "");
|
|
148
146
|
const baseFinalHandleName = `${handlePrefix}.${(0, shared_1.kebabCase)(basename)}`;
|
|
149
|
-
const handleNameMap =
|
|
147
|
+
const handleNameMap = usedHandleNames[type];
|
|
150
148
|
finalHandleName = baseFinalHandleName;
|
|
151
149
|
for (let count = 0; finalHandleName in handleNameMap && handleNameMap[finalHandleName] !== src;) {
|
|
152
150
|
finalHandleName = `${baseFinalHandleName}-${++count}`;
|
|
153
151
|
}
|
|
154
152
|
handleNameMap[finalHandleName] = src;
|
|
155
153
|
}
|
|
156
|
-
plainEntrypointsConfig[
|
|
154
|
+
plainEntrypointsConfig[`${type}Handles`][finalHandleName] = {
|
|
157
155
|
src,
|
|
158
156
|
rest,
|
|
159
157
|
locations,
|
|
160
|
-
|
|
158
|
+
type
|
|
161
159
|
};
|
|
162
160
|
}
|
|
163
161
|
}
|
|
164
162
|
PlainEntrypointsConfigFileGeneratorPlugin.addHandlesToHandleLists('script', Object.entries(plainEntrypointsConfig.scriptHandles)
|
|
165
163
|
.toSorted(([a], [b]) => a.localeCompare(b)), handleLists);
|
|
164
|
+
PlainEntrypointsConfigFileGeneratorPlugin.addHandlesToHandleLists('script_module', Object.entries(plainEntrypointsConfig.script_moduleHandles)
|
|
165
|
+
.toSorted(([a], [b]) => a.localeCompare(b)), handleLists);
|
|
166
166
|
const sortedStyleHandles = Object.entries(plainEntrypointsConfig.styleHandles)
|
|
167
167
|
.toSorted(([a], [b]) => a.localeCompare(b));
|
|
168
168
|
PlainEntrypointsConfigFileGeneratorPlugin.addHandlesToHandleLists('style', sortedStyleHandles, handleLists);
|
|
169
|
-
|
|
170
|
-
const callItemSorter = (a, b) => /*a.type.localeCompare(b.type) || */ a.handle.localeCompare(b.handle);
|
|
169
|
+
const callItemSorter = (a, b) => a.handle.localeCompare(b.handle);
|
|
171
170
|
for (const list of Object.values(handleLists)) {
|
|
172
171
|
list.sort(callItemSorter);
|
|
173
172
|
}
|
|
174
173
|
const writer = new php_writer_1.PHPWriter();
|
|
175
174
|
if (handleLists.register.length > 0) {
|
|
176
175
|
if (!this.useUnifiedLoader) {
|
|
177
|
-
|
|
176
|
+
(0, shared_1.emitResolveBaseUriFunction)(writer);
|
|
178
177
|
}
|
|
179
178
|
for (const [priority, prioritizedHandleList] of PlainEntrypointsConfigFileGeneratorPlugin.separateHandleListByPriority(handleLists.register)) {
|
|
180
179
|
writer.action("init", writer => {
|
|
181
|
-
writer.call("plaudit_webpack_extensions__resolve_base_uri", [
|
|
180
|
+
writer.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.Expr.__DIR__], { assignTo: "$base_uri" });
|
|
182
181
|
for (const { handle, type, data } of prioritizedHandleList) {
|
|
183
182
|
writer.call(`wp_register_${type}`, [handle, new php_writer_1.Expr(`$base_uri.${php_writer_1.Expr.jsonToPHPConverter(node_path_1.default.relative(emitDir, data.src))}`), ...data.rest]);
|
|
184
183
|
}
|
|
185
184
|
}, { priority, accountForAlreadyDoing: true });
|
|
186
185
|
}
|
|
187
186
|
const sortedEditorStyleHandles = sortedStyleHandles
|
|
188
|
-
.filter(([_, { locations: { clientEditor },
|
|
187
|
+
.filter(([_, { locations: { clientEditor }, type }]) => type === 'style' && (clientEditor || typeof clientEditor === 'number'))
|
|
189
188
|
.map(info => info[1]);
|
|
190
189
|
if (sortedEditorStyleHandles.length > 0) {
|
|
191
190
|
writer.linebreak();
|
|
@@ -249,25 +248,5 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
|
|
|
249
248
|
}
|
|
250
249
|
return lists.entries().toArray().sort((a, b) => a[0] - b[0]);
|
|
251
250
|
}
|
|
252
|
-
/**
|
|
253
|
-
* The primary benefit of emitting a function instead of baking its contents into each function that uses it is that it allows us to avoid recomputing the base uri multiple times
|
|
254
|
-
*/
|
|
255
|
-
static emitResolveBaseUriFunction(writer) {
|
|
256
|
-
writer.function("plaudit_webpack_extensions__resolve_base_uri", ["$dir"], writer => {
|
|
257
|
-
writer
|
|
258
|
-
.static("$base_uris", { initializer: [] })
|
|
259
|
-
.if("isset($base_uris[$dir])")
|
|
260
|
-
.return(new php_writer_1.Expr("$base_uris[$dir]"))
|
|
261
|
-
.elseIf("str_starts_with($dir, ABSPATH)")
|
|
262
|
-
.append("$path = ltrim(substr($dir, strlen(ABSPATH)), '/');")
|
|
263
|
-
.elseIf("str_starts_with($dir, '/workspace/website')")
|
|
264
|
-
.append("$path = ltrim(substr($dir, 18), '/');")
|
|
265
|
-
.else()
|
|
266
|
-
.call("error_log", ["UNABLE TO FIGURE OUT WHAT THE RELATIVE PATH TO THE BUILT FILES DIRECTORY SHOULD BE"])
|
|
267
|
-
.append("$path = '';")
|
|
268
|
-
.endIf()
|
|
269
|
-
.call("trailingslashit", [new php_writer_1.Expr("home_url($path)")], { return: true, assignTo: "$base_uris[$dir]" });
|
|
270
|
-
}, { returnType: "string", includeExistenceCheck: true });
|
|
271
|
-
}
|
|
272
251
|
}
|
|
273
252
|
exports.PlainEntrypointsConfigFileGeneratorPlugin = PlainEntrypointsConfigFileGeneratorPlugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
2
|
+
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
3
|
+
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
4
|
+
export declare class PlainEntrypointsStyleBlockJSONPlugin implements WebpackPluginInstance {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly blocksDest;
|
|
7
|
+
private readonly webpackRemoveEmptyScriptsPlugin;
|
|
8
|
+
private static readonly semaphore;
|
|
9
|
+
private static readonly phaseTwoAttached;
|
|
10
|
+
private readonly id;
|
|
11
|
+
private readonly libraryType;
|
|
12
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin);
|
|
13
|
+
apply(compiler: Compiler): void;
|
|
14
|
+
private emitBlockLoaderFile;
|
|
15
|
+
private transformBlocks;
|
|
16
|
+
private static extractAssetSource;
|
|
17
|
+
private static convertToScriptHandles;
|
|
18
|
+
private static doFileOrHandleReplacements;
|
|
19
|
+
private stripOffBlocksDestPrefix;
|
|
20
|
+
private static hashThingForAsset;
|
|
21
|
+
private static stripFilePrefix;
|
|
22
|
+
static findCommonAncestor(...paths: string[]): string[];
|
|
23
|
+
static findRelativeRouteBetween(path1: string, path2: string): string;
|
|
24
|
+
private static remapReferencedPHPFilesOnKey;
|
|
25
|
+
private static normalizeRenderTemplate;
|
|
26
|
+
}
|