@plaudit/webpack-extensions 2.75.0 → 2.76.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,18 +1,10 @@
1
- import { ParsedAssetsJson, VerifiedAdvancedOutputConfig } from "../shared";
1
+ import { MinimumViableMetadata, ParsedAssetJsonProvider, ParsedAssetsJson } 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 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 {
6
+ export type EntryProvider<M extends MinimumViableMetadata = MinimumViableMetadata> = () => ExtensibleEntryObject<M> | Promise<ExtensibleEntryObject<M>>;
7
+ export declare abstract class AbstractBiPhasicGroupAndEntryPlugin<M extends MinimumViableMetadata = MinimumViableMetadata> extends AbstractBiPhasicGroupPlugin {
16
8
  private readonly context;
17
9
  private readonly entry;
18
10
  private static readonly configuredCompilations;
@@ -28,6 +20,6 @@ export declare abstract class AbstractBiPhasicGroupAndEntryPlugin<M extends {
28
20
  srcPath: string;
29
21
  metadata: M;
30
22
  }, undefined, unknown>;
31
- protected abstract processAssets(compilation: Compilation, parsedAssetsJson: ParsedAssetsJson): Promise<void> | void;
32
- protected extractRelevantAssetData(compilation: Compilation, parsedAssetsJson: ParsedAssetsJson): ParsedAssetsJson;
23
+ protected abstract processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): Promise<void> | void;
24
+ protected extractRelevantAssetData(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): ParsedAssetsJson;
33
25
  }
@@ -70,15 +70,15 @@ class AbstractBiPhasicGroupAndEntryPlugin extends AbstractBiPhasicGroupPlugin_1.
70
70
  })
71
71
  .filter(item => item !== undefined);
72
72
  }
