@plaudit/webpack-extensions 2.53.1 → 2.54.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/shared.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Configuration } from "webpack";
1
2
  export type SharedCache = {
2
3
  specialAssets?: {
3
4
  files: {
@@ -8,4 +9,53 @@ export type SharedCache = {
8
9
  };
9
10
  };
10
11
  };
12
+ extensionsConfig?: {
13
+ assets: RawAssetData[];
14
+ setupFiles: [string, string][];
15
+ };
16
+ };
17
+ export type RawAssetData = Record<string, {
18
+ dependencies: string[];
19
+ version: string;
20
+ }>;
21
+ export declare function isRawAssetData(thing: any): thing is RawAssetData;
22
+ type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
23
+ export type HandleData = {
24
+ src: string;
25
+ rest: BaseRestType | [...BaseRestType, {
26
+ strategy?: 'defer' | 'async';
27
+ in_footer?: boolean;
28
+ } | boolean];
29
+ };
30
+ export declare const enum SourceType {
31
+ blocks = "blocks",
32
+ extensions = "extensions",
33
+ plain = "plain"
34
+ }
35
+ export declare function determineCurrentSourceType(dest: string | AdvancedOutputConfig, canCopyFiles: boolean): SourceType;
36
+ export interface AdvancedOutputConfig {
37
+ destination: string;
38
+ withLegacyBlocksIn?: string | undefined;
39
+ additionalDependencies?: string[];
40
+ directoryLayout?: SourceType;
41
+ assumeGlobalizedPlauditLibraries?: boolean;
42
+ externalize?: Required<Configuration>['output']['library'];
43
+ bundleAnalyzer?: boolean;
44
+ }
45
+ export declare function makeEmittableConfigPHP(data: any): string;
46
+ export type Sync<V> = {
47
+ sync: Promise<V>;
48
+ resolve(v: V): void;
49
+ reject(): void;
50
+ done: boolean;
51
+ };
52
+ type Readiness<V> = {
53
+ nonModule: Sync<V>;
54
+ module: Sync<V>;
11
55
  };
