@plaudit/webpack-extensions 2.38.0 → 2.40.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.
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  const node_fs_1 = __importDefault(require("node:fs"));
6
+ const promises_1 = __importDefault(require("node:fs/promises"));
6
7
  const node_path_1 = __importDefault(require("node:path"));
7
8
  const AdditionalDependencyInjectorPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin"));
8
9
  const BlockJSONManagingPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/BlockJSONManagingPlugin"));
@@ -12,6 +13,7 @@ const MiniCSSExtractPluginErrorCleaner_1 = __importDefault(require("./wordpress-
12
13
  const VariablesJSMonitorPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/VariablesJSMonitorPlugin"));
13
14
  const BrowserSyncPlugin_1 = require("./wordpress-scripts-wrapper/BrowserSyncPlugin");
14
15
  const static_configs_1 = require("./wordpress-scripts-wrapper/static-configs");
16
+ const WPMLConfigBuilder_1 = __importDefault(require("./wordpress-scripts-wrapper/WPMLConfigBuilder"));
15
17
  const dependency_extraction_webpack_plugin_1 = __importDefault(require("@wordpress/dependency-extraction-webpack-plugin"));
16
18
  const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
17
19
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
@@ -246,7 +248,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
246
248
  scriptExtension = scriptWithoutModuleExtension;
247
249
  entrypointFields = ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script"];
248
250
  }
249
- const { standaloneBlocks, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries } = config;
251
+ const { standaloneBlocks, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, combineAssetMetadata } = config;
250
252
  let currentVariables = config.currentVariables;
251
253
  const fixedRules = [
252
254
  replaceDefaultURLProcessing,
@@ -255,6 +257,16 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
255
257
  },
256
258
  injectSupportForInliningSVGsAsStrings
257
259
  ].reduce((r, a) => a(r), webpackConfig.module?.rules ?? []);
260
+ if (config.processTranslationConfigs) {
261
+ fixedRules.push({
262
+ test: /wpml-config\.xml$/i,
263
+ type: 'asset/resource',
264
+ generator: {
265
+ filename: '[name][ext]',
266
+ emit: false
267
+ }
268
+ });
269
+ }
258
270
  return sources.map(([src, dest]) => {
259
271
  const srcRoots = (typeof dest !== 'string' && dest.withLegacyBlocksIn
260
272
  ? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(dest.withLegacyBlocksIn)]
@@ -302,22 +314,26 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
302
314
  if (variablesFilePath) {
303
315
  plugins.push(new VariablesJSMonitorPlugin_1.default(variablesFilePath));
304
316
  }
305
- if (copyFiles && (typeof dest === 'string' || dest.directoryLayout !== 'extensions')) {
306
- plugins.push(new BlockJSONManagingPlugin_1.default(standaloneBlocks, processingModules));
307
- }
308
- plugins.push(new AdditionalDependencyInjectorPlugin_1.default(typeof dest !== 'string' && dest.additionalDependencies ? dest.additionalDependencies : [], processingModules));
309
- if (srcIsDirectory && (typeof dest !== 'string' && dest.directoryLayout === 'extensions')) {
310
- plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.default(srcRoot));
317
+ const forBlocksDirectory = copyFiles && (typeof dest === 'string' || dest.directoryLayout !== 'extensions');
318
+ if (forBlocksDirectory) {
319
+ const blockJSONManagingPlugin = new BlockJSONManagingPlugin_1.default(standaloneBlocks, processingModules);
320
+ plugins.push(blockJSONManagingPlugin);
321
+ if (config.processTranslationConfigs && srcIsDirectory && !processingModules) {
322
+ plugins.push(new WPMLConfigBuilder_1.default(blockJSONManagingPlugin));
323
+ }
311
324
  }
312
325
  const pluginIndex = plugins.findIndex(plugin => plugin instanceof dependency_extraction_webpack_plugin_1.default);
313
326
  if (pluginIndex === -1) {
314
327
  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 file");
315
328
  }
316
329
  else {
317
- const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, (typeof dest !== 'string' ? dest.assumeGlobalizedPlauditLibraries : undefined) ?? assumeGlobalizedPlauditLibraries);
318
- if (builtDependencyExtractionWebpackPlugin) {
319
- plugins[pluginIndex] = builtDependencyExtractionWebpackPlugin;
320
- }
330
+ const localAssumeGlobalizedPlauditLibraries = typeof dest !== 'string' ? dest.assumeGlobalizedPlauditLibraries : undefined;
331
+ const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, localAssumeGlobalizedPlauditLibraries ?? assumeGlobalizedPlauditLibraries, combineAssetMetadata && !processingModules && forBlocksDirectory);
332
+ plugins[pluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
333
+ plugins.push(new AdditionalDependencyInjectorPlugin_1.default(typeof dest !== 'string' && dest.additionalDependencies ? dest.additionalDependencies : [], processingModules, builtDependencyExtractionWebpackPlugin.addExternalizedDep));
334
+ }
335
+ if (srcIsDirectory && (typeof dest !== 'string' && dest.directoryLayout === 'extensions')) {
336
+ plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.default(srcRoot));
321
337
  }
