@plaudit/webpack-extensions 2.38.0 → 2.40.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/wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin.d.ts +2 -1
- package/build/wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin.js +29 -36
- package/build/wordpress-scripts-wrapper/BlockJSONManagingPlugin.d.ts +10 -1
- package/build/wordpress-scripts-wrapper/BlockJSONManagingPlugin.js +292 -166
- package/build/wordpress-scripts-wrapper/WPMLConfigBuilder.d.ts +16 -0
- package/build/wordpress-scripts-wrapper/WPMLConfigBuilder.js +471 -0
- package/build/wordpress-scripts-wrapper/dependency-extraction-webpack-plugin-config-builder.d.ts +4 -1
- package/build/wordpress-scripts-wrapper/dependency-extraction-webpack-plugin-config-builder.js +22 -9
- package/build/wordpress-scripts-wrapper.d.ts +2 -0
- package/build/wordpress-scripts-wrapper.js +89 -44
- package/package.json +91 -72
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
7
|
+
const jsdom_1 = require("jsdom");
|
|
8
|
+
const webpack_1 = require("webpack");
|
|
9
|
+
const xml_formatter_1 = __importDefault(require("xml-formatter"));
|
|
10
|
+
class WPMLConfigBuilder {
|
|
11
|
+
blockJSONManagingPlugin;
|
|
12
|
+
static jsdomInstance;
|
|
13
|
+
static domParser;
|
|
14
|
+
static xmlSerializer;
|
|
15
|
+
parsedDocumentsCache = new Map();
|
|
16
|
+
constructor(blockJSONManagingPlugin) {
|
|
17
|
+
this.blockJSONManagingPlugin = blockJSONManagingPlugin;
|
|
18
|
+
}
|
|
19
|
+
apply(compiler) {
|
|
20
|
+
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
21
|
+
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}__processXML`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, async (assets) => {
|
|
22
|
+
const entrypoint = compilation.entrypoints.get("wpml-config.xml");
|
|
23
|
+
if (!entrypoint) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const files = Promise.all([
|
|
27
|
+
Promise.all(entrypoint.origins.map(origin => origin.request).filter(request => request.endsWith("wpml-config.xml"))
|
|
28
|
+
.map(async (request) => this.loadWPMLConfigXML(request, compilation))),
|
|
29
|
+
Promise.all(entrypoint.origins.map(origin => origin.request).filter(request => request.endsWith("block.json"))
|
|
30
|
+
.map(async (request) => [JSON.parse(await promises_1.default.readFile(request, 'utf8')), request]))
|
|
31
|
+
]);
|
|
32
|
+
for (const name of Object.keys(assets)) {
|
|
33
|
+
if (name.startsWith("wpml-config.xml")) {
|
|
34
|
+
compilation.deleteAsset(name);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const [wpmlConfigs, blockJsons] = await files;
|
|
38
|
+
if (!wpmlConfigs.length && !blockJsons.length) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const mergedConfig = {
|
|
42
|
+
customFields: {}, customTermFields: {}, customTypes: {}, gutenbergBlocks: {}, shortcodeList: new Set(), shortcodes: {}, taxonomies: {}
|
|
43
|
+
};
|
|
44
|
+
const nonMergeableCategories = ['customFields', 'customTermFields', 'customTypes', 'shortcodes', 'taxonomies'];
|
|
45
|
+
for (const [wpmlConfig, file] of wpmlConfigs) {
|
|
46
|
+
for (const category of nonMergeableCategories) {
|
|
47
|
+
for (const [key, value] of Object.entries(wpmlConfig[category])) {
|
|
48
|
+
if (key in mergedConfig[category]) {
|
|
49
|
+
compilation.errors.push(newWebpackErrorForFile(`Already encountered a definition for the ${category} entry named, "${key}"`, file));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
mergedConfig[category][key] = value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const shortcode of wpmlConfig.shortcodeList) {
|
|
57
|
+
mergedConfig.shortcodeList.add(shortcode);
|
|
58
|
+
}
|
|
59
|
+
for (const [type, block] of Object.entries(wpmlConfig.gutenbergBlocks)) {
|
|
60
|
+
const existing = mergedConfig.gutenbergBlocks[type];
|
|
61
|
+
try {
|
|
62
|
+
mergedConfig.gutenbergBlocks[type] = existing ? mergeWPMLGutenbergBlocks(existing, block) : block;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
if (typeof e === 'string') {
|
|
66
|
+
compilation.errors.push(newWebpackErrorForFile(e, file));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
compilation.errors.push(e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const [blockJson, file] of blockJsons) {
|
|
75
|
+
const type = blockJson["name"]?.toString();
|
|
76
|
+
if (typeof type !== 'string') {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const blockConfig = { type, translate: '1', keys: [], xPaths: [] };
|
|
80
|
+
if (blockJson['plaudit']?.['properties']) {
|
|
81
|
+
const snps = blockJson['plaudit']['properties'];
|
|
82
|
+
if (Array.isArray(snps)) {
|
|
83
|
+
for (const snp of snps) {
|
|
84
|
+
convertSNPToKeys(snp, blockConfig.keys);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
convertSNPToKeys(snps, blockConfig.keys);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (typeof blockJson['attributes'] === 'object') {
|
|
92
|
+
for (const [name, { translatable }] of Object.entries(blockJson['attributes'])) {
|
|
93
|
+
if (translatable) {
|
|
94
|
+
blockConfig.keys.push({ name, keys: [] });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const existing = mergedConfig.gutenbergBlocks[blockConfig.type];
|
|
99
|
+
if (blockConfig.keys.length || blockConfig.xPaths.length) {
|
|
100
|
+
mergedConfig.gutenbergBlocks[blockConfig.type] = existing ? mergeWPMLGutenbergBlocks(existing, blockConfig) : blockConfig;
|
|
101
|
+
}
|
|
102
|
+
else if (!existing) {
|
|
103
|
+
mergedConfig.gutenbergBlocks[blockConfig.type] = blockConfig;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const config = WPMLConfigBuilder.getDOMParser().parseFromString("<wpml-config></wpml-config>", "application/xml");
|
|
107
|
+
appendNamedElementsListToConfig("custom-fields", mergedConfig.customFields, config);
|
|
108
|
+
appendNamedElementsListToConfig("custom-term-fields", mergedConfig.customTermFields, config);
|
|
109
|
+
appendNamedElementsListToConfig("custom-types", mergedConfig.customTypes, config);
|
|
110
|
+
const gutenbergBlocks = Object.values(mergedConfig.gutenbergBlocks);
|
|
111
|
+
if (gutenbergBlocks.length) {
|
|
112
|
+
const gutenbergBlocksElement = config.createElement("gutenberg-blocks");
|
|
113
|
+
gutenbergBlocksElement.append(...gutenbergBlocks
|
|
114
|
+
.sort((a, b) => a.type.localeCompare(b.type))
|
|
115
|
+
.map(gutenbergBlock => {
|
|
116
|
+
const gutenbergBlockElement = config.createElement("gutenberg-block");
|
|
117
|
+
gutenbergBlockElement.setAttribute("type", gutenbergBlock.type);
|
|
118
|
+
if (gutenbergBlock.label) {
|
|
119
|
+
gutenbergBlockElement.setAttribute("label", gutenbergBlock.label);
|
|
120
|
+
}
|
|
121
|
+
gutenbergBlockElement.setAttribute("translate", gutenbergBlock.translate);
|
|
122
|
+
writeGenericSettingsKeys(gutenbergBlock.keys, gutenbergBlockElement, config);
|
|
123
|
+
gutenbergBlockElement.append(...gutenbergBlock.xPaths
|
|
124
|
+
.sort((a, b) => a.path.localeCompare(b.path))
|
|
125
|
+
.map(xPath => {
|
|
126
|
+
const xPathElement = config.createElement("xpath");
|
|
127
|
+
writeCommonGenericSettingsItemProps(xPathElement, xPath);
|
|
128
|
+
xPathElement.append(xPath.path);
|
|
129
|
+
return xPathElement;
|
|
130
|
+
}));
|
|
131
|
+
return gutenbergBlockElement;
|
|
132
|
+
}));
|
|
133
|
+
config.documentElement.append(gutenbergBlocksElement);
|
|
134
|
+
}
|
|
135
|
+
if (mergedConfig.shortcodeList.size) {
|
|
136
|
+
const node = config.createElement("shortcode-list");
|
|
137
|
+
node.append([...mergedConfig.shortcodeList].sort().join(","));
|
|
138
|
+
config.documentElement.appendChild(node);
|
|
139
|
+
}
|
|
140
|
+
appendNamedElementsListToConfig("shortcodes", mergedConfig.shortcodes, config);
|
|
141
|
+
appendNamedElementsListToConfig("taxonomies", mergedConfig.taxonomies, config);
|
|
142
|
+
this.blockJSONManagingPlugin.additionalMetadata.set("wpml-config", true);
|
|
143
|
+
compilation["wpml-config.xml" in compilation.assets ? 'updateAsset' : 'emitAsset']("wpml-config.xml", new webpack_1.sources.RawSource(WPMLConfigBuilder.prettyPrintXML(config)));
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
static getJSDOMInstance() {
|
|
148
|
+
return WPMLConfigBuilder.jsdomInstance ?? (WPMLConfigBuilder.jsdomInstance = new jsdom_1.JSDOM("", { contentType: "text/html" }));
|
|
149
|
+
}
|
|
150
|
+
static getDOMParser() {
|
|
151
|
+
return WPMLConfigBuilder.domParser ?? (WPMLConfigBuilder.domParser = new (WPMLConfigBuilder.getJSDOMInstance().window.DOMParser)());
|
|
152
|
+
}
|
|
153
|
+
static getXMLSerializer() {
|
|
154
|
+
return WPMLConfigBuilder.xmlSerializer ?? (WPMLConfigBuilder.xmlSerializer = new (WPMLConfigBuilder.getJSDOMInstance().window.XMLSerializer)());
|
|
155
|
+
}
|
|
156
|
+
static prettyPrintXML(document) {
|
|
157
|
+
return (0, xml_formatter_1.default)(WPMLConfigBuilder.getXMLSerializer().serializeToString(document), {
|
|
158
|
+
indentation: '\t',
|
|
159
|
+
collapseContent: true,
|
|
160
|
+
lineSeparator: '\n',
|
|
161
|
+
whiteSpaceAtEndOfSelfclosingTag: true,
|
|
162
|
+
forceSelfClosingEmptyTag: true,
|
|
163
|
+
strictMode: true,
|
|
164
|
+
filter(node) {
|
|
165
|
+
return node.type === 'Element' || node.type === 'Text';
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async loadWPMLConfigXML(file, compilation) {
|
|
170
|
+
const contents = await promises_1.default.readFile(file, 'utf8');
|
|
171
|
+
const existing = this.parsedDocumentsCache.get(file);
|
|
172
|
+
if (existing?.raw === contents) {
|
|
173
|
+
return [existing, file];
|
|
174
|
+
}
|
|
175
|
+
const wpmlConfig = WPMLConfigBuilder.getDOMParser().parseFromString(contents.replaceAll(/\s+xmlns=['"][^'"]+['"]/sig, ""), "application/xml");
|
|
176
|
+
const res = { raw: contents, customFields: {}, customTermFields: {}, customTypes: {}, gutenbergBlocks: {}, shortcodeList: new Set(), shortcodes: {}, taxonomies: {} };
|
|
177
|
+
for (const element of wpmlConfig.documentElement.children) {
|
|
178
|
+
switch (element.nodeName) {
|
|
179
|
+
case "custom-fields":
|
|
180
|
+
importStandardTranslateActionMap(element, file, "custom-field", res.customFields, compilation);
|
|
181
|
+
break;
|
|
182
|
+
case "custom-term-fields":
|
|
183
|
+
importStandardTranslateActionMap(element, file, "custom-term-field", res.customTermFields, compilation);
|
|
184
|
+
break;
|
|
185
|
+
case "custom-types":
|
|
186
|
+
importStandardTranslateOptionMap(element, file, "custom-type", res.customTypes, compilation);
|
|
187
|
+
break;
|
|
188
|
+
case "gutenberg-blocks":
|
|
189
|
+
for (const child of element.children) {
|
|
190
|
+
try {
|
|
191
|
+
const block = convertGutenbergBlockToJSRepresentation(child);
|
|
192
|
+
const existing = res.gutenbergBlocks[block.type];
|
|
193
|
+
if (existing) {
|
|
194
|
+
res.gutenbergBlocks[block.type] = mergeWPMLGutenbergBlocks(existing, block);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
res.gutenbergBlocks[block.type] = block;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
if (typeof e === 'string') {
|
|
202
|
+
compilation.errors.push(newWebpackErrorForFile(e, file));
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
compilation.errors.push(e);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
case "shortcode-list":
|
|
211
|
+
if (element.textContent) {
|
|
212
|
+
for (const shortcode of element.textContent.split(",")) {
|
|
213
|
+
res.shortcodeList.add(shortcode.trim());
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
case "shortcodes":
|
|
218
|
+
for (const child of element.children) {
|
|
219
|
+
const tag = child.getElementsByTagName("tag")[0];
|
|
220
|
+
const shortcodeName = tag?.textContent?.trim();
|
|
221
|
+
if (!shortcodeName) {
|
|
222
|
+
compilation.errors.push(newWebpackErrorForFile(`A shortcode entry in a wpml-config.xml file is missing its tag name.`, file));
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const existing = res.shortcodes[shortcodeName];
|
|
226
|
+
if (existing) {
|
|
227
|
+
compilation.errors.push(newWebpackErrorForFile(`Already encountered a definition for the shortcode entry named, "${shortcodeName}"`, file));
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
res.shortcodes[shortcodeName] = child;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
break;
|
|
234
|
+
case "taxonomies":
|
|
235
|
+
importStandardTranslateOptionMap(element, file, "taxonomy", res.taxonomies, compilation);
|
|
236
|
+
break;
|
|
237
|
+
default:
|
|
238
|
+
compilation.errors.push(newWebpackErrorForFile(`Unsupported element type in a wpml-config.xml file: ${element.nodeName}`, file));
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
this.parsedDocumentsCache.set(file, res);
|
|
243
|
+
return [res, file];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
exports.default = WPMLConfigBuilder;
|
|
247
|
+
function importStandardTranslateOptionMap(element, file, type, actionMap, compilation) {
|
|
248
|
+
for (const child of element.children) {
|
|
249
|
+
const field = child.textContent;
|
|
250
|
+
if (!field) {
|
|
251
|
+
compilation.errors.push(newWebpackErrorForFile(`Encountered an empty ${type} entry in a wpml-config.xml file.`, file));
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const translate = child.getAttribute("translate");
|
|
255
|
+
if (!translate) {
|
|
256
|
+
compilation.errors.push(newWebpackErrorForFile(`The ${type} entry for ${field} is missing the translate attribute.`, file));
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
const existing = actionMap[field];
|
|
260
|
+
if (existing) {
|
|
261
|
+
compilation.errors.push(newWebpackErrorForFile(`Already encountered a definition for the ${type} entry named, "${field}"`, file));
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
actionMap[field] = child;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function importStandardTranslateActionMap(element, file, type, actionMap, compilation) {
|
|
269
|
+
for (const child of element.children) {
|
|
270
|
+
const field = child.textContent?.trim();
|
|
271
|
+
if (!field) {
|
|
272
|
+
compilation.errors.push(newWebpackErrorForFile(`Encountered a empty ${type} entry without a name in a wpml-config.xml file.`, file));
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const action = child.getAttribute("action");
|
|
276
|
+
if (!action) {
|
|
277
|
+
compilation.errors.push(newWebpackErrorForFile(`The ${type} entry for ${field} is missing an action.`, file));
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const existing = actionMap[field];
|
|
281
|
+
if (existing) {
|
|
282
|
+
compilation.errors.push(newWebpackErrorForFile(`Already encountered a definition for the ${type} entry named, "${field}"`, file));
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
actionMap[field] = child;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function convertSNPToKeys(prop, keys) {
|
|
290
|
+
if (Array.isArray(prop)) {
|
|
291
|
+
for (const p of prop) {
|
|
292
|
+
convertSNPToKeys(p, keys);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
else if ('properties' in prop) {
|
|
296
|
+
for (const item of prop.properties) {
|
|
297
|
+
convertSNPToKeys(item, keys);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else if ('items' in prop) {
|
|
301
|
+
for (const item of prop.items) {
|
|
302
|
+
convertSNPToKeys(item, keys);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
if (prop.translatable) {
|
|
307
|
+
keys.push({ name: prop.name, keys: [] });
|
|
308
|
+
}
|
|
309
|
+
else if ('fields' in prop) {
|
|
310
|
+
if (prop.fields) {
|
|
311
|
+
const nestedKeys = [];
|
|
312
|
+
convertSNPToKeys(prop.fields, nestedKeys);
|
|
313
|
+
if (nestedKeys.length) {
|
|
314
|
+
keys.push({ name: prop.name, keys: nestedKeys });
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else if ('itemType' in prop && Array.isArray(prop.itemType)) {
|
|
319
|
+
const nestedKeys = [];
|
|
320
|
+
convertSNPToKeys(prop.itemType, nestedKeys);
|
|
321
|
+
if (nestedKeys.length) {
|
|
322
|
+
keys.push({ name: prop.name, keys: nestedKeys });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function convertGutenbergBlockToJSRepresentation(element) {
|
|
328
|
+
const type = element.getAttribute("type");
|
|
329
|
+
if (!type) {
|
|
330
|
+
throw `A gutenberg-block entry in a wpml-config.xml file is missing its type attribute.`;
|
|
331
|
+
}
|
|
332
|
+
const translate = element.getAttribute("translate");
|
|
333
|
+
if (!translate) {
|
|
334
|
+
throw `The gutenberg-block entry for ${type} is missing its translate attribute.`;
|
|
335
|
+
}
|
|
336
|
+
if (translate !== '0' && translate !== '1') {
|
|
337
|
+
throw `The gutenberg-block entry for ${type} has an invalid translate attribute. Expected 0 or 1, but got, "${translate}"`;
|
|
338
|
+
}
|
|
339
|
+
const keys = [];
|
|
340
|
+
const xPaths = [];
|
|
341
|
+
for (const child of element.children) {
|
|
342
|
+
if (child.nodeName === 'key') {
|
|
343
|
+
keys.push(convertGenericSettingsKeyToJSRepresentation(child, `a gutenberg-block entry for ${type}`));
|
|
344
|
+
}
|
|
345
|
+
else if (child.nodeName === 'xpath') {
|
|
346
|
+
xPaths.push(convertGenericSettingsXPathToJSRepresentation(child, `a gutenberg-block entry for ${type}`));
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
throw `The gutenberg-block entry for ${type} has an unsupported child node ("${child.nodeName}")`;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return { type, label: element.getAttribute("label"), translate, keys, xPaths };
|
|
353
|
+
}
|
|
354
|
+
function convertGenericSettingsKeyToJSRepresentation(element, containerName) {
|
|
355
|
+
const name = element.getAttribute("name");
|
|
356
|
+
if (!name) {
|
|
357
|
+
throw `Encountered a key without a name in ${containerName}.`;
|
|
358
|
+
}
|
|
359
|
+
let encoding = element.getAttribute("encoding");
|
|
360
|
+
if (encoding && encoding !== 'json') {
|
|
361
|
+
throw `Encountered an invalid encoding on a key named, "${name}" in ${containerName}. It must be either blank or JSON`;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
encoding = null;
|
|
365
|
+
}
|
|
366
|
+
let searchMethod = element.getAttribute("searchMethod");
|
|
367
|
+
if (searchMethod && searchMethod !== 'wildcards' && searchMethod !== 'regex') {
|
|
368
|
+
throw `Encountered an invalid search-method on a key named, "${name}" in ${containerName}. It must be either blank or JSON`;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
searchMethod = null;
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
name,
|
|
375
|
+
label: element.getAttribute("label"),
|
|
376
|
+
type: element.getAttribute("type"),
|
|
377
|
+
subType: element.getAttribute("sub-type"),
|
|
378
|
+
encoding,
|
|
379
|
+
searchMethod,
|
|
380
|
+
keys: [...element.children].map(child => convertGenericSettingsKeyToJSRepresentation(child, containerName))
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function convertGenericSettingsXPathToJSRepresentation(element, containerName) {
|
|
384
|
+
if (!element.textContent) {
|
|
385
|
+
throw `Encountered an empty XPath in ${containerName}.`;
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
path: element.textContent,
|
|
389
|
+
label: element.getAttribute("label"),
|
|
390
|
+
type: element.getAttribute("type"),
|
|
391
|
+
subType: element.getAttribute("sub-type")
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
function mergeWPMLGutenbergBlocks(existing, novel) {
|
|
395
|
+
if (novel.type && existing.type !== novel.type) {
|
|
396
|
+
throw `Cannot merge WPML Gutenberg Blocks of differing types`;
|
|
397
|
+
}
|
|
398
|
+
if (novel.translate && existing.translate !== novel.translate) {
|
|
399
|
+
throw `Cannot merge WPML Gutenberg Blocks (${existing.type} and ${novel.type ?? existing.type}) with differing translate values`;
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
type: existing.type,
|
|
403
|
+
translate: existing.translate,
|
|
404
|
+
label: novel.label ?? existing.label,
|
|
405
|
+
keys: novel.keys?.length ? (existing.keys.length ? mergeGenericSettingsKeyLists(existing.keys, novel.keys) : novel.keys) : existing.keys,
|
|
406
|
+
xPaths: novel.xPaths?.length ? (existing.xPaths.length ? [...existing.xPaths, ...novel.xPaths] : novel.xPaths) : existing.xPaths
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function mergeGenericSettingsKeyLists(existingKeys, novelKeys) {
|
|
410
|
+
const keys = {};
|
|
411
|
+
for (const key of existingKeys) {
|
|
412
|
+
const existing = keys[key.name];
|
|
413
|
+
keys[key.name] = existing ? mergeGenericSettingsKeys(existing, key) : key;
|
|
414
|
+
}
|
|
415
|
+
for (const key of novelKeys) {
|
|
416
|
+
const existing = keys[key.name];
|
|
417
|
+
keys[key.name] = existing ? mergeGenericSettingsKeys(existing, key) : key;
|
|
418
|
+
}
|
|
419
|
+
return Object.values(keys);
|
|
420
|
+
}
|
|
421
|
+
function mergeGenericSettingsKeys(existing, novel) {
|
|
422
|
+
if (existing.encoding && novel.encoding && existing.encoding !== novel.encoding) {
|
|
423
|
+
throw `Cannot merge WPMLGenericSettingsKeys with differing encoding values (${existing.encoding} and ${novel.encoding}) on ${novel.name}.`;
|
|
424
|
+
}
|
|
425
|
+
if (existing.searchMethod && novel.searchMethod && existing.searchMethod !== novel.searchMethod) {
|
|
426
|
+
throw `Cannot merge WPMLGenericSettingsKeys with differing search-method values (${existing.searchMethod} and ${novel.searchMethod}) on ${novel.name}.`;
|
|
427
|
+
}
|
|
428
|
+
return { ...existing, ...novel, keys: mergeGenericSettingsKeyLists(existing.keys, novel.keys) };
|
|
429
|
+
}
|
|
430
|
+
function newWebpackErrorForFile(error, file) {
|
|
431
|
+
const res = new webpack_1.WebpackError(error);
|
|
432
|
+
res.hideStack = true;
|
|
433
|
+
res.file = file;
|
|
434
|
+
return res;
|
|
435
|
+
}
|
|
436
|
+
function writeGenericSettingsKeys(keys, parent, document) {
|
|
437
|
+
parent.append(...keys.sort((a, b) => a.name.localeCompare(b.name)).map(key => {
|
|
438
|
+
const element = document.createElement("key");
|
|
439
|
+
element.setAttribute("name", key.name);
|
|
440
|
+
writeCommonGenericSettingsItemProps(element, key);
|
|
441
|
+
if (key.encoding) {
|
|
442
|
+
element.setAttribute("encoding", key.encoding);
|
|
443
|
+
}
|
|
444
|
+
if (key.searchMethod) {
|
|
445
|
+
element.setAttribute("search-method", key.searchMethod);
|
|
446
|
+
}
|
|
447
|
+
writeGenericSettingsKeys(key.keys, element, document);
|
|
448
|
+
return element;
|
|
449
|
+
}));
|
|
450
|
+
}
|
|
451
|
+
function appendNamedElementsListToConfig(containerName, elements, config) {
|
|
452
|
+
const allElements = Object.entries(elements);
|
|
453
|
+
if (allElements.length) {
|
|
454
|
+
const containerElement = config.createElement(containerName);
|
|
455
|
+
config.documentElement.append(containerElement);
|
|
456
|
+
containerElement.append(...allElements
|
|
457
|
+
.sort(([fieldNameA], [fieldNameB]) => fieldNameA.localeCompare(fieldNameB))
|
|
458
|
+
.map(([_, element]) => element));
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function writeCommonGenericSettingsItemProps(element, item) {
|
|
462
|
+
if (item.label) {
|
|
463
|
+
element.setAttribute("label", item.label);
|
|
464
|
+
}
|
|
465
|
+
if (item.type) {
|
|
466
|
+
element.setAttribute("type", item.type);
|
|
467
|
+
}
|
|
468
|
+
if (item.subType) {
|
|
469
|
+
element.setAttribute("sub-type", item.subType);
|
|
470
|
+
}
|
|
471
|
+
}
|
package/build/wordpress-scripts-wrapper/dependency-extraction-webpack-plugin-config-builder.d.ts
CHANGED
|
@@ -6,4 +6,7 @@ export type IndividualExternalDepConfig = string | {
|
|
|
6
6
|
export type Externals = {
|
|
7
7
|
[dep: string]: IndividualExternalDepConfig;
|
|
8
8
|
};
|
|
9
|
-
export declare function makeDependencyExtractionPlugin(externals: Externals | undefined, assumeGlobalizedPlauditLibraries: boolean):
|
|
9
|
+
export declare function makeDependencyExtractionPlugin(externals: Externals | undefined, assumeGlobalizedPlauditLibraries: boolean, wantsGroupedDepData: boolean): {
|
|
10
|
+
instance: DependencyExtractionWebpackPlugin;
|
|
11
|
+
addExternalizedDep: (dep: string) => void;
|
|
12
|
+
};
|
package/build/wordpress-scripts-wrapper/dependency-extraction-webpack-plugin-config-builder.js
CHANGED
|
@@ -5,15 +5,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeDependencyExtractionPlugin = makeDependencyExtractionPlugin;
|
|
7
7
|
const dependency_extraction_webpack_plugin_1 = __importDefault(require("@wordpress/dependency-extraction-webpack-plugin"));
|
|
8
|
-
function makeDependencyExtractionPlugin(externals, assumeGlobalizedPlauditLibraries) {
|
|
8
|
+
function makeDependencyExtractionPlugin(externals, assumeGlobalizedPlauditLibraries, wantsGroupedDepData) {
|
|
9
|
+
const baseProps = makeDependencyExtractionPluginProps(externals, assumeGlobalizedPlauditLibraries);
|
|
10
|
+
const instance = new dependency_extraction_webpack_plugin_1.default(wantsGroupedDepData ? { ...baseProps, outputFormat: "json", combineAssets: true } : baseProps);
|
|
11
|
+
return {
|
|
12
|
+
instance,
|
|
13
|
+
addExternalizedDep: (dep) => {
|
|
14
|
+
instance.externalizedDeps.add(dep);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function makeDependencyExtractionPluginProps(externals, assumeGlobalizedPlauditLibraries) {
|
|
9
19
|
if (!externals) {
|
|
10
20
|
if (assumeGlobalizedPlauditLibraries) {
|
|
11
|
-
return
|
|
21
|
+
return {
|
|
12
22
|
requestToExternal: plauditRequestToExternal,
|
|
13
23
|
requestToHandle: plauditRequestToHandle
|
|
14
|
-
}
|
|
24
|
+
};
|
|
15
25
|
}
|
|
16
|
-
return
|
|
26
|
+
return {};
|
|
17
27
|
}
|
|
18
28
|
const exactExternals = {};
|
|
19
29
|
const suffixExternals = [];
|
|
@@ -54,15 +64,18 @@ function makeDependencyExtractionPlugin(externals, assumeGlobalizedPlauditLibrar
|
|
|
54
64
|
}
|
|
55
65
|
return undefined;
|
|
56
66
|
};
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
if (assumeGlobalizedPlauditLibraries) {
|
|
68
|
+
return {
|
|
59
69
|
requestToExternal: curryRequestHandlers(baselineRequestToExternal, plauditRequestToExternal),
|
|
60
70
|
requestToHandle: curryRequestHandlers(baselineRequestToHandle, plauditRequestToHandle),
|
|
61
|
-
}
|
|
62
|
-
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return {
|
|
63
75
|
requestToExternal: baselineRequestToExternal,
|
|
64
76
|
requestToHandle: baselineRequestToHandle,
|
|
65
|
-
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
66
79
|
}
|
|
67
80
|
const PLAUDIT_NAMESPACE = '@plaudit/';
|
|
68
81
|
const EXTERNALIZABLE_PLAUDIT_LIBRARIES = ['@plaudit/library-extensions'];
|
|
@@ -19,6 +19,8 @@ type PlauditWordpressWebpackConfig = {
|
|
|
19
19
|
};
|
|
20
20
|
externals?: Externals;
|
|
21
21
|
assumeGlobalizedPlauditLibraries?: boolean;
|
|
22
|
+
processTranslationConfigs?: boolean;
|
|
23
|
+
combineAssetMetadata?: boolean;
|
|
22
24
|
};
|
|
23
25
|
declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration[] | Configuration) => Configuration[];
|
|
24
26
|
export = _default;
|