@plaudit/webpack-extensions 2.64.0 → 2.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/plugins/{AbstractMultiPhaseLibraryAndEntryPlugin.d.ts → AbstractBiPhasicGroupAndEntryPlugin.d.ts} +7 -6
- package/build/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +85 -0
- package/build/plugins/AbstractBiPhasicGroupPlugin.d.ts +33 -0
- package/build/plugins/AbstractBiPhasicGroupPlugin.js +93 -0
- package/build/plugins/AdditionalDependencyInjectorPlugin.d.ts +2 -2
- package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +3 -3
- package/build/plugins/EnhancedDynamicEntryPlugin.js +3 -3
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +9 -8
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +103 -93
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +6 -7
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +10 -17
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +6 -7
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +15 -16
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +5 -5
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +7 -6
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +5 -5
- package/build/plugins/SpecialAssetHandlingPlugin.js +44 -47
- package/build/plugins/UnifiedLoaderGenerator.d.ts +8 -8
- package/build/plugins/UnifiedLoaderGenerator.js +54 -69
- package/build/plugins/WPMLConfigBuilder.d.ts +2 -2
- package/build/shared.d.ts +4 -3
- package/build/shared.js +19 -3
- package/build/utils/common-config-helpers.d.ts +3 -3
- package/build/utils/common-config-helpers.js +2 -2
- package/build/utils/json-to-php-but-with-__-injection.js +1 -1
- package/build/utils/pseduo-semaphore.d.ts +2 -3
- package/build/utils/pseduo-semaphore.js +9 -5
- package/build/wordpress-scripts-wrapper.js +13 -7
- package/package.json +1 -1
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.js +0 -113
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +0 -17
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +0 -44
|
@@ -5,34 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ExtensionsConfigFileGeneratorPluginV1 = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const
|
|
8
|
+
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
9
9
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
10
10
|
const php_serializer_1 = require("../utils/php-serializer");
|
|
11
11
|
const php_writer_1 = require("../utils/php-writer");
|
|
12
12
|
const webpack_1 = require("webpack");
|
|
13
|
-
class ExtensionsConfigFileGeneratorPluginV1 extends
|
|
13
|
+
class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
14
14
|
extensionsDest;
|
|
15
15
|
constructor(config, extensionsDest, context, entry) {
|
|
16
16
|
super(config, `extensions-v1-${extensionsDest}`, [UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
17
17
|
this.extensionsDest = extensionsDest;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
22
|
-
compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
|
|
23
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, { group: `extensions-config-v1-${this.extensionsDest}`, requiresBaseURI: false, action: writer => {
|
|
24
|
-
writer
|
|
25
|
-
.use("Plaudit\\Common\\Lib\\GutenbergUtils")
|
|
26
|
-
.call("GutenbergUtils::installExtensionsSupport", [php_writer_1.Op.join(php_writer_1.Constants.__DIR__, this.extensionsDest)]);
|
|
27
|
-
} });
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
attachSecondPhase() { }
|
|
32
|
-
processAssets(compilation, rawAssetData) {
|
|
19
|
+
attachUniquePhase() { }
|
|
20
|
+
processAssets(compilation, assetsJson) {
|
|
33
21
|
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
34
22
|
const mapping = {};
|
|
35
|
-
for (const fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation,
|
|
23
|
+
for (const fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation, assetsJson))) {
|
|
36
24
|
let match;
|
|
37
25
|
if ((match = regex.exec(fileWithAssetData)) && match[1] && match[2]) {
|
|
38
26
|
const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
|
|
@@ -41,6 +29,11 @@ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractMultiPhaseLibraryAnd
|
|
|
41
29
|
}
|
|
42
30
|
}
|
|
43
31
|
compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config"), new webpack_1.sources.RawSource((0, php_serializer_1.phpSerialize)(mapping)));
|
|
32
|
+
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, { group: `extensions-config-v1-${this.extensionsDest}`, requiresBaseURI: false, action: writer => {
|
|
33
|
+
writer
|
|
34
|
+
.use("Plaudit\\Common\\Lib\\GutenbergUtils")
|
|
35
|
+
.call("GutenbergUtils::installExtensionsSupport", [php_writer_1.Op.join(php_writer_1.Constants.__DIR__, this.extensionsDest)]);
|
|
36
|
+
} });
|
|
44
37
|
}
|
|
45
38
|
}
|
|
46
39
|
exports.ExtensionsConfigFileGeneratorPluginV1 = ExtensionsConfigFileGeneratorPluginV1;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParsedAssetsJson, UnpackedBlockEntrypointInfo, UsageLocations } from "../shared";
|
|
2
2
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
3
|
-
import {
|
|
3
|
+
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
4
4
|
import { Compilation } from "webpack";
|
|
5
|
-
export declare class PlainEntrypointsConfigFileGeneratorPlugin extends
|
|
5
|
+
export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
|
|
6
6
|
private readonly buildRoot;
|
|
7
7
|
private readonly outputDir;
|
|
8
8
|
private readonly usageLocations;
|
|
9
|
-
private readonly handlePrefix;
|
|
10
9
|
private readonly useUnifiedLoader;
|
|
11
10
|
private static readonly semaphore;
|
|
12
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: UsageLocations,
|
|
11
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: UsageLocations, useUnifiedLoader: boolean, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
|
|
13
12
|
private generatePlainEntrypointsLoader;
|
|
14
13
|
private static addHandlesToHandleLists;
|
|
15
14
|
private static appendEnqueuingHandleLists;
|
|
16
15
|
private static separateHandleListByPriority;
|
|
17
|
-
protected
|
|
18
|
-
protected processAssets(compilation: Compilation,
|
|
16
|
+
protected attachUniquePhase(compilation: Compilation): void;
|
|
17
|
+
protected processAssets(compilation: Compilation, assetsJson: ParsedAssetsJson): void;
|
|
19
18
|
}
|
|
@@ -8,22 +8,20 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
8
8
|
const shared_1 = require("../shared");
|
|
9
9
|
const php_writer_1 = require("../utils/php-writer");
|
|
10
10
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
11
|
-
const
|
|
11
|
+
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
12
12
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
13
13
|
const webpack_1 = require("webpack");
|
|
14
|
-
class PlainEntrypointsConfigFileGeneratorPlugin extends
|
|
14
|
+
class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
15
15
|
buildRoot;
|
|
16
16
|
outputDir;
|
|
17
17
|
usageLocations;
|
|
18
|
-
handlePrefix;
|
|
19
18
|
useUnifiedLoader;
|
|
20
|
-
static semaphore = new pseduo_semaphore_1.PseudoSemaphore(
|
|
21
|
-
constructor(config, buildRoot, outputDir, usageLocations,
|
|
19
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Plain");
|
|
20
|
+
constructor(config, buildRoot, outputDir, usageLocations, useUnifiedLoader, context, entry) {
|
|
22
21
|
super(config, "plain-entrypoints-v2", [PlainEntrypointsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
23
22
|
this.buildRoot = buildRoot;
|
|
24
23
|
this.outputDir = outputDir;
|
|
25
24
|
this.usageLocations = usageLocations;
|
|
26
|
-
this.handlePrefix = handlePrefix;
|
|
27
25
|
this.useUnifiedLoader = useUnifiedLoader;
|
|
28
26
|
}
|
|
29
27
|
generatePlainEntrypointsLoader(compilation, assets) {
|
|
@@ -160,18 +158,19 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibrar
|
|
|
160
158
|
}
|
|
161
159
|
return lists.entries().toArray().sort((a, b) => a[0] - b[0]);
|
|
162
160
|
}
|
|
163
|
-
|
|
164
|
-
compilation.hooks.processAssets.tapPromise({ name:
|
|
161
|
+
attachUniquePhase(compilation) {
|
|
162
|
+
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
165
163
|
this.generatePlainEntrypointsLoader(compilation, (await PlainEntrypointsConfigFileGeneratorPlugin.semaphore.wait()).flat());
|
|
166
164
|
});
|
|
167
165
|
}
|
|
168
|
-
processAssets(compilation,
|
|
166
|
+
processAssets(compilation, assetsJson) {
|
|
169
167
|
const isScriptRegex = /\.m?[jt]sx?(\?|$)/i;
|
|
170
168
|
const myAssetHandles = [];
|
|
171
|
-
|
|
169
|
+
const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
|
|
170
|
+
for (const { entrypoint, srcPath } of relevantEntrypoints) {
|
|
172
171
|
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
173
172
|
const assetData = entrypointChunk.files.values()
|
|
174
|
-
.map(file =>
|
|
173
|
+
.map(file => assetsJson[file]).find(v => v !== undefined);
|
|
175
174
|
if (!assetData) {
|
|
176
175
|
continue;
|
|
177
176
|
}
|
|
@@ -198,14 +197,14 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibrar
|
|
|
198
197
|
handleName: useHandleName ? this.usageLocations.handle : undefined,
|
|
199
198
|
});
|
|
200
199
|
}
|
|
201
|
-
myAssetHandles.push({
|
|
202
|
-
handles,
|
|
203
|
-
handlePrefix: this.handlePrefix
|
|
204
|
-
});
|
|
200
|
+
myAssetHandles.push({ handles, handlePrefix: this.config.plainEntrypointsHandlePrefix });
|
|
205
201
|
}
|
|
206
202
|
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myAssetHandles);
|
|
207
203
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myAssetHandles.length
|
|
208
|
-
? {
|
|
204
|
+
? {
|
|
205
|
+
group: this.group, requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';"),
|
|
206
|
+
staticallyLoadedEntrypoints: Object.keys(relevantEntrypoints)
|
|
207
|
+
}
|
|
209
208
|
: undefined);
|
|
210
209
|
}
|
|
211
210
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
+
import { ParsedAssetsJson, UnpackedBlockEntrypointInfo } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
4
|
import { Compilation } from "webpack";
|
|
5
5
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
6
|
-
export declare class PlainEntrypointsStyleBlockJSONPlugin extends
|
|
6
|
+
export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
|
|
7
7
|
private readonly blocksDest;
|
|
8
8
|
private readonly webpackRemoveEmptyScriptsPlugin;
|
|
9
9
|
private static readonly semaphore;
|
|
10
10
|
constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
|
|
11
|
-
protected processAssets(compilation: Compilation, rawAssetData:
|
|
11
|
+
protected processAssets(compilation: Compilation, rawAssetData: ParsedAssetsJson): Promise<void>;
|
|
12
12
|
private emitBlockLoaderFile;
|
|
13
13
|
private transformBlocks;
|
|
14
14
|
private static extractAssetSource;
|
|
@@ -21,5 +21,5 @@ export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiP
|
|
|
21
21
|
static findRelativeRouteBetween(path1: string, path2: string): string;
|
|
22
22
|
private static remapReferencedPHPFilesOnKey;
|
|
23
23
|
private static normalizeRenderTemplate;
|
|
24
|
-
protected
|
|
24
|
+
protected attachUniquePhase(compilation: Compilation): void;
|
|
25
25
|
}
|
|
@@ -7,17 +7,17 @@ exports.PlainEntrypointsStyleBlockJSONPlugin = void 0;
|
|
|
7
7
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
-
const
|
|
10
|
+
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
11
11
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
12
12
|
const shared_1 = require("../shared");
|
|
13
13
|
const php_writer_1 = require("../utils/php-writer");
|
|
14
14
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
15
15
|
const webpack_1 = require("webpack");
|
|
16
16
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
17
|
-
class PlainEntrypointsStyleBlockJSONPlugin extends
|
|
17
|
+
class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
18
18
|
blocksDest;
|
|
19
19
|
webpackRemoveEmptyScriptsPlugin;
|
|
20
|
-
static semaphore = new pseduo_semaphore_1.PseudoSemaphore(
|
|
20
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Block JSON v3");
|
|
21
21
|
constructor(config, blocksDest, webpackRemoveEmptyScriptsPlugin, context, entry) {
|
|
22
22
|
super(config, `block-json-${blocksDest}`, [PlainEntrypointsStyleBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
23
23
|
this.blocksDest = blocksDest;
|
|
@@ -96,8 +96,9 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
96
96
|
emittingWpmlXml: compilation.getAsset(node_path_1.default.join(this.blocksDest, "wpml-config.xml")) !== undefined
|
|
97
97
|
});
|
|
98
98
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(applicableBlockJsonFiles).length ? {
|
|
99
|
-
group: this.
|
|
99
|
+
group: this.group,
|
|
100
100
|
requiresBaseURI: false,
|
|
101
|
+
staticallyLoadedEntrypoints: Object.keys(relevantEntrypoints),
|
|
101
102
|
action: writer => writer.append(`require_once __DIR__.${php_writer_1.Expr.convertJsonToPHP("/" + node_path_1.default.join(this.blocksDest, "blockdir-loader.php"))};`)
|
|
102
103
|
} : undefined);
|
|
103
104
|
}
|
|
@@ -136,7 +137,6 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
136
137
|
const pathsNeedRemapping = !this.config.standaloneBlocks && blockJson["plaudit"] !== "simple";
|
|
137
138
|
PlainEntrypointsStyleBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "setup", pathsNeedRemapping, sourceDir, outputDir, compilation, true);
|
|
138
139
|
PlainEntrypointsStyleBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "variations", pathsNeedRemapping, sourceDir, outputDir, compilation, false);
|
|
139
|
-
PlainEntrypointsStyleBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
|
|
140
140
|
const hashForVersion = PlainEntrypointsStyleBlockJSONPlugin
|
|
141
141
|
.hashThingForAsset([blockJsonText, ...workableBlockEntrypointsInfo.map(bi => bi.hash)].join("~"));
|
|
142
142
|
if (blockJson["version"]) {
|
|
@@ -145,6 +145,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
145
145
|
else {
|
|
146
146
|
blockJson["version"] = hashForVersion;
|
|
147
147
|
}
|
|
148
|
+
PlainEntrypointsStyleBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
|
|
148
149
|
const blockDirName = node_path_1.default.dirname(node_path_1.default.relative(this.blocksDest, blockJsonAssetName));
|
|
149
150
|
blockData[blockDirName] = PlainEntrypointsStyleBlockJSONPlugin
|
|
150
151
|
.doFileOrHandleReplacements(compilation, Object.fromEntries(Object.entries(blockJson).filter(([k]) => k !== '$schema')), workableBlockEntrypointsInfo, epi => epi.handle);
|
|
@@ -343,7 +344,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndE
|
|
|
343
344
|
}
|
|
344
345
|
}
|
|
345
346
|
}
|
|
346
|
-
|
|
347
|
+
attachUniquePhase(compilation) {
|
|
347
348
|
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
348
349
|
const allSemaphoreData = (await PlainEntrypointsStyleBlockJSONPlugin.semaphore.wait())
|
|
349
350
|
.reduce((acc, cur) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
2
|
-
import {
|
|
3
|
-
import { Compilation
|
|
4
|
-
export declare class SpecialAssetHandlingPlugin extends
|
|
2
|
+
import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
|
|
3
|
+
import { Compilation } from "webpack";
|
|
4
|
+
export declare class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin {
|
|
5
5
|
private static readonly semaphore;
|
|
6
6
|
private static validPathname?;
|
|
7
7
|
constructor(config: VerifiedPlauditWordpressWebpackConfig);
|
|
8
|
-
|
|
8
|
+
protected attachStandardPhase(compilation: Compilation): void;
|
|
9
9
|
private collateAssets;
|
|
10
|
-
protected
|
|
10
|
+
protected attachUniquePhase(compilation: Compilation): void;
|
|
11
11
|
}
|
|
@@ -8,59 +8,54 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
8
8
|
const shared_1 = require("../shared");
|
|
9
9
|
const php_writer_1 = require("../utils/php-writer");
|
|
10
10
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
11
|
-
const
|
|
11
|
+
const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
|
|
12
12
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
13
13
|
const webpack_1 = require("webpack");
|
|
14
|
-
class SpecialAssetHandlingPlugin extends
|
|
15
|
-
static semaphore = new pseduo_semaphore_1.PseudoSemaphore(
|
|
14
|
+
class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
|
|
15
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Special");
|
|
16
16
|
static validPathname = undefined;
|
|
17
17
|
constructor(config) {
|
|
18
18
|
super(config, "special-assets", [SpecialAssetHandlingPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
specialAssetData[filename] = {
|
|
48
|
-
preload: true,
|
|
49
|
-
fetchpriority: params.get("fetchpriority"),
|
|
50
|
-
crossorigin: params.get("crossorigin")
|
|
51
|
-
};
|
|
52
|
-
}
|
|
20
|
+
attachStandardPhase(compilation) {
|
|
21
|
+
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE }, async (assets) => {
|
|
22
|
+
try {
|
|
23
|
+
const specialAssetData = {};
|
|
24
|
+
for (const pathname of Object.keys(assets)) {
|
|
25
|
+
if (!SpecialAssetHandlingPlugin.validPathname) {
|
|
26
|
+
SpecialAssetHandlingPlugin.validPathname = pathname;
|
|
27
|
+
}
|
|
28
|
+
const assetInfo = compilation.assetsInfo.get(pathname);
|
|
29
|
+
if (!assetInfo?.sourceFilename) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const filename = node_path_1.default.join(node_path_1.default.basename(node_path_1.default.dirname(pathname)), node_path_1.default.basename(pathname));
|
|
33
|
+
const queryStart = assetInfo.sourceFilename.indexOf('?');
|
|
34
|
+
if (queryStart < 0) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const params = new URLSearchParams(assetInfo.sourceFilename.substring(queryStart + 1)
|
|
38
|
+
.replace(/(?:fetchPriority|crossOrigin)=/gi, str => str.toLowerCase()) //This ensures consistent capitalization of the fetchPriority parameter
|
|
39
|
+
);
|
|
40
|
+
if (params.has("preload")) {
|
|
41
|
+
SpecialAssetHandlingPlugin.validPathname = pathname;
|
|
42
|
+
specialAssetData[filename] = {
|
|
43
|
+
preload: true,
|
|
44
|
+
fetchpriority: params.get("fetchpriority"),
|
|
45
|
+
crossorigin: params.get("crossorigin")
|
|
46
|
+
};
|
|
53
47
|
}
|
|
54
|
-
SpecialAssetHandlingPlugin.semaphore.resolve(this.id, specialAssetData);
|
|
55
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(specialAssetData).length > 0
|
|
56
|
-
? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/special-assets.php';") }
|
|
57
|
-
: undefined);
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
this.rejectSemaphores();
|
|
61
|
-
throw e;
|
|
62
48
|
}
|
|
63
|
-
|
|
49
|
+
SpecialAssetHandlingPlugin.semaphore.resolve(this.id, specialAssetData);
|
|
50
|
+
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(specialAssetData).length > 0
|
|
51
|
+
? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/special-assets.php';") }
|
|
52
|
+
: undefined);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error(e);
|
|
56
|
+
this.rejectSemaphores();
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
64
59
|
});
|
|
65
60
|
}
|
|
66
61
|
async collateAssets(compilation) {
|
|
@@ -127,8 +122,10 @@ class SpecialAssetHandlingPlugin extends AbstractMultiPhaseLibraryPlugin_1.Abstr
|
|
|
127
122
|
});
|
|
128
123
|
writer.emitAsset(compilation, outputFile);
|
|
129
124
|
}
|
|
130
|
-
|
|
131
|
-
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, () =>
|
|
125
|
+
attachUniquePhase(compilation) {
|
|
126
|
+
compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
127
|
+
await this.collateAssets(compilation);
|
|
128
|
+
});
|
|
132
129
|
}
|
|
133
130
|
}
|
|
134
131
|
exports.SpecialAssetHandlingPlugin = SpecialAssetHandlingPlugin;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
|
|
1
2
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
2
|
-
import { PseudoSemaphore } from "../utils/pseduo-semaphore";
|
|
3
3
|
import { PHPWriter } from "../utils/php-writer";
|
|
4
|
-
import {
|
|
4
|
+
import { PseudoSemaphore } from "../utils/pseduo-semaphore";
|
|
5
|
+
import { Compilation } from "webpack";
|
|
5
6
|
type LoaderInfo = {
|
|
6
7
|
group: string;
|
|
7
8
|
action(writer: PHPWriter): void;
|
|
8
9
|
requiresBaseURI: boolean;
|
|
10
|
+
staticallyLoadedEntrypoints?: string[];
|
|
9
11
|
priority?: number;
|
|
10
12
|
};
|
|
11
|
-
export declare class UnifiedLoaderGenerator
|
|
12
|
-
|
|
13
|
-
static readonly semaphore: PseudoSemaphore<LoaderInfo | undefined>;
|
|
14
|
-
private static attached;
|
|
15
|
-
private readonly id;
|
|
13
|
+
export declare class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin {
|
|
14
|
+
static readonly semaphore: PseudoSemaphore<LoaderInfo>;
|
|
16
15
|
constructor(config: VerifiedPlauditWordpressWebpackConfig);
|
|
17
|
-
|
|
16
|
+
protected attachStandardPhase(compilation: Compilation): void;
|
|
17
|
+
protected attachUniquePhase(compilation: Compilation): void;
|
|
18
18
|
}
|
|
19
19
|
export {};
|
|
@@ -5,84 +5,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.UnifiedLoaderGenerator = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
|
|
8
9
|
const shared_1 = require("../shared");
|
|
9
|
-
const
|
|
10
|
+
const json_to_php_but_with____injection_1 = __importDefault(require("../utils/json-to-php-but-with-__-injection"));
|
|
10
11
|
const php_writer_1 = require("../utils/php-writer");
|
|
12
|
+
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
11
13
|
const webpack_1 = require("webpack");
|
|
12
|
-
class UnifiedLoaderGenerator {
|
|
13
|
-
|
|
14
|
-
static semaphore = new pseduo_semaphore_1.PseudoSemaphore(undefined, "Unified");
|
|
15
|
-
static attached = false;
|
|
16
|
-
id;
|
|
14
|
+
class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
|
|
15
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Unified");
|
|
17
16
|
constructor(config) {
|
|
18
|
-
|
|
19
|
-
this.id = Math.random().toString();
|
|
17
|
+
super(config, "unified-loader", []);
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
compilation.
|
|
24
|
-
if (!this.config.useUnifiedLoader) {
|
|
25
|
-
const rawAssetDataSource = compilation.assets["assets.json"]?.source();
|
|
26
|
-
if (typeof rawAssetDataSource !== 'string') {
|
|
27
|
-
compilation.errors.push(new Error("assets.json is unexpectedly missing or not a string"));
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const rawAssetData = JSON.parse(rawAssetDataSource);
|
|
31
|
-
if (!(0, shared_1.isRawAssetData)(rawAssetData)) {
|
|
32
|
-
compilation.errors.push(new Error("assets.json is does not match the RawAssetData format"));
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
for (const [file, assetData] of Object.entries(rawAssetData)) {
|
|
36
|
-
const escapedDependencies = assetData.dependencies.map(php_writer_1.Expr.convertJsonToPHP).join(", ");
|
|
37
|
-
const contents = `<?php return ['dependencies' => [${escapedDependencies}], 'version' => ${php_writer_1.Expr.convertJsonToPHP(assetData.version)}];\n`;
|
|
38
|
-
const parsedPath = node_path_1.default.parse(file);
|
|
39
|
-
const assetPHPFile = node_path_1.default.join(parsedPath.dir, parsedPath.name) + ".asset.php";
|
|
40
|
-
compilation.emitAsset(assetPHPFile, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
compilation.deleteAsset("assets.json");
|
|
44
|
-
});
|
|
19
|
+
attachStandardPhase(compilation) {
|
|
20
|
+
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
21
|
+
compilation.deleteAsset("assets.json");
|
|
45
22
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const ap = a.priority ?? 0, bp = b.priority ?? 0;
|
|
64
|
-
return ap === bp ? a.group.localeCompare(b.group) : bp - ap;
|
|
65
|
-
})
|
|
66
|
-
.filter(a => !alreadyAllocatedGroups.has(a.group) && alreadyAllocatedGroups.add(a.group));
|
|
67
|
-
if (writerCallbacks.length > 0) {
|
|
68
|
-
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
69
|
-
const writer = new php_writer_1.PHPWriter();
|
|
70
|
-
if (writerCallbacks.some(wc => wc.requiresBaseURI)) {
|
|
71
|
-
(0, shared_1.emitResolveBaseUriFunction)(writer);
|
|
72
|
-
}
|
|
73
|
-
for (const writerCallback of writerCallbacks) {
|
|
74
|
-
writerCallback.action(writer);
|
|
75
|
-
}
|
|
76
|
-
writer.emitAsset(compilation, "unified-loader.php");
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
23
|
+
}
|
|
24
|
+
attachUniquePhase(compilation) {
|
|
25
|
+
this.tapWithParsedAssetsJson(compilation, { stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async (parsedAssetsJson) => {
|
|
26
|
+
const groupedLoaderInfo = Object.values((await UnifiedLoaderGenerator.semaphore.wait())
|
|
27
|
+
.reduce((acc, cur) => {
|
|
28
|
+
const accValue = acc[cur.group];
|
|
29
|
+
if (accValue === undefined) {
|
|
30
|
+
acc[cur.group] = { ...cur, priority: cur.priority ?? 0, staticallyLoadedEntrypoints: cur.staticallyLoadedEntrypoints?.length ? [...cur.staticallyLoadedEntrypoints] : [] };
|
|
31
|
+
return acc;
|
|
32
|
+
}
|
|
33
|
+
if (cur.priority && accValue.priority < cur.priority) {
|
|
34
|
+
accValue.priority = cur.priority;
|
|
35
|
+
accValue.action = cur.action;
|
|
36
|
+
accValue.requiresBaseURI = cur.requiresBaseURI;
|
|
37
|
+
}
|
|
38
|
+
else if (cur.requiresBaseURI && !accValue.requiresBaseURI) {
|
|
39
|
+
accValue.requiresBaseURI = cur.requiresBaseURI;
|
|
80
40
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
throw e;
|
|
41
|
+
if (cur.staticallyLoadedEntrypoints?.length) {
|
|
42
|
+
accValue.staticallyLoadedEntrypoints.push(...cur.staticallyLoadedEntrypoints);
|
|
84
43
|
}
|
|
44
|
+
return acc;
|
|
45
|
+
}, {}))
|
|
46
|
+
.sort((a, b) => {
|
|
47
|
+
const ap = a.priority ?? 0, bp = b.priority ?? 0;
|
|
48
|
+
return ap === bp ? a.group.localeCompare(b.group) : bp - ap;
|
|
85
49
|
});
|
|
50
|
+
const staticallyLoadedEntrypoints = new Set(groupedLoaderInfo.flatMap(lig => lig.staticallyLoadedEntrypoints));
|
|
51
|
+
for (const [file, assetData] of Object.entries(parsedAssetsJson)) {
|
|
52
|
+
if (staticallyLoadedEntrypoints.has(file)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const parsedPath = node_path_1.default.parse(file);
|
|
56
|
+
const contents = `<?php return ${(0, json_to_php_but_with____injection_1.default)(assetData)};\n`;
|
|
57
|
+
compilation.emitAsset(node_path_1.default.join(parsedPath.dir, parsedPath.name) + ".asset.php", new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
58
|
+
}
|
|
59
|
+
if (this.config.useUnifiedLoader) {
|
|
60
|
+
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
61
|
+
const writer = new php_writer_1.PHPWriter();
|
|
62
|
+
if (groupedLoaderInfo.some(wc => wc.requiresBaseURI)) {
|
|
63
|
+
(0, shared_1.emitResolveBaseUriFunction)(writer);
|
|
64
|
+
}
|
|
65
|
+
for (const { action } of groupedLoaderInfo) {
|
|
66
|
+
action(writer);
|
|
67
|
+
}
|
|
68
|
+
writer.emitAsset(compilation, "unified-loader.php");
|
|
69
|
+
});
|
|
70
|
+
}
|
|
86
71
|
});
|
|
87
72
|
}
|
|
88
73
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractBiPhasicGroupAndEntryPlugin } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
2
|
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
3
3
|
export declare class WPMLConfigBuilderPlugin implements WebpackPluginInstance {
|
|
4
4
|
private readonly destDir;
|
|
@@ -7,7 +7,7 @@ export declare class WPMLConfigBuilderPlugin implements WebpackPluginInstance {
|
|
|
7
7
|
private static domParser?;
|
|
8
8
|
private static xmlSerializer?;
|
|
9
9
|
private readonly parsedDocumentsCache;
|
|
10
|
-
constructor(destDir: string, referencePlugin:
|
|
10
|
+
constructor(destDir: string, referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>);
|
|
11
11
|
apply(compiler: Compiler): void;
|
|
12
12
|
private static getJSDOMInstance;
|
|
13
13
|
private static getDOMParser;
|
package/build/shared.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PHPWriter } from "./utils/php-writer";
|
|
2
2
|
import type { Options as PostcssFunctionsOptions } from "postcss-functions";
|
|
3
|
-
import { type Configuration, type EntryOptions, WebpackError } from "webpack";
|
|
4
|
-
export type
|
|
3
|
+
import { Compilation, type Configuration, type EntryOptions, WebpackError } from "webpack";
|
|
4
|
+
export type ParsedAssetsJson = Record<string, {
|
|
5
5
|
dependencies: string[];
|
|
6
6
|
version: string;
|
|
7
7
|
}>;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function isParsedAssetsJson(thing: any): thing is ParsedAssetsJson;
|
|
9
9
|
type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
|
|
10
10
|
export type HandleData = {
|
|
11
11
|
src: string;
|
|
@@ -117,4 +117,5 @@ export declare function newWebpackErrorForFile(error: string | ConstructorParame
|
|
|
117
117
|
* The primary benefit of emitting a function instead of baking its contents into each function that uses it is that it allows us to avoid recomputing the base uri multiple times
|
|
118
118
|
*/
|
|
119
119
|
export declare function emitResolveBaseUriFunction(writer: PHPWriter): void;
|
|
120
|
+
export declare function getAssetsJson(compilation: Compilation): ParsedAssetsJson;
|
|
120
121
|
export {};
|
package/build/shared.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.styleExtension = exports.scriptWithModuleExtension = exports.scriptWithoutModuleExtension = exports.scriptExtension = exports.entrypointFields = exports.standardLocationNames = void 0;
|
|
7
|
-
exports.
|
|
7
|
+
exports.isParsedAssetsJson = isParsedAssetsJson;
|
|
8
8
|
exports.determineCurrentSourceType = determineCurrentSourceType;
|
|
9
9
|
exports.packBlockEntrypointInfoForSmuggling = packBlockEntrypointInfoForSmuggling;
|
|
10
10
|
exports.unpackSmuggledBlockEntrypointInfo = unpackSmuggledBlockEntrypointInfo;
|
|
@@ -23,11 +23,12 @@ exports.loadEnvFile = loadEnvFile;
|
|
|
23
23
|
exports.parseEnvFile = parseEnvFile;
|
|
24
24
|
exports.newWebpackErrorForFile = newWebpackErrorForFile;
|
|
25
25
|
exports.emitResolveBaseUriFunction = emitResolveBaseUriFunction;
|
|
26
|
+
exports.getAssetsJson = getAssetsJson;
|
|
26
27
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
27
28
|
const json_to_php_but_with____injection_1 = __importDefault(require("./utils/json-to-php-but-with-__-injection"));
|
|
28
29
|
const php_writer_1 = require("./utils/php-writer");
|
|
29
30
|
const webpack_1 = require("webpack");
|
|
30
|
-
function
|
|
31
|
+
function isParsedAssetsJson(thing) {
|
|
31
32
|
if (!thing || typeof thing !== 'object') {
|
|
32
33
|
return false;
|
|
33
34
|
}
|
|
@@ -110,7 +111,7 @@ function isScriptModuleField(field) {
|
|
|
110
111
|
return field.includes("odule");
|
|
111
112
|
}
|
|
112
113
|
function hasAtLeastOneItem(list) {
|
|
113
|
-
return list.length > 0;
|
|
114
|
+
return list.length > 0 && list[0] !== undefined && list[0] !== null;
|
|
114
115
|
}
|
|
115
116
|
function arrayIsLength(arr, length) {
|
|
116
117
|
return !!arr && arr.length === length;
|
|
@@ -160,3 +161,18 @@ function emitResolveBaseUriFunction(writer) {
|
|
|
160
161
|
.call("trailingslashit", [php_writer_1.Expr.call("home_url", [path])], { return: true, assignTo: assignmentTarget });
|
|
161
162
|
}, { returnType: "string", includeExistenceCheck: true });
|
|
162
163
|
}
|
|
164
|
+
function getAssetsJson(compilation) {
|
|
165
|
+
const asset = compilation.getAsset("assets.json");
|
|
166
|
+
if (!asset) {
|
|
167
|
+
throw new Error("assets.json is unexpectedly missing");
|
|
168
|
+
}
|
|
169
|
+
if (isParsedAssetsJson(asset.info["parsed-assets-json"])) {
|
|
170
|
+
return asset.info["parsed-assets-json"];
|
|
171
|
+
}
|
|
172
|
+
const parsedAssetJson = JSON.parse(asset.source.source().toString('utf-8'));
|
|
173
|
+
if (!isParsedAssetsJson(parsedAssetJson)) {
|
|
174
|
+
throw new Error("assets.json is does not match the RawAssetData format");
|
|
175
|
+
}
|
|
176
|
+
compilation.updateAsset("assets.json", s => s, a => ({ ...a, "parsed-assets-json": parsedAssetJson }));
|
|
177
|
+
return parsedAssetJson;
|
|
178
|
+
}
|