@plaudit/webpack-extensions 2.65.0 → 2.65.2

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,10 +1,18 @@
1
- import { ParsedAssetsJson } from "../shared";
1
+ import { ParsedAssetsJson, VerifiedAdvancedOutputConfig } from "../shared";
2
2
  import type { ExtensibleEntryObject, VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
3
3
  import { PseudoSemaphore } from "../utils/pseduo-semaphore";
4
4
  import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
5
5
  import { Compilation, Compiler, Entrypoint } from "webpack";
6
- export type EntryProvider<M> = () => ExtensibleEntryObject<M> | Promise<ExtensibleEntryObject<M>>;
7
- export declare abstract class AbstractBiPhasicGroupAndEntryPlugin<M> extends AbstractBiPhasicGroupPlugin {
6
+ export type EntryProvider<M extends {
7
+ dest: VerifiedAdvancedOutputConfig;
8
+ } = {
9
+ dest: VerifiedAdvancedOutputConfig;
10
+ }> = () => ExtensibleEntryObject<M> | Promise<ExtensibleEntryObject<M>>;
11
+ export declare abstract class AbstractBiPhasicGroupAndEntryPlugin<M extends {
12
+ dest: VerifiedAdvancedOutputConfig;
13
+ } = {
14
+ dest: VerifiedAdvancedOutputConfig;
15
+ }> extends AbstractBiPhasicGroupPlugin {
8
16
  private readonly context;
9
17
  private readonly entry;
10
18
  private static readonly configuredCompilations;
@@ -12,11 +20,14 @@ export declare abstract class AbstractBiPhasicGroupAndEntryPlugin<M> extends Abs
12
20
  protected constructor(config: VerifiedPlauditWordpressWebpackConfig, group: string, semaphores: PseudoSemaphore<any>[], context: string, entry: EntryProvider<M>);
13
21
  apply(compiler: Compiler): void;
14
22
  protected attachStandardPhase(compilation: Compilation): void;
15
- getRelevantEntrypoints(compilation: Compilation): {
23
+ /**
24
+ * NOTE: This function returns an ITERATOR. Call .toArray() on it if you need to use the result multiple times
25
+ */
26
+ getRelevantEntrypoints(compilation: Compilation): IteratorObject<{
16
27
  entrypoint: Entrypoint;
17
28
  srcPath: string;
18
29
  metadata: M;
19
- }[];
30
+ }, undefined, unknown>;
20
31
  protected abstract processAssets(compilation: Compilation, parsedAssetsJson: ParsedAssetsJson): Promise<void> | void;
21
32
  protected extractRelevantAssetData(compilation: Compilation, parsedAssetsJson: ParsedAssetsJson): ParsedAssetsJson;
22
33
  }
@@ -48,6 +48,9 @@ class AbstractBiPhasicGroupAndEntryPlugin extends AbstractBiPhasicGroupPlugin_1.
48
48
  await this.processAssets(compilation, parsedAssetsJson);
49
49
  });
50
50
  }
51
+ /**
52
+ * NOTE: This function returns an ITERATOR. Call .toArray() on it if you need to use the result multiple times
53
+ */
51
54
  getRelevantEntrypoints(compilation) {
52
55
  return compilation.entrypoints.values()
53
56
  .map(entrypoint => {
@@ -65,13 +68,11 @@ class AbstractBiPhasicGroupAndEntryPlugin extends AbstractBiPhasicGroupPlugin_1.
65
68
  }
66
69
  return { entrypoint, srcPath, metadata };
67
70
  })
68
- .filter(item => item !== undefined)
69
- .toArray();
71
+ .filter(item => item !== undefined);
70
72
  }
