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