56
+ export declare class SyncsManager<V> {
57
+ private readonly readinessMapping;
58
+ get(name: string): Readiness<V>;
59
+ private makeSync;
60
+ }
61
+ export {};
package/build/shared.js CHANGED
@@ -1,2 +1,59 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SyncsManager = void 0;
7
+ exports.isRawAssetData = isRawAssetData;
8
+ exports.determineCurrentSourceType = determineCurrentSourceType;
9
+ exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
10
+ const json_to_php_but_with____injection_1 = __importDefault(require("./wordpress-scripts-wrapper/json-to-php-but-with-__-injection"));
11
+ function isRawAssetData(thing) {
12
+ if (!thing || typeof thing !== 'object') {
13
+ return false;
14
+ }
15
+ for (const value of Object.values(thing)) {
16
+ if ((!value || typeof value !== 'object') ||
17
+ (!('dependencies' in value) || !Array.isArray(value.dependencies) || value.dependencies.some(d => typeof d !== 'string')) ||
18
+ (!('version' in value) || !value.version || typeof value.version !== 'string')) {
19
+ return false;
20
+ }
21
+ }
22
+ return true;
23
+ }
24
+ function determineCurrentSourceType(dest, canCopyFiles) {
25
+ if (typeof dest === 'string') {
26
+ return canCopyFiles ? "blocks" /* SourceType.blocks */ : "plain" /* SourceType.plain */;
27
+ }
28
+ else {
29
+ return dest.directoryLayout ?? (canCopyFiles ? "blocks" /* SourceType.blocks */ : "plain" /* SourceType.plain */);
30
+ }
31
+ }
32
+ function makeEmittableConfigPHP(data) {
33
+ return "<?php return "
34
+ + json_to_php_but_with____injection_1.default.make({ indent: "\t", linebreak: "\n", shortArraySyntax: true })(data, "")
35
+ .replaceAll(/(\n\t*)\[\s+],/gs, "$1[],")
36
+ .replaceAll(/\[\n\t+([^\n]+)\n\t+]/gs, (_, inner) => `[${inner.trim()}]`)
37
+ .replaceAll(/'rest' => \[\n\t+(\[(?:'[^']+')?]),\n\t+('[^']+')(?:,\n\t+(\[[^\n]+]))?\n\t+]/gs, (_, deps, hash, args) => `'rest' => [${[deps, hash, args].filter(value => !!value).join(", ")}]`)
38
+ + ";";
39
+ }
40
+ class SyncsManager {
41
+ readinessMapping = new Map();
42
+ get(name) {
43
+ const res = this.readinessMapping.get(name);
44
+ if (res) {
45
+ return res;
46
+ }
47
+ this.readinessMapping.set(name, { nonModule: this.makeSync(), module: this.makeSync() });
48
+ return this.readinessMapping.get(name);
49
+ }
50
+ makeSync() {
51
+ const res = { done: false };
52
+ res.sync = new Promise((resolve, reject) => {
53
+ res.resolve = (v) => resolve(v);
54
+ res.reject = () => reject();
55
+ });
56
+ return res;
57
+ }
58
+ }
59
+ exports.SyncsManager = SyncsManager;
@@ -11,7 +11,7 @@ export declare class BlockJSONManagingPlugin implements WebpackPluginInstance {
11
11
  private static readonly blockJsonRawDependenciesMap;
12
12
  private static readonly blockJSONAssetSourceDirs;
13
13
  private static readonly blockJsonAssetKeyMapping;
14
- private static readonly blockJsonAssetKeyReadinessMapping;
14
+ private static readonly syncsManager;
15
15
  readonly additionalMetadata: Map<string, any>;
16
16
  constructor(standaloneBlocks: boolean, processingModules: boolean);
17
17
  static recordRawDependency(entrypoint: string, dependency: string): void;
@@ -32,8 +32,6 @@ export declare class BlockJSONManagingPlugin implements WebpackPluginInstance {
32
32
  private static populateEntrypointsMap;
33
33
  private registerBlockJsonProcessor;
34
34
  private static normalizeRenderTemplate;
35
- private static getSyncs;
36
- private static makeSync;
37
35
  private static getAssetDetails;
38
36
  private static getAssetDataAccountingForCSS;
39
37
  private static findFirstChunkFileWithExtension;
@@ -7,7 +7,7 @@ exports.BlockJSONManagingPlugin = void 0;
7
7
  const node_crypto_1 = __importDefault(require("node:crypto"));
8
8
  const node_fs_1 = __importDefault(require("node:fs"));
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
- const json_to_php_but_with____injection_1 = __importDefault(require("./json-to-php-but-with-__-injection"));
10
+ const shared_1 = require("../shared");
11
11
  const webpack_1 = require("webpack");
12
12
  class BlockJSONManagingPlugin {
13
13
  standaloneBlocks;
@@ -21,7 +21,7 @@ class BlockJSONManagingPlugin {
21
21
  static blockJsonRawDependenciesMap = new Map();
22
22
  static blockJSONAssetSourceDirs = new Map();
23
23
  static blockJsonAssetKeyMapping = new Map();
24
- static blockJsonAssetKeyReadinessMapping = new Map();
24
+ static syncsManager = new shared_1.SyncsManager();
25
25
  additionalMetadata = new Map();
26
26
  constructor(standaloneBlocks, processingModules) {
27
27
  this.standaloneBlocks = standaloneBlocks;
@@ -254,7 +254,7 @@ class BlockJSONManagingPlugin {
254
254
  }
255
255
  }
256
256
  }
257
- const syncs = BlockJSONManagingPlugin.getSyncs(name);
257
+ const syncs = BlockJSONManagingPlugin.syncsManager.get(name);
258
258
  let assetKeyMappings = BlockJSONManagingPlugin.blockJsonAssetKeyMapping.get(name);
259
259
  if (!assetKeyMappings) {
260
260
  BlockJSONManagingPlugin.blockJsonAssetKeyMapping.set(name, assetKeyMappings = {});
@@ -435,12 +435,7 @@ class BlockJSONManagingPlugin {
435
435
  ...blockDirConfigs.map(entry => [entry[0], Object.fromEntries(Object.entries(entry[1]).filter(e => e[0] !== '$schema'))])
436
436
  ]);
437
437
  }
438
- compilation.emitAsset("blockdir.config.php", new webpack_1.sources.RawSource("<?php return "
439
- + json_to_php_but_with____injection_1.default.make({ indent: "\t", linebreak: "\n", shortArraySyntax: true })(sortedBlockDirConfigData, "")
440
- .replaceAll(/(\n\t*)\[\s+],/gs, "$1[],")
441
- .replaceAll(/\[\n\t+([^\n]+)\n\t+]/gs, (_, inner) => `[${inner.trim()}]`)
442
- .replaceAll(/'rest' => \[\n\t+(\[(?:'[^']+')?]),\n\t+('[^']+')(?:,\n\t+(\[[^\n]+]))?\n\t+]/gs, (_, deps, hash, args) => `'rest' => [${[deps, hash, args].filter(value => !!value).join(", ")}]`)
443
- + ";"));
438
+ compilation.emitAsset("blockdir.config.php", new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(sortedBlockDirConfigData)));
444
439
  });
445
440
  }
446
441
  static normalizeRenderTemplate(json, pathsNeedRemapping, sourceDir, outputDir, compilation) {
@@ -494,22 +489,6 @@ class BlockJSONManagingPlugin {
494
489
  }
495
490
  }
496
491
  }
497
- static getSyncs(name) {
498
- const res = BlockJSONManagingPlugin.blockJsonAssetKeyReadinessMapping.get(name);
499
- if (res) {
500
- return res;
501
- }
502
- BlockJSONManagingPlugin.blockJsonAssetKeyReadinessMapping.set(name, { nonModule: BlockJSONManagingPlugin.makeSync(), module: BlockJSONManagingPlugin.makeSync() });
503
- return BlockJSONManagingPlugin.blockJsonAssetKeyReadinessMapping.get(name);
504
- }
505
- static makeSync() {
506
- const res = { done: false };
507
- res.sync = new Promise((resolve, reject) => {
508
- res.resolve = (v) => resolve(v);
509
- res.reject = () => reject();
510
- });
511
- return res;
512
- }
513
492
  static getAssetDetails(blockFolder, blockName, asset, rawAssetData, derivedFilesMap, mappableKey, usedHandles) {
514
493
  if (!asset.startsWith("file:./")) {
515
494
  return undefined;
@@ -1,6 +1,10 @@
1
+ import { SharedCache } from "../shared";
1
2
  import { type Compiler, type WebpackPluginInstance } from "webpack";
2
3
  export declare class ExtensionsConfigFileGeneratorPlugin implements WebpackPluginInstance {
3
4
  private readonly extensionsPath;
4
- constructor(extensionsPath: string);
5
+ private readonly version;
6
+ private readonly cache;
7
+ constructor(extensionsPath: string, version: 1 | 2, cache: SharedCache);
5
8
  apply(compiler: Compiler): void;
9
+ private makeVersionOneAfterProcessAssets;
6
10
  }
@@ -6,12 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ExtensionsConfigFileGeneratorPlugin = void 0;
7
7
  const promises_1 = __importDefault(require("node:fs/promises"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
- const webpack_1 = require("webpack");
10
9
  const php_serializer_1 = __importDefault(require("./php-serializer"));
10
+ const shared_1 = require("../shared");
11
+ const webpack_1 = require("webpack");
11
12
  class ExtensionsConfigFileGeneratorPlugin {
12
13
  extensionsPath;
13
- constructor(extensionsPath) {
14
+ version;
15
+ cache;
16
+ constructor(extensionsPath, version, cache) {
14
17
  this.extensionsPath = extensionsPath;
18
+ this.version = version;
19
+ this.cache = cache;
15
20
  }
16
21
  apply(compiler) {
17
22
  compiler.hooks.make.tapPromise(this.constructor.name, async (compilation) => {
@@ -29,24 +34,92 @@ class ExtensionsConfigFileGeneratorPlugin {
29
34
  }
30
35
  await Promise.all(emissionPromises);
31
36
  });
32
- compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
33
- compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_ProcessAssets`, compilationAssets => {
34
- const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
35
- const mapping = {};
36
- for (const asset of Object.keys(compilationAssets)) {
37
- let match;
38
- if ((match = /^(.+?)-setup.php$/i.exec(asset)) && match[1]) {
39
- (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[1] = `${asset}`;
37
+ if (this.version === 2) {
38
+ const tapName = { name: `${this.constructor.name}_ProcessBlockJSONFiles`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT };
39
+ compiler.hooks.compilation.tap(this.constructor.name, compilation => {
40
+ this.cache.extensionsConfig = undefined;
41
+ compilation.hooks.processAssets.tap(tapName, assets => {
42
+ if (this.cache.extensionsConfig === undefined) {
43
+ this.cache.extensionsConfig = { assets: [], setupFiles: [] };
44
+ compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_GenerateConfigFile`, () => {
45
+ const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
46
+ const blockExtensionsConfig = { metadata: { version: this.version }, scriptHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {} };
47
+ for (const assetDataSource of this.cache.extensionsConfig?.assets ?? []) {
48
+ for (const [assetPath, assetData] of Object.entries(assetDataSource)) {
49
+ let match, blockSlug, assetType;
50
+ if ((match = regex.exec(assetPath)) && (blockSlug = match[1]) && (assetType = match[2])) {
51
+ const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
52
+ const handle = `plaudit_block-extension_${blockSlug}-${assetType}`;
53
+ const isCss = assetType.endsWith("tyle");
54
+ blockExtensionsConfig[isCss ? 'styleHandles' : 'scriptHandles'][handle] = {
55
+ src: isCss ? assetPath.replace(/\.js$/, ".css") : assetPath,
56
+ rest: isCss || key.startsWith("editor")
57
+ ? [assetData.dependencies, assetData.version]
58
+ : [assetData.dependencies, assetData.version, { strategy: 'defer' }]
59
+ };
60
+ (blockExtensionsConfig.blocks[blockSlug] ?? (blockExtensionsConfig.blocks[blockSlug] = {}))[key] = handle;
61
+ }
62
+ }
63
+ for (const [blockSlug, asset] of this.cache.extensionsConfig?.setupFiles ?? []) {
64
+ blockExtensionsConfig.setupFiles[blockSlug] = asset;
65
+ }
66
+ }
67
+ blockExtensionsConfig.scriptHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptHandles)
68
+ .toSorted(([a], [b]) => a.localeCompare(b)));
69
+ blockExtensionsConfig.styleHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.styleHandles)
70
+ .toSorted(([a], [b]) => a.localeCompare(b)));
71
+ blockExtensionsConfig.setupFiles = Object.fromEntries(Object.entries(blockExtensionsConfig.setupFiles)
72
+ .toSorted(([a], [b]) => a.localeCompare(b)));
73
+ blockExtensionsConfig.blocks = Object.fromEntries(Object.entries(blockExtensionsConfig.blocks)
74
+ .map(block => {
75
+ return [block[0], Object.fromEntries(Object.entries(block[1]).toSorted(([a], [b]) => a.localeCompare(b)))];
76
+ })
77
+ .toSorted(([a], [b]) => a.localeCompare(b)));
78
+ compilation.emitAsset("mapping.config.php", new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig)));
79
+ });
40
80
  }
