@plaudit/webpack-extensions 2.65.3 → 2.66.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/ExtensionsConfigFileGeneratorPlugin.d.ts +1 -1
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +20 -28
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +1 -1
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +1 -1
- package/build/plugins/SpecialAssetHandlingPlugin.js +1 -1
- package/build/shared.d.ts +3 -2
- package/build/utils/php-writer.d.ts +1 -1
- package/build/utils/php-writer.js +18 -6
- package/build/wordpress-scripts-wrapper.js +13 -5
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasi
|
|
|
10
10
|
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsSrcPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider);
|
|
11
11
|
get extensionsDestPath(): string;
|
|
12
12
|
apply(compiler: Compiler): void;
|
|
13
|
-
private
|
|
13
|
+
private generateVersionThreeConfigFile;
|
|
14
14
|
protected attachUniquePhase(compilation: Compilation): void;
|
|
15
15
|
protected processAssets(compilation: Compilation, rawAssetData: ParsedAssetsJson): void;
|
|
16
16
|
}
|
|
@@ -48,7 +48,8 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
48
48
|
.filter((item) => item[0] !== undefined).sort((a, b) => a[0].localeCompare(b[0]));
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
generateVersionThreeConfigFile(compilation, relevantAssetData, setupFilePaths) {
|
|
52
|
+
const handlePrefix = `${this.config.plainEntrypointsHandlePrefix}_block-extensions`;
|
|
52
53
|
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
53
54
|
const blockExtensionsConfig = {
|
|
54
55
|
metadata: { version: this.config.extensionsVersion }, scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {}
|
|
@@ -67,7 +68,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
67
68
|
const blockSlug = match[1], assetType = match[2];
|
|
68
69
|
if (blockSlug && assetType) {
|
|
69
70
|
const key = assetType.replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
|
|
70
|
-
const handle =
|
|
71
|
+
const handle = `${handlePrefix}_${blockSlug}-${assetType}`;
|
|
71
72
|
const isCss = (0, shared_1.isStyleField)(assetType);
|
|
72
73
|
const handleGroup = isCss ? 'styleHandles'
|
|
73
74
|
: ((0, shared_1.isScriptModuleField)(assetType) ? 'scriptModuleHandles' : 'scriptHandles');
|
|
@@ -96,7 +97,14 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
96
97
|
return [block[0], Object.fromEntries(Object.entries(block[1]).toSorted(([a], [b]) => a.localeCompare(b)))];
|
|
97
98
|
})
|
|
98
99
|
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
99
|
-
|
|
100
|
+
new php_writer_1.PHPWriter()
|
|
101
|
+
.withScope(writer => {
|
|
102
|
+
const fileUriPrefixVar = new php_writer_1.Var("fileUriPrefix");
|
|
103
|
+
writer
|
|
104
|
+
.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.Constants.__DIR__], { assignTo: fileUriPrefixVar })
|
|
105
|
+
.call("Plaudit\\Common\\Lib\\GutenbergUtils::loadExtensionsV3", [new php_writer_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, false)), php_writer_1.Constants.__DIR__, fileUriPrefixVar]);
|
|
106
|
+
})
|
|
107
|
+
.emitAsset(compilation, node_path_1.default.join(this.dest.destination, "extensions-loader.php"));
|
|
100
108
|
}
|
|
101
109
|
attachUniquePhase(compilation) {
|
|
102
110
|
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
@@ -117,7 +125,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
117
125
|
}, {}))
|
|
118
126
|
.sort((a, b) => a.plugin.group.localeCompare(b.plugin.group));
|
|
119
127
|
for (const { plugin, relevantAssetData, setupFiles } of plugins) {
|
|
120
|
-
plugin.
|
|
128
|
+
plugin.generateVersionThreeConfigFile(compilation, relevantAssetData, setupFiles);
|
|
121
129
|
}
|
|
122
130
|
});
|
|
123
131
|
}
|
|
@@ -125,38 +133,22 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
125
133
|
const relevantAssetData = this.extractRelevantAssetData(compilation, rawAssetData);
|
|
126
134
|
const staticallyLoadedEntrypoints = Object.keys(relevantAssetData);
|
|
127
135
|
const generateLoader = (writer) => {
|
|
128
|
-
|
|
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
|
-
]);
|
|
136
|
+
writer.require(this.extensionsDestPath + "extensions-loader.php", { dirRelative: true, once: true });
|
|
138
137
|
};
|
|
139
138
|
let action;
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
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;
|
|
150
|
-
}
|
|
139
|
+
const lazyLoader = this.dest.lazyLoader;
|
|
140
|
+
if (lazyLoader) {
|
|
141
|
+
try {
|
|
142
|
+
action = writer => writer.function(lazyLoader, [], generateLoader, { returnType: 'void' });
|
|
151
143
|
}
|
|
152
|
-
|
|
153
|
-
compilation.errors.push(
|
|
144
|
+
catch (e) {
|
|
145
|
+
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for lazily loading extensions", { cause: e }], this.extensionsSrcPath));
|
|
154
146
|
this.rejectSemaphores();
|
|
155
147
|
return;
|
|
156
148
|
}
|
|
157
149
|
}
|
|
158
150
|
else {
|
|
159
|
-
action = writer => writer.
|
|
151
|
+
action = writer => writer.withScope(generateLoader);
|
|
160
152
|
}
|
|
161
153
|
const myCacheData = { plugin: this, setupFiles: this.setupFiles, relevantAssetData };
|
|
162
154
|
ExtensionsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myCacheData);
|
|
@@ -32,7 +32,7 @@ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntr
|
|
|
32
32
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, { group: `extensions-config-v1-${this.extensionsDest}`, requiresBaseURI: false, action: writer => {
|
|
33
33
|
writer
|
|
34
34
|
.use("Plaudit\\Common\\Lib\\GutenbergUtils")
|
|
35
|
-
.call("GutenbergUtils::installExtensionsSupport", [php_writer_1.Op.
|
|
35
|
+
.call("GutenbergUtils::installExtensionsSupport", [php_writer_1.Op.concat(php_writer_1.Constants.__DIR__, this.extensionsDest)]);
|
|
36
36
|
} });
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -88,7 +88,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
88
88
|
writer.action("init", writer => {
|
|
89
89
|
writer.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.Constants.__DIR__], { assignTo: baseUriVar });
|
|
90
90
|
for (const { handle, type, data } of prioritizedHandleList) {
|
|
91
|
-
writer.call(`wp_register_${type}`, [handle, php_writer_1.Op.
|
|
91
|
+
writer.call(`wp_register_${type}`, [handle, php_writer_1.Op.concat(baseUriVar, node_path_1.default.relative(emitDir, data.src)), ...data.rest]);
|
|
92
92
|
}
|
|
93
93
|
}, { priority, accountForAlreadyDoing: true });
|
|
94
94
|
}
|
|
@@ -116,7 +116,7 @@ class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractB
|
|
|
116
116
|
attributes.push(["crossorigin", crossorigin]);
|
|
117
117
|
}
|
|
118
118
|
const dynamicAttrs = attributes.map(([k, v]) => v ? `${k}="${v}"` : k).join(" ");
|
|
119
|
-
writer.append(`<link rel="preload" href="<?= ${php_writer_1.Expr.call("esc_url", [php_writer_1.Op.
|
|
119
|
+
writer.append(`<link rel="preload" href="<?= ${php_writer_1.Expr.call("esc_url", [php_writer_1.Op.concat(baseUriVar, filename)])} ?>" ${dynamicAttrs}>`);
|
|
120
120
|
}
|
|
121
121
|
writer.openPHP();
|
|
122
122
|
});
|
package/build/shared.d.ts
CHANGED
|
@@ -48,8 +48,9 @@ export type AdvancedOutputConfig = {
|
|
|
48
48
|
externalize?: Required<Configuration>['output']['library'];
|
|
49
49
|
bundleAnalyzer?: boolean;
|
|
50
50
|
locations?: UsageLocations | UsageLocations['handle'];
|
|
51
|
+
lazyLoader?: string;
|
|
51
52
|
};
|
|
52
|
-
type OptionalCfgFields = 'directoryLayout' | 'externalize';
|
|
53
|
+
type OptionalCfgFields = 'directoryLayout' | 'externalize' | 'lazyLoader';
|
|
53
54
|
export type VerifiedAdvancedOutputConfig = Required<Omit<AdvancedOutputConfig, 'locations' | OptionalCfgFields>> & Pick<AdvancedOutputConfig, OptionalCfgFields> & {
|
|
54
55
|
locations: UsageLocations;
|
|
55
56
|
};
|
|
@@ -68,7 +69,7 @@ export type PlauditWordpressWebpackConfig = {
|
|
|
68
69
|
combineAssetMetadata?: boolean;
|
|
69
70
|
useWebpackResourceFiltering?: boolean;
|
|
70
71
|
outputDir?: string;
|
|
71
|
-
extensionsVersion?: 1 | 2;
|
|
72
|
+
extensionsVersion?: 1 | 2 | 3;
|
|
72
73
|
plainEntrypointsHandlePrefix?: string;
|
|
73
74
|
plainEntrypointsVersion?: 1 | 2;
|
|
74
75
|
srcDir?: string;
|
|
@@ -66,7 +66,7 @@ export declare class Op extends ParenthesesEnclosableExpression {
|
|
|
66
66
|
constructor(operator: string, ...args: unknown[]);
|
|
67
67
|
toString(): string;
|
|
68
68
|
static binary(left: unknown, operator: string, right: unknown): Op;
|
|
69
|
-
static
|
|
69
|
+
static concat(...args: unknown[]): Op;
|
|
70
70
|
}
|
|
71
71
|
export declare class Not extends ParenthesesEnclosableExpression {
|
|
72
72
|
readonly expression: EnclosableExpression;
|
|
@@ -131,7 +131,7 @@ class Op extends ParenthesesEnclosableExpression {
|
|
|
131
131
|
static binary(left, operator, right) {
|
|
132
132
|
return new Op(operator, left, right);
|
|
133
133
|
}
|
|
134
|
-
static
|
|
134
|
+
static concat(...args) {
|
|
135
135
|
return new Op(".", ...args);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -248,11 +248,10 @@ class Assignment extends ParenthesesEnclosableExpression {
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
toString() {
|
|
251
|
-
const assignmentValue = isEnclosableExpression(this.value) ? this.value.toEnclosedForm() : Expr.convertJsonToPHP(this.value);
|
|
252
251
|
if (this.push) {
|
|
253
|
-
return this.assignees[0].toEnclosedForm() + "[] = " +
|
|
252
|
+
return this.assignees[0].toEnclosedForm() + "[] = " + Expr.convertJsonToPHP(this.value);
|
|
254
253
|
}
|
|
255
|
-
return [...this.assignees.map(t => t.toEnclosedForm()),
|
|
254
|
+
return [...this.assignees.map(t => t.toEnclosedForm()), Expr.convertJsonToPHP(this.value)].join(" = ");
|
|
256
255
|
}
|
|
257
256
|
}
|
|
258
257
|
exports.Assignment = Assignment;
|
|
@@ -312,7 +311,20 @@ class PHPWriter {
|
|
|
312
311
|
* @param opts flags to add additional markup around the expression
|
|
313
312
|
*/
|
|
314
313
|
appendExpr(expr, opts = {}) {
|
|
315
|
-
|
|
314
|
+
let expression;
|
|
315
|
+
if (isEnclosableExpression(expr)) {
|
|
316
|
+
expression = opts.chain ? expr.toEnclosedForm() : expr.toString();
|
|
317
|
+
}
|
|
318
|
+
else if (opts.chain && expr instanceof Expr) {
|
|
319
|
+
throw new Error(`Cannot chain non-enclosable expressions`);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
expression = expr.toString();
|
|
323
|
+
}
|
|
324
|
+
if (opts.chain && expr instanceof Expr && !isEnclosableExpression(expr)) {
|
|
325
|
+
throw new Error(`Cannot chain non-enclosable expressions`);
|
|
326
|
+
}
|
|
327
|
+
const res = (opts.return ? "return " : "") + expression;
|
|
316
328
|
return this.append(!opts.chain ? res + ';' : res);
|
|
317
329
|
}
|
|
318
330
|
assign(assignee, expression, opts = {}) {
|
|
@@ -526,7 +538,7 @@ class PHPWriter {
|
|
|
526
538
|
if (args.dirRelative && typeof filePath === 'string' && !filePath.startsWith("/")) {
|
|
527
539
|
filePath = "/" + filePath;
|
|
528
540
|
}
|
|
529
|
-
const path = args.dirRelative ? Op.
|
|
541
|
+
const path = args.dirRelative ? Op.concat(Constants.__DIR__, filePath) : Expr.convertJsonToPHP(filePath);
|
|
530
542
|
return this.appendExpr(`${command} ${path}`, args);
|
|
531
543
|
}
|
|
532
544
|
/**
|
|
@@ -172,7 +172,7 @@ function injectSupportForInliningSVGsAsStrings(rules) {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
function buildVerifiedConfig(config) {
|
|
175
|
-
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, outputDir = "",
|
|
175
|
+
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, outputDir = "", plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false } = config;
|
|
176
176
|
let srcPrefixes;
|
|
177
177
|
const trailingSlashedSrcDir = srcDir && !srcDir.endsWith("/") ? srcDir + "/" : srcDir;
|
|
178
178
|
if (config.srcPrefixes === undefined) {
|
|
@@ -184,7 +184,7 @@ function buildVerifiedConfig(config) {
|
|
|
184
184
|
let plainEntrypointsHandlePrefix = config.plainEntrypointsHandlePrefix ?? "";
|
|
185
185
|
if (plainEntrypointsVersion > 1) {
|
|
186
186
|
if (!plainEntrypointsHandlePrefix) {
|
|
187
|
-
plainEntrypointsHandlePrefix =
|
|
187
|
+
plainEntrypointsHandlePrefix = deriveDefaultHandlePrefixFromComposerJsonOrThemeName();
|
|
188
188
|
if (!plainEntrypointsHandlePrefix) {
|
|
189
189
|
throw new Error("Plain Entrypoints V2 and higher require either 'plainEntrypointsHandlePrefix' to be set or an adjacent composer.json or style.css file to be present");
|
|
190
190
|
}
|
|
@@ -214,6 +214,10 @@ function buildVerifiedConfig(config) {
|
|
|
214
214
|
if (!rawVariables) {
|
|
215
215
|
variablesFilePath = ["variables.js", "src/site/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p))[0];
|
|
216
216
|
}
|
|
217
|
+
let extensionsVersion = config.extensionsVersion ?? 1;
|
|
218
|
+
if (extensionsVersion === 2) {
|
|
219
|
+
extensionsVersion = 3; // Version 3 is a backwards-compatible upgrade of version 2, so we can automatically upgrade everything
|
|
220
|
+
}
|
|
217
221
|
const cfg = {
|
|
218
222
|
currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, processTranslationConfigs, combineAssetMetadata,
|
|
219
223
|
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, plainEntrypointsHandlePrefix, srcDir, srcPrefixes, useUnifiedLoader
|
|
@@ -291,21 +295,25 @@ function finalizeEntryDestination(entry, dynamicEffectiveDestinationsWithExpecte
|
|
|
291
295
|
allocatedDestinations[derivedDestination] = entry[0];
|
|
292
296
|
return [entry[0], { ...entry[1], destination: derivedDestination }];
|
|
293
297
|
}
|
|
294
|
-
|
|
298
|
+
let defaultHandlePrefix = undefined;
|
|
299
|
+
function deriveDefaultHandlePrefixFromComposerJsonOrThemeName() {
|
|
300
|
+
if (defaultHandlePrefix !== undefined) {
|
|
301
|
+
return defaultHandlePrefix;
|
|
302
|
+
}
|
|
295
303
|
let composerJson;
|
|
296
304
|
try {
|
|
297
305
|
composerJson = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(process.cwd(), "composer.json"), 'utf-8'));
|
|
298
306
|
}
|
|
299
307
|
catch {
|
|
300
308
|
// Then composer.json doesn't exist
|
|
301
|
-
return
|
|
309
|
+
return deriveDefaultHandlePrefixFromThemeName();
|
|
302
310
|
}
|
|
303
311
|
if (typeof composerJson !== 'object' || typeof composerJson.name !== 'string' || !composerJson.name) {
|
|
304
312
|
throw new ReferenceError("plainEntrypointsHandlePrefix was not set and the adjacent composer.json file does not have a valid name in it");
|
|
305
313
|
}
|
|
306
314
|
return (0, shared_1.kebabCase)(composerJson.name.replace(/plaudit\/plaudit/, 'plaudit'));
|
|
307
315
|
}
|
|
308
|
-
function
|
|
316
|
+
function deriveDefaultHandlePrefixFromThemeName() {
|
|
309
317
|
const styleFileContents = node_fs_1.default.readFileSync(node_path_1.default.join(process.cwd(), "style.css"), 'utf-8');
|
|
310
318
|
const themeName = /^\W*Theme\s*Name:\s*(.+)$/im.exec(styleFileContents)?.[1]?.trim();
|
|
311
319
|
if (!themeName) {
|