@plaudit/webpack-extensions 3.2.1 → 3.2.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.
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.2.2] - 2026-03-16
9
+ ### Changed
10
+ - Exposed additional aspects of the entrypoint resolution logic to tools that reference this package
11
+
8
12
  ## [3.2.1] - 2026-03-16
9
13
  ### Added
10
14
  - A function to expose standard flag sets to tools that reference this package
package/build/shared.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { PHPWriter } from "@plaudit/php-writer";
2
2
  import type { Options as PostcssFunctionsOptions } from "postcss-functions";
3
3
  import { AssetInfo, Compilation, Configuration, Entrypoint, WebpackError, Compiler } from "webpack";
4
+ import { SourceType } from "./utils/entrypoint-resolution-logic";
4
5
  import type { NormalizedEnqueuingControlFlags } from "./utils/path-query-and-related-helpers";
6
+ export * from "./utils/entrypoint-resolution-logic";
5
7
  export type ParsedAssetsJson = Record<string, {
6
8
  dependencies: string[];
7
9
  version: string;
@@ -83,12 +85,6 @@ export declare function constantKeys<K extends string, V>(object: {
83
85
  export declare function constantEntries<K extends string, V>(object: {
84
86
  [k in K]: V;
85
87
  }): [K, V][];
86
- export declare const enum SourceType {
87
- blocks = "blocks",
88
- extensions = "extensions",
89
- plain = "plain"
90
- }
91
- export declare function isSourceType(str: string): str is SourceType;
92
88
  export declare function determineCurrentSourceType(dest: string | AdvancedOutputConfig, srcIsDirectory: boolean): SourceType;
93
89
  export interface WebpackPlugin {
94
90
  apply(compiler: Compiler): void;
@@ -146,6 +142,32 @@ export type PlauditWordpressWebpackConfig = {
146
142
  omitDistDev?: boolean;
147
143
  onlyRunPostCSSOnPCSS?: boolean;
148
144
  };
145
+ export declare function applyStandards(config: PlauditWordpressWebpackConfig): {
146
+ readonly standard?: "2026-03-13";
147
+ readonly standaloneBlocks?: boolean;
148
+ readonly variables?: Record<string, any>;
149
+ readonly verbose?: boolean;
150
+ readonly src?: string[] | SourcesObject;
151
+ readonly stats?: Configuration["stats"];
152
+ readonly postcss?: {
153
+ functions?: (variables: (name: string) => unknown) => PostcssFunctionsOptions["functions"];
154
+ };
155
+ readonly externals?: Externals;
156
+ readonly assumeGlobalizedPlauditLibraries?: boolean;
157
+ readonly processTranslationConfigs?: boolean;
158
+ readonly combineAssetMetadata?: boolean;
159
+ useWebpackResourceFiltering?: boolean;
160
+ outputDir?: string;
161
+ extensionsVersion?: 1 | 2 | 3;
162
+ readonly targetHandlePrefix?: string;
163
+ plainEntrypointsVersion?: 1 | 2;
164
+ srcDir?: string;
165
+ readonly srcPrefixes?: string[];
166
+ useUnifiedLoader?: boolean;
167
+ readonly includePostInitFallback?: boolean;
168
+ readonly omitDistDev?: boolean;
169
+ onlyRunPostCSSOnPCSS?: boolean;
170
+ };
149
171
  export declare function resolveStandard(standard: PlauditWordpressWebpackConfig['standard']): {
150
172
  readonly useWebpackResourceFiltering: true;
151
173
  readonly extensionsVersion: 3;
@@ -187,7 +209,7 @@ export declare const scriptExtension: RegExp;
187
209
  export declare const scriptWithoutModuleExtension: RegExp;
188
210
  export declare const scriptWithModuleExtension: RegExp;
189
211
  export declare const styleExtension: RegExp;
190
- export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "style" | "script" | "";
212
+ export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "script" | "style" | "";
191
213
  export declare function isStyleField(field: string): field is 'style' | 'viewStyle' | 'editorStyle';
192
214
  export declare function isScriptModuleField(field: string): field is 'viewScriptModule';
193
215
  export declare function getHandleGroup(field: string): 'styleHandles' | 'scriptHandles' | 'scriptModuleHandles';
@@ -226,4 +248,3 @@ export declare function resolveLegacyBlockScriptsInFolder(folder: string): strin
226
248
  * @param file something that represents the file that is being inlined (this is purely for error-reporting purposes)
227
249
  */
228
250
  export declare function appendAddInlineAssetCall(compilation: Compilation, writer: PHPWriter, handle: string, type: 'script' | 'style' | 'script_module', inlinedAsset: InlinedAsset, handleData: HandleData, file: string): void;
229
- export {};
package/build/shared.js CHANGED
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
18
  };
@@ -10,8 +24,8 @@ exports.isRegisterScriptArgsShorthandName = isRegisterScriptArgsShorthandName;
10
24
  exports.isNormalizedUsageLocations = isNormalizedUsageLocations;
11
25
  exports.constantKeys = constantKeys;
12
26
  exports.constantEntries = constantEntries;
13
- exports.isSourceType = isSourceType;
14
27
  exports.determineCurrentSourceType = determineCurrentSourceType;
28
+ exports.applyStandards = applyStandards;
15
29
  exports.resolveStandard = resolveStandard;
16
30
  exports.convertUsageLocationsHandleToEmittableHandle = convertUsageLocationsHandleToEmittableHandle;
17
31
  exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
@@ -41,6 +55,7 @@ const node_path_1 = __importDefault(require("node:path"));
41
55
  const php_writer_1 = require("@plaudit/php-writer");
42
56
  const expressions_1 = require("@plaudit/php-writer/expressions");
43
57
  const webpack_1 = require("webpack");
58
+ __exportStar(require("./utils/entrypoint-resolution-logic"), exports);
44
59
  function isParsedAssetsJson(thing) {
45
60
  if (!thing || typeof thing !== 'object') {
46
61
  return false;
@@ -78,9 +93,6 @@ function constantKeys(object) {
78
93
  function constantEntries(object) {
79
94
  return Object.entries(object);
80
95
  }
81
- function isSourceType(str) {
82
- return str === "blocks" /* SourceType.blocks */ || str === "extensions" /* SourceType.extensions */ || str === "plain" /* SourceType.plain */;
83
- }
84
96
  function determineCurrentSourceType(dest, srcIsDirectory) {
85
97
  if (typeof dest === 'string') {
86
98
  return srcIsDirectory ? "blocks" /* SourceType.blocks */ : "plain" /* SourceType.plain */;
@@ -97,6 +109,19 @@ function determineCurrentSourceType(dest, srcIsDirectory) {
97
109
  return dest.directoryLayout;
98
110
  }
99
111
  }
112
+ function applyStandards(config) {
113
+ switch (config.standard) {
114
+ case '2026-03-13':
115
+ return {
116
+ ...resolveStandard('2026-03-13'),
117
+ ...config
118
+ };
119
+ case undefined:
120
+ return config;
121
+ default:
122
+ throw `Invalid standard: ${config.standard}`;
123
+ }
124
+ }
100
125
  function resolveStandard(standard) {
101
126
  switch (standard) {
102
127
  case "2026-03-13":
@@ -0,0 +1,8 @@
1
+ import type { AdvancedOutputConfig, PlauditWordpressWebpackConfig } from "../shared";
2
+ export declare const enum SourceType {
3
+ blocks = "blocks",
4
+ extensions = "extensions",
5
+ plain = "plain"
6
+ }
7
+ export declare function isSourceType(str: string): str is SourceType;
8
+ export declare function resolveAllConfigLevelEntrypoints(config: PlauditWordpressWebpackConfig): [string, AdvancedOutputConfig][];
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSourceType = isSourceType;
4
+ exports.resolveAllConfigLevelEntrypoints = resolveAllConfigLevelEntrypoints;
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const location_encoding_filename_parser_1 = require("./location-encoding-filename-parser");
8
+ const path_query_and_related_helpers_1 = require("./path-query-and-related-helpers");
9
+ function isSourceType(str) {
10
+ return str === "blocks" /* SourceType.blocks */ || str === "extensions" /* SourceType.extensions */ || str === "plain" /* SourceType.plain */;
11
+ }
12
+ function resolveAllConfigLevelEntrypoints(config) {
13
+ const srcDir = config.srcDir ?? "";
14
+ const normalizeSrcAndDestination = ([rawSrc, dest]) => {
15
+ let [src, pathQueryParameters] = (0, path_query_and_related_helpers_1.unpackPotentiallyPrefixedFilePath)(rawSrc);
16
+ if (srcDir) {
17
+ src = (0, node_path_1.join)(srcDir, src);
18
+ }
19
+ src = (0, node_path_1.isAbsolute)(src) ? (0, node_path_1.relative)(process.cwd(), src) : src;
20
+ 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
+ }
23
+ return [src, { ...dest, pathQueryParameters }];
24
+ };
25
+ if (Array.isArray(config.src)) {
26
+ return config.src.map(s => normalizeSrcAndDestination([s, { destination: s }]));
27
+ }
28
+ else {
29
+ const configSrc = config.src ?? {};
30
+ // We check for files with location-encoding filenames and add the pertinent ones to the sources
31
+ const dynamicallyIncludedEntrypoints = [];
32
+ 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);
34
+ using dir = (0, node_fs_1.opendirSync)(dynamicallyIncludedEntrypointsRoot);
35
+ for (let dirent; (dirent = dir.readSync()) !== null;) {
36
+ if (dirent.name in configSrc || `./${dirent.name}` in configSrc) {
37
+ continue;
38
+ }
39
+ if (dirent.isDirectory()) {
40
+ // If it's a directory that does not have an existing config entry, but does correspond to one of the non-plain SourceTypes, assume that it matches that source type
41
+ if (isSourceType(dirent.name) && dirent.name !== "plain" /* SourceType.plain */) {
42
+ dynamicallyIncludedEntrypoints.push([dirent.name, { directoryLayout: dirent.name }]);
43
+ continue;
44
+ }
45
+ using nestedDir = (0, node_fs_1.opendirSync)((0, node_path_1.join)(dynamicallyIncludedEntrypointsRoot, dirent.name));
46
+ for (let nestedDirent; (nestedDirent = nestedDir.readSync()) !== null;) {
47
+ if (!nestedDirent.isFile()) {
48
+ continue;
49
+ }
50
+ const cfgName = (0, node_path_1.join)(dirent.name, nestedDirent.name);
51
+ if (cfgName in configSrc || `./${cfgName}` in configSrc) {
52
+ continue;
53
+ }
54
+ const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(cfgName);
55
+ if (parsedFilename === undefined) {
56
+ continue;
57
+ }
58
+ dynamicallyIncludedEntrypoints.push([cfgName, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
59
+ }
60
+ }
61
+ else if (dirent.isFile()) {
62
+ const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(dirent.name);
63
+ if (parsedFilename === undefined) {
64
+ continue;
65
+ }
66
+ dynamicallyIncludedEntrypoints.push([dirent.name, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
67
+ }
68
+ }
69
+ }
70
+ return [...Object.entries(configSrc), ...dynamicallyIncludedEntrypoints]
71
+ .map(([k, v]) => {
72
+ return normalizeSrcAndDestination([k, typeof v === 'boolean' ? {} : (typeof v === 'string' ? { destination: v } : v)]);
73
+ });
74
+ }
75
+ }
@@ -6,8 +6,8 @@ const node_fs_1 = require("node:fs");
6
6
  const promises_1 = require("node:fs/promises");
7
7
  const node_path_1 = require("node:path");
8
8
  const shared_1 = require("./shared");
9
+ const entrypoint_resolution_logic_1 = require("./utils/entrypoint-resolution-logic");
9
10
  const common_config_helpers_1 = require("./utils/common-config-helpers");
10
- const location_encoding_filename_parser_1 = require("./utils/location-encoding-filename-parser");
11
11
  const path_query_and_related_helpers_1 = require("./utils/path-query-and-related-helpers");
12
12
  const AdditionalDependencyInjectorPlugin_1 = require("./plugins/AdditionalDependencyInjectorPlugin");
13
13
  const BrowserSyncPlugin_1 = require("./plugins/BrowserSyncPlugin");
@@ -165,7 +165,7 @@ function injectSupportForInliningSVGsAsStrings(rules) {
165
165
  });
166
166
  }
167
167
  function buildVerifiedConfig(config) {
168
- config = applyStandards(config);
168
+ config = (0, shared_1.applyStandards)(config);
169
169
  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, plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = false, omitDistDev = false, onlyRunPostCSSOnPCSS = false } = config;
170
170
  let outputDir = config.outputDir ?? "";
171
171
  if (outputDir && useUnifiedLoader && !omitDistDev && (process.env['SERVER_MODE'] ?? 'development') === 'development') {
@@ -191,68 +191,7 @@ function buildVerifiedConfig(config) {
191
191
  throw new Error("Plain Entrypoints V2 and higher require 'outputDir' to be set");
192
192
  }
193
193
  }
194
- const normalizeSrcAndDestination = ([rawSrc, dest]) => {
195
- let [src, pathQueryParameters] = (0, path_query_and_related_helpers_1.unpackPotentiallyPrefixedFilePath)(rawSrc);
196
- if (srcDir) {
197
- src = (0, node_path_1.join)(srcDir, src);
198
- }
199
- src = (0, node_path_1.isAbsolute)(src) ? (0, node_path_1.relative)(process.cwd(), src) : src;
200
- if (dest.destination !== undefined && (0, node_path_1.isAbsolute)(dest.destination)) {
201
- return [src, { ...dest, destination: (0, node_path_1.relative)(process.cwd(), dest.destination), pathQueryParameters }];
202
- }
203
- return [src, { ...dest, pathQueryParameters }];
204
- };
205
- let rawSources;
206
- if (Array.isArray(config.src)) {
207
- rawSources = config.src.map(s => normalizeSrcAndDestination([s, { destination: s }]));
208
- }
209
- else {
210
- const configSrc = config.src ?? {};
211
- // We check for files with location-encoding filenames and add the pertinent ones to the sources
212
- const dynamicallyIncludedEntrypoints = [];
213
- if (srcDir) { // This will only work if we have a unified src root
214
- const dynamicallyIncludedEntrypointsRoot = (0, node_path_1.isAbsolute)(srcDir) ? srcDir : (0, node_path_1.join)(process.cwd(), srcDir);
215
- using dir = (0, node_fs_1.opendirSync)(dynamicallyIncludedEntrypointsRoot);
216
- for (let dirent; (dirent = dir.readSync()) !== null;) {
217
- if (dirent.name in configSrc || `./${dirent.name}` in configSrc) {
218
- continue;
219
- }
220
- if (dirent.isDirectory()) {
221
- // If it's a directory that does not have an existing config entry, but does correspond to one of the non-plain SourceTypes, assume that it matches that source type
222
- if ((0, shared_1.isSourceType)(dirent.name) && dirent.name !== "plain" /* SourceType.plain */) {
223
- dynamicallyIncludedEntrypoints.push([dirent.name, { directoryLayout: dirent.name }]);
224
- continue;
225
- }
226
- using nestedDir = (0, node_fs_1.opendirSync)((0, node_path_1.join)(dynamicallyIncludedEntrypointsRoot, dirent.name));
227
- for (let nestedDirent; (nestedDirent = nestedDir.readSync()) !== null;) {
228
- if (!nestedDirent.isFile()) {
229
- continue;
230
- }
231
- const cfgName = (0, node_path_1.join)(dirent.name, nestedDirent.name);
232
- if (cfgName in configSrc || `./${cfgName}` in configSrc) {
233
- continue;
234
- }
235
- const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(cfgName);
236
- if (parsedFilename === undefined) {
237
- continue;
238
- }
239
- dynamicallyIncludedEntrypoints.push([cfgName, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
240
- }
241
- }
242
- else if (dirent.isFile()) {
243
- const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(dirent.name);
244
- if (parsedFilename === undefined) {
245
- continue;
246
- }
247
- dynamicallyIncludedEntrypoints.push([dirent.name, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
248
- }
249
- }
250
- }
251
- rawSources = [...Object.entries(configSrc), ...dynamicallyIncludedEntrypoints]
252
- .map(([k, v]) => {
253
- return normalizeSrcAndDestination([k, typeof v === 'boolean' ? {} : (typeof v === 'string' ? { destination: v } : v)]);
254
- });
255
- }
194
+ const rawSources = (0, entrypoint_resolution_logic_1.resolveAllConfigLevelEntrypoints)(config);
256
195
  let variablesFilePath = undefined;
257
196
  const currentVariables = rawVariables ?? {};
258
197
  if (!rawVariables) {
@@ -302,19 +241,6 @@ function buildVerifiedConfig(config) {
302
241
  testForDuplicatedEntryPaths(sources);
303
242
  return cfg.outputDir ? { cfg, sources } : withDerivedOutputDir(cfg, sources);
304
243
  }
305
- function applyStandards(config) {
306
- switch (config.standard) {
307
- case '2026-03-13':
308
- return {
309
- ...(0, shared_1.resolveStandard)('2026-03-13'),
310
- ...config
311
- };
312
- case undefined:
313
- return config;
314
- default:
315
- throw `Invalid standard: ${config.standard}`;
316
- }
317
- }
318
244
  function toEffectiveWebpackDestination(destination) {
319
245
  const pathParts = (0, node_path_1.parse)(destination);
320
246
  return (0, node_path_1.join)(pathParts.dir, pathParts.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build",