@plaudit/webpack-extensions 2.63.0 → 2.63.2
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 +19 -0
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.js +62 -0
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +0 -6
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +0 -68
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +4 -4
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +6 -6
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +4 -4
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +5 -9
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +4 -3
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +21 -29
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +1 -1
- package/build/plugins/SpecialAssetHandlingPlugin.js +1 -1
- package/build/utils/common-config-helpers.d.ts +12 -4
- package/build/utils/common-config-helpers.js +22 -22
- package/build/wordpress-scripts-wrapper.js +39 -23
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PseudoSemaphore } from "../utils/pseduo-semaphore";
|
|
2
|
+
import type { ExtensibleEntryObject } from "../utils/common-config-helpers";
|
|
3
|
+
import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
|
|
4
|
+
import { Compilation, Compiler, Entrypoint } from "webpack";
|
|
5
|
+
export type EntryProvider<M> = () => ExtensibleEntryObject<M> | Promise<ExtensibleEntryObject<M>>;
|
|
6
|
+
export declare abstract class AbstractMultiPhaseLibraryAndEntryPlugin<M> extends AbstractMultiPhaseLibraryPlugin {
|
|
7
|
+
private readonly context;
|
|
8
|
+
private readonly entry;
|
|
9
|
+
protected readonly entryMetadataRecord: {
|
|
10
|
+
[entryName: string]: M;
|
|
11
|
+
};
|
|
12
|
+
protected constructor(libraryType: string, semaphores: PseudoSemaphore<any>[], context: string, entry: EntryProvider<M>);
|
|
13
|
+
apply(compiler: Compiler): void;
|
|
14
|
+
protected getRelevantEntrypoints(compilation: Compilation): {
|
|
15
|
+
entrypoint: Entrypoint;
|
|
16
|
+
srcPath: string;
|
|
17
|
+
metadata: M;
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractMultiPhaseLibraryAndEntryPlugin = void 0;
|
|
4
|
+
const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
|
|
5
|
+
const webpack_1 = require("webpack");
|
|
6
|
+
class AbstractMultiPhaseLibraryAndEntryPlugin extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
|
|
7
|
+
context;
|
|
8
|
+
entry;
|
|
9
|
+
entryMetadataRecord = {};
|
|
10
|
+
constructor(libraryType, semaphores, context, entry) {
|
|
11
|
+
super(libraryType, semaphores);
|
|
12
|
+
this.context = context;
|
|
13
|
+
this.entry = entry;
|
|
14
|
+
}
|
|
15
|
+
apply(compiler) {
|
|
16
|
+
super.apply(compiler);
|
|
17
|
+
compiler.hooks.compilation.tap(this.constructor.name, (compilation, { normalModuleFactory }) => {
|
|
18
|
+
const dummyEntry = webpack_1.EntryPlugin.createDependency("", "");
|
|
19
|
+
compilation.dependencyFactories.set(dummyEntry.constructor, normalModuleFactory);
|
|
20
|
+
});
|
|
21
|
+
compiler.hooks.make.tapPromise(this.constructor.name, async (compilation) => {
|
|
22
|
+
const entry = await this.entry();
|
|
23
|
+
const promises = [];
|
|
24
|
+
for (const [name, { plauditMetadata, ...desc }] of Object.entries(entry)) {
|
|
25
|
+
const options = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, name, desc);
|
|
26
|
+
this.entryMetadataRecord[name] = plauditMetadata;
|
|
27
|
+
for (const entry of desc.import) {
|
|
28
|
+
promises.push(new Promise((resolve, reject) => {
|
|
29
|
+
compilation.addEntry(this.context, webpack_1.EntryPlugin.createDependency(entry, options), options, err => {
|
|
30
|
+
if (err) {
|
|
31
|
+
return reject(err);
|
|
32
|
+
}
|
|
33
|
+
resolve();
|
|
34
|
+
});
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
await Promise.all(promises);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
getRelevantEntrypoints(compilation) {
|
|
42
|
+
return compilation.entrypoints.values()
|
|
43
|
+
.map(entrypoint => {
|
|
44
|
+
const name = entrypoint.name;
|
|
45
|
+
if (!name) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const metadata = this.entryMetadataRecord[name];
|
|
49
|
+
if (metadata === undefined) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const srcPath = entrypoint.origins[0]?.request;
|
|
53
|
+
if (!srcPath) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return { entrypoint, srcPath, metadata };
|
|
57
|
+
})
|
|
58
|
+
.filter(item => item !== undefined)
|
|
59
|
+
.toArray();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.AbstractMultiPhaseLibraryAndEntryPlugin = AbstractMultiPhaseLibraryAndEntryPlugin;
|
|
@@ -11,10 +11,4 @@ export declare abstract class AbstractMultiPhaseLibraryPlugin implements Webpack
|
|
|
11
11
|
apply(compiler: Compiler): void;
|
|
12
12
|
protected resetSemaphores(): void;
|
|
13
13
|
protected abstract attachSecondPhase(compilation: Compilation): void;
|
|
14
|
-
protected getRelevantEntrypoints(compilation: Compilation): {
|
|
15
|
-
entrypoint: import("webpack").Entrypoint;
|
|
16
|
-
entrypointChunk: import("webpack").Chunk;
|
|
17
|
-
entrypointLibrary: import("webpack").LibraryOptions;
|
|
18
|
-
srcPath: string;
|
|
19
|
-
}[];
|
|
20
14
|
}
|
|
@@ -27,79 +27,11 @@ class AbstractMultiPhaseLibraryPlugin {
|
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
|
-
// compiler.hooks.compilation.tap(
|
|
31
|
-
// this.constructor.name,
|
|
32
|
-
// (compilation, { normalModuleFactory }) => {
|
|
33
|
-
// const dummyEntry = EntryPlugin.createDependency("", "");
|
|
34
|
-
// compilation.dependencyFactories.set(
|
|
35
|
-
// dummyEntry.constructor as any,
|
|
36
|
-
// normalModuleFactory
|
|
37
|
-
// );
|
|
38
|
-
// }
|
|
39
|
-
// );
|
|
40
|
-
//
|
|
41
|
-
// compiler.hooks.make.tapPromise(this.constructor.name, (compilation) =>
|
|
42
|
-
// Promise.resolve(this.entry())
|
|
43
|
-
// .then((entry) => {
|
|
44
|
-
// const promises = [];
|
|
45
|
-
// for (const name of Object.keys(entry)) {
|
|
46
|
-
// const desc = entry[name];
|
|
47
|
-
// const options = EntryOptionPlugin.entryDescriptionToOptions(
|
|
48
|
-
// compiler,
|
|
49
|
-
// name,
|
|
50
|
-
// desc
|
|
51
|
-
// );
|
|
52
|
-
// for (const entry of /** @type {NonNullable<EntryDescriptionNormalized["import"]>} */ (
|
|
53
|
-
// desc.import
|
|
54
|
-
// )) {
|
|
55
|
-
// promises.push(
|
|
56
|
-
// new Promise(
|
|
57
|
-
// /**
|
|
58
|
-
// * @param {(value?: undefined) => void} resolve resolve
|
|
59
|
-
// * @param {(reason?: Error) => void} reject reject
|
|
60
|
-
// */
|
|
61
|
-
// (resolve, reject) => {
|
|
62
|
-
// compilation.addEntry(
|
|
63
|
-
// this.context,
|
|
64
|
-
// EntryPlugin.createDependency(entry, options),
|
|
65
|
-
// options,
|
|
66
|
-
// (err) => {
|
|
67
|
-
// if (err) return reject(err);
|
|
68
|
-
// resolve();
|
|
69
|
-
// }
|
|
70
|
-
// );
|
|
71
|
-
// }
|
|
72
|
-
// )
|
|
73
|
-
// );
|
|
74
|
-
// }
|
|
75
|
-
// }
|
|
76
|
-
// return Promise.all(promises);
|
|
77
|
-
// })
|
|
78
|
-
// .then(() => {})
|
|
79
|
-
// );
|
|
80
30
|
}
|
|
81
|
-
// protected abstract generateEntries(compiler: Compiler, context: string, entry: EntryStaticNormalized): void;
|
|
82
31
|
resetSemaphores() {
|
|
83
32
|
for (const semaphore of this.semaphores) {
|
|
84
33
|
semaphore.reset(this.id);
|
|
85
34
|
}
|
|
86
35
|
}
|
|
87
|
-
getRelevantEntrypoints(compilation) {
|
|
88
|
-
return compilation.entrypoints.values()
|
|
89
|
-
.map(entrypoint => {
|
|
90
|
-
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
91
|
-
const entrypointLibrary = entrypointChunk.getEntryOptions()?.library;
|
|
92
|
-
if (entrypointLibrary?.type !== this.libraryType) {
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
const srcPath = entrypoint.origins[0]?.request;
|
|
96
|
-
if (!srcPath) {
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
return { entrypoint, entrypointChunk, entrypointLibrary, srcPath };
|
|
100
|
-
})
|
|
101
|
-
.filter(item => item !== undefined)
|
|
102
|
-
.toArray();
|
|
103
|
-
}
|
|
104
36
|
}
|
|
105
37
|
exports.AbstractMultiPhaseLibraryPlugin = AbstractMultiPhaseLibraryPlugin;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { VerifiedAdvancedOutputConfig } from "../shared";
|
|
1
|
+
import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
|
|
2
|
+
import { UnpackedBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
4
|
import { Compilation, type Compiler } from "webpack";
|
|
5
|
-
export declare class ExtensionsConfigFileGeneratorPlugin extends
|
|
5
|
+
export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
|
|
6
6
|
private readonly config;
|
|
7
7
|
private readonly extensionsPath;
|
|
8
8
|
private readonly dest;
|
|
9
9
|
private static readonly semaphore;
|
|
10
10
|
private static readonly perLibraryTypeSetupFilePaths;
|
|
11
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsPath: string, dest: VerifiedAdvancedOutputConfig);
|
|
11
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
|
|
12
12
|
apply(compiler: Compiler): void;
|
|
13
13
|
private generateVersionTwoConfigFile;
|
|
14
14
|
protected attachSecondPhase(compilation: Compilation): void;
|
|
@@ -6,20 +6,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ExtensionsConfigFileGeneratorPlugin = void 0;
|
|
7
7
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const
|
|
9
|
+
const AbstractMultiPhaseLibraryAndEntryPlugin_1 = require("./AbstractMultiPhaseLibraryAndEntryPlugin");
|
|
10
10
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
11
11
|
const shared_1 = require("../shared");
|
|
12
12
|
const php_writer_1 = require("../utils/php-writer");
|
|
13
13
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
14
14
|
const webpack_1 = require("webpack");
|
|
15
|
-
class ExtensionsConfigFileGeneratorPlugin extends
|
|
15
|
+
class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin_1.AbstractMultiPhaseLibraryAndEntryPlugin {
|
|
16
16
|
config;
|
|
17
17
|
extensionsPath;
|
|
18
18
|
dest;
|
|
19
19
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore({ libraryType: "", assets: [], setupFiles: [] }, "Extensions");
|
|
20
20
|
static perLibraryTypeSetupFilePaths = {};
|
|
21
|
-
constructor(config, extensionsPath, dest) {
|
|
22
|
-
super(`extensions-v2-${dest.destination}`, [ExtensionsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
21
|
+
constructor(config, extensionsPath, dest, context, entry) {
|
|
22
|
+
super(`extensions-v2-${dest.destination}`, [ExtensionsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
23
23
|
this.config = config;
|
|
24
24
|
this.extensionsPath = extensionsPath;
|
|
25
25
|
this.dest = dest;
|
|
@@ -69,8 +69,8 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryPlugi
|
|
|
69
69
|
}
|
|
70
70
|
const relevantAssetData = {};
|
|
71
71
|
const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
|
|
72
|
-
for (const {
|
|
73
|
-
const fileWithAssetData =
|
|
72
|
+
for (const { entrypoint, srcPath } of relevantEntrypoints) {
|
|
73
|
+
const fileWithAssetData = entrypoint.getEntrypointChunk().files.values().find(file => assetDataSource[file]);
|
|
74
74
|
if (!fileWithAssetData) {
|
|
75
75
|
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
|
|
76
76
|
continue;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { UsageLocations } from "../shared";
|
|
2
|
-
import {
|
|
1
|
+
import { UnpackedBlockEntrypointInfo, UsageLocations } from "../shared";
|
|
2
|
+
import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
|
|
3
3
|
import { Compilation, type Compiler } from "webpack";
|
|
4
|
-
export declare class PlainEntrypointsConfigFileGeneratorPlugin extends
|
|
4
|
+
export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
|
|
5
5
|
private readonly buildRoot;
|
|
6
6
|
private readonly outputDir;
|
|
7
7
|
private readonly usageLocations;
|
|
8
8
|
private readonly handlePrefix;
|
|
9
9
|
private readonly useUnifiedLoader;
|
|
10
10
|
private static readonly semaphore;
|
|
11
|
-
constructor(buildRoot: string, outputDir: string, usageLocations: UsageLocations, handlePrefix: string, useUnifiedLoader: boolean);
|
|
11
|
+
constructor(buildRoot: string, outputDir: string, usageLocations: UsageLocations, handlePrefix: string, useUnifiedLoader: boolean, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
|
|
12
12
|
apply(compiler: Compiler): void;
|
|
13
13
|
private generatePlainEntrypointsLoader;
|
|
14
14
|
private static addHandlesToHandleLists;
|
|
@@ -8,18 +8,18 @@ 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 AbstractMultiPhaseLibraryAndEntryPlugin_1 = require("./AbstractMultiPhaseLibraryAndEntryPlugin");
|
|
12
12
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
13
13
|
const webpack_1 = require("webpack");
|
|
14
|
-
class PlainEntrypointsConfigFileGeneratorPlugin extends
|
|
14
|
+
class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin_1.AbstractMultiPhaseLibraryAndEntryPlugin {
|
|
15
15
|
buildRoot;
|
|
16
16
|
outputDir;
|
|
17
17
|
usageLocations;
|
|
18
18
|
handlePrefix;
|
|
19
19
|
useUnifiedLoader;
|
|
20
20
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore([], "Plain");
|
|
21
|
-
constructor(buildRoot, outputDir, usageLocations, handlePrefix, useUnifiedLoader) {
|
|
22
|
-
super("plain-entrypoints-v2", [PlainEntrypointsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
21
|
+
constructor(buildRoot, outputDir, usageLocations, handlePrefix, useUnifiedLoader, context, entry) {
|
|
22
|
+
super("plain-entrypoints-v2", [PlainEntrypointsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
23
23
|
this.buildRoot = buildRoot;
|
|
24
24
|
this.outputDir = outputDir;
|
|
25
25
|
this.usageLocations = usageLocations;
|
|
@@ -48,11 +48,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractMultiPhaseLibrar
|
|
|
48
48
|
}
|
|
49
49
|
const isScriptRegex = /\.m?[jt]sx?(\?|$)/i;
|
|
50
50
|
const myAssetHandles = [];
|
|
51
|
-
for (const entrypoint of
|
|
52
|
-
const srcPath = entrypoint.origins.map(origin => origin.request)[0];
|
|
53
|
-
if (!srcPath) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
51
|
+
for (const { entrypoint, srcPath } of this.getRelevantEntrypoints(compilation)) {
|
|
56
52
|
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
57
53
|
const assetData = entrypointChunk.files.values()
|
|
58
54
|
.map(file => assetDataSource[file]).find(v => v !== undefined);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractMultiPhaseLibraryAndEntryPlugin, EntryProvider } from "./AbstractMultiPhaseLibraryAndEntryPlugin";
|
|
2
|
+
import { UnpackedBlockEntrypointInfo } from "../shared";
|
|
2
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
3
4
|
import { Compilation, type Compiler } from "webpack";
|
|
4
5
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
5
|
-
export declare class PlainEntrypointsStyleBlockJSONPlugin extends
|
|
6
|
+
export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
|
|
6
7
|
private readonly config;
|
|
7
8
|
private readonly blocksDest;
|
|
8
9
|
private readonly webpackRemoveEmptyScriptsPlugin;
|
|
9
10
|
private static readonly semaphore;
|
|
10
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin);
|
|
11
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
|
|
11
12
|
apply(compiler: Compiler): void;
|
|
12
13
|
private emitBlockLoaderFile;
|
|
13
14
|
private transformBlocks;
|
|
@@ -7,20 +7,20 @@ 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 AbstractMultiPhaseLibraryAndEntryPlugin_1 = require("./AbstractMultiPhaseLibraryAndEntryPlugin");
|
|
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 AbstractMultiPhaseLibraryAndEntryPlugin_1.AbstractMultiPhaseLibraryAndEntryPlugin {
|
|
18
18
|
config;
|
|
19
19
|
blocksDest;
|
|
20
20
|
webpackRemoveEmptyScriptsPlugin;
|
|
21
21
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore({ collatableWorkableBlockInfo: {}, blocksDest: "", emittingWpmlXml: false }, "Block JSON v3");
|
|
22
|
-
constructor(config, blocksDest, webpackRemoveEmptyScriptsPlugin) {
|
|
23
|
-
super(`block-json-${blocksDest}`, [PlainEntrypointsStyleBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore]);
|
|
22
|
+
constructor(config, blocksDest, webpackRemoveEmptyScriptsPlugin, context, entry) {
|
|
23
|
+
super(`block-json-${blocksDest}`, [PlainEntrypointsStyleBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
|
|
24
24
|
this.config = config;
|
|
25
25
|
this.blocksDest = blocksDest;
|
|
26
26
|
this.webpackRemoveEmptyScriptsPlugin = webpackRemoveEmptyScriptsPlugin;
|
|
@@ -46,23 +46,18 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryPlug
|
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
const applicableBlockJsonFiles = {};
|
|
49
|
-
compilation.modules.values()
|
|
50
|
-
.filter(mod => mod.type === 'json')
|
|
51
|
-
.flatMap(mod => compilation.chunkGraph.getModuleChunks(mod))
|
|
52
|
-
.filter(chunk => {
|
|
53
|
-
const entryOptions = chunk.getEntryOptions();
|
|
54
|
-
return entryOptions?.library?.type === this.libraryType && entryOptions.library.name === "block-json-inclusion-assurance";
|
|
55
|
-
})
|
|
56
|
-
.flatMap(chunk => chunk.files.values().toArray())
|
|
57
|
-
.forEach(danglingBlockJsFile => {
|
|
58
|
-
compilation.deleteAsset(danglingBlockJsFile);
|
|
59
|
-
});
|
|
60
|
-
const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
|
|
61
49
|
const blockJsonOriginToOutputMapping = {};
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
|
|
51
|
+
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
52
|
+
if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || metadata !== "block-json-inclusion-assurance") {
|
|
64
53
|
continue;
|
|
65
54
|
}
|
|
55
|
+
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
56
|
+
for (const danglingBlockJsFile of [...entrypointChunk.files, ...entrypointChunk.auxiliaryFiles]) {
|
|
57
|
+
if (!danglingBlockJsFile.endsWith("block.json")) {
|
|
58
|
+
compilation.deleteAsset(danglingBlockJsFile);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
66
61
|
const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypointChunk)][0]?.originalSource();
|
|
67
62
|
if (asset) {
|
|
68
63
|
//TODO: Can we guarantee that entrypoint.name is always non-null?
|
|
@@ -79,16 +74,13 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryPlug
|
|
|
79
74
|
blockJsonOriginToOutputMapping[srcPath] = epBlockJson;
|
|
80
75
|
}
|
|
81
76
|
}
|
|
82
|
-
for (const { entrypoint,
|
|
83
|
-
if (node_path_1.default.basename(srcPath).toLowerCase() === "block.json"
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
const blockEntrypointInfo = (0, shared_1.unpackSmuggledBlockEntrypointInfo)(entrypointLibrary);
|
|
87
|
-
if (!blockEntrypointInfo) {
|
|
77
|
+
for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
|
|
78
|
+
if (node_path_1.default.basename(srcPath).toLowerCase() === "block.json" || typeof metadata === 'string') {
|
|
88
79
|
continue;
|
|
89
80
|
}
|
|
81
|
+
const entrypointChunk = entrypoint.getEntrypointChunk();
|
|
90
82
|
const epBlockJson = entrypointChunk.auxiliaryFiles.values().find(auxFile => node_path_1.default.basename(auxFile) === "block.json")
|
|
91
|
-
?? blockJsonOriginToOutputMapping[
|
|
83
|
+
?? blockJsonOriginToOutputMapping[metadata.blockJsonOrigin];
|
|
92
84
|
if (epBlockJson) {
|
|
93
85
|
//TODO: Do we need to handle a single entrypoint potentially emitting multiple primary files?
|
|
94
86
|
const assetData = entrypointChunk.files.values().map(file => assetDataSource[file])
|
|
@@ -103,14 +95,14 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractMultiPhaseLibraryPlug
|
|
|
103
95
|
.map(file => [file, (0, shared_1.scriptOrStyleTest)(file, shared_1.scriptExtension)])
|
|
104
96
|
.filter((item) => item[1] !== '')
|
|
105
97
|
.map(([file, assetType]) => {
|
|
106
|
-
const wasOriginallyAStyleField = (0, shared_1.isStyleField)(
|
|
98
|
+
const wasOriginallyAStyleField = (0, shared_1.isStyleField)(metadata.entrypointField);
|
|
107
99
|
if (wasOriginallyAStyleField !== (assetType === "style")) { // This means that the file is extracted
|
|
108
100
|
return {
|
|
109
|
-
...
|
|
110
|
-
entrypointField: (0, shared_1.convertEntrypointFieldForAssetType)(
|
|
101
|
+
...metadata, outputPath: file, assetData, originalValue: undefined, hash: entrypointChunk.hash ?? "",
|
|
102
|
+
entrypointField: (0, shared_1.convertEntrypointFieldForAssetType)(metadata.entrypointField, assetType)
|
|
111
103
|
};
|
|
112
104
|
}
|
|
113
|
-
return ({ ...
|
|
105
|
+
return ({ ...metadata, outputPath: file, assetData, hash: entrypointChunk.hash ?? "" });
|
|
114
106
|
});
|
|
115
107
|
if (applicableBlockJsonFiles[epBlockJson]) {
|
|
116
108
|
applicableBlockJsonFiles[epBlockJson].workableBlockEntrypointsInfo.push(...workableBlockEntrypointsInfo);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
2
|
-
import { Compilation, type Compiler } from "webpack";
|
|
3
2
|
import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
|
|
3
|
+
import { Compilation, type Compiler } from "webpack";
|
|
4
4
|
export declare class SpecialAssetHandlingPlugin extends AbstractMultiPhaseLibraryPlugin {
|
|
5
5
|
private readonly config;
|
|
6
6
|
private static readonly semaphore;
|
|
@@ -8,9 +8,9 @@ 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 AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
|
|
11
12
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
12
13
|
const webpack_1 = require("webpack");
|
|
13
|
-
const AbstractMultiPhaseLibraryPlugin_1 = require("./AbstractMultiPhaseLibraryPlugin");
|
|
14
14
|
class SpecialAssetHandlingPlugin extends AbstractMultiPhaseLibraryPlugin_1.AbstractMultiPhaseLibraryPlugin {
|
|
15
15
|
config;
|
|
16
16
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore({}, "Special");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { EntryProvider } from "../plugins/AbstractMultiPhaseLibraryAndEntryPlugin";
|
|
2
|
+
import { EntrypointFields, PlauditWordpressWebpackConfig, UnpackedBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
|
|
3
|
+
import type { Compiler, Configuration, DynamicEntryPlugin, EntryObject, WebpackPluginInstance } from "webpack";
|
|
3
4
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
4
5
|
export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpressWebpackConfig, 'variables' | 'src' | 'externals'>> & {
|
|
5
6
|
variablesFilePath?: string;
|
|
@@ -18,5 +19,12 @@ export type CommonConfigProcessingResult = {
|
|
|
18
19
|
};
|
|
19
20
|
export declare function joinPossiblyAbsolutePaths(...paths: (string | undefined)[]): string;
|
|
20
21
|
export declare function groupEntrypointsByAssetFile<T>(entrypoints: T[], entrypointNameExtractor: (t: T) => string): Map<string, T[]>;
|
|
21
|
-
export
|
|
22
|
-
export
|
|
22
|
+
export type BlockJsonExtensibleEntryObject = ExtensibleEntryObject<UnpackedBlockEntrypointInfo | string>;
|
|
23
|
+
export type EntryStaticNormalized = Awaited<ReturnType<ConstructorParameters<typeof DynamicEntryPlugin>[1]>>;
|
|
24
|
+
export type ExtensibleEntryObject<M> = {
|
|
25
|
+
[index: string]: Omit<EntryStaticNormalized[string], 'import'> & Required<NonNullable<Pick<EntryStaticNormalized[string], 'import'>>> & {
|
|
26
|
+
plauditMetadata: M;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): EntryProvider<UnpackedBlockEntrypointInfo | string>;
|
|
30
|
+
export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration, srcIsDirectory: boolean, dest: VerifiedAdvancedOutputConfig, src: string, srcRoot: string | string[], entry: (() => Promise<EntryObject> | EntryObject) | EntryObject, plugins: CommonPluginConfig['plugins']): Configuration;
|
|
@@ -48,31 +48,30 @@ function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
|
|
|
48
48
|
handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name)
|
|
49
49
|
};
|
|
50
50
|
return [joinPossiblyAbsolutePaths(dest.destination, node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name),
|
|
51
|
-
{ import: ep,
|
|
51
|
+
{ import: [ep], plauditMetadata: fakeEntrypointInfo }];
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
function parseEntrypointsJSON(dir, dest, supportedExtensions
|
|
54
|
+
function parseEntrypointsJSON(dir, dest, supportedExtensions) {
|
|
55
55
|
const entrypointJsonOrigin = node_path_1.default.join(dir, 'entrypoints.json');
|
|
56
56
|
const entrypointsJSON = JSON.parse(node_fs_1.default.readFileSync(entrypointJsonOrigin, 'utf8'));
|
|
57
57
|
if (Array.isArray(entrypointsJSON)) {
|
|
58
|
-
return mapToRealEntrypoints(entrypointsJSON, dir, supportedExtensions, { dest, entrypointJsonOrigin
|
|
58
|
+
return mapToRealEntrypoints(entrypointsJSON, dir, supportedExtensions, { dest, entrypointJsonOrigin });
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
|
-
return Object.entries(entrypointsJSON).
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
else if (Array.isArray(config)) {
|
|
66
|
-
return [name, config.map(c => joinPossiblyAbsolutePaths(dir, c))];
|
|
61
|
+
return Object.entries(entrypointsJSON).flatMap(([name, config]) => {
|
|
62
|
+
if (Array.isArray(config)) {
|
|
63
|
+
return config.flatMap(c => mapToRealEntrypoints(c, dir, supportedExtensions, { dest, entrypointJsonOrigin }));
|
|
67
64
|
}
|
|
68
65
|
else {
|
|
66
|
+
return [[name, config]];
|
|
67
|
+
/* TODO: Fix compat with entrypoints.json in object mode
|
|
69
68
|
if (typeof config.import === 'string') {
|
|
70
69
|
config.import = joinPossiblyAbsolutePaths(dir, config.import);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
70
|
+
} else {
|
|
73
71
|
config.import = config.import.map(c => joinPossiblyAbsolutePaths(dir, c));
|
|
74
72
|
}
|
|
75
73
|
return [name, config];
|
|
74
|
+
*/
|
|
76
75
|
}
|
|
77
76
|
});
|
|
78
77
|
}
|
|
@@ -115,7 +114,7 @@ function addPotentiallyDuplicatedEntrypointName(entry, entrypoint, typeCounts, s
|
|
|
115
114
|
}
|
|
116
115
|
entry[potentialKey] = entrypoint[1];
|
|
117
116
|
}
|
|
118
|
-
function resolveEntryFromDirectory(commonConfig, srcRoot, dest
|
|
117
|
+
function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
119
118
|
const { entrypointFields, processingModules, scriptExtension } = commonConfig;
|
|
120
119
|
return async () => {
|
|
121
120
|
const loadingEntrypoints = [];
|
|
@@ -195,12 +194,12 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest, libraryType) {
|
|
|
195
194
|
return [
|
|
196
195
|
resolvedBlockEntrypoint.entrypointName,
|
|
197
196
|
{
|
|
198
|
-
import: resolvedBlockEntrypoint.absoluteSrc,
|
|
199
|
-
|
|
197
|
+
import: [resolvedBlockEntrypoint.absoluteSrc],
|
|
198
|
+
plauditMetadata: resolvedBlockEntrypoint
|
|
200
199
|
}
|
|
201
200
|
];
|
|
202
201
|
}));
|
|
203
|
-
rawEntrypoints.push([blockJsonChunkName, { import: blockJsonOrigin,
|
|
202
|
+
rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: "block-json-inclusion-assurance" }]);
|
|
204
203
|
wpmlFiles.push(node_path_1.default.join(dir, 'block.json'));
|
|
205
204
|
}
|
|
206
205
|
catch (e) {
|
|
@@ -208,15 +207,15 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest, libraryType) {
|
|
|
208
207
|
const packageJsonOrigin = node_path_1.default.join(dir, 'package.json');
|
|
209
208
|
const packageJson = JSON.parse(await promises_1.default.readFile(packageJsonOrigin, 'utf8'));
|
|
210
209
|
if (packageJson['main']) {
|
|
211
|
-
rawEntrypoints.push(...mapToRealEntrypoints(packageJson['main'], dir, commonConfig.scriptExtension.test, { dest,
|
|
210
|
+
rawEntrypoints.push(...mapToRealEntrypoints(packageJson['main'], dir, commonConfig.scriptExtension.test, { dest, entrypointJsonOrigin: packageJsonOrigin }));
|
|
212
211
|
}
|
|
213
212
|
if (!processingModules && packageJson['style']) {
|
|
214
|
-
rawEntrypoints.push(...mapToRealEntrypoints(packageJson['style'], dir, shared_1.styleExtension.test, { dest,
|
|
213
|
+
rawEntrypoints.push(...mapToRealEntrypoints(packageJson['style'], dir, shared_1.styleExtension.test, { dest, entrypointJsonOrigin: packageJsonOrigin }));
|
|
215
214
|
}
|
|
216
215
|
}
|
|
217
216
|
catch (e) {
|
|
218
217
|
try {
|
|
219
|
-
rawEntrypoints.push(...parseEntrypointsJSON(dir, dest, ep => commonConfig.scriptExtension.test(ep) || shared_1.styleExtension.test(ep)
|
|
218
|
+
rawEntrypoints.push(...parseEntrypointsJSON(dir, dest, ep => commonConfig.scriptExtension.test(ep) || shared_1.styleExtension.test(ep)));
|
|
220
219
|
}
|
|
221
220
|
catch (e) {
|
|
222
221
|
// This just means that the directory doesn't contain any declared entrypoints.
|
|
@@ -254,12 +253,12 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest, libraryType) {
|
|
|
254
253
|
const wpmlEntrypointFiles = allEntrypoints.flatMap(e => e[1]);
|
|
255
254
|
try {
|
|
256
255
|
await promises_1.default.access(node_path_1.default.join(srcRoot, "wpml-config.xml"));
|
|
257
|
-
currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles],
|
|
256
|
+
currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: "wpml-config-xml" };
|
|
258
257
|
}
|
|
259
258
|
catch (e) {
|
|
260
259
|
// If the wpml-config.xml file does not exist, just "import" the other files that will be used to build the emitted version
|
|
261
260
|
if (wpmlEntrypointFiles.length) {
|
|
262
|
-
currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles,
|
|
261
|
+
currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: "wpml-config-xml" };
|
|
263
262
|
}
|
|
264
263
|
}
|
|
265
264
|
}
|
|
@@ -348,7 +347,8 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
348
347
|
path: outPath,
|
|
349
348
|
chunkFilename: 'webpack-chunks/[id].js',
|
|
350
349
|
publicPath: publicPath,
|
|
351
|
-
library: outputLibrary
|
|
350
|
+
library: outputLibrary,
|
|
351
|
+
clean: false
|
|
352
352
|
},
|
|
353
353
|
optimization: {
|
|
354
354
|
...webpackConfig.optimization,
|
|
@@ -388,7 +388,7 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
388
388
|
delete require.cache[require.resolve(variablesFilePath)];
|
|
389
389
|
updateCurrentVariables(require(variablesFilePath));
|
|
390
390
|
}
|
|
391
|
-
return entry();
|
|
391
|
+
return typeof entry === 'function' ? entry() : entry;
|
|
392
392
|
},
|
|
393
393
|
performance: {
|
|
394
394
|
...webpackConfig.performance,
|
|
@@ -484,47 +484,63 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
|
484
484
|
}
|
|
485
485
|
function makeBlocksWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins) {
|
|
486
486
|
const { processingModules } = commonConfig;
|
|
487
|
-
const blockJSONManagingPlugin = new PlainEntrypointsStyleBlockJSONPlugin_1.PlainEntrypointsStyleBlockJSONPlugin(config, dest.destination, plugins.find(p => p instanceof webpack_remove_empty_scripts_1.default));
|
|
487
|
+
const blockJSONManagingPlugin = new PlainEntrypointsStyleBlockJSONPlugin_1.PlainEntrypointsStyleBlockJSONPlugin(config, dest.destination, plugins.find(p => p instanceof webpack_remove_empty_scripts_1.default), webpackConfig.context ?? process.cwd(), (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
|
|
488
488
|
plugins.push(blockJSONManagingPlugin);
|
|
489
489
|
if (config.processTranslationConfigs && !processingModules) {
|
|
490
490
|
plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination));
|
|
491
491
|
}
|
|
492
|
-
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot,
|
|
492
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, {}, plugins);
|
|
493
493
|
}
|
|
494
494
|
function makeExtensionsWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins) {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const file = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
|
|
505
|
-
rawEntrypoints.push([node_path_1.default.join(dest.destination, node_path_1.default.basename(file, node_path_1.default.extname(file))), { import: file, library: { type: plugin.libraryType } }]);
|
|
495
|
+
if (config.extensionsVersion > 1) {
|
|
496
|
+
const entry = async () => {
|
|
497
|
+
const rawEntrypoints = [];
|
|
498
|
+
for await (const dirent of await promises_1.default.opendir(srcRoot)) {
|
|
499
|
+
if (dirent.isFile() && !dirent.name.startsWith("~")) {
|
|
500
|
+
if (commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name)) {
|
|
501
|
+
const file = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
|
|
502
|
+
rawEntrypoints.push([node_path_1.default.join(dest.destination, node_path_1.default.basename(file, node_path_1.default.extname(file))), { import: [file], plauditMetadata: "entrypoint-v2" }]);
|
|
503
|
+
}
|
|
506
504
|
}
|
|
507
505
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
506
|
+
return Object.fromEntries(rawEntrypoints);
|
|
507
|
+
};
|
|
508
|
+
plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(config, srcRoot, dest, webpackConfig.context ?? process.cwd(), entry));
|
|
509
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, {}, plugins);
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
const plugin = new ExtensionsConfigFileGeneratorPluginV1_1.ExtensionsConfigFileGeneratorPluginV1(dest.destination);
|
|
513
|
+
plugins.push(plugin);
|
|
514
|
+
const entry = async () => {
|
|
515
|
+
const rawEntrypoints = [];
|
|
516
|
+
for await (const dirent of await promises_1.default.opendir(srcRoot)) {
|
|
517
|
+
if (dirent.isFile() && !dirent.name.startsWith("~")) {
|
|
518
|
+
if (commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name)) {
|
|
519
|
+
const file = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
|
|
520
|
+
rawEntrypoints.push([node_path_1.default.join(dest.destination, node_path_1.default.basename(file, node_path_1.default.extname(file))), file]);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return Object.fromEntries(rawEntrypoints);
|
|
525
|
+
};
|
|
526
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, entry, plugins);
|
|
527
|
+
}
|
|
512
528
|
}
|
|
513
529
|
function makePlainV1WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory) {
|
|
514
530
|
const baseDest = stripExtension(dest.destination);
|
|
515
531
|
const entry = srcIsDirectory // This being true implies that srcRoot is not an array
|
|
516
|
-
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest
|
|
532
|
+
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
|
|
517
533
|
: () => ({ [baseDest]: srcRoot });
|
|
518
534
|
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, srcIsDirectory, dest, src, srcRoot, entry, plugins);
|
|
519
535
|
}
|
|
520
536
|
function makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory) {
|
|
521
|
-
const requester = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(process.cwd(), config.outputDir, dest.locations, config.plainEntrypointsHandlePrefix, config.useUnifiedLoader);
|
|
522
|
-
plugins.push(requester);
|
|
523
537
|
const baseDest = stripExtension(dest.destination);
|
|
524
538
|
const entry = srcIsDirectory // This being true implies that srcRoot is not an array
|
|
525
|
-
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest
|
|
526
|
-
: () => ({ [baseDest]: srcRoot });
|
|
527
|
-
|
|
539
|
+
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
|
|
540
|
+
: () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: "plain-entrypoint" } });
|
|
541
|
+
const requester = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(process.cwd(), config.outputDir, dest.locations, config.plainEntrypointsHandlePrefix, config.useUnifiedLoader, webpackConfig.context ?? process.cwd(), entry);
|
|
542
|
+
plugins.push(requester);
|
|
543
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, srcIsDirectory, dest, src, srcRoot, {}, plugins);
|
|
528
544
|
}
|
|
529
545
|
function stripExtension(filepath) {
|
|
530
546
|
return node_path_1.default.join(node_path_1.default.dirname(filepath), node_path_1.default.basename(filepath, node_path_1.default.extname(filepath)));
|