322
338
  if (process.argv.includes('--browser-sync') || process.env['BROWSER_SYNC'] === 'true') {
323
339
  plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin());
@@ -325,50 +341,69 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
325
341
  let entry;
326
342
  if (srcIsDirectory) {
327
343
  if (typeof dest !== 'string' && dest.directoryLayout === 'extensions') {
328
- entry = () => {
329
- const rawEntrypoints = node_fs_1.default.readdirSync(srcRoot, 'utf8')
330
- .map(file => joinPossiblyAbsolutePaths(srcRoot, file))
331
- .filter(file => (scriptExtension.test(file) || styleExtension.test(file)) && node_fs_1.default.statSync(file).isFile())
332
- .map((file) => [node_path_1.default.basename(file, node_path_1.default.extname(file)), file]);
344
+ entry = async () => {
345
+ const rawEntrypoints = [];
346
+ for await (const dirent of await promises_1.default.opendir(srcRoot)) {
347
+ if (dirent.isFile()) {
348
+ if (scriptExtension.test(dirent.name) || styleExtension.test(dirent.name)) {
349
+ const file = joinPossiblyAbsolutePaths(srcRoot, dirent.name);
350
+ rawEntrypoints.push([node_path_1.default.basename(file, node_path_1.default.extname(file)), file]);
351
+ }
352
+ }
353
+ }
333
354
  return Object.fromEntries(rawEntrypoints);
334
355
  };
335
356
  }
336
357
  else {
337
- entry = () => {
338
- const rawEntrypoints = node_fs_1.default.readdirSync(srcRoot, 'utf8')
339
- .map(dir => joinPossiblyAbsolutePaths(srcRoot, dir))
340
- .filter(dir => node_fs_1.default.statSync(dir).isDirectory())
341
- .flatMap(dir => {
342
- const res = [];
343
- try {
344
- const blockJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'block.json'), 'utf8'));
345
- const blockJSONChunkName = node_path_1.default.join(node_path_1.default.basename(dir), "block.json");
346
- for (const key of entrypointFields) {
347
- if (key in blockJSON) {
348
- res.push(...mapToRealEntrypoints(blockJSON[key], dir, ep => ep.startsWith("file:") ? ep.substring(5) : ep, blockJSONChunkName));
349
- }
350
- }
351
- BlockJSONManagingPlugin_1.default.recordBlockJSONAssetSourceDir(blockJSONChunkName, dir);
352
- return res;
358
+ entry = async () => {
359
+ const loadingEntrypoints = [];
360
+ for await (const dirent of await promises_1.default.opendir(srcRoot)) {
361
+ if (!dirent.isDirectory()) {
362
+ continue;
353
363
  }
354
- catch (e) {
364
+ const dir = joinPossiblyAbsolutePaths(srcRoot, dirent.name);
365
+ loadingEntrypoints.push(new Promise(async (resolve) => {
366
+ const rawEntrypoints = [];
367
+ const wpmlFiles = [];
355
368
  try {
356
- const packageJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'package.json'), 'utf8'));
357
- res.push(...mapToRealEntrypoints(packageJSON['main'], dir));
358
- res.push(...mapToRealEntrypoints(packageJSON['style'], dir));
369
+ const blockJSON = JSON.parse(await promises_1.default.readFile(node_path_1.default.join(dir, 'block.json'), 'utf8'));
370
+ const blockJSONChunkName = node_path_1.default.join(node_path_1.default.basename(dir), "block.json");
371
+ for (const key of entrypointFields) {
372
+ if (key in blockJSON) {
373
+ rawEntrypoints.push(...mapToRealEntrypoints(blockJSON[key], dir, ep => ep.startsWith("file:") ? ep.substring(5) : ep, blockJSONChunkName));
374
+ }
375
+ }
376
+ wpmlFiles.push(node_path_1.default.join(dir, 'block.json'));
377
+ BlockJSONManagingPlugin_1.default.recordBlockJSONAssetSourceDir(blockJSONChunkName, dir);
359
378
  }
360
379
  catch (e) {
361
380
  try {
362
- res.push(...parseEntrypointsJSON(dir));
381
+ const packageJSON = JSON.parse(await promises_1.default.readFile(node_path_1.default.join(dir, 'package.json'), 'utf8'));
382
+ rawEntrypoints.push(...mapToRealEntrypoints(packageJSON['main'], dir));
383
+ rawEntrypoints.push(...mapToRealEntrypoints(packageJSON['style'], dir));
363
384
  }
364
385
  catch (e) {
365
- // This just means that the directory doesn't contain any declared entrypoints.
386
+ try {
387
+ rawEntrypoints.push(...parseEntrypointsJSON(dir));
388
+ }
389
+ catch (e) {
390
+ // This just means that the directory doesn't contain any declared entrypoints.
391
+ }
366
392
  }
367
393
  }
368
- }
369
- return res;
370
- });
371
- const perAssetPathGroupedEntrypoints = groupEntrypointsByAssetFile(rawEntrypoints, e => e[0]);
394
+ try {
395
+ const wpmlFilePath = node_path_1.default.join(dir, "wpml-config.xml");
396
+ await promises_1.default.access(wpmlFilePath);
397
+ wpmlFiles.push(wpmlFilePath);
398
+ }
399
+ catch (e) {
400
+ // This just means that the file doesn't exist
401
+ }
402
+ resolve([rawEntrypoints, wpmlFiles]);
403
+ }));
404
+ }
405
+ const allEntrypoints = await Promise.all(loadingEntrypoints);
406
+ const perAssetPathGroupedEntrypoints = groupEntrypointsByAssetFile(allEntrypoints.flatMap(e => e[0]), e => e[0]);
372
407
  const currentEntry = {};