71
73
  extractRelevantAssetData(compilation, parsedAssetsJson) {
72
74
  const relevantAssetData = {};
73
- const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
74
- for (const { entrypoint, srcPath } of relevantEntrypoints) {
75
+ for (const { entrypoint, srcPath } of this.getRelevantEntrypoints(compilation)) {
75
76
  const fileWithAssetData = entrypoint.getEntrypointChunk().files.values().find(file => parsedAssetsJson[file]);
76
77
  if (!fileWithAssetData) {
77
78
  compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
@@ -1,10 +1,12 @@
1
- import { type Compiler, type WebpackPluginInstance } from "webpack";
2
- import { AbstractBiPhasicGroupAndEntryPlugin } from "./AbstractBiPhasicGroupAndEntryPlugin";
3
- export declare class AdditionalDependencyInjectorPlugin implements WebpackPluginInstance {
4
- private readonly entrypointAdditionalDependencies;
1
+ import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
2
+ import type { AbstractBiPhasicGroupAndEntryPlugin } from "./AbstractBiPhasicGroupAndEntryPlugin";
3
+ import { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
+ import { Compilation } from "webpack";
5
+ export declare class AdditionalDependencyInjectorPlugin extends AbstractBiPhasicGroupPlugin {
5
6
  private readonly processingModules;
6
7
  private readonly addExternalizedDep;
7
8
  private readonly referencePlugin;
8
- constructor(entrypointAdditionalDependencies: string[], processingModules: boolean, addExternalizedDep: (dep: string) => void, referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>);
9
- apply(compiler: Compiler): void;
9
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, processingModules: boolean, addExternalizedDep: (dep: string) => void, referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>);
10
+ protected attachStandardPhase(compilation: Compilation): void;
11
+ protected attachUniquePhase(): void;
10
12
  }
@@ -4,57 +4,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.AdditionalDependencyInjectorPlugin = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
7
+ const promises_1 = __importDefault(require("node:fs/promises"));
8
+ const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
9
+ const shared_1 = require("../shared");
8
10
  const webpack_1 = require("webpack");
9
- class AdditionalDependencyInjectorPlugin {
10
- entrypointAdditionalDependencies;
11
+ class AdditionalDependencyInjectorPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
11
12
  processingModules;
12
13
  addExternalizedDep;
13
14
  referencePlugin;
14
- constructor(entrypointAdditionalDependencies, processingModules, addExternalizedDep, referencePlugin) {
15
- this.entrypointAdditionalDependencies = entrypointAdditionalDependencies;
15
+ constructor(config, processingModules, addExternalizedDep, referencePlugin) {
16
+ super(config, "additional-dependency-injector-plugin", []);
16
17
  this.processingModules = processingModules;
17
18
  this.addExternalizedDep = addExternalizedDep;
18
19
  this.referencePlugin = referencePlugin;
19
20
  }
20
- apply(compiler) {
21
- compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
22
- compilation.hooks.processAssets.tap({
23
- name: `${this.constructor.name}_ProcessAssets_AddFakeModules`,
24
- stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
25
- }, () => {
26
- const usableEntrypointTest = this.processingModules ? /\.m[jt]sx?$/i : /\.[jt]sx?$/i;
27
- for (const { entrypoint } of this.referencePlugin.getRelevantEntrypoints(compilation)) {
28
- const req = entrypoint.origins.filter(origin => usableEntrypointTest.test(origin.request))[0]?.request;
29
- if (!req) {
30
- continue;
31
- }
32
- const additionalDependencies = [...this.entrypointAdditionalDependencies];
33
- const firstLine = node_fs_1.default.readFileSync(req, 'utf8').trim().split(/\r?\n/)[0];
34
- if (firstLine?.startsWith("//ADDITIONAL_DEPENDENCIES:")) {
35
- additionalDependencies.push(...firstLine.substring(26).trim().split(',').map(dep => dep.trim()));
36
- }
37
- const chunk = entrypoint.getEntrypointChunk();
38
- for (const additionalDep of additionalDependencies) {
39
- this.addExternalizedDep(additionalDep);
40
- compilation.chunkGraph.connectChunkAndModule(chunk, new webpack_1.ExternalModule("__REMOVE_ME__", "", additionalDep));
41
- }
21
+ attachStandardPhase(compilation) {
22
+ const usableEntrypointTest = this.processingModules ? shared_1.scriptWithModuleExtension : shared_1.scriptWithoutModuleExtension;
23
+ compilation.hooks.processAssets.tapPromise({
24
+ name: `${this.constructor.name}_ProcessAssets_AddFakeModules`,
25
+ stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
26
+ }, async () => {
27
+ await Promise.all(this.referencePlugin.getRelevantEntrypoints(compilation)
28
+ .filter(re => usableEntrypointTest.test(re.srcPath))
29
+ .map(async ({ entrypoint, metadata, srcPath }) => {
30
+ const additionalDependencies = [...metadata.dest.additionalDependencies];
31
+ const firstLine = (await promises_1.default.readFile(srcPath, 'utf-8')).trim().split(/\r?\n/)[0];
32
+ if (firstLine?.startsWith("//ADDITIONAL_DEPENDENCIES:")) {
33
+ additionalDependencies.push(...firstLine.substring(26).trim().split(',').map(dep => dep.trim()));
42
34
  }
43
- });
44
- compilation.hooks.processAssets.tap({
45
- name: `${this.constructor.name}_ProcessAssets_RemoveFakeModules`,
46
- stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT
47
- }, () => {
48
- for (const { entrypoint } of this.referencePlugin.getRelevantEntrypoints(compilation)) {
49
- const entrypointChunk = entrypoint.getEntrypointChunk();
50
- for (const module of compilation.chunkGraph.getChunkModules(entrypointChunk)) {
51
- if (module instanceof webpack_1.ExternalModule && module.request === '__REMOVE_ME__') {
52
- compilation.chunkGraph.disconnectChunkAndModule(entrypointChunk, module);
53
- }
35
+ const chunk = entrypoint.getEntrypointChunk();
36
+ for (const additionalDep of additionalDependencies) {
37
+ this.addExternalizedDep(additionalDep);
38
+ compilation.chunkGraph.connectChunkAndModule(chunk, new webpack_1.ExternalModule("__REMOVE_ME__", "", additionalDep));
39
+ }
40
+ }));
41
+ });
42
+ compilation.hooks.processAssets.tap({
43
+ name: `${this.constructor.name}_ProcessAssets_RemoveFakeModules`,
44
+ stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT
45
+ }, () => {
46
+ for (const { entrypoint } of this.referencePlugin.getRelevantEntrypoints(compilation)) {
47
+ const entrypointChunk = entrypoint.getEntrypointChunk();
48
+ for (const module of compilation.chunkGraph.getChunkModules(entrypointChunk)) {
49
+ if (module instanceof webpack_1.ExternalModule && module.request === '__REMOVE_ME__') {
50
+ compilation.chunkGraph.disconnectChunkAndModule(entrypointChunk, module);
54
51
  }
55
52
  }
56
- });
53
+ }
57
54
  });
58
55
  }
56
+ attachUniquePhase() { }
59
57
  }
60
58
  exports.AdditionalDependencyInjectorPlugin = AdditionalDependencyInjectorPlugin;
@@ -1,8 +1,7 @@
1
1
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
- import type { UnpackedBlockEntrypointInfo } from "../shared";
3
2
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
- export declare class EnhancedDynamicEntryPlugin extends AbstractBiPhasicGroupAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
5
- constructor(config: VerifiedPlauditWordpressWebpackConfig, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
3
+ export declare class EnhancedDynamicEntryPlugin extends AbstractBiPhasicGroupAndEntryPlugin {
4
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, context: string, entry: EntryProvider);
6
5
  protected attachUniquePhase(): void;
7
6
  protected processAssets(): void;
8
7
  }
@@ -2,12 +2,12 @@ import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBi
2
2
  import { ParsedAssetsJson, VerifiedAdvancedOutputConfig } from "../shared";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
4
  import { Compilation, type Compiler } from "webpack";
5
- export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<string> {
5
+ export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin {
6
6
  private readonly extensionsSrcPath;
7
7
  private readonly dest;
8
8
  private static readonly semaphore;
9
9
  private setupFiles;
10
- constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsSrcPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider<string>);
10
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsSrcPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider);
11
11
  get extensionsDestPath(): string;
12
12
  apply(compiler: Compiler): void;
13
13
  private generateVersionTwoConfigFile;
@@ -2,9 +2,9 @@ import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBi
2
2
  import type { ParsedAssetsJson } from "../shared";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
4
  import { Compilation } from "webpack";
5
- export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin<string> {
5
+ export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin {
6
6
  private readonly extensionsDest;
7
- constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsDest: string, context: string, entry: EntryProvider<string>);
7
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsDest: string, context: string, entry: EntryProvider);
8
8
  protected attachUniquePhase(): void;
9
9
  protected processAssets(compilation: Compilation, assetsJson: ParsedAssetsJson): void;
10
10
  }
@@ -1,14 +1,14 @@
1
- import { ParsedAssetsJson, UnpackedBlockEntrypointInfo, UsageLocations } from "../shared";
1
+ import { ParsedAssetsJson, BlockEntrypointInfo, UsageLocations } from "../shared";
2
2
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
3
3
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
4
4
  import { Compilation } from "webpack";
5
- export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
5
+ export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
6
6
  private readonly buildRoot;
7
7
  private readonly outputDir;
8
8
  private readonly usageLocations;
9
9
  private readonly useUnifiedLoader;
10
10
  private static readonly semaphore;
11
- constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: UsageLocations, useUnifiedLoader: boolean, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
11
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: UsageLocations, useUnifiedLoader: boolean, context: string, entry: EntryProvider<BlockEntrypointInfo>);
12
12
  private generatePlainEntrypointsLoader;
13
13
  private static addHandlesToHandleLists;
14
14
  private static appendEnqueuingHandleLists;
@@ -166,7 +166,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
166
166
  processAssets(compilation, assetsJson) {
167
167
  const isScriptRegex = /\.m?[jt]sx?(\?|$)/i;
168
168
  const myAssetHandles = [];
169
- const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
169
+ const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
170
170
  for (const { entrypoint, srcPath } of relevantEntrypoints) {
171
171
  const entrypointChunk = entrypoint.getEntrypointChunk();
172
172
  const assetData = entrypointChunk.files.values()
@@ -203,7 +203,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
203
203
  UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myAssetHandles.length
204
204
  ? {
205
205
  group: this.group, requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';"),
206
- staticallyLoadedEntrypoints: Object.keys(relevantEntrypoints)
206
+ staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray())
207
207
  }
208
208
  : undefined);
209
209
  }
@@ -1,13 +1,13 @@
1
1
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
- import { ParsedAssetsJson, UnpackedBlockEntrypointInfo } from "../shared";
2
+ import { ParsedAssetsJson, BlockEntrypointInfo } 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";
6
- export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin<UnpackedBlockEntrypointInfo | string> {
6
+ export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
7
7
  private readonly blocksDest;
8
8
  private readonly webpackRemoveEmptyScriptsPlugin;
9
9
  private static readonly semaphore;
10
- constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<UnpackedBlockEntrypointInfo | string>);
10
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, blocksDest: string, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<BlockEntrypointInfo>);
11
11
  protected processAssets(compilation: Compilation, rawAssetData: ParsedAssetsJson): Promise<void>;
12
12
  private emitBlockLoaderFile;
13
13
  private transformBlocks;
@@ -22,4 +22,5 @@ export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhas
22
22
  private static remapReferencedPHPFilesOnKey;
23
23
  private static normalizeRenderTemplate;
24
24
  protected attachUniquePhase(compilation: Compilation): void;
25
+ protected attachStandardPhase(compilation: Compilation): void;
25
26
  }
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PlainEntrypointsStyleBlockJSONPlugin = void 0;
7
7
  const node_crypto_1 = __importDefault(require("node:crypto"));
8
+ const promises_1 = __importDefault(require("node:fs/promises"));
8
9
  const node_fs_1 = __importDefault(require("node:fs"));
9
10
  const node_path_1 = __importDefault(require("node:path"));
10
11
  const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
@@ -13,7 +14,6 @@ const shared_1 = require("../shared");
13
14
  const php_writer_1 = require("../utils/php-writer");
14
15
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
15
16
  const webpack_1 = require("webpack");
16
- const promises_1 = __importDefault(require("node:fs/promises"));
17
17
  class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
18
18
  blocksDest;
19
19
  webpackRemoveEmptyScriptsPlugin;
@@ -26,18 +26,12 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
26
26
  async processAssets(compilation, rawAssetData) {
27
27
  const applicableBlockJsonFiles = {};
28
28
  const blockJsonOriginToOutputMapping = {};
29
- const relevantEntrypoints = this.getRelevantEntrypoints(compilation);
29
+ const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
30
30
  for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
31
- if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || metadata !== "block-json-inclusion-assurance") {
31
+ if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
32
32
  continue;
33
33
  }
34
- const entrypointChunk = entrypoint.getEntrypointChunk();
35
- for (const danglingBlockJsFile of [...entrypointChunk.files, ...entrypointChunk.auxiliaryFiles]) {
36
- if (!danglingBlockJsFile.endsWith("block.json")) {
37
- compilation.deleteAsset(danglingBlockJsFile);
38
- }
39
- }
40
- const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypointChunk)][0]?.originalSource();
34
+ const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypoint.getEntrypointChunk())][0]?.originalSource();
41
35
  if (asset) {
42
36
  //TODO: Can we guarantee that entrypoint.name is always non-null?
43
37
  const epBlockJson = entrypoint.name + ".json";
@@ -54,7 +48,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
54
48
  }
55
49
  }
