@plaudit/webpack-extensions 2.62.2 → 2.63.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 +5 -4
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +50 -38
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +4 -5
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +0 -1
- package/build/shared.d.ts +9 -6
- package/build/shared.js +11 -5
- package/build/utils/common-config-helpers.d.ts +1 -1
- package/build/utils/common-config-helpers.js +29 -15
- package/build/utils/php-writer.d.ts +38 -9
- package/build/utils/php-writer.js +70 -29
- package/build/wordpress-scripts-wrapper.js +10 -8
- package/package.json +3 -3
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
|
|
2
|
+
import { VerifiedAdvancedOutputConfig } from "../shared";
|
|
1
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
2
4
|
import { Compilation, type Compiler } from "webpack";
|
|
3
|
-
import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
|
|
4
5
|
export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugin {
|
|
5
6
|
private readonly config;
|
|
6
7
|
private readonly extensionsPath;
|
|
7
|
-
private readonly
|
|
8
|
+
private readonly dest;
|
|
8
9
|
private static readonly semaphore;
|
|
9
|
-
|
|
10
|
+
private static readonly perLibraryTypeSetupFilePaths;
|
|
11
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsPath: string, dest: VerifiedAdvancedOutputConfig);
|
|
10
12
|
apply(compiler: Compiler): void;
|
|
11
13
|
private generateVersionTwoConfigFile;
|
|
12
|
-
private stripExtensionsDest;
|
|
13
14
|
protected attachSecondPhase(compilation: Compilation): void;
|
|
14
15
|
}
|
|
@@ -6,22 +6,23 @@ 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 AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
|
|
9
10
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
10
11
|
const shared_1 = require("../shared");
|
|
11
12
|
const php_writer_1 = require("../utils/php-writer");
|
|
12
13
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
13
14
|
const webpack_1 = require("webpack");
|
|
14
|
-
const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
|
|
15
15
|
class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
|
|
16
16
|
config;
|
|
17
17
|
extensionsPath;
|
|
18
|
-
|
|
18
|
+
dest;
|
|
19
19
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore({ libraryType: "", assets: [], setupFiles: [] }, "Extensions");
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
static perLibraryTypeSetupFilePaths = {};
|
|
21
|
+
constructor(config, extensionsPath, dest) {
|
|
22
|
+
super(`extensions-v2-${dest.destination}`, [ExtensionsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
22
23
|
this.config = config;
|
|
23
24
|
this.extensionsPath = extensionsPath;
|
|
24
|
-
this.
|
|
25
|
+
this.dest = dest;
|
|
25
26
|
}
|
|
26
27
|
apply(compiler) {
|
|
27
28
|
super.apply(compiler);
|
|
@@ -30,16 +31,19 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugi
|
|
|
30
31
|
compilation.contextDependencies.add(this.extensionsPath);
|
|
31
32
|
}
|
|
32
33
|
const emissionPromises = [];
|
|
33
|
-
for (const setupFilePath of await promises_1.default.
|
|
34
|
+
for await (const { name: setupFilePath } of await promises_1.default.opendir(this.extensionsPath, { encoding: 'utf-8' })) {
|
|
34
35
|
if (setupFilePath.endsWith("-setup.php")) {
|
|
35
36
|
const setupFileSourcePath = node_path_1.default.join(this.extensionsPath, setupFilePath);
|
|
36
37
|
compilation.fileDependencies.add(setupFileSourcePath);
|
|
37
38
|
emissionPromises.push(promises_1.default.readFile(setupFileSourcePath).then(contents => {
|
|
38
|
-
|
|
39
|
+
compilation.emitAsset(node_path_1.default.join(this.dest.destination, setupFilePath), new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
40
|
+
const blockSlug = /^(.+?)-setup.php$/i.exec(setupFilePath)?.[1];
|
|
41
|
+
return [blockSlug, setupFilePath];
|
|
39
42
|
}));
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
|
-
await Promise.all(emissionPromises)
|
|
45
|
+
ExtensionsConfigFileGeneratorPlugin.perLibraryTypeSetupFilePaths[this.libraryType] = (await Promise.all(emissionPromises))
|
|
46
|
+
.filter((item) => item[0] !== undefined).sort((a, b) => a[0].localeCompare(b[0]));
|
|
43
47
|
});
|
|
44
48
|
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
45
49
|
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, additionalAssets: true }, async (assets) => {
|
|
@@ -49,15 +53,8 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugi
|
|
|
49
53
|
try {
|
|
50
54
|
//TODO: It should be possible to use EntryPoints to determine the "original" file
|
|
51
55
|
//TODO: There is no reason to not use basically the exact same logic to implement support for this in plain file contexts
|
|
52
|
-
const myCacheData = { libraryType: this.libraryType, assets: [],
|
|
53
|
-
|
|
54
|
-
// That way, we'll be able to distinguish which ones go where
|
|
55
|
-
for (const asset of Object.keys(compilation.assets).map(asset => this.stripExtensionsDest(asset))) {
|
|
56
|
-
const blockSlug = /^(.+?)-setup.php$/i.exec(asset)?.[1];
|
|
57
|
-
if (blockSlug) {
|
|
58
|
-
myCacheData.setupFiles.push([blockSlug, asset]);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
56
|
+
const myCacheData = { libraryType: this.libraryType, assets: [],
|
|
57
|
+
setupFiles: ExtensionsConfigFileGeneratorPlugin.perLibraryTypeSetupFilePaths[this.libraryType] ?? [] };
|
|
61
58
|
const rawAssetDataSource = assets["assets.json"]?.source();
|
|
62
59
|
if (typeof rawAssetDataSource !== 'string') {
|
|
63
60
|
ExtensionsConfigFileGeneratorPlugin.semaphore.reject(this.id);
|
|
@@ -87,22 +84,40 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugi
|
|
|
87
84
|
group: this.libraryType,
|
|
88
85
|
requiresBaseURI: true,
|
|
89
86
|
action: writer => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
finalExtensionsDest
|
|
87
|
+
const generateLoader = (writer) => {
|
|
88
|
+
let finalExtensionsDest = this.dest.destination.endsWith("/") ? this.dest.destination : this.dest.destination + "/";
|
|
89
|
+
if (!finalExtensionsDest.startsWith("/")) {
|
|
90
|
+
finalExtensionsDest = "/" + finalExtensionsDest;
|
|
91
|
+
}
|
|
92
|
+
const filePathPrefixVar = new php_writer_1.Var("filePathPrefix");
|
|
93
|
+
const fileUriPrefixVar = new php_writer_1.Var("fileUriPrefix");
|
|
94
|
+
writer
|
|
95
|
+
.assign(filePathPrefixVar, new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest)}`))
|
|
96
|
+
.call("plaudit_webpack_extensions__resolve_base_uri", [filePathPrefixVar], { assignTo: fileUriPrefixVar })
|
|
97
|
+
.call("GutenbergUtils::loadExtensionsV2", [
|
|
98
|
+
new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest + "mapping.config.php")}`),
|
|
99
|
+
filePathPrefixVar, fileUriPrefixVar,
|
|
100
|
+
`${this.config.plainEntrypointsHandlePrefix || node_path_1.default.basename(process.cwd())}_extension_`
|
|
101
|
+
]);
|
|
102
|
+
};
|
|
103
|
+
writer.use("Plaudit\\Common\\Lib\\GutenbergUtils");
|
|
104
|
+
const potentialHandle = this.dest.locations?.handle;
|
|
105
|
+
if (potentialHandle) {
|
|
106
|
+
if (typeof potentialHandle === 'string') {
|
|
107
|
+
try {
|
|
108
|
+
//TODO: Generate a function
|
|
109
|
+
writer.function(potentialHandle, [], generateLoader, { returnType: 'void' });
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for dynamically loading extensions", { cause: e }], this.extensionsPath));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
compilation.errors.push(new Error("The extensions directoryLayout's handle support is limited to static strings"));
|
|
118
|
+
}
|
|
93
119
|
}
|
|
94
|
-
|
|
95
|
-
const fileUriPrefixVar = new php_writer_1.Var("fileUriPrefix");
|
|
96
|
-
writer
|
|
97
|
-
.use("Plaudit\\Common\\Lib\\GutenbergUtils")
|
|
98
|
-
.withScope(writer => writer
|
|
99
|
-
.assign(filePathPrefixVar, new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest)}`))
|
|
100
|
-
.call("plaudit_webpack_extensions__resolve_base_uri", [filePathPrefixVar], { assignTo: fileUriPrefixVar })
|
|
101
|
-
.call("GutenbergUtils::loadExtensionsV2", [
|
|
102
|
-
new php_writer_1.Literal(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(finalExtensionsDest + "mapping.config.php")}`),
|
|
103
|
-
filePathPrefixVar, fileUriPrefixVar,
|
|
104
|
-
`${this.config.plainEntrypointsHandlePrefix || node_path_1.default.basename(process.cwd())}_extension_`
|
|
105
|
-
]));
|
|
120
|
+
writer.withScope(generateLoader);
|
|
106
121
|
}
|
|
107
122
|
} : undefined);
|
|
108
123
|
}
|
|
@@ -126,8 +141,8 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugi
|
|
|
126
141
|
for (const assetDataSource of combinedExtensionData.assets) {
|
|
127
142
|
const normalizedAssetData = Object.entries(assetDataSource)
|
|
128
143
|
.map(entry => {
|
|
129
|
-
const assetPath = this.
|
|
130
|
-
? entry[0].substring(this.
|
|
144
|
+
const assetPath = this.dest.destination && entry[0].startsWith(this.dest.destination + "/")
|
|
145
|
+
? entry[0].substring(this.dest.destination.length + 1) : entry[0];
|
|
131
146
|
return [assetPath, entry[1]];
|
|
132
147
|
});
|
|
133
148
|
for (const [assetPath, assetData] of normalizedAssetData) {
|
|
@@ -168,10 +183,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugi
|
|
|
168
183
|
return [block[0], Object.fromEntries(Object.entries(block[1]).toSorted(([a], [b]) => a.localeCompare(b)))];
|
|
169
184
|
})
|
|
170
185
|
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
171
|
-
compilation.emitAsset(node_path_1.default.join(this.
|
|
172
|
-
}
|
|
173
|
-
stripExtensionsDest(item) {
|
|
174
|
-
return this.extensionsDest && item.startsWith(this.extensionsDest + "/") ? item.substring(this.extensionsDest.length + 1 /* we also need to drop the "/" */) : item;
|
|
186
|
+
compilation.emitAsset(node_path_1.default.join(this.dest.destination, "mapping.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, true)));
|
|
175
187
|
}
|
|
176
188
|
attachSecondPhase(compilation) {
|
|
177
189
|
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_GenerateConfigFile`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
@@ -84,7 +84,6 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibrar
|
|
|
84
84
|
}
|
|
85
85
|
myAssetHandles.push({
|
|
86
86
|
handles,
|
|
87
|
-
usageLocations: this.usageLocations,
|
|
88
87
|
handlePrefix: this.handlePrefix
|
|
89
88
|
});
|
|
90
89
|
}
|
|
@@ -126,15 +125,15 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibrar
|
|
|
126
125
|
const plainEntrypointsConfig = { scriptHandles: {}, script_moduleHandles: {}, styleHandles: {} };
|
|
127
126
|
for (const { handles, handlePrefix } of assets) {
|
|
128
127
|
for (const { src, rest, locations, type, handleName } of handles) {
|
|
128
|
+
const basename = node_path_1.default.basename(src).replace(/_(?:script(?:-\d+)?\.js|style(?:-\d+)?\.css)$|(?<!_(script|style))\.(js|css)$/, "");
|
|
129
129
|
let finalHandleName;
|
|
130
|
-
if (handleName) {
|
|
131
|
-
finalHandleName = handleName;
|
|
130
|
+
if (typeof handleName === 'string') {
|
|
131
|
+
finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, basename);
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
134
|
-
const basename = node_path_1.default.basename(src).replace(/_(?:script(?:-\d+)?\.js|style(?:-\d+)?\.css)$|(?<!_(script|style))\.(js|css)$/, "");
|
|
135
134
|
const baseFinalHandleName = `${handlePrefix}.${(0, shared_1.kebabCase)(basename)}`;
|
|
136
135
|
const handleNameMap = usedHandleNames[type];
|
|
137
|
-
finalHandleName =
|
|
136
|
+
finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, basename);
|
|
138
137
|
for (let count = 0; finalHandleName in handleNameMap && handleNameMap[finalHandleName] !== src;) {
|
|
139
138
|
finalHandleName = `${baseFinalHandleName}-${++count}`;
|
|
140
139
|
}
|
|
@@ -255,7 +255,6 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryPlug
|
|
|
255
255
|
return blockJson;
|
|
256
256
|
}
|
|
257
257
|
stripOffBlocksDestPrefix(file) {
|
|
258
|
-
file = node_path_1.default.normalize(file);
|
|
259
258
|
return this.blocksDest && file.startsWith(this.blocksDest + "/") ? file.substring(this.blocksDest.length + 1 /* we also need to drop the "/" */) : file;
|
|
260
259
|
}
|
|
261
260
|
static hashThingForAsset(thing) {
|
package/build/shared.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type UsageLocations = {
|
|
|
20
20
|
[K in StandardLocationNames]?: boolean | number;
|
|
21
21
|
} & {
|
|
22
22
|
register?: boolean | number;
|
|
23
|
-
handle?: string;
|
|
23
|
+
handle?: string | ((generatedHandle: string) => string);
|
|
24
24
|
registerScriptArgs?: {
|
|
25
25
|
strategy?: 'defer' | 'async';
|
|
26
26
|
in_footer?: boolean;
|
|
@@ -47,9 +47,11 @@ export type AdvancedOutputConfig = {
|
|
|
47
47
|
assumeGlobalizedPlauditLibraries?: boolean;
|
|
48
48
|
externalize?: Required<Configuration>['output']['library'];
|
|
49
49
|
bundleAnalyzer?: boolean;
|
|
50
|
-
locations?: UsageLocations |
|
|
50
|
+
locations?: UsageLocations | UsageLocations['handle'];
|
|
51
|
+
};
|
|
52
|
+
export type VerifiedAdvancedOutputConfig = Omit<AdvancedOutputConfig, 'destination' | 'locations'> & Required<Pick<AdvancedOutputConfig, 'destination'>> & {
|
|
53
|
+
locations: UsageLocations;
|
|
51
54
|
};
|
|
52
|
-
export type VerifiedAdvancedOutputConfig = Omit<AdvancedOutputConfig, 'destination'> & Required<Pick<AdvancedOutputConfig, 'destination'>>;
|
|
53
55
|
export type PlauditWordpressWebpackConfig = {
|
|
54
56
|
standaloneBlocks?: boolean;
|
|
55
57
|
variables?: Record<string, any>;
|
|
@@ -87,8 +89,9 @@ export type UnpackedBlockEntrypointInfo = {
|
|
|
87
89
|
handle: string;
|
|
88
90
|
};
|
|
89
91
|
export declare function packBlockEntrypointInfoForSmuggling(info: UnpackedBlockEntrypointInfo): SmuggledBlockEntrypointInfo;
|
|
90
|
-
export declare function unpackSmuggledBlockEntrypointInfo(library: EntryOptions['library']): UnpackedBlockEntrypointInfo | undefined;
|
|
91
|
-
export declare function isSmuggledLibraryInfo(libraryName: NonNullable<EntryOptions['library']>['name'] | undefined): libraryName is SmuggledBlockEntrypointInfo;
|
|
92
|
+
export declare function unpackSmuggledBlockEntrypointInfo(library: EntryOptions['library'], allowedEndings?: string[] | false): UnpackedBlockEntrypointInfo | undefined;
|
|
93
|
+
export declare function isSmuggledLibraryInfo(libraryName: NonNullable<EntryOptions['library']>['name'] | undefined, allowedEndings?: string[] | false): libraryName is SmuggledBlockEntrypointInfo;
|
|
94
|
+
export declare function convertUsageLocationsHandleToEmittableHandle(handle: UsageLocations['handle'], generatedHandle: string): string;
|
|
92
95
|
export declare function makeEmittableConfigPHP(data: any, asFullFile: boolean, parentIndent?: string): string;
|
|
93
96
|
export type EntrypointFields = ["viewScriptModule", "scriptModule"] | ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script"];
|
|
94
97
|
export declare const entrypointFields: ReadonlyArray<EntrypointFields[number]>;
|
|
@@ -108,7 +111,7 @@ export declare function arrayIsLength<T, N extends number>(arr: T[] | null | und
|
|
|
108
111
|
export declare function kebabCase(value: string): string;
|
|
109
112
|
export declare function loadEnvFile(filePath: string): Promise<Record<string, string>>;
|
|
110
113
|
export declare function parseEnvFile(contents: string): Record<string, string>;
|
|
111
|
-
export declare function newWebpackErrorForFile(error: string
|
|
114
|
+
export declare function newWebpackErrorForFile(error: string | ConstructorParameters<typeof WebpackError>, file: string): WebpackError;
|
|
112
115
|
/**
|
|
113
116
|
* 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
|
|
114
117
|
*/
|
package/build/shared.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.determineCurrentSourceType = determineCurrentSourceType;
|
|
|
9
9
|
exports.packBlockEntrypointInfoForSmuggling = packBlockEntrypointInfoForSmuggling;
|
|
10
10
|
exports.unpackSmuggledBlockEntrypointInfo = unpackSmuggledBlockEntrypointInfo;
|
|
11
11
|
exports.isSmuggledLibraryInfo = isSmuggledLibraryInfo;
|
|
12
|
+
exports.convertUsageLocationsHandleToEmittableHandle = convertUsageLocationsHandleToEmittableHandle;
|
|
12
13
|
exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
|
|
13
14
|
exports.convertEntrypointFieldForAssetType = convertEntrypointFieldForAssetType;
|
|
14
15
|
exports.leadingSlashIt = leadingSlashIt;
|
|
@@ -59,18 +60,23 @@ function determineCurrentSourceType(dest, srcIsDirectory) {
|
|
|
59
60
|
function packBlockEntrypointInfoForSmuggling(info) {
|
|
60
61
|
return [info.blockJsonOrigin, info.entrypointField, info.originalValue, info.entrypointName, info.handle];
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
+
const defaultAllowedEndings = ["/block.json", "/entrypoints.json", "/package.json"];
|
|
64
|
+
function unpackSmuggledBlockEntrypointInfo(library, allowedEndings) {
|
|
63
65
|
const libraryName = library?.name;
|
|
64
|
-
if (!isSmuggledLibraryInfo(libraryName)) {
|
|
66
|
+
if (!isSmuggledLibraryInfo(libraryName, allowedEndings)) {
|
|
65
67
|
return undefined;
|
|
66
68
|
}
|
|
67
69
|
return { blockJsonOrigin: libraryName[0], entrypointField: libraryName[1], originalValue: libraryName[2], entrypointName: libraryName[3], handle: libraryName[4] };
|
|
68
70
|
}
|
|
69
|
-
function isSmuggledLibraryInfo(libraryName) {
|
|
71
|
+
function isSmuggledLibraryInfo(libraryName, allowedEndings = defaultAllowedEndings) {
|
|
70
72
|
if (!Array.isArray(libraryName) || !arrayIsLength(libraryName, 5) || libraryName.some(item => typeof item !== 'string')) {
|
|
71
73
|
return false;
|
|
72
74
|
}
|
|
73
|
-
return libraryName[0].endsWith(
|
|
75
|
+
return (!allowedEndings || allowedEndings.some(s => libraryName[0].endsWith(s))) && exports.entrypointFields.includes(libraryName[1]);
|
|
76
|
+
}
|
|
77
|
+
function convertUsageLocationsHandleToEmittableHandle(handle, generatedHandle) {
|
|
78
|
+
const emittableHandle = typeof handle === 'string' ? handle : handle?.(generatedHandle) ?? generatedHandle;
|
|
79
|
+
return emittableHandle.replaceAll("{basename}", generatedHandle);
|
|
74
80
|
}
|
|
75
81
|
function makeEmittableConfigPHP(data, asFullFile, parentIndent = "") {
|
|
76
82
|
const prettyPrintedMetadata = json_to_php_but_with____injection_1.default.make({ indent: "\t", linebreak: "\n", shortArraySyntax: true })(data, parentIndent)
|
|
@@ -125,7 +131,7 @@ function parseEnvFile(contents) {
|
|
|
125
131
|
}));
|
|
126
132
|
}
|
|
127
133
|
function newWebpackErrorForFile(error, file) {
|
|
128
|
-
const res = new webpack_1.WebpackError(error);
|
|
134
|
+
const res = typeof error === 'string' ? new webpack_1.WebpackError(error) : new webpack_1.WebpackError(...error);
|
|
129
135
|
res.hideStack = true;
|
|
130
136
|
res.file = file;
|
|
131
137
|
return res;
|
|
@@ -18,5 +18,5 @@ export type CommonConfigProcessingResult = {
|
|
|
18
18
|
};
|
|
19
19
|
export declare function joinPossiblyAbsolutePaths(...paths: (string | undefined)[]): string;
|
|
20
20
|
export declare function groupEntrypointsByAssetFile<T>(entrypoints: T[], entrypointNameExtractor: (t: T) => string): Map<string, T[]>;
|
|
21
|
-
export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): () => Promise<EntryObject>;
|
|
21
|
+
export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig, libraryType: string | undefined): () => Promise<EntryObject>;
|
|
22
22
|
export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration, srcIsDirectory: boolean, dest: VerifiedAdvancedOutputConfig, src: string, srcRoot: string | string[], entry: () => Promise<EntryObject> | EntryObject, plugins: CommonPluginConfig['plugins']): Configuration;
|
|
@@ -33,20 +33,29 @@ function groupEntrypointsByAssetFile(entrypoints, entrypointNameExtractor) {
|
|
|
33
33
|
}
|
|
34
34
|
return seenPaths;
|
|
35
35
|
}
|
|
36
|
-
function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args
|
|
37
|
-
const { mapper = ep => ep,
|
|
36
|
+
function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
|
|
37
|
+
const { mapper = ep => ep, dest } = args;
|
|
38
38
|
return (Array.isArray(entrypoint) ? entrypoint : [entrypoint])
|
|
39
39
|
.map(ep => joinPossiblyAbsolutePaths(dir, mapper(ep)))
|
|
40
40
|
.filter(ep => supportedExtensions(ep) && node_fs_1.default.statSync(ep, { throwIfNoEntry: false })?.isFile())
|
|
41
41
|
.map(ep => {
|
|
42
42
|
const parsedEntrypoint = node_path_1.default.parse(ep);
|
|
43
|
-
|
|
43
|
+
const fakeEntrypointInfo = {
|
|
44
|
+
blockJsonOrigin: args.entrypointJsonOrigin,
|
|
45
|
+
entrypointField: shared_1.styleExtension.test(ep) ? 'style' : shared_1.scriptWithModuleExtension.test(ep) ? 'scriptModule' : 'script',
|
|
46
|
+
originalValue: ep,
|
|
47
|
+
entrypointName: parsedEntrypoint.name,
|
|
48
|
+
handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name)
|
|
49
|
+
};
|
|
50
|
+
return [joinPossiblyAbsolutePaths(dest.destination, node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name),
|
|
51
|
+
{ import: ep, library: args.libraryType ? { type: args.libraryType, name: (0, shared_1.packBlockEntrypointInfoForSmuggling)(fakeEntrypointInfo) } : undefined }];
|
|
44
52
|
});
|
|
45
53
|
}
|
|
46
|
-
function parseEntrypointsJSON(dir, dest, supportedExtensions) {
|
|
47
|
-
const
|
|
54
|
+
function parseEntrypointsJSON(dir, dest, supportedExtensions, args) {
|
|
55
|
+
const entrypointJsonOrigin = node_path_1.default.join(dir, 'entrypoints.json');
|
|
56
|
+
const entrypointsJSON = JSON.parse(node_fs_1.default.readFileSync(entrypointJsonOrigin, 'utf8'));
|
|
48
57
|
if (Array.isArray(entrypointsJSON)) {
|
|
49
|
-
return mapToRealEntrypoints(entrypointsJSON, dir, supportedExtensions, {
|
|
58
|
+
return mapToRealEntrypoints(entrypointsJSON, dir, supportedExtensions, { dest, entrypointJsonOrigin, ...args });
|
|
50
59
|
}
|
|
51
60
|
else {
|
|
52
61
|
return Object.entries(entrypointsJSON).map(([name, config]) => {
|
|
@@ -106,7 +115,7 @@ function addPotentiallyDuplicatedEntrypointName(entry, entrypoint, typeCounts, s
|
|
|
106
115
|
}
|
|
107
116
|
entry[potentialKey] = entrypoint[1];
|
|
108
117
|
}
|
|
109
|
-
function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
118
|
+
function resolveEntryFromDirectory(commonConfig, srcRoot, dest, libraryType) {
|
|
110
119
|
const { entrypointFields, processingModules, scriptExtension } = commonConfig;
|
|
111
120
|
return async () => {
|
|
112
121
|
const loadingEntrypoints = [];
|
|
@@ -158,8 +167,12 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
158
167
|
.map(presentEntrypoint => {
|
|
159
168
|
const overallSource = node_path_1.default.dirname(blockJsonOrigin);
|
|
160
169
|
const overallSourceRelativeName = node_path_1.default.relative(overallSource, node_path_1.default.normalize(node_path_1.default.join(blockJsonOrigin, node_path_1.default.relative(overallSource, presentEntrypoint.extensionlessExpectedSrc))));
|
|
170
|
+
const handleSuffix = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, overallSourceRelativeName);
|
|
161
171
|
if (!entrypointNamesWithEffectiveDuplicates[presentEntrypoint.entrypointName]) {
|
|
162
|
-
return {
|
|
172
|
+
return {
|
|
173
|
+
blockJsonOrigin, ...presentEntrypoint,
|
|
174
|
+
handle: `${handlePrefix}/${handleSuffix}`
|
|
175
|
+
};
|
|
163
176
|
}
|
|
164
177
|
const baseSuffix = `_${(0, shared_1.isStyleField)(presentEntrypoint.entrypointField) ? "style" : "script"}`;
|
|
165
178
|
let count = 0, suffix = baseSuffix, deduplicatedEntrypointName;
|
|
@@ -174,7 +187,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
174
187
|
...presentEntrypoint,
|
|
175
188
|
entrypointName: deduplicatedEntrypointName,
|
|
176
189
|
extensionlessExpectedSrc: deduplicatedExtensionlessExpectedSrc,
|
|
177
|
-
handle: `${handlePrefix}/${count ?
|
|
190
|
+
handle: `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`
|
|
178
191
|
};
|
|
179
192
|
});
|
|
180
193
|
rawEntrypoints.push(...resolvedBlockEntrypoints
|
|
@@ -192,17 +205,18 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
192
205
|
}
|
|
193
206
|
catch (e) {
|
|
194
207
|
try {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
208
|
+
const packageJsonOrigin = node_path_1.default.join(dir, 'package.json');
|
|
209
|
+
const packageJson = JSON.parse(await promises_1.default.readFile(packageJsonOrigin, 'utf8'));
|
|
210
|
+
if (packageJson['main']) {
|
|
211
|
+
rawEntrypoints.push(...mapToRealEntrypoints(packageJson['main'], dir, commonConfig.scriptExtension.test, { dest, libraryType, entrypointJsonOrigin: packageJsonOrigin }));
|
|
198
212
|
}
|
|
199
|
-
if (!processingModules &&
|
|
200
|
-
rawEntrypoints.push(...mapToRealEntrypoints(
|
|
213
|
+
if (!processingModules && packageJson['style']) {
|
|
214
|
+
rawEntrypoints.push(...mapToRealEntrypoints(packageJson['style'], dir, shared_1.styleExtension.test, { dest, libraryType, entrypointJsonOrigin: packageJsonOrigin }));
|
|
201
215
|
}
|
|
202
216
|
}
|
|
203
217
|
catch (e) {
|
|
204
218
|
try {
|
|
205
|
-
rawEntrypoints.push(...parseEntrypointsJSON(dir, dest, ep => commonConfig.scriptExtension.test(ep) || shared_1.styleExtension.test(ep)));
|
|
219
|
+
rawEntrypoints.push(...parseEntrypointsJSON(dir, dest, ep => commonConfig.scriptExtension.test(ep) || shared_1.styleExtension.test(ep), { libraryType }));
|
|
206
220
|
}
|
|
207
221
|
catch (e) {
|
|
208
222
|
// This just means that the directory doesn't contain any declared entrypoints.
|
|
@@ -18,6 +18,11 @@ export interface PotentiallyWriteableExpression extends EnclosableExpression {
|
|
|
18
18
|
export declare function isEnclosableExpression(a: unknown): a is EnclosableExpression;
|
|
19
19
|
export declare function isPotentiallyWriteableExpression(a: unknown): a is PotentiallyWriteableExpression;
|
|
20
20
|
export declare abstract class AbstractEnclosableExpression extends Expr implements EnclosableExpression {
|
|
21
|
+
static readonly closers: Readonly<{
|
|
22
|
+
"(": ")";
|
|
23
|
+
"[": "]";
|
|
24
|
+
"{": "}";
|
|
25
|
+
}>;
|
|
21
26
|
abstract toEnclosedForm(): string;
|
|
22
27
|
not(): Not;
|
|
23
28
|
}
|
|
@@ -31,9 +36,10 @@ export declare class Literal extends Expr {
|
|
|
31
36
|
readonly expression: string;
|
|
32
37
|
constructor(expression: string);
|
|
33
38
|
toString(): string;
|
|
34
|
-
static
|
|
35
|
-
static
|
|
36
|
-
static
|
|
39
|
+
static of(expression: string | PHPWriter, enclosed: true): EnclosedLiteral;
|
|
40
|
+
static of(expression: string | PHPWriter, enclosureOpen: keyof typeof AbstractEnclosableExpression.closers, encloserClose?: string): EnclosableLiteral;
|
|
41
|
+
static of(expression: string | PHPWriter, enclosureOpen: string, encloserClose: string): EnclosableLiteral;
|
|
42
|
+
static of(expression: string | PHPWriter, enclosed?: false | undefined): Literal;
|
|
37
43
|
static name(expression: string): EnclosedLiteral;
|
|
38
44
|
}
|
|
39
45
|
export declare class EnclosedLiteral extends Literal implements EnclosableExpression {
|
|
@@ -97,6 +103,19 @@ export declare class Call extends EnclosedExpression implements PotentiallyWrite
|
|
|
97
103
|
constructor(callee: string | EnclosableExpression, args: readonly unknown[]);
|
|
98
104
|
toString(): string;
|
|
99
105
|
}
|
|
106
|
+
export declare class Parameter extends Expr {
|
|
107
|
+
readonly value: unknown;
|
|
108
|
+
readonly name?: string | undefined;
|
|
109
|
+
constructor(value: unknown, name?: string | undefined);
|
|
110
|
+
toString(): string;
|
|
111
|
+
}
|
|
112
|
+
export declare class FirstClassCallable extends ParenthesesEnclosableExpression {
|
|
113
|
+
readonly name: EnclosableExpression;
|
|
114
|
+
constructor(name: EnclosableExpression);
|
|
115
|
+
static from(literal: string): FirstClassCallable;
|
|
116
|
+
toString(): string;
|
|
117
|
+
}
|
|
118
|
+
export declare const validPHPLabel: RegExp;
|
|
100
119
|
type Assignable = EnclosedExpression & PotentiallyWriteableExpression;
|
|
101
120
|
export declare class Assignment extends ParenthesesEnclosableExpression {
|
|
102
121
|
readonly value: unknown;
|
|
@@ -140,7 +159,18 @@ export declare class PHPWriter {
|
|
|
140
159
|
indent(): this;
|
|
141
160
|
outdent(): this;
|
|
142
161
|
setIndentation(level: number): this;
|
|
162
|
+
/**
|
|
163
|
+
* @param lines These are treated as literal *regardless of their types*
|
|
164
|
+
*/
|
|
143
165
|
append(...lines: (string | Expr)[]): this;
|
|
166
|
+
/**
|
|
167
|
+
* @param expr This is treated as literal *regardless of its type*
|
|
168
|
+
* @param opts flags to add additional markup around the expression
|
|
169
|
+
*/
|
|
170
|
+
appendExpr(expr: string | Expr, opts?: {
|
|
171
|
+
chain?: boolean;
|
|
172
|
+
return?: boolean;
|
|
173
|
+
}): this;
|
|
144
174
|
assign(assignee: ConstructorParameters<typeof Assignment>[0] | string, expression: unknown, opts?: {
|
|
145
175
|
chain?: boolean;
|
|
146
176
|
return?: boolean;
|
|
@@ -151,6 +181,11 @@ export declare class PHPWriter {
|
|
|
151
181
|
withTest?: boolean | 'chainable';
|
|
152
182
|
}): this;
|
|
153
183
|
linebreak(): this;
|
|
184
|
+
/**
|
|
185
|
+
* @param func This is treated as literal *regardless of its type*
|
|
186
|
+
* @param args
|
|
187
|
+
* @param opts
|
|
188
|
+
*/
|
|
154
189
|
call(func: string | EnclosableExpression, args: unknown[], opts?: {
|
|
155
190
|
chain?: boolean;
|
|
156
191
|
assignTo?: ConstructorParameters<typeof Assignment>[0];
|
|
@@ -195,11 +230,5 @@ export declare class PHPWriter {
|
|
|
195
230
|
includeNamespaceAndUse?: boolean;
|
|
196
231
|
}): string;
|
|
197
232
|
emitAsset(compilation: Compilation, file: string, assetInfo?: AssetInfo): void;
|
|
198
|
-
/**
|
|
199
|
-
* @param expr Unlike most other methods on this class, this is treated as literal *regardless of the argument's type*
|
|
200
|
-
* @param opts
|
|
201
|
-
* @private
|
|
202
|
-
*/
|
|
203
|
-
private appendWithPossibleReturnAndChain;
|
|
204
233
|
}
|
|
205
234
|
export {};
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PHPWriter = exports.Constants = exports.Assignment = exports.Call = exports.ObjectAccess = exports.ArrayAccess = exports.Access = exports.Not = exports.Op = exports.Var = exports.EnclosableLiteral = exports.EnclosedLiteral = exports.Literal = exports.EnclosedExpression = exports.ParenthesesEnclosableExpression = exports.AbstractEnclosableExpression = exports.Expr = void 0;
|
|
6
|
+
exports.PHPWriter = exports.Constants = exports.Assignment = exports.validPHPLabel = exports.FirstClassCallable = exports.Parameter = exports.Call = exports.ObjectAccess = exports.ArrayAccess = exports.Access = exports.Not = exports.Op = exports.Var = exports.EnclosableLiteral = exports.EnclosedLiteral = exports.Literal = exports.EnclosedExpression = exports.ParenthesesEnclosableExpression = exports.AbstractEnclosableExpression = exports.Expr = void 0;
|
|
7
7
|
exports.isEnclosableExpression = isEnclosableExpression;
|
|
8
8
|
exports.isPotentiallyWriteableExpression = isPotentiallyWriteableExpression;
|
|
9
9
|
const json_to_php_but_with____injection_1 = __importDefault(require("./json-to-php-but-with-__-injection"));
|
|
@@ -30,6 +30,7 @@ function isPotentiallyWriteableExpression(a) {
|
|
|
30
30
|
return isEnclosableExpression(a) && 'potentiallyWritable' in a && a.potentiallyWritable === true;
|
|
31
31
|
}
|
|
32
32
|
class AbstractEnclosableExpression extends Expr {
|
|
33
|
+
static closers = Object.freeze({ "(": ")", "[": "]", "{": "}" });
|
|
33
34
|
not() {
|
|
34
35
|
return new Not(this);
|
|
35
36
|
}
|
|
@@ -56,9 +57,12 @@ class Literal extends Expr {
|
|
|
56
57
|
toString() {
|
|
57
58
|
return this.expression;
|
|
58
59
|
}
|
|
59
|
-
static
|
|
60
|
+
static of(expression, enclosed = false, enclosureClose) {
|
|
61
|
+
if (expression instanceof PHPWriter) {
|
|
62
|
+
expression = expression.toString({ includeOpenPHP: false, includeNamespaceAndUse: false }).trim();
|
|
63
|
+
}
|
|
60
64
|
if (typeof enclosed === 'string') {
|
|
61
|
-
return new EnclosableLiteral(expression, enclosed, enclosureClose ?? enclosed);
|
|
65
|
+
return new EnclosableLiteral(expression, enclosed, enclosureClose ?? AbstractEnclosableExpression.closers[enclosed] ?? enclosed);
|
|
62
66
|
}
|
|
63
67
|
if (enclosed) {
|
|
64
68
|
return new EnclosedLiteral(expression);
|
|
@@ -198,6 +202,34 @@ class Call extends EnclosedExpression {
|
|
|
198
202
|
}
|
|
199
203
|
}
|
|
200
204
|
exports.Call = Call;
|
|
205
|
+
class Parameter extends Expr {
|
|
206
|
+
value;
|
|
207
|
+
name;
|
|
208
|
+
constructor(value, name) {
|
|
209
|
+
super();
|
|
210
|
+
this.value = value;
|
|
211
|
+
this.name = name;
|
|
212
|
+
}
|
|
213
|
+
toString() {
|
|
214
|
+
return this.name ? `${this.name}: ${Expr.convertJsonToPHP(this.value)}` : Expr.convertJsonToPHP(this.value);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.Parameter = Parameter;
|
|
218
|
+
class FirstClassCallable extends ParenthesesEnclosableExpression {
|
|
219
|
+
name;
|
|
220
|
+
constructor(name) {
|
|
221
|
+
super();
|
|
222
|
+
this.name = name;
|
|
223
|
+
}
|
|
224
|
+
static from(literal) {
|
|
225
|
+
return new FirstClassCallable(Literal.name(literal));
|
|
226
|
+
}
|
|
227
|
+
toString() {
|
|
228
|
+
return this.name.toEnclosedForm() + "(...)";
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.FirstClassCallable = FirstClassCallable;
|
|
232
|
+
exports.validPHPLabel = /^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/; // This is from https://www.php.net/manual/en/functions.user-defined.php
|
|
201
233
|
class Assignment extends ParenthesesEnclosableExpression {
|
|
202
234
|
value;
|
|
203
235
|
push;
|
|
@@ -210,14 +242,11 @@ class Assignment extends ParenthesesEnclosableExpression {
|
|
|
210
242
|
if (this.assignees.some(a => a instanceof Access && !a.endsWithPotentiallyWritableExpression())) {
|
|
211
243
|
throw new Error("Cannot assign a value to an access chain that does not end in a writable state");
|
|
212
244
|
}
|
|
213
|
-
if (!this.push && this.assignees.some(a => a instanceof Access && a.endsWithCall())) {
|
|
245
|
+
if (!this.push && this.assignees.some(a => a instanceof Call || (a instanceof Access && a.endsWithCall()))) {
|
|
214
246
|
throw new Error("Cannot assign a value to an access chain that ends in a function call unless that 'assignment' is a push");
|
|
215
247
|
}
|
|
216
248
|
}
|
|
217
249
|
toString() {
|
|
218
|
-
//TODO: Validate that we're in push mode if assigning to a call
|
|
219
|
-
if (!this.push && this.assignees.some(a => a instanceof Call)) {
|
|
220
|
-
}
|
|
221
250
|
const assignmentValue = isEnclosableExpression(this.value) ? this.value.toEnclosedForm() : Expr.convertJsonToPHP(this.value);
|
|
222
251
|
if (this.push) {
|
|
223
252
|
return this.assignees[0].toEnclosedForm() + "[] = " + assignmentValue;
|
|
@@ -268,12 +297,23 @@ class PHPWriter {
|
|
|
268
297
|
this.indentation = "\t".repeat(level);
|
|
269
298
|
return this;
|
|
270
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* @param lines These are treated as literal *regardless of their types*
|
|
302
|
+
*/
|
|
271
303
|
append(...lines) {
|
|
272
304
|
for (const line of lines) {
|
|
273
305
|
this.buffer.push(`${this.indentation}${line}`);
|
|
274
306
|
}
|
|
275
307
|
return this;
|
|
276
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* @param expr This is treated as literal *regardless of its type*
|
|
311
|
+
* @param opts flags to add additional markup around the expression
|
|
312
|
+
*/
|
|
313
|
+
appendExpr(expr, opts = {}) {
|
|
314
|
+
const res = (opts.return ? "return " : "") + expr.toString();
|
|
315
|
+
return this.append(!opts.chain ? res + ';' : res);
|
|
316
|
+
}
|
|
277
317
|
assign(assignee, expression, opts = {}) {
|
|
278
318
|
if (typeof assignee === 'string') {
|
|
279
319
|
assignee = new Var(assignee);
|
|
@@ -288,10 +328,10 @@ class PHPWriter {
|
|
|
288
328
|
this.scopeStack[this.scopeStack.length - 1].push(assignee.name);
|
|
289
329
|
}
|
|
290
330
|
}
|
|
291
|
-
return this.
|
|
331
|
+
return this.appendExpr(new Assignment(assignee, expression), opts);
|
|
292
332
|
}
|
|
293
333
|
return(expression) {
|
|
294
|
-
return this.
|
|
334
|
+
return this.appendExpr(Expr.convertJsonToPHP(expression), { return: true });
|
|
295
335
|
}
|
|
296
336
|
static(variable, opts = {}) {
|
|
297
337
|
if (typeof variable === 'string') {
|
|
@@ -312,12 +352,17 @@ class PHPWriter {
|
|
|
312
352
|
this.buffer.push("");
|
|
313
353
|
return this;
|
|
314
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* @param func This is treated as literal *regardless of its type*
|
|
357
|
+
* @param args
|
|
358
|
+
* @param opts
|
|
359
|
+
*/
|
|
315
360
|
call(func, args, opts = {}) {
|
|
316
361
|
const functionCall = new Call(typeof func === 'string' ? Literal.name(func) : func, args);
|
|
317
362
|
if (opts.assignTo) {
|
|
318
363
|
return this.assign(opts.assignTo, functionCall, opts);
|
|
319
364
|
}
|
|
320
|
-
return this.
|
|
365
|
+
return this.appendExpr(functionCall, opts);
|
|
321
366
|
}
|
|
322
367
|
action(name, contents, args = {}) {
|
|
323
368
|
return this.actionOrFilter('action', name, contents, args);
|
|
@@ -328,7 +373,7 @@ class PHPWriter {
|
|
|
328
373
|
actionOrFilter(type, name, contents, args) {
|
|
329
374
|
const { priority = 10, functionArgParameters = [], useVars = [], accountForAlreadyDoing } = args;
|
|
330
375
|
const functionWriter = this.createSubwriter();
|
|
331
|
-
let
|
|
376
|
+
let declarationFunction;
|
|
332
377
|
if (accountForAlreadyDoing) {
|
|
333
378
|
if (functionArgParameters.length > 0 && accountForAlreadyDoing === true) {
|
|
334
379
|
console.trace(`The accountForAlreadyDoing flag must be set to a list of default parameters when applied to ${type}s that take arguments`);
|
|
@@ -336,35 +381,35 @@ class PHPWriter {
|
|
|
336
381
|
this.openPHP().openScope();
|
|
337
382
|
const functionName = functionWriter.function(true, functionArgParameters, contents, { useVars, scopeActionDescription: `closing the function call for the ${name} ${type}.`, assignToName: true });
|
|
338
383
|
this.append(functionWriter.toString().trim());
|
|
339
|
-
|
|
384
|
+
declarationFunction = new FirstClassCallable(functionName);
|
|
340
385
|
this.if(Expr.call(`doing_${type}`, [name]))
|
|
341
386
|
.call(functionName, accountForAlreadyDoing === true ? [] : accountForAlreadyDoing);
|
|
342
387
|
}
|
|
343
388
|
else {
|
|
344
389
|
functionWriter.function(false, functionArgParameters, contents, { useVars, scopeActionDescription: `closing the function call for the ${name} ${type}.` });
|
|
345
|
-
|
|
390
|
+
declarationFunction = Literal.of(functionWriter);
|
|
346
391
|
}
|
|
347
392
|
// The trailing comma inside the first item is necessary
|
|
348
|
-
const
|
|
393
|
+
const additionArgs = [name, declarationFunction];
|
|
349
394
|
const accepted_args = Math.max(functionArgParameters.length, 1); // This avoids us unnecessarily setting the accepted_args value to 0 for actions
|
|
350
395
|
if (priority !== 10) {
|
|
351
|
-
|
|
396
|
+
additionArgs.push(priority);
|
|
352
397
|
if (accepted_args !== 1) {
|
|
353
|
-
|
|
398
|
+
additionArgs.push(accepted_args);
|
|
354
399
|
}
|
|
355
400
|
}
|
|
356
401
|
else if (accepted_args !== 1) {
|
|
357
|
-
|
|
402
|
+
additionArgs.push(new Parameter(accepted_args, "accepted_args"));
|
|
358
403
|
}
|
|
359
|
-
const line = `add_${type}
|
|
404
|
+
const line = Expr.call(`add_${type}`, additionArgs);
|
|
360
405
|
if (accountForAlreadyDoing) {
|
|
361
406
|
return this
|
|
362
407
|
.else()
|
|
363
|
-
.
|
|
408
|
+
.appendExpr(line)
|
|
364
409
|
.endIf()
|
|
365
410
|
.closeScope();
|
|
366
411
|
}
|
|
367
|
-
return this.openPHP().
|
|
412
|
+
return this.openPHP().appendExpr(line);
|
|
368
413
|
}
|
|
369
414
|
if(condition) {
|
|
370
415
|
return this.openPHP().append(`if (${condition}) {`).indent();
|
|
@@ -387,6 +432,11 @@ class PHPWriter {
|
|
|
387
432
|
console.trace('Anonymous functions cannot be assigned to a name');
|
|
388
433
|
}
|
|
389
434
|
}
|
|
435
|
+
if (typeof name === 'string') {
|
|
436
|
+
if (!exports.validPHPLabel.test(name)) {
|
|
437
|
+
throw new Error(`'${name}' is not a valid function name. Please see https://www.php.net/manual/en/functions.user-defined.php for what constitutes one`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
390
440
|
const returningString = name === true;
|
|
391
441
|
if (name === true) {
|
|
392
442
|
name = this.generateFunctionName(args.assignToName);
|
|
@@ -553,14 +603,5 @@ class PHPWriter {
|
|
|
553
603
|
const contents = this.toString() + "\n";
|
|
554
604
|
compilation[file in compilation.assets ? 'updateAsset' : 'emitAsset'](file, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents), ...assetInfo });
|
|
555
605
|
}
|
|
556
|
-
/**
|
|
557
|
-
* @param expr Unlike most other methods on this class, this is treated as literal *regardless of the argument's type*
|
|
558
|
-
* @param opts
|
|
559
|
-
* @private
|
|
560
|
-
*/
|
|
561
|
-
appendWithPossibleReturnAndChain(expr, opts) {
|
|
562
|
-
const res = (opts.return ? "return " : "") + expr.toString();
|
|
563
|
-
return this.append(!opts.chain ? res + ';' : res);
|
|
564
|
-
}
|
|
565
606
|
}
|
|
566
607
|
exports.PHPWriter = PHPWriter;
|
|
@@ -211,15 +211,17 @@ function buildVerifiedConfig(config) {
|
|
|
211
211
|
const allocatedDestinations = {};
|
|
212
212
|
const partiallyVerifiedSources = rawSources.map(rawSource => {
|
|
213
213
|
const destination = rawSource[1].destination;
|
|
214
|
+
const locations = typeof rawSource[1].locations === 'string' || typeof rawSource[1].locations === 'function'
|
|
215
|
+
? { handle: rawSource[1].locations } : rawSource[1].locations ?? {};
|
|
214
216
|
if (destination !== undefined) {
|
|
215
217
|
const effectiveDestination = toEffectiveWebpackDestination(destination);
|
|
216
218
|
allocatedDestinations[effectiveDestination] = rawSource[0]; // We need to pre-populate the allocatedDestinations map with statically-declared destinations
|
|
217
|
-
return [rawSource[0], { ...rawSource[1], destination, effectiveDestination, staticallyDeclaredDestination: true }];
|
|
219
|
+
return [rawSource[0], { ...rawSource[1], locations, destination, effectiveDestination, staticallyDeclaredDestination: true }];
|
|
218
220
|
}
|
|
219
221
|
else {
|
|
220
222
|
const naiveDestination = deriveNaiveDestinationFromUnverifiedSourceEntry(rawSource, srcPrefixes);
|
|
221
223
|
const effectiveDestination = toEffectiveWebpackDestination(naiveDestination);
|
|
222
|
-
return [rawSource[0], { ...rawSource[1], destination: naiveDestination, effectiveDestination, staticallyDeclaredDestination: false }];
|
|
224
|
+
return [rawSource[0], { ...rawSource[1], locations, destination: naiveDestination, effectiveDestination, staticallyDeclaredDestination: false }];
|
|
223
225
|
}
|
|
224
226
|
});
|
|
225
227
|
const dynamicEffectiveDestinationsWithExpectedNaiveDuplicates = partiallyVerifiedSources
|
|
@@ -487,11 +489,11 @@ function makeBlocksWebpackConfig(config, commonConfig, webpackConfig, dest, src,
|
|
|
487
489
|
if (config.processTranslationConfigs && !processingModules) {
|
|
488
490
|
plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination));
|
|
489
491
|
}
|
|
490
|
-
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest), plugins);
|
|
492
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest, blockJSONManagingPlugin.libraryType), plugins);
|
|
491
493
|
}
|
|
492
494
|
function makeExtensionsWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins) {
|
|
493
495
|
const plugin = config.extensionsVersion > 1
|
|
494
|
-
? new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(config, srcRoot, dest
|
|
496
|
+
? new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(config, srcRoot, dest)
|
|
495
497
|
: new ExtensionsConfigFileGeneratorPluginV1_1.ExtensionsConfigFileGeneratorPluginV1(dest.destination);
|
|
496
498
|
plugins.push(plugin);
|
|
497
499
|
const entry = async () => {
|
|
@@ -511,16 +513,16 @@ function makeExtensionsWebpackConfig(config, commonConfig, webpackConfig, dest,
|
|
|
511
513
|
function makePlainV1WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory) {
|
|
512
514
|
const baseDest = stripExtension(dest.destination);
|
|
513
515
|
const entry = srcIsDirectory // This being true implies that srcRoot is not an array
|
|
514
|
-
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
|
|
516
|
+
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest, undefined)
|
|
515
517
|
: () => ({ [baseDest]: srcRoot });
|
|
516
518
|
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, srcIsDirectory, dest, src, srcRoot, entry, plugins);
|
|
517
519
|
}
|
|
518
520
|
function makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory) {
|
|
519
|
-
const
|
|
520
|
-
plugins.push(
|
|
521
|
+
const requester = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(process.cwd(), config.outputDir, dest.locations, config.plainEntrypointsHandlePrefix, config.useUnifiedLoader);
|
|
522
|
+
plugins.push(requester);
|
|
521
523
|
const baseDest = stripExtension(dest.destination);
|
|
522
524
|
const entry = srcIsDirectory // This being true implies that srcRoot is not an array
|
|
523
|
-
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
|
|
525
|
+
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest, requester.libraryType)
|
|
524
526
|
: () => ({ [baseDest]: srcRoot });
|
|
525
527
|
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, srcIsDirectory, dest, src, srcRoot, entry, plugins);
|
|
526
528
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.63.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"/build"
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@plaudit/postcss-silent-extend": "^3.0.0",
|
|
36
36
|
"@plaudit/postcss-strip-units": "^3.0.0",
|
|
37
37
|
"@plaudit/postcss-variables": "^1.1.0",
|
|
38
|
-
"@wordpress/dependency-extraction-webpack-plugin": "^6.
|
|
39
|
-
"@wordpress/scripts": "^30.
|
|
38
|
+
"@wordpress/dependency-extraction-webpack-plugin": "^6.30.0",
|
|
39
|
+
"@wordpress/scripts": "^30.23.0",
|
|
40
40
|
"autoprefixer": "^10.4.21",
|
|
41
41
|
"browser-sync": "^3.0.4",
|
|
42
42
|
"clean-webpack-plugin": "^4.0.0",
|