@plaudit/webpack-extensions 2.70.0 → 2.71.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.
@@ -1,5 +1,5 @@
1
1
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
- import { ParsedAssetsJson, BlockEntrypointInfo, FileSegmentBlockEntrypointInfo } from "../shared";
2
+ import { ParsedAssetsJson, BlockEntrypointInfo, FileSegmentBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
4
  import { Compilation } from "webpack";
5
5
  import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
@@ -14,10 +14,10 @@ type CollatedWorkableBlockInfo = Record<string, {
14
14
  blockJsonText?: string;
15
15
  }>;
16
16
  export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
17
- private readonly blocksDest;
17
+ private readonly dest;
18
18
  private readonly webpackRemoveEmptyScriptsPlugin;
19
19
  private static readonly semaphore;
20
- constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<BlockEntrypointInfo>);
20
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, dest: VerifiedAdvancedOutputConfig, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<BlockEntrypointInfo>);
21
21
  protected processAssets(compilation: Compilation, rawAssetData: ParsedAssetsJson): Promise<void>;
22
22
  private emitBlockLoaderFile;
23
23
  private transformBlocks;
@@ -15,12 +15,12 @@ const php_writer_1 = require("../utils/php-writer");
15
15
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
16
16
  const webpack_1 = require("webpack");
17
17
  class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
18
- blocksDest;
18
+ dest;
19
19
  webpackRemoveEmptyScriptsPlugin;
20
20
  static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Block JSON v3");
21
- constructor(config, blocksDest, webpackRemoveEmptyScriptsPlugin, context, entry) {
22
- super(config, `block-json-${blocksDest}`, [PlainEntrypointsStyleBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
23
- this.blocksDest = blocksDest;
21
+ constructor(config, dest, webpackRemoveEmptyScriptsPlugin, context, entry) {
22
+ super(config, `block-json-${dest.destination}`, [PlainEntrypointsStyleBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
23
+ this.dest = dest;
24
24
  this.webpackRemoveEmptyScriptsPlugin = webpackRemoveEmptyScriptsPlugin;
25
25
  }
26
26
  async processAssets(compilation, rawAssetData) {
@@ -64,7 +64,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
64
64
  }
65
65
  const workableBlockEntrypointsInfo = entrypoint.getFiles()
66
66
  .map(file => this.stripOffBlocksDestPrefix(file))
67
- .filter(file => !this.webpackRemoveEmptyScriptsPlugin['trash'].includes(node_path_1.default.join(this.blocksDest, file)))
67
+ .filter(file => !this.webpackRemoveEmptyScriptsPlugin['trash'].includes(node_path_1.default.join(this.dest.destination, file)))
68
68
  .map(file => [file, (0, shared_1.scriptOrStyleTest)(file, shared_1.scriptExtension)])
69
69
  .filter((item) => item[1] !== '')
70
70
  .map(([file, assetType]) => {
@@ -87,14 +87,32 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
87
87
  }
88
88
  }
89
89
  PlainEntrypointsStyleBlockJSONPlugin.semaphore.resolve(this.id, {
90
- collatableWorkableBlockInfo: applicableBlockJsonFiles, blocksDest: this.blocksDest,
91
- emittingWpmlXml: compilation.getAsset(node_path_1.default.join(this.blocksDest, "wpml-config.xml")) !== undefined
90
+ collatableWorkableBlockInfo: applicableBlockJsonFiles, blocksDest: this.dest.destination,
91
+ emittingWpmlXml: compilation.getAsset(node_path_1.default.join(this.dest.destination, "wpml-config.xml")) !== undefined
92
92
  });
93
+ const generateLoader = (writer) => {
94
+ writer.require(node_path_1.default.join(this.dest.destination, "blockdir-loader.php"), { dirRelative: true, once: true });
95
+ };
96
+ let action;
97
+ const lazyLoader = this.dest.lazyLoader;
98
+ if (lazyLoader) {
99
+ try {
100
+ action = writer => writer.function(lazyLoader, [], generateLoader, { returnType: 'void' });
101
+ }
102
+ catch (e) {
103
+ compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for lazily loading blocks", { cause: e }], this.dest.destination));
104
+ this.rejectSemaphores();
105
+ return;
106
+ }
107
+ }
108
+ else {
109
+ action = writer => writer.withScope(generateLoader);
110
+ }
93
111
  UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(applicableBlockJsonFiles).length ? {
94
112
  group: this.group,
95
113
  requiresBaseURI: false,
96
114
  staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray()),
97
- action: writer => writer.require(node_path_1.default.join(this.blocksDest, "blockdir-loader.php"), { dirRelative: true, once: true })
115
+ action
98
116
  } : undefined);
99
117
  }
100
118
  emitBlockLoaderFile(compilation, blockData) {
@@ -106,10 +124,10 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
106
124
  writer.call("\\Plaudit\\Common\\ACF\\BlockManager::autoloadSubfoldersV3", [php_writer_1.Constants.__DIR__, new php_writer_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockData, false, "\t")),
107
125
  php_writer_1.Constants.__FILE__, new php_writer_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(metadata, false, "\t")), null]);