56
50
  for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
57
- if (node_path_1.default.basename(srcPath).toLowerCase() === "block.json" || typeof metadata === 'string') {
51
+ if (node_path_1.default.basename(srcPath).toLowerCase() === "block.json" || 'purpose' in metadata) {
58
52
  continue;
59
53
  }
60
54
  const entrypointChunk = entrypoint.getEntrypointChunk();
@@ -98,7 +92,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
98
92
  UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(applicableBlockJsonFiles).length ? {
99
93
  group: this.group,
100
94
  requiresBaseURI: false,
101
- staticallyLoadedEntrypoints: Object.keys(relevantEntrypoints),
95
+ staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray()),
102
96
  action: writer => writer.append(`require_once __DIR__.${php_writer_1.Expr.convertJsonToPHP("/" + node_path_1.default.join(this.blocksDest, "blockdir-loader.php"))};`)
103
97
  } : undefined);
104
98
  }
@@ -378,5 +372,22 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
378
372
  this.emitBlockLoaderFile(compilation, blockData);
379
373
  });
380
374
  }
375
+ attachStandardPhase(compilation) {
376
+ super.attachStandardPhase(compilation);
377
+ compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER }, async () => {
378
+ const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
379
+ for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
380
+ if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
381
+ continue;
382
+ }
383
+ const entrypointChunk = entrypoint.getEntrypointChunk();
384
+ for (const danglingBlockJsFile of [...entrypointChunk.files, ...entrypointChunk.auxiliaryFiles]) {
385
+ if (!danglingBlockJsFile.endsWith("block.json")) {
386
+ compilation.deleteAsset(danglingBlockJsFile);
387
+ }
388
+ }
389
+ }
390
+ });
391
+ }
381
392
  }