73
- extractRelevantAssetData(compilation, parsedAssetsJson) {
73
+ extractRelevantAssetData(compilation, parsedAssetJsonProvider) {
74
74
  const relevantAssetData = {};
75
- for (const { entrypoint, srcPath } of this.getRelevantEntrypoints(compilation)) {
76
- const fileWithAssetData = entrypoint.getEntrypointChunk().files.values().find(file => parsedAssetsJson[file]);
77
- if (!fileWithAssetData) {
75
+ for (const { entrypoint, srcPath, metadata } of this.getRelevantEntrypoints(compilation)) {
76
+ const providedData = parsedAssetJsonProvider(entrypoint, metadata);
77
+ if (providedData === undefined) {
78
78
  compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
79
79
  continue;
80
80
  }
81
- relevantAssetData[fileWithAssetData] = parsedAssetsJson[fileWithAssetData];
81
+ relevantAssetData[providedData.assetName] = providedData.assetData;
82
82
  }
83
83
  return relevantAssetData;
84
84
  }
@@ -1,14 +1,14 @@
1
1
  import { Compilation, Compiler, type WebpackPluginInstance } from "webpack";
2
2
  import { PseudoSemaphore } from "../utils/pseduo-semaphore";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
- import { ParsedAssetsJson } from "../shared";
4
+ import { type ParsedAssetJsonProvider } from "../shared";
5
5
  type TapWithAssetsJsonOptions = {
6
6
  name?: string;
7
7
  stage?: (typeof Compilation.PROCESS_ASSETS_STAGE_REPORT) | (typeof Compilation.PROCESS_ASSETS_STAGE_ANALYSE);
8
8
  additionalAssets?: any;
9
9
  };
10
10
  type TapWithAssetsJsonFn = Parameters<Compilation['hooks']['processAssets']['tapPromise']>[1];
11
- type TapWithParsedAssetsJsonFn = (parsedAssetsJson: ParsedAssetsJson, assets: Parameters<TapWithAssetsJsonFn>[0]) => Promise<void> | void;
11
+ type TapWithParsedAssetsJsonFn = (parsedAssetJsonProvider: ParsedAssetJsonProvider, assets: Parameters<TapWithAssetsJsonFn>[0]) => Promise<void> | void;
12
12
  export declare abstract class AbstractBiPhasicGroupPlugin implements WebpackPluginInstance {
13
13
  protected readonly config: VerifiedPlauditWordpressWebpackConfig;
14
14
  readonly group: string;
@@ -49,7 +49,7 @@ class AbstractBiPhasicGroupPlugin {
49
49
  const { tap, earlyStage, fn } = this.extractTapAndFunction(fnOrOptions, fnIfOptions);
50
50
  this.sharedTapLogicForAssetsJsonHelpers(compilation, { tap, earlyStage, fn: async (assets) => {
51
51
  try {
52
- await fn((0, shared_1.getAssetsJson)(compilation), assets);
52
+ await fn((entrypoint, dest) => (0, shared_1.getParsedAssetsJsonDataForEntrypoint)(compilation, entrypoint, dest), assets);
53
53
  }
54
54
  catch (e) {
55
55
  console.error(e);
@@ -1,5 +1,5 @@
1
1
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
- import { ParsedAssetsJson, VerifiedAdvancedOutputConfig } from "../shared";
2
+ import { ParsedAssetJsonProvider, VerifiedAdvancedOutputConfig } from "../shared";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
4
  import { Compilation, type Compiler } from "webpack";
5
5
  export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin {
@@ -12,5 +12,5 @@ export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasi
12
12
  apply(compiler: Compiler): void;
13
13
  private generateVersionThreeConfigFile;
14
14
  protected attachUniquePhase(compilation: Compilation): void;
15
- protected processAssets(compilation: Compilation, rawAssetData: ParsedAssetsJson): void;
15
+ protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
16
16
  }
@@ -126,8 +126,8 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
126
126
  }
127
127
  });
128
128
  }
129
- processAssets(compilation, rawAssetData) {
130
- const relevantAssetData = this.extractRelevantAssetData(compilation, rawAssetData);
129
+ processAssets(compilation, parsedAssetJsonProvider) {
130
+ const relevantAssetData = this.extractRelevantAssetData(compilation, parsedAssetJsonProvider);
131
131
  const staticallyLoadedEntrypoints = Object.keys(relevantAssetData);
132
132
  const generateLoader = (writer) => {
133
133
  writer.require(this.extensionsDestPath + "extensions-loader.php", { dirRelative: true, once: true });
@@ -1,10 +1,10 @@
1
1
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
- import type { ParsedAssetsJson } from "../shared";
2
+ import { ParsedAssetJsonProvider } from "../shared";
3
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
4
  import { Compilation } from "webpack";
5
5
  export declare class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin {
6
6
  private readonly extensionsDest;
7
7
  constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsDest: string, context: string, entry: EntryProvider);
8
8
  protected attachUniquePhase(): void;
9
- protected processAssets(compilation: Compilation, assetsJson: ParsedAssetsJson): void;
9
+ protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
10
10
  }
@@ -17,10 +17,10 @@ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntr
17
17
  this.extensionsDest = extensionsDest;
18
18
  }
19
19
  attachUniquePhase() { }
20
- processAssets(compilation, assetsJson) {
20
+ processAssets(compilation, parsedAssetJsonProvider) {
21
21
  const regex = /^(.+?)-((?<prefix>editor-|view-|)(?<type>style|script|script-module))\.(?<extension>css|m?js)$/i;
22
22
  const mapping = {};
23
- for (let fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation, assetsJson))) {
23
+ for (let fileWithAssetData of Object.keys(this.extractRelevantAssetData(compilation, parsedAssetJsonProvider))) {
24
24
  let match;
25
25
  if ((match = regex.exec(fileWithAssetData)) && match[1] && match[2]) {
26
26
  if (match.groups?.['type'] === 'style' && match.groups['extension'] !== 'css') {
@@ -1,4 +1,4 @@
1
- import { ParsedAssetsJson, BlockEntrypointInfo, UsageLocations } from "../shared";
1
+ import { BlockEntrypointInfo, UsageLocations, ParsedAssetJsonProvider } 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";
@@ -14,5 +14,5 @@ export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractB
14
14
  private static appendEnqueuingHandleLists;
15
15
  private static separateHandleListByPriority;
16
16
  protected attachUniquePhase(compilation: Compilation): void;
17
- protected processAssets(compilation: Compilation, assetsJson: ParsedAssetsJson): void;
17
+ protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
18
18
  }
@@ -139,14 +139,13 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
139
139
  this.generatePlainEntrypointsLoader(compilation, (await PlainEntrypointsConfigFileGeneratorPlugin.semaphore.wait()).flat());
140
140
  });
141
141
  }
142
- processAssets(compilation, assetsJson) {
142
+ processAssets(compilation, parsedAssetJsonProvider) {
143
143
  const isScriptRegex = /\.m?[jt]sx?(\?|$)/i;
144
144
  const myAssetHandles = [];
145
145
  const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
146
- for (const { entrypoint, srcPath } of relevantEntrypoints) {
146
+ for (const { entrypoint, srcPath, metadata } of relevantEntrypoints) {
147
147
  const entrypointChunk = entrypoint.getEntrypointChunk();
148
- const assetData = entrypointChunk.files.values()
149
- .map(file => assetsJson[file]).find(v => v !== undefined);
148
+ const assetData = parsedAssetJsonProvider(entrypoint, metadata)?.assetData;
150
149
  if (!assetData) {
151
150
  continue;
152
151
  }
@@ -1,5 +1,5 @@
1
1
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
- import { ParsedAssetsJson, BlockEntrypointInfo, FileSegmentBlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
2
+ import { ParsedAssetsJson, BlockEntrypointInfo, FileSegmentBlockEntrypointInfo, VerifiedAdvancedOutputConfig, ParsedAssetJsonProvider } 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";
@@ -18,7 +18,7 @@ export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhas
18
18
  private readonly webpackRemoveEmptyScriptsPlugin;
19
19
  private static readonly semaphore;
20
20
  constructor(config: VerifiedPlauditWordpressWebpackConfig, dest: VerifiedAdvancedOutputConfig, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<BlockEntrypointInfo>);
21
- protected processAssets(compilation: Compilation, rawAssetData: ParsedAssetsJson): Promise<void>;
21
+ protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): Promise<void>;
22
22
  private emitBlockLoaderFile;
23
23
  private transformBlocks;
24
24
  private static extractAssetSource;
@@ -24,7 +24,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
24
24
  this.dest = dest;
25
25
  this.webpackRemoveEmptyScriptsPlugin = webpackRemoveEmptyScriptsPlugin;
26
26
  }
27
- async processAssets(compilation, rawAssetData) {
27
+ async processAssets(compilation, parsedAssetJsonProvider) {
28
28
  const applicableBlockJsonFiles = {};
29
29
  const blockJsonOriginToOutputMapping = {};
30
30
  const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
@@ -56,9 +56,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
56
56
  const epBlockJson = entrypointChunk.auxiliaryFiles.values().find(auxFile => node_path_1.default.basename(auxFile) === "block.json")
57
57
  ?? blockJsonOriginToOutputMapping[metadata.blockJsonOrigin];
58
58
  if (epBlockJson) {
59
- //TODO: Do we need to handle a single entrypoint potentially emitting multiple primary files?
60
- const assetData = entrypointChunk.files.values().map(file => rawAssetData[file])
61
- .find(assetData => assetData !== undefined);
59
+ const assetData = parsedAssetJsonProvider(entrypoint, metadata)?.assetData;
62
60
  if (!assetData) {
63
61
  compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
64
62
  continue;
@@ -21,7 +21,7 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
21
21
  });
22
22
  }
23
23
  attachUniquePhase(compilation) {
24
- this.tapWithParsedAssetsJson(compilation, { stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async (parsedAssetsJson) => {
24
+ this.tapRequiringAssetsJson(compilation, { stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
25
25
  const groupedLoaderInfo = Object.values((await UnifiedLoaderGenerator.semaphore.wait())
26
26
  .reduce((acc, cur) => {
27
27
  const accValue = acc[cur.group];
@@ -47,7 +47,7 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
47
47
  return ap === bp ? a.group.localeCompare(b.group) : bp - ap;
48
48
  });
49
49
  const staticallyLoadedEntrypoints = new Set(groupedLoaderInfo.flatMap(lig => lig.staticallyLoadedEntrypoints));
50
- for (const [file, assetData] of Object.entries(parsedAssetsJson)) {
50
+ for (const [file, assetData] of Object.entries((0, shared_1.getAssetsJson)(compilation))) {
51
51
  if (staticallyLoadedEntrypoints.has(file)) {
52
52
  continue;
53
53
  }
package/build/shared.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PHPWriter } from "@plaudit/php-writer";
2
2
  import type { Options as PostcssFunctionsOptions } from "postcss-functions";
3
- import { AssetInfo, Compilation, type Configuration, WebpackError } from "webpack";
3
+ import { AssetInfo, Compilation, type Configuration, Entrypoint, WebpackError } from "webpack";
4
4
  export type ParsedAssetsJson = Record<string, {
5
5
  dependencies: string[];
6
6
  version: string;
@@ -113,10 +113,16 @@ export type FileSegmentBlockEntrypointInfo = {
113
113
  entrypointName: string;
114
114
  handle: string;
115
115
  dest: VerifiedAdvancedOutputConfig;
116
+ absoluteSrc: string;
116
117
  };
117
118
  export type BlockEntrypointInfo = FileSegmentBlockEntrypointInfo | {
118
119
  dest: VerifiedAdvancedOutputConfig;
119
120
  purpose: string;
121
+ absoluteSrc: string;
122
+ };
123
+ export type MinimumViableMetadata = {
124
+ dest: VerifiedAdvancedOutputConfig;
125
+ absoluteSrc: string;
120
126
  };
121
127
  export declare function convertUsageLocationsHandleToEmittableHandle(handle: UsageLocations['handle'], generatedHandle: string): string;
122
128
  export declare function makeEmittableConfigPHP(data: any, asFullFile: boolean, parentIndent?: string): string;
@@ -145,6 +151,14 @@ export declare function newWebpackErrorForFile(error: string | ConstructorParame
145
151
  */
146
152
  export declare function emitResolveBaseUriFunction(writer: PHPWriter): void;
147
153
  export declare function getAssetsJson(compilation: Compilation): ParsedAssetsJson;
154
+ export type ParsedAssetJsonProvider = (entrypoint: Entrypoint, metadata: MinimumViableMetadata) => {
155
+ assetName: string;
156
+ assetData: ParsedAssetsJson[string];
157
+ } | undefined;
158
+ export declare function getParsedAssetsJsonDataForEntrypoint(compilation: Compilation, entrypoint: Entrypoint, metadata: MinimumViableMetadata): {
159
+ assetName: string;
160
+ assetData: ParsedAssetsJson[string];
161
+ } | undefined;
148
162
  export declare function emitPHPWriterAsAsset(writer: PHPWriter, compilation: Compilation, file: string, assetInfo?: AssetInfo): void;
149
163
  export declare function dedent(text: TemplateStringsArray): string;
150
164
  export declare function resolveLegacyBlockScriptsInFolder(folder: string): string[];
package/build/shared.js CHANGED
@@ -24,6 +24,7 @@ exports.parseEnvFile = parseEnvFile;
24
24
  exports.newWebpackErrorForFile = newWebpackErrorForFile;
25
25
  exports.emitResolveBaseUriFunction = emitResolveBaseUriFunction;
26
26
  exports.getAssetsJson = getAssetsJson;
27
+ exports.getParsedAssetsJsonDataForEntrypoint = getParsedAssetsJsonDataForEntrypoint;
27
28
  exports.emitPHPWriterAsAsset = emitPHPWriterAsAsset;
28
29
  exports.dedent = dedent;
29
30
  exports.resolveLegacyBlockScriptsInFolder = resolveLegacyBlockScriptsInFolder;
@@ -183,6 +184,41 @@ function getAssetsJson(compilation) {
183
184
  compilation.updateAsset("assets.json", s => s, a => ({ ...a, "parsed-assets-json": parsedAssetJson }));
184
185
  return parsedAssetJson;
185
186
  }
187
+ function getParsedAssetsJsonDataForEntrypoint(compilation, entrypoint, metadata) {
188
+ const dest = metadata.dest;
189
+ const parsedAssetJson = getAssetsJson(compilation);
190
+ const scriptExtension = compilation.outputOptions.module ? exports.scriptWithModuleExtension : exports.scriptWithoutModuleExtension;
191
+ const assetType = scriptOrStyleTest(metadata.absoluteSrc, scriptExtension);
192
+ const chunkFiles = [dest.destination, ...entrypoint.chunks.flatMap(chunk => Array.from(chunk.files))]
193
+ .filter(chunkFile => scriptOrStyleTest(chunkFile, scriptExtension) === assetType);
194
+ for (const chunkFile of chunkFiles) {
195
+ if (parsedAssetJson[chunkFile]) {
196
+ return { assetName: chunkFile, assetData: parsedAssetJson[chunkFile] };
197
+ }
198
+ }
199
+ if (assetType !== 'style' || !hasAtLeastOneItem(chunkFiles)) {
200
+ return undefined;
201
+ }
202
+ // The rest of this function is a modified version of the hash-computing logic from @wordpress/dependency-extraction-webpack-plugin
203
+ const { hashFunction, hashDigest, hashDigestLength } = compilation.outputOptions;
204
+ const hashBuilder = webpack_1.util.createHash(hashFunction);
205
+ for (const chunkFile of chunkFiles.toSorted()) {
206
+ const source = compilation.getAsset(chunkFile)?.source.buffer();
207
+ if (source !== undefined) {
208
+ hashBuilder.update(source);
209
+ }
210
+ }
211
+ // Finalise hash.
212
+ const contentHash = hashBuilder
213
+ .digest(hashDigest)
214
+ .slice(0, hashDigestLength);
215
+ const assetData = {
216
+ dependencies: [],
217
+ version: contentHash,
218
+ };
219
+ compilation.updateAsset("assets.json", s => s, a => ({ ...a, "parsed-assets-json": { ...parsedAssetJson, [chunkFiles[0]]: assetData } }));
220
+ return { assetName: chunkFiles[0], assetData };
221
+ }
186
222
  function emitPHPWriterAsAsset(writer, compilation, file, assetInfo) {
187
223
  const contents = writer.toString() + "\n";
188
224
  compilation[file in compilation.assets ? 'updateAsset' : 'emitAsset'](file, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents), ...assetInfo });
@@ -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, BlockEntrypointInfo, VerifiedAdvancedOutputConfig } from "../shared";
3
+ import { EntrypointFields, PlauditWordpressWebpackConfig, BlockEntrypointInfo, VerifiedAdvancedOutputConfig, MinimumViableMetadata } 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'>> & {
@@ -23,9 +23,9 @@ export declare function joinPossiblyAbsolutePaths(...paths: (string | undefined)
23
23
  export declare function groupEntrypointsByAssetFile<T>(entrypoints: T[], entrypointNameExtractor: (t: T) => string): Map<string, T[]>;
24
24
  export type BlockJsonExtensibleEntryObject = ExtensibleEntryObject<BlockEntrypointInfo>;
25
25
  export type EntryStaticNormalized = Awaited<ReturnType<ConstructorParameters<typeof DynamicEntryPlugin>[1]>>;
26
- export type ExtensibleEntryObject<M> = {
26
+ export type ExtensibleEntryObject<M extends object = {}> = {
27
27
  [index: string]: Omit<EntryStaticNormalized[string], 'import'> & Required<NonNullable<Pick<EntryStaticNormalized[string], 'import'>>> & {
28
- plauditMetadata: M;
28
+ plauditMetadata: M & MinimumViableMetadata;
29
29
  };
30
30
  };
31
31
  export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: VerifiedAdvancedOutputConfig): EntryProvider<BlockEntrypointInfo>;
@@ -47,7 +47,8 @@ function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
47
47
  entrypointName: parsedEntrypoint.name,
48
48
  handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name),
49
49
  handleGroup: (0, shared_1.getHandleGroup)(entrypointField),
50
- dest
50
+ dest,
51
+ absoluteSrc: ep
51
52
  };
52
53
  return [joinPossiblyAbsolutePaths(dest.destination, node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name),
53
54
  { import: [ep], plauditMetadata: fakeEntrypointInfo }];
@@ -198,7 +199,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
198
199
  }
199
200
  ];
200
201
  }));
201
- rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: { purpose: "block-json-inclusion-assurance", dest } }]);
202
+ rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: { purpose: "block-json-inclusion-assurance", dest, absoluteSrc: blockJsonOrigin } }]);
202
203
  wpmlFiles.push(node_path_1.default.join(dir, 'block.json'));
203
204
  }
204
205
  catch (e) {
@@ -250,14 +251,15 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
250
251
  }
251
252
  if (!processingModules) {
252
253
  const wpmlEntrypointFiles = allEntrypoints.flatMap(e => e[1]);
254
+ const absoluteSrc = node_path_1.default.join(srcRoot, "wpml-config.xml");
253
255
  try {
254
- await promises_1.default.access(node_path_1.default.join(srcRoot, "wpml-config.xml"));
255
- currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: { purpose: "wpml-config-xml", dest } };
256
+ await promises_1.default.access(absoluteSrc);
257
+ currentEntry["wpml-config.xml"] = { import: [node_path_1.default.join(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: { purpose: "wpml-config-xml", dest, absoluteSrc } };
256
258
  }
257
259
  catch (e) {
258
260
  // If the wpml-config.xml file does not exist, just "import" the other files that will be used to build the emitted version
259
261
  if (wpmlEntrypointFiles.length) {
260
- currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: { purpose: "wpml-config-xml", dest } };
262
+ currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: { purpose: "wpml-config-xml", dest, absoluteSrc } };
261
263
  }
262
264
  }
263
265
  }
@@ -494,8 +494,8 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
494
494
  for await (const dirent of await promises_1.default.opendir(srcRoot)) {
495
495
  if (dirent.isFile() && !dirent.name.startsWith("~")) {
496
496
  if (commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name)) {
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: { dest } }]);
497
+ const absoluteSrc = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
498
+ rawEntrypoints.push([node_path_1.default.join(dest.destination, node_path_1.default.basename(absoluteSrc, node_path_1.default.extname(absoluteSrc))), { import: [absoluteSrc], plauditMetadata: { dest, absoluteSrc } }]);
499
499
  }
500
500
  }
501
501
  }
