@plaudit/webpack-extensions 4.0.0-rc.1 → 4.0.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/CHANGELOG.md +5 -1
- package/dist/api/asset-information-emission.d.ts +74 -0
- package/dist/api/asset-information-emission.d.ts.map +1 -0
- package/dist/api/asset-information-emission.js +398 -0
- package/dist/api/asset-information-emission.js.map +1 -0
- package/dist/api/configuration.d.ts +102 -0
- package/dist/api/configuration.d.ts.map +1 -0
- package/dist/api/configuration.js +83 -0
- package/dist/api/configuration.js.map +1 -0
- package/dist/api/coordinatable-emitter.d.ts +27 -0
- package/dist/api/coordinatable-emitter.d.ts.map +1 -0
- package/dist/api/coordinatable-emitter.js +20 -0
- package/dist/api/coordinatable-emitter.js.map +1 -0
- package/dist/api/entries/dependencies.d.ts +69 -0
- package/dist/api/entries/dependencies.d.ts.map +1 -0
- package/dist/api/entries/dependencies.js +61 -0
- package/dist/api/entries/dependencies.js.map +1 -0
- package/dist/api/entries/flag-logic.d.ts +37 -0
- package/dist/api/entries/flag-logic.d.ts.map +1 -0
- package/dist/api/entries/flag-logic.js +110 -0
- package/dist/api/entries/flag-logic.js.map +1 -0
- package/dist/api/entries/identifiers.d.ts +84 -0
- package/dist/api/entries/identifiers.d.ts.map +1 -0
- package/dist/api/entries/identifiers.js +590 -0
- package/dist/api/entries/identifiers.js.map +1 -0
- package/dist/api/entries/index.d.ts +6 -0
- package/dist/api/entries/index.d.ts.map +1 -0
- package/dist/api/entries/index.js +22 -0
- package/dist/api/entries/index.js.map +1 -0
- package/dist/api/entries/locations.d.ts +135 -0
- package/dist/api/entries/locations.d.ts.map +1 -0
- package/dist/api/entries/locations.js +174 -0
- package/dist/api/entries/locations.js.map +1 -0
- package/dist/api/entries/manager.d.ts +12 -0
- package/dist/api/entries/manager.d.ts.map +1 -0
- package/dist/api/entries/manager.js +35 -0
- package/dist/api/entries/manager.js.map +1 -0
- package/dist/api/handle-derivation.d.ts +32 -0
- package/dist/api/handle-derivation.d.ts.map +1 -0
- package/dist/api/handle-derivation.js +77 -0
- package/dist/api/handle-derivation.js.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +23 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/shared-types.d.ts +86 -0
- package/dist/api/shared-types.d.ts.map +1 -0
- package/dist/api/shared-types.js +3 -0
- package/dist/api/shared-types.js.map +1 -0
- package/dist/internal-utils/auto-registering-plugins-loader.d.ts +3 -0
- package/dist/internal-utils/auto-registering-plugins-loader.d.ts.map +1 -0
- package/dist/internal-utils/auto-registering-plugins-loader.js +42 -0
- package/dist/internal-utils/auto-registering-plugins-loader.js.map +1 -0
- package/dist/internal-utils/common-config-helpers.d.ts +14 -0
- package/dist/internal-utils/common-config-helpers.d.ts.map +1 -0
- package/dist/internal-utils/common-config-helpers.js +140 -0
- package/dist/internal-utils/common-config-helpers.js.map +1 -0
- package/dist/internal-utils/entrypoint-resolution-logic.d.ts +14 -0
- package/dist/internal-utils/entrypoint-resolution-logic.d.ts.map +1 -0
- package/dist/internal-utils/entrypoint-resolution-logic.js +223 -0
- package/dist/internal-utils/entrypoint-resolution-logic.js.map +1 -0
- package/dist/internal-utils/internal-pseudo-plugin.d.ts +6 -0
- package/dist/internal-utils/internal-pseudo-plugin.d.ts.map +1 -0
- package/dist/internal-utils/internal-pseudo-plugin.js +46 -0
- package/dist/internal-utils/internal-pseudo-plugin.js.map +1 -0
- package/dist/mocks/blocks.d.ts +32 -0
- package/dist/mocks/blocks.d.ts.map +1 -0
- package/dist/mocks/blocks.js +3 -0
- package/dist/mocks/blocks.js.map +1 -0
- package/dist/mocks/index.d.ts +2 -0
- package/dist/mocks/index.d.ts.map +1 -0
- package/dist/mocks/index.js +18 -0
- package/dist/mocks/index.js.map +1 -0
- package/dist/plugins/AdditionalDependencyInjectorPlugin.d.ts +5 -0
- package/dist/plugins/AdditionalDependencyInjectorPlugin.d.ts.map +1 -0
- package/dist/plugins/AdditionalDependencyInjectorPlugin.js +59 -0
- package/dist/plugins/AdditionalDependencyInjectorPlugin.js.map +1 -0
- package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts +5 -0
- package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts.map +1 -0
- package/dist/plugins/MiniCSSExtractPluginErrorCleaner.js +16 -0
- package/dist/plugins/MiniCSSExtractPluginErrorCleaner.js.map +1 -0
- package/dist/plugins/PackageConfigSanityChecker.d.ts +5 -0
- package/dist/plugins/PackageConfigSanityChecker.d.ts.map +1 -0
- package/dist/plugins/PackageConfigSanityChecker.js +31 -0
- package/dist/plugins/PackageConfigSanityChecker.js.map +1 -0
- package/dist/plugins/RootCoordinatorPluginImpl.d.ts +56 -0
- package/dist/plugins/RootCoordinatorPluginImpl.d.ts.map +1 -0
- package/dist/plugins/RootCoordinatorPluginImpl.js +767 -0
- package/dist/plugins/RootCoordinatorPluginImpl.js.map +1 -0
- package/dist/plugins/VariablesJSMonitorPlugin.d.ts +8 -0
- package/dist/plugins/VariablesJSMonitorPlugin.d.ts.map +1 -0
- package/dist/plugins/VariablesJSMonitorPlugin.js +21 -0
- package/dist/plugins/VariablesJSMonitorPlugin.js.map +1 -0
- package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.d.ts +25 -0
- package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.d.ts.map +1 -0
- package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.js +458 -0
- package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.js.map +1 -0
- package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.d.ts +29 -0
- package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.d.ts.map +1 -0
- package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.js +290 -0
- package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.js.map +1 -0
- package/dist/plugins/blocks/register.d.ts +6 -0
- package/dist/plugins/blocks/register.d.ts.map +1 -0
- package/dist/plugins/blocks/register.js +14 -0
- package/dist/plugins/blocks/register.js.map +1 -0
- package/dist/plugins/blocks/registerEmitter.d.ts +4 -0
- package/dist/plugins/blocks/registerEmitter.d.ts.map +1 -0
- package/dist/plugins/blocks/registerEmitter.js +13 -0
- package/dist/plugins/blocks/registerEmitter.js.map +1 -0
- package/dist/plugins/blocks/registerProcessor.d.ts +4 -0
- package/dist/plugins/blocks/registerProcessor.d.ts.map +1 -0
- package/dist/plugins/blocks/registerProcessor.js +46 -0
- package/dist/plugins/blocks/registerProcessor.js.map +1 -0
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +5 -0
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts.map +1 -0
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js +148 -0
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js.map +1 -0
- package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.d.ts +14 -0
- package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.d.ts.map +1 -0
- package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.js +191 -0
- package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.js.map +1 -0
- package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.d.ts +14 -0
- package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.d.ts.map +1 -0
- package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.js +102 -0
- package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.js.map +1 -0
- package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.d.ts +25 -0
- package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.d.ts.map +1 -0
- package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.js +229 -0
- package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.js.map +1 -0
- package/dist/plugins/extensions/register.d.ts +6 -0
- package/dist/plugins/extensions/register.d.ts.map +1 -0
- package/dist/plugins/extensions/register.js +14 -0
- package/dist/plugins/extensions/register.js.map +1 -0
- package/dist/plugins/extensions/registerEmitter.d.ts +4 -0
- package/dist/plugins/extensions/registerEmitter.d.ts.map +1 -0
- package/dist/plugins/extensions/registerEmitter.js +18 -0
- package/dist/plugins/extensions/registerEmitter.js.map +1 -0
- package/dist/plugins/extensions/registerProcessor.d.ts +4 -0
- package/dist/plugins/extensions/registerProcessor.d.ts.map +1 -0
- package/dist/plugins/extensions/registerProcessor.js +42 -0
- package/dist/plugins/extensions/registerProcessor.js.map +1 -0
- package/dist/plugins/plain/PlainEntrypointProcessingPlugin.d.ts +18 -0
- package/dist/plugins/plain/PlainEntrypointProcessingPlugin.d.ts.map +1 -0
- package/dist/plugins/plain/PlainEntrypointProcessingPlugin.js +203 -0
- package/dist/plugins/plain/PlainEntrypointProcessingPlugin.js.map +1 -0
- package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.d.ts +13 -0
- package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.d.ts.map +1 -0
- package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.js +51 -0
- package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.js.map +1 -0
- package/dist/plugins/plain/register.d.ts +6 -0
- package/dist/plugins/plain/register.d.ts.map +1 -0
- package/dist/plugins/plain/register.js +14 -0
- package/dist/plugins/plain/register.js.map +1 -0
- package/dist/plugins/plain/registerEmitter.d.ts +4 -0
- package/dist/plugins/plain/registerEmitter.d.ts.map +1 -0
- package/dist/plugins/plain/registerEmitter.js +21 -0
- package/dist/plugins/plain/registerEmitter.js.map +1 -0
- package/dist/plugins/plain/registerProcessor.d.ts +4 -0
- package/dist/plugins/plain/registerProcessor.d.ts.map +1 -0
- package/dist/plugins/plain/registerProcessor.js +34 -0
- package/dist/plugins/plain/registerProcessor.js.map +1 -0
- package/dist/plugins/register.d.ts +3 -0
- package/dist/plugins/register.d.ts.map +1 -0
- package/dist/plugins/register.js +17 -0
- package/dist/plugins/register.js.map +1 -0
- package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.d.ts +20 -0
- package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.d.ts.map +1 -0
- package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.js +56 -0
- package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.js.map +1 -0
- package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.d.ts +13 -0
- package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.d.ts.map +1 -0
- package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.js +105 -0
- package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.js.map +1 -0
- package/dist/plugins/special-assets/register.d.ts +6 -0
- package/dist/plugins/special-assets/register.d.ts.map +1 -0
- package/dist/plugins/special-assets/register.js +14 -0
- package/dist/plugins/special-assets/register.js.map +1 -0
- package/dist/plugins/special-assets/registerEmitter.d.ts +4 -0
- package/dist/plugins/special-assets/registerEmitter.d.ts.map +1 -0
- package/dist/plugins/special-assets/registerEmitter.js +15 -0
- package/dist/plugins/special-assets/registerEmitter.js.map +1 -0
- package/dist/plugins/special-assets/registerProcessor.d.ts +4 -0
- package/dist/plugins/special-assets/registerProcessor.d.ts.map +1 -0
- package/dist/plugins/special-assets/registerProcessor.js +15 -0
- package/dist/plugins/special-assets/registerProcessor.js.map +1 -0
- package/dist/plugins/unified-loader/UnifiedLoaderGenerator.d.ts +22 -0
- package/dist/plugins/unified-loader/UnifiedLoaderGenerator.d.ts.map +1 -0
- package/dist/plugins/unified-loader/UnifiedLoaderGenerator.js +95 -0
- package/dist/plugins/unified-loader/UnifiedLoaderGenerator.js.map +1 -0
- package/dist/plugins/wpml-config/WPMLConfigBuilder.d.ts +24 -0
- package/dist/plugins/wpml-config/WPMLConfigBuilder.d.ts.map +1 -0
- package/dist/plugins/wpml-config/WPMLConfigBuilder.js +542 -0
- package/dist/plugins/wpml-config/WPMLConfigBuilder.js.map +1 -0
- package/dist/plugins/wpml-config/register.d.ts +6 -0
- package/dist/plugins/wpml-config/register.d.ts.map +1 -0
- package/dist/plugins/wpml-config/register.js +25 -0
- package/dist/plugins/wpml-config/register.js.map +1 -0
- package/dist/shared.d.ts +38 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +163 -0
- package/dist/shared.js.map +1 -0
- package/dist/utils/error-helpers.d.ts +7 -0
- package/dist/utils/error-helpers.d.ts.map +1 -0
- package/dist/utils/error-helpers.js +73 -0
- package/dist/utils/error-helpers.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/misc.d.ts +4 -0
- package/dist/utils/misc.d.ts.map +1 -0
- package/dist/utils/misc.js +18 -0
- package/dist/utils/misc.js.map +1 -0
- package/dist/utils/path-helpers.d.ts +16 -0
- package/dist/utils/path-helpers.d.ts.map +1 -0
- package/dist/utils/path-helpers.js +115 -0
- package/dist/utils/path-helpers.js.map +1 -0
- package/dist/utils/pseudo-semaphore.d.ts +15 -0
- package/dist/utils/pseudo-semaphore.d.ts.map +1 -0
- package/dist/utils/pseudo-semaphore.js +77 -0
- package/dist/utils/pseudo-semaphore.js.map +1 -0
- package/dist/utils/type-helpers.d.ts +27 -0
- package/dist/utils/type-helpers.d.ts.map +1 -0
- package/dist/utils/type-helpers.js +33 -0
- package/dist/utils/type-helpers.js.map +1 -0
- package/dist/utils/writer-utils.d.ts +8 -0
- package/dist/utils/writer-utils.d.ts.map +1 -0
- package/dist/utils/writer-utils.js +35 -0
- package/dist/utils/writer-utils.js.map +1 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts +73 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts.map +1 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js +516 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js.map +1 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts +57 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts.map +1 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js +156 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js.map +1 -0
- package/dist/wordpress-scripts-wrapper.d.ts +5 -0
- package/dist/wordpress-scripts-wrapper.d.ts.map +1 -0
- package/dist/wordpress-scripts-wrapper.js +444 -0
- package/dist/wordpress-scripts-wrapper.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnifiedLoaderGenerator = void 0;
|
|
4
|
+
const promises_1 = require("node:fs/promises");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const php_writer_1 = require("@plaudit/php-writer");
|
|
7
|
+
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
8
|
+
const webpack_1 = require("webpack");
|
|
9
|
+
const api_1 = require("../../api");
|
|
10
|
+
const utils_1 = require("../../utils");
|
|
11
|
+
class UnifiedLoaderGenerator extends api_1.CoordinatableEmitter {
|
|
12
|
+
coordinator;
|
|
13
|
+
config;
|
|
14
|
+
constructor(coordinator, config) {
|
|
15
|
+
super();
|
|
16
|
+
this.coordinator = coordinator;
|
|
17
|
+
this.config = config;
|
|
18
|
+
}
|
|
19
|
+
provides = [];
|
|
20
|
+
requires = ["unified-loader"];
|
|
21
|
+
get defaultCompilationName() {
|
|
22
|
+
return "unified-loader";
|
|
23
|
+
}
|
|
24
|
+
apply(compiler) {
|
|
25
|
+
super.apply(compiler);
|
|
26
|
+
compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
|
|
27
|
+
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, async () => {
|
|
28
|
+
const collectedLoaders = {};
|
|
29
|
+
for (const loader of this.coordinator.getData("unified-loader")) {
|
|
30
|
+
collectedLoaders[loader.group] = { ...loader, ...collectedLoaders[loader.group], requiresBaseURI: loader.requiresBaseURI || (collectedLoaders[loader.group]?.requiresBaseURI ?? false) };
|
|
31
|
+
}
|
|
32
|
+
const loaders = Object.values(collectedLoaders).sort((a, b) => a.group.localeCompare(b.group));
|
|
33
|
+
if (this.config.useUnifiedLoader) {
|
|
34
|
+
let phpFile;
|
|
35
|
+
if (compilation.outputOptions.path?.endsWith("-dev")) {
|
|
36
|
+
compilation['.gitignore' in compilation.assets ? 'updateAsset' : 'emitAsset']('.gitignore', new webpack_1.sources.RawSource('**'), { size: 2 });
|
|
37
|
+
await this.ensureDistExists(compilation.outputOptions.path);
|
|
38
|
+
phpFile = new php_writer_1.PHPFile();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
phpFile = this.withDistDevLoader();
|
|
42
|
+
}
|
|
43
|
+
if (loaders.some(wc => wc.requiresBaseURI)) {
|
|
44
|
+
(0, utils_1.emitResolveBaseUriFunction)(phpFile);
|
|
45
|
+
}
|
|
46
|
+
for (const { action } of loaders) {
|
|
47
|
+
action(phpFile);
|
|
48
|
+
}
|
|
49
|
+
(0, utils_1.emitPHPWriterAsAsset)(phpFile, compilation, "unified-loader.php");
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
static emissionTarget(config) {
|
|
55
|
+
return ["unified-loader", (baseConfig, coordinator) => {
|
|
56
|
+
return {
|
|
57
|
+
...baseConfig,
|
|
58
|
+
plugins: [new UnifiedLoaderGenerator(coordinator, config)]
|
|
59
|
+
};
|
|
60
|
+
}];
|
|
61
|
+
}
|
|
62
|
+
withDistDevLoader() {
|
|
63
|
+
if (this.config.omitDistDev) {
|
|
64
|
+
return new php_writer_1.PHPFile();
|
|
65
|
+
}
|
|
66
|
+
const devLoaderPath = expressions_1.Op.concat(expressions_1.Constants.__DIR__, '-dev/unified-loader.php');
|
|
67
|
+
const res = new php_writer_1.PHPFile();
|
|
68
|
+
res.getWriter("")
|
|
69
|
+
.if(expressions_1.Op.binary(expressions_1.Op.binary(expressions_1.Expr.call('wp_get_environment_type', []), ' === ', 'development'), ' && ', expressions_1.Expr.call('file_exists', [devLoaderPath])))
|
|
70
|
+
.require(devLoaderPath, { once: true })
|
|
71
|
+
.append("return;")
|
|
72
|
+
.endIf();
|
|
73
|
+
return res;
|
|
74
|
+
}
|
|
75
|
+
async ensureDistExists(outputPath) {
|
|
76
|
+
if (outputPath.endsWith("-dev")) {
|
|
77
|
+
outputPath = outputPath.substring(0, outputPath.length - 4);
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const contents = await (0, promises_1.readFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), 'utf-8');
|
|
81
|
+
if (!contents.includes("-dev/unified-loader.php")) {
|
|
82
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), this.withDistDevLoader().toString() + contents.substring(5), 'utf-8');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
await (0, promises_1.mkdir)(outputPath, { recursive: true });
|
|
87
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), this.withDistDevLoader().toString(), 'utf-8');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
getCoordinatedEmissionTargets() {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.UnifiedLoaderGenerator = UnifiedLoaderGenerator;
|
|
95
|
+
//# sourceMappingURL=UnifiedLoaderGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnifiedLoaderGenerator.js","sourceRoot":"","sources":["../../../src/plugins/unified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E,OAAO,CAAC,CAAC;YACjF,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAAC;gBACnD,MAAM,IAAA,oBAAS,EAAC,IAAA,gBAAI,EAAC,UAAU,EAAE,oBAAoB,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAC/H,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,MAAM,IAAA,gBAAK,EAAC,UAAU,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;YAC3C,MAAM,IAAA,oBAAS,EAAC,IAAA,gBAAI,EAAC,UAAU,EAAE,oBAAoB,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC;QACvG,CAAC;IACF,CAAC;IAED,6BAA6B;QAC5B,OAAO,EAAE,CAAC;IACX,CAAC;CACD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Compiler } from "webpack";
|
|
2
|
+
import { CoordinatableEmitter, type CoordinatedEmissionTargetBuilder, type RootCoordinatorPlugin, type VerifiedAdvancedDestinationConfig, type VerifiedPlauditWordpressWebpackConfig } from "../../api";
|
|
3
|
+
export declare class WPMLConfigEmitterPlugin extends CoordinatableEmitter {
|
|
4
|
+
protected readonly coordinator: RootCoordinatorPlugin;
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly dest;
|
|
7
|
+
private readonly srcRoot;
|
|
8
|
+
private static jsdomInstance?;
|
|
9
|
+
private static domParser?;
|
|
10
|
+
private static xmlSerializer?;
|
|
11
|
+
private readonly parsedDocumentsCache;
|
|
12
|
+
constructor(coordinator: RootCoordinatorPlugin, config: VerifiedPlauditWordpressWebpackConfig, dest: VerifiedAdvancedDestinationConfig, srcRoot: string);
|
|
13
|
+
readonly provides: readonly ["unified-loader"];
|
|
14
|
+
get requires(): readonly [`blocks-directory:${string}`];
|
|
15
|
+
get defaultCompilationName(): string;
|
|
16
|
+
apply(compiler: Compiler): void;
|
|
17
|
+
getCoordinatedEmissionTargets(): CoordinatedEmissionTargetBuilder[];
|
|
18
|
+
private static getJSDOMInstance;
|
|
19
|
+
private static getDOMParser;
|
|
20
|
+
private static getXMLSerializer;
|
|
21
|
+
private static prettyPrintXML;
|
|
22
|
+
private loadWPMLConfigXML;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=WPMLConfigBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WPMLConfigBuilder.d.ts","sourceRoot":"","sources":["../../../src/plugins/wpml-config/WPMLConfigBuilder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAc,KAAK,QAAQ,EAA6B,MAAM,SAAS,CAAC;AAG/E,OAAO,EACN,oBAAoB,EAAE,KAAK,gCAAgC,EAAE,KAAK,qBAAqB,EAAE,KAAK,iCAAiC,EAC/H,KAAK,qCAAqC,EAC1C,MAAM,WAAW,CAAC;AAyBnB,qBAAa,uBAAwB,SAAQ,oBAAoB;IAQ/D,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,qBAAqB;IACrD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAVzB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAQ;IACrC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAY;IACrC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAgB;IAE7C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA0C;IAE/E,YACoB,WAAW,EAAE,qBAAqB,EACpC,MAAM,EAAE,qCAAqC,EAC7C,IAAI,EAAE,iCAAiC,EACvC,OAAO,EAAE,MAAM,EAGhC;IAED,SAAgB,QAAQ,YAAI,gBAAgB,EAAW;IAEvD,IAAW,QAAQ,4CAElB;IAED,IAAW,sBAAsB,WAEhC;IAED,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAwJ9B;IAED,6BAA6B,IAAI,gCAAgC,EAAE,CAElE;IAED,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAG/B,OAAO,CAAC,MAAM,CAAC,YAAY;IAG3B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAI/B,OAAO,CAAC,MAAM,CAAC,cAAc;YAcf,iBAAiB;CAyE/B"}
|
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.WPMLConfigEmitterPlugin = void 0;
|
|
40
|
+
const promises_1 = __importStar(require("node:fs/promises"));
|
|
41
|
+
const node_path_1 = __importStar(require("node:path"));
|
|
42
|
+
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
43
|
+
const jsdom_1 = require("jsdom");
|
|
44
|
+
const webpack_1 = require("webpack");
|
|
45
|
+
const xml_formatter_1 = __importDefault(require("xml-formatter"));
|
|
46
|
+
const api_1 = require("../../api");
|
|
47
|
+
const utils_1 = require("../../utils");
|
|
48
|
+
const UnifiedLoaderGenerator_1 = require("../unified-loader/UnifiedLoaderGenerator");
|
|
49
|
+
class WPMLConfigEmitterPlugin extends api_1.CoordinatableEmitter {
|
|
50
|
+
coordinator;
|
|
51
|
+
config;
|
|
52
|
+
dest;
|
|
53
|
+
srcRoot;
|
|
54
|
+
static jsdomInstance;
|
|
55
|
+
static domParser;
|
|
56
|
+
static xmlSerializer;
|
|
57
|
+
parsedDocumentsCache = new Map();
|
|
58
|
+
constructor(coordinator, config, dest, srcRoot) {
|
|
59
|
+
super();
|
|
60
|
+
this.coordinator = coordinator;
|
|
61
|
+
this.config = config;
|
|
62
|
+
this.dest = dest;
|
|
63
|
+
this.srcRoot = srcRoot;
|
|
64
|
+
}
|
|
65
|
+
provides = ["unified-loader"];
|
|
66
|
+
get requires() {
|
|
67
|
+
return [`blocks-directory:${this.dest.destination}`];
|
|
68
|
+
}
|
|
69
|
+
get defaultCompilationName() {
|
|
70
|
+
return `wpml-config:${this.dest.destination}`;
|
|
71
|
+
}
|
|
72
|
+
apply(compiler) {
|
|
73
|
+
super.apply(compiler);
|
|
74
|
+
compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
|
|
75
|
+
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, async () => {
|
|
76
|
+
const rootWpmlConfigXmlSrc = (0, node_path_1.join)(this.srcRoot, "wpml-config.xml");
|
|
77
|
+
const blockJsonData = this.coordinator
|
|
78
|
+
.getData(`blocks-directory:${this.dest.destination}`)
|
|
79
|
+
.flatMap(Object.values);
|
|
80
|
+
let wpmlConfigs;
|
|
81
|
+
if ((await (0, promises_1.stat)(rootWpmlConfigXmlSrc, { throwIfNoEntry: false }))?.isFile()) {
|
|
82
|
+
wpmlConfigs = [rootWpmlConfigXmlSrc, ...blockJsonData.map(v => v.wpmlConfigSrcPath).filter((v) => !!v)];
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
wpmlConfigs = blockJsonData.map(v => v.wpmlConfigSrcPath).filter((v) => !!v);
|
|
86
|
+
}
|
|
87
|
+
compilation.contextDependencies.addAll(wpmlConfigs);
|
|
88
|
+
const blockJsons = blockJsonData.map(v => v.blockJson);
|
|
89
|
+
if (!wpmlConfigs.length && !blockJsons.length) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const mergedConfig = {
|
|
93
|
+
customFields: {}, customTermFields: {}, customTypes: {}, gutenbergBlocks: {}, shortcodeList: new Set(), shortcodes: {}, taxonomies: {}
|
|
94
|
+
};
|
|
95
|
+
const nonMergeableCategories = ['customFields', 'customTermFields', 'customTypes', 'shortcodes', 'taxonomies'];
|
|
96
|
+
for (const [wpmlConfig, file] of await Promise.all(wpmlConfigs.map(request => this.loadWPMLConfigXML(request, compilation)))) {
|
|
97
|
+
for (const category of nonMergeableCategories) {
|
|
98
|
+
for (const [key, value] of Object.entries(wpmlConfig[category])) {
|
|
99
|
+
if (key in mergedConfig[category]) {
|
|
100
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`Already encountered a definition for the ${category} entry named, "${key}"`, file));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
mergedConfig[category][key] = value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const shortcode of wpmlConfig.shortcodeList) {
|
|
108
|
+
mergedConfig.shortcodeList.add(shortcode);
|
|
109
|
+
}
|
|
110
|
+
for (const [type, block] of Object.entries(wpmlConfig.gutenbergBlocks)) {
|
|
111
|
+
const existing = mergedConfig.gutenbergBlocks[type];
|
|
112
|
+
try {
|
|
113
|
+
mergedConfig.gutenbergBlocks[type] = existing ? mergeWPMLGutenbergBlocks(existing, block) : block;
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
if (typeof e === 'string') {
|
|
117
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(e, file));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
compilation.errors.push(e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (const blockJson of blockJsons) {
|
|
126
|
+
const type = blockJson["name"]?.toString();
|
|
127
|
+
if (typeof type !== 'string') {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const blockConfig = {
|
|
131
|
+
type,
|
|
132
|
+
translate: blockJson['supports']?.['translation'] ?? true ? '1' : '0',
|
|
133
|
+
keys: [],
|
|
134
|
+
xPaths: []
|
|
135
|
+
};
|
|
136
|
+
if (typeof blockJson.plaudit === 'object' && !('group' in blockJson.plaudit) && blockJson.plaudit?.properties) {
|
|
137
|
+
const snps = blockJson.plaudit.properties;
|
|
138
|
+
if (Array.isArray(snps)) {
|
|
139
|
+
for (const snp of snps) {
|
|
140
|
+
convertSNPToKeys(snp, blockConfig.keys);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
convertSNPToKeys(snps, blockConfig.keys);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (typeof blockJson['attributes'] === 'object') {
|
|
148
|
+
for (const [name, { translatable }] of Object.entries(blockJson['attributes'])) {
|
|
149
|
+
if (translatable) {
|
|
150
|
+
blockConfig.keys.push({ name, keys: [] });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const existing = mergedConfig.gutenbergBlocks[blockConfig.type];
|
|
155
|
+
if (blockConfig.keys.length || blockConfig.xPaths.length) {
|
|
156
|
+
mergedConfig.gutenbergBlocks[blockConfig.type] = existing ? mergeWPMLGutenbergBlocks(existing, blockConfig) : blockConfig;
|
|
157
|
+
}
|
|
158
|
+
else if (!existing) {
|
|
159
|
+
mergedConfig.gutenbergBlocks[blockConfig.type] = blockConfig;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const config = WPMLConfigEmitterPlugin.getDOMParser().parseFromString("<wpml-config></wpml-config>", "application/xml");
|
|
163
|
+
appendNamedElementsListToConfig("custom-fields", mergedConfig.customFields, config);
|
|
164
|
+
appendNamedElementsListToConfig("custom-term-fields", mergedConfig.customTermFields, config);
|
|
165
|
+
appendNamedElementsListToConfig("custom-types", mergedConfig.customTypes, config);
|
|
166
|
+
const gutenbergBlocks = Object.values(mergedConfig.gutenbergBlocks);
|
|
167
|
+
if (gutenbergBlocks.length) {
|
|
168
|
+
const gutenbergBlocksElement = config.createElement("gutenberg-blocks");
|
|
169
|
+
gutenbergBlocksElement.append(...gutenbergBlocks
|
|
170
|
+
.sort((a, b) => a.type.localeCompare(b.type))
|
|
171
|
+
.map(gutenbergBlock => {
|
|
172
|
+
const gutenbergBlockElement = config.createElement("gutenberg-block");
|
|
173
|
+
gutenbergBlockElement.setAttribute("type", gutenbergBlock.type);
|
|
174
|
+
if (gutenbergBlock.label) {
|
|
175
|
+
gutenbergBlockElement.setAttribute("label", gutenbergBlock.label);
|
|
176
|
+
}
|
|
177
|
+
gutenbergBlockElement.setAttribute("translate", gutenbergBlock.translate);
|
|
178
|
+
writeGenericSettingsKeys(gutenbergBlock.keys, gutenbergBlockElement, config);
|
|
179
|
+
gutenbergBlockElement.append(...gutenbergBlock.xPaths
|
|
180
|
+
.sort((a, b) => a.path.localeCompare(b.path))
|
|
181
|
+
.map(xPath => {
|
|
182
|
+
const xPathElement = config.createElement("xpath");
|
|
183
|
+
writeCommonGenericSettingsItemProps(xPathElement, xPath);
|
|
184
|
+
xPathElement.append(xPath.path);
|
|
185
|
+
return xPathElement;
|
|
186
|
+
}));
|
|
187
|
+
return gutenbergBlockElement;
|
|
188
|
+
}));
|
|
189
|
+
config.documentElement.append(gutenbergBlocksElement);
|
|
190
|
+
}
|
|
191
|
+
if (mergedConfig.shortcodeList.size) {
|
|
192
|
+
const node = config.createElement("shortcode-list");
|
|
193
|
+
node.append([...mergedConfig.shortcodeList].sort().join(","));
|
|
194
|
+
config.documentElement.appendChild(node);
|
|
195
|
+
}
|
|
196
|
+
appendNamedElementsListToConfig("shortcodes", mergedConfig.shortcodes, config);
|
|
197
|
+
appendNamedElementsListToConfig("taxonomies", mergedConfig.taxonomies, config);
|
|
198
|
+
//TODO: CONSIDER: Add lazy-loader support
|
|
199
|
+
const wpmlEmitPath = node_path_1.default.join(this.dest.destination, "wpml-config.xml");
|
|
200
|
+
compilation[wpmlEmitPath in compilation.assets ? 'updateAsset' : 'emitAsset'](wpmlEmitPath, new webpack_1.sources.RawSource(WPMLConfigEmitterPlugin.prettyPrintXML(config)));
|
|
201
|
+
//TODO: This needs to still work in non-unified-loader mode
|
|
202
|
+
this.coordinator.reportData(compilation, this, "unified-loader", {
|
|
203
|
+
group: "wpml-config",
|
|
204
|
+
requiresBaseURI: true,
|
|
205
|
+
action: file => {
|
|
206
|
+
const wpml_config_class = expressions_1.Expr.namespacedRef("\\WPML_Config");
|
|
207
|
+
const writer = file.getWriter("");
|
|
208
|
+
if (writer.getLineCount() > 0) {
|
|
209
|
+
writer.linebreak();
|
|
210
|
+
}
|
|
211
|
+
writer
|
|
212
|
+
.if(wpml_config_class.isAvailable())
|
|
213
|
+
.assign(wpml_config_class.access(new expressions_1.Var('wpml_config_files', 'array')), expressions_1.Op.concat(expressions_1.Constants.__DIR__, '/' + wpmlEmitPath.split(node_path_1.default.sep).join('/')), { push: true })
|
|
214
|
+
.endIf();
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
getCoordinatedEmissionTargets() {
|
|
221
|
+
return [UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.emissionTarget(this.config)];
|
|
222
|
+
}
|
|
223
|
+
static getJSDOMInstance() {
|
|
224
|
+
return WPMLConfigEmitterPlugin.jsdomInstance ?? (WPMLConfigEmitterPlugin.jsdomInstance = new jsdom_1.JSDOM("", { contentType: "text/html" }));
|
|
225
|
+
}
|
|
226
|
+
static getDOMParser() {
|
|
227
|
+
return WPMLConfigEmitterPlugin.domParser ?? (WPMLConfigEmitterPlugin.domParser = new (WPMLConfigEmitterPlugin.getJSDOMInstance().window.DOMParser)());
|
|
228
|
+
}
|
|
229
|
+
static getXMLSerializer() {
|
|
230
|
+
return WPMLConfigEmitterPlugin.xmlSerializer ?? (WPMLConfigEmitterPlugin.xmlSerializer = new (WPMLConfigEmitterPlugin.getJSDOMInstance().window.XMLSerializer)());
|
|
231
|
+
}
|
|
232
|
+
static prettyPrintXML(document) {
|
|
233
|
+
return (0, xml_formatter_1.default)(WPMLConfigEmitterPlugin.getXMLSerializer().serializeToString(document), {
|
|
234
|
+
indentation: '\t',
|
|
235
|
+
collapseContent: true,
|
|
236
|
+
lineSeparator: '\n',
|
|
237
|
+
whiteSpaceAtEndOfSelfclosingTag: true,
|
|
238
|
+
forceSelfClosingEmptyTag: true,
|
|
239
|
+
strictMode: true,
|
|
240
|
+
filter(node) {
|
|
241
|
+
return node.type === 'Element' || node.type === 'Text';
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
async loadWPMLConfigXML(file, compilation) {
|
|
246
|
+
const contents = await promises_1.default.readFile(file, 'utf8');
|
|
247
|
+
const existing = this.parsedDocumentsCache.get(file);
|
|
248
|
+
if (existing?.raw === contents) {
|
|
249
|
+
return [existing, file];
|
|
250
|
+
}
|
|
251
|
+
const wpmlConfig = WPMLConfigEmitterPlugin.getDOMParser().parseFromString(contents.replaceAll(/\s+xmlns=['"][^'"]+['"]/sig, ""), "application/xml");
|
|
252
|
+
const res = { raw: contents, customFields: {}, customTermFields: {}, customTypes: {}, gutenbergBlocks: {}, shortcodeList: new Set(), shortcodes: {}, taxonomies: {} };
|
|
253
|
+
for (const element of wpmlConfig.documentElement.children) {
|
|
254
|
+
switch (element.nodeName) {
|
|
255
|
+
case "custom-fields":
|
|
256
|
+
importStandardTranslateActionMap(element, file, "custom-field", res.customFields, compilation);
|
|
257
|
+
break;
|
|
258
|
+
case "custom-term-fields":
|
|
259
|
+
importStandardTranslateActionMap(element, file, "custom-term-field", res.customTermFields, compilation);
|
|
260
|
+
break;
|
|
261
|
+
case "custom-types":
|
|
262
|
+
importStandardTranslateOptionMap(element, file, "custom-type", res.customTypes, compilation);
|
|
263
|
+
break;
|
|
264
|
+
case "gutenberg-blocks":
|
|
265
|
+
for (const child of element.children) {
|
|
266
|
+
try {
|
|
267
|
+
const block = convertGutenbergBlockToJSRepresentation(child);
|
|
268
|
+
const existing = res.gutenbergBlocks[block.type];
|
|
269
|
+
if (existing) {
|
|
270
|
+
res.gutenbergBlocks[block.type] = mergeWPMLGutenbergBlocks(existing, block);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
res.gutenbergBlocks[block.type] = block;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
catch (e) {
|
|
277
|
+
if (typeof e === 'string') {
|
|
278
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(e, file));
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
compilation.errors.push(e);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
break;
|
|
286
|
+
case "shortcode-list":
|
|
287
|
+
if (element.textContent) {
|
|
288
|
+
for (const shortcode of element.textContent.split(",")) {
|
|
289
|
+
res.shortcodeList.add(shortcode.trim());
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
break;
|
|
293
|
+
case "shortcodes":
|
|
294
|
+
for (const child of element.children) {
|
|
295
|
+
const tag = child.getElementsByTagName("tag")[0];
|
|
296
|
+
const shortcodeName = tag?.textContent?.trim();
|
|
297
|
+
if (!shortcodeName) {
|
|
298
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`A shortcode entry in a wpml-config.xml file is missing its tag name.`, file));
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const existing = res.shortcodes[shortcodeName];
|
|
302
|
+
if (existing) {
|
|
303
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`Already encountered a definition for the shortcode entry named, "${shortcodeName}"`, file));
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
res.shortcodes[shortcodeName] = child;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
case "taxonomies":
|
|
311
|
+
importStandardTranslateOptionMap(element, file, "taxonomy", res.taxonomies, compilation);
|
|
312
|
+
break;
|
|
313
|
+
default:
|
|
314
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`Unsupported element type in a wpml-config.xml file: ${element.nodeName}`, file));
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
this.parsedDocumentsCache.set(file, res);
|
|
319
|
+
return [res, file];
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
exports.WPMLConfigEmitterPlugin = WPMLConfigEmitterPlugin;
|
|
323
|
+
function importStandardTranslateOptionMap(element, file, type, actionMap, compilation) {
|
|
324
|
+
for (const child of element.children) {
|
|
325
|
+
const field = child.textContent;
|
|
326
|
+
if (!field) {
|
|
327
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`Encountered an empty ${type} entry in a wpml-config.xml file.`, file));
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const translate = child.getAttribute("translate");
|
|
331
|
+
if (!translate) {
|
|
332
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`The ${type} entry for ${field} is missing the translate attribute.`, file));
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const existing = actionMap[field];
|
|
336
|
+
if (existing) {
|
|
337
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`Already encountered a definition for the ${type} entry named, "${field}"`, file));
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
actionMap[field] = child;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function importStandardTranslateActionMap(element, file, type, actionMap, compilation) {
|
|
345
|
+
for (const child of element.children) {
|
|
346
|
+
const field = child.textContent?.trim();
|
|
347
|
+
if (!field) {
|
|
348
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`Encountered a empty ${type} entry without a name in a wpml-config.xml file.`, file));
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const action = child.getAttribute("action");
|
|
352
|
+
if (!action) {
|
|
353
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`The ${type} entry for ${field} is missing an action.`, file));
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const existing = actionMap[field];
|
|
357
|
+
if (existing) {
|
|
358
|
+
compilation.errors.push((0, utils_1.newWebpackErrorForFile)(`Already encountered a definition for the ${type} entry named, "${field}"`, file));
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
actionMap[field] = child;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function convertSNPToKeys(prop, keys) {
|
|
366
|
+
if (Array.isArray(prop)) {
|
|
367
|
+
for (const p of prop) {
|
|
368
|
+
convertSNPToKeys(p, keys);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
else if ('properties' in prop) {
|
|
372
|
+
for (const item of prop.properties) {
|
|
373
|
+
convertSNPToKeys(item, keys);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else if ('items' in prop) {
|
|
377
|
+
for (const item of prop.items) {
|
|
378
|
+
convertSNPToKeys(item, keys);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
if (prop.translatable) {
|
|
383
|
+
keys.push({ name: prop.name, keys: [] });
|
|
384
|
+
}
|
|
385
|
+
else if ('fields' in prop) {
|
|
386
|
+
if (prop.fields) {
|
|
387
|
+
const nestedKeys = [];
|
|
388
|
+
convertSNPToKeys(prop.fields, nestedKeys);
|
|
389
|
+
if (nestedKeys.length) {
|
|
390
|
+
keys.push({ name: prop.name, keys: nestedKeys });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
else if ('itemType' in prop && Array.isArray(prop.itemType)) {
|
|
395
|
+
const nestedKeys = [];
|
|
396
|
+
convertSNPToKeys(prop.itemType, nestedKeys);
|
|
397
|
+
if (nestedKeys.length) {
|
|
398
|
+
keys.push({ name: prop.name, keys: nestedKeys });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function convertGutenbergBlockToJSRepresentation(element) {
|
|
404
|
+
const type = element.getAttribute("type");
|
|
405
|
+
if (!type) {
|
|
406
|
+
throw `A gutenberg-block entry in a wpml-config.xml file is missing its type attribute.`;
|
|
407
|
+
}
|
|
408
|
+
const translate = element.getAttribute("translate");
|
|
409
|
+
if (!translate) {
|
|
410
|
+
throw `The gutenberg-block entry for ${type} is missing its translate attribute.`;
|
|
411
|
+
}
|
|
412
|
+
if (translate !== '0' && translate !== '1') {
|
|
413
|
+
throw `The gutenberg-block entry for ${type} has an invalid translate attribute. Expected 0 or 1, but got, "${translate}"`;
|
|
414
|
+
}
|
|
415
|
+
const keys = [];
|
|
416
|
+
const xPaths = [];
|
|
417
|
+
for (const child of element.children) {
|
|
418
|
+
if (child.nodeName === 'key') {
|
|
419
|
+
keys.push(convertGenericSettingsKeyToJSRepresentation(child, `a gutenberg-block entry for ${type}`));
|
|
420
|
+
}
|
|
421
|
+
else if (child.nodeName === 'xpath') {
|
|
422
|
+
xPaths.push(convertGenericSettingsXPathToJSRepresentation(child, `a gutenberg-block entry for ${type}`));
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
throw `The gutenberg-block entry for ${type} has an unsupported child node ("${child.nodeName}")`;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return { type, label: element.getAttribute("label"), translate, keys, xPaths };
|
|
429
|
+
}
|
|
430
|
+
function convertGenericSettingsKeyToJSRepresentation(element, containerName) {
|
|
431
|
+
const name = element.getAttribute("name");
|
|
432
|
+
if (!name) {
|
|
433
|
+
throw `Encountered a key without a name in ${containerName}.`;
|
|
434
|
+
}
|
|
435
|
+
let encoding = element.getAttribute("encoding");
|
|
436
|
+
if (encoding && encoding !== 'json') {
|
|
437
|
+
throw `Encountered an invalid encoding on a key named, "${name}" in ${containerName}. It must be either blank or JSON`;
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
encoding = null;
|
|
441
|
+
}
|
|
442
|
+
let searchMethod = element.getAttribute("searchMethod");
|
|
443
|
+
if (searchMethod && searchMethod !== 'wildcards' && searchMethod !== 'regex') {
|
|
444
|
+
throw `Encountered an invalid search-method on a key named, "${name}" in ${containerName}. It must be either blank or JSON`;
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
searchMethod = null;
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
name,
|
|
451
|
+
label: element.getAttribute("label"),
|
|
452
|
+
type: element.getAttribute("type"),
|
|
453
|
+
subType: element.getAttribute("sub-type"),
|
|
454
|
+
encoding,
|
|
455
|
+
searchMethod,
|
|
456
|
+
keys: [...element.children].map(child => convertGenericSettingsKeyToJSRepresentation(child, containerName))
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function convertGenericSettingsXPathToJSRepresentation(element, containerName) {
|
|
460
|
+
if (!element.textContent) {
|
|
461
|
+
throw `Encountered an empty XPath in ${containerName}.`;
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
path: element.textContent,
|
|
465
|
+
label: element.getAttribute("label"),
|
|
466
|
+
type: element.getAttribute("type"),
|
|
467
|
+
subType: element.getAttribute("sub-type")
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function mergeWPMLGutenbergBlocks(existing, novel) {
|
|
471
|
+
if (novel.type && existing.type !== novel.type) {
|
|
472
|
+
throw `Cannot merge WPML Gutenberg Blocks of differing types`;
|
|
473
|
+
}
|
|
474
|
+
if (novel.translate && existing.translate !== novel.translate) {
|
|
475
|
+
throw `Cannot merge WPML Gutenberg Blocks (${existing.type} and ${novel.type ?? existing.type}) with differing translate values`;
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
type: existing.type,
|
|
479
|
+
translate: existing.translate,
|
|
480
|
+
label: novel.label ?? existing.label,
|
|
481
|
+
keys: novel.keys?.length ? (existing.keys.length ? mergeGenericSettingsKeyLists(existing.keys, novel.keys) : novel.keys) : existing.keys,
|
|
482
|
+
xPaths: novel.xPaths?.length ? (existing.xPaths.length ? [...existing.xPaths, ...novel.xPaths] : novel.xPaths) : existing.xPaths
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function mergeGenericSettingsKeyLists(existingKeys, novelKeys) {
|
|
486
|
+
const keys = {};
|
|
487
|
+
for (const key of existingKeys) {
|
|
488
|
+
const existing = keys[key.name];
|
|
489
|
+
keys[key.name] = existing ? mergeGenericSettingsKeys(existing, key) : key;
|
|
490
|
+
}
|
|
491
|
+
for (const key of novelKeys) {
|
|
492
|
+
const existing = keys[key.name];
|
|
493
|
+
keys[key.name] = existing ? mergeGenericSettingsKeys(existing, key) : key;
|
|
494
|
+
}
|
|
495
|
+
return Object.values(keys);
|
|
496
|
+
}
|
|
497
|
+
function mergeGenericSettingsKeys(existing, novel) {
|
|
498
|
+
if (existing.encoding && novel.encoding && existing.encoding !== novel.encoding) {
|
|
499
|
+
throw `Cannot merge WPMLGenericSettingsKeys with differing encoding values (${existing.encoding} and ${novel.encoding}) on ${novel.name}.`;
|
|
500
|
+
}
|
|
501
|
+
if (existing.searchMethod && novel.searchMethod && existing.searchMethod !== novel.searchMethod) {
|
|
502
|
+
throw `Cannot merge WPMLGenericSettingsKeys with differing search-method values (${existing.searchMethod} and ${novel.searchMethod}) on ${novel.name}.`;
|
|
503
|
+
}
|
|
504
|
+
return { ...existing, ...novel, keys: mergeGenericSettingsKeyLists(existing.keys, novel.keys) };
|
|
505
|
+
}
|
|
506
|
+
function writeGenericSettingsKeys(keys, parent, document) {
|
|
507
|
+
parent.append(...keys.sort((a, b) => a.name.localeCompare(b.name)).map(key => {
|
|
508
|
+
const element = document.createElement("key");
|
|
509
|
+
element.setAttribute("name", key.name);
|
|
510
|
+
writeCommonGenericSettingsItemProps(element, key);
|
|
511
|
+
if (key.encoding) {
|
|
512
|
+
element.setAttribute("encoding", key.encoding);
|
|
513
|
+
}
|
|
514
|
+
if (key.searchMethod) {
|
|
515
|
+
element.setAttribute("search-method", key.searchMethod);
|
|
516
|
+
}
|
|
517
|
+
writeGenericSettingsKeys(key.keys, element, document);
|
|
518
|
+
return element;
|
|
519
|
+
}));
|
|
520
|
+
}
|
|
521
|
+
function appendNamedElementsListToConfig(containerName, elements, config) {
|
|
522
|
+
const allElements = Object.entries(elements);
|
|
523
|
+
if (allElements.length) {
|
|
524
|
+
const containerElement = config.createElement(containerName);
|
|
525
|
+
config.documentElement.append(containerElement);
|
|
526
|
+
containerElement.append(...allElements
|
|
527
|
+
.sort(([fieldNameA], [fieldNameB]) => fieldNameA.localeCompare(fieldNameB))
|
|
528
|
+
.map(([_, element]) => element));
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
function writeCommonGenericSettingsItemProps(element, item) {
|
|
532
|
+
if (item.label) {
|
|
533
|
+
element.setAttribute("label", item.label);
|
|
534
|
+
}
|
|
535
|
+
if (item.type) {
|
|
536
|
+
element.setAttribute("type", item.type);
|
|
537
|
+
}
|
|
538
|
+
if (item.subType) {
|
|
539
|
+
element.setAttribute("sub-type", item.subType);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
//# sourceMappingURL=WPMLConfigBuilder.js.map
|