382
393
  exports.PlainEntrypointsStyleBlockJSONPlugin = PlainEntrypointsStyleBlockJSONPlugin;
package/build/shared.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PHPWriter } from "./utils/php-writer";
2
2
  import type { Options as PostcssFunctionsOptions } from "postcss-functions";
3
- import { Compilation, type Configuration, type EntryOptions, WebpackError } from "webpack";
3
+ import { Compilation, type Configuration, WebpackError } from "webpack";
4
4
  export type ParsedAssetsJson = Record<string, {
5
5
  dependencies: string[];
6
6
  version: string;
@@ -75,23 +75,18 @@ export type PlauditWordpressWebpackConfig = {
75
75
  srcPrefixes?: string[];
76
76
  useUnifiedLoader?: boolean;
77
77
  };
78
- export type SmuggledBlockEntrypointInfo = [
79
- string,
80
- EntrypointFields[number],
81
- string,
82
- string,
83
- string
84
- ];
85
- export type UnpackedBlockEntrypointInfo = {
78
+ export type FileSegmentBlockEntrypointInfo = {
86
79
  blockJsonOrigin: string;
87
80
  entrypointField: EntrypointFields[number];
88
81
  originalValue: string;
89
82
  entrypointName: string;
90
83
  handle: string;
84
+ dest: VerifiedAdvancedOutputConfig;
85
+ };
86
+ export type BlockEntrypointInfo = FileSegmentBlockEntrypointInfo | {
87
+ dest: VerifiedAdvancedOutputConfig;
88
+ purpose: string;
91
89
  };
92
- export declare function packBlockEntrypointInfoForSmuggling(info: UnpackedBlockEntrypointInfo): SmuggledBlockEntrypointInfo;
93
- export declare function unpackSmuggledBlockEntrypointInfo(library: EntryOptions['library'], allowedEndings?: string[] | false): UnpackedBlockEntrypointInfo | undefined;
94
- export declare function isSmuggledLibraryInfo(libraryName: NonNullable<EntryOptions['library']>['name'] | undefined, allowedEndings?: string[] | false): libraryName is SmuggledBlockEntrypointInfo;
95
90
  export declare function convertUsageLocationsHandleToEmittableHandle(handle: UsageLocations['handle'], generatedHandle: string): string;
96
91
  export declare function makeEmittableConfigPHP(data: any, asFullFile: boolean, parentIndent?: string): string;
97
92
  export type EntrypointFields = ["viewScriptModule", "scriptModule"] | ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script"];
package/build/shared.js CHANGED
@@ -6,9 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.styleExtension = exports.scriptWithModuleExtension = exports.scriptWithoutModuleExtension = exports.scriptExtension = exports.entrypointFields = exports.standardLocationNames = void 0;
7
7
  exports.isParsedAssetsJson = isParsedAssetsJson;
8
8
  exports.determineCurrentSourceType = determineCurrentSourceType;
9
- exports.packBlockEntrypointInfoForSmuggling = packBlockEntrypointInfoForSmuggling;
10
- exports.unpackSmuggledBlockEntrypointInfo = unpackSmuggledBlockEntrypointInfo;
11
- exports.isSmuggledLibraryInfo = isSmuggledLibraryInfo;
12
9
  exports.convertUsageLocationsHandleToEmittableHandle = convertUsageLocationsHandleToEmittableHandle;
13
10
  exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
14
11
  exports.convertEntrypointFieldForAssetType = convertEntrypointFieldForAssetType;
@@ -58,23 +55,6 @@ function determineCurrentSourceType(dest, srcIsDirectory) {
58
55
  return dest.directoryLayout;
59
56
  }
60
57
  }
61
- function packBlockEntrypointInfoForSmuggling(info) {
62
- return [info.blockJsonOrigin, info.entrypointField, info.originalValue, info.entrypointName, info.handle];
63
- }
64
- const defaultAllowedEndings = ["/block.json", "/entrypoints.json", "/package.json"];
65
- function unpackSmuggledBlockEntrypointInfo(library, allowedEndings) {
66
- const libraryName = library?.name;
67
- if (!isSmuggledLibraryInfo(libraryName, allowedEndings)) {
68
- return undefined;
69
- }
70
- return { blockJsonOrigin: libraryName[0], entrypointField: libraryName[1], originalValue: libraryName[2], entrypointName: libraryName[3], handle: libraryName[4] };
71
- }
72
- function isSmuggledLibraryInfo(libraryName, allowedEndings = defaultAllowedEndings) {
73
- if (!Array.isArray(libraryName) || !arrayIsLength(libraryName, 5) || libraryName.some(item => typeof item !== 'string')) {
74
- return false;
75
- }
76
- return (!allowedEndings || allowedEndings.some(s => libraryName[0].endsWith(s))) && exports.entrypointFields.includes(libraryName[1]);
77
- }
78
58
  function convertUsageLocationsHandleToEmittableHandle(handle, generatedHandle) {
79
59
  const emittableHandle = typeof handle === 'string' ? handle : handle?.(generatedHandle) ?? generatedHandle;
80
60
  return emittableHandle.replaceAll("{basename}", generatedHandle);
@@ -1,6 +1,6 @@
1
1
  import type { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "../plugins/AbstractBiPhasicGroupAndEntryPlugin";
2
2
  import type { AdditionalDependencyInjectorPlugin } from "../plugins/AdditionalDependencyInjectorPlugin";
3
- import { EntrypointFields, PlauditWordpressWebpackConfig, UnpackedBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
3
+ import { EntrypointFields, PlauditWordpressWebpackConfig, BlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
4
4
  import type { Compiler, Configuration, DynamicEntryPlugin, WebpackPluginInstance } from "webpack";
5
5
  import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
6
6
  export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpressWebpackConfig, 'variables' | 'src' | 'externals'>> & {
@@ -21,12 +21,12 @@ export type CommonConfigProcessingResult = {
21
21
  };
22
22
  export declare function joinPossiblyAbsolutePaths(...paths: (string | undefined)[]): string;
23
23
  export declare function groupEntrypointsByAssetFile<T>(entrypoints: T[], entrypointNameExtractor: (t: T) => string): Map<string, T[]>;
24
- export type BlockJsonExtensibleEntryObject = ExtensibleEntryObject<UnpackedBlockEntrypointInfo | string>;
24
+ export type BlockJsonExtensibleEntryObject = ExtensibleEntryObject<BlockEntrypointInfo>;
25
25
  export type EntryStaticNormalized = Awaited<ReturnType<ConstructorParameters<typeof DynamicEntryPlugin>[1]>>;
26
26
  export type ExtensibleEntryObject<M> = {
27
27
  [index: string]: Omit<EntryStaticNormalized[string], 'import'> & Required<NonNullable<Pick<EntryStaticNormalized[string], 'import'>>> & {
28
28
  plauditMetadata: M;
29
29
  };
30
30
  };
31
- export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): EntryProvider<UnpackedBlockEntrypointInfo | string>;
31
+ export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): EntryProvider<BlockEntrypointInfo>;
32
32
  export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration, externalize: VerifiedAdvancedOutputConfig['externalize'], plugins: CommonPluginConfig['plugins'], canClean: boolean): Configuration;
@@ -44,7 +44,8 @@ function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
44
44
  entrypointField: shared_1.styleExtension.test(ep) ? 'style' : shared_1.scriptWithModuleExtension.test(ep) ? 'scriptModule' : 'script',
45
45
  originalValue: ep,
46
46
  entrypointName: parsedEntrypoint.name,
47
- handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name)
47
+ handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name),
48
+ dest
48
49
  };