108
126
  }, { accountForAlreadyDoing: this.config.includePostInitFallback })
109
- .emitAsset(compilation, node_path_1.default.join(this.blocksDest, "blockdir-loader.php"));
127
+ .emitAsset(compilation, node_path_1.default.join(this.dest.destination, "blockdir-loader.php"));
110
128
  }
111
129
  else {
112
- compilation.emitAsset(node_path_1.default.join(this.blocksDest, "blockdir.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockData, true)));
130
+ compilation.emitAsset(node_path_1.default.join(this.dest.destination, "blockdir.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockData, true)));
113
131
  }
114
132
  }
115
133
  transformBlocks(compilation, collatedWorkableBlockInfo, emittingWpmlXml) {
@@ -141,7 +159,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
141
159
  blockJson["version"] = hashForVersion;
142
160
  }
143
161
  PlainEntrypointsStyleBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
144
- const blockDirName = node_path_1.default.dirname(node_path_1.default.relative(this.blocksDest, blockJsonAssetName));
162
+ const blockDirName = node_path_1.default.dirname(node_path_1.default.relative(this.dest.destination, blockJsonAssetName));
145
163
  blockData[blockDirName] = PlainEntrypointsStyleBlockJSONPlugin
146
164
  .doFileOrHandleReplacements(compilation, Object.fromEntries(Object.entries(blockJson).filter(([k]) => k !== '$schema')), workableBlockEntrypointsInfo, epi => epi.handle);
147
165
  compilation[blockJsonAssetName in compilation.assets ? 'updateAsset' : 'emitAsset'](blockJsonAssetName, new webpack_1.sources.RawSource(JSON.stringify(PlainEntrypointsStyleBlockJSONPlugin
@@ -215,7 +233,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
215
233
  return blockJson;
216
234
  }
217
235
  stripOffBlocksDestPrefix(file) {
218
- return this.blocksDest && file.startsWith(this.blocksDest + "/") ? file.substring(this.blocksDest.length + 1 /* we also need to drop the "/" */) : file;
236
+ return this.dest.destination && file.startsWith(this.dest.destination + "/") ? file.substring(this.dest.destination.length + 1 /* we also need to drop the "/" */) : file;
219
237
  }
220
238
  static hashThingForAsset(thing) {
221
239
  return node_crypto_1.default.createHash('md5').update(thing).digest("hex").substring(0, 20).toLowerCase();
@@ -348,9 +366,9 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
348
366
  (acc[cur.blocksDest] ?? (acc[cur.blocksDest] = [])).push(cur);
349
367
  return acc;
350
368
  }, {});
351
- const semaphoreData = allSemaphoreData[this.blocksDest];
369
+ const semaphoreData = allSemaphoreData[this.dest.destination];
352
370
  if (semaphoreData === undefined) {
353
- compilation.errors.push(new Error(`Semaphore data missing for ${this.blocksDest}`));
371
+ compilation.errors.push(new Error(`Semaphore data missing for ${this.dest.destination}`));
354
372
  return;
355
373
  }
356
374
  const workableBlockInfo = semaphoreData.map(sd => sd.collatableWorkableBlockInfo)
package/build/shared.d.ts CHANGED
@@ -82,11 +82,12 @@ type OptionalCfgFields = 'directoryLayout' | 'externalize' | 'lazyLoader';
82
82
  export type VerifiedAdvancedOutputConfig = Required<Omit<AdvancedOutputConfig, 'locations' | OptionalCfgFields>> & Pick<AdvancedOutputConfig, OptionalCfgFields> & {
83
83
  locations: UsageLocations;
84
84
  };
85
+ export type SourcesObject = Record<string, string | AdvancedOutputConfig | boolean>;
85
86
  export type PlauditWordpressWebpackConfig = {
86
87
  standaloneBlocks?: boolean;
87
88
  variables?: Record<string, any>;
88
89
  verbose?: boolean;
89
- src: string[] | Record<string, string | AdvancedOutputConfig | boolean>;
90
+ src: string[] | SourcesObject;
90
91
  stats?: Configuration['stats'];
91
92
  postcss?: {
92
93
  functions?: (variables: (name: string) => unknown) => PostcssFunctionsOptions['functions'];
@@ -172,7 +172,7 @@ function injectSupportForInliningSVGsAsStrings(rules) {
172
172
  });
173
173
  }
174
174
  function buildVerifiedConfig(config) {
175
- 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 = "", plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = true } = config;
175
+ 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 = "", plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = false } = config;
176
176
  let srcPrefixes;
177
177
  const trailingSlashedSrcDir = srcDir && !srcDir.endsWith("/") ? srcDir + "/" : srcDir;
178
178
  if (config.srcPrefixes === undefined) {
@@ -480,6 +480,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
480
480
  const { bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize } = currentBatch[0].dest;
481
481
  const { plugins, removeEmptyScriptsPlugin, makeAdditionalDependencyInjectorPlugin } = buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize);
482
482
  handleDisablingTSCheckerIfNecessary(currentBatch.flatMap(a => a.srcRoots), scriptExtension, plugins);
483
+ const contextPath = webpackConfig.context ?? process.cwd();
483
484
  for (const { dest, src, srcIsDirectory, srcRoot } of currentBatch) {
484
485
  let plugin;
485
486
  const sourceType = (0, shared_1.determineCurrentSourceType)(dest, srcIsDirectory);
@@ -487,7 +488,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
487
488
  if (!srcIsDirectory) {
488
489
  continue;
489
490
  }
490
- plugin = new PlainEntrypointsStyleBlockJSONPlugin_1.PlainEntrypointsStyleBlockJSONPlugin(config, dest.destination, removeEmptyScriptsPlugin, webpackConfig.context ?? process.cwd(), (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
491
+ plugin = new PlainEntrypointsStyleBlockJSONPlugin_1.PlainEntrypointsStyleBlockJSONPlugin(config, dest, removeEmptyScriptsPlugin, contextPath, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
491
492
  plugins.push(plugin);
492
493
  if (config.processTranslationConfigs && !processingModules) {
493
494
  plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination, plugin));
@@ -510,8 +511,8 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
510
511
  return Object.fromEntries(rawEntrypoints);
511
512
  };
512
513
  plugin = config.extensionsVersion > 1
513
- ? new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(config, srcRoot, dest, webpackConfig.context ?? process.cwd(), entry)
514
- : new ExtensionsConfigFileGeneratorPluginV1_1.ExtensionsConfigFileGeneratorPluginV1(config, dest.destination, webpackConfig.context ?? process.cwd(), entry);
514
+ ? new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(config, srcRoot, dest, contextPath, entry)
515
+ : new ExtensionsConfigFileGeneratorPluginV1_1.ExtensionsConfigFileGeneratorPluginV1(config, dest.destination, contextPath, entry);
515
516
  plugins.push(plugin);
516
517
  }
517
518
  else if (sourceType === "plain" /* SourceType.plain */) {
@@ -526,14 +527,14 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
526
527
  const entry = srcIsDirectory // This being true implies that srcRoot is not an array
527
528
  ? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
528
529
  : () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest } } });
529
- plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest.locations, config.useUnifiedLoader, webpackConfig.context ?? process.cwd(), entry);
530
+ plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest.locations, config.useUnifiedLoader, contextPath, entry);
530
531
  }
