@plaudit/webpack-extensions 2.63.2 → 2.65.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/AbstractBiPhasicGroupAndEntryPlugin.d.ts +22 -0
- package/build/plugins/{AbstractMultiPhaseLibraryAndEntryPlugin.js → AbstractBiPhasicGroupAndEntryPlugin.js} +31 -8
- package/build/plugins/AbstractBiPhasicGroupPlugin.d.ts +33 -0
- package/build/plugins/AbstractBiPhasicGroupPlugin.js +93 -0
- 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 +9 -8
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +108 -142
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +8 -6
- package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +22 -32
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +8 -8
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +51 -82
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +6 -7
- package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +78 -107
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +5 -6
- package/build/plugins/SpecialAssetHandlingPlugin.js +45 -51
- package/build/plugins/UnifiedLoaderGenerator.d.ts +8 -8
- package/build/plugins/UnifiedLoaderGenerator.js +59 -46
- package/build/plugins/WPMLConfigBuilder.d.ts +3 -1
- package/build/plugins/WPMLConfigBuilder.js +7 -4
- package/build/shared.d.ts +7 -5
- package/build/shared.js +19 -3
- package/build/utils/common-config-helpers.d.ts +5 -3
- package/build/utils/common-config-helpers.js +10 -31
- package/build/utils/json-to-php-but-with-__-injection.js +1 -1
- package/build/utils/pseduo-semaphore.d.ts +2 -3
- package/build/utils/pseduo-semaphore.js +9 -5
- package/build/wordpress-scripts-wrapper.js +116 -106
- package/package.json +1 -2
- package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.d.ts +0 -19
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +0 -14
- package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +0 -37
|
@@ -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,33 @@ 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
|
-
|
|
388
|
-
|
|
391
|
+
if (config.useWebpackResourceFiltering) {
|
|
392
|
+
plugins.push(new SpecialAssetHandlingPlugin_1.SpecialAssetHandlingPlugin(config));
|
|
393
|
+
}
|
|
389
394
|
plugins.push(new VariablesJSMonitorPlugin_1.VariablesJSMonitorPlugin(config));
|
|
390
395
|
const dependencyExtractionPluginIndex = plugins.findIndex(plugin => plugin instanceof dependency_extraction_webpack_plugin_1.default);
|
|
391
396
|
if (dependencyExtractionPluginIndex === -1) {
|
|
392
397
|
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");
|
|
398
|
+
throw new Error();
|
|
393
399
|
}
|
|
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
|
-
}
|
|
400
|
+
const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, assumeGlobalizedPlauditLibraries, true, externalize);
|
|
401
|
+
plugins[dependencyExtractionPluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
|
|
404
402
|
plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin());
|
|
405
|
-
return {
|
|
403
|
+
return {
|
|
404
|
+
plugins, removeEmptyScriptsPlugin,
|
|
405
|
+
makeAdditionalDependencyInjectorPlugin(referencePlugin) {
|
|
406
|
+
return new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(additionalDependencies ?? [], processingModules, builtDependencyExtractionWebpackPlugin.addExternalizedDep, referencePlugin);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
406
409
|
}
|
|
407
410
|
function commonConfigProcessingPrep(config, webpackConfig) {
|
|
408
411
|
let scriptExtension; // This is only used in non-block contexts. It might not actually be necessary, but it is good to have
|
|
@@ -439,11 +442,16 @@ function commonConfigProcessingPrep(config, webpackConfig) {
|
|
|
439
442
|
updateCurrentVariables: (value) => currentVariables = value
|
|
440
443
|
};
|
|
441
444
|
}
|
|
442
|
-
|
|
443
|
-
|
|
445
|
+
function destToKey(dest) {
|
|
446
|
+
const externalize = typeof dest.externalize === 'object' && dest.externalize !== undefined
|
|
447
|
+
? (Array.isArray(dest.externalize) ? dest.externalize.join("_") : (dest.externalize ? Object.entries(dest.externalize).flat().sort().join() : "undefined"))
|
|
448
|
+
: dest.externalize?.toString() ?? "undefined";
|
|
449
|
+
return [dest.additionalDependencies.join("_"), dest.assumeGlobalizedPlauditLibraries, dest.bundleAnalyzer, externalize, dest.withLegacyBlocksIn].join("~");
|
|
450
|
+
}
|
|
451
|
+
function processIndividualWebpackConfig(config, webpackConfig, sources, canClean) {
|
|
444
452
|
const commonConfig = commonConfigProcessingPrep(config, webpackConfig);
|
|
445
453
|
const { processingModules, scriptExtension } = commonConfig;
|
|
446
|
-
|
|
454
|
+
const allSrcRoots = sources.map(([src, dest]) => {
|
|
447
455
|
const srcRoots = (dest.withLegacyBlocksIn
|
|
448
456
|
? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(node_path_1.default.join(config.srcDir, dest.withLegacyBlocksIn))]
|
|
449
457
|
: src.split(',')).filter(s => s.endsWith(".json") || !s.substring(s.lastIndexOf('/')).includes('.') || processingModules === shared_1.scriptWithModuleExtension.test(s));
|
|
@@ -452,108 +460,110 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
|
452
460
|
if (srcIsDirectory === undefined) {
|
|
453
461
|
return undefined;
|
|
454
462
|
}
|
|
455
|
-
|
|
456
|
-
|
|
463
|
+
return { srcRoots, src, dest, srcRoot, srcIsDirectory };
|
|
464
|
+
}).filter(a => a !== undefined);
|
|
465
|
+
const groupedSrcRoots = {};
|
|
466
|
+
for (const entry of allSrcRoots) {
|
|
467
|
+
const key = destToKey(entry.dest);
|
|
468
|
+
(groupedSrcRoots[key] ?? (groupedSrcRoots[key] = [])).push(entry);
|
|
469
|
+
}
|
|
470
|
+
const batches = Object.values(groupedSrcRoots).filter(shared_1.hasAtLeastOneItem);
|
|
471
|
+
return batches.map(currentBatch => {
|
|
472
|
+
const { bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize, additionalDependencies } = currentBatch[0].dest;
|
|
473
|
+
const { plugins, removeEmptyScriptsPlugin, makeAdditionalDependencyInjectorPlugin } = buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize, additionalDependencies);
|
|
474
|
+
handleDisablingTSCheckerIfNecessary(currentBatch.flatMap(a => a.srcRoots), scriptExtension, plugins);
|
|
475
|
+
for (const { dest, src, srcIsDirectory, srcRoot } of currentBatch) {
|
|
476
|
+
let plugin;
|
|
477
|
+
const sourceType = (0, shared_1.determineCurrentSourceType)(dest, srcIsDirectory);
|
|
478
|
+
if (sourceType === "blocks" /* SourceType.blocks */) {
|
|
457
479
|
if (!srcIsDirectory) {
|
|
458
|
-
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
plugin = new PlainEntrypointsStyleBlockJSONPlugin_1.PlainEntrypointsStyleBlockJSONPlugin(config, dest.destination, removeEmptyScriptsPlugin, webpackConfig.context ?? process.cwd(), (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
|
|
483
|
+
plugins.push(plugin);
|
|
484
|
+
if (config.processTranslationConfigs && !processingModules) {
|
|
485
|
+
plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination, plugin));
|
|
459
486
|
}
|
|
460
|
-
const { plugins } = buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest, config, "blocks" /* SourceType.blocks */);
|
|
461
|
-
return makeBlocksWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins);
|
|
462
487
|
}
|
|
463
|
-
|
|
488
|
+
else if (sourceType === "extensions" /* SourceType.extensions */) {
|
|
464
489
|
if (!srcIsDirectory) {
|
|
465
|
-
|
|
490
|
+
continue;
|
|
466
491
|
}
|
|
467
|
-
const
|
|
468
|
-
|
|
492
|
+
const entry = async () => {
|
|
493
|
+
const rawEntrypoints = [];
|
|
494
|
+
for await (const dirent of await promises_1.default.opendir(srcRoot)) {
|
|
495
|
+
if (dirent.isFile() && !dirent.name.startsWith("~")) {
|
|
496
|
+
if (commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name)) {
|
|
497
|
+
const file = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
|
|
498
|
+
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" }]);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return Object.fromEntries(rawEntrypoints);
|
|
503
|
+
};
|
|
504
|
+
plugin = config.extensionsVersion > 1
|
|
505
|
+
? new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(config, srcRoot, dest, webpackConfig.context ?? process.cwd(), entry)
|
|
506
|
+
: new ExtensionsConfigFileGeneratorPluginV1_1.ExtensionsConfigFileGeneratorPluginV1(config, dest.destination, webpackConfig.context ?? process.cwd(), entry);
|
|
507
|
+
plugins.push(plugin);
|
|
469
508
|
}
|
|
470
|
-
|
|
509
|
+
else if (sourceType === "plain" /* SourceType.plain */) {
|
|
471
510
|
if (!srcIsDirectory) {
|
|
472
511
|
const primarySrcRoot = typeof srcRoot === 'string' ? srcRoot : srcRoot[0];
|
|
473
512
|
if (!scriptExtension.test(primarySrcRoot) && !shared_1.styleExtension.test(primarySrcRoot)) {
|
|
474
|
-
|
|
513
|
+
continue;
|
|
475
514
|
}
|
|
476
515
|
}
|
|
477
|
-
const
|
|
516
|
+
const baseDest = stripExtension(dest.destination);
|
|
478
517
|
if (config.plainEntrypointsVersion > 1) {
|
|
479
|
-
|
|
518
|
+
const entry = srcIsDirectory // This being true implies that srcRoot is not an array
|
|
519
|
+
? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
|
|
520
|
+
: () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: "plain-entrypoint" } });
|
|
521
|
+
plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest.locations, config.useUnifiedLoader, webpackConfig.context ?? process.cwd(), entry);
|
|
480
522
|
}
|
|
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" }]);
|
|
523
|
+
else {
|
|
524
|
+
if (srcIsDirectory) {
|
|
525
|
+
console.error("Using directory mode with legacy plain entrypoint handling is not supported");
|
|
526
|
+
continue;
|
|
503
527
|
}
|
|
528
|
+
plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(config, webpackConfig.context ?? process.cwd(), () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: "plain-entrypoint" } }));
|
|
504
529
|
}
|
|
530
|
+
plugins.push(plugin);
|
|
505
531
|
}
|
|
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
|
-
}
|
|
532
|
+
else {
|
|
533
|
+
console.error("Unrecognized sourceType");
|
|
534
|
+
continue;
|
|
523
535
|
}
|
|
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);
|
|
536
|
+
plugins.push(makeAdditionalDependencyInjectorPlugin(plugin));
|
|
537
|
+
const canCopyFiles = srcIsDirectory && src !== dest.destination;
|
|
538
|
+
if (canCopyFiles) {
|
|
539
|
+
plugins.push(new copy_webpack_plugin_1.default({
|
|
540
|
+
patterns: [{
|
|
541
|
+
from: config.standaloneBlocks ? '**/*.(php|twig|svg)' : '**/*.(asset\.php|svg)',
|
|
542
|
+
to: dest.destination,
|
|
543
|
+
context: srcRoot /* canCopyFiles can only be true if srcRoot is a string, so this is safe */, noErrorOnMissing: true
|
|
544
|
+
}]
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
plugins.push(new UnifiedLoaderGenerator_1.UnifiedLoaderGenerator(config));
|
|
549
|
+
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, externalize, plugins, canClean && batches.length < 2);
|
|
550
|
+
}).filter(cfg => cfg !== undefined);
|
|
544
551
|
}
|
|
545
552
|
function stripExtension(filepath) {
|
|
546
553
|
return node_path_1.default.join(node_path_1.default.dirname(filepath), node_path_1.default.basename(filepath, node_path_1.default.extname(filepath)));
|
|
547
554
|
}
|
|
548
555
|
module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
|
|
549
556
|
const { cfg, sources } = buildVerifiedConfig(config);
|
|
557
|
+
if (Array.isArray(webpackConfig) && (0, shared_1.hasAtLeastOneItem)(webpackConfig)) {
|
|
558
|
+
webpackConfig = webpackConfig[0];
|
|
559
|
+
}
|
|
550
560
|
if (Array.isArray(webpackConfig)) {
|
|
551
561
|
return webpackConfig.toSorted((a, b) => {
|
|
552
562
|
if (a.output?.module) {
|
|
553
563
|
return b.output?.module ? 0 : -1;
|
|
554
564
|
}
|
|
555
565
|
return b.output?.module ? 1 : 0;
|
|
556
|
-
}).flatMap(wpCfg => processIndividualWebpackConfig(cfg, wpCfg, sources));
|
|
566
|
+
}).flatMap(wpCfg => processIndividualWebpackConfig(cfg, wpCfg, sources, false));
|
|
557
567
|
}
|
|
558
|
-
return processIndividualWebpackConfig(cfg, webpackConfig, sources);
|
|
568
|
+
return processIndividualWebpackConfig(cfg, webpackConfig, sources, true);
|
|
559
569
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.65.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",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { PseudoSemaphore } from "../utils/pseduo-semaphore";
|
|
2
|
-
import type { ExtensibleEntryObject } from "../utils/common-config-helpers";
|
|
3
|
-
import { AbstractMultiPhaseLibraryPlugin } from "./AbstractMultiPhaseLibraryPlugin";
|
|
4
|
-
import { Compilation, Compiler, Entrypoint } from "webpack";
|
|
5
|
-
export type EntryProvider<M> = () => ExtensibleEntryObject<M> | Promise<ExtensibleEntryObject<M>>;
|
|
6
|
-
export declare abstract class AbstractMultiPhaseLibraryAndEntryPlugin<M> extends AbstractMultiPhaseLibraryPlugin {
|
|
7
|
-
private readonly context;
|
|
8
|
-
private readonly entry;
|
|
9
|
-
protected readonly entryMetadataRecord: {
|
|
10
|
-
[entryName: string]: M;
|
|
11
|
-
};
|
|
12
|
-
protected constructor(libraryType: string, semaphores: PseudoSemaphore<any>[], context: string, entry: EntryProvider<M>);
|
|
13
|
-
apply(compiler: Compiler): void;
|
|
14
|
-
protected getRelevantEntrypoints(compilation: Compilation): {
|
|
15
|
-
entrypoint: Entrypoint;
|
|
16
|
-
srcPath: string;
|
|
17
|
-
metadata: M;
|
|
18
|
-
}[];
|
|
19
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Compilation, Compiler, type WebpackPluginInstance } from "webpack";
|
|
2
|
-
import { PseudoSemaphore } from "../utils/pseduo-semaphore";
|
|
3
|
-
export declare abstract class AbstractMultiPhaseLibraryPlugin implements WebpackPluginInstance {
|
|
4
|
-
readonly libraryType: string;
|
|
5
|
-
private readonly semaphores;
|
|
6
|
-
protected static readonly phaseTwoAttached: {
|
|
7
|
-
[key in string]: any;
|
|
8
|
-
};
|
|
9
|
-
protected readonly id: string;
|
|
10
|
-
protected constructor(libraryType: string, semaphores: PseudoSemaphore<any>[]);
|
|
11
|
-
apply(compiler: Compiler): void;
|
|
12
|
-
protected resetSemaphores(): void;
|
|
13
|
-
protected abstract attachSecondPhase(compilation: Compilation): void;
|
|
14
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractMultiPhaseLibraryPlugin = void 0;
|
|
4
|
-
const webpack_1 = require("webpack");
|
|
5
|
-
class AbstractMultiPhaseLibraryPlugin {
|
|
6
|
-
libraryType;
|
|
7
|
-
semaphores;
|
|
8
|
-
static phaseTwoAttached = {};
|
|
9
|
-
id;
|
|
10
|
-
constructor(libraryType, semaphores) {
|
|
11
|
-
this.libraryType = libraryType;
|
|
12
|
-
this.semaphores = semaphores;
|
|
13
|
-
this.id = Math.random().toString();
|
|
14
|
-
}
|
|
15
|
-
apply(compiler) {
|
|
16
|
-
webpack_1.library.EnableLibraryPlugin.setEnabled(compiler, this.libraryType);
|
|
17
|
-
for (const semaphore of this.semaphores) {
|
|
18
|
-
semaphore.register(this.id);
|
|
19
|
-
}
|
|
20
|
-
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
21
|
-
AbstractMultiPhaseLibraryPlugin.phaseTwoAttached[this.libraryType] = false;
|
|
22
|
-
this.resetSemaphores();
|
|
23
|
-
compilation.hooks.beforeChunkIds.tap(this.constructor.name, () => {
|
|
24
|
-
if (!AbstractMultiPhaseLibraryPlugin.phaseTwoAttached[this.libraryType]) {
|
|
25
|
-
AbstractMultiPhaseLibraryPlugin.phaseTwoAttached[this.libraryType] = this;
|
|
26
|
-
this.attachSecondPhase(compilation);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
resetSemaphores() {
|
|
32
|
-
for (const semaphore of this.semaphores) {
|
|
33
|
-
semaphore.reset(this.id);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.AbstractMultiPhaseLibraryPlugin = AbstractMultiPhaseLibraryPlugin;
|