49
50
  return [joinPossiblyAbsolutePaths(dest.destination, node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name),
50
51
  { import: [ep], plauditMetadata: fakeEntrypointInfo }];
@@ -168,7 +169,8 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
168
169
  if (!entrypointNamesWithEffectiveDuplicates[presentEntrypoint.entrypointName]) {
169
170
  return {
170
171
  blockJsonOrigin, ...presentEntrypoint,
171
- handle: `${handlePrefix}/${handleSuffix}`
172
+ handle: `${handlePrefix}/${handleSuffix}`,
173
+ dest
172
174
  };
173
175
  }
174
176
  const baseSuffix = `_${(0, shared_1.isStyleField)(presentEntrypoint.entrypointField) ? "style" : "script"}`;
@@ -184,7 +186,8 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
184
186
  ...presentEntrypoint,
185
187
  entrypointName: deduplicatedEntrypointName,
186
188
  extensionlessExpectedSrc: deduplicatedExtensionlessExpectedSrc,
187
- handle: `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`
189
+ handle: `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`,
190
+ dest
188
191
  };
189
192
  });
190
193
  rawEntrypoints.push(...resolvedBlockEntrypoints
@@ -197,7 +200,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
197
200
  }
198
201
  ];
199
202
  }));
200
- rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: "block-json-inclusion-assurance" }]);
203
+ rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: { purpose: "block-json-inclusion-assurance", dest } }]);
201
204
  wpmlFiles.push(node_path_1.default.join(dir, 'block.json'));
