@plaudit/webpack-extensions 2.89.2 → 3.0.0-rc.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/CHANGELOG.md +0 -110
- package/USER-GUIDE.md +81 -117
- package/{dist → build}/plugins/EnhancedBlockJSONPlugin.d.ts +4 -7
- package/{dist → build}/plugins/EnhancedBlockJSONPlugin.js +53 -116
- package/{dist → build}/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +3 -7
- package/{dist → build}/plugins/ExtensionsConfigFileGeneratorPlugin.js +10 -74
- package/{dist → build}/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +1 -1
- package/{dist → build}/plugins/ExtensionsConfigFileGeneratorPluginV1.js +0 -4
- package/{dist → build}/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +20 -46
- package/{dist → build}/plugins/UnifiedLoaderGenerator.d.ts +2 -1
- package/build/plugins/static-configs.d.ts +3 -0
- package/build/plugins/static-configs.js +33 -0
- package/{dist → build}/shared.d.ts +18 -86
- package/{dist → build}/shared.js +11 -124
- package/{dist → build}/utils/common-config-helpers.d.ts +1 -1
- package/{dist → build}/utils/common-config-helpers.js +49 -126
- package/{dist → build}/wordpress-scripts-wrapper.js +36 -70
- package/package.json +26 -36
- package/dist/plugins/static-configs.d.ts +0 -3
- package/dist/plugins/static-configs.js +0 -91
- package/dist/utils/entrypoint-resolution-logic.d.ts +0 -10
- package/dist/utils/entrypoint-resolution-logic.js +0 -82
- package/dist/utils/location-encoding-filename-parser.d.ts +0 -26
- package/dist/utils/location-encoding-filename-parser.js +0 -118
- package/dist/utils/path-query-and-related-helpers.d.ts +0 -58
- package/dist/utils/path-query-and-related-helpers.js +0 -263
- /package/{dist → build}/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +0 -0
- /package/{dist → build}/plugins/AbstractBiPhasicGroupPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/AbstractBiPhasicGroupPlugin.js +0 -0
- /package/{dist → build}/plugins/AdditionalDependencyInjectorPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/AdditionalDependencyInjectorPlugin.js +0 -0
- /package/{dist → build}/plugins/BrowserSyncPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/BrowserSyncPlugin.js +0 -0
- /package/{dist → build}/plugins/EnhancedDynamicEntryPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/EnhancedDynamicEntryPlugin.js +0 -0
- /package/{dist → build}/plugins/MiniCSSExtractPluginErrorCleaner.d.ts +0 -0
- /package/{dist → build}/plugins/MiniCSSExtractPluginErrorCleaner.js +0 -0
- /package/{dist → build}/plugins/PackageConfigSanityChecker.d.ts +0 -0
- /package/{dist → build}/plugins/PackageConfigSanityChecker.js +0 -0
- /package/{dist → build}/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/SpecialAssetHandlingPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/SpecialAssetHandlingPlugin.js +0 -0
- /package/{dist → build}/plugins/UnifiedLoaderGenerator.js +0 -0
- /package/{dist → build}/plugins/VariablesJSMonitorPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/VariablesJSMonitorPlugin.js +0 -0
- /package/{dist → build}/plugins/WPMLConfigBuilder.d.ts +0 -0
- /package/{dist → build}/plugins/WPMLConfigBuilder.js +0 -0
- /package/{dist → build}/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +0 -0
- /package/{dist → build}/plugins/dependency-extraction-webpack-plugin-config-builder.js +0 -0
- /package/{dist → build}/utils/css-writer.d.ts +0 -0
- /package/{dist → build}/utils/css-writer.js +0 -0
- /package/{dist → build}/utils/pseduo-semaphore.d.ts +0 -0
- /package/{dist → build}/utils/pseduo-semaphore.js +0 -0
- /package/{dist → build}/wordpress-scripts-wrapper.d.ts +0 -0
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.EnhancedBlockJSONPlugin = void 0;
|
|
4
|
-
const node_crypto_1 = require("node:crypto");
|
|
5
|
-
const promises_1 = require("node:fs/promises");
|
|
6
|
-
const node_fs_1 = require("node:fs");
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
|
-
const php_writer_1 = require("@plaudit/php-writer");
|
|
9
|
-
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
10
|
-
const webpack_1 = require("webpack");
|
|
7
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
11
|
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
12
12
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
13
|
+
const php_writer_1 = require("@plaudit/php-writer");
|
|
14
|
+
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
13
15
|
const shared_1 = require("../shared");
|
|
14
|
-
const path_query_and_related_helpers_1 = require("../utils/path-query-and-related-helpers");
|
|
15
16
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
17
|
+
const webpack_1 = require("webpack");
|
|
16
18
|
class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
17
19
|
dest;
|
|
18
20
|
webpackRemoveEmptyScriptsPlugin;
|
|
@@ -25,18 +27,18 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
25
27
|
async processAssets(compilation, parsedAssetJsonProvider) {
|
|
26
28
|
const applicableBlockJsonFiles = {};
|
|
27
29
|
const blockJsonOriginToOutputMapping = {};
|
|
28
|
-
const staticallyLoadedEntrypoints = [];
|
|
29
30
|
const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
|
|
30
31
|
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
31
|
-
|
|
32
|
-
if ((0, node_path_1.basename)(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
|
|
32
|
+
if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
35
|
const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypoint.getEntrypointChunk())][0]?.originalSource();
|
|
36
36
|
if (asset) {
|
|
37
|
+
//TODO: Can we guarantee that entrypoint.name is always non-null?
|
|
37
38
|
const epBlockJson = entrypoint.name + ".json";
|
|
38
39
|
if (!applicableBlockJsonFiles[epBlockJson]) {
|
|
39
|
-
const blockJsonText = EnhancedBlockJSONPlugin.extractAssetSource(compilation, epBlockJson)
|
|
40
|
+
const blockJsonText = EnhancedBlockJSONPlugin.extractAssetSource(compilation, epBlockJson)
|
|
41
|
+
?? await promises_1.default.readFile(srcPath, 'utf-8');
|
|
40
42
|
if (!blockJsonText) {
|
|
41
43
|
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`Unable to extract the source for ${epBlockJson}`, srcPath));
|
|
42
44
|
continue;
|
|
@@ -47,11 +49,11 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
50
|
-
if (
|
|
52
|
+
if (node_path_1.default.basename(srcPath).toLowerCase() === "block.json" || 'purpose' in metadata) {
|
|
51
53
|
continue;
|
|
52
54
|
}
|
|
53
55
|
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
54
|
-
const epBlockJson = entrypointChunk.auxiliaryFiles.values().find(auxFile =>
|
|
56
|
+
const epBlockJson = entrypointChunk.auxiliaryFiles.values().find(auxFile => node_path_1.default.basename(auxFile) === "block.json")
|
|
55
57
|
?? blockJsonOriginToOutputMapping[metadata.blockJsonOrigin];
|
|
56
58
|
if (epBlockJson) {
|
|
57
59
|
const assetData = parsedAssetJsonProvider(entrypoint, metadata)?.assetData;
|
|
@@ -60,25 +62,20 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
60
62
|
continue;
|
|
61
63
|
}
|
|
62
64
|
const workableBlockEntrypointsInfo = entrypoint.getFiles()
|
|
63
|
-
.
|
|
65
|
+
.map(file => this.stripOffBlocksDestPrefix(file))
|
|
66
|
+
.filter(file => !this.webpackRemoveEmptyScriptsPlugin['trash'].includes(node_path_1.default.join(this.dest.destination, file)))
|
|
64
67
|
.map(file => [file, (0, shared_1.scriptOrStyleTest)(file, shared_1.scriptExtension)])
|
|
65
68
|
.filter((item) => item[1] !== '')
|
|
66
69
|
.map(([file, assetType]) => {
|
|
67
|
-
const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(file, metadata.enqueuingFlags, this.dest.enqueuingFlags);
|
|
68
|
-
const { scriptArgsObject, inlinedAsset } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, enqueuingFlags);
|
|
69
|
-
if (inlinedAsset !== undefined) {
|
|
70
|
-
staticallyLoadedEntrypoints.push(file);
|
|
71
|
-
}
|
|
72
70
|
const wasOriginallyAStyleField = (0, shared_1.isStyleField)(metadata.entrypointField);
|
|
73
|
-
const outputPath = this.stripOffBlocksDestPrefix(file);
|
|
74
71
|
if (wasOriginallyAStyleField !== (assetType === "style")) { // This means that the file is extracted
|
|
75
72
|
const entrypointField = (0, shared_1.convertEntrypointFieldForAssetType)(metadata.entrypointField, assetType);
|
|
76
73
|
return {
|
|
77
|
-
...metadata, outputPath, assetData, originalValue: undefined, hash: entrypointChunk.hash ?? "",
|
|
78
|
-
entrypointField, handleGroup: (0, shared_1.getHandleGroup)(entrypointField)
|
|
74
|
+
...metadata, outputPath: file, assetData, originalValue: undefined, hash: entrypointChunk.hash ?? "",
|
|
75
|
+
entrypointField, handleGroup: (0, shared_1.getHandleGroup)(entrypointField)
|
|
79
76
|
};
|
|
80
77
|
}
|
|
81
|
-
return { ...metadata, outputPath, assetData, hash: entrypointChunk.hash ?? ""
|
|
78
|
+
return ({ ...metadata, outputPath: file, assetData, hash: entrypointChunk.hash ?? "" });
|
|
82
79
|
});
|
|
83
80
|
if (applicableBlockJsonFiles[epBlockJson]) {
|
|
84
81
|
applicableBlockJsonFiles[epBlockJson].workableBlockEntrypointsInfo.push(...workableBlockEntrypointsInfo);
|
|
@@ -90,10 +87,10 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
90
87
|
}
|
|
91
88
|
EnhancedBlockJSONPlugin.semaphore.resolve(this.id, {
|
|
92
89
|
collatableWorkableBlockInfo: applicableBlockJsonFiles, blocksDest: this.dest.destination,
|
|
93
|
-
emittingWpmlXml: compilation.getAsset(
|
|
90
|
+
emittingWpmlXml: compilation.getAsset(node_path_1.default.join(this.dest.destination, "wpml-config.xml")) !== undefined
|
|
94
91
|
});
|
|
95
92
|
const generateLoader = (writer) => {
|
|
96
|
-
writer.require(
|
|
93
|
+
writer.require(node_path_1.default.join(this.dest.destination, "blockdir-loader.php"), { dirRelative: true, once: true });
|
|
97
94
|
};
|
|
98
95
|
let action;
|
|
99
96
|
const lazyLoader = this.dest.lazyLoader;
|
|
@@ -113,71 +110,22 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
113
110
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(applicableBlockJsonFiles).length ? {
|
|
114
111
|
group: this.group,
|
|
115
112
|
requiresBaseURI: false,
|
|
116
|
-
staticallyLoadedEntrypoints,
|
|
113
|
+
staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray()),
|
|
117
114
|
action
|
|
118
115
|
} : undefined);
|
|
119
116
|
}
|
|
120
|
-
emitBlockLoaderFile(compilation,
|
|
117
|
+
emitBlockLoaderFile(compilation, blockData) {
|
|
121
118
|
if (this.config.useUnifiedLoader) {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const inlinedAssets = [];
|
|
126
|
-
for (const [handle, handleData] of Object.entries(handles)) {
|
|
127
|
-
const { inlinedAsset, ...finalizedHandle } = handleData;
|
|
128
|
-
if (inlinedAsset !== undefined) {
|
|
129
|
-
finalizedHandle.src = false;
|
|
130
|
-
inlinedAssets.push([handle, type, inlinedAsset, handleData, handleData.src]);
|
|
131
|
-
}
|
|
132
|
-
registerableHandles[handle] = finalizedHandle;
|
|
133
|
-
}
|
|
134
|
-
return [registerableHandles, inlinedAssets];
|
|
135
|
-
};
|
|
136
|
-
const [finalizedScriptHandles, inlinableScripts] = splitOutInlinedAssets(metadata.scriptHandles, 'script');
|
|
137
|
-
const [finalizedStyleHandles, inlinableStyles] = splitOutInlinedAssets(metadata.styleHandles, 'style');
|
|
138
|
-
const finalizedMetadata = Object.fromEntries(Object.entries(metadata)
|
|
139
|
-
.map(([key, value]) => {
|
|
140
|
-
if (key === 'scriptHandles') {
|
|
141
|
-
return [key, []];
|
|
142
|
-
}
|
|
143
|
-
if (key === 'styleHandles') {
|
|
144
|
-
return [key, []];
|
|
145
|
-
}
|
|
146
|
-
if (key === 'scriptModuleHandles') {
|
|
147
|
-
return [key, []];
|
|
148
|
-
}
|
|
149
|
-
return [key, value];
|
|
150
|
-
}));
|
|
151
|
-
const writer = new php_writer_1.PHPWriter()
|
|
119
|
+
const metadata = blockData['__metadata'];
|
|
120
|
+
delete blockData['__metadata'];
|
|
121
|
+
(0, shared_1.emitPHPWriterAsAsset)(new php_writer_1.PHPWriter()
|
|
152
122
|
.action("init", writer => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.callRegisterFunction('style', writer, baseUriVar, Object.entries(finalizedStyleHandles));
|
|
157
|
-
this.callRegisterFunction('script_module', writer, baseUriVar, Object.entries(metadata.scriptModuleHandles));
|
|
158
|
-
writer.call("\\Plaudit\\Common\\ACF\\BlockManager::autoloadSubfoldersV3", [
|
|
159
|
-
expressions_1.Constants.__DIR__, // string $dir
|
|
160
|
-
new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockData, false, "\t")), // array $blockdirConfig
|
|
161
|
-
expressions_1.Constants.__FILE__, // string $blockdirConfigFile
|
|
162
|
-
new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(finalizedMetadata, false, "\t")), // array $metadata
|
|
163
|
-
null // ?string $urlPrefix
|
|
164
|
-
]);
|
|
165
|
-
for (const inlinableScript of inlinableScripts) {
|
|
166
|
-
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, ...inlinableScript);
|
|
167
|
-
}
|
|
168
|
-
for (const inlinableStyle of inlinableStyles) {
|
|
169
|
-
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, ...inlinableStyle);
|
|
170
|
-
}
|
|
171
|
-
}, { accountForAlreadyDoing: this.config.includePostInitFallback });
|
|
172
|
-
(0, shared_1.emitPHPWriterAsAsset)(writer, compilation, (0, node_path_1.join)(this.dest.destination, "blockdir-loader.php"));
|
|
123
|
+
writer.call("\\Plaudit\\Common\\ACF\\BlockManager::autoloadSubfoldersV3", [expressions_1.Constants.__DIR__, new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockData, false, "\t")),
|
|
124
|
+
expressions_1.Constants.__FILE__, new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(metadata, false, "\t")), null]);
|
|
125
|
+
}, { accountForAlreadyDoing: this.config.includePostInitFallback }), compilation, node_path_1.default.join(this.dest.destination, "blockdir-loader.php"));
|
|
173
126
|
}
|
|
174
127
|
else {
|
|
175
|
-
compilation.emitAsset(
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
callRegisterFunction(type, writer, baseUriVar, handles) {
|
|
179
|
-
for (const [name, { src, rest }] of handles) {
|
|
180
|
-
writer.call(`wp_register_${type}`, [name, src === false ? false : expressions_1.Op.concat(baseUriVar, src), ...rest]);
|
|
128
|
+
compilation.emitAsset(node_path_1.default.join(this.dest.destination, "blockdir.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockData, true)));
|
|
181
129
|
}
|
|
182
130
|
}
|
|
183
131
|
transformBlocks(compilation, collatedWorkableBlockInfo, emittingWpmlXml) {
|
|
@@ -194,8 +142,8 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
194
142
|
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`${blockJsonAssetName} does not have recorded text`, blockJsonAssetName));
|
|
195
143
|
continue;
|
|
196
144
|
}
|
|
197
|
-
const sourceDir =
|
|
198
|
-
const outputDir =
|
|
145
|
+
const sourceDir = node_path_1.default.dirname(blockJsonSourcePath);
|
|
146
|
+
const outputDir = node_path_1.default.join(compilation.compiler.outputPath, node_path_1.default.dirname(blockJsonAssetName));
|
|
199
147
|
const blockJson = JSON.parse(blockJsonText);
|
|
200
148
|
const pathsNeedRemapping = !this.config.standaloneBlocks && blockJson["plaudit"] !== "simple";
|
|
201
149
|
EnhancedBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "setup", pathsNeedRemapping, sourceDir, outputDir, compilation, true);
|
|
@@ -209,11 +157,11 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
209
157
|
blockJson["version"] = hashForVersion;
|
|
210
158
|
}
|
|
211
159
|
EnhancedBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
|
|
212
|
-
const blockDirName =
|
|
160
|
+
const blockDirName = node_path_1.default.dirname(node_path_1.default.relative(this.dest.destination, blockJsonAssetName));
|
|
213
161
|
blockData[blockDirName] = EnhancedBlockJSONPlugin
|
|
214
162
|
.doFileOrHandleReplacements(compilation, Object.fromEntries(Object.entries(blockJson).filter(([k]) => k !== '$schema')), workableBlockEntrypointsInfo, epi => epi.handle);
|
|
215
|
-
|
|
216
|
-
|
|
163
|
+
compilation[blockJsonAssetName in compilation.assets ? 'updateAsset' : 'emitAsset'](blockJsonAssetName, new webpack_1.sources.RawSource(JSON.stringify(EnhancedBlockJSONPlugin
|
|
164
|
+
.doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, epi => "file:./" + node_path_1.default.relative(blockDirName, epi.outputPath)), undefined, " ")));
|
|
217
165
|
}
|
|
218
166
|
return {
|
|
219
167
|
__metadata: {
|
|
@@ -225,7 +173,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
225
173
|
.convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && (0, shared_1.isScriptModuleField)(hd.entrypointField)))),
|
|
226
174
|
styleHandles: Object.fromEntries(handleData.filter(hd => (0, shared_1.isStyleField)(hd.entrypointField))
|
|
227
175
|
.map(hd => {
|
|
228
|
-
return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version]
|
|
176
|
+
return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version] }];
|
|
229
177
|
}))
|
|
230
178
|
},
|
|
231
179
|
...Object.fromEntries(Object.entries(blockData).sort((a, b) => a[0].localeCompare(b[0])))
|
|
@@ -238,20 +186,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
238
186
|
static convertToScriptHandles(handleData) {
|
|
239
187
|
return handleData.map(hd => {
|
|
240
188
|
const deps = hd.originalValue !== undefined ? hd.assetData.dependencies : [];
|
|
241
|
-
|
|
242
|
-
if (hd.scriptArgsObject !== undefined) {
|
|
243
|
-
scriptArgsObject = hd.scriptArgsObject;
|
|
244
|
-
}
|
|
245
|
-
else if (hd.inlinedAsset !== undefined) {
|
|
246
|
-
scriptArgsObject = hd.inlinedAsset.position === 'before' ? { strategy: "defer" } : undefined;
|
|
247
|
-
}
|
|
248
|
-
else if (!hd.entrypointField.startsWith("editor")) {
|
|
249
|
-
scriptArgsObject = { strategy: "defer" };
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
scriptArgsObject = undefined;
|
|
253
|
-
}
|
|
254
|
-
return [hd.handle, { src: hd.outputPath, rest: scriptArgsObject !== undefined ? [deps, hd.assetData.version, scriptArgsObject] : [deps, hd.assetData.version], inlinedAsset: hd.inlinedAsset }];
|
|
189
|
+
return [hd.handle, { src: hd.outputPath, rest: hd.entrypointField.startsWith("editor") ? [deps, hd.assetData.version] : [deps, hd.assetData.version, { strategy: "defer" }] }];
|
|
255
190
|
});
|
|
256
191
|
}
|
|
257
192
|
static doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, getter) {
|
|
@@ -299,13 +234,13 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
299
234
|
return this.dest.destination && file.startsWith(this.dest.destination + "/") ? file.substring(this.dest.destination.length + 1 /* we also need to drop the "/" */) : file;
|
|
300
235
|
}
|
|
301
236
|
static hashThingForAsset(thing) {
|
|
302
|
-
return
|
|
237
|
+
return node_crypto_1.default.createHash('md5').update(thing).digest("hex").substring(0, 20).toLowerCase();
|
|
303
238
|
}
|
|
304
239
|
static stripFilePrefix(file) {
|
|
305
240
|
return file.startsWith("file:./") ? file.substring(7) : file;
|
|
306
241
|
}
|
|
307
242
|
static findCommonAncestor(...paths) {
|
|
308
|
-
return paths.map(p =>
|
|
243
|
+
return paths.map(p => node_path_1.default.normalize(p).split(node_path_1.default.sep)).reduce((prior, current) => {
|
|
309
244
|
for (let i = 0, limit = Math.min(prior.length, current.length); i < limit; i++) {
|
|
310
245
|
if (prior[i] !== current[i]) {
|
|
311
246
|
return prior.slice(0, i);
|
|
@@ -316,7 +251,9 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
316
251
|
}
|
|
317
252
|
static findRelativeRouteBetween(path1, path2) {
|
|
318
253
|
const commonAncestor = EnhancedBlockJSONPlugin.findCommonAncestor(path1, path2);
|
|
319
|
-
|
|
254
|
+
const route = Array(path1.split(node_path_1.default.sep).length - commonAncestor.length).fill("..");
|
|
255
|
+
route.push(node_path_1.default.relative(commonAncestor.join(node_path_1.default.sep), path2));
|
|
256
|
+
return route.join(node_path_1.default.sep);
|
|
320
257
|
}
|
|
321
258
|
static remapReferencedPHPFilesOnKey(blockJson, key, pathsNeedRemapping, sourceDir, outputDir, compilation, inPlaudit) {
|
|
322
259
|
const rawValue = (inPlaudit ? blockJson["plaudit"] : blockJson)?.[key];
|
|
@@ -332,7 +269,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
332
269
|
}
|
|
333
270
|
else {
|
|
334
271
|
if (fileReferences.length !== 0) {
|
|
335
|
-
compilation.warnings.push((0, shared_1.newWebpackErrorForFile)(`Encountered a block with a mixture of file-reference and non-file-reference elements in the "${inPlaudit ? 'plaudit.' : ''}${key}" property`,
|
|
272
|
+
compilation.warnings.push((0, shared_1.newWebpackErrorForFile)(`Encountered a block with a mixture of file-reference and non-file-reference elements in the "${inPlaudit ? 'plaudit.' : ''}${key}" property`, node_path_1.default.join(sourceDir, 'block.json')));
|
|
336
273
|
rawFiles = fileReferences;
|
|
337
274
|
}
|
|
338
275
|
else {
|
|
@@ -349,11 +286,11 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
349
286
|
}
|
|
350
287
|
const mappedFiles = pathsNeedRemapping
|
|
351
288
|
? rawFiles
|
|
352
|
-
.map(p =>
|
|
353
|
-
.filter(node_fs_1.existsSync)
|
|
289
|
+
.map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
|
|
290
|
+
.filter(p => node_fs_1.default.existsSync(p))
|
|
354
291
|
.map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
|
|
355
292
|
: rawFiles
|
|
356
|
-
.filter(p =>
|
|
293
|
+
.filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
|
|
357
294
|
if (mappedFiles.length === 0) {
|
|
358
295
|
if (deleteOnEmpty && rawValue !== undefined) {
|
|
359
296
|
delete (inPlaudit ? blockJson["plaudit"] : blockJson)[key];
|
|
@@ -389,11 +326,11 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
389
326
|
: [`${blockName.substring(blockName.indexOf('/') + 1)}.php`, "template.php", "template.twig"]);
|
|
390
327
|
const renderTemplate = pathsNeedRemapping
|
|
391
328
|
? rawRenderTemplate
|
|
392
|
-
.map(p =>
|
|
393
|
-
.filter(node_fs_1.existsSync)
|
|
329
|
+
.map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
|
|
330
|
+
.filter(p => node_fs_1.default.existsSync(p))
|
|
394
331
|
.map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
|
|
395
332
|
: rawRenderTemplate
|
|
396
|
-
.filter(p =>
|
|
333
|
+
.filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
|
|
397
334
|
if (renderTemplate.length === 0) {
|
|
398
335
|
delete blockJson["render_template"];
|
|
399
336
|
delete blockJson["render"];
|
|
@@ -412,7 +349,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
412
349
|
}
|
|
413
350
|
delete blockJson[invalidTemplateLocation];
|
|
414
351
|
if (renderTemplate.length > 1) {
|
|
415
|
-
compilation.warnings.push((0, shared_1.newWebpackErrorForFile)("Encountered a block with multiple possible render files",
|
|
352
|
+
compilation.warnings.push((0, shared_1.newWebpackErrorForFile)("Encountered a block with multiple possible render files", node_path_1.default.join(sourceDir, 'block.json')));
|
|
416
353
|
blockJson[validTemplateLocation] = renderTemplate.find(p => p.endsWith(".php")) ?? renderTemplate[0];
|
|
417
354
|
}
|
|
418
355
|
else {
|
|
@@ -459,7 +396,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
459
396
|
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER }, async () => {
|
|
460
397
|
const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
|
|
461
398
|
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
462
|
-
if (
|
|
399
|
+
if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
|
|
463
400
|
continue;
|
|
464
401
|
}
|
|
465
402
|
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
-
import {
|
|
2
|
+
import { ParsedAssetJsonProvider, VerifiedAdvancedOutputConfig } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
4
|
import { Compilation, type Compiler } from "webpack";
|
|
5
|
-
export
|
|
6
|
-
extensionId: string;
|
|
7
|
-
};
|
|
8
|
-
export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<ExtensionConfigFileGeneratorMetadata> {
|
|
5
|
+
export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin {
|
|
9
6
|
private readonly extensionsSrcPath;
|
|
10
7
|
private readonly dest;
|
|
11
8
|
private static readonly semaphore;
|
|
12
9
|
private setupFiles;
|
|
13
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsSrcPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider
|
|
10
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsSrcPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider);
|
|
14
11
|
get extensionsDestPath(): string;
|
|
15
12
|
apply(compiler: Compiler): void;
|
|
16
|
-
private walkSubtreeForMetaInfo;
|
|
17
13
|
private generateVersionThreeConfigFile;
|
|
18
14
|
protected attachUniquePhase(compilation: Compilation): void;
|
|
19
15
|
protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
|
|
@@ -1,41 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
35
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
6
|
exports.ExtensionsConfigFileGeneratorPlugin = void 0;
|
|
37
|
-
const promises_1 = require("node:fs/promises");
|
|
38
|
-
const node_path_1 =
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
39
9
|
const php_writer_1 = require("@plaudit/php-writer");
|
|
40
10
|
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
41
11
|
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
@@ -64,49 +34,24 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
64
34
|
compilation.contextDependencies.add(this.extensionsSrcPath);
|
|
65
35
|
}
|
|
66
36
|
const emissionPromises = [];
|
|
67
|
-
for await (const { name: setupFilePath } of await
|
|
37
|
+
for await (const { name: setupFilePath } of await promises_1.default.opendir(this.extensionsSrcPath, { encoding: 'utf-8' })) {
|
|
68
38
|
if (setupFilePath.endsWith("-setup.php")) {
|
|
69
39
|
const setupFileSourcePath = node_path_1.default.join(this.extensionsSrcPath, setupFilePath);
|
|
70
40
|
compilation.fileDependencies.add(setupFileSourcePath);
|
|
71
|
-
emissionPromises.push(
|
|
41
|
+
emissionPromises.push(promises_1.default.readFile(setupFileSourcePath).then(contents => {
|
|
72
42
|
compilation.emitAsset(node_path_1.default.join(this.dest.destination, setupFilePath), new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
73
43
|
const blockSlug = /^(.+?)-setup.php$/i.exec(setupFilePath)?.[1];
|
|
74
44
|
return [blockSlug, setupFilePath];
|
|
75
45
|
}));
|
|
76
46
|
}
|
|
77
47
|
}
|
|
78
|
-
await this.walkSubtreeForMetaInfo(compilation, this.extensionsSrcPath, this.dest, [], emissionPromises);
|
|
79
48
|
this.setupFiles = (await Promise.all(emissionPromises))
|
|
80
49
|
.filter((item) => item[0] !== undefined).sort((a, b) => a[0].localeCompare(b[0]));
|
|
81
50
|
});
|
|
82
51
|
}
|
|
83
|
-
async walkSubtreeForMetaInfo(compilation, srcRoot, dest, parents, emissionPromises) {
|
|
84
|
-
if (!compilation.contextDependencies.has(srcRoot)) {
|
|
85
|
-
compilation.contextDependencies.add(srcRoot);
|
|
86
|
-
}
|
|
87
|
-
for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
|
|
88
|
-
if (dirent.name.startsWith("~")) {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (dirent.isFile()) {
|
|
92
|
-
if (dirent.name === "setup.php") {
|
|
93
|
-
const setupFilePath = (0, node_path_1.join)(...parents, dirent.name);
|
|
94
|
-
const setupFileSourcePath = node_path_1.default.join(this.extensionsSrcPath, setupFilePath);
|
|
95
|
-
compilation.fileDependencies.add(setupFileSourcePath);
|
|
96
|
-
emissionPromises.push((0, promises_1.readFile)(setupFileSourcePath).then(contents => {
|
|
97
|
-
compilation.emitAsset(node_path_1.default.join(this.dest.destination, setupFilePath), new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
98
|
-
return [parents.join("-") /* blockSlug */, setupFilePath];
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else if (dirent.isDirectory()) {
|
|
103
|
-
await this.walkSubtreeForMetaInfo(compilation, (0, node_path_1.join)(srcRoot, dirent.name), dest, [...parents, dirent.name], emissionPromises);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
52
|
generateVersionThreeConfigFile(compilation, relevantAssetData, setupFilePaths) {
|
|
108
53
|
const handlePrefix = `${this.config.targetHandlePrefix}_block-extensions`;
|
|
109
|
-
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))$/i;
|
|
54
|
+
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
110
55
|
const blockExtensionsConfig = {
|
|
111
56
|
metadata: { version: this.config.extensionsVersion }, scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {}
|
|
112
57
|
};
|
|
@@ -117,7 +62,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
117
62
|
return [assetPath, entry[1]];
|
|
118
63
|
});
|
|
119
64
|
for (const [assetPath, assetData] of normalizedAssetData) {
|
|
120
|
-
const match = regex.exec(
|
|
65
|
+
const match = regex.exec(assetPath);
|
|
121
66
|
if (!match) {
|
|
122
67
|
continue;
|
|
123
68
|
}
|
|
@@ -182,16 +127,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
182
127
|
});
|
|
183
128
|
}
|
|
184
129
|
processAssets(compilation, parsedAssetJsonProvider) {
|
|
185
|
-
const relevantAssetData =
|
|
186
|
-
.map(({ entrypoint, metadata, srcPath }) => {
|
|
187
|
-
const providedData = parsedAssetJsonProvider(entrypoint, metadata);
|
|
188
|
-
if (providedData === undefined) {
|
|
189
|
-
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
192
|
-
return [providedData.assetName, { ...providedData.assetData, extensionId: metadata.extensionId }];
|
|
193
|
-
})
|
|
194
|
-
.filter(item => item !== undefined));
|
|
130
|
+
const relevantAssetData = this.extractRelevantAssetData(compilation, parsedAssetJsonProvider);
|
|
195
131
|
const staticallyLoadedEntrypoints = Object.keys(relevantAssetData);
|
|
196
132
|
const generateLoader = (writer) => {
|
|
197
133
|
writer.require(this.extensionsDestPath + "extensions-loader.php", { dirRelative: true, once: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
-
import
|
|
2
|
+
import { ParsedAssetJsonProvider } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
4
|
import { Compilation } from "webpack";
|
|
5
5
|
export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin {
|
|
@@ -20,12 +20,8 @@ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntr
|
|
|
20
20
|
processAssets(compilation, parsedAssetJsonProvider) {
|
|
21
21
|
const regex = /^(.+?)-((?<prefix>editor-|view-|)(?<type>style|script|script-module))\.(?<extension>css|m?js)$/i;
|
|
22
22
|
const mapping = {};
|
|
23
|
-
const prefix = this.extensionsDest + node_path_1.default.sep;
|
|
24
23
|
for (let fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation, parsedAssetJsonProvider))) {
|
|
25
24
|
let match;
|
|
26
|
-
if (fileWithAssetData.startsWith(prefix)) {
|
|
27
|
-
fileWithAssetData = fileWithAssetData.substring(prefix.length);
|
|
28
|
-
}
|
|
29
25
|
if ((match = regex.exec(fileWithAssetData)) && match[1] && match[2]) {
|
|
30
26
|
if (match.groups?.['type'] === 'style' && match.groups['extension'] !== 'css') {
|
|
31
27
|
fileWithAssetData = fileWithAssetData.replace(/\.m?js$/i, ".css");
|