@plaudit/webpack-extensions 2.63.2 → 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/AbstractBiPhasicGroupAndEntryPlugin.d.ts +22 -0
- package/build/plugins/{AbstractMultiPhaseLibraryAndEntryPlugin.js → AbstractBiPhasicGroupAndEntryPlugin.js} +31 -8
- package/build/plugins/AbstractBiPhasicGroupPlugin.d.ts +33 -0
- package/build/plugins/AbstractBiPhasicGroupPlugin.js +93 -0
- package/build/plugins/AdditionalDependencyInjectorPlugin.d.ts +3 -1
- package/build/plugins/AdditionalDependencyInjectorPlugin.js +5 -3
- package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +8 -0
- package/build/plugins/EnhancedDynamicEntryPlugin.js +12 -0
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +9 -8
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +108 -142
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +8 -6
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +22 -32
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +8 -8
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +51 -82
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +6 -7
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +78 -107
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +5 -6
- package/build/plugins/SpecialAssetHandlingPlugin.js +45 -51
- package/build/plugins/UnifiedLoaderGenerator.d.ts +8 -8
- package/build/plugins/UnifiedLoaderGenerator.js +59 -46
- package/build/plugins/WPMLConfigBuilder.d.ts +3 -1
- package/build/plugins/WPMLConfigBuilder.js +7 -4
- package/build/shared.d.ts +7 -5
- package/build/shared.js +19 -3
- package/build/utils/common-config-helpers.d.ts +5 -3
- package/build/utils/common-config-helpers.js +10 -31
- 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 +116 -106
- package/package.json +1 -2
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.d.ts +0 -19
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +0 -14
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +0 -37
|
@@ -8,62 +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
|
-
|
|
16
|
-
static semaphore = new pseduo_semaphore_1.PseudoSemaphore({}, "Special");
|
|
14
|
+
class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
|
|
15
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Special");
|
|
17
16
|
static validPathname = undefined;
|
|
18
17
|
constructor(config) {
|
|
19
|
-
super("special-assets", [SpecialAssetHandlingPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
20
|
-
this.config = config;
|
|
18
|
+
super(config, "special-assets", [SpecialAssetHandlingPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
specialAssetData[filename] = {
|
|
50
|
-
preload: true,
|
|
51
|
-
fetchpriority: params.get("fetchpriority"),
|
|
52
|
-
crossorigin: params.get("crossorigin")
|
|
53
|
-
};
|
|
54
|
-
}
|
|
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
|
+
};
|
|
55
47
|
}
|
|
56
|
-
SpecialAssetHandlingPlugin.semaphore.resolve(this.id, specialAssetData);
|
|
57
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(specialAssetData).length > 0
|
|
58
|
-
? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/special-assets.php';") }
|
|
59
|
-
: undefined);
|
|
60
|
-
}
|
|
61
|
-
catch (e) {
|
|
62
|
-
SpecialAssetHandlingPlugin.semaphore.reject(this.id);
|
|
63
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reject(this.id);
|
|
64
|
-
throw e;
|
|
65
48
|
}
|
|
66
|
-
|
|
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
|
+
}
|
|
67
59
|
});
|
|
68
60
|
}
|
|
69
61
|
async collateAssets(compilation) {
|
|
@@ -130,8 +122,10 @@ class SpecialAssetHandlingPlugin extends AbstractMultiPhaseLibraryPlugin_1.Abstr
|
|
|
130
122
|
});
|
|
131
123
|
writer.emitAsset(compilation, outputFile);
|
|
132
124
|
}
|
|
133
|
-
|
|
134
|
-
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
|
+
});
|
|
135
129
|
}
|
|
136
130
|
}
|
|
137
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 {};
|
|
@@ -1,60 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.UnifiedLoaderGenerator = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
|
|
4
9
|
const shared_1 = require("../shared");
|
|
5
|
-
const
|
|
10
|
+
const json_to_php_but_with____injection_1 = __importDefault(require("../utils/json-to-php-but-with-__-injection"));
|
|
6
11
|
const php_writer_1 = require("../utils/php-writer");
|
|
12
|
+
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
7
13
|
const webpack_1 = require("webpack");
|
|
8
|
-
class UnifiedLoaderGenerator {
|
|
9
|
-
|
|
10
|
-
static semaphore = new pseduo_semaphore_1.PseudoSemaphore(undefined, "Unified");
|
|
11
|
-
static attached = false;
|
|
12
|
-
id;
|
|
14
|
+
class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
|
|
15
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Unified");
|
|
13
16
|
constructor(config) {
|
|
14
|
-
|
|
15
|
-
this.id = Math.random().toString();
|
|
17
|
+
super(config, "unified-loader", []);
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
UnifiedLoaderGenerator.attached = true;
|
|
31
|
-
const alreadyAllocatedGroups = new Set();
|
|
32
|
-
const writerCallbacks = (await UnifiedLoaderGenerator.semaphore.wait())
|
|
33
|
-
.filter((a) => a !== undefined)
|
|
34
|
-
.sort((a, b) => {
|
|
35
|
-
const ap = a.priority ?? 0, bp = b.priority ?? 0;
|
|
36
|
-
return ap === bp ? a.group.localeCompare(b.group) : bp - ap;
|
|
37
|
-
})
|
|
38
|
-
.filter(a => !alreadyAllocatedGroups.has(a.group) && alreadyAllocatedGroups.add(a.group));
|
|
39
|
-
if (writerCallbacks.length > 0) {
|
|
40
|
-
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
41
|
-
const writer = new php_writer_1.PHPWriter();
|
|
42
|
-
if (writerCallbacks.some(wc => wc.requiresBaseURI)) {
|
|
43
|
-
(0, shared_1.emitResolveBaseUriFunction)(writer);
|
|
44
|
-
}
|
|
45
|
-
for (const writerCallback of writerCallbacks) {
|
|
46
|
-
writerCallback.action(writer);
|
|
47
|
-
}
|
|
48
|
-
writer.emitAsset(compilation, "unified-loader.php");
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
19
|
+
attachStandardPhase(compilation) {
|
|
20
|
+
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
21
|
+
compilation.deleteAsset("assets.json");
|
|
22
|
+
});
|
|
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;
|
|
52
32
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
33
|
+
if (cur.priority && accValue.priority < cur.priority) {
|
|
34
|
+
accValue.priority = cur.priority;
|
|
35
|
+
accValue.action = cur.action;
|
|
36
|
+
accValue.requiresBaseURI = cur.requiresBaseURI;
|
|
56
37
|
}
|
|
38
|
+
else if (cur.requiresBaseURI && !accValue.requiresBaseURI) {
|
|
39
|
+
accValue.requiresBaseURI = cur.requiresBaseURI;
|
|
40
|
+
}
|
|
41
|
+
if (cur.staticallyLoadedEntrypoints?.length) {
|
|
42
|
+
accValue.staticallyLoadedEntrypoints.push(...cur.staticallyLoadedEntrypoints);
|
|
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;
|
|
57
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
|
+
}
|
|
58
71
|
});
|
|
59
72
|
}
|
|
60
73
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { AbstractBiPhasicGroupAndEntryPlugin } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
1
2
|
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
2
3
|
export declare class WPMLConfigBuilderPlugin implements WebpackPluginInstance {
|
|
3
4
|
private readonly destDir;
|
|
5
|
+
private readonly referencePlugin;
|
|
4
6
|
private static jsdomInstance?;
|
|
5
7
|
private static domParser?;
|
|
6
8
|
private static xmlSerializer?;
|
|
7
9
|
private readonly parsedDocumentsCache;
|
|
8
|
-
constructor(destDir: string);
|
|
10
|
+
constructor(destDir: string, referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>);
|
|
9
11
|
apply(compiler: Compiler): void;
|
|
10
12
|
private static getJSDOMInstance;
|
|
11
13
|
private static getDOMParser;
|
|
@@ -12,26 +12,29 @@ const webpack_1 = require("webpack");
|
|
|
12
12
|
const xml_formatter_1 = __importDefault(require("xml-formatter"));
|
|
13
13
|
class WPMLConfigBuilderPlugin {
|
|
14
14
|
destDir;
|
|
15
|
+
referencePlugin;
|
|
15
16
|
static jsdomInstance;
|
|
16
17
|
static domParser;
|
|
17
18
|
static xmlSerializer;
|
|
18
19
|
parsedDocumentsCache = new Map();
|
|
19
|
-
constructor(destDir) {
|
|
20
|
+
constructor(destDir, referencePlugin) {
|
|
20
21
|
this.destDir = destDir;
|
|
22
|
+
this.referencePlugin = referencePlugin;
|
|
21
23
|
}
|
|
22
24
|
apply(compiler) {
|
|
23
|
-
//TODO: Filter by library here as well
|
|
24
25
|
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
25
26
|
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}__processXML`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, async (assets) => {
|
|
26
27
|
const entrypoint = compilation.entrypoints.get("wpml-config.xml");
|
|
27
28
|
if (!entrypoint) {
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
31
|
+
const blockJsonFiles = this.referencePlugin.getRelevantEntrypoints(compilation)
|
|
32
|
+
.map(ep => ep.srcPath)
|
|
33
|
+
.filter(srcPath => srcPath.endsWith("block.json"));
|
|
30
34
|
const files = Promise.all([
|
|
31
35
|
Promise.all(entrypoint.origins.map(origin => origin.request).filter(request => request.endsWith("wpml-config.xml"))
|
|
32
36
|
.map(async (request) => this.loadWPMLConfigXML(request, compilation))),
|
|
33
|
-
Promise.all(
|
|
34
|
-
.map(async (request) => JSON.parse(await promises_1.default.readFile(request, 'utf8'))))
|
|
37
|
+
Promise.all(blockJsonFiles.map(async (request) => JSON.parse(await promises_1.default.readFile(request, 'utf8'))))
|
|
35
38
|
]);
|
|
36
39
|
const wpmlEmitPath = node_path_1.default.join(this.destDir, "wpml-config.xml");
|
|
37
40
|
for (const name of Object.keys(assets)) {
|
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;
|
|
@@ -41,7 +41,7 @@ export type Externals = {
|
|
|
41
41
|
};
|
|
42
42
|
export type AdvancedOutputConfig = {
|
|
43
43
|
destination?: string;
|
|
44
|
-
withLegacyBlocksIn?: string | undefined;
|
|
44
|
+
withLegacyBlocksIn?: string | undefined | false;
|
|
45
45
|
additionalDependencies?: string[];
|
|
46
46
|
directoryLayout?: SourceType;
|
|
47
47
|
assumeGlobalizedPlauditLibraries?: boolean;
|
|
@@ -49,7 +49,8 @@ export type AdvancedOutputConfig = {
|
|
|
49
49
|
bundleAnalyzer?: boolean;
|
|
50
50
|
locations?: UsageLocations | UsageLocations['handle'];
|
|
51
51
|
};
|
|
52
|
-
|
|
52
|
+
type OptionalCfgFields = 'directoryLayout' | 'externalize';
|
|
53
|
+
export type VerifiedAdvancedOutputConfig = Required<Omit<AdvancedOutputConfig, 'locations' | OptionalCfgFields>> & Pick<AdvancedOutputConfig, OptionalCfgFields> & {
|
|
53
54
|
locations: UsageLocations;
|
|
54
55
|
};
|
|
55
56
|
export type PlauditWordpressWebpackConfig = {
|
|
@@ -116,4 +117,5 @@ export declare function newWebpackErrorForFile(error: string | ConstructorParame
|
|
|
116
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
|
|
117
118
|
*/
|
|
118
119
|
export declare function emitResolveBaseUriFunction(writer: PHPWriter): void;
|
|
120
|
+
export declare function getAssetsJson(compilation: Compilation): ParsedAssetsJson;
|
|
119
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
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { EntryProvider } from "../plugins/
|
|
1
|
+
import type { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "../plugins/AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
+
import type { AdditionalDependencyInjectorPlugin } from "../plugins/AdditionalDependencyInjectorPlugin";
|
|
2
3
|
import { EntrypointFields, PlauditWordpressWebpackConfig, UnpackedBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
|
|
3
|
-
import type { Compiler, Configuration, DynamicEntryPlugin,
|
|
4
|
+
import type { Compiler, Configuration, DynamicEntryPlugin, WebpackPluginInstance } from "webpack";
|
|
4
5
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
5
6
|
export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpressWebpackConfig, 'variables' | 'src' | 'externals'>> & {
|
|
6
7
|
variablesFilePath?: string;
|
|
@@ -9,6 +10,7 @@ export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpre
|
|
|
9
10
|
export type CommonPluginConfig = {
|
|
10
11
|
plugins: (WebpackPluginInstance | ((this: Compiler, compiler: Compiler) => void))[];
|
|
11
12
|
removeEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin;
|
|
13
|
+
makeAdditionalDependencyInjectorPlugin(referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>): AdditionalDependencyInjectorPlugin;
|
|
12
14
|
};
|
|
13
15
|
export type CommonConfigProcessingResult = {
|
|
14
16
|
entrypointFields: EntrypointFields;
|
|
@@ -27,4 +29,4 @@ export type ExtensibleEntryObject<M> = {
|
|
|
27
29
|
};
|
|
28
30
|
};
|
|
29
31
|
export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): EntryProvider<UnpackedBlockEntrypointInfo | string>;
|
|
30
|
-
export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration,
|
|
32
|
+
export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration, externalize: VerifiedAdvancedOutputConfig['externalize'], plugins: CommonPluginConfig['plugins'], canClean: boolean): Configuration;
|
|
@@ -11,7 +11,6 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
11
11
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
12
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
13
13
|
const shared_1 = require("../shared");
|
|
14
|
-
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
15
14
|
let isInThemeCache = undefined;
|
|
16
15
|
function isInTheme() {
|
|
17
16
|
return isInThemeCache ?? (isInThemeCache = node_fs_1.default.existsSync(node_path_1.default.join(process.cwd(), "theme.json")));
|
|
@@ -122,7 +121,6 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
122
121
|
if (!dirent.isDirectory()) {
|
|
123
122
|
continue;
|
|
124
123
|
}
|
|
125
|
-
//TODO: It should be possible to handle all block.json files simultaneously, which would allow for better detection of repeated code
|
|
126
124
|
const dir = joinPossiblyAbsolutePaths(srcRoot, dirent.name);
|
|
127
125
|
loadingEntrypoints.push(new Promise(async (resolve) => {
|
|
128
126
|
const rawEntrypoints = [];
|
|
@@ -265,8 +263,8 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
265
263
|
return currentEntry;
|
|
266
264
|
};
|
|
267
265
|
}
|
|
268
|
-
function commonMakeWebpackConfig(config, commonConfig, webpackConfig,
|
|
269
|
-
const {
|
|
266
|
+
function commonMakeWebpackConfig(config, commonConfig, webpackConfig, externalize, plugins, canClean) {
|
|
267
|
+
const { variablesFilePath } = config;
|
|
270
268
|
const { fixedRules, processingModules, updateCurrentVariables } = commonConfig;
|
|
271
269
|
const outPath = joinPossiblyAbsolutePaths(process.cwd(), config.outputDir);
|
|
272
270
|
let publicPath = webpackConfig.output?.publicPath;
|
|
@@ -281,12 +279,6 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
281
279
|
}
|
|
282
280
|
}
|
|
283
281
|
let viableRoots = [...(Array.isArray(webpackConfig.context) ? webpackConfig.context : [webpackConfig.context ?? process.cwd()])];
|
|
284
|
-
if (Array.isArray(srcRoot)) {
|
|
285
|
-
viableRoots.push(...(srcIsDirectory ? srcRoot : srcRoot.map(s => node_path_1.default.dirname(s))));
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
viableRoots.push(srcIsDirectory ? srcRoot : node_path_1.default.dirname(srcRoot));
|
|
289
|
-
}
|
|
290
282
|
let wpContentHolderDirectory = process.cwd();
|
|
291
283
|
while (wpContentHolderDirectory.length > 5) {
|
|
292
284
|
if (node_path_1.default.basename(wpContentHolderDirectory) === 'wp-content') {
|
|
@@ -301,10 +293,10 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
301
293
|
const distinctViableRoots = new Set();
|
|
302
294
|
viableRoots = viableRoots.filter(value => distinctViableRoots.has(value) ? false : distinctViableRoots.add(value) && true);
|
|
303
295
|
let outputLibrary;
|
|
304
|
-
if (
|
|
305
|
-
if (Array.isArray(
|
|
296
|
+
if (externalize) {
|
|
297
|
+
if (Array.isArray(externalize) || typeof externalize === 'string') {
|
|
306
298
|
outputLibrary = {
|
|
307
|
-
name:
|
|
299
|
+
name: externalize,
|
|
308
300
|
type: "assign"
|
|
309
301
|
};
|
|
310
302
|
}
|
|
@@ -313,30 +305,17 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
313
305
|
if (originalLibrary && typeof originalLibrary === 'object' && !Array.isArray(originalLibrary)) {
|
|
314
306
|
outputLibrary = {
|
|
315
307
|
...originalLibrary,
|
|
316
|
-
...
|
|
308
|
+
...externalize
|
|
317
309
|
};
|
|
318
310
|
}
|
|
319
311
|
else {
|
|
320
|
-
outputLibrary =
|
|
312
|
+
outputLibrary = externalize;
|
|
321
313
|
}
|
|
322
314
|
}
|
|
323
315
|
}
|
|
324
316
|
else {
|
|
325
317
|
outputLibrary = webpackConfig.output?.library;
|
|
326
318
|
}
|
|
327
|
-
const canCopyFiles = srcIsDirectory && src !== dest.destination;
|
|
328
|
-
const possiblePlugins = canCopyFiles
|
|
329
|
-
? plugins.filter(plugin => plugin.constructor.name !== 'CleanWebpackPlugin')
|
|
330
|
-
.map(plugin => !processingModules && plugin.constructor.name === 'CopyPlugin'
|
|
331
|
-
? new copy_webpack_plugin_1.default({
|
|
332
|
-
patterns: [{
|
|
333
|
-
from: standaloneBlocks ? '**/*.(php|twig|svg)' : '**/*.(asset\.php|svg)',
|
|
334
|
-
to: dest.destination,
|
|
335
|
-
context: srcRoot /* canCopyFiles can only be true if srcRoot is a string, so this is safe */, noErrorOnMissing: true
|
|
336
|
-
}]
|
|
337
|
-
})
|
|
338
|
-
: plugin)
|
|
339
|
-
: plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin');
|
|
340
319
|
const extensions = processingModules ? ['.mjsx', '.mjs', '.mtsx', '.mts', '...'] : ['.jsx', '.tsx', '.ts', '...'];
|
|
341
320
|
return {
|
|
342
321
|
...webpackConfig,
|
|
@@ -348,7 +327,7 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
348
327
|
chunkFilename: 'webpack-chunks/[id].js',
|
|
349
328
|
publicPath: publicPath,
|
|
350
329
|
library: outputLibrary,
|
|
351
|
-
clean: false
|
|
330
|
+
clean: canClean ? webpackConfig.output?.clean : false
|
|
352
331
|
},
|
|
353
332
|
optimization: {
|
|
354
333
|
...webpackConfig.optimization,
|
|
@@ -382,13 +361,13 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
382
361
|
extensions
|
|
383
362
|
},
|
|
384
363
|
stats: config.stats,
|
|
385
|
-
plugins
|
|
364
|
+
plugins,
|
|
386
365
|
entry() {
|
|
387
366
|
if (variablesFilePath) {
|
|
388
367
|
delete require.cache[require.resolve(variablesFilePath)];
|
|
389
368
|
updateCurrentVariables(require(variablesFilePath));
|
|
390
369
|
}
|
|
391
|
-
return
|
|
370
|
+
return {};
|
|
392
371
|
},
|
|
393
372
|
performance: {
|
|
394
373
|
...webpackConfig.performance,
|
|
@@ -5,7 +5,7 @@ const make = (props = {}) => {
|
|
|
5
5
|
const linebreak = props.linebreak ?? '';
|
|
6
6
|
const indent = props.indent ?? '';
|
|
7
7
|
const stripSpaces = props.stripSpaces ?? false;
|
|
8
|
-
const shortArraySyntax = props.shortArraySyntax ??
|
|
8
|
+
const shortArraySyntax = props.shortArraySyntax ?? true;
|
|
9
9
|
const arrOpen = shortArraySyntax ? '[' : 'array(';
|
|
10
10
|
const arrClose = shortArraySyntax ? ']' : ')';
|
|
11
11
|
const arrow = stripSpaces ? '=>' : ' => ';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export declare class PseudoSemaphore<T> {
|
|
2
|
-
private readonly defaultValue;
|
|
3
2
|
private readonly name;
|
|
4
3
|
private flagSet;
|
|
5
4
|
private readonly flags;
|
|
6
5
|
private readonly debugMode;
|
|
7
|
-
constructor(
|
|
6
|
+
constructor(name: string);
|
|
8
7
|
register(id: string): void;
|
|
9
|
-
resolve(id: string, value: T): void;
|
|
8
|
+
resolve(id: string, value: T | undefined): void;
|
|
10
9
|
reject(id: string): void;
|
|
11
10
|
reset(id: string): void;
|
|
12
11
|
private getFlag;
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PseudoSemaphore = void 0;
|
|
4
4
|
class PseudoSemaphore {
|
|
5
|
-
defaultValue;
|
|
6
5
|
name;
|
|
7
6
|
flagSet = 0;
|
|
8
7
|
flags = new Map();
|
|
9
8
|
debugMode = false;
|
|
10
|
-
constructor(
|
|
11
|
-
this.defaultValue = defaultValue;
|
|
9
|
+
constructor(name) {
|
|
12
10
|
this.name = name;
|
|
13
11
|
}
|
|
14
12
|
register(id) {
|
|
@@ -16,7 +14,7 @@ class PseudoSemaphore {
|
|
|
16
14
|
throw new Error();
|
|
17
15
|
}
|
|
18
16
|
this.initializeFlag(id);
|
|
19
|
-
this.resolve(id,
|
|
17
|
+
this.resolve(id, undefined);
|
|
20
18
|
}
|
|
21
19
|
resolve(id, value) {
|
|
22
20
|
if (this.debugMode) {
|
|
@@ -67,7 +65,13 @@ class PseudoSemaphore {
|
|
|
67
65
|
let res;
|
|
68
66
|
do {
|
|
69
67
|
currentFlagSet = this.flagSet;
|
|
70
|
-
|
|
68
|
+
if (this.debugMode) {
|
|
69
|
+
console.log("WAITING FOR:", this.name, currentFlagSet);
|
|
70
|
+
}
|
|
71
|
+
res = (await Promise.all(this.flags.values().map(flag => flag[0]))).filter(r => r !== undefined);
|
|
72
|
+
if (this.debugMode) {
|
|
73
|
+
console.log("POSSIBLY FINISHED WAITING FOR:", this.name, currentFlagSet);
|
|
74
|
+
}
|
|
71
75
|
} while (currentFlagSet !== this.flagSet);
|
|
72
76
|
return res;
|
|
73
77
|
}
|