@plaudit/webpack-extensions 2.75.0 → 2.76.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +5 -13
- package/build/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +5 -5
- package/build/plugins/AbstractBiPhasicGroupPlugin.d.ts +2 -2
- package/build/plugins/AbstractBiPhasicGroupPlugin.js +1 -1
- package/build/plugins/{PlainEntrypointsStyleBlockJSONPlugin.d.ts → EnhancedBlockJSONPlugin.d.ts} +3 -3
- package/build/plugins/{PlainEntrypointsStyleBlockJSONPlugin.js → EnhancedBlockJSONPlugin.js} +24 -26
- package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +3 -1
- package/build/plugins/EnhancedDynamicEntryPlugin.js +3 -1
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +2 -2
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +2 -2
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +2 -2
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +2 -2
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +2 -2
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +3 -4
- package/build/plugins/UnifiedLoaderGenerator.js +4 -3
- package/build/shared.d.ts +15 -1
- package/build/shared.js +36 -0
- package/build/utils/common-config-helpers.d.ts +3 -3
- package/build/utils/common-config-helpers.js +7 -5
- package/build/wordpress-scripts-wrapper.js +8 -8
- package/package.json +2 -2
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MinimumViableMetadata, ParsedAssetJsonProvider, ParsedAssetsJson } from "../shared";
|
|
2
2
|
import type { ExtensibleEntryObject, VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
3
3
|
import { PseudoSemaphore } from "../utils/pseduo-semaphore";
|
|
4
4
|
import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
|
|
5
5
|
import { Compilation, Compiler, Entrypoint } from "webpack";
|
|
6
|
-
export type EntryProvider<M extends
|
|
7
|
-
|
|
8
|
-
} = {
|
|
9
|
-
dest: VerifiedAdvancedOutputConfig;
|
|
10
|
-
}> = () => ExtensibleEntryObject<M> | Promise<ExtensibleEntryObject<M>>;
|
|
11
|
-
export declare abstract class AbstractBiPhasicGroupAndEntryPlugin<M extends {
|
|
12
|
-
dest: VerifiedAdvancedOutputConfig;
|
|
13
|
-
} = {
|
|
14
|
-
dest: VerifiedAdvancedOutputConfig;
|
|
15
|
-
}> extends AbstractBiPhasicGroupPlugin {
|
|
6
|
+
export type EntryProvider<M extends MinimumViableMetadata = MinimumViableMetadata> = () => ExtensibleEntryObject<M> | Promise<ExtensibleEntryObject<M>>;
|
|
7
|
+
export declare abstract class AbstractBiPhasicGroupAndEntryPlugin<M extends MinimumViableMetadata = MinimumViableMetadata> extends AbstractBiPhasicGroupPlugin {
|
|
16
8
|
private readonly context;
|
|
17
9
|
private readonly entry;
|
|
18
10
|
private static readonly configuredCompilations;
|
|
@@ -28,6 +20,6 @@ export declare abstract class AbstractBiPhasicGroupAndEntryPlugin<M extends {
|
|
|
28
20
|
srcPath: string;
|
|
29
21
|
metadata: M;
|
|
30
22
|
}, undefined, unknown>;
|
|
31
|
-
protected abstract processAssets(compilation: Compilation,
|
|
32
|
-
protected extractRelevantAssetData(compilation: Compilation,
|
|
23
|
+
protected abstract processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): Promise<void> | void;
|
|
24
|
+
protected extractRelevantAssetData(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): ParsedAssetsJson;
|
|
33
25
|
}
|
|
@@ -70,15 +70,15 @@ class AbstractBiPhasicGroupAndEntryPlugin extends AbstractBiPhasicGroupPlugin_1.
|
|
|
70
70
|
})
|
|
71
71
|
.filter(item => item !== undefined);
|
|
72
72
|
}
|
|
73
|
-
extractRelevantAssetData(compilation,
|
|
73
|
+
extractRelevantAssetData(compilation, parsedAssetJsonProvider) {
|
|
74
74
|
const relevantAssetData = {};
|
|
75
|
-
for (const { entrypoint, srcPath } of this.getRelevantEntrypoints(compilation)) {
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
75
|
+
for (const { entrypoint, srcPath, metadata } of this.getRelevantEntrypoints(compilation)) {
|
|
76
|
+
const providedData = parsedAssetJsonProvider(entrypoint, metadata);
|
|
77
|
+
if (providedData === undefined) {
|
|
78
78
|
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
|
|
79
79
|
continue;
|
|
80
80
|
}
|
|
81
|
-
relevantAssetData[
|
|
81
|
+
relevantAssetData[providedData.assetName] = providedData.assetData;
|
|
82
82
|
}
|
|
83
83
|
return relevantAssetData;
|
|
84
84
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Compilation, Compiler, type WebpackPluginInstance } from "webpack";
|
|
2
2
|
import { PseudoSemaphore } from "../utils/pseduo-semaphore";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
|
-
import {
|
|
4
|
+
import { type ParsedAssetJsonProvider } from "../shared";
|
|
5
5
|
type TapWithAssetsJsonOptions = {
|
|
6
6
|
name?: string;
|
|
7
7
|
stage?: (typeof Compilation.PROCESS_ASSETS_STAGE_REPORT) | (typeof Compilation.PROCESS_ASSETS_STAGE_ANALYSE);
|
|
8
8
|
additionalAssets?: any;
|
|
9
9
|
};
|
|
10
10
|
type TapWithAssetsJsonFn = Parameters<Compilation['hooks']['processAssets']['tapPromise']>[1];
|
|
11
|
-
type TapWithParsedAssetsJsonFn = (
|
|
11
|
+
type TapWithParsedAssetsJsonFn = (parsedAssetJsonProvider: ParsedAssetJsonProvider, assets: Parameters<TapWithAssetsJsonFn>[0]) => Promise<void> | void;
|
|
12
12
|
export declare abstract class AbstractBiPhasicGroupPlugin implements WebpackPluginInstance {
|
|
13
13
|
protected readonly config: VerifiedPlauditWordpressWebpackConfig;
|
|
14
14
|
readonly group: string;
|
|
@@ -49,7 +49,7 @@ class AbstractBiPhasicGroupPlugin {
|
|
|
49
49
|
const { tap, earlyStage, fn } = this.extractTapAndFunction(fnOrOptions, fnIfOptions);
|
|
50
50
|
this.sharedTapLogicForAssetsJsonHelpers(compilation, { tap, earlyStage, fn: async (assets) => {
|
|
51
51
|
try {
|
|
52
|
-
await fn((0, shared_1.
|
|
52
|
+
await fn((entrypoint, dest) => (0, shared_1.getParsedAssetsJsonDataForEntrypoint)(compilation, entrypoint, dest), assets);
|
|
53
53
|
}
|
|
54
54
|
catch (e) {
|
|
55
55
|
console.error(e);
|
package/build/plugins/{PlainEntrypointsStyleBlockJSONPlugin.d.ts → EnhancedBlockJSONPlugin.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
-
import { ParsedAssetsJson, BlockEntrypointInfo, FileSegmentBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
|
|
2
|
+
import { ParsedAssetsJson, BlockEntrypointInfo, FileSegmentBlockEntrypointInfo, VerifiedAdvancedOutputConfig, ParsedAssetJsonProvider } 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";
|
|
@@ -13,12 +13,12 @@ type CollatedWorkableBlockInfo = Record<string, {
|
|
|
13
13
|
workableBlockEntrypointsInfo: WorkableBlockEntrypointInfo[];
|
|
14
14
|
blockJsonText?: string;
|
|
15
15
|
}>;
|
|
16
|
-
export declare class
|
|
16
|
+
export declare class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
|
|
17
17
|
private readonly dest;
|
|
18
18
|
private readonly webpackRemoveEmptyScriptsPlugin;
|
|
19
19
|
private static readonly semaphore;
|
|
20
20
|
constructor(config: VerifiedPlauditWordpressWebpackConfig, dest: VerifiedAdvancedOutputConfig, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<BlockEntrypointInfo>);
|
|
21
|
-
protected processAssets(compilation: Compilation,
|
|
21
|
+
protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): Promise<void>;
|
|
22
22
|
private emitBlockLoaderFile;
|
|
23
23
|
private transformBlocks;
|
|
24
24
|
private static extractAssetSource;
|
package/build/plugins/{PlainEntrypointsStyleBlockJSONPlugin.js → EnhancedBlockJSONPlugin.js}
RENAMED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.EnhancedBlockJSONPlugin = void 0;
|
|
7
7
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
8
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
9
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
@@ -15,16 +15,16 @@ const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
|
15
15
|
const shared_1 = require("../shared");
|
|
16
16
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
17
17
|
const webpack_1 = require("webpack");
|
|
18
|
-
class
|
|
18
|
+
class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
|
|
19
19
|
dest;
|
|
20
20
|
webpackRemoveEmptyScriptsPlugin;
|
|
21
21
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Block JSON v3");
|
|
22
22
|
constructor(config, dest, webpackRemoveEmptyScriptsPlugin, context, entry) {
|
|
23
|
-
super(config, `block-json-${dest.destination}`, [
|
|
23
|
+
super(config, `block-json-${dest.destination}`, [EnhancedBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
24
24
|
this.dest = dest;
|
|
25
25
|
this.webpackRemoveEmptyScriptsPlugin = webpackRemoveEmptyScriptsPlugin;
|
|
26
26
|
}
|
|
27
|
-
async processAssets(compilation,
|
|
27
|
+
async processAssets(compilation, parsedAssetJsonProvider) {
|
|
28
28
|
const applicableBlockJsonFiles = {};
|
|
29
29
|
const blockJsonOriginToOutputMapping = {};
|
|
30
30
|
const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
|
|
@@ -37,7 +37,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
37
37
|
//TODO: Can we guarantee that entrypoint.name is always non-null?
|
|
38
38
|
const epBlockJson = entrypoint.name + ".json";
|
|
39
39
|
if (!applicableBlockJsonFiles[epBlockJson]) {
|
|
40
|
-
const blockJsonText =
|
|
40
|
+
const blockJsonText = EnhancedBlockJSONPlugin.extractAssetSource(compilation, epBlockJson)
|
|
41
41
|
?? await promises_1.default.readFile(srcPath, 'utf-8');
|
|
42
42
|
if (!blockJsonText) {
|
|
43
43
|
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`Unable to extract the source for ${epBlockJson}`, srcPath));
|
|
@@ -56,9 +56,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
56
56
|
const epBlockJson = entrypointChunk.auxiliaryFiles.values().find(auxFile => node_path_1.default.basename(auxFile) === "block.json")
|
|
57
57
|
?? blockJsonOriginToOutputMapping[metadata.blockJsonOrigin];
|
|
58
58
|
if (epBlockJson) {
|
|
59
|
-
|
|
60
|
-
const assetData = entrypointChunk.files.values().map(file => rawAssetData[file])
|
|
61
|
-
.find(assetData => assetData !== undefined);
|
|
59
|
+
const assetData = parsedAssetJsonProvider(entrypoint, metadata)?.assetData;
|
|
62
60
|
if (!assetData) {
|
|
63
61
|
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
|
|
64
62
|
continue;
|
|
@@ -87,7 +85,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
|
-
|
|
88
|
+
EnhancedBlockJSONPlugin.semaphore.resolve(this.id, {
|
|
91
89
|
collatableWorkableBlockInfo: applicableBlockJsonFiles, blocksDest: this.dest.destination,
|
|
92
90
|
emittingWpmlXml: compilation.getAsset(node_path_1.default.join(this.dest.destination, "wpml-config.xml")) !== undefined
|
|
93
91
|
});
|
|
@@ -148,9 +146,9 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
148
146
|
const outputDir = node_path_1.default.join(compilation.compiler.outputPath, node_path_1.default.dirname(blockJsonAssetName));
|
|
149
147
|
const blockJson = JSON.parse(blockJsonText);
|
|
150
148
|
const pathsNeedRemapping = !this.config.standaloneBlocks && blockJson["plaudit"] !== "simple";
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const hashForVersion =
|
|
149
|
+
EnhancedBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "setup", pathsNeedRemapping, sourceDir, outputDir, compilation, true);
|
|
150
|
+
EnhancedBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "variations", pathsNeedRemapping, sourceDir, outputDir, compilation, false);
|
|
151
|
+
const hashForVersion = EnhancedBlockJSONPlugin
|
|
154
152
|
.hashThingForAsset([blockJsonText, ...workableBlockEntrypointsInfo.map(bi => bi.hash)].join("~"));
|
|
155
153
|
if (blockJson["version"]) {
|
|
156
154
|
blockJson["version"] = `${blockJson["version"]}-${hashForVersion}`;
|
|
@@ -158,20 +156,20 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
158
156
|
else {
|
|
159
157
|
blockJson["version"] = hashForVersion;
|
|
160
158
|
}
|
|
161
|
-
|
|
159
|
+
EnhancedBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
|
|
162
160
|
const blockDirName = node_path_1.default.dirname(node_path_1.default.relative(this.dest.destination, blockJsonAssetName));
|
|
163
|
-
blockData[blockDirName] =
|
|
161
|
+
blockData[blockDirName] = EnhancedBlockJSONPlugin
|
|
164
162
|
.doFileOrHandleReplacements(compilation, Object.fromEntries(Object.entries(blockJson).filter(([k]) => k !== '$schema')), workableBlockEntrypointsInfo, epi => epi.handle);
|
|
165
|
-
compilation[blockJsonAssetName in compilation.assets ? 'updateAsset' : 'emitAsset'](blockJsonAssetName, new webpack_1.sources.RawSource(JSON.stringify(
|
|
163
|
+
compilation[blockJsonAssetName in compilation.assets ? 'updateAsset' : 'emitAsset'](blockJsonAssetName, new webpack_1.sources.RawSource(JSON.stringify(EnhancedBlockJSONPlugin
|
|
166
164
|
.doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, epi => "file:./" + node_path_1.default.relative(blockDirName, epi.outputPath)), undefined, " ")));
|
|
167
165
|
}
|
|
168
166
|
return {
|
|
169
167
|
__metadata: {
|
|
170
168
|
version: 3,
|
|
171
169
|
"wpml-config": emittingWpmlXml,
|
|
172
|
-
scriptHandles: Object.fromEntries(
|
|
170
|
+
scriptHandles: Object.fromEntries(EnhancedBlockJSONPlugin
|
|
173
171
|
.convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && !(0, shared_1.isScriptModuleField)(hd.entrypointField)))),
|
|
174
|
-
scriptModuleHandles: Object.fromEntries(
|
|
172
|
+
scriptModuleHandles: Object.fromEntries(EnhancedBlockJSONPlugin
|
|
175
173
|
.convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && (0, shared_1.isScriptModuleField)(hd.entrypointField)))),
|
|
176
174
|
styleHandles: Object.fromEntries(handleData.filter(hd => (0, shared_1.isStyleField)(hd.entrypointField))
|
|
177
175
|
.map(hd => {
|
|
@@ -252,7 +250,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
252
250
|
});
|
|
253
251
|
}
|
|
254
252
|
static findRelativeRouteBetween(path1, path2) {
|
|
255
|
-
const commonAncestor =
|
|
253
|
+
const commonAncestor = EnhancedBlockJSONPlugin.findCommonAncestor(path1, path2);
|
|
256
254
|
const route = Array(path1.split(node_path_1.default.sep).length - commonAncestor.length).fill("..");
|
|
257
255
|
route.push(node_path_1.default.relative(commonAncestor.join(node_path_1.default.sep), path2));
|
|
258
256
|
return route.join(node_path_1.default.sep);
|
|
@@ -288,11 +286,11 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
288
286
|
}
|
|
289
287
|
const mappedFiles = pathsNeedRemapping
|
|
290
288
|
? rawFiles
|
|
291
|
-
.map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir,
|
|
289
|
+
.map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
|
|
292
290
|
.filter(p => node_fs_1.default.existsSync(p))
|
|
293
|
-
.map(p => `file:./${
|
|
291
|
+
.map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
|
|
294
292
|
: rawFiles
|
|
295
|
-
.filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir,
|
|
293
|
+
.filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
|
|
296
294
|
if (mappedFiles.length === 0) {
|
|
297
295
|
if (deleteOnEmpty && rawValue !== undefined) {
|
|
298
296
|
delete (inPlaudit ? blockJson["plaudit"] : blockJson)[key];
|
|
@@ -328,11 +326,11 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
328
326
|
: [`${blockName.substring(blockName.indexOf('/') + 1)}.php`, "template.php", "template.twig"]);
|
|
329
327
|
const renderTemplate = pathsNeedRemapping
|
|
330
328
|
? rawRenderTemplate
|
|
331
|
-
.map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir,
|
|
329
|
+
.map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
|
|
332
330
|
.filter(p => node_fs_1.default.existsSync(p))
|
|
333
|
-
.map(p => `file:./${
|
|
331
|
+
.map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
|
|
334
332
|
: rawRenderTemplate
|
|
335
|
-
.filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir,
|
|
333
|
+
.filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
|
|
336
334
|
if (renderTemplate.length === 0) {
|
|
337
335
|
delete blockJson["render_template"];
|
|
338
336
|
delete blockJson["render"];
|
|
@@ -361,7 +359,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
361
359
|
}
|
|
362
360
|
attachUniquePhase(compilation) {
|
|
363
361
|
compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
364
|
-
const allSemaphoreData = (await
|
|
362
|
+
const allSemaphoreData = (await EnhancedBlockJSONPlugin.semaphore.wait())
|
|
365
363
|
.reduce((acc, cur) => {
|
|
366
364
|
(acc[cur.blocksDest] ?? (acc[cur.blocksDest] = [])).push(cur);
|
|
367
365
|
return acc;
|
|
@@ -434,4 +432,4 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
|
|
|
434
432
|
}));
|
|
435
433
|
}
|
|
436
434
|
}
|
|
437
|
-
exports.
|
|
435
|
+
exports.EnhancedBlockJSONPlugin = EnhancedBlockJSONPlugin;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { Compilation } from "webpack";
|
|
1
2
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
|
+
import { ParsedAssetJsonProvider } from "../shared";
|
|
3
5
|
export declare class EnhancedDynamicEntryPlugin extends AbstractBiPhasicGroupAndEntryPlugin {
|
|
4
6
|
constructor(config: VerifiedPlauditWordpressWebpackConfig, context: string, entry: EntryProvider);
|
|
5
7
|
protected attachUniquePhase(): void;
|
|
6
|
-
protected processAssets(): void;
|
|
8
|
+
protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
|
|
7
9
|
}
|
|
@@ -7,6 +7,8 @@ class EnhancedDynamicEntryPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.A
|
|
|
7
7
|
super(config, `enhanced-dynamic-entries`, [], context, entry);
|
|
8
8
|
}
|
|
9
9
|
attachUniquePhase() { }
|
|
10
|
-
processAssets() {
|
|
10
|
+
processAssets(compilation, parsedAssetJsonProvider) {
|
|
11
|
+
this.extractRelevantAssetData(compilation, parsedAssetJsonProvider);
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
exports.EnhancedDynamicEntryPlugin = EnhancedDynamicEntryPlugin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
-
import {
|
|
2
|
+
import { ParsedAssetJsonProvider, VerifiedAdvancedOutputConfig } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
4
|
import { Compilation, type Compiler } from "webpack";
|
|
5
5
|
export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin {
|
|
@@ -12,5 +12,5 @@ export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasi
|
|
|
12
12
|
apply(compiler: Compiler): void;
|
|
13
13
|
private generateVersionThreeConfigFile;
|
|
14
14
|
protected attachUniquePhase(compilation: Compilation): void;
|
|
15
|
-
protected processAssets(compilation: Compilation,
|
|
15
|
+
protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
|
|
16
16
|
}
|
|
@@ -126,8 +126,8 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
-
processAssets(compilation,
|
|
130
|
-
const relevantAssetData = this.extractRelevantAssetData(compilation,
|
|
129
|
+
processAssets(compilation, parsedAssetJsonProvider) {
|
|
130
|
+
const relevantAssetData = this.extractRelevantAssetData(compilation, parsedAssetJsonProvider);
|
|
131
131
|
const staticallyLoadedEntrypoints = Object.keys(relevantAssetData);
|
|
132
132
|
const generateLoader = (writer) => {
|
|
133
133
|
writer.require(this.extensionsDestPath + "extensions-loader.php", { dirRelative: true, once: true });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
-
import
|
|
2
|
+
import { ParsedAssetJsonProvider } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
4
|
import { Compilation } from "webpack";
|
|
5
5
|
export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin {
|
|
6
6
|
private readonly extensionsDest;
|
|
7
7
|
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsDest: string, context: string, entry: EntryProvider);
|
|
8
8
|
protected attachUniquePhase(): void;
|
|
9
|
-
protected processAssets(compilation: Compilation,
|
|
9
|
+
protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
|
|
10
10
|
}
|
|
@@ -17,10 +17,10 @@ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntr
|
|
|
17
17
|
this.extensionsDest = extensionsDest;
|
|
18
18
|
}
|
|
19
19
|
attachUniquePhase() { }
|
|
20
|
-
processAssets(compilation,
|
|
20
|
+
processAssets(compilation, parsedAssetJsonProvider) {
|
|
21
21
|
const regex = /^(.+?)-((?<prefix>editor-|view-|)(?<type>style|script|script-module))\.(?<extension>css|m?js)$/i;
|
|
22
22
|
const mapping = {};
|
|
23
|
-
for (let fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation,
|
|
23
|
+
for (let fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation, parsedAssetJsonProvider))) {
|
|
24
24
|
let match;
|
|
25
25
|
if ((match = regex.exec(fileWithAssetData)) && match[1] && match[2]) {
|
|
26
26
|
if (match.groups?.['type'] === 'style' && match.groups['extension'] !== 'css') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockEntrypointInfo, UsageLocations, ParsedAssetJsonProvider } from "../shared";
|
|
2
2
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
3
3
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
4
4
|
import { Compilation } from "webpack";
|
|
@@ -14,5 +14,5 @@ export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractB
|
|
|
14
14
|
private static appendEnqueuingHandleLists;
|
|
15
15
|
private static separateHandleListByPriority;
|
|
16
16
|
protected attachUniquePhase(compilation: Compilation): void;
|
|
17
|
-
protected processAssets(compilation: Compilation,
|
|
17
|
+
protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
|
|
18
18
|
}
|
|
@@ -139,14 +139,13 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
139
139
|
this.generatePlainEntrypointsLoader(compilation, (await PlainEntrypointsConfigFileGeneratorPlugin.semaphore.wait()).flat());
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
-
processAssets(compilation,
|
|
142
|
+
processAssets(compilation, parsedAssetJsonProvider) {
|
|
143
143
|
const isScriptRegex = /\.m?[jt]sx?(\?|$)/i;
|
|
144
144
|
const myAssetHandles = [];
|
|
145
145
|
const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
|
|
146
|
-
for (const { entrypoint, srcPath } of relevantEntrypoints) {
|
|
146
|
+
for (const { entrypoint, srcPath, metadata } of relevantEntrypoints) {
|
|
147
147
|
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
148
|
-
const assetData =
|
|
149
|
-
.map(file => assetsJson[file]).find(v => v !== undefined);
|
|
148
|
+
const assetData = parsedAssetJsonProvider(entrypoint, metadata)?.assetData;
|
|
150
149
|
if (!assetData) {
|
|
151
150
|
continue;
|
|
152
151
|
}
|
|
@@ -21,7 +21,7 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
attachUniquePhase(compilation) {
|
|
24
|
-
this.
|
|
24
|
+
this.tapRequiringAssetsJson(compilation, { stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
|
|
25
25
|
const groupedLoaderInfo = Object.values((await UnifiedLoaderGenerator.semaphore.wait())
|
|
26
26
|
.reduce((acc, cur) => {
|
|
27
27
|
const accValue = acc[cur.group];
|
|
@@ -47,13 +47,14 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
|
|
|
47
47
|
return ap === bp ? a.group.localeCompare(b.group) : bp - ap;
|
|
48
48
|
});
|
|
49
49
|
const staticallyLoadedEntrypoints = new Set(groupedLoaderInfo.flatMap(lig => lig.staticallyLoadedEntrypoints));
|
|
50
|
-
for (const [file, assetData] of Object.entries(
|
|
50
|
+
for (const [file, assetData] of Object.entries((0, shared_1.getAssetsJson)(compilation))) {
|
|
51
51
|
if (staticallyLoadedEntrypoints.has(file)) {
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
54
54
|
const parsedPath = node_path_1.default.parse(file);
|
|
55
55
|
const contents = `<?php return ${(0, php_writer_1.json2php)(assetData)};\n`;
|
|
56
|
-
|
|
56
|
+
const assetName = node_path_1.default.join(parsedPath.dir, parsedPath.name) + ".asset.php";
|
|
57
|
+
compilation[assetName in compilation.assets ? 'updateAsset' : 'emitAsset'](assetName, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
57
58
|
}
|
|
58
59
|
if (this.config.useUnifiedLoader) {
|
|
59
60
|
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
package/build/shared.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PHPWriter } from "@plaudit/php-writer";
|
|
2
2
|
import type { Options as PostcssFunctionsOptions } from "postcss-functions";
|
|
3
|
-
import { AssetInfo, Compilation, type Configuration, WebpackError } from "webpack";
|
|
3
|
+
import { AssetInfo, Compilation, type Configuration, Entrypoint, WebpackError } from "webpack";
|
|
4
4
|
export type ParsedAssetsJson = Record<string, {
|
|
5
5
|
dependencies: string[];
|
|
6
6
|
version: string;
|
|
@@ -113,10 +113,16 @@ export type FileSegmentBlockEntrypointInfo = {
|
|
|
113
113
|
entrypointName: string;
|
|
114
114
|
handle: string;
|
|
115
115
|
dest: VerifiedAdvancedOutputConfig;
|
|
116
|
+
absoluteSrc: string;
|
|
116
117
|
};
|
|
117
118
|
export type BlockEntrypointInfo = FileSegmentBlockEntrypointInfo | {
|
|
118
119
|
dest: VerifiedAdvancedOutputConfig;
|
|
119
120
|
purpose: string;
|
|
121
|
+
absoluteSrc: string;
|
|
122
|
+
};
|
|
123
|
+
export type MinimumViableMetadata = {
|
|
124
|
+
dest: VerifiedAdvancedOutputConfig;
|
|
125
|
+
absoluteSrc: string;
|
|
120
126
|
};
|
|
121
127
|
export declare function convertUsageLocationsHandleToEmittableHandle(handle: UsageLocations['handle'], generatedHandle: string): string;
|
|
122
128
|
export declare function makeEmittableConfigPHP(data: any, asFullFile: boolean, parentIndent?: string): string;
|
|
@@ -145,6 +151,14 @@ export declare function newWebpackErrorForFile(error: string | ConstructorParame
|
|
|
145
151
|
*/
|
|
146
152
|
export declare function emitResolveBaseUriFunction(writer: PHPWriter): void;
|
|
147
153
|
export declare function getAssetsJson(compilation: Compilation): ParsedAssetsJson;
|
|
154
|
+
export type ParsedAssetJsonProvider = (entrypoint: Entrypoint, metadata: MinimumViableMetadata) => {
|
|
155
|
+
assetName: string;
|
|
156
|
+
assetData: ParsedAssetsJson[string];
|
|
157
|
+
} | undefined;
|
|
158
|
+
export declare function getParsedAssetsJsonDataForEntrypoint(compilation: Compilation, entrypoint: Entrypoint, metadata: MinimumViableMetadata): {
|
|
159
|
+
assetName: string;
|
|
160
|
+
assetData: ParsedAssetsJson[string];
|
|
161
|
+
} | undefined;
|
|
148
162
|
export declare function emitPHPWriterAsAsset(writer: PHPWriter, compilation: Compilation, file: string, assetInfo?: AssetInfo): void;
|
|
149
163
|
export declare function dedent(text: TemplateStringsArray): string;
|
|
150
164
|
export declare function resolveLegacyBlockScriptsInFolder(folder: string): string[];
|
package/build/shared.js
CHANGED
|
@@ -24,6 +24,7 @@ exports.parseEnvFile = parseEnvFile;
|
|
|
24
24
|
exports.newWebpackErrorForFile = newWebpackErrorForFile;
|
|
25
25
|
exports.emitResolveBaseUriFunction = emitResolveBaseUriFunction;
|
|
26
26
|
exports.getAssetsJson = getAssetsJson;
|
|
27
|
+
exports.getParsedAssetsJsonDataForEntrypoint = getParsedAssetsJsonDataForEntrypoint;
|
|
27
28
|
exports.emitPHPWriterAsAsset = emitPHPWriterAsAsset;
|
|
28
29
|
exports.dedent = dedent;
|
|
29
30
|
exports.resolveLegacyBlockScriptsInFolder = resolveLegacyBlockScriptsInFolder;
|
|
@@ -183,6 +184,41 @@ function getAssetsJson(compilation) {
|
|
|
183
184
|
compilation.updateAsset("assets.json", s => s, a => ({ ...a, "parsed-assets-json": parsedAssetJson }));
|
|
184
185
|
return parsedAssetJson;
|
|
185
186
|
}
|
|
187
|
+
function getParsedAssetsJsonDataForEntrypoint(compilation, entrypoint, metadata) {
|
|
188
|
+
const dest = metadata.dest;
|
|
189
|
+
const parsedAssetJson = getAssetsJson(compilation);
|
|
190
|
+
const scriptExtension = compilation.outputOptions.module ? exports.scriptWithModuleExtension : exports.scriptWithoutModuleExtension;
|
|
191
|
+
const assetType = scriptOrStyleTest(metadata.absoluteSrc, scriptExtension);
|
|
192
|
+
const chunkFiles = [dest.destination, ...entrypoint.chunks.flatMap(chunk => Array.from(chunk.files))]
|
|
193
|
+
.filter(chunkFile => scriptOrStyleTest(chunkFile, scriptExtension) === assetType);
|
|
194
|
+
for (const chunkFile of chunkFiles) {
|
|
195
|
+
if (parsedAssetJson[chunkFile]) {
|
|
196
|
+
return { assetName: chunkFile, assetData: parsedAssetJson[chunkFile] };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (assetType !== 'style' || !hasAtLeastOneItem(chunkFiles)) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
// The rest of this function is a modified version of the hash-computing logic from @wordpress/dependency-extraction-webpack-plugin
|
|
203
|
+
const { hashFunction, hashDigest, hashDigestLength } = compilation.outputOptions;
|
|
204
|
+
const hashBuilder = webpack_1.util.createHash(hashFunction);
|
|
205
|
+
for (const chunkFile of chunkFiles.toSorted()) {
|
|
206
|
+
const source = compilation.getAsset(chunkFile)?.source.buffer();
|
|
207
|
+
if (source !== undefined) {
|
|
208
|
+
hashBuilder.update(source);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Finalise hash.
|
|
212
|
+
const contentHash = hashBuilder
|
|
213
|
+
.digest(hashDigest)
|
|
214
|
+
.slice(0, hashDigestLength);
|
|
215
|
+
const assetData = {
|
|
216
|
+
dependencies: [],
|
|
217
|
+
version: contentHash,
|
|
218
|
+
};
|
|
219
|
+
compilation.updateAsset("assets.json", s => s, a => ({ ...a, "parsed-assets-json": { ...parsedAssetJson, [chunkFiles[0]]: assetData } }));
|
|
220
|
+
return { assetName: chunkFiles[0], assetData };
|
|
221
|
+
}
|
|
186
222
|
function emitPHPWriterAsAsset(writer, compilation, file, assetInfo) {
|
|
187
223
|
const contents = writer.toString() + "\n";
|
|
188
224
|
compilation[file in compilation.assets ? 'updateAsset' : 'emitAsset'](file, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents), ...assetInfo });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "../plugins/AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
2
|
import type { AdditionalDependencyInjectorPlugin } from "../plugins/AdditionalDependencyInjectorPlugin";
|
|
3
|
-
import { EntrypointFields, PlauditWordpressWebpackConfig, BlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
|
|
3
|
+
import { EntrypointFields, PlauditWordpressWebpackConfig, BlockEntrypointInfo, VerifiedAdvancedOutputConfig, MinimumViableMetadata } from "../shared";
|
|
4
4
|
import type { Compiler, Configuration, DynamicEntryPlugin, WebpackPluginInstance } from "webpack";
|
|
5
5
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
6
6
|
export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpressWebpackConfig, 'variables' | 'src' | 'externals'>> & {
|
|
@@ -23,9 +23,9 @@ export declare function joinPossiblyAbsolutePaths(...paths: (string | undefined)
|
|
|
23
23
|
export declare function groupEntrypointsByAssetFile<T>(entrypoints: T[], entrypointNameExtractor: (t: T) => string): Map<string, T[]>;
|
|
24
24
|
export type BlockJsonExtensibleEntryObject = ExtensibleEntryObject<BlockEntrypointInfo>;
|
|
25
25
|
export type EntryStaticNormalized = Awaited<ReturnType<ConstructorParameters<typeof DynamicEntryPlugin>[1]>>;
|
|
26
|
-
export type ExtensibleEntryObject<M> = {
|
|
26
|
+
export type ExtensibleEntryObject<M extends object = {}> = {
|
|
27
27
|
[index: string]: Omit<EntryStaticNormalized[string], 'import'> & Required<NonNullable<Pick<EntryStaticNormalized[string], 'import'>>> & {
|
|
28
|
-
plauditMetadata: M;
|
|
28
|
+
plauditMetadata: M & MinimumViableMetadata;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): EntryProvider<BlockEntrypointInfo>;
|
|
@@ -47,7 +47,8 @@ function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
|
|
|
47
47
|
entrypointName: parsedEntrypoint.name,
|
|
48
48
|
handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name),
|
|
49
49
|
handleGroup: (0, shared_1.getHandleGroup)(entrypointField),
|
|
50
|
-
dest
|
|
50
|
+
dest,
|
|
51
|
+
absoluteSrc: ep
|
|
51
52
|
};
|
|
52
53
|
return [joinPossiblyAbsolutePaths(dest.destination, node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name),
|
|
53
54
|
{ import: [ep], plauditMetadata: fakeEntrypointInfo }];
|
|
@@ -198,7 +199,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
198
199
|
}
|
|
199
200
|
];
|
|
200
201
|
}));
|
|
201
|
-
rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: { purpose: "block-json-inclusion-assurance", dest } }]);
|
|
202
|
+
rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: { purpose: "block-json-inclusion-assurance", dest, absoluteSrc: blockJsonOrigin } }]);
|
|
202
203
|
wpmlFiles.push(node_path_1.default.join(dir, 'block.json'));
|
|
203
204
|
}
|
|
204
205
|
catch (e) {
|
|
@@ -250,14 +251,15 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
250
251
|
}
|
|
251
252
|
if (!processingModules) {
|
|
252
253
|
const wpmlEntrypointFiles = allEntrypoints.flatMap(e => e[1]);
|
|
254
|
+
const absoluteSrc = node_path_1.default.join(srcRoot, "wpml-config.xml");
|
|
253
255
|
try {
|
|
254
|
-
await promises_1.default.access(
|
|
255
|
-
currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: { purpose: "wpml-config-xml", dest } };
|
|
256
|
+
await promises_1.default.access(absoluteSrc);
|
|
257
|
+
currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: { purpose: "wpml-config-xml", dest, absoluteSrc } };
|
|
256
258
|
}
|
|
257
259
|
catch (e) {
|
|
258
260
|
// If the wpml-config.xml file does not exist, just "import" the other files that will be used to build the emitted version
|
|
259
261
|
if (wpmlEntrypointFiles.length) {
|
|
260
|
-
currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: { purpose: "wpml-config-xml", dest } };
|
|
262
|
+
currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: { purpose: "wpml-config-xml", dest, absoluteSrc } };
|
|
261
263
|
}
|
|
262
264
|
}
|
|
263
265
|
}
|
|
@@ -16,7 +16,7 @@ const ExtensionsConfigFileGeneratorPluginV1_1 = require("./plugins/ExtensionsCon
|
|
|
16
16
|
const MiniCSSExtractPluginErrorCleaner_1 = require("./plugins/MiniCSSExtractPluginErrorCleaner");
|
|
17
17
|
const PackageConfigSanityChecker_1 = require("./plugins/PackageConfigSanityChecker");
|
|
18
18
|
const PlainEntrypointsConfigFileGeneratorPlugin_1 = require("./plugins/PlainEntrypointsConfigFileGeneratorPlugin");
|
|
19
|
-
const
|
|
19
|
+
const EnhancedBlockJSONPlugin_1 = require("./plugins/EnhancedBlockJSONPlugin");
|
|
20
20
|
const SpecialAssetHandlingPlugin_1 = require("./plugins/SpecialAssetHandlingPlugin");
|
|
21
21
|
const VariablesJSMonitorPlugin_1 = require("./plugins/VariablesJSMonitorPlugin");
|
|
22
22
|
const WPMLConfigBuilder_1 = require("./plugins/WPMLConfigBuilder");
|
|
@@ -479,7 +479,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
|
|
|
479
479
|
if (!srcIsDirectory) {
|
|
480
480
|
continue;
|
|
481
481
|
}
|
|
482
|
-
plugin = new
|
|
482
|
+
plugin = new EnhancedBlockJSONPlugin_1.EnhancedBlockJSONPlugin(config, dest, removeEmptyScriptsPlugin, contextPath, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
|
|
483
483
|
plugins.push(plugin);
|
|
484
484
|
if (config.processTranslationConfigs && !processingModules) {
|
|
485
485
|
plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination, plugin));
|
|
@@ -494,8 +494,8 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
|
|
|
494
494
|
for await (const dirent of await promises_1.default.opendir(srcRoot)) {
|
|
495
495
|
if (dirent.isFile() && !dirent.name.startsWith("~")) {
|
|
496
496
|
if (commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name)) {
|
|
497
|
-
const
|
|
498
|
-
rawEntrypoints.push([node_path_1.default.join(dest.destination, node_path_1.default.basename(
|
|
497
|
+
const absoluteSrc = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
|
|
498
|
+
rawEntrypoints.push([node_path_1.default.join(dest.destination, node_path_1.default.basename(absoluteSrc, node_path_1.default.extname(absoluteSrc))), { import: [absoluteSrc], plauditMetadata: { dest, absoluteSrc } }]);
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
}
|
|
@@ -507,9 +507,9 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
|
|
|
507
507
|
plugins.push(plugin);
|
|
508
508
|
}
|
|
509
509
|
else if (sourceType === "plain" /* SourceType.plain */) {
|
|
510
|
+
const absoluteSrc = typeof srcRoot === 'string' ? srcRoot : srcRoot[0];
|
|
510
511
|
if (!srcIsDirectory) {
|
|
511
|
-
|
|
512
|
-
if (!scriptExtension.test(primarySrcRoot) && !shared_1.styleExtension.test(primarySrcRoot)) {
|
|
512
|
+
if (!scriptExtension.test(absoluteSrc) && !shared_1.styleExtension.test(absoluteSrc)) {
|
|
513
513
|
continue;
|
|
514
514
|
}
|
|
515
515
|
}
|
|
@@ -517,7 +517,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
|
|
|
517
517
|
if (config.plainEntrypointsVersion > 1) {
|
|
518
518
|
const entry = srcIsDirectory // This being true implies that srcRoot is not an array
|
|
519
519
|
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
|
|
520
|
-
: () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest } } });
|
|
520
|
+
: () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest, absoluteSrc } } });
|
|
521
521
|
plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest.locations, config.useUnifiedLoader, contextPath, entry);
|
|
522
522
|
}
|
|
523
523
|
else {
|
|
@@ -525,7 +525,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
|
|
|
525
525
|
console.error("Using directory mode with legacy plain entrypoint handling is not supported");
|
|
526
526
|
continue;
|
|
527
527
|
}
|
|
528
|
-
plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(config, contextPath, () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest } } }));
|
|
528
|
+
plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(config, contextPath, () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest, absoluteSrc } } }));
|
|
529
529
|
}
|
|
530
530
|
plugins.push(plugin);
|
|
531
531
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.76.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"/build"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"webpack-bundle-analyzer": "^4.10.2"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@plaudit/php-writer": "^1.3.
|
|
36
|
+
"@plaudit/php-writer": "^1.3.2",
|
|
37
37
|
"@plaudit/postcss-color-function": "^5.0.0",
|
|
38
38
|
"@plaudit/postcss-legacy-shorthand": "^1.0.0",
|
|
39
39
|
"@plaudit/postcss-silent-extend": "^3.0.0",
|