@plaudit/webpack-extensions 3.11.0 → 3.12.1

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,17 @@ 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.12.1] - 2026-06-23
9
+ ### Fixed
10
+ - The nice name handling not working for blocks
11
+
12
+ ## [3.12.0] - 2026-06-23
13
+ ### Added
14
+ - Logic to treat the nice name of a file as the suffix of its handle
15
+
16
+ ### Changed
17
+ - The handle-part-separator for plain entrypoints from `.` to `/`
18
+
8
19
  ## [3.11.0] - 2026-06-22
9
20
  ### Added
10
21
  - Logic to allow our internal PostCSS plugins to be "optional"
@@ -43,15 +43,15 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
43
43
  for (const { src, rest, locations, type, handleName, lazyLoader, ...otherProps } of handles) {
44
44
  const cleanBasename = (0, node_path_1.basename)(src).replace(/_(?:script(?:-\d+)?\.js|style(?:-\d+)?\.css)$|(?<!_(script|style))\.(js|css)$/, "");
45
45
  let finalHandleName;
46
- if (typeof handleName === 'string') {
47
- finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, cleanBasename);
46
+ const handleNameMap = usedHandleNames[type];
47
+ const baseFinalHandleName = finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)({ niceName: (0, shared_1.kebabCase)(cleanBasename) }, handlePrefix, cleanBasename);
48
+ for (let count = 0; finalHandleName in handleNameMap && handleNameMap[finalHandleName] !== src;) {
49
+ finalHandleName = `${baseFinalHandleName}-${++count}`;
50
+ }
51
+ if (typeof handleName === 'string' || typeof handleName === 'function') {
52
+ finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, handlePrefix, finalHandleName.substring(handlePrefix.length + 1));
48
53
  }
49
54
  else {
50
- const handleNameMap = usedHandleNames[type];
51
- const baseFinalHandleName = finalHandleName = `${handlePrefix}.${(0, shared_1.convertUsageLocationsHandleToEmittableHandle)((0, shared_1.kebabCase)(cleanBasename), cleanBasename)}`;
52
- for (let count = 0; finalHandleName in handleNameMap && handleNameMap[finalHandleName] !== src;) {
53
- finalHandleName = `${baseFinalHandleName}-${++count}`;
54
- }
55
55
  handleNameMap[finalHandleName] = src;
56
56
  }
57
57
  plainEntrypointsConfig[`${type}Handles`][finalHandleName] = { src, rest, locations, type, lazyLoader, ...otherProps };
