@plaudit/webpack-extensions 2.63.2 → 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.
Files changed (26) hide show
  1. package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.d.ts +8 -6
  2. package/build/plugins/AbstractMultiPhaseLibraryAndEntryPlugin.js +53 -2
  3. package/build/plugins/AbstractMultiPhaseLibraryPlugin.d.ts +4 -1
  4. package/build/plugins/AbstractMultiPhaseLibraryPlugin.js +8 -1
  5. package/build/plugins/AdditionalDependencyInjectorPlugin.d.ts +3 -1
  6. package/build/plugins/AdditionalDependencyInjectorPlugin.js +5 -3
  7. package/build/plugins/EnhancedDynamicEntryPlugin.d.ts +8 -0
  8. package/build/plugins/EnhancedDynamicEntryPlugin.js +12 -0
  9. package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +4 -4
  10. package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +46 -90
  11. package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +7 -4
  12. package/build/plugins/ExtensionsConfigFileGeneratorPluginV1.js +18 -21
  13. package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +5 -4
  14. package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +45 -75
  15. package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.d.ts +3 -4
  16. package/build/plugins/PlainEntrypointsStyleBlockJSONPlugin.js +72 -102
  17. package/build/plugins/SpecialAssetHandlingPlugin.d.ts +0 -1
  18. package/build/plugins/SpecialAssetHandlingPlugin.js +2 -5
  19. package/build/plugins/UnifiedLoaderGenerator.js +28 -0
  20. package/build/plugins/WPMLConfigBuilder.d.ts +3 -1
  21. package/build/plugins/WPMLConfigBuilder.js +7 -4
  22. package/build/shared.d.ts +3 -2
  23. package/build/utils/common-config-helpers.d.ts +5 -3
  24. package/build/utils/common-config-helpers.js +9 -30
  25. package/build/wordpress-scripts-wrapper.js +106 -102
  26. package/package.json +1 -2
@@ -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].destination;
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], { ...rawSource[1], locations, destination, effectiveDestination, staticallyDeclaredDestination: true }];
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], { ...rawSource[1], locations, destination: naiveDestination, effectiveDestination, staticallyDeclaredDestination: false }];
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(srcRoot, scriptExtension, webpackConfig, dest, config, sourceType) {
360
- const { assumeGlobalizedPlauditLibraries, combineAssetMetadata, externals, extensionsVersion, plainEntrypointsVersion, } = config;
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 (dest.bundleAnalyzer) {
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
- else {
395
- const localAssumeGlobalizedPlauditLibraries = dest.assumeGlobalizedPlauditLibraries ?? assumeGlobalizedPlauditLibraries;
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 { plugins, removeEmptyScriptsPlugin };
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
- //TODO: Try using context to avoid needing to cobble dest paths together?
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
- return sources.map(([src, dest]) => {
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
- switch ((0, shared_1.determineCurrentSourceType)(dest, srcIsDirectory)) {
456
- case "blocks" /* SourceType.blocks */: {
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
- return undefined;
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
- case "extensions" /* SourceType.extensions */: {
485
+ else if (sourceType === "extensions" /* SourceType.extensions */) {
464
486
  if (!srcIsDirectory) {
465
- return undefined;
487
+ continue;
466
488
  }
467
- const { plugins } = buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest, config, "extensions" /* SourceType.extensions */);
468
- return makeExtensionsWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins);
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
- case "plain" /* SourceType.plain */:
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
- return undefined;
510
+ continue;
475
511
  }
476
512
  }
477
- const { plugins } = buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest, config, "plain" /* SourceType.plain */);
513
+ const baseDest = stripExtension(dest.destination);
478
514
  if (config.plainEntrypointsVersion > 1) {
479
- return makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory);
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
- return makePlainV1WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory);
482
- }
483
- }).filter(cfg => cfg !== undefined);
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
- return Object.fromEntries(rawEntrypoints);
507
- };
508
- plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(config, srcRoot, dest, webpackConfig.context ?? process.cwd(), entry));
509
- return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, {}, plugins);
510
- }
511
- else {
512
- const plugin = new ExtensionsConfigFileGeneratorPluginV1_1.ExtensionsConfigFileGeneratorPluginV1(dest.destination);
513
- plugins.push(plugin);
514
- const entry = async () => {
515
- const rawEntrypoints = [];
516
- for await (const dirent of await promises_1.default.opendir(srcRoot)) {
517
- if (dirent.isFile() && !dirent.name.startsWith("~")) {
518
- if (commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name)) {
519
- const file = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
520
- rawEntrypoints.push([node_path_1.default.join(dest.destination, node_path_1.default.basename(file, node_path_1.default.extname(file))), file]);
521
- }
522
- }
529
+ else {
530
+ console.error("Unrecognized sourceType");
531
+ continue;
523
532
  }
524
- return Object.fromEntries(rawEntrypoints);
525
- };
526
- return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, entry, plugins);
527
- }
528
- }
529
- function makePlainV1WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory) {
530
- const baseDest = stripExtension(dest.destination);
531
- const entry = srcIsDirectory // This being true implies that srcRoot is not an array
532
- ? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
533
- : () => ({ [baseDest]: srcRoot });
534
- return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, srcIsDirectory, dest, src, srcRoot, entry, plugins);
535
- }
536
- function makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory) {
537
- const baseDest = stripExtension(dest.destination);
538
- const entry = srcIsDirectory // This being true implies that srcRoot is not an array
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.63.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",