@@ -507,9 +507,9 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
507
507
  plugins.push(plugin);
508
508
  }
509
509
  else if (sourceType === "plain" /* SourceType.plain */) {
510
+ const absoluteSrc = typeof srcRoot === 'string' ? srcRoot : srcRoot[0];
510
511
  if (!srcIsDirectory) {
511
- const primarySrcRoot = typeof srcRoot === 'string' ? srcRoot : srcRoot[0];
512
- if (!scriptExtension.test(primarySrcRoot) && !shared_1.styleExtension.test(primarySrcRoot)) {
512
+ if (!scriptExtension.test(absoluteSrc) && !shared_1.styleExtension.test(absoluteSrc)) {
513
513
  continue;
514
514
  }
515
515
  }
@@ -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: { purpose: "plain-entrypoint", dest } } });
520
+ : () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest, absoluteSrc } } });
521
521
  plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest.locations, config.useUnifiedLoader, contextPath, 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, contextPath, () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest } } }));
528
+ plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(config, contextPath, () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest, absoluteSrc } } }));
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.75.0",
3
+ "version": "2.76.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build"
@@ -33,7 +33,7 @@
33
33
  "webpack-bundle-analyzer": "^4.10.2"
34
34
  },
35
35
  "dependencies": {
36
- "@plaudit/php-writer": "^1.3.1",
36
+ "@plaudit/php-writer": "^1.3.2",
37
37
  "@plaudit/postcss-color-function": "^5.0.0",
38
38
  "@plaudit/postcss-legacy-shorthand": "^1.0.0",
39
39
  "@plaudit/postcss-silent-extend": "^3.0.0",