package/dist/shared.d.ts CHANGED
@@ -78,7 +78,9 @@ export type RealUsageLocations = {
78
78
  export type UsageLocations = RealUsageLocations & {
79
79
  register?: boolean | number;
80
80
  inline?: number;
81
- handle?: string | ((generatedHandle: string) => string);
81
+ handle?: string | ((generatedHandle: string) => string) | {
82
+ niceName: string;
83
+ };
82
84
  registerScriptArgs?: InputRegisterScriptArgs;
83
85
  };
84
86
  export type NormalizedUsageLocations = Omit<UsageLocations, 'registerScriptArgs'> & {
@@ -207,7 +209,8 @@ export type MinimumViableMetadata = {
207
209
  dest: VerifiedAdvancedOutputConfig;
208
210
  absoluteSrc: string;
209
211
  };
210
- export declare function convertUsageLocationsHandleToEmittableHandle(handle: UsageLocations['handle'], generatedHandle: string): string;
212
+ export declare function convertUsageLocationsHandleToEmittableHandle(handle: UsageLocations['handle'], handlePrefix: string, generatedNiceName: string): string;
213
+ export declare function convertUsageLocationsHandleToEmittableHandleSuffix(handle: UsageLocations['handle'], generatedNiceName: string): string;
211
214
  export declare function makeEmittableConfigPHP(data: any, asFullFile: boolean, parentIndent?: string): string;
212
215
  export declare const entrypointFields: readonly ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script", "viewScriptModule"];
213
216
  export type EntrypointFields = (typeof entrypointFields[number])[];
package/dist/shared.js CHANGED
@@ -28,6 +28,7 @@ exports.determineCurrentSourceType = determineCurrentSourceType;
28
28
  exports.applyStandards = applyStandards;
29
29
  exports.resolveStandard = resolveStandard;
30
30
  exports.convertUsageLocationsHandleToEmittableHandle = convertUsageLocationsHandleToEmittableHandle;
31
+ exports.convertUsageLocationsHandleToEmittableHandleSuffix = convertUsageLocationsHandleToEmittableHandleSuffix;
31
32
  exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
32
33
  exports.convertEntrypointFieldForAssetType = convertEntrypointFieldForAssetType;
33
34
  exports.leadingSlashIt = leadingSlashIt;
@@ -143,9 +144,37 @@ function resolveStandard(standard) {
143
144
  return undefined;
144
145
  }
145
146
  }
146
- function convertUsageLocationsHandleToEmittableHandle(handle, generatedHandle) {
147
- const emittableHandle = typeof handle === 'string' ? handle : handle?.(generatedHandle) ?? generatedHandle;
148
- return emittableHandle.replaceAll("{basename}", generatedHandle);
147
+ function convertUsageLocationsHandleToEmittableHandle(handle, handlePrefix, generatedNiceName) {
148
+ let emittableHandle;
149
+ if (!handle) {
150
+ return `${handlePrefix}/${generatedNiceName}`;
151
+ }
152
+ if (typeof handle === 'string') {
153
+ emittableHandle = handle;
154
+ }
155
+ else if (typeof handle === 'function') {
156
+ emittableHandle = handle(`${handlePrefix}/${generatedNiceName}`);
157
+ }
158
+ else {
159
+ emittableHandle = `${handlePrefix}/${handle.niceName}`;
160
+ }
161
+ return emittableHandle.replaceAll("{basename}", generatedNiceName);
162
+ }
163
+ function convertUsageLocationsHandleToEmittableHandleSuffix(handle, generatedNiceName) {
164
+ let emittableHandle;
165
+ if (!handle) {
166
+ return generatedNiceName;
167
+ }
168
+ if (typeof handle === 'string') {
169
+ emittableHandle = handle;
170
+ }
171
+ else if (typeof handle === 'function') {
172
+ emittableHandle = handle(generatedNiceName);
173
+ }
174
+ else {
175
+ emittableHandle = handle.niceName;
176
+ }
177
+ return emittableHandle.replaceAll("{basename}", generatedNiceName);
149
178
  }
150
179
  function makeEmittableConfigPHP(data, asFullFile, parentIndent = "") {
151
180
  const prettyPrintedMetadata = php_writer_1.json2php.make({ indent: "\t", linebreak: "\n", shortArraySyntax: true })(data, parentIndent)
@@ -40,13 +40,13 @@ function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
40
40
  .map(([ep, rawPathQueryParameters]) => {
41
41
  const parsedEntrypoint = (0, node_path_1.parse)(ep);
42
42
  const entrypointField = shared_1.styleExtension.test(ep) ? 'style' : shared_1.scriptWithModuleExtension.test(ep) ? 'viewScriptModule' : 'script';
43
- const { flags: enqueuingFlags, remainder: pathQueryParameters } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(rawPathQueryParameters, ep, 'path query parameters');
43
+ const { flags: enqueuingFlags, remainder: pathQueryParameters, handle } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(rawPathQueryParameters, ep, 'path query parameters');
44
44
  const fakeEntrypointInfo = {
45
45
  blockJsonOrigin: args.entrypointJsonOrigin,
46
46
  entrypointField,
47
47
  originalValue: ep,
48
48
  entrypointName: parsedEntrypoint.name,
49
- handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, parsedEntrypoint.name),
49
+ handle: handle ?? dest.locations.handle ? (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handle ?? dest.locations.handle, parsedEntrypoint.name, parsedEntrypoint.name) : parsedEntrypoint.name,
50
50
  handleGroup: (0, shared_1.getHandleGroup)(entrypointField),
51
51
  dest,
52
52
  absoluteSrc: ep,
@@ -157,6 +157,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
157
157
  if (!stats.isFile()) {
158
158
  return undefined;
159
159
  }
160
+ //TODO: Handle alternate methods of declaring a handle
160
161
  const parsedEntrypoint = (0, node_path_1.parse)((0, node_path_1.normalize)((0, node_path_1.join)(dest.destination, (0, node_path_1.relative)(srcRoot, dir), entrypointPath)));
161
162
  const extensionlessExpectedSrc = (0, node_path_1.normalize)((0, node_path_1.join)(parsedEntrypoint.dir, parsedEntrypoint.name));
162
163
  const entrypointName = (0, node_path_1.normalize)(joinPossiblyAbsolutePaths(parsedEntrypoint.dir, parsedEntrypoint.name));
@@ -180,7 +181,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
180
181
  if (!parsedFilename) {
181
182
  continue;
182
183
  }
183
- const { type, locations, flags } = parsedFilename;
184
+ const { type, locations, handle, flags } = parsedFilename;
184
185
  if (((type === 'script-module') !== processingModules)) {
185
186
  continue;
186
187
  }
@@ -219,7 +220,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
219
220
  absoluteSrc,
220
221
  pathQueryParameters: dest.pathQueryParameters,
221
222
  enqueuingFlags,
222
- handle: undefined
223
+ handle
223
224
  });
224
225
  }
225
226
  const entrypointNamesWithEffectiveDuplicates = presentEntrypoints
@@ -228,19 +229,44 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
228
229
  a[entry.entrypointName] = (a[entry.entrypointName] !== undefined);
229
230
  return a;
230
231
  }, {});
