@plaudit/webpack-extensions 2.65.2 → 2.66.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 +22 -28
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +1 -1
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +3 -4
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +1 -1
- package/build/plugins/SpecialAssetHandlingPlugin.js +2 -2
- package/build/shared.d.ts +3 -2
- package/build/utils/php-writer.d.ts +15 -12
- package/build/utils/php-writer.js +32 -5
- 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,16 @@ 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 filePathPrefixVar = new php_writer_1.Var("filePathPrefix");
|
|
103
|
+
const fileUriPrefixVar = new php_writer_1.Var("fileUriPrefix");
|
|
104
|
+
writer
|
|
105
|
+
.assign(filePathPrefixVar, php_writer_1.Op.concat(php_writer_1.Constants.__DIR__, '/'))
|
|
106
|
+
.call("plaudit_webpack_extensions__resolve_base_uri", [filePathPrefixVar], { assignTo: fileUriPrefixVar })
|
|
107
|
+
.call("Plaudit\\Common\\Lib\\GutenbergUtils::loadExtensionsV3", [new php_writer_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, false)), filePathPrefixVar, fileUriPrefixVar]);
|
|
108
|
+
})
|
|
109
|
+
.emitAsset(compilation, node_path_1.default.join(this.dest.destination, "extensions-loader.php"));
|
|
100
110
|
}
|
|
101
111
|
attachUniquePhase(compilation) {
|
|
102
112
|
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
@@ -117,7 +127,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
117
127
|
}, {}))
|
|
118
128
|
.sort((a, b) => a.plugin.group.localeCompare(b.plugin.group));
|
|
119
129
|
for (const { plugin, relevantAssetData, setupFiles } of plugins) {
|
|
120
|
-
plugin.
|
|
130
|
+
plugin.generateVersionThreeConfigFile(compilation, relevantAssetData, setupFiles);
|
|
121
131
|
}
|
|
122
132
|
});
|
|
123
133
|
}
|
|
@@ -125,38 +135,22 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
125
135
|
const relevantAssetData = this.extractRelevantAssetData(compilation, rawAssetData);
|
|
126
136
|
const staticallyLoadedEntrypoints = Object.keys(relevantAssetData);
|
|
127
137
|
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
|
-
]);
|
|
138
|
+
writer.require(this.extensionsDestPath + "extensions-loader.php", { dirRelative: true, once: true });
|
|
138
139
|
};
|
|
139
140
|
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
|
-
}
|
|
141
|
+
const lazyLoader = this.dest.lazyLoader;
|
|
142
|
+
if (lazyLoader) {
|
|
143
|
+
try {
|
|
144
|
+
action = writer => writer.function(lazyLoader, [], generateLoader, { returnType: 'void' });
|
|
151
145
|
}
|
|
152
|
-
|
|
153
|
-
compilation.errors.push(
|
|
146
|
+
catch (e) {
|
|
147
|
+
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for lazily loading extensions", { cause: e }], this.extensionsSrcPath));
|
|
154
148
|
this.rejectSemaphores();
|
|
155
149
|
return;
|
|
156
150
|
}
|
|
157
151
|
}
|
|
158
152
|
else {
|
|
159
|
-
action = writer => writer.
|
|
153
|
+
action = writer => writer.withScope(generateLoader);
|
|
160
154
|
}
|
|
161
155
|
const myCacheData = { plugin: this, setupFiles: this.setupFiles, relevantAssetData };
|
|
162
156
|
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
|
}
|
|
@@ -52,9 +52,8 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
52
52
|
finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, basename);
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
|
-
const baseFinalHandleName = `${handlePrefix}.${(0, shared_1.kebabCase)(basename)}`;
|
|
56
55
|
const handleNameMap = usedHandleNames[type];
|
|
57
|
-
finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(
|
|
56
|
+
const baseFinalHandleName = finalHandleName = `${handlePrefix}.${(0, shared_1.convertUsageLocationsHandleToEmittableHandle)((0, shared_1.kebabCase)(basename), basename)}`;
|
|
58
57
|
for (let count = 0; finalHandleName in handleNameMap && handleNameMap[finalHandleName] !== src;) {
|
|
59
58
|
finalHandleName = `${baseFinalHandleName}-${++count}`;
|
|
60
59
|
}
|
|
@@ -89,7 +88,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
89
88
|
writer.action("init", writer => {
|
|
90
89
|
writer.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.Constants.__DIR__], { assignTo: baseUriVar });
|
|
91
90
|
for (const { handle, type, data } of prioritizedHandleList) {
|
|
92
|
-
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]);
|
|
93
92
|
}
|
|
94
93
|
}, { priority, accountForAlreadyDoing: true });
|
|
95
94
|
}
|
|
@@ -202,7 +201,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
202
201
|
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myAssetHandles);
|
|
203
202
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myAssetHandles.length
|
|
204
203
|
? {
|
|
205
|
-
group: this.group, requiresBaseURI: true, action: writer => writer.
|
|
204
|
+
group: this.group, requiresBaseURI: true, action: writer => writer.require("/plain-entrypoints-loader.php", { dirRelative: true, once: true }),
|
|
206
205
|
staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray())
|
|
207
206
|
}
|
|
208
207
|
: undefined);
|
|
@@ -93,7 +93,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
93
93
|
group: this.group,
|
|
94
94
|
requiresBaseURI: false,
|
|
95
95
|
staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray()),
|
|
96
|
-
action: writer => writer.
|
|
96
|
+
action: writer => writer.require(node_path_1.default.join(this.blocksDest, "blockdir-loader.php"), { dirRelative: true, once: true })
|
|
97
97
|
} : undefined);
|
|
98
98
|
}
|
|
99
99
|
emitBlockLoaderFile(compilation, blockData) {
|
|
@@ -48,7 +48,7 @@ class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractB
|
|
|
48
48
|
}
|
|
49
49
|
SpecialAssetHandlingPlugin.semaphore.resolve(this.id, specialAssetData);
|
|
50
50
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(specialAssetData).length > 0
|
|
51
|
-
? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.
|
|
51
|
+
? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.require("/special-assets.php", { dirRelative: true, once: true }) }
|
|
52
52
|
: undefined);
|
|
53
53
|
}
|
|
54
54
|
catch (e) {
|
|
@@ -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;
|
|
@@ -130,6 +130,10 @@ export declare abstract class Constants {
|
|
|
130
130
|
static readonly __DIR__: EnclosedLiteral;
|
|
131
131
|
static readonly ABSPATH: EnclosedLiteral;
|
|
132
132
|
}
|
|
133
|
+
export type AppendExprArgs = {
|
|
134
|
+
chain?: boolean;
|
|
135
|
+
return?: boolean;
|
|
136
|
+
};
|
|
133
137
|
export type ActionOrFilterArgs = {
|
|
134
138
|
priority?: number | Expr;
|
|
135
139
|
functionArgParameters?: string[];
|
|
@@ -143,6 +147,10 @@ export type FunctionCreationArgs = {
|
|
|
143
147
|
assignToName?: boolean;
|
|
144
148
|
scopeActionDescription?: string;
|
|
145
149
|
};
|
|
150
|
+
export type RequireOrIncludeArgs = {
|
|
151
|
+
dirRelative?: boolean;
|
|
152
|
+
once?: boolean;
|
|
153
|
+
} & AppendExprArgs;
|
|
146
154
|
export declare class PHPWriter {
|
|
147
155
|
private readonly inlineFirstLine;
|
|
148
156
|
private readonly scopeStack;
|
|
@@ -167,14 +175,8 @@ export declare class PHPWriter {
|
|
|
167
175
|
* @param expr This is treated as literal *regardless of its type*
|
|
168
176
|
* @param opts flags to add additional markup around the expression
|
|
169
177
|
*/
|
|
170
|
-
appendExpr(expr: string | Expr, opts?:
|
|
171
|
-
|
|
172
|
-
return?: boolean;
|
|
173
|
-
}): this;
|
|
174
|
-
assign(assignee: ConstructorParameters<typeof Assignment>[0] | string, expression: unknown, opts?: {
|
|
175
|
-
chain?: boolean;
|
|
176
|
-
return?: boolean;
|
|
177
|
-
}): this;
|
|
178
|
+
appendExpr(expr: string | Expr, opts?: AppendExprArgs): this;
|
|
179
|
+
assign(assignee: ConstructorParameters<typeof Assignment>[0] | string, expression: unknown, opts?: AppendExprArgs): this;
|
|
178
180
|
return(expression: unknown | Expr): this;
|
|
179
181
|
static(variable: Var | string, opts?: {
|
|
180
182
|
initializer?: unknown | Literal;
|
|
@@ -187,10 +189,8 @@ export declare class PHPWriter {
|
|
|
187
189
|
* @param opts
|
|
188
190
|
*/
|
|
189
191
|
call(func: string | EnclosableExpression, args: unknown[], opts?: {
|
|
190
|
-
chain?: boolean;
|
|
191
192
|
assignTo?: ConstructorParameters<typeof Assignment>[0];
|
|
192
|
-
|
|
193
|
-
}): this;
|
|
193
|
+
} & AppendExprArgs): this;
|
|
194
194
|
action(name: string | Expr, contents: (writer: PHPWriter) => void, args?: ActionOrFilterArgs): this;
|
|
195
195
|
filter(name: string | Expr, contents: (writer: PHPWriter) => void, args?: ActionOrFilterArgs): this;
|
|
196
196
|
actionOrFilter(type: 'action' | 'filter', name: string | Expr, contents: (writer: PHPWriter) => void, args: ActionOrFilterArgs): this;
|
|
@@ -207,6 +207,9 @@ export declare class PHPWriter {
|
|
|
207
207
|
openPHP(): this;
|
|
208
208
|
namespace(namespace: string): this;
|
|
209
209
|
use(...uses: string[]): this;
|
|
210
|
+
require(filePath: string | Expr, args?: RequireOrIncludeArgs): this;
|
|
211
|
+
include(filePath: string | Expr, args?: RequireOrIncludeArgs): this;
|
|
212
|
+
requireOrInclude(type: 'require' | 'include', filePath: string | Expr, args: RequireOrIncludeArgs): this;
|
|
210
213
|
/**
|
|
211
214
|
* Starts a scope that, when paired with {@link #closeScope()}, allows for automating unset calls.
|
|
212
215
|
* All scopes started MUST be paired with either an {@link #closeScope()} or {@link #popScope()} call.
|
|
@@ -12,6 +12,7 @@ class Expr {
|
|
|
12
12
|
static jsonToPHPConverter = json_to_php_but_with____injection_1.default.make({ shortArraySyntax: true });
|
|
13
13
|
static convertJsonToPHP = (obj) => obj instanceof Expr ? obj.toString() : Expr.jsonToPHPConverter(obj);
|
|
14
14
|
constructor() { }
|
|
15
|
+
// noinspection JSUnusedGlobalSymbols - this technically-unused method is necessary for TypeScript to differentiate subclasses of Expr from any
|
|
15
16
|
typeName() {
|
|
16
17
|
return this.constructor.name;
|
|
17
18
|
}
|
|
@@ -130,7 +131,7 @@ class Op extends ParenthesesEnclosableExpression {
|
|
|
130
131
|
static binary(left, operator, right) {
|
|
131
132
|
return new Op(operator, left, right);
|
|
132
133
|
}
|
|
133
|
-
static
|
|
134
|
+
static concat(...args) {
|
|
134
135
|
return new Op(".", ...args);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
@@ -247,11 +248,10 @@ class Assignment extends ParenthesesEnclosableExpression {
|
|
|
247
248
|
}
|
|
248
249
|
}
|
|
249
250
|
toString() {
|
|
250
|
-
const assignmentValue = isEnclosableExpression(this.value) ? this.value.toEnclosedForm() : Expr.convertJsonToPHP(this.value);
|
|
251
251
|
if (this.push) {
|
|
252
|
-
return this.assignees[0].toEnclosedForm() + "[] = " +
|
|
252
|
+
return this.assignees[0].toEnclosedForm() + "[] = " + Expr.convertJsonToPHP(this.value);
|
|
253
253
|
}
|
|
254
|
-
return [...this.assignees.map(t => t.toEnclosedForm()),
|
|
254
|
+
return [...this.assignees.map(t => t.toEnclosedForm()), Expr.convertJsonToPHP(this.value)].join(" = ");
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
exports.Assignment = Assignment;
|
|
@@ -311,7 +311,20 @@ class PHPWriter {
|
|
|
311
311
|
* @param opts flags to add additional markup around the expression
|
|
312
312
|
*/
|
|
313
313
|
appendExpr(expr, opts = {}) {
|
|
314
|
-
|
|
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;
|
|
315
328
|
return this.append(!opts.chain ? res + ';' : res);
|
|
316
329
|
}
|
|
317
330
|
assign(assignee, expression, opts = {}) {
|
|
@@ -514,6 +527,20 @@ class PHPWriter {
|
|
|
514
527
|
}
|
|
515
528
|
return this;
|
|
516
529
|
}
|
|
530
|
+
require(filePath, args = {}) {
|
|
531
|
+
return this.requireOrInclude('require', filePath, args);
|
|
532
|
+
}
|
|
533
|
+
include(filePath, args = {}) {
|
|
534
|
+
return this.requireOrInclude('include', filePath, args);
|
|
535
|
+
}
|
|
536
|
+
requireOrInclude(type, filePath, args) {
|
|
537
|
+
const command = args.once ? `${type}_once` : type;
|
|
538
|
+
if (args.dirRelative && typeof filePath === 'string' && !filePath.startsWith("/")) {
|
|
539
|
+
filePath = "/" + filePath;
|
|
540
|
+
}
|
|
541
|
+
const path = args.dirRelative ? Op.concat(Constants.__DIR__, filePath) : Expr.convertJsonToPHP(filePath);
|
|
542
|
+
return this.appendExpr(`${command} ${path}`, args);
|
|
543
|
+
}
|
|
517
544
|
/**
|
|
518
545
|
* Starts a scope that, when paired with {@link #closeScope()}, allows for automating unset calls.
|
|
519
546
|
* All scopes started MUST be paired with either an {@link #closeScope()} or {@link #popScope()} call.
|
|
@@ -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) {
|