202
205
  }
203
206
  catch (e) {
@@ -251,12 +254,12 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
251
254
  const wpmlEntrypointFiles = allEntrypoints.flatMap(e => e[1]);
252
255
  try {
253
256
  await promises_1.default.access(node_path_1.default.join(srcRoot, "wpml-config.xml"));
254
- currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: "wpml-config-xml" };
257
+ currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: { purpose: "wpml-config-xml", dest } };
255
258
  }
256
259
  catch (e) {
257
260
  // If the wpml-config.xml file does not exist, just "import" the other files that will be used to build the emitted version
258
261
  if (wpmlEntrypointFiles.length) {
259
- currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: "wpml-config-xml" };
262
+ currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: { purpose: "wpml-config-xml", dest } };
260
263
  }
261
264
  }
262
265
  }
@@ -360,7 +360,7 @@ function handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins)
360
360
  }
361
361
  }
362
362
  }
363
- function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize, additionalDependencies) {
363
+ function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize) {
364
364
  const { externals } = config;
365
365
  const processingModules = webpackConfig.output?.module ?? false;
366
366
  const plugins = webpackConfig.plugins?.filter(v => !!v)
@@ -403,7 +403,7 @@ function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGl
403
403
  return {
404
404
  plugins, removeEmptyScriptsPlugin,
405
405
  makeAdditionalDependencyInjectorPlugin(referencePlugin) {
406
- return new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(additionalDependencies ?? [], processingModules, builtDependencyExtractionWebpackPlugin.addExternalizedDep, referencePlugin);
406
+ return new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(config, processingModules, builtDependencyExtractionWebpackPlugin.addExternalizedDep, referencePlugin);
407
407
  }
408
408
  };
409
409
  }