373
408
  for (const groupedEntrypoints of perAssetPathGroupedEntrypoints.values()) {
374
409
  if (groupedEntrypoints.length === 1 && groupedEntrypoints[0] !== undefined) {
@@ -387,6 +422,16 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
387
422
  BlockJSONManagingPlugin_1.default.recordRawDependency(entry.lazyDependent, key);
388
423
  }
389
424
  }
425
+ const wpmlEntrypointFiles = allEntrypoints.flatMap(e => e[1]);
426
+ try {
427
+ await promises_1.default.access(node_path_1.default.join(srcRoot, "wpml-config.xml"));
428
+ currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles] };
429
+ }
430
+ catch (e) {
431
+ if (wpmlEntrypointFiles.length) {
432
+ currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles };
433
+ }
434
+ }
390
435
  return currentEntry;
391
436
  };
392
437
  }
@@ -469,13 +514,13 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
469
514
  }
470
515
  module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
471
516
  testForDuplicatedEntryPaths(config);
472
- const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true } = config;
517
+ 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 } = config;
473
518
  let variablesFilePath = undefined;
474
519
  const currentVariables = rawVariables ?? {};
475
520
  if (!rawVariables) {
476
521
  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];
477
522
  }
478
- const cfg = { currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries };
523
+ const cfg = { currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, processTranslationConfigs, combineAssetMetadata };
479
524
  const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
