@plaudit/webpack-extensions 2.18.1 → 2.20.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/wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin.d.ts +2 -1
- package/build/wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin.js +5 -2
- package/build/wordpress-scripts-wrapper/BlockJSONManagingPlugin.d.ts +6 -1
- package/build/wordpress-scripts-wrapper/BlockJSONManagingPlugin.js +98 -42
- package/build/wordpress-scripts-wrapper.d.ts +3 -3
- package/build/wordpress-scripts-wrapper.js +69 -35
- package/package.json +7 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
2
2
|
export default class AdditionalDependencyInjectorPlugin implements WebpackPluginInstance {
|
|
3
3
|
private readonly entrypointAdditionalDependencies;
|
|
4
|
-
|
|
4
|
+
private readonly processingModules;
|
|
5
|
+
constructor(entrypointAdditionalDependencies: string[], processingModules: boolean);
|
|
5
6
|
apply(compiler: Compiler): void;
|
|
6
7
|
}
|
|
@@ -7,8 +7,10 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
7
7
|
const webpack_1 = require("webpack");
|
|
8
8
|
class AdditionalDependencyInjectorPlugin {
|
|
9
9
|
entrypointAdditionalDependencies;
|
|
10
|
-
|
|
10
|
+
processingModules;
|
|
11
|
+
constructor(entrypointAdditionalDependencies, processingModules) {
|
|
11
12
|
this.entrypointAdditionalDependencies = entrypointAdditionalDependencies;
|
|
13
|
+
this.processingModules = processingModules;
|
|
12
14
|
}
|
|
13
15
|
apply(compiler) {
|
|
14
16
|
compiler.hooks.thisCompilation.tap("AdditionalDependencyInjectorPlugin", compilation => {
|
|
@@ -16,9 +18,10 @@ class AdditionalDependencyInjectorPlugin {
|
|
|
16
18
|
name: "AdditionalDependencyInjectorPlugin_ProcessAssets",
|
|
17
19
|
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE
|
|
18
20
|
}, compilationAssets => {
|
|
21
|
+
const usableEntrypointTest = this.processingModules ? /\.mtsx?$/ : /\.tsx?$/;
|
|
19
22
|
const assetSources = new Map();
|
|
20
23
|
for (const entrypoint of compilation.entrypoints.values()) {
|
|
21
|
-
const req = entrypoint.origins.filter(origin =>
|
|
24
|
+
const req = entrypoint.origins.filter(origin => usableEntrypointTest.test(origin.request))[0]?.request;
|
|
22
25
|
if (req) {
|
|
23
26
|
for (const chunk of entrypoint.chunks) {
|
|
24
27
|
for (const file of chunk.files) {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
2
2
|
export default class BlockJSONManagingPlugin implements WebpackPluginInstance {
|
|
3
3
|
private readonly standaloneBlocks;
|
|
4
|
-
|
|
4
|
+
private readonly processingModules;
|
|
5
|
+
private static readonly sourceToOutputMapping;
|
|
6
|
+
private static readonly moduleSourcesToOutputs;
|
|
7
|
+
constructor(standaloneBlocks: boolean, processingModules: boolean);
|
|
5
8
|
apply(compiler: Compiler): void;
|
|
6
9
|
findCommonAncestor(...paths: string[]): string[];
|
|
7
10
|
findRelativeRouteBetween(path1: string, path2: string): string;
|
|
11
|
+
private static hashThingForAsset;
|
|
12
|
+
private static resolveFilesFromStats;
|
|
8
13
|
}
|
|
@@ -3,83 +3,108 @@ 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
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
6
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
const webpack_1 = require("webpack");
|
|
9
10
|
const php_serializer_1 = __importDefault(require("./php-serializer"));
|
|
10
11
|
class BlockJSONManagingPlugin {
|
|
11
12
|
standaloneBlocks;
|
|
12
|
-
|
|
13
|
+
processingModules;
|
|
14
|
+
static sourceToOutputMapping = new Map();
|
|
15
|
+
static moduleSourcesToOutputs = new Map();
|
|
16
|
+
constructor(standaloneBlocks, processingModules) {
|
|
13
17
|
this.standaloneBlocks = standaloneBlocks;
|
|
18
|
+
this.processingModules = processingModules;
|
|
14
19
|
}
|
|
15
20
|
apply(compiler) {
|
|
16
21
|
compiler.hooks.compilation.tap("BlockJSONManagingPlugin", compilation => {
|
|
17
22
|
compilation.hooks.afterProcessAssets.tap("BlockJSONStyleRemappingPlugin_ProcessAssets", compilationAssets => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (module.nameForCondition !== undefined && module.chunks?.length === 1) {
|
|
44
|
-
const output = singleFileChunkToOutputName.get(module.chunks[0]);
|
|
45
|
-
return output !== undefined ? [module.nameForCondition, output] : undefined;
|
|
23
|
+
let assetSourceFilesCache = undefined;
|
|
24
|
+
let singleFileInputToOutputNameAndHashCache = undefined;
|
|
25
|
+
const sourceFileMappers = () => {
|
|
26
|
+
if (singleFileInputToOutputNameAndHashCache === undefined || assetSourceFilesCache === undefined) {
|
|
27
|
+
const stats = compilation.getStats().toJson({
|
|
28
|
+
hash: true,
|
|
29
|
+
publicPath: true,
|
|
30
|
+
assets: true,
|
|
31
|
+
moduleAssets: true,
|
|
32
|
+
chunks: true,
|
|
33
|
+
modules: true,
|
|
34
|
+
source: true,
|
|
35
|
+
errorDetails: false,
|
|
36
|
+
timings: false
|
|
37
|
+
});
|
|
38
|
+
if (!stats.assets) {
|
|
39
|
+
throw new Error("Stats did not include assets despite them being requested");
|
|
40
|
+
}
|
|
41
|
+
if (!stats.modules) {
|
|
42
|
+
throw new Error("Stats did not include modules despite them being requested");
|
|
43
|
+
}
|
|
44
|
+
singleFileInputToOutputNameAndHashCache = BlockJSONManagingPlugin.resolveFilesFromStats(compilationAssets, stats);
|
|
45
|
+
assetSourceFilesCache = new Map(stats.assets
|
|
46
|
+
.map(asset => [asset.name, asset.info?.sourceFilename])
|
|
47
|
+
.filter((v) => v[0] !== undefined && v[1] !== undefined));
|
|
46
48
|
}
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const remapValue = (value, name, dirname) => {
|
|
49
|
+
return { assetSourceFiles: assetSourceFilesCache, singleFileInputToOutputNameAndHash: singleFileInputToOutputNameAndHashCache };
|
|
50
|
+
};
|
|
51
|
+
const remapValue = (value, name) => {
|
|
51
52
|
if (value.startsWith("file:")) {
|
|
53
|
+
let res = BlockJSONManagingPlugin.sourceToOutputMapping.get(`${name};${value}`);
|
|
54
|
+
if (res !== undefined) {
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
const { assetSourceFiles, singleFileInputToOutputNameAndHash } = sourceFileMappers();
|
|
58
|
+
const dirname = node_path_1.default.dirname(assetSourceFiles.get(name) ?? name);
|
|
52
59
|
const styleInputPath = node_path_1.default.normalize(node_path_1.default.join(compiler.context, dirname, value.substring(5)));
|
|
53
|
-
const styleOutputPath =
|
|
60
|
+
const styleOutputPath = singleFileInputToOutputNameAndHash.get(styleInputPath);
|
|
54
61
|
if (styleOutputPath !== undefined) {
|
|
55
62
|
const prefix = value.startsWith("./", 5) ? "./" : "";
|
|
56
|
-
const relativePath = node_path_1.default.relative(node_path_1.default.dirname(name), styleOutputPath);
|
|
57
|
-
|
|
63
|
+
const relativePath = node_path_1.default.relative(node_path_1.default.dirname(name), styleOutputPath[0]);
|
|
64
|
+
const res = [`file:${prefix}${relativePath}`, typeof styleOutputPath[1] === 'string' ? styleOutputPath[1] : styleOutputPath[1]()];
|
|
65
|
+
BlockJSONManagingPlugin.sourceToOutputMapping.set(`${name};${value}`, res);
|
|
66
|
+
return res;
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
|
-
return value;
|
|
69
|
+
return [value, ""];
|
|
61
70
|
};
|
|
71
|
+
if (this.processingModules) {
|
|
72
|
+
for (const [key, value] of sourceFileMappers().singleFileInputToOutputNameAndHash.entries()) {
|
|
73
|
+
BlockJSONManagingPlugin.moduleSourcesToOutputs.set(key, value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
62
76
|
const blockDirConfigData = {};
|
|
63
|
-
const mappableKeys = ["editorStyle", "style", "viewStyle", "viewScript", "script", "editorScript"];
|
|
77
|
+
const mappableKeys = ["editorStyle", "style", "viewStyle", "viewScript", "script", "editorScript", "viewScriptModule", "scriptModule"];
|
|
64
78
|
for (const [name, asset] of Object.entries(compilationAssets)) {
|
|
65
79
|
if (name.endsWith("block.json")) {
|
|
80
|
+
let compositeHash = "";
|
|
66
81
|
blockDirConfigData[name] = true;
|
|
67
82
|
if (asset.constructor.name === 'RawSource') {
|
|
68
|
-
const dirname = node_path_1.default.dirname(assetSourceFiles.get(name) ?? name);
|
|
69
83
|
const json = JSON.parse(asset.source().toString());
|
|
70
84
|
for (const mappableKey of mappableKeys) {
|
|
71
85
|
if (mappableKey in json) {
|
|
72
86
|
const unmappedValue = json[mappableKey];
|
|
73
87
|
if (Array.isArray(unmappedValue)) {
|
|
74
|
-
|
|
88
|
+
const remappedValue = unmappedValue.map(value => remapValue(value, name));
|
|
89
|
+
json[mappableKey] = remappedValue.map(([resource]) => resource);
|
|
90
|
+
compositeHash += "~" + remappedValue.map(([_, hash]) => hash).join("~");
|
|
75
91
|
}
|
|
76
92
|
else if (typeof unmappedValue === 'string') {
|
|
77
|
-
|
|
93
|
+
const remappedValue = remapValue(unmappedValue, name);
|
|
94
|
+
json[mappableKey] = remappedValue[0];
|
|
95
|
+
compositeHash += "~" + remappedValue[1];
|
|
78
96
|
}
|
|
79
97
|
}
|
|
80
98
|
}
|
|
99
|
+
if (json["version"]) {
|
|
100
|
+
json["version"] = `${json["version"]}-${BlockJSONManagingPlugin.hashThingForAsset(compositeHash)}`;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
json["version"] = BlockJSONManagingPlugin.hashThingForAsset(compositeHash);
|
|
104
|
+
}
|
|
81
105
|
if (!this.standaloneBlocks && json["plaudit"] !== "simple") {
|
|
82
|
-
const
|
|
106
|
+
const { assetSourceFiles } = sourceFileMappers();
|
|
107
|
+
const sourceDir = node_path_1.default.join(compiler.context, node_path_1.default.dirname(assetSourceFiles.get(name) ?? name));
|
|
83
108
|
const outputDir = node_path_1.default.join(compiler.outputPath, node_path_1.default.dirname(name));
|
|
84
109
|
const stripFilePrefix = (file) => file.startsWith("file:./") ? file.substring(7) : file;
|
|
85
110
|
let setupFiles = (json["plaudit"]?.["setup"]
|
|
@@ -164,5 +189,36 @@ class BlockJSONManagingPlugin {
|
|
|
164
189
|
route.push(node_path_1.default.relative(commonAncestor.join(node_path_1.default.sep), path2));
|
|
165
190
|
return route.join(node_path_1.default.sep);
|
|
166
191
|
}
|
|
192
|
+
static hashThingForAsset(thing) {
|
|
193
|
+
return node_crypto_1.default.createHash('md5').update(thing).digest("hex").substring(0, 20).toLowerCase();
|
|
194
|
+
}
|
|
195
|
+
static resolveFilesFromStats(compilationAssets, stats) {
|
|
196
|
+
const singleFileChunkToOutputName = new Map(stats.assets
|
|
197
|
+
.filter((asset) => asset.chunks?.length === 1)
|
|
198
|
+
.filter(asset => !asset.name.endsWith('.asset.php'))
|
|
199
|
+
.map(asset => {
|
|
200
|
+
let assetHash = asset.info.contenthash ?? asset.info.fullhash;
|
|
201
|
+
if (Array.isArray(assetHash)) {
|
|
202
|
+
assetHash = BlockJSONManagingPlugin.hashThingForAsset(assetHash.join('~'));
|
|
203
|
+
}
|
|
204
|
+
return [asset.chunks[0], [asset.name, assetHash ?? (() => {
|
|
205
|
+
const realAsset = compilationAssets[asset.name];
|
|
206
|
+
return BlockJSONManagingPlugin.hashThingForAsset(realAsset ? realAsset.source().toString() : Date.now().toString());
|
|
207
|
+
})]];
|
|
208
|
+
}));
|
|
209
|
+
const res = new Map(stats.modules
|
|
210
|
+
.map(module => {
|
|
211
|
+
if (module.nameForCondition !== undefined && module.chunks?.length === 1) {
|
|
212
|
+
const output = singleFileChunkToOutputName.get(module.chunks[0]);
|
|
213
|
+
return output !== undefined ? [module.nameForCondition, output] : undefined;
|
|
214
|
+
}
|
|
215
|
+
return undefined;
|
|
216
|
+
})
|
|
217
|
+
.filter((v) => v !== undefined));
|
|
218
|
+
for (const [key, value] of BlockJSONManagingPlugin.moduleSourcesToOutputs.entries()) {
|
|
219
|
+
res.set(key, value);
|
|
220
|
+
}
|
|
221
|
+
return res;
|
|
222
|
+
}
|
|
167
223
|
}
|
|
168
224
|
exports.default = BlockJSONManagingPlugin;
|
|
@@ -5,12 +5,12 @@ interface AdvancedOutputConfig {
|
|
|
5
5
|
additionalDependencies?: string[];
|
|
6
6
|
directoryLayout?: 'blocks' | 'extensions';
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
type PlauditWordpressWebpackConfig = {
|
|
9
9
|
standaloneBlocks?: boolean;
|
|
10
10
|
variables?: Record<string, any>;
|
|
11
11
|
verbose?: boolean;
|
|
12
12
|
src: string[] | Record<string, string | AdvancedOutputConfig>;
|
|
13
13
|
stats?: Configuration['stats'];
|
|
14
|
-
}
|
|
15
|
-
declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration) => Configuration[];
|
|
14
|
+
};
|
|
15
|
+
declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration[] | Configuration) => Configuration[];
|
|
16
16
|
export = _default;
|
|
@@ -59,27 +59,28 @@ function resolveLegacyBlockScriptsInFolder(folder) {
|
|
|
59
59
|
}
|
|
60
60
|
return blockScriptEntrypoints;
|
|
61
61
|
}
|
|
62
|
-
const
|
|
62
|
+
const scriptWithoutModuleExtension = /\.[jt]sx?$/;
|
|
63
|
+
const scriptWithModuleExtension = /\.m[jt]sx?$/;
|
|
63
64
|
const styleExtension = /\.(p?c|sa)ss$/;
|
|
64
|
-
function scriptOrStyleTest(entryPath) {
|
|
65
|
+
function scriptOrStyleTest(entryPath, scriptExtension) {
|
|
65
66
|
return scriptExtension.test(entryPath) ? "script" : (styleExtension.test(entryPath) ? "style" : "");
|
|
66
67
|
}
|
|
67
|
-
function determineEntrypointType(entrypoint) {
|
|
68
|
-
let res = scriptOrStyleTest(entrypoint[0]);
|
|
68
|
+
function determineEntrypointType(entrypoint, scriptExtension) {
|
|
69
|
+
let res = scriptOrStyleTest(entrypoint[0], scriptExtension);
|
|
69
70
|
if (res) {
|
|
70
71
|
return res;
|
|
71
72
|
}
|
|
72
73
|
if (typeof entrypoint[1] === 'string') {
|
|
73
|
-
return scriptOrStyleTest(entrypoint[1]);
|
|
74
|
+
return scriptOrStyleTest(entrypoint[1], scriptExtension);
|
|
74
75
|
}
|
|
75
76
|
else if (Array.isArray(entrypoint[1])) {
|
|
76
|
-
return entrypoint[1].reduce((prior, ep) => prior || scriptOrStyleTest(ep), "");
|
|
77
|
+
return entrypoint[1].reduce((prior, ep) => prior || scriptOrStyleTest(ep, scriptExtension), "");
|
|
77
78
|
}
|
|
78
79
|
else if (typeof entrypoint[1].import === 'string') {
|
|
79
|
-
return scriptOrStyleTest(entrypoint[1].import);
|
|
80
|
+
return scriptOrStyleTest(entrypoint[1].import, scriptExtension);
|
|
80
81
|
}
|
|
81
82
|
else {
|
|
82
|
-
return entrypoint[1].import.reduce((prior, ep) => prior || scriptOrStyleTest(ep), "");
|
|
83
|
+
return entrypoint[1].import.reduce((prior, ep) => prior || scriptOrStyleTest(ep, scriptExtension), "");
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
function injectTypeAndCountToEntrypointName(entrypointName, type, typeCounts) {
|
|
@@ -94,8 +95,8 @@ function injectTypeAndCountToEntrypointName(entrypointName, type, typeCounts) {
|
|
|
94
95
|
typeCounts[type] += 1;
|
|
95
96
|
return `${entrypointBasename}_${parts.join('-')}${node_path_1.default.extname(entrypointName)}`;
|
|
96
97
|
}
|
|
97
|
-
function addPotentiallyDuplicatedEntrypointName(entry, entrypoint, typeCounts) {
|
|
98
|
-
const type = determineEntrypointType(entrypoint);
|
|
98
|
+
function addPotentiallyDuplicatedEntrypointName(entry, entrypoint, typeCounts, scriptExtension) {
|
|
99
|
+
const type = determineEntrypointType(entrypoint, scriptExtension);
|
|
99
100
|
let potentialKey = injectTypeAndCountToEntrypointName(entrypoint[0], type, typeCounts);
|
|
100
101
|
while (entry[potentialKey]) {
|
|
101
102
|
potentialKey = injectTypeAndCountToEntrypointName(entrypoint[0], type, typeCounts);
|
|
@@ -141,12 +142,10 @@ function disableDefaultURLProcessing(webpackConfig) {
|
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
|
-
function injectPostcssConfigOverrides(webpackConfig, variables, verbose) {
|
|
145
|
+
function injectPostcssConfigOverrides(webpackConfig, variables, verbose, processingModules) {
|
|
145
146
|
if (webpackConfig.module?.rules) {
|
|
146
|
-
const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, (name)
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
for (const rule of webpackConfig.module.rules) {
|
|
147
|
+
const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, name => variables(name) ?? (name === 'ENV' ? '' : undefined));
|
|
148
|
+
return webpackConfig.module.rules.map(rule => {
|
|
150
149
|
if (isTruthy(rule) && typeof rule === 'object' && Array.isArray(rule.use)) {
|
|
151
150
|
for (const useItem of rule.use) {
|
|
152
151
|
if (isTruthy(useItem) && typeof useItem === 'object' && typeof useItem.options === 'object') {
|
|
@@ -163,12 +162,14 @@ function injectPostcssConfigOverrides(webpackConfig, variables, verbose) {
|
|
|
163
162
|
}
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
|
-
if (rule.test instanceof RegExp && rule.test.test("index.ts")) { // Then this is the javascript and typescript rule
|
|
167
|
-
rule
|
|
165
|
+
if (rule.test instanceof RegExp && (rule.test.test("index.ts") || rule.test.test("index.mts"))) { // Then this is the javascript and typescript rule
|
|
166
|
+
return { ...rule, test: processingModules ? scriptWithModuleExtension : scriptWithoutModuleExtension }; // This hacks in differentiated support for mjs and mts files
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
|
-
|
|
169
|
+
return rule;
|
|
170
|
+
});
|
|
171
171
|
}
|
|
172
|
+
return undefined;
|
|
172
173
|
}
|
|
173
174
|
function parseEntrypointsJSON(dir) {
|
|
174
175
|
const entrypointsJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'entrypoints.json'), 'utf8'));
|
|
@@ -195,21 +196,26 @@ function parseEntrypointsJSON(dir) {
|
|
|
195
196
|
});
|
|
196
197
|
}
|
|
197
198
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
199
|
+
function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
200
|
+
let scriptExtension;
|
|
201
|
+
let entrypointFields;
|
|
202
|
+
const processingModules = webpackConfig.output?.module ?? false;
|
|
203
|
+
if (processingModules) {
|
|
204
|
+
scriptExtension = scriptWithModuleExtension;
|
|
205
|
+
entrypointFields = ["viewScriptModule", "scriptModule"];
|
|
205
206
|
}
|
|
207
|
+
else {
|
|
208
|
+
scriptExtension = scriptWithoutModuleExtension;
|
|
209
|
+
entrypointFields = ["editorStyle", "style", "editorScript", "viewScript", "script"];
|
|
210
|
+
}
|
|
211
|
+
const { standaloneBlocks, variablesFilePath, verbose } = config;
|
|
212
|
+
let currentVariables = config.currentVariables;
|
|
206
213
|
disableDefaultURLProcessing(webpackConfig);
|
|
207
|
-
injectPostcssConfigOverrides(webpackConfig, name => currentVariables[name], verbose);
|
|
208
|
-
const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
|
|
214
|
+
const fixedRules = injectPostcssConfigOverrides(webpackConfig, name => currentVariables[name], verbose, processingModules);
|
|
209
215
|
return sources.map(([src, dest]) => {
|
|
210
|
-
const srcRoots = typeof dest !== 'string' && dest.withLegacyBlocksIn
|
|
216
|
+
const srcRoots = (typeof dest !== 'string' && dest.withLegacyBlocksIn
|
|
211
217
|
? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(dest.withLegacyBlocksIn)]
|
|
212
|
-
: src.split(',');
|
|
218
|
+
: src.split(',')).filter(s => s.endsWith(".json") || !s.substring(s.lastIndexOf('/')).includes('.') || processingModules === scriptWithModuleExtension.test(s));
|
|
213
219
|
const destPath = typeof dest === 'string' ? dest : dest.destination;
|
|
214
220
|
const srcRoot = srcRoots.length === 1 ? joinPossiblyAbsolutePaths(process.cwd(), src) : srcRoots.map(s => joinPossiblyAbsolutePaths(process.cwd(), s));
|
|
215
221
|
const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot).isDirectory();
|
|
@@ -217,7 +223,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
217
223
|
const plugins = webpackConfig.plugins?.filter(isTruthy) ?? [];
|
|
218
224
|
if (process.env["NO_TS_CHECKER"] !== "true") {
|
|
219
225
|
const include = (Array.isArray(srcRoot) ? srcRoot : [srcRoot])
|
|
220
|
-
.filter(sr => node_path_1.default.extname(sr).length === 0 || scriptOrStyleTest(sr) === "script")
|
|
226
|
+
.filter(sr => node_path_1.default.extname(sr).length === 0 || scriptOrStyleTest(sr, scriptExtension) === "script")
|
|
221
227
|
.map(sr => node_path_1.default.extname(sr).length > 0 ? sr : node_path_1.default.join(sr, "**", "*"));
|
|
222
228
|
if (include.length > 0) {
|
|
223
229
|
plugins.push(new fork_ts_checker_webpack_plugin_1.default({
|
|
@@ -233,6 +239,11 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
233
239
|
skipLibCheck: true
|
|
234
240
|
}
|
|
235
241
|
}
|
|
242
|
+
},
|
|
243
|
+
issue: {
|
|
244
|
+
exclude(issue) {
|
|
245
|
+
return issue.code === 'TS18003'; // This hides the "no TypeScript files found" error while still monitoring the directory
|
|
246
|
+
}
|
|
236
247
|
}
|
|
237
248
|
}));
|
|
238
249
|
}
|
|
@@ -245,9 +256,9 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
245
256
|
plugins.push(new VariablesJSMonitorPlugin_1.default(variablesFilePath));
|
|
246
257
|
}
|
|
247
258
|
if (copyFiles && (typeof dest === 'string' || dest.directoryLayout !== 'extensions')) {
|
|
248
|
-
plugins.push(new BlockJSONManagingPlugin_1.default(standaloneBlocks));
|
|
259
|
+
plugins.push(new BlockJSONManagingPlugin_1.default(standaloneBlocks, processingModules));
|
|
249
260
|
}
|
|
250
|
-
plugins.push(new AdditionalDependencyInjectorPlugin_1.default(typeof dest !== 'string' && dest.additionalDependencies ? dest.additionalDependencies : []));
|
|
261
|
+
plugins.push(new AdditionalDependencyInjectorPlugin_1.default(typeof dest !== 'string' && dest.additionalDependencies ? dest.additionalDependencies : [], processingModules));
|
|
251
262
|
if (srcIsDirectory && (typeof dest !== 'string' && dest.directoryLayout === 'extensions')) {
|
|
252
263
|
plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.default(srcRoot));
|
|
253
264
|
}
|
|
@@ -274,7 +285,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
274
285
|
const res = [];
|
|
275
286
|
try {
|
|
276
287
|
const blockJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'block.json'), 'utf8'));
|
|
277
|
-
for (const key of
|
|
288
|
+
for (const key of entrypointFields) {
|
|
278
289
|
if (key in blockJSON) {
|
|
279
290
|
res.push(...mapToRealEntrypoints(blockJSON[key], dir, ep => ep.startsWith("file:") ? ep.substring(5) : ep));
|
|
280
291
|
}
|
|
@@ -307,7 +318,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
307
318
|
else {
|
|
308
319
|
const typeCounts = {};
|
|
309
320
|
for (const entrypoint of groupedEntrypoints) {
|
|
310
|
-
addPotentiallyDuplicatedEntrypointName(currentEntry, entrypoint, typeCounts);
|
|
321
|
+
addPotentiallyDuplicatedEntrypointName(currentEntry, entrypoint, typeCounts, scriptExtension);
|
|
311
322
|
}
|
|
312
323
|
}
|
|
313
324
|
}
|
|
@@ -343,7 +354,15 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
343
354
|
chunkFilename: 'webpack-chunks/[id].js',
|
|
344
355
|
publicPath: publicPath
|
|
345
356
|
},
|
|
346
|
-
|
|
357
|
+
module: {
|
|
358
|
+
...webpackConfig.module,
|
|
359
|
+
rules: fixedRules
|
|
360
|
+
},
|
|
361
|
+
resolve: {
|
|
362
|
+
...webpackConfig.resolve,
|
|
363
|
+
extensions: processingModules ? ['.mjsx', '.mjs', '.mtsx', '.mts'] : ['.jsx', '.tsx', '.ts', '...']
|
|
364
|
+
},
|
|
365
|
+
stats: config.stats,
|
|
347
366
|
plugins: copyFiles
|
|
348
367
|
? plugins.map(plugin => plugin.constructor.name === 'CopyPlugin'
|
|
349
368
|
? new copy_webpack_plugin_1.default({ patterns: [{ from: standaloneBlocks ? '**/(block.json|*.(php|twig|svg))' : '**/(block.json|*.(asset\.php|svg))',
|
|
@@ -361,4 +380,19 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
361
380
|
}
|
|
362
381
|
};
|
|
363
382
|
});
|
|
383
|
+
}
|
|
384
|
+
module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
|
|
385
|
+
testForDuplicatedEntryPaths(config);
|
|
386
|
+
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true' } = config;
|
|
387
|
+
let variablesFilePath = undefined;
|
|
388
|
+
const currentVariables = rawVariables ?? {};
|
|
389
|
+
if (!rawVariables) {
|
|
390
|
+
variablesFilePath = ["variables.js", "src/site/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p))[0];
|
|
391
|
+
}
|
|
392
|
+
const cfg = { currentVariables, standaloneBlocks, stats, variablesFilePath, verbose };
|
|
393
|
+
const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
|
|
394
|
+
if (Array.isArray(webpackConfig)) {
|
|
395
|
+
return webpackConfig.flatMap(wpCfg => processIndividualWebpackConfig(cfg, wpCfg, sources));
|
|
396
|
+
}
|
|
397
|
+
return processIndividualWebpackConfig(cfg, webpackConfig, sources);
|
|
364
398
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
@@ -19,28 +19,28 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/browser-sync-webpack-plugin": "^2.2.5",
|
|
22
|
-
"@types/node": "^20.
|
|
22
|
+
"@types/node": "^20.12.10",
|
|
23
23
|
"@types/tapable": "^2.2.7",
|
|
24
24
|
"@types/webpack": "^5.28.5",
|
|
25
25
|
"@types/webpack-sources": "^3.2.3",
|
|
26
26
|
"postcss-load-config": "^4.0.2",
|
|
27
27
|
"postcss-loader": "^7.3.4",
|
|
28
28
|
"ts-node": "^10.9.2",
|
|
29
|
-
"typescript": "^5.4.
|
|
29
|
+
"typescript": "^5.4.5"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@plaudit/postcss-color-function": "^5.0.0",
|
|
33
33
|
"@plaudit/postcss-silent-extend": "^3.0.0",
|
|
34
34
|
"@plaudit/postcss-strip-units": "^3.0.0",
|
|
35
35
|
"@plaudit/postcss-variables": "^1.0.0",
|
|
36
|
-
"@wordpress/scripts": "^27.
|
|
37
|
-
"autoprefixer": "^10.4.
|
|
36
|
+
"@wordpress/scripts": "^27.8.0",
|
|
37
|
+
"autoprefixer": "^10.4.19",
|
|
38
38
|
"browser-sync": "^3.0.2",
|
|
39
39
|
"clean-webpack-plugin": "^4.0.0",
|
|
40
40
|
"copy-webpack-plugin": "^12.0.2",
|
|
41
|
-
"cssnano": "^6.1.
|
|
41
|
+
"cssnano": "^6.1.2",
|
|
42
42
|
"eslint": "^8.57.0",
|
|
43
|
-
"eslint-plugin-jsdoc": "^48.2.
|
|
43
|
+
"eslint-plugin-jsdoc": "^48.2.3",
|
|
44
44
|
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
|
45
45
|
"http-proxy-middleware": "^3.0.0-beta.1",
|
|
46
46
|
"postcss": "^8.4.38",
|