@@ -446,7 +446,7 @@ function destToKey(dest) {
446
446
  const externalize = typeof dest.externalize === 'object' && dest.externalize !== undefined
447
447
  ? (Array.isArray(dest.externalize) ? dest.externalize.join("_") : (dest.externalize ? Object.entries(dest.externalize).flat().sort().join() : "undefined"))
448
448
  : dest.externalize?.toString() ?? "undefined";
449
- return [dest.additionalDependencies.join("_"), dest.assumeGlobalizedPlauditLibraries, dest.bundleAnalyzer, externalize, dest.withLegacyBlocksIn].join("~");
449
+ return [dest.assumeGlobalizedPlauditLibraries, dest.bundleAnalyzer, externalize].join("~");
450
450
  }
451
451
  function processIndividualWebpackConfig(config, webpackConfig, sources, canClean) {
452
452
  const commonConfig = commonConfigProcessingPrep(config, webpackConfig);
@@ -469,8 +469,8 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
469
469
  }
470
470
  const batches = Object.values(groupedSrcRoots).filter(shared_1.hasAtLeastOneItem);
471
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);
472
+ const { bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize } = currentBatch[0].dest;
473
+ const { plugins, removeEmptyScriptsPlugin, makeAdditionalDependencyInjectorPlugin } = buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize);
474
474
  handleDisablingTSCheckerIfNecessary(currentBatch.flatMap(a => a.srcRoots), scriptExtension, plugins);