480
525
  if (Array.isArray(webpackConfig)) {
481
526
  return webpackConfig.toSorted((a, b) => {
package/package.json CHANGED
@@ -1,74 +1,93 @@
1
1
  {
2
- "name": "@plaudit/webpack-extensions",
3
- "version": "2.38.0",
4
- "license": "UNLICENSED",
5
- "scripts": {
6
- "prepublishOnly": "rm -rf build && mkdir build && tsc",
7
- "build": "tsc",
8
- "watch": "tsc -w"
9
- },
10
- "files": [
11
- "/build"
12
- ],
13
- "exports": {
14
- "./wordpress-scripts-wrapper": "./build/wordpress-scripts-wrapper.js"
15
- },
16
- "typesVersions": {
17
- "*": {
18
- "wordpress-scripts-wrapper": [
19
- "build/wordpress-scripts-wrapper.d.ts"
20
- ]
21
- }
22
- },
23
- "devDependencies": {
24
- "@types/browser-sync-webpack-plugin": "^2.2.5",
25
- "@types/postcss-functions": "^4.0.4",
26
- "@types/node": "^22.9.0",
27
- "@types/tapable": "^2.2.7",
28
- "@types/webpack": "^5.28.5",
29
- "@types/webpack-sources": "^3.2.3",
30
- "postcss-load-config": "^4.0.2",
31
- "postcss-loader": "^7.3.4",
32
- "ts-node": "^10.9.2",
33
- "typescript": "^5.6.3"
34
- },
35
- "dependencies": {
36
- "@plaudit/postcss-color-function": "^5.0.0",
37
- "@plaudit/postcss-silent-extend": "^3.0.0",
38
- "@plaudit/postcss-strip-units": "^3.0.0",
39
- "@plaudit/postcss-variables": "^1.0.0",
40
- "@wordpress/dependency-extraction-webpack-plugin": "^6.11.0",
41
- "@wordpress/scripts": "^30.4.0",
42
- "autoprefixer": "^10.4.19",
43
- "browser-sync": "^3.0.3",
44
- "clean-webpack-plugin": "^4.0.0",
45
- "copy-webpack-plugin": "^12.0.2",
46
- "cssnano": "^6.1.2",
47
- "eslint": "^8.57.0",
48
- "eslint-plugin-jsdoc": "^48.2.3",
49
- "fork-ts-checker-webpack-plugin": "^9.0.2",
50
- "http-proxy-middleware": "^3.0.3",
51
- "postcss": "^8.4.39",
52
- "postcss-calc": "^9.0.1",
53
- "postcss-discard-comments": "^6.0.2",
54
- "postcss-fallback": "^0.1.0",
55
- "postcss-functions": "^4.0.2",
56
- "postcss-import": "^16.1.0",
57
- "postcss-inline-svg": "^6.0.0",
58
- "postcss-media-minmax": "^5.0.0",
59
- "postcss-mixins": "6.2.3",
60
- "postcss-nested": "^6.0.1",
61
- "postcss-property-lookup": "^3.0.0",
62
- "postcss-quantity-queries": "^0.5.0",
63
- "postcss-reporter": "^7.1.0",
64
- "postcss-short-position": "^4.0.1",
65
- "postcss-short-size": "^4.0.0",
66
- "postcss-short-spacing": "^4.0.0",
67
- "postcss-simple-vars": "^7.0.1",
68
- "postcss-url": "^10.1.3",
69
- "react": "^18.3.1",
70
- "react-dom": "^18.3.1",
71
- "webpack": "^5.96.1",
72
- "webpack-remove-empty-scripts": "^1.0.4"
73
- }
2
+ "name": "@plaudit/webpack-extensions",
3
+ "version": "2.40.0",
4
+ "license": "UNLICENSED",
5
+ "scripts": {
6
+ "prepublishOnly": "rm -rf build && mkdir build && tsc",
7
+ "build": "tsc",
8
+ "watch": "tsc -w"
9
+ },
10
+ "files": [
11
+ "/build"
12
+ ],
13
+ "exports": {
14
+ "./wordpress-scripts-wrapper": "./build/wordpress-scripts-wrapper.js"
15
+ },
16
+ "typesVersions": {
17
+ "*": {
18
+ "wordpress-scripts-wrapper": [
19
+ "build/wordpress-scripts-wrapper.d.ts"
20
+ ]
21
+ }
22
+ },
23
+ "devDependencies": {
24
+ "@plaudit/gutenberg-api-extensions": "^2.66.0",
25
+ "@types/browser-sync-webpack-plugin": "^2.2.5",
26
+ "@types/node": "^22.13.13",
27
+ "@types/postcss-functions": "^4.0.4",
28
+ "@types/tapable": "^2.2.7",
29
+ "@types/webpack": "^5.28.5",
30
+ "@types/webpack-sources": "^3.2.3",
31
+ "postcss-load-config": "^4.0.2",
32
+ "postcss-loader": "^7.3.4",
33
+ "ts-node": "^10.9.2",
34
+ "typescript": "^5.8.2"
35
+ },
36
+ "dependencies": {
37
+ "@plaudit/postcss-color-function": "^5.0.0",
38
+ "@plaudit/postcss-silent-extend": "^3.0.0",
39
+ "@plaudit/postcss-strip-units": "^3.0.0",
40
+ "@plaudit/postcss-variables": "^1.1.0",
41
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.20.0",
42
+ "@wordpress/scripts": "^30.13.0",
43
+ "autoprefixer": "^10.4.21",
44
+ "browser-sync": "^3.0.3",
45
+ "clean-webpack-plugin": "^4.0.0",
46
+ "copy-webpack-plugin": "^10.2.4",
47
+ "cssnano": "^6.1.2",
48
+ "eslint": "^8.57.1",
49
+ "eslint-plugin-jsdoc": "^48.11.0",
50
+ "fork-ts-checker-webpack-plugin": "^9.0.2",
51
+ "http-proxy-middleware": "^3.0.3",
52
+ "postcss": "^8.5.3",
53
+ "postcss-calc": "^9.0.1",
54
+ "postcss-discard-comments": "^6.0.2",
55
+ "postcss-fallback": "^0.1.0",
56
+ "postcss-functions": "^4.0.2",
57
+ "postcss-import": "^16.1.0",
58
+ "postcss-inline-svg": "^6.0.0",
59
+ "postcss-media-minmax": "^5.0.0",
60
+ "postcss-mixins": "6.2.3",
61
+ "postcss-nested": "^6.2.0",
62
+ "postcss-property-lookup": "^3.0.0",
63
+ "postcss-quantity-queries": "^0.5.0",
64
+ "postcss-reporter": "^7.1.0",
65
+ "postcss-short-position": "^4.0.1",
66
+ "postcss-short-size": "^4.0.0",
67
+ "postcss-short-spacing": "^4.0.0",
68
+ "postcss-simple-vars": "^7.0.1",
69
+ "postcss-url": "^10.1.3",
70
+ "react": "^18.3.1",
71
+ "react-dom": "^18.3.1",
72
+ "webpack": "^5.98.0",
73
+ "webpack-remove-empty-scripts": "^1.0.4",
74
+ "xml-formatter": "^3.6.5"
75
+ },
76
+ "engines": {
77
+ "node": ">=20"
78
+ },
79
+ "pnpm": {
80
+ "onlyBuiltDependencies": [
81
+ "core-js",
82
+ "core-js-pure"
83
+ ],
84
+ "ignoredBuiltDependencies": [
85
+ "@parcel/watcher"
86
+ ],
87
+ "overrides": {
88
+ "micromatch": "^4",
89
+ "react-autosize-textarea>react": "*",
90
+ "react-autosize-textarea>react-dom": "*"
91
+ }
92
+ }
74
93
  }