@plaudit/webpack-extensions 2.82.2 → 2.83.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 ADDED
@@ -0,0 +1,478 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.83.0] - 2026-01-20
9
+ ### Added
10
+ - Support for `hook_name` condition to the `admin` location for plain entrypoints
11
+
12
+ ## [2.82.3] - 2026-01-07
13
+ ### Fixed
14
+ - ESM module *files* in script attributes not being processed
15
+
16
+ ## [2.82.2] - 2026-01-06
17
+ ### Fixed
18
+ - Additional issues in how WordPress handles ESM modules
19
+ - CSS generated from module files getting put in `styleModule` instead of `style`
20
+
21
+ ### Removed
22
+ - Support for the `scriptModule` field because it turns out that that isn't a thing
23
+
24
+ ## [2.82.1] - 2026-01-06
25
+ ### Fixed
26
+ - The modules mode being dropped even when building with module support
27
+
28
+ ## [2.82.0] - 2025-12-29
29
+ ### Added
30
+ - The `onlyRunPostCSSOnPCSS` flag to allow for PostCSS processing to be disabled for `.css` files
31
+ - The [`CSSMinimizerPlugin`](https://github.com/webpack/css-minimizer-webpack-plugin)
32
+
33
+ ## [2.81.0] - 2025-12-24
34
+ ### Removed
35
+ - The old absolute-path enforcement logic now that our local dev Docker images no longer need it
36
+
37
+ ## [2.80.1] - 2025-12-19
38
+ ### Fixed
39
+ - The `google.maps` "externalizable" library causing a crash due to not being fully real
40
+
41
+ ## [2.80.0] - 2025-12-18
42
+ ### Added
43
+ - `google.maps` as an "externalizable" library
44
+ - Technically, there's nothing there to externalize per-se; however, it *does* need to be associated with a handle, which is part of the externalization process
45
+
46
+ ## [2.79.0] - 2025-12-17
47
+ ### Added
48
+ - A flag to disable the `-dev` features: `omitDistDev`
49
+ - This is pretty much for Josh's use only
50
+
51
+ ## [2.78.1] - 2025-12-17
52
+ ### Added
53
+ - Code to handle a missing `dist` directory when building for dev
54
+
55
+ ## [2.78.0] - 2025-12-16
56
+ ### Added
57
+ - Logic that separates out dev and prod builds
58
+ - Credit to David for the idea and pseudocode
59
+ - `'lazy'` as an alias for `{strategy: 'defer', in_footer: true}`
60
+ - An improved [User Guide](USER-GUIDE.md)
61
+ - Credit to David for the initial draft, structure, and ideal inclusions list
62
+
63
+ ## [2.77.0] - 2025-12-11
64
+ ### Added
65
+ - `@plaudit/wp-consent-api` to the list of externalizable packages
66
+ - `@plaudit/analytics-integrations-api` to the list of externalizable packages
67
+
68
+ ## [2.76.2] - 2025-12-05
69
+ ### Fixed
70
+ - Excess `.asset.php` files being emitted
71
+
72
+ ## [2.76.1] - 2025-12-05
73
+ ### Fixed
74
+ - The computed version-hashes not being emitted when in plain entrypoints v1 mode
75
+
76
+ ## [2.76.0] - 2025-12-05
77
+ ### Added
78
+ - Proper version-hash computation for stylesheets
79
+ - This replaces other long-standing attempts at accounting for WordPress's broken computation method
80
+
81
+ ## [2.75.0] - 2025-12-01
82
+ ### Added
83
+ - The ability to exclude blocks from the build by prefixing their folder with a tilde (`~`)
84
+
85
+ ## [2.74.0] - 2025-11-26
86
+ ### Added
87
+ - Support for WordPress 6.9's upcoming `fetchpriority` flag on scripts and styles
88
+
89
+ ## [2.73.2] - 2025-11-13
90
+ ### Fixed
91
+ - A compatibility issue with WPML that broke blocks on non-default-language pages
92
+ - Credit to Melanie for the report
93
+ - The extensions v1 generator saving the path to generated CSS files with the ".js" extension
94
+ - Credit to Melanie for the report
95
+
96
+ ## [2.73.1] - 2025-11-11
97
+ ### Fixed
98
+ - The styles enqueued via `clientEditor` being "enqueued" using WordPress' legacy `add_editor_style` mechanism
99
+
100
+ ## [2.73.0] - 2025-10-30
101
+ ### Added
102
+ - The function used to find legacy blocks in a folder to the `@plaudit/webpack-extensions/shared` export
103
+ - This is for use by `@plaudit/scaffold`
104
+
105
+ ## [2.72.1] - 2025-10-29
106
+ ### Fixed
107
+ - The wrapper being unable to find the `DependencyExtractionWebpackPlugin` due to version desyncs
108
+ - This isn't so much a "fix" as it is a "mitigation" - version desyncs are not fixable at the library level
109
+
110
+ ## [2.72.0] - 2025-10-13
111
+ ### Changed
112
+ - Extracted the PHP writing utilities into their own package.
113
+
114
+ ## [2.71.0] - 2025-10-10
115
+ ### Added
116
+ - Support for the `lazyLoader` attribute to `PlainEntrypointsStyleBlockJSONPlugin`
117
+
118
+ ### Changed
119
+ - The default value of `includePostInitFallback` to `false`
120
+ - This was originally a stopgap measure to prevent issues when plaudit-common's asset loader was triggered too late, but that has since been fixed at a
121
+ structural level, so, we can safely make it default to `false`
122
+
123
+ ## [2.70.1] - 2025-10-09
124
+ ### Added
125
+ - `shared.ts` to the exports list
126
+
127
+ ## [2.70.0] - 2025-10-01
128
+ ### Added
129
+ - `includePostInitFallback` to the config
130
+
131
+ ### Changed
132
+ - Reverted everything from version `2.69.0` except for renaming `plainEntrypointsHandlePrefix` to `targetHandlePrefix`
133
+
134
+ ## [2.69.0] - 2025-09-30
135
+ ### Added
136
+ - `plainEntrypointsSettings` to the config
137
+ - `plainEntrypointsSettings.includePostInitFallback` to allow emitting a fallback for the loader being called too late to be opted out of
138
+
139
+ ### Changed
140
+ - Renamed `plainEntrypointsHandlePrefix` to `targetHandlePrefix` because it's not just being used for `Plain Entrypoints`
141
+ - The old name of the setting will still work
142
+ - Moved `plainEntrypointsVersion` to `plainEntrypointsSettings.version`
143
+ - The old name of the setting will still work
144
+
145
+ ## [2.68.1] - 2025-09-24
146
+ ### Internals
147
+ - Reworked how the enqueuing location data is stored to make editing it easier in the future
148
+
149
+ ## [2.68.0] - 2025-09-24
150
+ ### Added
151
+ - Support for enqueuing plain entrypoints within the `enqueue_block_assets` action via the `blockAssets` location
152
+
153
+ ## [2.67.0] - 2025-09-23
154
+ ### Removed
155
+ - `postcss-fallback`, `postcss-inline-svg`, and `postcss-quantity-queries`
156
+ - They weren't being used but were causing dependency graph issues
157
+
158
+ ## [2.66.6] - 2025-09-18
159
+ ### Fixed
160
+ - Handles for extracted assets inheriting dependencies of the entrypoint from which they were extracted
161
+
162
+ ## [2.66.5] - 2025-09-17
163
+ ### Fixed
164
+ - Handle deduplication not accounting for extracted files in `PlainEntrypointsStyleBlockJSONPlugin`
165
+
166
+ ### Changed
167
+ - Replaced a `trailingslashit` call in the generated `Extensions V3` loader with `.'/'`
168
+
169
+ ## [2.66.4] - 2025-09-15
170
+ ### Fixed
171
+ - `*-setup.php` files causing a fatal error in `Extensions V3`
172
+
173
+ ## [2.66.3] - 2025-09-11
174
+ ### Fixed
175
+ - The `lazyLoad` attribute not being respected
176
+
177
+ ## [2.66.2] - 2025-09-11
178
+ ### Removed
179
+ - An unnecessary variable allocation from the emitted `Extensions V3` code
180
+
181
+ ## [2.66.1] - 2025-09-11
182
+ ### Removed
183
+ - An unnecessary suffixing of `__DIR__` in the `Extensions V3` emitter
184
+
185
+ ## [2.66.0] - 2025-09-11
186
+ ### Added
187
+ - Support for `Extensions V3`
188
+ - This resolves some handle consistency issues that V2 had
189
+ - `Extensions V3` is an automatic upgrade as a result
190
+
191
+ ### Fixed
192
+ - Handle consistency issues in `Extensions V2`
193
+
194
+ ## [2.65.3] - 2025-09-08
195
+ ### Fixed
196
+ - `Plain Entrypoints` not getting their proper handle prefix
197
+
198
+ ### Added
199
+ - Standardized functions for `require` and `include` to `PHPWriter`
200
+
201
+ ## [2.65.2] - 2025-09-04
202
+ ### Fixed
203
+ - `block.json` files causing `block.asset.php` files to be emitted
204
+
205
+ ## [2.65.1] - 2025-09-04
206
+ ### Fixed
207
+ - Lingering issues in the dependency extractor
208
+ - Random `.asset.php` files being output when they should not have been
209
+
210
+ ### Internals
211
+ - Removed the need to split builds on `additionalDependencies`
212
+
213
+ ## [2.65.0] - 2025-09-03
214
+ ### Added
215
+ - Full backwards compatibility
216
+ - Multi-source support for `Extensions`
217
+
218
+ ### Internals
219
+ - Refactored almost every plugin to eliminate as much duplicated code as I could.
220
+ - Massively cleaned up the logic
221
+
222
+ ## [2.64.0] - 2025-09-03
223
+ ### Added
224
+ - Proper monobuild support!
225
+
226
+ ### Internals
227
+ - Fundamentally changed how we load entrypoints and batch builds. This should vastly reduce build times.
228
+ - Refactored most of the plugins to share more code
229
+
230
+ ## [2.63.2] - 2025-09-03
231
+ ### Fixed
232
+ - Builds being self-deleting
233
+ - WordPress switched to a different way of handling cleaning
234
+
235
+ ## [2.63.1] - 2025-09-03
236
+ ### Fixed
237
+ - Builds not working
238
+ - This is a horrible and hastily-thrown-together version of the monobuild prototype. The entire implementation is subject to change.
239
+
240
+ ## [2.63.0] - 2025-09-03
241
+ ### Added
242
+ - The ability to dynamically load extensions
243
+ - This is done by setting the `locations` property to a string, which, in turn, will be used to name a function that contains the extensions loader code
244
+ - An initial version of dynamic handle names for Plain Entrypoints
245
+
246
+ ### Internals
247
+ - Made further improvements to `PHPWriter`
248
+ - Made a bit more progress on working out how to get monobuilds working
249
+
250
+ ## [2.62.3] - 2025-09-01
251
+ ### Fixed
252
+ - A missed case in the validation for the `Assignment` expression in `php-writer.ts`
253
+
254
+ ## [2.62.2] - 2025-09-01
255
+ ### Fixed
256
+ - An issue caused by returning an Iterator instead of an Iterable
257
+
258
+ ## [2.62.1] - 2025-09-01
259
+ ### Fixed
260
+ - A couple of minor teething issues with the new logic
261
+
262
+ ### Internals
263
+ - Did a massive refactor of `PHPWriter` to make it more flexible
264
+ - This was entirely for fun, so it doesn't count as a "feature"
265
+ - Started refactoring plugins to share code
266
+ - This is in prep for Monobuild support
267
+
268
+ ## [2.62.0] - 2025-08-31
269
+ ### Added
270
+ - Proper script module support in Extension- and Plain Entrypoint-style outputs
271
+
272
+ ### Changed
273
+ - Rewrote `BlockJsonManagingPlugin` to use proper WebPack features instead of crazy hacks
274
+ - Updated the Blocks loader to emit a call to `BlockManager::autoloadSubfoldersV3()`
275
+ - This requires `plaudit-common` version `2.24.0` or higher
276
+
277
+ ### Fixed
278
+ - Module scripts being included improperly when included a directory in Plain Entrypoints mode
279
+
280
+ ## [2.61.2] - 2025-08-28
281
+ ### Removed
282
+ - An unnecessary `accountForAlreadyDoing` flag from the code generated by `SpecialAssetHandlingPlugin`
283
+
284
+ ## [2.61.1] - 2025-08-28
285
+ ### Fixed
286
+ - Legacy Blocks not loading properly
287
+
288
+ ## [2.61.0] - 2025-08-26
289
+ ### Changed
290
+ - `ExtensionsConfigFileGeneratorPlugin` to use plaudit-common's `GutenbergUtils` instead of plaudit-base's `ThemeUtils` for registering extensions
291
+
292
+ ## [2.60.2] - 2025-08-26
293
+ ### Fixed
294
+ - `use` declarations being emitted by `PHPWriter`s in subwriter mode
295
+
296
+ ## [2.60.1] - 2025-08-25
297
+ ### Changed
298
+ - All `init` hooks emitted as part of the generated loader code to check for whether they're already in an init hook
299
+ - Made some crazy improvements to `PHPWriter`
300
+
301
+ ## [2.60.0] - 2025-08-25
302
+ ### Added
303
+ - Support for using `DEV_TARGET` to further filter whether the BrowserSync plugin should be started
304
+ - This is intended to make recursive commands a viable option
305
+
306
+ ### Removed
307
+ - `CleanWebpackPlugin` because it was significantly more trouble than it was ever worth
308
+
309
+ ### Changed
310
+ - Started refactoring some of the plugins to better-match the pattern that WebPack expects plugins to follow
311
+
312
+ ## [2.59.0] - 2025-08-22
313
+ ### Changed
314
+ - Replaced a lingering dependence on `theapp` within the `BrowserSyncPlugin` with some code that does the same basic thing
315
+
316
+ ## [2.58.4] - 2025-08-21
317
+ ### Fixed
318
+ - Unnecessary emission of the `plaudit_webpack_extensions__resolve_base_uri` function in the `Unified Loader`
319
+ - This doesn't actually cause any problems - I just disliked seeing it emitted unnecessarily
320
+
321
+ ## [2.58.3] - 2025-08-20
322
+ ### Changed
323
+ - The `return` method in `PHPWriter` to handle its argument as a php value instead of as formatted code
324
+ ### Fixed
325
+ - A race condition in the `ExtensionsConfigFileGeneratorPlugin`
326
+
327
+ ## [2.58.2] - 2025-08-15
328
+ ### Changed
329
+ - Reworked how postprocessing pipelines are implemented to avoid some of the async hackery that I've previously used
330
+ - This is in prep for a total rewrite of the block.json handling logic
331
+
332
+ ## [2.58.1] - 2025-08-14
333
+ ### Added
334
+ - Automatic variable unsetting via "scope"s to PHPWriter
335
+ - I added this entirely for fun
336
+
337
+ ## [2.58.0] - 2025-08-13
338
+ ### Added
339
+ - The ability to specify the handle for manually-enqueued scripts by setting the location property to a string
340
+
341
+ ## [2.57.3] - 2025-08-13
342
+ ### Removed
343
+ - A whole `trailingslashit` call from the `Unified Loader` code!
344
+ - This is a comically pointless micro-optimization
345
+
346
+ ## [2.57.2] - 2025-08-12
347
+ ### Fixed
348
+ - An incorrect default value
349
+
350
+ ## [2.57.1] - 2025-08-12
351
+ ### Changed
352
+ - Made the unified loader opt-in in order to avoid a ton of duplicated code
353
+
354
+ ## [2.57.0] - 2025-08-12
355
+ ### Added
356
+ - Unified Loader Generation
357
+ - At last, users are free from having to load each output type!
358
+ - Automatic computation of the `plainEntrypointsHandlePrefix` setting
359
+ - The prefixes were just the kebab'd plugin or theme names, so automatically grabbing those removes some unnecessary config burden from the user
360
+
361
+ ## [2.56.4] - 2025-08-08
362
+ ### Fixed
363
+ - A bug that caused all plain entrypoint scripts to processed be regardless of module-ness
364
+
365
+ ## [2.56.3] - 2025-08-07
366
+ ### Fixed
367
+ - The generation logic for `plaudit_webpack_extensions__resolve_base_uri` not taking the lack of namespaces into account
368
+
369
+ ## [2.56.2] - 2025-08-06
370
+ ### Changed
371
+ - Removed a now-unnecessary sorting step in `PseudoSemaphore`
372
+
373
+ ## [2.56.1] - 2025-08-06
374
+ ### Fixed
375
+ - The Automatic Destination Calculator adding the wrong handle suffixes for scripts and styles
376
+
377
+ ### Changed
378
+ - How generated handles are trimmed down to make them more aesthetically pleasing
379
+
380
+ ## [2.56.0] - 2025-08-06
381
+ ### Added
382
+ - Automatic Destination Calculation for all Entrypoints
383
+ - Requires Plain Entrypoints V2 for Plain Entrypoints
384
+ - Works best in projects that have a single root src directory
385
+ - In short, this means that the destination property is optional
386
+ - The `srcPrefixes` config property
387
+ - Allows Automatic Destination Calculation to be used in projects that have multiple source roots
388
+ - Support for `true` as a valid value for src that have an entirely-derived configuration
389
+
390
+ ## [2.55.1] - 2025-08-06
391
+ ### Fixed
392
+ - Unnecessary newlines being added by PHPWriter
393
+
394
+ ## [2.55.0] - 2025-08-04
395
+ ### Added
396
+ - Plain Entrypoints V2
397
+ - This feature removes the need to enqueue scripts and styles separately from their build declarations
398
+ - It requires `outputDir` and `plainEntrypointsHandlePrefix` to be set
399
+ - It requires modifications to the current theme, so it's not a drop-in upgrade
400
+ - `plainEntrypointsVersion` to the root config object. It can be either 1 or 2 (default: 1)
401
+ - `plainEntrypointsHandlePrefix` to the root config object
402
+
403
+ ## [2.54.0] - 2025-07-26
404
+ ### Added
405
+ - Block Extensions V2
406
+ - This has the same feature set as Block Extensions V1, but uses the "single-file" output that BlockJSON V3 uses
407
+ - This is entirely for performance reasons. From a features perspective, there should not be any outward difference
408
+ - Requires `plaudit-base` version 2.98.0 or higher
409
+ - `extensionsVersion` to the root config object. It can be either 1 or 2 (default: 1)
410
+
411
+ ### Changed
412
+ - Refactored the synchronization logic used in `BlockJSONManagingPlugin` into its own class
413
+
414
+ ## [2.53.1] - 2025-07-25
415
+ ### Fixed
416
+ - Updated the PNPM overrides to fix a build error
417
+
418
+ ## [2.53.0] - 2025-07-25
419
+ ### Changed
420
+ - Files prefixed with `~` in the extensions directory are excluded from the build
421
+
422
+ ## [2.52.1] - 2025-06-20
423
+ ### Fixed
424
+ - Hid excessive "asset too large" warnings for incompressible assets
425
+
426
+ ## [2.52.0] - 2025-06-11
427
+ ### Added
428
+ - Support for inlining SVGs in PCSS files
429
+
430
+ ## [2.51.0] - 2025-06-10
431
+ ### Added
432
+ - Support for running the `webpack-bundle-analyzer` on code
433
+
434
+ ## [2.50.0] - 2025-06-03
435
+ ### Added
436
+ - Checks for common conflicting config files
437
+ - Primarily: `postcss.config.js`, `babel-transform.js`, and Babel's config files
438
+
439
+ ### Changed
440
+ - Replaced all default exports with standard ones for consistency
441
+
442
+ ## [2.49.0] - 2025-05-20
443
+ ### Added
444
+ - The `@plaudit/block-supports` library to the externalizable libraries list
445
+
446
+ ## [2.48.0] - 2025-05-19
447
+ ### Added
448
+ - Support for generating `<link>` tags from preload and fetchPriority parameters in asset references.
449
+ - This feature requires `useWebpackResourceFiltering` to be set to `true`
450
+ - A flag to switch to using Webpack's native handling for all assets regardless of whether the path starts with a "/"
451
+ - The flag is `useWebpackResourceFiltering`. It defaults to `false`
452
+
453
+ ## [2.47.0] - 2025-05-16
454
+ ### Added
455
+ - Support for externalizing non-plaudit libraries.
456
+ - Automatic detection of whether a library is currently being externalized (this prevents infinite loops in the generated dependency list)
457
+
458
+ ### Fixed
459
+ - Corrected the readme
460
+
461
+ ## [2.46.0] - 2025-05-15
462
+ ### Added
463
+ - This changelog
464
+
465
+ ### Changed
466
+ - Made the handle-generation code for Blocks include the block's full name in the handle instead of its folder name
467
+ - Switched to using a shared publishing script
468
+
469
+ ### Removed
470
+ - The old project-specific deployment script
471
+
472
+ ## [2.45.1] - 2025-04-30
473
+ ### Fixed
474
+ - Resolved the "extensions" module including the phantom JS files generated by "MiniCssExtractPlugin" in the "mapping.config" file.
475
+
476
+ ## [2.45.0] - 2025-04-22
477
+ ### Changed
478
+ - Upgraded to PostCSS-8-compatible versions of shorthand plugins.
@@ -13,6 +13,12 @@ export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractB
13
13
  private static addHandlesToHandleLists;
14
14
  private static appendEnqueuingHandleLists;
15
15
  private static separateHandleListByPriority;
16
+ /**
17
+ * This is used to allow scripts and styles to be grouped based on hook_name for the admin handle
18
+ * @param handleItems
19
+ * @private
20
+ */
21
+ private static separateHandleListByHookName;
16
22
  protected attachUniquePhase(compilation: Compilation): void;
17
23
  protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
18
24
  }