475
475
  for (const { dest, src, srcIsDirectory, srcRoot } of currentBatch) {
476
476
  let plugin;
@@ -495,7 +495,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
495
495
  if (dirent.isFile() && !dirent.name.startsWith("~")) {
496
496
  if (commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name)) {
497
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" }]);
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: { dest } }]);
499
499
  }
500
500
  }
501
501
  }
@@ -517,7 +517,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
517
517
  if (config.plainEntrypointsVersion > 1) {
518
518
  const entry = srcIsDirectory // This being true implies that srcRoot is not an array
519
519
  ? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
520
- : () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: "plain-entrypoint" } });
520
+ : () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest } } });
521
521
  plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest.locations, config.useUnifiedLoader, webpackConfig.context ?? process.cwd(), entry);
522
522
  }
523
523
  else {
@@ -525,7 +525,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
525
525
  console.error("Using directory mode with legacy plain entrypoint handling is not supported");
526
526
  continue;
527
527
  }
528
- plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(config, webpackConfig.context ?? process.cwd(), () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: "plain-entrypoint" } }));
528
+ plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(config, webpackConfig.context ?? process.cwd(), () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest } } }));
529
529
  }
530
530
  plugins.push(plugin);
531
531
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.65.0",
3
+ "version": "2.65.2",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build"
@@ -16,9 +16,9 @@
16
16
  }
17
17
  },
18
18
  "devDependencies": {
19
- "@plaudit/gutenberg-api-extensions": "^2.75.0",
19
+ "@plaudit/gutenberg-api-extensions": "^2.76.1",
20
20
  "@types/browser-sync-webpack-plugin": "^2.2.5",
21
- "@types/node": "^24.3.0",
21
+ "@types/node": "^24.3.1",
22
22
  "@types/postcss-functions": "^4.0.4",
23
23
  "@types/tapable": "^2.2.7",
24
24
  "@types/webpack": "^5.28.5",