@plaudit/webpack-extensions 3.21.2 → 4.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 +9 -1
- package/USER-GUIDE.md +2 -1
- package/package.json +27 -49
- package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +0 -25
- package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +0 -86
- package/dist/plugins/AbstractBiPhasicGroupPlugin.d.ts +0 -31
- package/dist/plugins/AbstractBiPhasicGroupPlugin.js +0 -91
- package/dist/plugins/AdditionalDependencyInjectorPlugin.d.ts +0 -11
- package/dist/plugins/AdditionalDependencyInjectorPlugin.js +0 -58
- package/dist/plugins/EnhancedBlockJSONPlugin.d.ts +0 -47
- package/dist/plugins/EnhancedBlockJSONPlugin.js +0 -657
- package/dist/plugins/EnhancedDynamicEntryPlugin.d.ts +0 -8
- package/dist/plugins/EnhancedDynamicEntryPlugin.js +0 -14
- package/dist/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +0 -20
- package/dist/plugins/ExtensionsConfigFileGeneratorPlugin.js +0 -191
- package/dist/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +0 -9
- package/dist/plugins/ExtensionsConfigFileGeneratorPluginV1.js +0 -45
- package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts +0 -4
- package/dist/plugins/MiniCSSExtractPluginErrorCleaner.js +0 -15
- package/dist/plugins/MixableBiPhasicGroupAndEntryPlugin.d.ts +0 -6
- package/dist/plugins/MixableBiPhasicGroupAndEntryPlugin.js +0 -13
- package/dist/plugins/MixableBiPhasicGroupPlugin.d.ts +0 -6
- package/dist/plugins/MixableBiPhasicGroupPlugin.js +0 -13
- package/dist/plugins/PackageConfigSanityChecker.d.ts +0 -4
- package/dist/plugins/PackageConfigSanityChecker.js +0 -30
- package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +0 -26
- package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +0 -392
- package/dist/plugins/SpecialAssetHandlingPlugin.d.ts +0 -12
- package/dist/plugins/SpecialAssetHandlingPlugin.js +0 -134
- package/dist/plugins/UnifiedLoaderGenerator.d.ts +0 -21
- package/dist/plugins/UnifiedLoaderGenerator.js +0 -144
- package/dist/plugins/VariablesJSMonitorPlugin.d.ts +0 -7
- package/dist/plugins/VariablesJSMonitorPlugin.js +0 -20
- package/dist/plugins/WPMLConfigBuilder.d.ts +0 -17
- package/dist/plugins/WPMLConfigBuilder.js +0 -472
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +0 -4
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js +0 -147
- package/dist/plugins/index.d.ts +0 -8
- package/dist/plugins/index.js +0 -24
- package/dist/plugins/static-configs.d.ts +0 -3
- package/dist/plugins/static-configs.js +0 -44
- package/dist/shared.d.ts +0 -311
- package/dist/shared.js +0 -536
- package/dist/utils/common-config-helpers.d.ts +0 -28
- package/dist/utils/common-config-helpers.js +0 -489
- package/dist/utils/css-writer.d.ts +0 -4
- package/dist/utils/css-writer.js +0 -46
- package/dist/utils/entrypoint-resolution-logic.d.ts +0 -13
- package/dist/utils/entrypoint-resolution-logic.js +0 -82
- package/dist/utils/location-encoding-filename-parser.d.ts +0 -30
- package/dist/utils/location-encoding-filename-parser.js +0 -120
- package/dist/utils/path-query-and-related-helpers.d.ts +0 -64
- package/dist/utils/path-query-and-related-helpers.js +0 -269
- package/dist/utils/pseudo-semaphore.d.ts +0 -14
- package/dist/utils/pseudo-semaphore.js +0 -79
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts +0 -72
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js +0 -518
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts +0 -56
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js +0 -155
- package/dist/wordpress-scripts-wrapper.d.ts +0 -4
- package/dist/wordpress-scripts-wrapper.js +0 -698
|
@@ -1,657 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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");
|
|
11
|
-
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
12
|
-
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
13
|
-
const shared_1 = require("../shared");
|
|
14
|
-
const path_query_and_related_helpers_1 = require("../utils/path-query-and-related-helpers");
|
|
15
|
-
const pseudo_semaphore_1 = require("../utils/pseudo-semaphore");
|
|
16
|
-
class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
17
|
-
config;
|
|
18
|
-
dest;
|
|
19
|
-
webpackRemoveEmptyScriptsPlugin;
|
|
20
|
-
static semaphore = new pseudo_semaphore_1.PseudoSemaphore("Block JSON v3");
|
|
21
|
-
constructor(config, dest, webpackRemoveEmptyScriptsPlugin, context, entry) {
|
|
22
|
-
super(`block-json-${dest.destination}`, [EnhancedBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
23
|
-
this.config = config;
|
|
24
|
-
this.dest = dest;
|
|
25
|
-
this.webpackRemoveEmptyScriptsPlugin = webpackRemoveEmptyScriptsPlugin;
|
|
26
|
-
}
|
|
27
|
-
async processAssets(compilation, parsedAssetJsonProvider) {
|
|
28
|
-
const applicableBlockJsonFiles = {};
|
|
29
|
-
const blockJsonOriginToOutputMapping = {};
|
|
30
|
-
const staticallyLoadedEntrypoints = [];
|
|
31
|
-
const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
|
|
32
|
-
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
33
|
-
staticallyLoadedEntrypoints.push(...entrypoint.getEntrypointChunk().files);
|
|
34
|
-
if ((0, node_path_1.basename)(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypoint.getEntrypointChunk())][0]?.originalSource();
|
|
38
|
-
if (asset) {
|
|
39
|
-
const epBlockJson = entrypoint.name + ".json";
|
|
40
|
-
if (!applicableBlockJsonFiles[epBlockJson]) {
|
|
41
|
-
const blockJsonText = EnhancedBlockJSONPlugin.extractAssetSource(compilation, epBlockJson) ?? await (0, promises_1.readFile)(srcPath, 'utf-8');
|
|
42
|
-
if (!blockJsonText) {
|
|
43
|
-
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`Unable to extract the source for ${epBlockJson}`, srcPath));
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
applicableBlockJsonFiles[epBlockJson] = { sourcePath: srcPath, workableBlockEntrypointsInfo: [], blockJsonText };
|
|
47
|
-
}
|
|
48
|
-
blockJsonOriginToOutputMapping[srcPath] = epBlockJson;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
52
|
-
if ((0, node_path_1.basename)(srcPath).toLowerCase() === "block.json" || 'purpose' in metadata) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
56
|
-
const epBlockJson = entrypointChunk.auxiliaryFiles.values().find(auxFile => (0, node_path_1.basename)(auxFile) === "block.json")
|
|
57
|
-
?? blockJsonOriginToOutputMapping[metadata.blockJsonOrigin];
|
|
58
|
-
if (epBlockJson) {
|
|
59
|
-
const assetData = parsedAssetJsonProvider(entrypoint, metadata)?.assetData;
|
|
60
|
-
if (!assetData) {
|
|
61
|
-
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const workableBlockEntrypointsInfo = entrypoint.getFiles()
|
|
65
|
-
.filter(file => !this.webpackRemoveEmptyScriptsPlugin['trash'].includes(file))
|
|
66
|
-
.map(file => [file, (0, shared_1.scriptOrStyleTest)(file, shared_1.scriptExtension)])
|
|
67
|
-
.filter((item) => item[1] !== '')
|
|
68
|
-
.map(([file, assetType]) => {
|
|
69
|
-
const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(file, metadata.enqueuingFlags, this.dest.enqueuingFlags);
|
|
70
|
-
const { scriptArgsObject, assetMeta } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, enqueuingFlags);
|
|
71
|
-
if (assetMeta?.inlinedAsset !== undefined) {
|
|
72
|
-
staticallyLoadedEntrypoints.push(file);
|
|
73
|
-
}
|
|
74
|
-
const wasOriginallyAStyleField = (0, shared_1.isStyleField)(metadata.entrypointField);
|
|
75
|
-
const outputPath = this.stripOffBlocksDestPrefix(file);
|
|
76
|
-
if (wasOriginallyAStyleField !== (assetType === "style")) { // This means that the file is extracted
|
|
77
|
-
const entrypointField = (0, shared_1.convertEntrypointFieldForAssetType)(metadata.entrypointField, assetType);
|
|
78
|
-
return {
|
|
79
|
-
...metadata, outputPath, assetData, originalValue: undefined, hash: entrypointChunk.hash ?? "",
|
|
80
|
-
entrypointField, handleGroup: (0, shared_1.getHandleGroup)(entrypointField), scriptArgsObject, ...assetMeta
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
return { ...metadata, outputPath, assetData, hash: entrypointChunk.hash ?? "", scriptArgsObject, ...assetMeta };
|
|
84
|
-
});
|
|
85
|
-
if (applicableBlockJsonFiles[epBlockJson]) {
|
|
86
|
-
applicableBlockJsonFiles[epBlockJson].workableBlockEntrypointsInfo.push(...workableBlockEntrypointsInfo);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
applicableBlockJsonFiles[epBlockJson] = { sourcePath: workableBlockEntrypointsInfo[0]?.blockJsonOrigin, workableBlockEntrypointsInfo };
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
EnhancedBlockJSONPlugin.semaphore.resolve(this.id, {
|
|
94
|
-
collatableWorkableBlockInfo: applicableBlockJsonFiles, blocksDest: this.dest.destination,
|
|
95
|
-
emittingWpmlXml: compilation.getAsset((0, node_path_1.join)(this.dest.destination, "wpml-config.xml")) !== undefined
|
|
96
|
-
});
|
|
97
|
-
const generateLoader = (writer) => {
|
|
98
|
-
writer.require((0, node_path_1.join)(this.dest.destination, "blockdir-loader.php"), { dirRelative: true, once: true });
|
|
99
|
-
};
|
|
100
|
-
let action;
|
|
101
|
-
const lazyLoader = this.dest.lazyLoader;
|
|
102
|
-
if (lazyLoader) {
|
|
103
|
-
try {
|
|
104
|
-
action = writer => writer.function(new expressions_1.NamespacedReference(this.config.targetNamespace, lazyLoader, 'function'), [], generateLoader, { returnType: 'void' });
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for lazily loading blocks", { cause: e }], this.dest.destination));
|
|
108
|
-
this.rejectSemaphores();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
action = writer => writer.withScope(generateLoader);
|
|
114
|
-
}
|
|
115
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(applicableBlockJsonFiles).length ? {
|
|
116
|
-
group: this.group,
|
|
117
|
-
requiresBaseURI: false,
|
|
118
|
-
staticallyLoadedEntrypoints,
|
|
119
|
-
action
|
|
120
|
-
} : undefined);
|
|
121
|
-
}
|
|
122
|
-
emitBlockLoaderFile(compilation, blockDirConfig) {
|
|
123
|
-
if (this.config.useUnifiedLoader) {
|
|
124
|
-
const { '__metadata': metadata, ...blockData } = blockDirConfig;
|
|
125
|
-
const splitOutInlinedAssets = (handles, type) => {
|
|
126
|
-
const registerableHandles = {};
|
|
127
|
-
const inlinedAssets = [];
|
|
128
|
-
for (const [handle, handleData] of Object.entries(handles)) {
|
|
129
|
-
const { inlinedAsset, ...finalizedHandle } = handleData;
|
|
130
|
-
if (inlinedAsset !== undefined) {
|
|
131
|
-
finalizedHandle.src = false;
|
|
132
|
-
inlinedAssets.push([handle, type, handleData]);
|
|
133
|
-
}
|
|
134
|
-
registerableHandles[handle] = finalizedHandle;
|
|
135
|
-
}
|
|
136
|
-
return [registerableHandles, inlinedAssets];
|
|
137
|
-
};
|
|
138
|
-
const [finalizedScriptHandles, inlinableScripts] = splitOutInlinedAssets(metadata.scriptHandles, 'script');
|
|
139
|
-
const [finalizedStyleHandles, inlinableStyles] = splitOutInlinedAssets(metadata.styleHandles, 'style');
|
|
140
|
-
const finalizedMetadata = Object.fromEntries(Object.entries(metadata)
|
|
141
|
-
.map(([key, value]) => {
|
|
142
|
-
if (key === 'scriptHandles') {
|
|
143
|
-
return [key, []];
|
|
144
|
-
}
|
|
145
|
-
if (key === 'styleHandles') {
|
|
146
|
-
return [key, []];
|
|
147
|
-
}
|
|
148
|
-
if (key === 'scriptModuleHandles') {
|
|
149
|
-
return [key, []];
|
|
150
|
-
}
|
|
151
|
-
return [key, value];
|
|
152
|
-
}));
|
|
153
|
-
const writer = new php_writer_1.PHPWriter()
|
|
154
|
-
.action("init", writer => {
|
|
155
|
-
const baseUriVar = new expressions_1.Var("base_uri");
|
|
156
|
-
writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
|
|
157
|
-
this.callRegisterFunction('script', writer, baseUriVar, Object.entries(finalizedScriptHandles));
|
|
158
|
-
this.callRegisterFunction('style', writer, baseUriVar, Object.entries(finalizedStyleHandles));
|
|
159
|
-
this.callRegisterFunction('script_module', writer, baseUriVar, Object.entries(metadata.scriptModuleHandles));
|
|
160
|
-
const entries = Object.entries(metadata.bindableBlockAttributes);
|
|
161
|
-
const supportedAttributes = new expressions_1.Var("supported_block_attributes", "?array");
|
|
162
|
-
if ((0, shared_1.arrayIsLength)(entries, 1)) {
|
|
163
|
-
writer.filter(`block_bindings_supported_attributes_${entries[0][0]}`, writer => {
|
|
164
|
-
const parameters = entries[0][1];
|
|
165
|
-
if (parameters.length === 1) {
|
|
166
|
-
writer.appendExpr(new expressions_1.Assignment(supportedAttributes, parameters[0], true));
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
writer.call("array_push", [supportedAttributes, ...parameters]);
|
|
170
|
-
}
|
|
171
|
-
writer.return(supportedAttributes);
|
|
172
|
-
}, { functionArgParameters: [supportedAttributes] });
|
|
173
|
-
}
|
|
174
|
-
else if (entries.length > 1) {
|
|
175
|
-
const compiledBindingSupportingAttributes = new expressions_1.Var("compiled_binding_supporting_attributes");
|
|
176
|
-
writer.assign(compiledBindingSupportingAttributes, metadata.bindableBlockAttributes);
|
|
177
|
-
const blockType = new expressions_1.Var("block_type", "?string");
|
|
178
|
-
writer.filter(`block_bindings_supported_attributes`, writer => {
|
|
179
|
-
writer
|
|
180
|
-
.if(expressions_1.Op.binary(expressions_1.Expr.call("empty", [blockType]), " || ", expressions_1.Expr.call("empty", [new expressions_1.ArrayAccess(compiledBindingSupportingAttributes, blockType)])))
|
|
181
|
-
.return(supportedAttributes)
|
|
182
|
-
.endIf()
|
|
183
|
-
.call("array_push", [supportedAttributes, new expressions_1.Op("...", new expressions_1.ArrayAccess(compiledBindingSupportingAttributes, blockType))])
|
|
184
|
-
.return(supportedAttributes);
|
|
185
|
-
}, { functionArgParameters: [supportedAttributes, blockType], useVars: [compiledBindingSupportingAttributes] });
|
|
186
|
-
}
|
|
187
|
-
writer.call("\\Plaudit\\Common\\ACF\\BlockManager::autoloadSubfoldersV3", [
|
|
188
|
-
expressions_1.Constants.__DIR__, // string $dir
|
|
189
|
-
new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockData, false, "\t")), // array $blockdirConfig
|
|
190
|
-
expressions_1.Constants.__FILE__, // string $blockdirConfigFile
|
|
191
|
-
new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(finalizedMetadata, false, "\t")), // array $metadata
|
|
192
|
-
null // ?string $urlPrefix
|
|
193
|
-
]);
|
|
194
|
-
for (const inlinableScript of inlinableScripts) {
|
|
195
|
-
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, ...inlinableScript);
|
|
196
|
-
}
|
|
197
|
-
for (const inlinableStyle of inlinableStyles) {
|
|
198
|
-
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, ...inlinableStyle);
|
|
199
|
-
}
|
|
200
|
-
}, { accountForAlreadyDoing: this.config.includePostInitFallback });
|
|
201
|
-
if (this.config.useBlockSupportsAsThemeJsonDefaults) {
|
|
202
|
-
const copyableBlockSupports = [];
|
|
203
|
-
for (const { name, supports } of Object.values(blockData)) {
|
|
204
|
-
if (typeof name === 'string' && !!name && typeof supports === 'object' && !!supports && !Array.isArray(supports)) {
|
|
205
|
-
const flagProps = EnhancedBlockJSONPlugin.pickOutFlagPropsFromBlockSupports(supports);
|
|
206
|
-
if (flagProps) {
|
|
207
|
-
copyableBlockSupports.push([name, flagProps]);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if (copyableBlockSupports.length > 0) {
|
|
212
|
-
const themeJsonBlockSettings = new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)({
|
|
213
|
-
version: 3,
|
|
214
|
-
settings: {
|
|
215
|
-
blocks: Object.fromEntries(copyableBlockSupports)
|
|
216
|
-
}
|
|
217
|
-
}, false, "\t"));
|
|
218
|
-
const theme_json = new expressions_1.Var("theme_json");
|
|
219
|
-
writer.filter('wp_theme_json_data_blocks', writer => {
|
|
220
|
-
const updateCall = new expressions_1.Call(expressions_1.Literal.of("update_with", true), [themeJsonBlockSettings]);
|
|
221
|
-
writer.appendExpr(new expressions_1.InstanceAccess(theme_json, [updateCall]), { return: true });
|
|
222
|
-
}, { functionArgParameters: [theme_json] });
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
(0, shared_1.emitPHPWriterAsAsset)(writer, compilation, (0, node_path_1.join)(this.dest.destination, "blockdir-loader.php"));
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
compilation.emitAsset((0, node_path_1.join)(this.dest.destination, "blockdir.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockDirConfig, true)));
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/*
|
|
232
|
-
* The block supports that have a boolean counterpart under theme.json's settings, as
|
|
233
|
-
* `settings key -> {support prop: settings prop}`. This is an allow-list rather than an ignore-list
|
|
234
|
-
* because most supports (align, alignWide, anchor, contentRole, inserter, interactivity, listView,
|
|
235
|
-
* plaudit, ...) have no theme.json settings equivalent at all, and the ones that do don't always
|
|
236
|
-
* share a name: typography's fontSize is settings.typography.customFontSize, and Gutenberg still
|
|
237
|
-
* ships several of these under an __experimental prefix.
|
|
238
|
-
*/
|
|
239
|
-
static THEME_JSON_FLAG_PROPS = {
|
|
240
|
-
color: { background: 'background', link: 'link', text: 'text' },
|
|
241
|
-
dimensions: { aspectRatio: 'aspectRatio', minHeight: 'minHeight' },
|
|
242
|
-
spacing: { blockGap: 'blockGap', margin: 'margin', padding: 'padding' },
|
|
243
|
-
typography: {
|
|
244
|
-
fontSize: 'customFontSize',
|
|
245
|
-
lineHeight: 'lineHeight',
|
|
246
|
-
textAlign: 'textAlign',
|
|
247
|
-
fontStyle: 'fontStyle', __experimentalFontStyle: 'fontStyle',
|
|
248
|
-
fontWeight: 'fontWeight', __experimentalFontWeight: 'fontWeight',
|
|
249
|
-
letterSpacing: 'letterSpacing', __experimentalLetterSpacing: 'letterSpacing',
|
|
250
|
-
textDecoration: 'textDecoration', __experimentalTextDecoration: 'textDecoration',
|
|
251
|
-
textTransform: 'textTransform', __experimentalTextTransform: 'textTransform',
|
|
252
|
-
writingMode: 'writingMode', __experimentalWritingMode: 'writingMode'
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
static pickOutFlagPropsFromBlockSupports(supports) {
|
|
256
|
-
function isRecord(value) {
|
|
257
|
-
return typeof value === 'object' && !!value && !Array.isArray(value);
|
|
258
|
-
}
|
|
259
|
-
let addedProp = false;
|
|
260
|
-
const res = {};
|
|
261
|
-
for (const [settingsKey, props] of Object.entries(EnhancedBlockJSONPlugin.THEME_JSON_FLAG_PROPS)) {
|
|
262
|
-
const support = supports[settingsKey];
|
|
263
|
-
if (!isRecord(support)) {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
const flags = {};
|
|
267
|
-
for (const [supportProp, settingsProp] of Object.entries(props)) {
|
|
268
|
-
// A sided support such as `"margin": ["top", "bottom"]` is still just "on" as far as theme.json is concerned
|
|
269
|
-
if (support[supportProp]) {
|
|
270
|
-
flags[settingsProp] = true;
|
|
271
|
-
res[settingsKey] = flags;
|
|
272
|
-
addedProp = true;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return addedProp ? res : undefined;
|
|
277
|
-
}
|
|
278
|
-
callRegisterFunction(type, writer, baseUriVar, handles) {
|
|
279
|
-
for (const [name, { src, rest }] of handles) {
|
|
280
|
-
writer.call(`wp_register_${type}`, [name, src === false ? false : expressions_1.Op.concat(baseUriVar, src), ...rest]);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
transformBlocks(compilation, collatedWorkableBlockInfo, emittingWpmlXml) {
|
|
284
|
-
const handleData = Object.values(collatedWorkableBlockInfo)
|
|
285
|
-
.flatMap(bi => bi.workableBlockEntrypointsInfo)
|
|
286
|
-
.sort((a, b) => a.handle.localeCompare(b.handle) || a.entrypointField.localeCompare(b.entrypointField));
|
|
287
|
-
const blockData = {};
|
|
288
|
-
const bindableBlockAttributes = {};
|
|
289
|
-
for (const [blockJsonAssetName, { sourcePath: blockJsonSourcePath, workableBlockEntrypointsInfo, blockJsonText }] of Object.entries(collatedWorkableBlockInfo)) {
|
|
290
|
-
if (!blockJsonSourcePath) {
|
|
291
|
-
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`${blockJsonAssetName} does not have a source path`, blockJsonAssetName));
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
if (!blockJsonText) {
|
|
295
|
-
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`${blockJsonAssetName} does not have recorded text`, blockJsonAssetName));
|
|
296
|
-
continue;
|
|
297
|
-
}
|
|
298
|
-
const sourceDir = (0, node_path_1.dirname)(blockJsonSourcePath);
|
|
299
|
-
const outputDir = (0, node_path_1.join)(compilation.compiler.outputPath, (0, node_path_1.dirname)(blockJsonAssetName));
|
|
300
|
-
const blockJson = JSON.parse(blockJsonText);
|
|
301
|
-
const pathsNeedRemapping = !this.config.standaloneBlocks && blockJson["plaudit"] !== "simple";
|
|
302
|
-
EnhancedBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "setup", pathsNeedRemapping, sourceDir, outputDir, compilation, true);
|
|
303
|
-
EnhancedBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "variations", pathsNeedRemapping, sourceDir, outputDir, compilation, false);
|
|
304
|
-
EnhancedBlockJSONPlugin.handleExperimentalBlockSupportsFlags(blockJson);
|
|
305
|
-
const hashForVersion = EnhancedBlockJSONPlugin
|
|
306
|
-
.hashThingForAsset([blockJsonText, ...workableBlockEntrypointsInfo.map(bi => bi.hash)].join("~"));
|
|
307
|
-
if (blockJson["version"]) {
|
|
308
|
-
blockJson["version"] = `${blockJson["version"]}-${hashForVersion}`;
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
blockJson["version"] = hashForVersion;
|
|
312
|
-
}
|
|
313
|
-
if (typeof blockJson["name"] === 'string' && typeof blockJson["attributes"] === 'object' && blockJson["attributes"]) {
|
|
314
|
-
for (const [name, attr] of Object.entries(blockJson["attributes"])) {
|
|
315
|
-
if (attr["supports-bindings"]) {
|
|
316
|
-
delete attr["supports-bindings"];
|
|
317
|
-
if (bindableBlockAttributes[blockJson["name"]] !== undefined) {
|
|
318
|
-
bindableBlockAttributes[blockJson["name"]].push(name);
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
bindableBlockAttributes[blockJson["name"]] = [name];
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
EnhancedBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
|
|
327
|
-
const blockDirName = (0, node_path_1.dirname)((0, node_path_1.relative)(this.dest.destination, blockJsonAssetName));
|
|
328
|
-
blockData[blockDirName] = EnhancedBlockJSONPlugin
|
|
329
|
-
.doFileOrHandleReplacements(compilation, Object.fromEntries(Object.entries(blockJson).filter(([k]) => k !== '$schema')), workableBlockEntrypointsInfo, epi => epi.handle);
|
|
330
|
-
const emittableBlockJson = EnhancedBlockJSONPlugin.doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, epi => "file:./" + (0, node_path_1.relative)(blockDirName, epi.outputPath));
|
|
331
|
-
compilation[blockJsonAssetName in compilation.assets ? 'updateAsset' : 'emitAsset'](blockJsonAssetName, new webpack_1.sources.RawSource(JSON.stringify(emittableBlockJson, undefined, " ")));
|
|
332
|
-
}
|
|
333
|
-
return {
|
|
334
|
-
__metadata: {
|
|
335
|
-
version: 3,
|
|
336
|
-
"wpml-config": emittingWpmlXml,
|
|
337
|
-
scriptHandles: Object.fromEntries(EnhancedBlockJSONPlugin
|
|
338
|
-
.convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && !(0, shared_1.isScriptModuleField)(hd.entrypointField)))),
|
|
339
|
-
scriptModuleHandles: Object.fromEntries(EnhancedBlockJSONPlugin
|
|
340
|
-
.convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && (0, shared_1.isScriptModuleField)(hd.entrypointField)))),
|
|
341
|
-
styleHandles: Object.fromEntries(handleData.filter(hd => (0, shared_1.isStyleField)(hd.entrypointField))
|
|
342
|
-
.map(hd => {
|
|
343
|
-
if (hd.inlinedAsset === undefined) {
|
|
344
|
-
return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], assetContents: hd.assetContents }];
|
|
345
|
-
}
|
|
346
|
-
return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], inlinedAsset: hd.inlinedAsset, assetContents: hd.assetContents }];
|
|
347
|
-
})),
|
|
348
|
-
bindableBlockAttributes
|
|
349
|
-
},
|
|
350
|
-
...Object.fromEntries(Object.entries(blockData).sort((a, b) => a[0].localeCompare(b[0])))
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
static extractAssetSource(compilation, assetName) {
|
|
354
|
-
const assetSource = compilation.getAsset(assetName)?.source.source();
|
|
355
|
-
return typeof assetSource === 'string' ? assetSource : assetSource?.toString('utf-8');
|
|
356
|
-
}
|
|
357
|
-
static convertToScriptHandles(handleData) {
|
|
358
|
-
return handleData.map(hd => {
|
|
359
|
-
const { assetContents, inlinedAsset, originalValue, outputPath, entrypointField, scriptArgsObject: rawScriptArgsObject, assetData, handle } = hd;
|
|
360
|
-
const { dependencies = [], module_dependencies = undefined } = originalValue !== undefined ? assetData : {};
|
|
361
|
-
let scriptArgsObject;
|
|
362
|
-
if (rawScriptArgsObject !== undefined) {
|
|
363
|
-
const merged_module_dependencies = (0, shared_1.mergeModuleDependencyArrays)(rawScriptArgsObject.module_dependencies, module_dependencies);
|
|
364
|
-
scriptArgsObject = merged_module_dependencies?.length ? { ...rawScriptArgsObject, module_dependencies: merged_module_dependencies } : { ...rawScriptArgsObject };
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
if (inlinedAsset !== undefined) {
|
|
368
|
-
scriptArgsObject = inlinedAsset.position === 'before' ? { strategy: "defer" } : undefined;
|
|
369
|
-
}
|
|
370
|
-
else if (!entrypointField.startsWith("editor")) {
|
|
371
|
-
scriptArgsObject = { strategy: "defer" };
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
scriptArgsObject = undefined;
|
|
375
|
-
}
|
|
376
|
-
if (module_dependencies?.length) {
|
|
377
|
-
if (scriptArgsObject === undefined) {
|
|
378
|
-
scriptArgsObject = { module_dependencies };
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
scriptArgsObject.module_dependencies = module_dependencies;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
const rest = scriptArgsObject !== undefined ? [dependencies, assetData.version, scriptArgsObject] : [dependencies, assetData.version];
|
|
386
|
-
if (inlinedAsset) {
|
|
387
|
-
return [handle, { src: outputPath, rest, inlinedAsset, assetContents }];
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
return [handle, { src: outputPath, rest, assetContents }];
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
static doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, getter) {
|
|
395
|
-
for (const entrypointInfo of workableBlockEntrypointsInfo) {
|
|
396
|
-
const fieldValue = blockJson[entrypointInfo.entrypointField];
|
|
397
|
-
if (!fieldValue) {
|
|
398
|
-
blockJson[entrypointInfo.entrypointField] = getter(entrypointInfo);
|
|
399
|
-
}
|
|
400
|
-
else if (entrypointInfo.originalValue) {
|
|
401
|
-
if (entrypointInfo.originalValue === fieldValue) {
|
|
402
|
-
blockJson[entrypointInfo.entrypointField] = getter(entrypointInfo);
|
|
403
|
-
}
|
|
404
|
-
else if (typeof fieldValue === 'string') {
|
|
405
|
-
blockJson[entrypointInfo.entrypointField] = [fieldValue, getter(entrypointInfo)];
|
|
406
|
-
}
|
|
407
|
-
else if (Array.isArray(fieldValue)) {
|
|
408
|
-
const replacementPos = fieldValue.indexOf(entrypointInfo.originalValue);
|
|
409
|
-
if (replacementPos === -1) {
|
|
410
|
-
compilation.warnings.push((0, shared_1.newWebpackErrorForFile)(`Unable to find ${entrypointInfo.originalValue} in ${entrypointInfo.entrypointField}`, entrypointInfo.blockJsonOrigin));
|
|
411
|
-
blockJson[entrypointInfo.entrypointField] = fieldValue.concat(getter(entrypointInfo));
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
blockJson[entrypointInfo.entrypointField] = fieldValue.toSpliced(replacementPos, 1, getter(entrypointInfo));
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
blockJson[entrypointInfo.entrypointField] = getter(entrypointInfo);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
if (typeof fieldValue === 'string') {
|
|
423
|
-
blockJson[entrypointInfo.entrypointField] = [fieldValue, getter(entrypointInfo)];
|
|
424
|
-
}
|
|
425
|
-
else if (Array.isArray(fieldValue)) {
|
|
426
|
-
blockJson[entrypointInfo.entrypointField] = fieldValue.concat(getter(entrypointInfo));
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
blockJson[entrypointInfo.entrypointField] = getter(entrypointInfo);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
return blockJson;
|
|
434
|
-
}
|
|
435
|
-
stripOffBlocksDestPrefix(file) {
|
|
436
|
-
return this.dest.destination && file.startsWith(this.dest.destination + "/") ? file.substring(this.dest.destination.length + 1 /* we also need to drop the "/" */) : file;
|
|
437
|
-
}
|
|
438
|
-
static hashThingForAsset(thing) {
|
|
439
|
-
return (0, node_crypto_1.createHash)('md5').update(thing).digest("hex").substring(0, 20).toLowerCase();
|
|
440
|
-
}
|
|
441
|
-
static stripFilePrefix(file) {
|
|
442
|
-
return file.startsWith("file:./") ? file.substring(7) : file;
|
|
443
|
-
}
|
|
444
|
-
static findCommonAncestor(...paths) {
|
|
445
|
-
return paths.map(p => (0, node_path_1.normalize)(p).split(node_path_1.sep)).reduce((prior, current) => {
|
|
446
|
-
for (let i = 0, limit = Math.min(prior.length, current.length); i < limit; i++) {
|
|
447
|
-
if (prior[i] !== current[i]) {
|
|
448
|
-
return prior.slice(0, i);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
return current.length < prior.length ? current : prior;
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
static findRelativeRouteBetween(path1, path2) {
|
|
455
|
-
const commonAncestor = EnhancedBlockJSONPlugin.findCommonAncestor(path1, path2);
|
|
456
|
-
return (".." + node_path_1.sep).repeat(path1.split(node_path_1.sep).length - commonAncestor.length) + (0, node_path_1.relative)(commonAncestor.join(node_path_1.sep), path2);
|
|
457
|
-
}
|
|
458
|
-
static remapReferencedPHPFilesOnKey(blockJson, key, pathsNeedRemapping, sourceDir, outputDir, compilation, inPlaudit) {
|
|
459
|
-
const rawValue = (inPlaudit ? blockJson["plaudit"] : blockJson)?.[key];
|
|
460
|
-
let rawFiles;
|
|
461
|
-
let deleteOnEmpty = true;
|
|
462
|
-
if (typeof rawValue === 'string') {
|
|
463
|
-
rawFiles = [rawValue];
|
|
464
|
-
}
|
|
465
|
-
else if (Array.isArray(rawValue) && rawValue.length > 0) {
|
|
466
|
-
const fileReferences = rawValue.filter((value) => typeof value === 'string' && value.startsWith("file:./"));
|
|
467
|
-
if (fileReferences.length === rawValue.length) {
|
|
468
|
-
rawFiles = fileReferences;
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
if (fileReferences.length !== 0) {
|
|
472
|
-
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`, (0, node_path_1.join)(sourceDir, 'block.json')));
|
|
473
|
-
rawFiles = fileReferences;
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
rawFiles = [`${key}.php`]; // We want to emit an error if both an appropriately-named file AND an incompatible value exist, so we still need to do the check
|
|
477
|
-
}
|
|
478
|
-
deleteOnEmpty = false;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
if (rawValue && (!Array.isArray(rawValue) || rawValue.length === 0)) {
|
|
483
|
-
deleteOnEmpty = false;
|
|
484
|
-
}
|
|
485
|
-
rawFiles = [`${key}.php`];
|
|
486
|
-
}
|
|
487
|
-
const mappedFiles = pathsNeedRemapping
|
|
488
|
-
? rawFiles
|
|
489
|
-
.map(p => (0, node_path_1.normalize)((0, node_path_1.join)(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
|
|
490
|
-
.filter(node_fs_1.existsSync)
|
|
491
|
-
.map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
|
|
492
|
-
: rawFiles
|
|
493
|
-
.filter(p => (0, node_fs_1.existsSync)((0, node_path_1.normalize)((0, node_path_1.join)(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
|
|
494
|
-
if (mappedFiles.length === 0) {
|
|
495
|
-
if (deleteOnEmpty && rawValue !== undefined) {
|
|
496
|
-
delete (inPlaudit ? blockJson["plaudit"] : blockJson)[key];
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
if (inPlaudit && typeof blockJson["plaudit"] !== 'object') {
|
|
501
|
-
if (blockJson["plaudit"] === "native") {
|
|
502
|
-
blockJson["plaudit"] = { type: "native" };
|
|
503
|
-
}
|
|
504
|
-
else {
|
|
505
|
-
blockJson["plaudit"] = {};
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
(inPlaudit ? blockJson["plaudit"] : blockJson)[key] = mappedFiles.length === 1 ? mappedFiles[0] : mappedFiles;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
static normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation) {
|
|
512
|
-
if (blockJson["acf"]) {
|
|
513
|
-
if (blockJson["acf"]["renderTemplate"]) {
|
|
514
|
-
blockJson["render_template"] = blockJson["acf"]["renderTemplate"];
|
|
515
|
-
delete blockJson["acf"]["renderTemplate"];
|
|
516
|
-
}
|
|
517
|
-
else if (blockJson["acf"]["render_template"]) {
|
|
518
|
-
blockJson["render_template"] = blockJson["acf"]["render_template"];
|
|
519
|
-
delete blockJson["acf"]["render_template"];
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
const blockName = blockJson["name"]?.toString() || "non-existent/block-name";
|
|
523
|
-
let rawRenderTemplate = blockJson["render"] ?? blockJson["render_template"];
|
|
524
|
-
rawRenderTemplate = (rawRenderTemplate
|
|
525
|
-
? (typeof rawRenderTemplate === 'string' ? [rawRenderTemplate] : rawRenderTemplate)
|
|
526
|
-
: [`${blockName.substring(blockName.indexOf('/') + 1)}.php`, "template.php", "template.twig"]);
|
|
527
|
-
const renderTemplate = pathsNeedRemapping
|
|
528
|
-
? rawRenderTemplate
|
|
529
|
-
.map(p => (0, node_path_1.normalize)((0, node_path_1.join)(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
|
|
530
|
-
.filter(node_fs_1.existsSync)
|
|
531
|
-
.map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
|
|
532
|
-
: rawRenderTemplate
|
|
533
|
-
.filter(p => (0, node_fs_1.existsSync)((0, node_path_1.normalize)((0, node_path_1.join)(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
|
|
534
|
-
if (renderTemplate.length === 0) {
|
|
535
|
-
delete blockJson["render_template"];
|
|
536
|
-
delete blockJson["render"];
|
|
537
|
-
}
|
|
538
|
-
else {
|
|
539
|
-
let validTemplateLocation, invalidTemplateLocation;
|
|
540
|
-
if (blockJson["acf"] || (blockJson["plaudit"] && (blockJson["plaudit"] !== "native" && (typeof blockJson["plaudit"] !== 'object' || blockJson["plaudit"]?.["type"] !== "native")))) {
|
|
541
|
-
// ACF-like blocks need to have the template stored in render_template.
|
|
542
|
-
// Because we can statically detect ACF-like blocks, we can make the move here instead of at run-time.
|
|
543
|
-
validTemplateLocation = "render_template";
|
|
544
|
-
invalidTemplateLocation = "render";
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
validTemplateLocation = "render";
|
|
548
|
-
invalidTemplateLocation = "render_template";
|
|
549
|
-
}
|
|
550
|
-
delete blockJson[invalidTemplateLocation];
|
|
551
|
-
if (renderTemplate.length > 1) {
|
|
552
|
-
compilation.warnings.push((0, shared_1.newWebpackErrorForFile)("Encountered a block with multiple possible render files. Please set the render key in block.json to the intended one", (0, node_path_1.join)(sourceDir, 'block.json')));
|
|
553
|
-
blockJson[validTemplateLocation] = renderTemplate.find(p => p.endsWith(".php")) ?? renderTemplate[0];
|
|
554
|
-
}
|
|
555
|
-
else {
|
|
556
|
-
blockJson[validTemplateLocation] = renderTemplate[0];
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
static knownExperimentalProperties = ['border', 'defaultControls', 'fontFamily', 'fontWeight', 'fontStyle', 'letterSpacing', 'textTransform', 'textDecoration']
|
|
561
|
-
.map(prop => [prop, "__experimental" + prop.substring(0, 1).toUpperCase() + prop.substring(1)]);
|
|
562
|
-
static handleExperimentalBlockSupportsFlags(blockSupports) {
|
|
563
|
-
for (const [key, value] of Object.entries(blockSupports)) {
|
|
564
|
-
if (typeof value === 'object' && !!value && !Array.isArray(value)) {
|
|
565
|
-
EnhancedBlockJSONPlugin.handleExperimentalBlockSupportsFlags(value);
|
|
566
|
-
}
|
|
567
|
-
if (!key.startsWith("__experimental")) {
|
|
568
|
-
continue;
|
|
569
|
-
}
|
|
570
|
-
const realKey = key.substring(14, 15).toLowerCase() + key.substring(15);
|
|
571
|
-
if (!(realKey in blockSupports)) {
|
|
572
|
-
blockSupports[realKey] = value;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
// This handles known currently-experimental properties
|
|
576
|
-
for (const [eventualKey, experimentalKey] of EnhancedBlockJSONPlugin.knownExperimentalProperties) {
|
|
577
|
-
if (eventualKey in blockSupports && !(experimentalKey in blockSupports)) {
|
|
578
|
-
blockSupports[experimentalKey] = blockSupports[eventualKey];
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
attachUniquePhase(compilation) {
|
|
583
|
-
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
584
|
-
const allSemaphoreData = (await EnhancedBlockJSONPlugin.semaphore.wait())
|
|
585
|
-
.reduce((acc, cur) => {
|
|
586
|
-
(acc[cur.blocksDest] ?? (acc[cur.blocksDest] = [])).push(cur);
|
|
587
|
-
return acc;
|
|
588
|
-
}, {});
|
|
589
|
-
const semaphoreData = allSemaphoreData[this.dest.destination];
|
|
590
|
-
if (semaphoreData === undefined) {
|
|
591
|
-
compilation.errors.push(new Error(`Semaphore data missing for ${this.dest.destination}`));
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
const workableBlockInfo = semaphoreData.map(sd => sd.collatableWorkableBlockInfo)
|
|
595
|
-
.reduce((acc, cur) => {
|
|
596
|
-
for (const [k, v] of Object.entries(cur)) {
|
|
597
|
-
if (acc[k]) {
|
|
598
|
-
acc[k].workableBlockEntrypointsInfo.push(...v.workableBlockEntrypointsInfo);
|
|
599
|
-
if (!acc[k].sourcePath && v.sourcePath) {
|
|
600
|
-
acc[k].sourcePath = v.sourcePath;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
else {
|
|
604
|
-
acc[k] = { ...v, workableBlockEntrypointsInfo: [...v.workableBlockEntrypointsInfo] };
|
|
605
|
-
}
|
|
606
|
-
acc[k].workableBlockEntrypointsInfo.sort((a, b) => {
|
|
607
|
-
return a.handle.localeCompare(b.handle) || a.entrypointField.localeCompare(b.entrypointField);
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
return acc;
|
|
611
|
-
}, {});
|
|
612
|
-
const blockData = this.transformBlocks(compilation, this.deduplicateEntrypointHandles(workableBlockInfo), semaphoreData.some(sd => sd.emittingWpmlXml));
|
|
613
|
-
this.emitBlockLoaderFile(compilation, blockData);
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
attachStandardPhase(compilation) {
|
|
617
|
-
super.attachStandardPhase(compilation);
|
|
618
|
-
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER }, async () => {
|
|
619
|
-
const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
|
|
620
|
-
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
621
|
-
if ((0, node_path_1.basename)(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
|
|
622
|
-
continue;
|
|
623
|
-
}
|
|
624
|
-
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
625
|
-
for (const danglingBlockJsFile of [...entrypointChunk.files, ...entrypointChunk.auxiliaryFiles]) {
|
|
626
|
-
if (!danglingBlockJsFile.endsWith("block.json")) {
|
|
627
|
-
compilation.deleteAsset(danglingBlockJsFile);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
deduplicateEntrypointHandles(workableBlockInfo) {
|
|
634
|
-
const handleRecords = { scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {} };
|
|
635
|
-
for (const { workableBlockEntrypointsInfo } of Object.values(workableBlockInfo)) {
|
|
636
|
-
for (const { handleGroup, handle, originalValue, outputPath } of workableBlockEntrypointsInfo) {
|
|
637
|
-
if (originalValue !== undefined) {
|
|
638
|
-
handleRecords[handleGroup][handle] = outputPath;
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
return Object.fromEntries(Object.entries(workableBlockInfo).map((e) => {
|
|
643
|
-
const deduplicatedWorkableBlockEntrypointsInfo = e[1].workableBlockEntrypointsInfo.map(bei => {
|
|
644
|
-
if (handleRecords[bei.handleGroup][bei.handle] === bei.outputPath) {
|
|
645
|
-
return bei;
|
|
646
|
-
}
|
|
647
|
-
for (let count = 1, handle = `${bei.handle}_${count}`;; handle = `${bei.handle}_${++count}`) {
|
|
648
|
-
if (!handleRecords[bei.handleGroup][handle] || handleRecords[bei.handleGroup][handle] === bei.outputPath) {
|
|
649
|
-
return { ...bei, handle };
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
});
|
|
653
|
-
return [e[0], { ...e[1], workableBlockEntrypointsInfo: deduplicatedWorkableBlockEntrypointsInfo }];
|
|
654
|
-
}));
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
exports.EnhancedBlockJSONPlugin = EnhancedBlockJSONPlugin;
|