@@ -93,25 +93,70 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
93
93
  (0, shared_1.emitPHPWriterAsAsset)(writer, compilation, "plain-entrypoints-loader.php");
94
94
  }
95
95
  static addHandlesToHandleLists(type, handles, handleLists) {
96
+ const defaultPriority = 10;
96
97
  for (const [handle, data] of handles) {
97
98
  if (data.locations.register !== false) {
98
99
  handleLists.register.push({ handle, type, data, priority: typeof data.locations.register === 'number' ? data.locations.register : 10 });
99
100
  }
100
101
  for (const location of (0, shared_1.constantKeys)(shared_1.standardLocationNamesMeta)) {
101
- if (typeof data.locations[location] === 'number') {
102
- handleLists[location].push({ handle, type, priority: data.locations[location] });
102
+ let priority, hook_name;
103
+ const dataLocation = data.locations[location];
104
+ if (typeof dataLocation === 'number') {
105
+ priority = dataLocation;
106
+ hook_name = undefined;
103
107
  }
104
- else if (data.locations[location]) {
105
- handleLists[location].push({ handle, type, priority: 10 });
108
+ else if (dataLocation) {
109
+ if (typeof dataLocation === 'string') {
110
+ priority = defaultPriority;
111
+ hook_name = dataLocation;
112
+ }
113
+ else if (Array.isArray(dataLocation)) {
114
+ if (!(0, shared_1.hasAtLeastOneItem)(dataLocation)) {
115
+ continue;
116
+ }
117
+ priority = defaultPriority;
118
+ hook_name = dataLocation;
119
+ }
120
+ else if (typeof dataLocation === 'object') {
121
+ priority = dataLocation.priority ?? defaultPriority;
122
+ hook_name = Array.isArray(dataLocation.hook_name)
123
+ ? (0, shared_1.hasAtLeastOneItem)(dataLocation.hook_name) ? dataLocation.hook_name : undefined
124
+ : dataLocation.hook_name ? dataLocation.hook_name : undefined;
125
+ }
126
+ else {
127
+ priority = defaultPriority;
128
+ hook_name = undefined;
129
+ }
106
130
  }
131
+ else {
132
+ continue;
133
+ }
134
+ handleLists[location].push({ handle, type, priority, hook_name });
107
135
  }
108
136
  }
109
137
  }
110
138
  static appendEnqueuingHandleLists(writer, handleLists) {
111
- const enqueuingHandleActions = (0, shared_1.constantEntries)(shared_1.standardLocationNamesMeta).map(([sln, { action }]) => [action, handleLists[sln]]);
112
- for (const [action, handleList] of enqueuingHandleActions) {
139
+ const enqueuingHandleActions = (0, shared_1.constantEntries)(shared_1.standardLocationNamesMeta)
140
+ .map(([sln, { action, supports_hook_name }]) => [action, [handleLists[sln], supports_hook_name]]);
141
+ for (const [action, [handleList, supports_hook_name]] of enqueuingHandleActions) {
113
142
  if (handleList.length > 0) {
114
143
  for (const [priority, prioritizedHandleList] of PlainEntrypointsConfigFileGeneratorPlugin.separateHandleListByPriority(handleList)) {
144
+ if (supports_hook_name) {
145
+ const hookNamedHandleLists = PlainEntrypointsConfigFileGeneratorPlugin.separateHandleListByHookName(prioritizedHandleList);
146
+ if (!(0, shared_1.arrayIsLength)(hookNamedHandleLists, 1) || hookNamedHandleLists[0][0] !== "") {
147
+ const hook_name_var = new expressions_1.Var("hook_name", "?string");
148
+ writer.action(action, writer => {
149
+ for (const [hook_name, handles] of hookNamedHandleLists) {
150
+ writer.if(expressions_1.Op.binary(hook_name_var, " === ", hook_name));
151
+ for (const handle of handles) {
152
+ writer.call(`wp_enqueue_${handle.type}`, [handle.handle]);
153
+ }
154
+ writer.endIf();
155
+ }
156
+ }, { priority, functionArgParameters: [hook_name_var] });
157
+ continue;
158
+ }
159
+ }
115
160
  writer.action(action, writer => {
116
161
  for (const handle of prioritizedHandleList) {
117
162
  writer.call(`wp_enqueue_${handle.type}`, [handle.handle]);
@@ -134,6 +179,35 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
134
179
  }
135
180
  return lists.entries().toArray().sort((a, b) => a[0] - b[0]);
136
181
  }
182
+ /**
183
+ * This is used to allow scripts and styles to be grouped based on hook_name for the admin handle
184
+ * @param handleItems
185
+ * @private
186
+ */
187
+ static separateHandleListByHookName(handleItems) {
188
+ const lists = new Map();
189
+ for (const handleItem of handleItems) {
190
+ const hook_name = handleItem.hook_name ?? "";
191
+ for (const hn of Array.isArray(hook_name) ? hook_name : [hook_name]) {
192
+ const list = lists.get(hn);
193
+ if (list) {
194
+ list.push(handleItem);
195
+ }
196
+ else {
197
+ lists.set(hn, [handleItem]);
198
+ }
199
+ }
200
+ }
201
+ return lists.entries().toArray().sort((a, b) => {
202
+ if (a[0] === "") {
203
+ return b[0] === "" ? 0 : -1;
204
+ }
205
+ else if (b[0] === "") {
206
+ return 1;
207
+ }
208
+ return a[0].localeCompare(b[0]);
209
+ });
210
+ }
137
211
  attachUniquePhase(compilation) {
138
212
  compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
139
213
  this.generatePlainEntrypointsLoader(compilation, (await PlainEntrypointsConfigFileGeneratorPlugin.semaphore.wait()).flat());
package/build/shared.d.ts CHANGED
@@ -19,29 +19,40 @@ export type HandleData = {
19
19
  export declare const standardLocationNamesMeta: {
20
20
  readonly clientView: {
21
21
  readonly action: "wp_enqueue_scripts";
22
+ readonly supports_hook_name: false;
22
23
  };
23
24
  readonly clientEditor: {
24
25
  readonly action: "enqueue_block_editor_assets";
26
+ readonly supports_hook_name: false;
25
27
  };
26
28
  readonly blockAssets: {
27
29
  readonly action: "enqueue_block_assets";
30
+ readonly supports_hook_name: false;
28
31
  };
29
32
  readonly admin: {
30
33
  readonly action: "admin_enqueue_scripts";
34
+ readonly supports_hook_name: true;
31
35
  };
32
36
  readonly login: {
33
37
  readonly action: "login_enqueue_scripts";
38
+ readonly supports_hook_name: false;
34
39
  };
35
40
  readonly customizer: {
36
41
  readonly action: "customize_controls_enqueue_scripts";
42
+ readonly supports_hook_name: false;
37
43
  };
38
44
  readonly analytics: {
39
45
  readonly action: "plaudit_enqueue_analytics";
46
+ readonly supports_hook_name: false;
40
47
  };
41
48
  };
42
49
  export type StandardLocationNames = keyof typeof standardLocationNamesMeta;
50
+ type LocationWithHookNameSupport = boolean | number | string | string[] | {
51
+ hook_name?: string | string[];
52
+ priority?: number;
53
+ };
43
54
  export type UsageLocations = {
44
- [K in StandardLocationNames]?: boolean | number;
55
+ [K in StandardLocationNames]?: typeof standardLocationNamesMeta[K]['supports_hook_name'] extends true ? LocationWithHookNameSupport : boolean | number;
45
56
  } & {
46
57
  register?: boolean | number;
47
58
  handle?: string | ((generatedHandle: string) => string);
package/build/shared.js CHANGED
@@ -49,9 +49,13 @@ function isParsedAssetsJson(thing) {
49
49
  return true;
50
50
  }
51
51
  exports.standardLocationNamesMeta = {
52
- clientView: { action: "wp_enqueue_scripts" }, clientEditor: { action: "enqueue_block_editor_assets" }, blockAssets: { action: "enqueue_block_assets" },
53
- admin: { action: "admin_enqueue_scripts" }, login: { action: "login_enqueue_scripts" }, customizer: { action: "customize_controls_enqueue_scripts" },
54
- analytics: { action: "plaudit_enqueue_analytics" }
52
+ clientView: { action: "wp_enqueue_scripts", supports_hook_name: false },
53
+ clientEditor: { action: "enqueue_block_editor_assets", supports_hook_name: false },
54
+ blockAssets: { action: "enqueue_block_assets", supports_hook_name: false },
55
+ admin: { action: "admin_enqueue_scripts", supports_hook_name: true },
56
+ login: { action: "login_enqueue_scripts", supports_hook_name: false },
57
+ customizer: { action: "customize_controls_enqueue_scripts", supports_hook_name: false },
58
+ analytics: { action: "plaudit_enqueue_analytics", supports_hook_name: false }
55
59
  };
56
60
  function isNormalizedUsageLocations(usageLocations) {
57
61
  return typeof usageLocations.registerScriptArgs !== 'string';
@@ -189,10 +193,9 @@ function getAssetsJson(compilation) {
189
193
  function getParsedAssetsJsonDataForEntrypoint(compilation, entrypoint, metadata) {
190
194
  const dest = metadata.dest;
191
195
  const parsedAssetJson = getAssetsJson(compilation);
192
- const scriptExtension = compilation.outputOptions.module ? exports.scriptWithModuleExtension : exports.scriptWithoutModuleExtension;
193
- const assetType = scriptOrStyleTest(metadata.absoluteSrc, scriptExtension);
196
+ const assetType = scriptOrStyleTest(metadata.absoluteSrc, exports.scriptExtension);
194
197
  const chunkFiles = [dest.destination, ...entrypoint.chunks.flatMap(chunk => Array.from(chunk.files))]
195
- .filter(chunkFile => scriptOrStyleTest(chunkFile, scriptExtension) === assetType);
198
+ .filter(chunkFile => scriptOrStyleTest(chunkFile, exports.scriptExtension) === assetType);
196
199
  for (const chunkFile of chunkFiles) {
197
200
  if (parsedAssetJson[chunkFile]) {
198
201
  return { assetName: chunkFile, assetData: parsedAssetJson[chunkFile] };
@@ -2,9 +2,9 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- const node_fs_1 = __importDefault(require("node:fs"));
6
- const promises_1 = __importDefault(require("node:fs/promises"));
7
- const node_path_1 = __importDefault(require("node:path"));
5
+ const node_fs_1 = require("node:fs");
6
+ const promises_1 = require("node:fs/promises");
7
+ const node_path_1 = require("node:path");
8
8
  const shared_1 = require("./shared");
9
9
  const common_config_helpers_1 = require("./utils/common-config-helpers");
10
10
  const AdditionalDependencyInjectorPlugin_1 = require("./plugins/AdditionalDependencyInjectorPlugin");
@@ -34,8 +34,8 @@ function testForDuplicatedEntryPaths(sources) {
34
34
  for (const sameNamePaths of seenPaths.values()) {
35
35
  if (sameNamePaths.length > 1) {
36
36
  if (projectPrefix === undefined) {
37
- for (let p = process.cwd(); p.length > 1; p = node_path_1.default.dirname(p)) {
38
- if (node_fs_1.default.existsSync(node_path_1.default.join(p, "docker-compose.yml"))) {
37
+ for (let p = process.cwd(); p.length > 1; p = (0, node_path_1.dirname)(p)) {
38
+ if ((0, node_fs_1.existsSync)((0, node_path_1.join)(p, "docker-compose.yml"))) {
39
39
  projectPrefix = new RegExp(`^${p}`);
40
40
  break;
41
41
  }
@@ -44,7 +44,7 @@ function testForDuplicatedEntryPaths(sources) {
44
44
  projectPrefix = /^/;
45
45
  }
46
46
  }
47
- duplicatedPaths += `\n* ${node_path_1.default.dirname(sameNamePaths[0]).replace(projectPrefix, '')}/[${sameNamePaths.map(p => node_path_1.default.basename(p)).join(', ')}]`;
47
+ duplicatedPaths += `\n* ${(0, node_path_1.dirname)(sameNamePaths[0]).replace(projectPrefix, '')}/[${sameNamePaths.map(p => (0, node_path_1.basename)(p)).join(', ')}]`;
48
48
  }
49
49
  }
50
50
  if (duplicatedPaths.length !== 0) {
@@ -190,11 +190,11 @@ function buildVerifiedConfig(config) {
190
190
  }
191
191
  const normalizeSrcAndDestination = ([src, dest]) => {
192
192
  if (srcDir) {
193
- src = node_path_1.default.join(srcDir, src);
193
+ src = (0, node_path_1.join)(srcDir, src);
194
194
  }
195
- src = node_path_1.default.isAbsolute(src) ? node_path_1.default.relative(process.cwd(), src) : src;
196
- if (dest.destination !== undefined && node_path_1.default.isAbsolute(dest.destination)) {
197
- dest = { ...dest, destination: node_path_1.default.relative(process.cwd(), dest.destination) };
195
+ src = (0, node_path_1.isAbsolute)(src) ? (0, node_path_1.relative)(process.cwd(), src) : src;
196
+ if (dest.destination !== undefined && (0, node_path_1.isAbsolute)(dest.destination)) {
197
+ dest = { ...dest, destination: (0, node_path_1.relative)(process.cwd(), dest.destination) };
198
198
  }
199
199
  return [src, dest];
200
200
  };
@@ -207,7 +207,7 @@ function buildVerifiedConfig(config) {
207
207
  let variablesFilePath = undefined;
208
208
  const currentVariables = rawVariables ?? {};
209
209
  if (!rawVariables) {
210
- variablesFilePath = ["variables.js", "src/site/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p))[0];
210
+ variablesFilePath = ["variables.js", "src/site/variables.js"].map(p => (0, node_path_1.join)(process.cwd(), p)).filter(p => (0, node_fs_1.existsSync)(p))[0];
211
211
  }
212
212
  let extensionsVersion = config.extensionsVersion ?? 1;
213
213
  if (extensionsVersion === 2) {
@@ -259,8 +259,8 @@ function buildVerifiedConfig(config) {
259
259
  return cfg.outputDir ? { cfg, sources } : withDerivedOutputDir(cfg, sources);
260
260
  }
261
261
  function toEffectiveWebpackDestination(destination) {
262
- const pathParts = node_path_1.default.parse(destination);
263
- return node_path_1.default.join(pathParts.dir, pathParts.name);
262
+ const pathParts = (0, node_path_1.parse)(destination);
263
+ return (0, node_path_1.join)(pathParts.dir, pathParts.name);
264
264
  }
265
265
  function deriveNaiveDestinationFromUnverifiedSourceEntry([src, { destination }], srcPrefixes) {
266
266
  if (destination !== undefined) {
@@ -289,7 +289,7 @@ function finalizeEntryDestination(entry, dynamicEffectiveDestinationsWithExpecte
289
289
  if (entry[1].staticallyDeclaredDestination) {
290
290
  return entry;
291
291
  }
292
- const extension = node_path_1.default.extname(entry[1].destination);
292
+ const extension = (0, node_path_1.extname)(entry[1].destination);
293
293
  const filename = dynamicEffectiveDestinationsWithExpectedNaiveDuplicates[entry[1].effectiveDestination]
294
294
  ? entry[1].effectiveDestination + (extension === '.css' ? "_style" : "_script")
295
295
  : entry[1].effectiveDestination;
@@ -308,7 +308,7 @@ function deriveDefaultHandlePrefixFromComposerJsonOrThemeName() {
308
308
  }
309
309
  let composerJson;
310
310
  try {
311
- composerJson = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(process.cwd(), "composer.json"), 'utf-8'));
311
+ composerJson = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(process.cwd(), "composer.json"), 'utf-8'));
312
312
  }
313
313
  catch {
314
314
  // Then composer.json doesn't exist
@@ -320,7 +320,7 @@ function deriveDefaultHandlePrefixFromComposerJsonOrThemeName() {
320
320
  return (0, shared_1.kebabCase)(composerJson.name.replace(/plaudit\/plaudit/, 'plaudit'));
321
321
  }
322
322
  function deriveDefaultHandlePrefixFromThemeName() {
323
- const styleFileContents = node_fs_1.default.readFileSync(node_path_1.default.join(process.cwd(), "style.css"), 'utf-8');
323
+ const styleFileContents = (0, node_fs_1.readFileSync)((0, node_path_1.join)(process.cwd(), "style.css"), 'utf-8');
324
324
  const themeName = /^\W*Theme\s*Name:\s*(.+)$/im.exec(styleFileContents)?.[1]?.trim();
325
325
  if (!themeName) {
326
326
  throw new ReferenceError("targetHandlePrefix was not set and the adjacent style.css file does not have a valid name in it");
@@ -348,8 +348,8 @@ function withDerivedOutputDir(cfg, sources) {
348
348
  function handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins) {
349
349
  if (process.env["NO_TS_CHECKER"] !== "true") {
350
350
  const include = (Array.isArray(srcRoot) ? srcRoot : [srcRoot])
351
- .filter(sr => node_path_1.default.extname(sr).length === 0 || (0, shared_1.scriptOrStyleTest)(sr, scriptExtension) === "script")
352
- .map(sr => node_path_1.default.extname(sr).length > 0 ? sr : node_path_1.default.join(sr, "**", "*"));
351
+ .filter(sr => (0, node_path_1.extname)(sr).length === 0 || (0, shared_1.scriptOrStyleTest)(sr, scriptExtension) === "script")
352
+ .map(sr => (0, node_path_1.extname)(sr).length > 0 ? sr : (0, node_path_1.join)(sr, "**", "*"));
353
353
  if (include.length > 0) {
354
354
  plugins.push(new fork_ts_checker_webpack_plugin_1.default({
355
355
  async: true,
@@ -482,10 +482,10 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
482
482
  const { processingModules, scriptExtension } = commonConfig;
483
483
  const allSrcRoots = sources.map(([src, dest]) => {
484
484
  const srcRoots = (dest.withLegacyBlocksIn
485
- ? [...src.split(','), ...(0, shared_1.resolveLegacyBlockScriptsInFolder)(node_path_1.default.join(config.srcDir, dest.withLegacyBlocksIn))]
485
+ ? [...src.split(','), ...(0, shared_1.resolveLegacyBlockScriptsInFolder)((0, node_path_1.join)(config.srcDir, dest.withLegacyBlocksIn))]
486
486
  : src.split(',')).filter(s => s.endsWith(".json") || !s.substring(s.lastIndexOf('/')).includes('.') || processingModules === shared_1.scriptWithModuleExtension.test(s));
487
487
  const srcRoot = srcRoots.length < 2 ? (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(process.cwd(), src) : srcRoots.map(s => (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(process.cwd(), s));
488
- const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot, { throwIfNoEntry: false })?.isDirectory();
488
+ const srcIsDirectory = !Array.isArray(srcRoot) && (0, node_fs_1.lstatSync)(srcRoot, { throwIfNoEntry: false })?.isDirectory();
489
489
  if (srcIsDirectory === undefined) {
490
490
  return undefined;
491
491
  }
@@ -521,11 +521,11 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
521
521
  }
522
522
  const entry = async () => {
523
523
  const rawEntrypoints = [];
524
- for await (const dirent of await promises_1.default.opendir(srcRoot)) {
524
+ for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
525
525
  if (dirent.isFile() && !dirent.name.startsWith("~")) {
526
526
  if (commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name)) {
527
527
  const absoluteSrc = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
528
- 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 } }]);
528
+ rawEntrypoints.push([(0, node_path_1.join)(dest.destination, (0, node_path_1.basename)(absoluteSrc, (0, node_path_1.extname)(absoluteSrc))), { import: [absoluteSrc], plauditMetadata: { dest, absoluteSrc } }]);
529
529
  }
530
530
  }
531
531
  }
@@ -580,7 +580,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
580
580
  }).filter(cfg => cfg !== undefined);
581
581
  }
582
582
  function stripExtension(filepath) {
583
- return node_path_1.default.join(node_path_1.default.dirname(filepath), node_path_1.default.basename(filepath, node_path_1.default.extname(filepath)));
583
+ return (0, node_path_1.join)((0, node_path_1.dirname)(filepath), (0, node_path_1.basename)(filepath, (0, node_path_1.extname)(filepath)));
584
584
  }
585
585
  module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
586
586
  const { cfg, sources } = buildVerifiedConfig(config);
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.82.2",
3
+ "version": "2.83.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
- "/build"
6
+ "/build",
7
+ "README.md",
8
+ "LICENSE.md",
9
+ "CHANGELOG.md"
7
10
  ],
8
11
  "exports": {
9
12
  "./wordpress-scripts-wrapper": "./build/wordpress-scripts-wrapper.js",
@@ -20,9 +23,9 @@
20
23
  }
21
24
  },
22
25
  "devDependencies": {
23
- "@plaudit/gutenberg-api-extensions": "^2.83.0",
26
+ "@plaudit/gutenberg-api-extensions": "^2.84.3",
24
27
  "@types/browser-sync-webpack-plugin": "^2.2.5",
25
- "@types/node": "^25.0.3",
28
+ "@types/node": "^25.0.9",
26
29
  "@types/postcss-functions": "^4.0.4",
27
30
  "@types/tapable": "^2.3.0",
28
31
  "@types/webpack": "^5.28.5",
@@ -33,14 +36,14 @@
33
36
  "webpack-bundle-analyzer": "^4.10.2"
34
37
  },
35
38
  "dependencies": {
36
- "@plaudit/php-writer": "^1.3.2",
39
+ "@plaudit/php-writer": "^1.3.3",
37
40
  "@plaudit/postcss-color-function": "^5.0.0",
38
41
  "@plaudit/postcss-legacy-shorthand": "^1.0.0",
39
42
  "@plaudit/postcss-silent-extend": "^3.0.0",
40
43
  "@plaudit/postcss-strip-units": "^3.0.0",
41
44
  "@plaudit/postcss-variables": "^1.1.0",
42
- "@wordpress/dependency-extraction-webpack-plugin": "^6.37.0",
43
- "@wordpress/scripts": "^31.2.0",
45
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.38.0",
46
+ "@wordpress/scripts": "^31.3.0",
44
47
  "autoprefixer": "^10.4.23",
45
48
  "browser-sync": "^3.0.4",
46
49
  "copy-webpack-plugin": "10.2.4",