@plaudit/webpack-extensions 2.63.1 → 2.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.d.ts +8 -6
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.js +53 -2
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +4 -1
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +8 -1
- package/build/plugins/AdditionalDependencyInjectorPlugin.d.ts +3 -1
- package/build/plugins/AdditionalDependencyInjectorPlugin.js +5 -3
- package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +8 -0
- package/build/plugins/EnhancedDynamicEntryPlugin.js +12 -0
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +4 -4
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +46 -90
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +7 -4
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +18 -21
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +5 -4
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +45 -75
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +3 -4
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +72 -102
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +0 -1
- package/build/plugins/SpecialAssetHandlingPlugin.js +2 -5
- package/build/plugins/UnifiedLoaderGenerator.js +28 -0
- package/build/plugins/WPMLConfigBuilder.d.ts +3 -1
- package/build/plugins/WPMLConfigBuilder.js +7 -4
- package/build/shared.d.ts +3 -2
- package/build/utils/common-config-helpers.d.ts +5 -3
- package/build/utils/common-config-helpers.js +11 -31
- package/build/wordpress-scripts-wrapper.js +106 -102
- package/package.json +1 -2
|
@@ -11,7 +11,6 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
11
11
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
12
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
13
13
|
const shared_1 = require("../shared");
|
|
14
|
-
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
15
14
|
let isInThemeCache = undefined;
|
|
16
15
|
function isInTheme() {
|
|
17
16
|
return isInThemeCache ?? (isInThemeCache = node_fs_1.default.existsSync(node_path_1.default.join(process.cwd(), "theme.json")));
|
|
@@ -122,7 +121,6 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
122
121
|
if (!dirent.isDirectory()) {
|
|
123
122
|
continue;
|
|
124
123
|
}
|
|
125
|
-
//TODO: It should be possible to handle all block.json files simultaneously, which would allow for better detection of repeated code
|
|
126
124
|
const dir = joinPossiblyAbsolutePaths(srcRoot, dirent.name);
|
|
127
125
|
loadingEntrypoints.push(new Promise(async (resolve) => {
|
|
128
126
|
const rawEntrypoints = [];
|
|
@@ -265,8 +263,8 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
265
263
|
return currentEntry;
|
|
266
264
|
};
|
|
267
265
|
}
|
|
268
|
-
function commonMakeWebpackConfig(config, commonConfig, webpackConfig,
|
|
269
|
-
const {
|
|
266
|
+
function commonMakeWebpackConfig(config, commonConfig, webpackConfig, externalize, plugins) {
|
|
267
|
+
const { variablesFilePath } = config;
|
|
270
268
|
const { fixedRules, processingModules, updateCurrentVariables } = commonConfig;
|
|
271
269
|
const outPath = joinPossiblyAbsolutePaths(process.cwd(), config.outputDir);
|
|
272
270
|
let publicPath = webpackConfig.output?.publicPath;
|
|
@@ -281,12 +279,6 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
281
279
|
}
|
|
282
280
|
}
|
|
283
281
|
let viableRoots = [...(Array.isArray(webpackConfig.context) ? webpackConfig.context : [webpackConfig.context ?? process.cwd()])];
|
|
284
|
-
if (Array.isArray(srcRoot)) {
|
|
285
|
-
viableRoots.push(...(srcIsDirectory ? srcRoot : srcRoot.map(s => node_path_1.default.dirname(s))));
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
viableRoots.push(srcIsDirectory ? srcRoot : node_path_1.default.dirname(srcRoot));
|
|
289
|
-
}
|
|
290
282
|
let wpContentHolderDirectory = process.cwd();
|
|
291
283
|
while (wpContentHolderDirectory.length > 5) {
|
|
292
284
|
if (node_path_1.default.basename(wpContentHolderDirectory) === 'wp-content') {
|
|
@@ -301,10 +293,10 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
301
293
|
const distinctViableRoots = new Set();
|
|
302
294
|
viableRoots = viableRoots.filter(value => distinctViableRoots.has(value) ? false : distinctViableRoots.add(value) && true);
|
|
303
295
|
let outputLibrary;
|
|
304
|
-
if (
|
|
305
|
-
if (Array.isArray(
|
|
296
|
+
if (externalize) {
|
|
297
|
+
if (Array.isArray(externalize) || typeof externalize === 'string') {
|
|
306
298
|
outputLibrary = {
|
|
307
|
-
name:
|
|
299
|
+
name: externalize,
|
|
308
300
|
type: "assign"
|
|
309
301
|
};
|
|
310
302
|
}
|
|
@@ -313,30 +305,17 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
313
305
|
if (originalLibrary && typeof originalLibrary === 'object' && !Array.isArray(originalLibrary)) {
|
|
314
306
|
outputLibrary = {
|
|
315
307
|
...originalLibrary,
|
|
316
|
-
...
|
|
308
|
+
...externalize
|
|
317
309
|
};
|
|
318
310
|
}
|
|
319
311
|
else {
|
|
320
|
-
outputLibrary =
|
|
312
|
+
outputLibrary = externalize;
|
|
321
313
|
}
|
|
322
314
|
}
|
|
323
315
|
}
|
|
324
316
|
else {
|
|
325
317
|
outputLibrary = webpackConfig.output?.library;
|
|
326
318
|
}
|
|
327
|
-
const canCopyFiles = srcIsDirectory && src !== dest.destination;
|
|
328
|
-
const possiblePlugins = canCopyFiles
|
|
329
|
-
? plugins.filter(plugin => plugin.constructor.name !== 'CleanWebpackPlugin')
|
|
330
|
-
.map(plugin => !processingModules && plugin.constructor.name === 'CopyPlugin'
|
|
331
|
-
? new copy_webpack_plugin_1.default({
|
|
332
|
-
patterns: [{
|
|
333
|
-
from: standaloneBlocks ? '**/*.(php|twig|svg)' : '**/*.(asset\.php|svg)',
|
|
334
|
-
to: dest.destination,
|
|
335
|
-
context: srcRoot /* canCopyFiles can only be true if srcRoot is a string, so this is safe */, noErrorOnMissing: true
|
|
336
|
-
}]
|
|
337
|
-
})
|
|
338
|
-
: plugin)
|
|
339
|
-
: plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin');
|
|
340
319
|
const extensions = processingModules ? ['.mjsx', '.mjs', '.mtsx', '.mts', '...'] : ['.jsx', '.tsx', '.ts', '...'];
|
|
341
320
|
return {
|
|
342
321
|
...webpackConfig,
|
|
@@ -347,7 +326,8 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
347
326
|
path: outPath,
|
|
348
327
|
chunkFilename: 'webpack-chunks/[id].js',
|
|
349
328
|
publicPath: publicPath,
|
|
350
|
-
library: outputLibrary
|
|
329
|
+
library: outputLibrary,
|
|
330
|
+
clean: false
|
|
351
331
|
},
|
|
352
332
|
optimization: {
|
|
353
333
|
...webpackConfig.optimization,
|
|
@@ -381,13 +361,13 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
|
|
|
381
361
|
extensions
|
|
382
362
|
},
|
|
383
363
|
stats: config.stats,
|
|
384
|
-
plugins
|
|
364
|
+
plugins,
|
|
385
365
|
entry() {
|
|
386
366
|
if (variablesFilePath) {
|
|
387
367
|
delete require.cache[require.resolve(variablesFilePath)];
|
|
388
368
|
updateCurrentVariables(require(variablesFilePath));
|
|
389
369
|
}
|
|
390
|
-
return
|
|
370
|
+
return {};
|
|
391
371
|
},
|
|
392
372
|
performance: {
|
|
393
373
|
...webpackConfig.performance,
|
|
@@ -10,6 +10,7 @@ const common_config_helpers_1 = require("./utils/common-config-helpers");
|
|
|
10
10
|
const AdditionalDependencyInjectorPlugin_1 = require("./plugins/AdditionalDependencyInjectorPlugin");
|
|
11
11
|
const BrowserSyncPlugin_1 = require("./plugins/BrowserSyncPlugin");
|
|
12
12
|
const dependency_extraction_webpack_plugin_config_builder_1 = require("./plugins/dependency-extraction-webpack-plugin-config-builder");
|
|
13
|
+
const EnhancedDynamicEntryPlugin_1 = require("./plugins/EnhancedDynamicEntryPlugin");
|
|
13
14
|
const ExtensionsConfigFileGeneratorPlugin_1 = require("./plugins/ExtensionsConfigFileGeneratorPlugin");
|
|
14
15
|
const ExtensionsConfigFileGeneratorPluginV1_1 = require("./plugins/ExtensionsConfigFileGeneratorPluginV1");
|
|
15
16
|
const MiniCSSExtractPluginErrorCleaner_1 = require("./plugins/MiniCSSExtractPluginErrorCleaner");
|
|
@@ -22,6 +23,7 @@ const WPMLConfigBuilder_1 = require("./plugins/WPMLConfigBuilder");
|
|
|
22
23
|
const static_configs_1 = require("./plugins/static-configs");
|
|
23
24
|
const UnifiedLoaderGenerator_1 = require("./plugins/UnifiedLoaderGenerator");
|
|
24
25
|
const dependency_extraction_webpack_plugin_1 = __importDefault(require("@wordpress/dependency-extraction-webpack-plugin"));
|
|
26
|
+
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
25
27
|
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
26
28
|
const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
|
|
27
29
|
function resolveLegacyBlockScriptsInFolder(folder) {
|
|
@@ -207,21 +209,31 @@ function buildVerifiedConfig(config) {
|
|
|
207
209
|
.map(([k, v]) => {
|
|
208
210
|
return normalizeSrcAndDestination([k, typeof v === 'boolean' ? {} : (typeof v === 'string' ? { destination: v } : v)]);
|
|
209
211
|
});
|
|
212
|
+
let variablesFilePath = undefined;
|
|
213
|
+
const currentVariables = rawVariables ?? {};
|
|
214
|
+
if (!rawVariables) {
|
|
215
|
+
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];
|
|
216
|
+
}
|
|
217
|
+
const cfg = {
|
|
218
|
+
currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, processTranslationConfigs, combineAssetMetadata,
|
|
219
|
+
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, plainEntrypointsHandlePrefix, srcDir, srcPrefixes, useUnifiedLoader
|
|
220
|
+
};
|
|
210
221
|
// Destination -> source map
|
|
211
222
|
const allocatedDestinations = {};
|
|
212
223
|
const partiallyVerifiedSources = rawSources.map(rawSource => {
|
|
213
|
-
const destination = rawSource[1]
|
|
224
|
+
const { destination, additionalDependencies = [], assumeGlobalizedPlauditLibraries = cfg.assumeGlobalizedPlauditLibraries, bundleAnalyzer = false, directoryLayout, externalize, withLegacyBlocksIn = false } = rawSource[1];
|
|
225
|
+
const normalizedParts = { additionalDependencies, assumeGlobalizedPlauditLibraries, bundleAnalyzer, directoryLayout, externalize, withLegacyBlocksIn };
|
|
214
226
|
const locations = typeof rawSource[1].locations === 'string' || typeof rawSource[1].locations === 'function'
|
|
215
227
|
? { handle: rawSource[1].locations } : rawSource[1].locations ?? {};
|
|
216
228
|
if (destination !== undefined) {
|
|
217
229
|
const effectiveDestination = toEffectiveWebpackDestination(destination);
|
|
218
230
|
allocatedDestinations[effectiveDestination] = rawSource[0]; // We need to pre-populate the allocatedDestinations map with statically-declared destinations
|
|
219
|
-
return [rawSource[0], { ...
|
|
231
|
+
return [rawSource[0], { ...normalizedParts, locations, destination, effectiveDestination, staticallyDeclaredDestination: true }];
|
|
220
232
|
}
|
|
221
233
|
else {
|
|
222
234
|
const naiveDestination = deriveNaiveDestinationFromUnverifiedSourceEntry(rawSource, srcPrefixes);
|
|
223
235
|
const effectiveDestination = toEffectiveWebpackDestination(naiveDestination);
|
|
224
|
-
return [rawSource[0], { ...
|
|
236
|
+
return [rawSource[0], { ...normalizedParts, locations, destination: naiveDestination, effectiveDestination, staticallyDeclaredDestination: false }];
|
|
225
237
|
}
|
|
226
238
|
});
|
|
227
239
|
const dynamicEffectiveDestinationsWithExpectedNaiveDuplicates = partiallyVerifiedSources
|
|
@@ -234,15 +246,6 @@ function buildVerifiedConfig(config) {
|
|
|
234
246
|
const sources = partiallyVerifiedSources
|
|
235
247
|
.map(entry => finalizeEntryDestination(entry, dynamicEffectiveDestinationsWithExpectedNaiveDuplicates, allocatedDestinations));
|
|
236
248
|
testForDuplicatedEntryPaths(sources);
|
|
237
|
-
let variablesFilePath = undefined;
|
|
238
|
-
const currentVariables = rawVariables ?? {};
|
|
239
|
-
if (!rawVariables) {
|
|
240
|
-
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];
|
|
241
|
-
}
|
|
242
|
-
const cfg = {
|
|
243
|
-
currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, processTranslationConfigs, combineAssetMetadata,
|
|
244
|
-
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, plainEntrypointsHandlePrefix, srcDir, srcPrefixes, useUnifiedLoader
|
|
245
|
-
};
|
|
246
249
|
return cfg.outputDir ? { cfg, sources } : withDerivedOutputDir(cfg, sources);
|
|
247
250
|
}
|
|
248
251
|
function toEffectiveWebpackDestination(destination) {
|
|
@@ -284,6 +287,7 @@ function finalizeEntryDestination(entry, dynamicEffectiveDestinationsWithExpecte
|
|
|
284
287
|
while (derivedDestination in allocatedDestinations && allocatedDestinations[derivedDestination] !== entry[0]) {
|
|
285
288
|
derivedDestination = `${filename}_${++count}${extension}`; // We don't want to add deduplication indexes unless absolutely necessary
|
|
286
289
|
}
|
|
290
|
+
entry[1].additionalDependencies?.sort();
|
|
287
291
|
allocatedDestinations[derivedDestination] = entry[0];
|
|
288
292
|
return [entry[0], { ...entry[1], destination: derivedDestination }];
|
|
289
293
|
}
|
|
@@ -356,11 +360,12 @@ function handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins)
|
|
|
356
360
|
}
|
|
357
361
|
}
|
|
358
362
|
}
|
|
359
|
-
function buildCommonPluginConfig(
|
|
360
|
-
const {
|
|
363
|
+
function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize, additionalDependencies) {
|
|
364
|
+
const { externals } = config;
|
|
361
365
|
const processingModules = webpackConfig.output?.module ?? false;
|
|
362
366
|
const plugins = webpackConfig.plugins?.filter(v => !!v)
|
|
363
367
|
.filter(plugin => plugin.constructor.name !== 'RtlCssPlugin')
|
|
368
|
+
.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
|
|
364
369
|
.map(plugin => {
|
|
365
370
|
if (plugin.constructor.name === 'MiniCssExtractPlugin') {
|
|
366
371
|
return new plugin.constructor({
|
|
@@ -374,35 +379,31 @@ function buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest,
|
|
|
374
379
|
})
|
|
375
380
|
?? [];
|
|
376
381
|
plugins.splice(0, 0, new PackageConfigSanityChecker_1.PackageConfigSanityChecker());
|
|
377
|
-
if (
|
|
382
|
+
if (bundleAnalyzer) {
|
|
378
383
|
plugins.splice(0, 0, new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({ analyzerMode: 'static' }));
|
|
379
384
|
}
|
|
380
|
-
handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins);
|
|
381
385
|
const removeEmptyScriptsPlugin = new webpack_remove_empty_scripts_1.default({
|
|
382
386
|
stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
|
|
383
387
|
extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss'],
|
|
384
388
|
ignore: /block\.json/
|
|
385
389
|
});
|
|
386
390
|
plugins.push(removeEmptyScriptsPlugin, new MiniCSSExtractPluginErrorCleaner_1.MiniCSSExtractPluginErrorCleaner());
|
|
387
|
-
plugins.push(new UnifiedLoaderGenerator_1.UnifiedLoaderGenerator(config));
|
|
388
391
|
plugins.push(new SpecialAssetHandlingPlugin_1.SpecialAssetHandlingPlugin(config));
|
|
389
392
|
plugins.push(new VariablesJSMonitorPlugin_1.VariablesJSMonitorPlugin(config));
|
|
390
393
|
const dependencyExtractionPluginIndex = plugins.findIndex(plugin => plugin instanceof dependency_extraction_webpack_plugin_1.default);
|
|
391
394
|
if (dependencyExtractionPluginIndex === -1) {
|
|
392
395
|
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");
|
|
396
|
+
throw new Error();
|
|
393
397
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const wantsGroupedDepData = combineAssetMetadata
|
|
397
|
-
&& ((sourceType === "blocks" /* SourceType.blocks */)
|
|
398
|
-
|| (extensionsVersion > 1 && sourceType === "extensions" /* SourceType.extensions */)
|
|
399
|
-
|| (plainEntrypointsVersion > 1 && sourceType === "plain" /* SourceType.plain */));
|
|
400
|
-
const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, localAssumeGlobalizedPlauditLibraries, wantsGroupedDepData, dest.externalize);
|
|
401
|
-
plugins[dependencyExtractionPluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
|
|
402
|
-
plugins.push(new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(dest.additionalDependencies ? dest.additionalDependencies : [], processingModules, builtDependencyExtractionWebpackPlugin.addExternalizedDep));
|
|
403
|
-
}
|
|
398
|
+
const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, assumeGlobalizedPlauditLibraries, true, externalize);
|
|
399
|
+
plugins[dependencyExtractionPluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
|
|
404
400
|
plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin());
|
|
405
|
-
return {
|
|
401
|
+
return {
|
|
402
|
+
plugins, removeEmptyScriptsPlugin,
|
|
403
|
+
makeAdditionalDependencyInjectorPlugin(referencePlugin) {
|
|
404
|
+
return new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(additionalDependencies ?? [], processingModules, builtDependencyExtractionWebpackPlugin.addExternalizedDep, referencePlugin);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
406
407
|
}
|
|
407
408
|
function commonConfigProcessingPrep(config, webpackConfig) {
|
|
408
409
|
let scriptExtension; // This is only used in non-block contexts. It might not actually be necessary, but it is good to have
|
|
@@ -439,11 +440,16 @@ function commonConfigProcessingPrep(config, webpackConfig) {
|
|
|
439
440
|
updateCurrentVariables: (value) => currentVariables = value
|
|
440
441
|
};
|
|
441
442
|
}
|
|
442
|
-
|
|
443
|
+
function destToKey(dest) {
|
|
444
|
+
const externalize = typeof dest.externalize === 'object' && dest.externalize !== undefined
|
|
445
|
+
? (Array.isArray(dest.externalize) ? dest.externalize.join("_") : (dest.externalize ? Object.entries(dest.externalize).flat().sort().join() : "undefined"))
|
|
446
|
+
: dest.externalize?.toString() ?? "undefined";
|
|
447
|
+
return [dest.additionalDependencies.join("_"), dest.assumeGlobalizedPlauditLibraries, dest.bundleAnalyzer, externalize, dest.withLegacyBlocksIn].join("~");
|
|
448
|
+
}
|
|
443
449
|
function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
444
450
|
const commonConfig = commonConfigProcessingPrep(config, webpackConfig);
|
|
445
451
|
const { processingModules, scriptExtension } = commonConfig;
|
|
446
|
-
|
|
452
|
+
const allSrcRoots = sources.map(([src, dest]) => {
|
|
447
453
|
const srcRoots = (dest.withLegacyBlocksIn
|
|
448
454
|
? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(node_path_1.default.join(config.srcDir, dest.withLegacyBlocksIn))]
|
|
449
455
|
: src.split(',')).filter(s => s.endsWith(".json") || !s.substring(s.lastIndexOf('/')).includes('.') || processingModules === shared_1.scriptWithModuleExtension.test(s));
|
|
@@ -452,95 +458,93 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
|
452
458
|
if (srcIsDirectory === undefined) {
|
|
453
459
|
return undefined;
|
|
454
460
|
}
|
|
455
|
-
|
|
456
|
-
|
|
461
|
+
return { srcRoots, src, dest, srcRoot, srcIsDirectory };
|
|
462
|
+
}).filter(a => a !== undefined);
|
|
463
|
+
const groupedSrcRoots = {};
|
|
464
|
+
for (const entry of allSrcRoots) {
|
|
465
|
+
const key = destToKey(entry.dest);
|
|
466
|
+
(groupedSrcRoots[key] ?? (groupedSrcRoots[key] = [])).push(entry);
|
|
467
|
+
}
|
|
468
|
+
return Object.values(groupedSrcRoots).filter(shared_1.hasAtLeastOneItem).map(currentBatch => {
|
|
469
|
+
const { bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize, additionalDependencies } = currentBatch[0].dest;
|
|
470
|
+
const { plugins, removeEmptyScriptsPlugin, makeAdditionalDependencyInjectorPlugin } = buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize, additionalDependencies);
|
|
471
|
+
handleDisablingTSCheckerIfNecessary(currentBatch.flatMap(a => a.srcRoots), scriptExtension, plugins);
|
|
472
|
+
for (const { dest, src, srcIsDirectory, srcRoot } of currentBatch) {
|
|
473
|
+
let plugin;
|
|
474
|
+
const sourceType = (0, shared_1.determineCurrentSourceType)(dest, srcIsDirectory);
|
|
475
|
+
if (sourceType === "blocks" /* SourceType.blocks */) {
|
|
457
476
|
if (!srcIsDirectory) {
|
|
458
|
-
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
plugin = new PlainEntrypointsStyleBlockJSONPlugin_1.PlainEntrypointsStyleBlockJSONPlugin(config, dest.destination, removeEmptyScriptsPlugin, webpackConfig.context ?? process.cwd(), (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
|
|
480
|
+
plugins.push(plugin);
|
|
481
|
+
if (config.processTranslationConfigs && !processingModules) {
|
|
482
|
+
plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination, plugin));
|
|
459
483
|
}
|
|
460
|
-
const { plugins } = buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest, config, "blocks" /* SourceType.blocks */);
|
|
461
|
-
return makeBlocksWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins);
|
|
462
484
|
}
|
|
463
|
-
|
|
485
|
+
else if (sourceType === "extensions" /* SourceType.extensions */) {
|
|
464
486
|
if (!srcIsDirectory) {
|
|
465
|
-
|
|
487
|
+
continue;
|
|
466
488
|
}
|
|
467
|
-
const
|
|
468
|
-
|
|
489
|
+
const entry = async () => {
|
|
490
|
+
const rawEntrypoints = [];
|
|
491
|
+
for await (const dirent of await promises_1.default.opendir(srcRoot)) {
|
|
492
|
+
if (dirent.isFile() && !dirent.name.startsWith("~")) {
|
|
493
|
+
if (commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name)) {
|
|
494
|
+
const file = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
|
|
495
|
+
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" }]);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return Object.fromEntries(rawEntrypoints);
|
|
500
|
+
};
|
|
501
|
+
plugin = config.extensionsVersion > 1
|
|
502
|
+
? new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(config, srcRoot, dest, webpackConfig.context ?? process.cwd(), entry)
|
|
503
|
+
: new ExtensionsConfigFileGeneratorPluginV1_1.ExtensionsConfigFileGeneratorPluginV1(config, dest.destination, webpackConfig.context ?? process.cwd(), entry);
|
|
504
|
+
plugins.push(plugin);
|
|
469
505
|
}
|
|
470
|
-
|
|
506
|
+
else if (sourceType === "plain" /* SourceType.plain */) {
|
|
471
507
|
if (!srcIsDirectory) {
|
|
472
508
|
const primarySrcRoot = typeof srcRoot === 'string' ? srcRoot : srcRoot[0];
|
|
473
509
|
if (!scriptExtension.test(primarySrcRoot) && !shared_1.styleExtension.test(primarySrcRoot)) {
|
|
474
|
-
|
|
510
|
+
continue;
|
|
475
511
|
}
|
|
476
512
|
}
|
|
477
|
-
const
|
|
513
|
+
const baseDest = stripExtension(dest.destination);
|
|
478
514
|
if (config.plainEntrypointsVersion > 1) {
|
|
479
|
-
|
|
515
|
+
const entry = srcIsDirectory // This being true implies that srcRoot is not an array
|
|
516
|
+
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
|
|
517
|
+
: () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: "plain-entrypoint" } });
|
|
518
|
+
plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest.locations, config.plainEntrypointsHandlePrefix, config.useUnifiedLoader, webpackConfig.context ?? process.cwd(), entry);
|
|
480
519
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
function makeBlocksWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins) {
|
|
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), webpackConfig.context ?? process.cwd(), (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
|
|
488
|
-
plugins.push(blockJSONManagingPlugin);
|
|
489
|
-
if (config.processTranslationConfigs && !processingModules) {
|
|
490
|
-
plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination));
|
|
491
|
-
}
|
|
492
|
-
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, {}, plugins);
|
|
493
|
-
}
|
|
494
|
-
function makeExtensionsWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins) {
|
|
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" }]);
|
|
520
|
+
else {
|
|
521
|
+
if (srcIsDirectory) {
|
|
522
|
+
console.error("Using directory mode with legacy plain entrypoint handling is not supported");
|
|
523
|
+
continue;
|
|
503
524
|
}
|
|
525
|
+
plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(config, webpackConfig.context ?? process.cwd(), () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: "plain-entrypoint" } }));
|
|
504
526
|
}
|
|
527
|
+
plugins.push(plugin);
|
|
505
528
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
}
|
|
529
|
+
else {
|
|
530
|
+
console.error("Unrecognized sourceType");
|
|
531
|
+
continue;
|
|
523
532
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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);
|
|
533
|
+
plugins.push(makeAdditionalDependencyInjectorPlugin(plugin));
|
|
534
|
+
const canCopyFiles = srcIsDirectory && src !== dest.destination;
|
|
535
|
+
if (canCopyFiles) {
|
|
536
|
+
plugins.push(new copy_webpack_plugin_1.default({
|
|
537
|
+
patterns: [{
|
|
538
|
+
from: config.standaloneBlocks ? '**/*.(php|twig|svg)' : '**/*.(asset\.php|svg)',
|
|
539
|
+
to: dest.destination,
|
|
540
|
+
context: srcRoot /* canCopyFiles can only be true if srcRoot is a string, so this is safe */, noErrorOnMissing: true
|
|
541
|
+
}]
|
|
542
|
+
}));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
plugins.push(new UnifiedLoaderGenerator_1.UnifiedLoaderGenerator(config));
|
|
546
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, externalize, plugins);
|
|
547
|
+
}).filter(cfg => cfg !== undefined);
|
|
544
548
|
}
|
|
545
549
|
function stripExtension(filepath) {
|
|
546
550
|
return node_path_1.default.join(node_path_1.default.dirname(filepath), node_path_1.default.basename(filepath, node_path_1.default.extname(filepath)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.64.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"/build"
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"@wordpress/scripts": "^30.23.0",
|
|
40
40
|
"autoprefixer": "^10.4.21",
|
|
41
41
|
"browser-sync": "^3.0.4",
|
|
42
|
-
"clean-webpack-plugin": "^4.0.0",
|
|
43
42
|
"copy-webpack-plugin": "^10.2.4",
|
|
44
43
|
"cssnano": "^6.1.2",
|
|
45
44
|
"eslint-plugin-jsdoc": "^48.11.0",
|