232
+ const getDefaultHandle = (presentEntrypoint) => {
233
+ const baseSuffix = `_${(0, shared_1.isStyleField)(presentEntrypoint.entrypointField) ? "style" : "script"}`;
234
+ let count = 0, suffix = baseSuffix, deduplicatedEntrypointName;
235
+ while (((deduplicatedEntrypointName = (presentEntrypoint.entrypointName + suffix)) in allocatedDestinations)
236
+ && allocatedDestinations[deduplicatedEntrypointName] !== presentEntrypoint.originalValue) {
237
+ suffix = baseSuffix + "_" + (++count);
238
+ }
239
+ return { count, suffix, deduplicatedEntrypointName };
240
+ };
231
241
  const handlePrefix = blockJson['name']?.toString() ?? `__UNKNOWN_PREFIX__/${dirent.name}`;
232
242
  const allocatedDestinations = {};
233
243
  const resolvedBlockEntrypoints = presentEntrypoints
234
244
  .map(presentEntrypoint => {
235
245
  const overallSource = (0, node_path_1.dirname)(blockJsonOrigin);
236
246
  const overallSourceRelativeName = (0, node_path_1.relative)(overallSource, (0, node_path_1.normalize)((0, node_path_1.join)(blockJsonOrigin, (0, node_path_1.relative)(overallSource, presentEntrypoint.extensionlessExpectedSrc))));
237
- const handleSuffix = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, overallSourceRelativeName);
247
+ const handleSuffix = (0, shared_1.convertUsageLocationsHandleToEmittableHandleSuffix)(dest.locations.handle, overallSourceRelativeName);
238
248
  const handleGroup = (0, shared_1.getHandleGroup)(presentEntrypoint.entrypointField);
249
+ let explicitlySetHandle;
239
250
  if (presentEntrypoint.handle) {
240
- (seenExplicitHandles[handleGroup][presentEntrypoint.handle] ??= []).push(overallSource);
251
+ if (typeof presentEntrypoint.handle === 'string') {
252
+ explicitlySetHandle = presentEntrypoint.handle;
253
+ }
254
+ else if ('niceName' in presentEntrypoint.handle) {
255
+ explicitlySetHandle = `${handlePrefix}/${presentEntrypoint.handle.niceName}`;
256
+ }
257
+ else {
258
+ explicitlySetHandle = presentEntrypoint.handle(`${handlePrefix}/${getDefaultHandle(presentEntrypoint)}`);
259
+ }
260
+ if (explicitlySetHandle.length < 5) {
261
+ throw (0, shared_1.newWebpackErrorForFile)(`The handle was invalid. Received: ${explicitlySetHandle}. Expected: a string that is at least 5 characters long`, overallSourceRelativeName);
262
+ }
263
+ (seenExplicitHandles[handleGroup][explicitlySetHandle] ??= []).push(overallSource);
264
+ }
265
+ else {
266
+ explicitlySetHandle = undefined;
241
267
  }
242
268
  if (!entrypointNamesWithEffectiveDuplicates[presentEntrypoint.entrypointName]) {
243
- return { blockJsonOrigin, ...presentEntrypoint, handle: presentEntrypoint.handle ?? `${handlePrefix}/${handleSuffix}`, dest, handleGroup };
269
+ return { blockJsonOrigin, ...presentEntrypoint, handle: explicitlySetHandle ?? `${handlePrefix}/${handleSuffix}`, dest, handleGroup };
244
270
  }
245
271
  const baseSuffix = `_${(0, shared_1.isStyleField)(presentEntrypoint.entrypointField) ? "style" : "script"}`;
246
272
  let count = 0, suffix = baseSuffix, deduplicatedEntrypointName;
@@ -255,7 +281,8 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
255
281
  ...presentEntrypoint,
256
282
  entrypointName: deduplicatedEntrypointName,
257
283
  extensionlessExpectedSrc: deduplicatedExtensionlessExpectedSrc,
258
- handle: presentEntrypoint.handle ?? `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`, handleGroup,
284
+ handle: explicitlySetHandle ?? `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`,
285
+ handleGroup,
259
286
  dest
260
287
  };
