@plaudit/webpack-extensions 3.12.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 +4 -0
- package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +2 -2
- package/dist/shared.d.ts +5 -2
- package/dist/shared.js +32 -3
- package/dist/utils/common-config-helpers.js +21 -9
- package/dist/utils/location-encoding-filename-parser.d.ts +9 -4
- package/dist/utils/location-encoding-filename-parser.js +5 -6
- package/dist/wordpress-scripts-wrapper.js +1 -1
- package/package.json +1 -1
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.12.1] - 2026-06-23
|
|
9
|
+
### Fixed
|
|
10
|
+
- The nice name handling not working for blocks
|
|
11
|
+
|
|
8
12
|
## [3.12.0] - 2026-06-23
|
|
9
13
|
### Added
|
|
10
14
|
- Logic to treat the nice name of a file as the suffix of its handle
|
|
@@ -44,12 +44,12 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
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
46
|
const handleNameMap = usedHandleNames[type];
|
|
47
|
-
const baseFinalHandleName = finalHandleName =
|
|
47
|
+
const baseFinalHandleName = finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)({ niceName: (0, shared_1.kebabCase)(cleanBasename) }, handlePrefix, cleanBasename);
|
|
48
48
|
for (let count = 0; finalHandleName in handleNameMap && handleNameMap[finalHandleName] !== src;) {
|
|
49
49
|
finalHandleName = `${baseFinalHandleName}-${++count}`;
|
|
50
50
|
}
|
|
51
51
|
if (typeof handleName === 'string' || typeof handleName === 'function') {
|
|
52
|
-
finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, finalHandleName);
|
|
52
|
+
finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, handlePrefix, finalHandleName.substring(handlePrefix.length + 1));
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
handleNameMap[finalHandleName] = src;
|
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'],
|
|
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,
|
|
147
|
-
|
|
148
|
-
|
|
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)
|
|
@@ -46,7 +46,7 @@ function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
|
|
|
46
46
|
entrypointField,
|
|
47
47
|
originalValue: ep,
|
|
48
48
|
entrypointName: parsedEntrypoint.name,
|
|
49
|
-
handle: (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handle ?? 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
|
|
223
|
+
handle
|
|
223
224
|
});
|
|
224
225
|
}
|
|
225
226
|
const entrypointNamesWithEffectiveDuplicates = presentEntrypoints
|
|
@@ -243,17 +244,27 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
243
244
|
.map(presentEntrypoint => {
|
|
244
245
|
const overallSource = (0, node_path_1.dirname)(blockJsonOrigin);
|
|
245
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))));
|
|
246
|
-
const handleSuffix = (0, shared_1.
|
|
247
|
+
const handleSuffix = (0, shared_1.convertUsageLocationsHandleToEmittableHandleSuffix)(dest.locations.handle, overallSourceRelativeName);
|
|
247
248
|
const handleGroup = (0, shared_1.getHandleGroup)(presentEntrypoint.entrypointField);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
let explicitlySetHandle;
|
|
250
|
+
if (presentEntrypoint.handle) {
|
|
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
|
+
}
|
|
252
260
|
if (explicitlySetHandle.length < 5) {
|
|
253
261
|
throw (0, shared_1.newWebpackErrorForFile)(`The handle was invalid. Received: ${explicitlySetHandle}. Expected: a string that is at least 5 characters long`, overallSourceRelativeName);
|
|
254
262
|
}
|
|
255
263
|
(seenExplicitHandles[handleGroup][explicitlySetHandle] ??= []).push(overallSource);
|
|
256
264
|
}
|
|
265
|
+
else {
|
|
266
|
+
explicitlySetHandle = undefined;
|
|
267
|
+
}
|
|
257
268
|
if (!entrypointNamesWithEffectiveDuplicates[presentEntrypoint.entrypointName]) {
|
|
258
269
|
return { blockJsonOrigin, ...presentEntrypoint, handle: explicitlySetHandle ?? `${handlePrefix}/${handleSuffix}`, dest, handleGroup };
|
|
259
270
|
}
|
|
@@ -270,7 +281,8 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
|
|
|
270
281
|
...presentEntrypoint,
|
|
271
282
|
entrypointName: deduplicatedEntrypointName,
|
|
272
283
|
extensionlessExpectedSrc: deduplicatedExtensionlessExpectedSrc,
|
|
273
|
-
handle: explicitlySetHandle ?? `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`,
|
|
284
|
+
handle: explicitlySetHandle ?? `${handlePrefix}/${count ? handleSuffix + "_" + count : handleSuffix}`,
|
|
285
|
+
handleGroup,
|
|
274
286
|
dest
|
|
275
287
|
};
|
|
276
288
|
});
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import { RealUsageLocations
|
|
1
|
+
import { RealUsageLocations } from "../shared";
|
|
2
2
|
import { NormalizedEnqueuingControlFlags } from "./path-query-and-related-helpers";
|
|
3
3
|
export type ParsedLocationEncodingFilename = {
|
|
4
4
|
type: 'script' | 'style' | 'script-module';
|
|
5
5
|
locations: RealUsageLocations & {
|
|
6
6
|
register?: boolean | number;
|
|
7
|
-
} &
|
|
7
|
+
} & {
|
|
8
|
+
handle?: {
|
|
9
|
+
niceName: string;
|
|
10
|
+
};
|
|
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
|
-
|
|
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
|
|
@@ -79,22 +79,21 @@ function parseLocationEncodingFilename(filename) {
|
|
|
79
79
|
return undefined;
|
|
80
80
|
}
|
|
81
81
|
if (niceName !== undefined) {
|
|
82
|
-
locations.handle =
|
|
83
|
-
const lastSlash = generatedHandle.lastIndexOf('/');
|
|
84
|
-
return (lastSlash > 0 ? generatedHandle.substring(0, lastSlash) : generatedHandle) + "/" + niceName;
|
|
85
|
-
};
|
|
82
|
+
locations.handle = { niceName };
|
|
86
83
|
}
|
|
87
84
|
return { type, locations, flags, niceName };
|
|
88
85
|
}
|
|
89
86
|
function parseLocationEncodingFilenameForBlock(filename, errorBuilder = shared_1.newWebpackErrorForFile) {
|
|
90
87
|
const parsedFilename = parseLocationEncodingFilename(filename);
|
|
91
88
|
if (parsedFilename !== undefined) {
|
|
92
|
-
|
|
89
|
+
const { handle, ...locations } = parsedFilename.locations;
|
|
90
|
+
if ((0, shared_1.constantKeys)(locations).some(value => value !== 'clientView' && value !== 'clientEditor')) {
|
|
93
91
|
throw errorBuilder(`Block assets cannot be enqueued anywhere other than view, editor, or both. Saw: ${(0, shared_1.constantKeys)(parsedFilename).join(", ")}`, filename);
|
|
94
92
|
}
|
|
95
|
-
if (Object.values(
|
|
93
|
+
if (Object.values(locations).some(value => typeof value === 'number')) {
|
|
96
94
|
throw errorBuilder(`Block assets cannot be enqueued with a priority`, filename);
|
|
97
95
|
}
|
|
96
|
+
return { ...parsedFilename, handle, locations };
|
|
98
97
|
}
|
|
99
98
|
return parsedFilename;
|
|
100
99
|
}
|
|
@@ -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'");
|