@plaudit/webpack-extensions 2.54.0 → 2.55.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 → plugins}/AdditionalDependencyInjectorPlugin.js +3 -3
- package/build/{wordpress-scripts-wrapper → plugins}/BlockJSONManagingPlugin.d.ts +4 -2
- package/build/{wordpress-scripts-wrapper → plugins}/BlockJSONManagingPlugin.js +14 -9
- package/build/{wordpress-scripts-wrapper → plugins}/ExtensionsConfigFileGeneratorPlugin.d.ts +6 -3
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +173 -0
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +24 -0
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +244 -0
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +12 -0
- package/build/plugins/SpecialAssetHandlingPlugin.js +135 -0
- package/build/{wordpress-scripts-wrapper → plugins}/VariablesJSMonitorPlugin.js +1 -1
- package/build/{wordpress-scripts-wrapper → plugins}/WPMLConfigBuilder.d.ts +3 -2
- package/build/{wordpress-scripts-wrapper → plugins}/WPMLConfigBuilder.js +7 -3
- package/build/{wordpress-scripts-wrapper → plugins}/dependency-extraction-webpack-plugin-config-builder.d.ts +1 -7
- package/build/shared.d.ts +45 -18
- package/build/shared.js +18 -5
- package/build/utils/common-config-helpers.d.ts +26 -0
- package/build/utils/common-config-helpers.js +336 -0
- package/build/{wordpress-scripts-wrapper → utils}/php-serializer.d.ts +1 -1
- package/build/{wordpress-scripts-wrapper → utils}/php-serializer.js +1 -1
- package/build/utils/php-writer.d.ts +54 -0
- package/build/utils/php-writer.js +191 -0
- package/build/utils/pseduo-semaphore.d.ts +13 -0
- package/build/utils/pseduo-semaphore.js +63 -0
- package/build/wordpress-scripts-wrapper.d.ts +1 -20
- package/build/wordpress-scripts-wrapper.js +232 -443
- package/package.json +4 -4
- package/build/wordpress-scripts-wrapper/ExtensionsConfigFileGeneratorPlugin.js +0 -125
- package/build/wordpress-scripts-wrapper/SpecialAssetHandlingPlugin.d.ts +0 -7
- package/build/wordpress-scripts-wrapper/SpecialAssetHandlingPlugin.js +0 -107
- /package/build/{wordpress-scripts-wrapper → plugins}/AdditionalDependencyInjectorPlugin.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/BrowserSyncPlugin.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/BrowserSyncPlugin.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/MiniCSSExtractPluginErrorCleaner.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/MiniCSSExtractPluginErrorCleaner.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/PackageConfigSanityChecker.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/PackageConfigSanityChecker.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/VariablesJSMonitorPlugin.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/dependency-extraction-webpack-plugin-config-builder.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/static-configs.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/static-configs.js +0 -0
- /package/build/{wordpress-scripts-wrapper → utils}/json-to-php-but-with-__-injection.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → utils}/json-to-php-but-with-__-injection.js +0 -0
|
@@ -6,51 +6,22 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
6
6
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const shared_1 = require("./shared");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
9
|
+
const common_config_helpers_1 = require("./utils/common-config-helpers");
|
|
10
|
+
const AdditionalDependencyInjectorPlugin_1 = require("./plugins/AdditionalDependencyInjectorPlugin");
|
|
11
|
+
const BlockJSONManagingPlugin_1 = require("./plugins/BlockJSONManagingPlugin");
|
|
12
|
+
const BrowserSyncPlugin_1 = require("./plugins/BrowserSyncPlugin");
|
|
13
|
+
const ExtensionsConfigFileGeneratorPlugin_1 = require("./plugins/ExtensionsConfigFileGeneratorPlugin");
|
|
14
|
+
const MiniCSSExtractPluginErrorCleaner_1 = require("./plugins/MiniCSSExtractPluginErrorCleaner");
|
|
15
|
+
const PackageConfigSanityChecker_1 = require("./plugins/PackageConfigSanityChecker");
|
|
16
|
+
const PlainEntrypointsConfigFileGeneratorPlugin_1 = require("./plugins/PlainEntrypointsConfigFileGeneratorPlugin");
|
|
17
|
+
const SpecialAssetHandlingPlugin_1 = require("./plugins/SpecialAssetHandlingPlugin");
|
|
18
|
+
const VariablesJSMonitorPlugin_1 = require("./plugins/VariablesJSMonitorPlugin");
|
|
19
|
+
const WPMLConfigBuilder_1 = require("./plugins/WPMLConfigBuilder");
|
|
20
|
+
const static_configs_1 = require("./plugins/static-configs");
|
|
21
|
+
const dependency_extraction_webpack_plugin_config_builder_1 = require("./plugins/dependency-extraction-webpack-plugin-config-builder");
|
|
20
22
|
const dependency_extraction_webpack_plugin_1 = __importDefault(require("@wordpress/dependency-extraction-webpack-plugin"));
|
|
21
|
-
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
22
23
|
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
23
24
|
const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
|
|
24
|
-
function joinPossiblyAbsolutePaths(...paths) {
|
|
25
|
-
return paths.filter((p) => !!p)
|
|
26
|
-
.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
|
|
27
|
-
}
|
|
28
|
-
function mapToRealEntrypoints(entrypoint, dir, mapper = (entrypoint) => entrypoint, lazyDependent, associatedQuery) {
|
|
29
|
-
return (Array.isArray(entrypoint) ? entrypoint : [entrypoint])
|
|
30
|
-
.map(ep => joinPossiblyAbsolutePaths(dir, mapper(ep)))
|
|
31
|
-
.filter(ep => node_fs_1.default.statSync(ep, { throwIfNoEntry: false })?.isFile())
|
|
32
|
-
.map(ep => {
|
|
33
|
-
const parsedEntrypoint = node_path_1.default.parse(ep);
|
|
34
|
-
return [joinPossiblyAbsolutePaths(node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name), { import: ep, lazyDependent, associatedQuery }];
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
let isInThemeCache = undefined;
|
|
38
|
-
function isInTheme() {
|
|
39
|
-
return isInThemeCache ?? (isInThemeCache = node_fs_1.default.existsSync(node_path_1.default.join(process.cwd(), "theme.json")));
|
|
40
|
-
}
|
|
41
|
-
function groupEntrypointsByAssetFile(entrypoints, entrypointNameExtractor) {
|
|
42
|
-
const seenPaths = new Map();
|
|
43
|
-
for (const entrypoint of entrypoints) {
|
|
44
|
-
const entrypointName = entrypointNameExtractor(entrypoint);
|
|
45
|
-
const key = entrypointName.substring(0, entrypointName.length - node_path_1.default.extname(entrypointName).length);
|
|
46
|
-
let seen = seenPaths.get(key);
|
|
47
|
-
if (seen === undefined) {
|
|
48
|
-
seenPaths.set(key, seen = []);
|
|
49
|
-
}
|
|
50
|
-
seen.push(entrypoint);
|
|
51
|
-
}
|
|
52
|
-
return seenPaths;
|
|
53
|
-
}
|
|
54
25
|
function resolveLegacyBlockScriptsInFolder(folder) {
|
|
55
26
|
const blockScriptEntrypoints = [];
|
|
56
27
|
for (const blockDir of node_fs_1.default.readdirSync(folder)) {
|
|
@@ -65,52 +36,8 @@ function resolveLegacyBlockScriptsInFolder(folder) {
|
|
|
65
36
|
}
|
|
66
37
|
return blockScriptEntrypoints;
|
|
67
38
|
}
|
|
68
|
-
const scriptWithoutModuleExtension = /\.[jt]sx?$/;
|
|
69
|
-
const scriptWithModuleExtension = /\.m[jt]sx?$/;
|
|
70
|
-
const styleExtension = /\.(p?c|sa)ss$/;
|
|
71
|
-
function scriptOrStyleTest(entryPath, scriptExtension) {
|
|
72
|
-
return scriptExtension.test(entryPath) ? "script" : (styleExtension.test(entryPath) ? "style" : "");
|
|
73
|
-
}
|
|
74
|
-
function determineEntrypointType(entrypoint, scriptExtension) {
|
|
75
|
-
let res = scriptOrStyleTest(entrypoint[0], scriptExtension);
|
|
76
|
-
if (res) {
|
|
77
|
-
return res;
|
|
78
|
-
}
|
|
79
|
-
if (typeof entrypoint[1] === 'string') {
|
|
80
|
-
return scriptOrStyleTest(entrypoint[1], scriptExtension);
|
|
81
|
-
}
|
|
82
|
-
else if (Array.isArray(entrypoint[1])) {
|
|
83
|
-
return entrypoint[1].reduce((prior, ep) => prior || scriptOrStyleTest(ep, scriptExtension), "");
|
|
84
|
-
}
|
|
85
|
-
else if (typeof entrypoint[1].import === 'string') {
|
|
86
|
-
return scriptOrStyleTest(entrypoint[1].import, scriptExtension);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return entrypoint[1].import.reduce((prior, ep) => prior || scriptOrStyleTest(ep, scriptExtension), "");
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function injectTypeAndCountToEntrypointName(entrypointName, type, typeCounts) {
|
|
93
|
-
const entrypointBasename = entrypointName.substring(0, entrypointName.length - node_path_1.default.extname(entrypointName).length);
|
|
94
|
-
const parts = [];
|
|
95
|
-
if (type) {
|
|
96
|
-
parts.push(type);
|
|
97
|
-
}
|
|
98
|
-
if (typeCounts[type] ?? (typeCounts[type] = 0)) {
|
|
99
|
-
parts.push(typeCounts[type].toString());
|
|
100
|
-
}
|
|
101
|
-
typeCounts[type] += 1;
|
|
102
|
-
return `${entrypointBasename}_${parts.join('-')}${node_path_1.default.extname(entrypointName)}`;
|
|
103
|
-
}
|
|
104
|
-
function addPotentiallyDuplicatedEntrypointName(entry, entrypoint, typeCounts, scriptExtension) {
|
|
105
|
-
const type = determineEntrypointType(entrypoint, scriptExtension);
|
|
106
|
-
let potentialKey = injectTypeAndCountToEntrypointName(entrypoint[0], type, typeCounts);
|
|
107
|
-
while (entry[potentialKey]) {
|
|
108
|
-
potentialKey = injectTypeAndCountToEntrypointName(entrypoint[0], type, typeCounts);
|
|
109
|
-
}
|
|
110
|
-
entry[potentialKey] = entrypoint[1];
|
|
111
|
-
}
|
|
112
39
|
function testForDuplicatedEntryPaths(config) {
|
|
113
|
-
const seenPaths = groupEntrypointsByAssetFile(Array.isArray(config.src) ? config.src : Object.values(config.src).map(bn => typeof bn === 'string' ? bn : bn.destination), bn => bn);
|
|
40
|
+
const seenPaths = (0, common_config_helpers_1.groupEntrypointsByAssetFile)(Array.isArray(config.src) ? config.src : Object.values(config.src).map(bn => typeof bn === 'string' ? bn : bn.destination), bn => bn);
|
|
114
41
|
let projectPrefix = undefined;
|
|
115
42
|
let duplicatedPaths = "";
|
|
116
43
|
for (const sameNamePaths of seenPaths.values()) {
|
|
@@ -167,7 +94,7 @@ function replaceDefaultURLProcessing(useWebpackResourceFiltering) {
|
|
|
167
94
|
return rules;
|
|
168
95
|
};
|
|
169
96
|
}
|
|
170
|
-
function injectPostcssConfigOverrides(rules, variables, postcssFunctionsConfig, verbose) {
|
|
97
|
+
function injectPostcssConfigOverrides(rules, config, variables, postcssFunctionsConfig, verbose) {
|
|
171
98
|
const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, name => variables(name) ?? (name === 'ENV' ? '' : undefined), postcssFunctionsConfig);
|
|
172
99
|
return recursivelyAddParentDirectoryStepToImagesAndFonts(rules.map(rule => {
|
|
173
100
|
if (rule && typeof rule === 'object') {
|
|
@@ -203,9 +130,12 @@ function injectPostcssConfigOverrides(rules, variables, postcssFunctionsConfig,
|
|
|
203
130
|
}
|
|
204
131
|
}
|
|
205
132
|
return rule;
|
|
206
|
-
}));
|
|
133
|
+
}), config);
|
|
207
134
|
}
|
|
208
|
-
function recursivelyAddParentDirectoryStepToImagesAndFonts(rules) {
|
|
135
|
+
function recursivelyAddParentDirectoryStepToImagesAndFonts(rules, config) {
|
|
136
|
+
if (config.outputDir) {
|
|
137
|
+
return rules;
|
|
138
|
+
}
|
|
209
139
|
return rules.map(rule => {
|
|
210
140
|
if (rule && typeof rule === 'object') {
|
|
211
141
|
if (typeof rule.generator === 'object') {
|
|
@@ -216,7 +146,7 @@ function recursivelyAddParentDirectoryStepToImagesAndFonts(rules) {
|
|
|
216
146
|
}
|
|
217
147
|
}
|
|
218
148
|
if (rule.oneOf) {
|
|
219
|
-
rule = { ...rule, oneOf: recursivelyAddParentDirectoryStepToImagesAndFonts(rule.oneOf) };
|
|
149
|
+
rule = { ...rule, oneOf: recursivelyAddParentDirectoryStepToImagesAndFonts(rule.oneOf, config) };
|
|
220
150
|
}
|
|
221
151
|
}
|
|
222
152
|
return rule;
|
|
@@ -235,49 +165,156 @@ function injectSupportForInliningSVGsAsStrings(rules) {
|
|
|
235
165
|
return rule;
|
|
236
166
|
});
|
|
237
167
|
}
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
168
|
+
function buildVerifiedConfig(config) {
|
|
169
|
+
testForDuplicatedEntryPaths(config);
|
|
170
|
+
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, outputDir = "", extensionsVersion = 1, plainEntrypointsHandlePrefix = "", plainEntrypointsVersion = 1, srcDir = "" } = config;
|
|
171
|
+
if (plainEntrypointsVersion > 1) {
|
|
172
|
+
if (!plainEntrypointsHandlePrefix) {
|
|
173
|
+
throw new Error("Plain Entrypoints V2 and higher require 'plainEntrypointsHandlePrefix' to be set");
|
|
174
|
+
}
|
|
175
|
+
if (!outputDir) {
|
|
176
|
+
throw new Error("Plain Entrypoints V2 and higher require 'outputDir' to be set");
|
|
177
|
+
}
|
|
242
178
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
179
|
+
let variablesFilePath = undefined;
|
|
180
|
+
const currentVariables = rawVariables ?? {};
|
|
181
|
+
if (!rawVariables) {
|
|
182
|
+
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];
|
|
183
|
+
}
|
|
184
|
+
const cfg = {
|
|
185
|
+
currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, processTranslationConfigs, combineAssetMetadata,
|
|
186
|
+
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, plainEntrypointsHandlePrefix, srcDir
|
|
187
|
+
};
|
|
188
|
+
const sources = (Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src))
|
|
189
|
+
.map(entry => {
|
|
190
|
+
let dest = typeof entry[1] === 'string' ? { destination: entry[1] } : entry[1];
|
|
191
|
+
if (srcDir) {
|
|
192
|
+
return [node_path_1.default.join(srcDir, entry[0]), dest];
|
|
193
|
+
}
|
|
194
|
+
const relativeSrc = node_path_1.default.isAbsolute(entry[0]) ? node_path_1.default.relative(process.cwd(), entry[0]) : entry[0];
|
|
195
|
+
if (node_path_1.default.isAbsolute(dest.destination)) {
|
|
196
|
+
dest = { ...dest, destination: node_path_1.default.relative(process.cwd(), dest.destination) };
|
|
197
|
+
}
|
|
198
|
+
return [relativeSrc, dest];
|
|
199
|
+
});
|
|
200
|
+
return cfg.outputDir ? { cfg, sources } : withDerivedOutputDir(cfg, sources);
|
|
201
|
+
}
|
|
202
|
+
function withDerivedOutputDir(cfg, sources) {
|
|
203
|
+
const destinations = sources.map(([_, { destination }]) => destination.split(/[\/\\]/g));
|
|
204
|
+
if (destinations.length < 2) {
|
|
205
|
+
return { cfg, sources };
|
|
206
|
+
}
|
|
207
|
+
const commonParent = destinations[0][0];
|
|
208
|
+
for (const destination of destinations) {
|
|
209
|
+
if (destination[0] !== commonParent) {
|
|
210
|
+
return { cfg, sources };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
cfg: { ...cfg, outputDir: commonParent },
|
|
215
|
+
sources: sources.map(([src, dest]) => {
|
|
216
|
+
return [src, { ...dest, destination: dest.destination.substring(commonParent.length + 1) }];
|
|
217
|
+
})
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins) {
|
|
221
|
+
if (process.env["NO_TS_CHECKER"] !== "true") {
|
|
222
|
+
const include = (Array.isArray(srcRoot) ? srcRoot : [srcRoot])
|
|
223
|
+
.filter(sr => node_path_1.default.extname(sr).length === 0 || (0, common_config_helpers_1.scriptOrStyleTest)(sr, scriptExtension) === "script")
|
|
224
|
+
.map(sr => node_path_1.default.extname(sr).length > 0 ? sr : node_path_1.default.join(sr, "**", "*"));
|
|
225
|
+
if (include.length > 0) {
|
|
226
|
+
plugins.push(new fork_ts_checker_webpack_plugin_1.default({
|
|
227
|
+
async: true,
|
|
228
|
+
typescript: {
|
|
229
|
+
diagnosticOptions: {
|
|
230
|
+
semantic: true,
|
|
231
|
+
syntactic: true,
|
|
232
|
+
},
|
|
233
|
+
configOverwrite: {
|
|
234
|
+
include,
|
|
235
|
+
compilerOptions: {
|
|
236
|
+
skipLibCheck: true
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
issue: {
|
|
241
|
+
exclude(issue) {
|
|
242
|
+
return issue.code === 'TS18003'; // This hides the "no TypeScript files found" error while still monitoring the directory
|
|
243
|
+
}
|
|
254
244
|
}
|
|
255
|
-
|
|
256
|
-
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest, config, sourceType) {
|
|
250
|
+
const { assumeGlobalizedPlauditLibraries, combineAssetMetadata, externals, extensionsVersion, plainEntrypointsVersion, variablesFilePath } = config;
|
|
251
|
+
const processingModules = webpackConfig.output?.module ?? false;
|
|
252
|
+
const plugins = webpackConfig.plugins?.filter(v => !!v)
|
|
253
|
+
.filter(plugin => plugin.constructor.name !== 'RtlCssPlugin')
|
|
254
|
+
.map(plugin => {
|
|
255
|
+
if (plugin.constructor.name === 'MiniCssExtractPlugin') {
|
|
256
|
+
return new plugin.constructor({
|
|
257
|
+
filename(pd) {
|
|
258
|
+
const name = pd.chunk?.name?.replaceAll(/__[a-zA-Z0-9]+__/g, ""); // This removes the prefix that the cache group adds
|
|
259
|
+
return name ? `${name}.css` : "[name].css";
|
|
257
260
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
return plugin;
|
|
264
|
+
})
|
|
265
|
+
?? [];
|
|
266
|
+
plugins.splice(0, 0, new PackageConfigSanityChecker_1.PackageConfigSanityChecker());
|
|
267
|
+
if (typeof dest !== 'string' && dest.bundleAnalyzer) {
|
|
268
|
+
plugins.splice(0, 0, new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({ analyzerMode: 'static' }));
|
|
269
|
+
}
|
|
270
|
+
handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins);
|
|
271
|
+
const removeEmptyScriptsPlugin = new webpack_remove_empty_scripts_1.default({
|
|
272
|
+
stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
|
|
273
|
+
extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss']
|
|
274
|
+
});
|
|
275
|
+
plugins.push(removeEmptyScriptsPlugin, new MiniCSSExtractPluginErrorCleaner_1.MiniCSSExtractPluginErrorCleaner());
|
|
276
|
+
if (config.useWebpackResourceFiltering) {
|
|
277
|
+
plugins.push(new SpecialAssetHandlingPlugin_1.SpecialAssetHandlingPlugin(config.outputDir));
|
|
278
|
+
}
|
|
279
|
+
if (variablesFilePath) {
|
|
280
|
+
plugins.push(new VariablesJSMonitorPlugin_1.VariablesJSMonitorPlugin(variablesFilePath));
|
|
281
|
+
}
|
|
282
|
+
const pluginIndex = plugins.findIndex(plugin => plugin instanceof dependency_extraction_webpack_plugin_1.default);
|
|
283
|
+
if (pluginIndex === -1) {
|
|
284
|
+
console.error("Cannot apply externals when they have been disabled via CLI flag. This will greatly increase bundle size and will likely cause the build to fail");
|
|
261
285
|
}
|
|
286
|
+
else {
|
|
287
|
+
const localAssumeGlobalizedPlauditLibraries = (typeof dest !== 'string' ? dest.assumeGlobalizedPlauditLibraries : undefined) ?? assumeGlobalizedPlauditLibraries;
|
|
288
|
+
const wantsGroupedDepData = combineAssetMetadata
|
|
289
|
+
&& ((!processingModules && sourceType === "blocks" /* SourceType.blocks */)
|
|
290
|
+
|| (extensionsVersion > 1 && sourceType === "extensions" /* SourceType.extensions */)
|
|
291
|
+
|| (plainEntrypointsVersion > 1 && sourceType === "plain" /* SourceType.plain */));
|
|
292
|
+
const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, localAssumeGlobalizedPlauditLibraries, wantsGroupedDepData, typeof dest !== 'string' ? dest.externalize : undefined);
|
|
293
|
+
plugins[pluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
|
|
294
|
+
plugins.push(new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(typeof dest !== 'string' && dest.additionalDependencies ? dest.additionalDependencies : [], processingModules, builtDependencyExtractionWebpackPlugin.addExternalizedDep));
|
|
295
|
+
}
|
|
296
|
+
if (process.argv.includes('--browser-sync') || process.env['BROWSER_SYNC'] === 'true') {
|
|
297
|
+
plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin());
|
|
298
|
+
}
|
|
299
|
+
return { plugins, removeEmptyScriptsPlugin };
|
|
262
300
|
}
|
|
263
|
-
function
|
|
301
|
+
function commonConfigProcessingPrep(config, webpackConfig) {
|
|
264
302
|
let scriptExtension; // This is only used in non-block contexts. It might not actually be necessary, but it is good to have
|
|
265
303
|
let entrypointFields;
|
|
266
|
-
const processingModules = webpackConfig.output?.module
|
|
304
|
+
const processingModules = webpackConfig.output?.module;
|
|
267
305
|
if (processingModules) {
|
|
268
|
-
scriptExtension = scriptWithModuleExtension;
|
|
306
|
+
scriptExtension = common_config_helpers_1.scriptWithModuleExtension;
|
|
269
307
|
entrypointFields = ["viewScriptModule", "scriptModule"];
|
|
270
308
|
}
|
|
271
309
|
else {
|
|
272
|
-
scriptExtension = scriptWithoutModuleExtension;
|
|
310
|
+
scriptExtension = common_config_helpers_1.scriptWithoutModuleExtension;
|
|
273
311
|
entrypointFields = ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script"];
|
|
274
312
|
}
|
|
275
|
-
const { standaloneBlocks, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, combineAssetMetadata, extensionsVersion } = config;
|
|
276
313
|
let currentVariables = config.currentVariables;
|
|
277
314
|
const fixedRules = [
|
|
278
315
|
replaceDefaultURLProcessing(config.useWebpackResourceFiltering),
|
|
279
316
|
(rules) => {
|
|
280
|
-
return injectPostcssConfigOverrides(rules, name => currentVariables[name], config.postcss.functions ?? (() => ({})), verbose);
|
|
317
|
+
return injectPostcssConfigOverrides(rules, config, name => currentVariables[name], config.postcss.functions ?? (() => ({})), config.verbose);
|
|
281
318
|
},
|
|
282
319
|
injectSupportForInliningSVGsAsStrings
|
|
283
320
|
].reduce((r, a) => a(r), webpackConfig.module?.rules ?? []);
|
|
@@ -291,351 +328,103 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
|
|
|
291
328
|
}
|
|
292
329
|
});
|
|
293
330
|
}
|
|
331
|
+
return {
|
|
332
|
+
entrypointFields, fixedRules, processingModules, scriptExtension,
|
|
333
|
+
updateCurrentVariables: (value) => currentVariables = value
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
//TODO: Try using context to avoid needing to cobble dest paths together?
|
|
337
|
+
function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
338
|
+
const commonConfig = commonConfigProcessingPrep(config, webpackConfig);
|
|
339
|
+
const { processingModules, scriptExtension } = commonConfig;
|
|
294
340
|
return sources.map(([src, dest]) => {
|
|
295
|
-
const srcRoots = (
|
|
296
|
-
? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(dest.withLegacyBlocksIn)]
|
|
297
|
-
: src.split(',')).filter(s => s.endsWith(".json") || !s.substring(s.lastIndexOf('/')).includes('.') || processingModules === scriptWithModuleExtension.test(s));
|
|
298
|
-
const
|
|
299
|
-
const srcRoot = srcRoots.length === 1 ? joinPossiblyAbsolutePaths(process.cwd(), src) : srcRoots.map(s => joinPossiblyAbsolutePaths(process.cwd(), s));
|
|
341
|
+
const srcRoots = (dest.withLegacyBlocksIn
|
|
342
|
+
? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(node_path_1.default.join(config.srcDir, dest.withLegacyBlocksIn))]
|
|
343
|
+
: src.split(',')).filter(s => s.endsWith(".json") || !s.substring(s.lastIndexOf('/')).includes('.') || processingModules === common_config_helpers_1.scriptWithModuleExtension.test(s));
|
|
344
|
+
const srcRoot = srcRoots.length < 2 ? (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(process.cwd(), src) : srcRoots.map(s => (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(process.cwd(), s));
|
|
300
345
|
const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot, { throwIfNoEntry: false })?.isDirectory();
|
|
301
346
|
if (srcIsDirectory === undefined) {
|
|
302
347
|
return undefined;
|
|
303
348
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
.map(plugin => {
|
|
309
|
-
if (plugin.constructor.name === 'MiniCssExtractPlugin') {
|
|
310
|
-
return new plugin.constructor({
|
|
311
|
-
filename(pd) {
|
|
312
|
-
const name = pd.chunk?.name?.replaceAll(/__[a-zA-Z0-9]+__/g, ""); // This removes the prefix that the cache group adds
|
|
313
|
-
return name ? `${name}.css` : "[name].css";
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
return plugin;
|
|
318
|
-
})
|
|
319
|
-
?? [];
|
|
320
|
-
plugins.splice(0, 0, new PackageConfigSanityChecker_1.PackageConfigSanityChecker());
|
|
321
|
-
if (typeof dest !== 'string' && dest.bundleAnalyzer) {
|
|
322
|
-
plugins.splice(0, 0, new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({ analyzerMode: 'static' }));
|
|
323
|
-
}
|
|
324
|
-
if (process.env["NO_TS_CHECKER"] !== "true") {
|
|
325
|
-
const include = (Array.isArray(srcRoot) ? srcRoot : [srcRoot])
|
|
326
|
-
.filter(sr => node_path_1.default.extname(sr).length === 0 || scriptOrStyleTest(sr, scriptExtension) === "script")
|
|
327
|
-
.map(sr => node_path_1.default.extname(sr).length > 0 ? sr : node_path_1.default.join(sr, "**", "*"));
|
|
328
|
-
if (include.length > 0) {
|
|
329
|
-
plugins.push(new fork_ts_checker_webpack_plugin_1.default({
|
|
330
|
-
async: true,
|
|
331
|
-
typescript: {
|
|
332
|
-
diagnosticOptions: {
|
|
333
|
-
semantic: true,
|
|
334
|
-
syntactic: true,
|
|
335
|
-
},
|
|
336
|
-
configOverwrite: {
|
|
337
|
-
include,
|
|
338
|
-
compilerOptions: {
|
|
339
|
-
skipLibCheck: true
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
issue: {
|
|
344
|
-
exclude(issue) {
|
|
345
|
-
return issue.code === 'TS18003'; // This hides the "no TypeScript files found" error while still monitoring the directory
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}));
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
plugins.push(new webpack_remove_empty_scripts_1.default({
|
|
352
|
-
stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
|
|
353
|
-
extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss']
|
|
354
|
-
}), new MiniCSSExtractPluginErrorCleaner_1.MiniCSSExtractPluginErrorCleaner());
|
|
355
|
-
if (config.useWebpackResourceFiltering) {
|
|
356
|
-
plugins.push(new SpecialAssetHandlingPlugin_1.SpecialAssetHandlingPlugin(sharedCache));
|
|
357
|
-
}
|
|
358
|
-
if (variablesFilePath) {
|
|
359
|
-
plugins.push(new VariablesJSMonitorPlugin_1.VariablesJSMonitorPlugin(variablesFilePath));
|
|
360
|
-
}
|
|
361
|
-
if (sourceType === "blocks" /* SourceType.blocks */) {
|
|
362
|
-
const blockJSONManagingPlugin = new BlockJSONManagingPlugin_1.BlockJSONManagingPlugin(standaloneBlocks, processingModules);
|
|
363
|
-
plugins.push(blockJSONManagingPlugin);
|
|
364
|
-
if (config.processTranslationConfigs && srcIsDirectory && !processingModules) {
|
|
365
|
-
plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(blockJSONManagingPlugin));
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
const pluginIndex = plugins.findIndex(plugin => plugin instanceof dependency_extraction_webpack_plugin_1.default);
|
|
369
|
-
if (pluginIndex === -1) {
|
|
370
|
-
console.error("Cannot apply externals when they have been disabled via CLI flag. This will greatly increase bundle size and will likely cause the build to fail");
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
const localAssumeGlobalizedPlauditLibraries = (typeof dest !== 'string' ? dest.assumeGlobalizedPlauditLibraries : undefined) ?? assumeGlobalizedPlauditLibraries;
|
|
374
|
-
const wantsGroupedDepData = combineAssetMetadata
|
|
375
|
-
&& ((!processingModules && sourceType === "blocks" /* SourceType.blocks */) || (extensionsVersion > 1 && sourceType === "extensions" /* SourceType.extensions */));
|
|
376
|
-
const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, localAssumeGlobalizedPlauditLibraries, wantsGroupedDepData, typeof dest !== 'string' ? dest.externalize : undefined);
|
|
377
|
-
plugins[pluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
|
|
378
|
-
plugins.push(new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(typeof dest !== 'string' && dest.additionalDependencies ? dest.additionalDependencies : [], processingModules, builtDependencyExtractionWebpackPlugin.addExternalizedDep));
|
|
379
|
-
}
|
|
380
|
-
if (srcIsDirectory && sourceType === "extensions" /* SourceType.extensions */) {
|
|
381
|
-
plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(srcRoot, extensionsVersion, sharedCache));
|
|
382
|
-
}
|
|
383
|
-
if (process.argv.includes('--browser-sync') || process.env['BROWSER_SYNC'] === 'true') {
|
|
384
|
-
plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin());
|
|
385
|
-
}
|
|
386
|
-
let entry;
|
|
387
|
-
if (srcIsDirectory) {
|
|
388
|
-
if (typeof dest !== 'string' && dest.directoryLayout === 'extensions') {
|
|
389
|
-
entry = async () => {
|
|
390
|
-
const rawEntrypoints = [];
|
|
391
|
-
for await (const dirent of await promises_1.default.opendir(srcRoot)) {
|
|
392
|
-
if (dirent.isFile() && !dirent.name.startsWith("~")) {
|
|
393
|
-
if (scriptExtension.test(dirent.name) || styleExtension.test(dirent.name)) {
|
|
394
|
-
const file = joinPossiblyAbsolutePaths(srcRoot, dirent.name);
|
|
395
|
-
rawEntrypoints.push([node_path_1.default.basename(file, node_path_1.default.extname(file)), file]);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return Object.fromEntries(rawEntrypoints);
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
entry = async () => {
|
|
404
|
-
const loadingEntrypoints = [];
|
|
405
|
-
for await (const dirent of await promises_1.default.opendir(srcRoot)) {
|
|
406
|
-
if (!dirent.isDirectory()) {
|
|
407
|
-
continue;
|
|
408
|
-
}
|
|
409
|
-
const dir = joinPossiblyAbsolutePaths(srcRoot, dirent.name);
|
|
410
|
-
loadingEntrypoints.push(new Promise(async (resolve) => {
|
|
411
|
-
const rawEntrypoints = [];
|
|
412
|
-
const wpmlFiles = [];
|
|
413
|
-
try {
|
|
414
|
-
const blockJSON = JSON.parse(await promises_1.default.readFile(node_path_1.default.join(dir, 'block.json'), 'utf8'));
|
|
415
|
-
const blockJSONChunkName = node_path_1.default.join(node_path_1.default.basename(dir), "block.json");
|
|
416
|
-
for (const key of entrypointFields) {
|
|
417
|
-
if (key in blockJSON) {
|
|
418
|
-
rawEntrypoints.push(...mapToRealEntrypoints(blockJSON[key], dir, ep => ep.startsWith("file:") ? ep.substring(5) : ep, blockJSONChunkName));
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
wpmlFiles.push(node_path_1.default.join(dir, 'block.json'));
|
|
422
|
-
BlockJSONManagingPlugin_1.BlockJSONManagingPlugin.recordBlockJSONAssetSourceDir(blockJSONChunkName, dir);
|
|
423
|
-
}
|
|
424
|
-
catch (e) {
|
|
425
|
-
try {
|
|
426
|
-
const packageJSON = JSON.parse(await promises_1.default.readFile(node_path_1.default.join(dir, 'package.json'), 'utf8'));
|
|
427
|
-
rawEntrypoints.push(...mapToRealEntrypoints(packageJSON['main'], dir));
|
|
428
|
-
rawEntrypoints.push(...mapToRealEntrypoints(packageJSON['style'], dir));
|
|
429
|
-
}
|
|
430
|
-
catch (e) {
|
|
431
|
-
try {
|
|
432
|
-
rawEntrypoints.push(...parseEntrypointsJSON(dir));
|
|
433
|
-
}
|
|
434
|
-
catch (e) {
|
|
435
|
-
// This just means that the directory doesn't contain any declared entrypoints.
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
if (!processingModules) {
|
|
440
|
-
try {
|
|
441
|
-
const wpmlFilePath = node_path_1.default.join(dir, "wpml-config.xml");
|
|
442
|
-
await promises_1.default.access(wpmlFilePath);
|
|
443
|
-
wpmlFiles.push(wpmlFilePath);
|
|
444
|
-
}
|
|
445
|
-
catch (e) {
|
|
446
|
-
// This just means that the file doesn't exist
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
resolve([rawEntrypoints, wpmlFiles]);
|
|
450
|
-
}));
|
|
451
|
-
}
|
|
452
|
-
const allEntrypoints = await Promise.all(loadingEntrypoints);
|
|
453
|
-
const perAssetPathGroupedEntrypoints = groupEntrypointsByAssetFile(allEntrypoints.flatMap(e => e[0]), e => e[0]);
|
|
454
|
-
const currentEntry = {};
|
|
455
|
-
for (const groupedEntrypoints of perAssetPathGroupedEntrypoints.values()) {
|
|
456
|
-
if (groupedEntrypoints.length === 1 && groupedEntrypoints[0] !== undefined) {
|
|
457
|
-
currentEntry[groupedEntrypoints[0][0]] = groupedEntrypoints[0][1];
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
460
|
-
const typeCounts = {};
|
|
461
|
-
for (const entrypoint of groupedEntrypoints) {
|
|
462
|
-
addPotentiallyDuplicatedEntrypointName(currentEntry, entrypoint, typeCounts, scriptExtension);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
// This is used to allow for block.json dependencies to correctly account for name-deduplication
|
|
467
|
-
for (const [key, entry] of Object.entries(currentEntry)) {
|
|
468
|
-
if (typeof entry === 'object' && !Array.isArray(entry) && 'lazyDependent' in entry && typeof entry.lazyDependent === 'string') {
|
|
469
|
-
BlockJSONManagingPlugin_1.BlockJSONManagingPlugin.recordRawDependency(entry.lazyDependent, key);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
if (!processingModules) {
|
|
473
|
-
const wpmlEntrypointFiles = allEntrypoints.flatMap(e => e[1]);
|
|
474
|
-
try {
|
|
475
|
-
await promises_1.default.access(node_path_1.default.join(srcRoot, "wpml-config.xml"));
|
|
476
|
-
currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles] };
|
|
477
|
-
}
|
|
478
|
-
catch (e) {
|
|
479
|
-
if (wpmlEntrypointFiles.length) {
|
|
480
|
-
currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles };
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return currentEntry;
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
const baseDest = node_path_1.default.basename(destPath);
|
|
490
|
-
entry = () => ({
|
|
491
|
-
[baseDest.includes('.') ? node_path_1.default.basename(baseDest, node_path_1.default.extname(baseDest)) : baseDest]: srcRoot
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
const outPath = joinPossiblyAbsolutePaths(process.cwd(), config.outputDir, srcIsDirectory ? destPath : node_path_1.default.dirname(destPath));
|
|
495
|
-
let publicPath = webpackConfig.output?.publicPath;
|
|
496
|
-
if (isInTheme()) {
|
|
497
|
-
let prefix = process.cwd();
|
|
498
|
-
while (prefix.length > 5 && node_path_1.default.basename(prefix) !== "wp-content") {
|
|
499
|
-
prefix = node_path_1.default.dirname(prefix);
|
|
500
|
-
}
|
|
501
|
-
if (prefix.length > 5) {
|
|
502
|
-
prefix = node_path_1.default.dirname(prefix);
|
|
503
|
-
publicPath = `/${node_path_1.default.relative(prefix, outPath)}/`;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
let viableRoots = [...(Array.isArray(webpackConfig.context) ? webpackConfig.context : [webpackConfig.context ?? process.cwd()])];
|
|
507
|
-
if (Array.isArray(srcRoot)) {
|
|
508
|
-
viableRoots.push(...(srcIsDirectory ? srcRoot : srcRoot.map(s => node_path_1.default.dirname(s))));
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
viableRoots.push(srcIsDirectory ? srcRoot : node_path_1.default.dirname(srcRoot));
|
|
512
|
-
}
|
|
513
|
-
let wpContentHolderDirectory = process.cwd();
|
|
514
|
-
while (wpContentHolderDirectory.length > 5) {
|
|
515
|
-
if (node_path_1.default.basename(wpContentHolderDirectory) === 'wp-content') {
|
|
516
|
-
wpContentHolderDirectory = node_path_1.default.dirname(wpContentHolderDirectory);
|
|
517
|
-
if (wpContentHolderDirectory.length > 5) {
|
|
518
|
-
viableRoots.push(wpContentHolderDirectory);
|
|
349
|
+
switch ((0, shared_1.determineCurrentSourceType)(dest, srcIsDirectory)) {
|
|
350
|
+
case "blocks" /* SourceType.blocks */: {
|
|
351
|
+
if (!srcIsDirectory) {
|
|
352
|
+
return undefined;
|
|
519
353
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
wpContentHolderDirectory = node_path_1.default.dirname(wpContentHolderDirectory);
|
|
523
|
-
}
|
|
524
|
-
const distinctViableRoots = new Set();
|
|
525
|
-
viableRoots = viableRoots.filter(value => distinctViableRoots.has(value) ? false : distinctViableRoots.add(value) && true);
|
|
526
|
-
let outputLibrary;
|
|
527
|
-
if (typeof dest === 'object' && dest.externalize) {
|
|
528
|
-
if (Array.isArray(dest.externalize) || typeof dest.externalize === 'string') {
|
|
529
|
-
outputLibrary = {
|
|
530
|
-
name: dest.externalize,
|
|
531
|
-
type: "assign"
|
|
532
|
-
};
|
|
354
|
+
const { plugins } = buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest, config, "blocks" /* SourceType.blocks */);
|
|
355
|
+
return makeBlocksWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins);
|
|
533
356
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
outputLibrary = {
|
|
538
|
-
...originalLibrary,
|
|
539
|
-
...dest.externalize
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
else {
|
|
543
|
-
outputLibrary = dest.externalize;
|
|
357
|
+
case "extensions" /* SourceType.extensions */: {
|
|
358
|
+
if (!srcIsDirectory) {
|
|
359
|
+
return undefined;
|
|
544
360
|
}
|
|
361
|
+
const { plugins } = buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest, config, "extensions" /* SourceType.extensions */);
|
|
362
|
+
return makeExtensionsWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins);
|
|
545
363
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
...webpackConfig,
|
|
552
|
-
devtool: 'source-map',
|
|
553
|
-
mode: "production",
|
|
554
|
-
output: {
|
|
555
|
-
...webpackConfig.output,
|
|
556
|
-
path: outPath,
|
|
557
|
-
chunkFilename: 'webpack-chunks/[id].js',
|
|
558
|
-
publicPath: publicPath,
|
|
559
|
-
library: outputLibrary
|
|
560
|
-
},
|
|
561
|
-
optimization: {
|
|
562
|
-
...webpackConfig.optimization,
|
|
563
|
-
splitChunks: {
|
|
564
|
-
...(webpackConfig.optimization?.splitChunks || {}),
|
|
565
|
-
cacheGroups: {
|
|
566
|
-
style: {
|
|
567
|
-
// This is a flagrant abuse of cache groups, but it fixes a persistent problem wherein the dependencies and versions of scripts and styles were bleeding into each-other
|
|
568
|
-
type: 'css/mini-extract',
|
|
569
|
-
chunks: 'all',
|
|
570
|
-
enforce: true,
|
|
571
|
-
name(_, chunks, cacheGroupKey) {
|
|
572
|
-
const chunkName = chunks.find(chunk => chunk.name)?.name;
|
|
573
|
-
// We use "__${cacheGroupKey}__" instead of "${cacheGroupKey}-" to make it easier to remove when generating the filename
|
|
574
|
-
const filename = `__${cacheGroupKey}__${node_path_1.default.basename(chunkName)}`;
|
|
575
|
-
const dirname = node_path_1.default.dirname(chunkName);
|
|
576
|
-
return dirname === '.' ? filename : `${dirname}/${filename}`;
|
|
577
|
-
}
|
|
578
|
-
},
|
|
579
|
-
default: false
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
},
|
|
583
|
-
module: {
|
|
584
|
-
...webpackConfig.module,
|
|
585
|
-
rules: fixedRules
|
|
586
|
-
},
|
|
587
|
-
resolve: {
|
|
588
|
-
...webpackConfig.resolve,
|
|
589
|
-
roots: viableRoots,
|
|
590
|
-
extensions: ['.mjsx', '.mjs', '.mtsx', '.mts', '.jsx', '.tsx', '.ts', '...']
|
|
591
|
-
},
|
|
592
|
-
stats: config.stats,
|
|
593
|
-
plugins: canCopyFiles
|
|
594
|
-
? plugins.map(plugin => !processingModules && plugin.constructor.name === 'CopyPlugin'
|
|
595
|
-
? new copy_webpack_plugin_1.default({ patterns: [{ from: standaloneBlocks ? '**/(block.json|*.(php|twig|svg))' : '**/(block.json|*.(asset\.php|svg))',
|
|
596
|
-
context: srcRoot, noErrorOnMissing: true }] })
|
|
597
|
-
: plugin)
|
|
598
|
-
: (srcIsDirectory
|
|
599
|
-
? plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
|
|
600
|
-
: plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin')),
|
|
601
|
-
entry() {
|
|
602
|
-
if (variablesFilePath) {
|
|
603
|
-
delete require.cache[require.resolve(variablesFilePath)];
|
|
604
|
-
currentVariables = require(variablesFilePath);
|
|
364
|
+
case "plain" /* SourceType.plain */:
|
|
365
|
+
if (config.plainEntrypointsVersion > 1) {
|
|
366
|
+
// plainEntrypoints.push({dest, src, srcRoot});
|
|
367
|
+
// return undefined;
|
|
368
|
+
return makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, srcIsDirectory);
|
|
605
369
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
...webpackConfig.performance,
|
|
610
|
-
assetFilter(assetFilename) {
|
|
611
|
-
// We don't want to warn about the sizes of incompressible assets
|
|
612
|
-
return !/\.(map|svg|png|jpe?g|gif)$/i.test(assetFilename);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
};
|
|
370
|
+
const { plugins } = buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest, config, "plain" /* SourceType.plain */);
|
|
371
|
+
return makePlainV1WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory);
|
|
372
|
+
}
|
|
616
373
|
}).filter(cfg => cfg !== undefined);
|
|
617
374
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
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];
|
|
375
|
+
function makeBlocksWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins) {
|
|
376
|
+
const { processingModules } = commonConfig;
|
|
377
|
+
const blockJSONManagingPlugin = new BlockJSONManagingPlugin_1.BlockJSONManagingPlugin(config.standaloneBlocks, processingModules, dest.destination);
|
|
378
|
+
plugins.push(blockJSONManagingPlugin);
|
|
379
|
+
if (config.processTranslationConfigs && !processingModules) {
|
|
380
|
+
plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(blockJSONManagingPlugin, dest.destination));
|
|
625
381
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
382
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest), plugins);
|
|
383
|
+
}
|
|
384
|
+
function makeExtensionsWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins) {
|
|
385
|
+
plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(srcRoot, config.extensionsVersion, dest.destination));
|
|
386
|
+
const entry = async () => {
|
|
387
|
+
const rawEntrypoints = [];
|
|
388
|
+
for await (const dirent of await promises_1.default.opendir(srcRoot)) {
|
|
389
|
+
if (dirent.isFile() && !dirent.name.startsWith("~")) {
|
|
390
|
+
if (commonConfig.scriptExtension.test(dirent.name) || common_config_helpers_1.styleExtension.test(dirent.name)) {
|
|
391
|
+
const file = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
|
|
392
|
+
rawEntrypoints.push([node_path_1.default.join(dest.destination, node_path_1.default.basename(file, node_path_1.default.extname(file))), file]);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return Object.fromEntries(rawEntrypoints);
|
|
629
397
|
};
|
|
630
|
-
|
|
631
|
-
|
|
398
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, entry, plugins);
|
|
399
|
+
}
|
|
400
|
+
function makePlainV1WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory) {
|
|
401
|
+
const baseDest = stripExtension(dest.destination);
|
|
402
|
+
const entry = srcIsDirectory // This being true implies that srcRoot is not an array
|
|
403
|
+
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
|
|
404
|
+
: () => ({ [baseDest]: srcRoot });
|
|
405
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, srcIsDirectory, dest, src, srcRoot, entry, plugins);
|
|
406
|
+
}
|
|
407
|
+
function makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, srcIsDirectory) {
|
|
408
|
+
const { plugins } = buildCommonPluginConfig(srcRoot, commonConfig.scriptExtension, webpackConfig, dest, config, "extensions" /* SourceType.extensions */);
|
|
409
|
+
plugins.push(new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(process.cwd(), config.outputDir, dest.locations ?? {}, config.plainEntrypointsHandlePrefix));
|
|
410
|
+
const baseDest = stripExtension(dest.destination);
|
|
411
|
+
const entry = srcIsDirectory // This being true implies that srcRoot is not an array
|
|
412
|
+
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
|
|
413
|
+
: () => ({ [baseDest]: srcRoot });
|
|
414
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, srcIsDirectory, dest, src, srcRoot, entry, plugins);
|
|
415
|
+
}
|
|
416
|
+
function stripExtension(filepath) {
|
|
417
|
+
return node_path_1.default.join(node_path_1.default.dirname(filepath), node_path_1.default.basename(filepath, node_path_1.default.extname(filepath)));
|
|
418
|
+
}
|
|
419
|
+
module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
|
|
420
|
+
const { cfg, sources } = buildVerifiedConfig(config);
|
|
632
421
|
if (Array.isArray(webpackConfig)) {
|
|
633
422
|
return webpackConfig.toSorted((a, b) => {
|
|
634
423
|
if (a.output?.module) {
|
|
635
424
|
return b.output?.module ? 0 : -1;
|
|
636
425
|
}
|
|
637
426
|
return b.output?.module ? 1 : 0;
|
|
638
|
-
}).flatMap(wpCfg => processIndividualWebpackConfig(cfg, wpCfg, sources
|
|
427
|
+
}).flatMap(wpCfg => processIndividualWebpackConfig(cfg, wpCfg, sources));
|
|
639
428
|
}
|
|
640
|
-
return processIndividualWebpackConfig(cfg, webpackConfig, sources
|
|
429
|
+
return processIndividualWebpackConfig(cfg, webpackConfig, sources);
|
|
641
430
|
};
|