261
288
  });
@@ -4,14 +4,19 @@ export type ParsedLocationEncodingFilename = {
4
4
  type: 'script' | 'style' | 'script-module';
5
5
  locations: RealUsageLocations & {
6
6
  register?: boolean | number;
7
+ } & {
8
+ handle?: {
9
+ niceName: string;
10
+ };
7
11
  };
8
12
  flags: NormalizedEnqueuingControlFlags;
9
13
  niceName?: string;
10
14
  };
11
15
  export declare function parseLocationEncodingFilename(filename: string): ParsedLocationEncodingFilename | undefined;
12
- export declare function parseLocationEncodingFilenameForBlock(filename: string, errorBuilder?: (message: string, filename: string) => unknown): Omit<ParsedLocationEncodingFilename, 'locations'> & {
16
+ export declare function parseLocationEncodingFilenameForBlock(filename: string, errorBuilder?: (message: string, filename: string) => unknown): (Omit<ParsedLocationEncodingFilename, 'locations'> & {
13
17
  locations: Pick<RealUsageLocations, 'clientEditor' | 'clientView'>;
14
- } | undefined;
18
+ handle: ParsedLocationEncodingFilename['locations']['handle'];
19
+ }) | undefined;
15
20
  /**
16
21
  * This handles detecting all keys of standardLocationNamesMeta as well as "view", "client-view", "editor", "client-editor", and "block-assets".
17
22
  * It MUST be kept in sync with standardLocationNamesMeta
@@ -78,17 +78,22 @@ function parseLocationEncodingFilename(filename) {
78
78
  if (Object.values(locations).length === 0) {
79
79
  return undefined;
80
80
  }
81
+ if (niceName !== undefined) {
82
+ locations.handle = { niceName };
83
+ }
81
84
  return { type, locations, flags, niceName };
82
85
  }
83
86
  function parseLocationEncodingFilenameForBlock(filename, errorBuilder = shared_1.newWebpackErrorForFile) {
84
87
  const parsedFilename = parseLocationEncodingFilename(filename);
85
88
  if (parsedFilename !== undefined) {
86
- if ((0, shared_1.constantKeys)(parsedFilename.locations).some(value => value !== 'clientView' && value !== 'clientEditor')) {
89
+ const { handle, ...locations } = parsedFilename.locations;
90
+ if ((0, shared_1.constantKeys)(locations).some(value => value !== 'clientView' && value !== 'clientEditor')) {
87
91
  throw errorBuilder(`Block assets cannot be enqueued anywhere other than view, editor, or both. Saw: ${(0, shared_1.constantKeys)(parsedFilename).join(", ")}`, filename);
88
92
  }
89
- if (Object.values(parsedFilename.locations).some(value => typeof value === 'number')) {
93
+ if (Object.values(locations).some(value => typeof value === 'number')) {
90
94
  throw errorBuilder(`Block assets cannot be enqueued with a priority`, filename);
91
95
  }
96
+ return { ...parsedFilename, handle, locations };
92
97
  }
93
98
  return parsedFilename;
94
99
  }
@@ -1,5 +1,5 @@
1
1
  import type { Compilation } from "webpack";
2
- import { type InlinedAsset, type PathQueryParameters, type ScriptArgsObject } from "../shared";
2
+ import { type InlinedAsset, type PathQueryParameters, type ScriptArgsObject, type UsageLocations } from "../shared";
3
3
  export declare function getAssetFileContents(compilation: Compilation, name: string): string;
4
4
  export declare function unpackPotentiallyPrefixedFilePath(filePath: string): [string, PathQueryParameters | undefined];
5
5
  /**
@@ -39,7 +39,7 @@ export type NormalizedEnqueuingControlFlags = {
39
39
  export declare function mergeTwoEnqueuingControlFlagSets(file: string, ...argsBlocks: (NormalizedEnqueuingControlFlags | undefined)[]): NormalizedEnqueuingControlFlags | undefined;
40
40
  export declare function unpackEnqueuingControlFlagsFromPathQueryParameters(pathQueryParameters: PathQueryParameters | undefined, file: string, sourceType: 'registerScriptArgs' | 'path query parameters'): {
41
41
  flags?: NormalizedEnqueuingControlFlags;
42
- handle?: string;
42
+ handle?: UsageLocations['handle'];
43
43
  remainder?: PathQueryParameters;
44
44
  };
45
45
  /**
@@ -216,7 +216,7 @@ function buildVerifiedConfig(config) {
216
216
  const { flags: queryEnqueuingFlags, remainder: pathQueryParameters } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(rawPathQueryParameters, rawSource[0], 'path query parameters');
217
217
  const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(rawSource[0], rawEnqueuingFlags, queryEnqueuingFlags);
218
218
  const normalizedParts = { additionalDependencies, assumeGlobalizedPlauditLibraries, bundleAnalyzer, directoryLayout, externalize, withLegacyBlocksIn, lazyLoader };
219
- const locations = typeof rawSource[1].locations === 'string' || typeof rawSource[1].locations === 'function'
219
+ const locations = typeof rawSource[1].locations === 'string' || typeof rawSource[1].locations === 'function' || (rawSource[1].locations && 'niceName' in rawSource[1].locations)
220
220
  ? { handle: rawSource[1].locations } : rawSource[1].locations ?? {};
221
221
  if (typeof locations.registerScriptArgs === 'string' && !['lazy', 'eager', 'inline'].includes(locations.registerScriptArgs)) {
222
222
  throw new ReferenceError("The only supported string values for registerScriptArgs are 'lazy', 'eager', and 'inline'");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "3.11.0",
3
+ "version": "3.12.1",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/dist",
@@ -48,7 +48,7 @@
48
48
  "@plaudit/postcss-variables": "^2.0.1",
49
49
  "@wordpress/dependency-extraction-webpack-plugin": "^6.48.1",
50
50
  "@wordpress/scripts": "^32.4.1",
51
- "autoprefixer": "^10.5.0",
51
+ "autoprefixer": "^10.5.1",
52
52
  "browser-sync": "^3.0.4",
53
53
  "copy-webpack-plugin": "10.2.4",
54
54
  "css-minimizer-webpack-plugin": "^8.0.0",