@plaudit/webpack-extensions 3.2.2 → 3.3.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/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [3.3.0] - 2026-03-16
9
+ ### Added
10
+ - A few helper methods for tools that reference this package and care about the entrypoint resolution logic
11
+
8
12
  ## [3.2.2] - 2026-03-16
9
13
  ### Changed
10
14
  - Exposed additional aspects of the entrypoint resolution logic to tools that reference this package
@@ -5,4 +5,6 @@ export declare const enum SourceType {
5
5
  plain = "plain"
6
6
  }
7
7
  export declare function isSourceType(str: string): str is SourceType;
8
- export declare function resolveAllConfigLevelEntrypoints(config: PlauditWordpressWebpackConfig): [string, AdvancedOutputConfig][];
8
+ type Entrypoints = [string, AdvancedOutputConfig][];
9
+ export declare function resolveAllConfigLevelEntrypoints(config: PlauditWordpressWebpackConfig, projectRoot?: string): Record<'staticEntrypoints' | 'dynamicEntrypoints', Entrypoints>;
10
+ export {};
@@ -9,28 +9,35 @@ const path_query_and_related_helpers_1 = require("./path-query-and-related-helpe
9
9
  function isSourceType(str) {
10
10
  return str === "blocks" /* SourceType.blocks */ || str === "extensions" /* SourceType.extensions */ || str === "plain" /* SourceType.plain */;
11
11
  }
12
- function resolveAllConfigLevelEntrypoints(config) {
12
+ function resolveAllConfigLevelEntrypoints(config, projectRoot = process.cwd()) {
13
13
  const srcDir = config.srcDir ?? "";
14
14
  const normalizeSrcAndDestination = ([rawSrc, dest]) => {
15
15
  let [src, pathQueryParameters] = (0, path_query_and_related_helpers_1.unpackPotentiallyPrefixedFilePath)(rawSrc);
16
16
  if (srcDir) {
17
17
  src = (0, node_path_1.join)(srcDir, src);
18
18
  }
19
- src = (0, node_path_1.isAbsolute)(src) ? (0, node_path_1.relative)(process.cwd(), src) : src;
19
+ src = (0, node_path_1.isAbsolute)(src) ? (0, node_path_1.relative)(projectRoot, src) : src;
20
+ let resultObject;
20
21
  if (dest.destination !== undefined && (0, node_path_1.isAbsolute)(dest.destination)) {
21
- return [src, { ...dest, destination: (0, node_path_1.relative)(process.cwd(), dest.destination), pathQueryParameters }];
22
+ resultObject = { ...dest, destination: (0, node_path_1.relative)(projectRoot, dest.destination) };
22
23
  }
23
- return [src, { ...dest, pathQueryParameters }];
24
+ else {
25
+ resultObject = { ...dest };
26
+ }
27
+ return [src, pathQueryParameters ? { ...resultObject, pathQueryParameters } : resultObject];
24
28
  };
25
29
  if (Array.isArray(config.src)) {
26
- return config.src.map(s => normalizeSrcAndDestination([s, { destination: s }]));
30
+ return {
31
+ staticEntrypoints: config.src.map(s => normalizeSrcAndDestination([s, { destination: s }])),
32
+ dynamicEntrypoints: []
33
+ };
27
34
  }
28
35
  else {
29
36
  const configSrc = config.src ?? {};
30
37
  // We check for files with location-encoding filenames and add the pertinent ones to the sources
31
38
  const dynamicallyIncludedEntrypoints = [];
32
39
  if (srcDir) { // This will only work if we have a unified src root
33
- const dynamicallyIncludedEntrypointsRoot = (0, node_path_1.isAbsolute)(srcDir) ? srcDir : (0, node_path_1.join)(process.cwd(), srcDir);
40
+ const dynamicallyIncludedEntrypointsRoot = (0, node_path_1.isAbsolute)(srcDir) ? srcDir : (0, node_path_1.join)(projectRoot, srcDir);
34
41
  using dir = (0, node_fs_1.opendirSync)(dynamicallyIncludedEntrypointsRoot);
35
42
  for (let dirent; (dirent = dir.readSync()) !== null;) {
36
43
  if (dirent.name in configSrc || `./${dirent.name}` in configSrc) {
@@ -67,9 +74,11 @@ function resolveAllConfigLevelEntrypoints(config) {
67
74
  }
68
75
  }
69
76
  }
70
- return [...Object.entries(configSrc), ...dynamicallyIncludedEntrypoints]
71
- .map(([k, v]) => {
72
- return normalizeSrcAndDestination([k, typeof v === 'boolean' ? {} : (typeof v === 'string' ? { destination: v } : v)]);
73
- });
77
+ return {
78
+ staticEntrypoints: Object.entries(configSrc).map(([k, v]) => {
79
+ return normalizeSrcAndDestination([k, typeof v === 'boolean' ? {} : (typeof v === 'string' ? { destination: v } : v)]);
80
+ }),
81
+ dynamicEntrypoints: dynamicallyIncludedEntrypoints.map(normalizeSrcAndDestination)
82
+ };
74
83
  }
75
84
  }
@@ -8,7 +8,7 @@ export type ParsedLocationEncodingFilename = {
8
8
  flags: NormalizedEnqueuingControlFlags;
9
9
  };
10
10
  export declare function parseLocationEncodingFilename(filename: string): ParsedLocationEncodingFilename | undefined;
11
- export declare function parseLocationEncodingFilenameForBlock(filename: string): Omit<ParsedLocationEncodingFilename, 'locations'> & {
11
+ export declare function parseLocationEncodingFilenameForBlock(filename: string, errorBuilder?: (message: string, filename: string) => unknown): Omit<ParsedLocationEncodingFilename, 'locations'> & {
12
12
  locations: Pick<RealUsageLocations, 'clientEditor' | 'clientView'>;
13
13
  } | undefined;
14
14
  /**
@@ -76,14 +76,14 @@ function parseLocationEncodingFilename(filename) {
76
76
  }
77
77
  return { type, locations, flags };
78
78
  }
79
- function parseLocationEncodingFilenameForBlock(filename) {
79
+ function parseLocationEncodingFilenameForBlock(filename, errorBuilder = shared_1.newWebpackErrorForFile) {
80
80
  const parsedFilename = parseLocationEncodingFilename(filename);
81
81
  if (parsedFilename !== undefined) {
82
82
  if ((0, shared_1.constantKeys)(parsedFilename.locations).some(value => value !== 'clientView' && value !== 'clientEditor')) {
83
- throw (0, shared_1.newWebpackErrorForFile)(`Block assets cannot be enqueued anywhere other than view, editor, or both. Saw: ${(0, shared_1.constantKeys)(parsedFilename).join(", ")}`, filename);
83
+ throw errorBuilder(`Block assets cannot be enqueued anywhere other than view, editor, or both. Saw: ${(0, shared_1.constantKeys)(parsedFilename).join(", ")}`, filename);
84
84
  }
85
85
  if (Object.values(parsedFilename.locations).some(value => typeof value === 'number')) {
86
- throw (0, shared_1.newWebpackErrorForFile)(`Block assets cannot be enqueued with a priority`, filename);
86
+ throw errorBuilder(`Block assets cannot be enqueued with a priority`, filename);
87
87
  }
88
88
  }
89
89
  return parsedFilename;
@@ -191,7 +191,8 @@ function buildVerifiedConfig(config) {
191
191
  throw new Error("Plain Entrypoints V2 and higher require 'outputDir' to be set");
192
192
  }
193
193
  }
194
- const rawSources = (0, entrypoint_resolution_logic_1.resolveAllConfigLevelEntrypoints)(config);
194
+ const { staticEntrypoints, dynamicEntrypoints } = (0, entrypoint_resolution_logic_1.resolveAllConfigLevelEntrypoints)(config);
195
+ const rawSources = [...staticEntrypoints, ...dynamicEntrypoints];
195
196
  let variablesFilePath = undefined;
196
197
  const currentVariables = rawVariables ?? {};
197
198
  if (!rawVariables) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build",
@@ -11,6 +11,7 @@
11
11
  ],
12
12
  "exports": {
13
13
  "./wordpress-scripts-wrapper": "./build/wordpress-scripts-wrapper.js",
14
+ "./location-encoding-filename-parser": "./build/utils/location-encoding-filename-parser.js",
14
15
  "./shared": "./build/shared.js"
15
16
  },
16
17
  "typesVersions": {
@@ -18,6 +19,9 @@
18
19
  "wordpress-scripts-wrapper": [
19
20
  "build/wordpress-scripts-wrapper.d.ts"
20
21
  ],
22
+ "location-encoding-filename-parser": [
23
+ "build/location-encoding-filename-parser.d.ts"
24
+ ],
21
25
  "shared": [
22
26
  "build/shared.d.ts"
23
27
  ]