41
- else if ((match = regex.exec(asset)) && match[1] && match[2]) {
42
- const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
43
- const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
44
- (resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset]);
81
+ for (const asset of Object.keys(compilation.assets)) {
82
+ const blockSlug = /^(.+?)-setup.php$/i.exec(asset)?.[1];
83
+ if (blockSlug) {
84
+ this.cache.extensionsConfig.setupFiles.push([blockSlug, asset]);
85
+ }
45
86
  }
46
- }
47
- compilation.emitAsset("mapping.config", new webpack_1.sources.RawSource((0, php_serializer_1.default)(mapping)));
87
+ const rawAssetDataSource = assets["assets.json"]?.source();
88
+ if (typeof rawAssetDataSource !== 'string') {
89
+ throw new Error("assets.json is unexpectedly missing or not a string");
90
+ }
91
+ const assetDataSource = JSON.parse(rawAssetDataSource);
92
+ if (!(0, shared_1.isRawAssetData)(assetDataSource)) {
93
+ throw new Error("assets.json is does not match the RawAssetData format");
94
+ }
95
+ this.cache.extensionsConfig.assets.push(assetDataSource);
96
+ compilation.deleteAsset("assets.json");
97
+ });
48
98
  });
49
- });
99
+ }
100
+ else {
101
+ compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
102
+ compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_AfterProcessAssets`, this.makeVersionOneAfterProcessAssets(compilation));
103
+ });
104
+ }
105
+ }
106
+ makeVersionOneAfterProcessAssets(compilation) {
107
+ return compilationAssets => {
108
+ const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
109
+ const mapping = {};
110
+ for (const asset of Object.keys(compilationAssets)) {
111
+ let match;
112
+ if ((match = /^(.+?)-setup.php$/i.exec(asset)) && match[1]) {
113
+ (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[1] = `${asset}`;
114
+ }
115
+ else if ((match = regex.exec(asset)) && match[1] && match[2]) {
116
+ const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
117
+ const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
118
+ (resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset]);
119
+ }
120
+ }
121
+ compilation.emitAsset("mapping.config", new webpack_1.sources.RawSource((0, php_serializer_1.default)(mapping)));
122
+ };
50
123
  }
51
124
  }
52
125
  exports.ExtensionsConfigFileGeneratorPlugin = ExtensionsConfigFileGeneratorPlugin;
@@ -1,15 +1,7 @@
1
+ import { AdvancedOutputConfig } from "./shared";
1
2
  import { type Externals } from "./wordpress-scripts-wrapper/dependency-extraction-webpack-plugin-config-builder";
2
3
  import type { Options as PostcssFunctionsOptions } from "postcss-functions";
3
4
  import type { Configuration } from "webpack";
4
- interface AdvancedOutputConfig {
5
- destination: string;
6
- withLegacyBlocksIn?: string | undefined;
7
- additionalDependencies?: string[];
8
- directoryLayout?: 'blocks' | 'extensions' | 'plain';
9
- assumeGlobalizedPlauditLibraries?: boolean;
10
- externalize?: Required<Configuration>['output']['library'];
11
- bundleAnalyzer?: boolean;
12
- }
13
5
  type PlauditWordpressWebpackConfig = {
14
6
  standaloneBlocks?: boolean;
15
7
  variables?: Record<string, any>;
@@ -25,6 +17,7 @@ type PlauditWordpressWebpackConfig = {
25
17
  combineAssetMetadata?: boolean;
26
18
  useWebpackResourceFiltering?: boolean;
27
19
  outputDir?: string;
20
+ extensionsVersion?: 1 | 2;
28
21
  };
29
22
  declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration[] | Configuration) => Configuration[];
30
23
  export = _default;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  const node_fs_1 = __importDefault(require("node:fs"));
6
6
  const promises_1 = __importDefault(require("node:fs/promises"));
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
+ const shared_1 = require("./shared");
8
9
  const AdditionalDependencyInjectorPlugin_1 = require("./wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin");
9
10
  const BlockJSONManagingPlugin_1 = require("./wordpress-scripts-wrapper/BlockJSONManagingPlugin");
10
11
  const BrowserSyncPlugin_1 = require("./wordpress-scripts-wrapper/BrowserSyncPlugin");
@@ -271,7 +272,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
271
272
  scriptExtension = scriptWithoutModuleExtension;
272
273
  entrypointFields = ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script"];
273
274
  }
274
- const { standaloneBlocks, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, combineAssetMetadata } = config;
275
+ const { standaloneBlocks, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, combineAssetMetadata, extensionsVersion } = config;
275
276
  let currentVariables = config.currentVariables;
276
277
  const fixedRules = [
277
278
  replaceDefaultURLProcessing(config.useWebpackResourceFiltering),
@@ -300,7 +301,8 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
300
301
  if (srcIsDirectory === undefined) {
301
302
  return undefined;
302
303
  }
303
- const copyFiles = srcIsDirectory && src !== dest;
304
+ const canCopyFiles = srcIsDirectory && src !== dest;
305
+ const sourceType = (0, shared_1.determineCurrentSourceType)(dest, canCopyFiles);
304
306
  const plugins = webpackConfig.plugins?.filter(v => !!v)
305
307
  .filter(plugin => plugin.constructor.name !== 'RtlCssPlugin')
306
308
  .map(plugin => {
@@ -356,8 +358,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
356
358
  if (variablesFilePath) {
357
359
  plugins.push(new VariablesJSMonitorPlugin_1.VariablesJSMonitorPlugin(variablesFilePath));
358
360
  }
359
- const forBlocksDirectory = copyFiles && (typeof dest === 'string' || (dest.directoryLayout !== 'extensions' && dest.directoryLayout !== 'plain'));
360
- if (forBlocksDirectory) {
361
+ if (sourceType === "blocks" /* SourceType.blocks */) {
361
362
  const blockJSONManagingPlugin = new BlockJSONManagingPlugin_1.BlockJSONManagingPlugin(standaloneBlocks, processingModules);
362
363
  plugins.push(blockJSONManagingPlugin);
363
364
  if (config.processTranslationConfigs && srcIsDirectory && !processingModules) {
@@ -370,12 +371,14 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
370
371
  }
371
372
  else {
372
373
  const localAssumeGlobalizedPlauditLibraries = (typeof dest !== 'string' ? dest.assumeGlobalizedPlauditLibraries : undefined) ?? assumeGlobalizedPlauditLibraries;
373
- const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, localAssumeGlobalizedPlauditLibraries, combineAssetMetadata && !processingModules && forBlocksDirectory, typeof dest !== 'string' ? dest.externalize : undefined);
374
+ const wantsGroupedDepData = combineAssetMetadata
375
+ && ((!processingModules && sourceType === "blocks" /* SourceType.blocks */) || (extensionsVersion > 1 && sourceType === "extensions" /* SourceType.extensions */));
376
+ const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, localAssumeGlobalizedPlauditLibraries, wantsGroupedDepData, typeof dest !== 'string' ? dest.externalize : undefined);
374
377
  plugins[pluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
375
378
  plugins.push(new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(typeof dest !== 'string' && dest.additionalDependencies ? dest.additionalDependencies : [], processingModules, builtDependencyExtractionWebpackPlugin.addExternalizedDep));
376
379
  }
377
- if (srcIsDirectory && (typeof dest !== 'string' && dest.directoryLayout === 'extensions')) {
378
- plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(srcRoot));
380
+ if (srcIsDirectory && sourceType === "extensions" /* SourceType.extensions */) {
381
+ plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(srcRoot, extensionsVersion, sharedCache));
379
382
  }
380
383
  if (process.argv.includes('--browser-sync') || process.env['BROWSER_SYNC'] === 'true') {
381
384
  plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin());
@@ -587,7 +590,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
587
590
  extensions: ['.mjsx', '.mjs', '.mtsx', '.mts', '.jsx', '.tsx', '.ts', '...']
588
591
  },
589
592
  stats: config.stats,
590
- plugins: copyFiles
593
+ plugins: canCopyFiles
591
594
  ? plugins.map(plugin => !processingModules && plugin.constructor.name === 'CopyPlugin'
592
595
  ? new copy_webpack_plugin_1.default({ patterns: [{ from: standaloneBlocks ? '**/(block.json|*.(php|twig|svg))' : '**/(block.json|*.(asset\.php|svg))',
593
596
  context: srcRoot, noErrorOnMissing: true }] })
@@ -614,7 +617,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
614
617
  }
615
618
  module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
616
619
  testForDuplicatedEntryPaths(config);
617
- 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 = "" } = config;
620
+ 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 = "", extensionsVersion = 1 } = config;
618
621
  let variablesFilePath = undefined;
619
622
  const currentVariables = rawVariables ?? {};
620
623
  if (!rawVariables) {
@@ -622,7 +625,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
622
625
  }
623
626
  const cfg = {
624
627
  currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, processTranslationConfigs, combineAssetMetadata,
625
- useWebpackResourceFiltering, outputDir
628
+ useWebpackResourceFiltering, outputDir, extensionsVersion
626
629
  };
627
630
  const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
628
631
  const sharedCache = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.53.1",
3
+ "version": "2.54.0",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "/build"