531
532
  else {
532
533
  if (srcIsDirectory) {
533
534
  console.error("Using directory mode with legacy plain entrypoint handling is not supported");
534
535
  continue;
535
536
  }
536
- plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(config, webpackConfig.context ?? process.cwd(), () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest } } }));
537
+ plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(config, contextPath, () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest } } }));
537
538
  }
538
539
  plugins.push(plugin);
539
540
  }
package/package.json CHANGED
@@ -1,26 +1,30 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.70.0",
3
+ "version": "2.71.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build"
7
7
  ],
8
8
  "exports": {
9
- "./wordpress-scripts-wrapper": "./build/wordpress-scripts-wrapper.js"
9
+ "./wordpress-scripts-wrapper": "./build/wordpress-scripts-wrapper.js",
10
+ "./shared": "./build/shared.js"
10
11
  },
11
12
  "typesVersions": {
12
13
  "*": {
13
14
  "wordpress-scripts-wrapper": [
14
15
  "build/wordpress-scripts-wrapper.d.ts"
16
+ ],
17
+ "shared": [
18
+ "build/shared.d.ts"
15
19
  ]
16
20
  }
17
21
  },
18
22
  "devDependencies": {
19
23
  "@plaudit/gutenberg-api-extensions": "^2.77.2",
20
24
  "@types/browser-sync-webpack-plugin": "^2.2.5",
21
- "@types/node": "^24.6.1",
25
+ "@types/node": "^24.7.1",
22
26
  "@types/postcss-functions": "^4.0.4",
23
- "@types/tapable": "^2.2.7",
27
+ "@types/tapable": "^2.3.0",
24
28
  "@types/webpack": "^5.28.5",
25
29
  "@types/webpack-sources": "^3.2.3",
26
30
  "postcss-load-config": "^4.0.2",
@@ -59,7 +63,7 @@
59
63
  "postcss-url": "^10.1.3",
60
64
  "react": "^18.3.1",
61
65
  "react-dom": "^18.3.1",
62
- "webpack": "^5.102.0",
66
+ "webpack": "^5.102.1",
63
67
  "webpack-remove-empty-scripts": "^1.1.1",
64
68
  "xml-formatter": "^3.6.7"
65
69
  },