@plaudit/webpack-extensions 2.83.0 → 2.84.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 CHANGED
@@ -5,6 +5,18 @@ 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
+ ## [2.84.0] - 2026-01-30
9
+ ### Added
10
+ - Support for using `lazyLoader` on plain entrypoints
11
+
12
+ ## [2.83.1] - 2026-01-27
13
+ ### Fixed
14
+ - An issue wherein the theme-level styles would pollute the editor's UI styles
15
+ - This was done by reverting the changes from `2.73.1`
16
+
17
+ ### Internals
18
+ - Removed `build` from git
19
+
8
20
  ## [2.83.0] - 2026-01-20
9
21
  ### Added
10
22
  - Support for `hook_name` condition to the `admin` location for plain entrypoints
@@ -1,14 +1,14 @@
1
- import { BlockEntrypointInfo, ParsedAssetJsonProvider, NormalizedUsageLocations } from "../shared";
1
+ import { BlockEntrypointInfo, ParsedAssetJsonProvider, VerifiedAdvancedOutputConfig } from "../shared";
2
2
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
3
3
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
4
4
  import { Compilation } from "webpack";
5
5
  export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
6
6
  private readonly buildRoot;
7
7
  private readonly outputDir;
8
- private readonly usageLocations;
8
+ private readonly dest;
9
9
  private readonly useUnifiedLoader;
10
10
  private static readonly semaphore;
11
- constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: NormalizedUsageLocations, useUnifiedLoader: boolean, context: string, entry: EntryProvider<BlockEntrypointInfo>);
11
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, dest: VerifiedAdvancedOutputConfig, useUnifiedLoader: boolean, context: string, entry: EntryProvider<BlockEntrypointInfo>);
12
12
  private generatePlainEntrypointsLoader;
13
13
  private static addHandlesToHandleLists;
14
14
  private static appendEnqueuingHandleLists;
@@ -15,14 +15,14 @@ const webpack_1 = require("webpack");
15
15
  class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
16
16
  buildRoot;
17
17
  outputDir;
18
- usageLocations;
18
+ dest;
19
19
  useUnifiedLoader;
20
20
  static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Plain");
21
- constructor(config, buildRoot, outputDir, usageLocations, useUnifiedLoader, context, entry) {
21
+ constructor(config, buildRoot, outputDir, dest, useUnifiedLoader, context, entry) {
22
22
  super(config, "plain-entrypoints-v2", [PlainEntrypointsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
23
23
  this.buildRoot = buildRoot;
24
24
  this.outputDir = outputDir;
25
- this.usageLocations = usageLocations;
25
+ this.dest = dest;
26
26
  this.useUnifiedLoader = useUnifiedLoader;
27
27
  }
28
28
  generatePlainEntrypointsLoader(compilation, assets) {
@@ -41,7 +41,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
41
41
  .map(handle => [handle.handleName, handle.src]))]));
42
42
  const plainEntrypointsConfig = { scriptHandles: {}, script_moduleHandles: {}, styleHandles: {} };
43
43
  for (const { handles, handlePrefix } of assets) {
44
- for (const { src, rest, locations, type, handleName } of handles) {
44
+ for (const { src, rest, locations, type, handleName, lazyLoader } of handles) {
45
45
  const basename = node_path_1.default.basename(src).replace(/_(?:script(?:-\d+)?\.js|style(?:-\d+)?\.css)$|(?<!_(script|style))\.(js|css)$/, "");
46
46
  let finalHandleName;
47
47
  if (typeof handleName === 'string') {
@@ -55,12 +55,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
55
55
  }
56
56
  handleNameMap[finalHandleName] = src;
57
57
  }
58
- plainEntrypointsConfig[`${type}Handles`][finalHandleName] = {
59
- src,
60
- rest,
61
- locations,
62
- type
63
- };
58
+ plainEntrypointsConfig[`${type}Handles`][finalHandleName] = { src, rest, locations, type, lazyLoader };
64
59
  }
65
60
  }
66
61
  PlainEntrypointsConfigFileGeneratorPlugin.addHandlesToHandleLists('script', Object.entries(plainEntrypointsConfig.scriptHandles)
@@ -90,6 +85,40 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
90
85
  }
91
86
  }
92
87
  PlainEntrypointsConfigFileGeneratorPlugin.appendEnqueuingHandleLists(writer, handleLists);
88
+ const sortedEditorStyleHandles = sortedStyleHandles
89
+ .filter(([_, { locations: { clientEditor }, type }]) => type === 'style' && (clientEditor || typeof clientEditor === 'number'))
90
+ .sort((a, b) => {
91
+ const aPriority = typeof a[1].locations.clientEditor === 'boolean' ? 10 : a[1].locations.clientEditor;
92
+ const bPriority = typeof b[1].locations.clientEditor === 'boolean' ? 10 : b[1].locations.clientEditor;
93
+ return aPriority - bPriority;
94
+ })
95
+ .map(info => info[1].src);
96
+ if (sortedEditorStyleHandles.length > 0) {
97
+ writer.linebreak();
98
+ for (const handleSrc of sortedEditorStyleHandles) {
99
+ const handlePath = node_path_1.default.join(this.outputDir, node_path_1.default.relative(emitDir, handleSrc));
100
+ writer.call("add_editor_style", [(0, shared_1.leadingSlashIt)(handlePath)]);
101
+ }
102
+ }
103
+ const lazyLoadedHandles = Object.values(handleLists)
104
+ .flatMap(handleList => handleList.map(handle => [handle.data.lazyLoader, handle]))
105
+ .filter((entry) => entry[0] !== undefined)
106
+ .sort((a, b) => a[0].localeCompare(b[0]) || a[1].priority - b[1].priority);
107
+ if (lazyLoadedHandles.length > 0) {
108
+ writer.linebreak();
109
+ const groupedLazyLoadedHandles = Object.entries(lazyLoadedHandles
110
+ .reduce((a, b) => {
111
+ (a[b[0]] ??= []).push(b[1]);
112
+ return a;
113
+ }, {}));
114
+ for (const [lazyLoader, handles] of groupedLazyLoadedHandles) {
115
+ writer.function(lazyLoader, [], writer => {
116
+ for (const handle of handles) {
117
+ writer.call(`wp_enqueue_${handle.type}`, [handle.handle]);
118
+ }
119
+ }, { returnType: "void" });
120
+ }
121
+ }
93
122
  (0, shared_1.emitPHPWriterAsAsset)(writer, compilation, "plain-entrypoints-loader.php");
94
123
  }
95
124
  static addHandlesToHandleLists(type, handles, handleLists) {
@@ -101,6 +130,11 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
101
130
  for (const location of (0, shared_1.constantKeys)(shared_1.standardLocationNamesMeta)) {
102
131
  let priority, hook_name;
103
132
  const dataLocation = data.locations[location];
133
+ if (location === 'clientEditor' && type === 'style') {
134
+ // We don't include editor styles in the handle list because editor styles are enqueued via a completely separate mechanism at runtime and, therefore,
135
+ // cannot be handled by the same code as every other enqueueable item
136
+ continue;
137
+ }
104
138
  if (typeof dataLocation === 'number') {
105
139
  priority = dataLocation;
106
140
  hook_name = undefined;
@@ -131,21 +165,23 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
131
165
  else {
132
166
  continue;
133
167
  }
134
- handleLists[location].push({ handle, type, priority, hook_name });
168
+ handleLists[location].push({ data, handle, type, priority, hook_name });
135
169
  }
136
170
  }
137
171
  }
138
172
  static appendEnqueuingHandleLists(writer, handleLists) {
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) {
173
+ const lazyLoadableHandles = {};
174
+ for (const [sln, { action, supports_hook_name, additional_action_code }] of (0, shared_1.constantEntries)(shared_1.standardLocationNamesMeta)) {
175
+ const handleList = handleLists[sln];
142
176
  if (handleList.length > 0) {
177
+ writer.linebreak();
143
178
  for (const [priority, prioritizedHandleList] of PlainEntrypointsConfigFileGeneratorPlugin.separateHandleListByPriority(handleList)) {
144
179
  if (supports_hook_name) {
145
180
  const hookNamedHandleLists = PlainEntrypointsConfigFileGeneratorPlugin.separateHandleListByHookName(prioritizedHandleList);
146
181
  if (!(0, shared_1.arrayIsLength)(hookNamedHandleLists, 1) || hookNamedHandleLists[0][0] !== "") {
147
182
  const hook_name_var = new expressions_1.Var("hook_name", "?string");
148
183
  writer.action(action, writer => {
184
+ additional_action_code?.before?.(writer);
149
185
  for (const [hook_name, handles] of hookNamedHandleLists) {
150
186
  writer.if(expressions_1.Op.binary(hook_name_var, " === ", hook_name));
151
187
  for (const handle of handles) {
@@ -153,18 +189,22 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
153
189
  }
154
190
  writer.endIf();
155
191
  }
192
+ additional_action_code?.after?.(writer);
156
193
  }, { priority, functionArgParameters: [hook_name_var] });
157
194
  continue;
158
195
  }
159
196
  }
160
197
  writer.action(action, writer => {
198
+ additional_action_code?.before?.(writer);
161
199
  for (const handle of prioritizedHandleList) {
162
200
  writer.call(`wp_enqueue_${handle.type}`, [handle.handle]);
163
201
  }
202
+ additional_action_code?.after?.(writer);
164
203
  }, { priority });
165
204
  }
166
205
  }
167
206
  }
207
+ return lazyLoadableHandles;
168
208
  }
169
209
  static separateHandleListByPriority(handleItems) {
170
210
  const lists = new Map();
@@ -237,13 +277,14 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
237
277
  const type = extension === ".js" ? 'script' : (extension === ".mjs" ? 'script_module' : 'style');
238
278
  const isScript = type !== 'style';
239
279
  const dependencies = isScript === entrypointChunkIsScript ? assetData.dependencies : [];
240
- const rest = isScript && this.usageLocations.registerScriptArgs !== undefined
241
- ? [dependencies, assetData.version, this.usageLocations.registerScriptArgs] : [dependencies, assetData.version];
280
+ const { registerScriptArgs } = this.dest.locations;
281
+ const rest = isScript && registerScriptArgs !== undefined ? [dependencies, assetData.version, registerScriptArgs] : [dependencies, assetData.version];
242
282
  const destPath = node_path_1.default.join(compilation.outputOptions.path, file);
243
283
  handles.push({
244
284
  src: destPath, rest, type,
245
- locations: this.usageLocations,
246
- handleName: useHandleName ? this.usageLocations.handle : undefined,
285
+ locations: this.dest.locations,
286
+ handleName: useHandleName ? this.dest.locations.handle : undefined,
287
+ lazyLoader: this.dest.lazyLoader
247
288
  });
248
289
  }
249
290
  myAssetHandles.push({ handles, handlePrefix: this.config.targetHandlePrefix });
package/build/shared.d.ts CHANGED
@@ -19,15 +19,12 @@ 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;
23
22
  };
24
23
  readonly clientEditor: {
25
24
  readonly action: "enqueue_block_editor_assets";
26
- readonly supports_hook_name: false;
27
25
  };
28
26
  readonly blockAssets: {
29
27
  readonly action: "enqueue_block_assets";
30
- readonly supports_hook_name: false;
31
28
  };
32
29
  readonly admin: {
33
30
  readonly action: "admin_enqueue_scripts";
@@ -35,15 +32,20 @@ export declare const standardLocationNamesMeta: {
35
32
  };
36
33
  readonly login: {
37
34
  readonly action: "login_enqueue_scripts";
38
- readonly supports_hook_name: false;
39
35
  };
40
36
  readonly customizer: {
41
37
  readonly action: "customize_controls_enqueue_scripts";
42
- readonly supports_hook_name: false;
43
38
  };
44
39
  readonly analytics: {
45
40
  readonly action: "plaudit_enqueue_analytics";
46
- readonly supports_hook_name: false;
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;
47
49
  };
48
50
  };
49
51
  export type StandardLocationNames = keyof typeof standardLocationNamesMeta;
@@ -52,7 +54,9 @@ type LocationWithHookNameSupport = boolean | number | string | string[] | {
52
54
  priority?: number;
53
55
  };
54
56
  export type UsageLocations = {
55
- [K in StandardLocationNames]?: typeof standardLocationNamesMeta[K]['supports_hook_name'] extends true ? LocationWithHookNameSupport : boolean | number;
57
+ [K in StandardLocationNames]?: typeof standardLocationNamesMeta[K] extends {
58
+ supports_hook_name: true;
59
+ } ? LocationWithHookNameSupport : boolean | number;
56
60
  } & {
57
61
  register?: boolean | number;
58
62
  handle?: string | ((generatedHandle: string) => string);
package/build/shared.js CHANGED
@@ -49,13 +49,13 @@ function isParsedAssetsJson(thing) {
49
49
  return true;
50
50
  }
51
51
  exports.standardLocationNamesMeta = {
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 },
52
+ clientView: { action: "wp_enqueue_scripts" },
53
+ clientEditor: { action: "enqueue_block_editor_assets" },
54
+ blockAssets: { action: "enqueue_block_assets" },
55
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 }
56
+ login: { action: "login_enqueue_scripts" },
57
+ customizer: { action: "customize_controls_enqueue_scripts" },
58
+ analytics: { action: "plaudit_enqueue_analytics" },
59
59
  };
60
60
  function isNormalizedUsageLocations(usageLocations) {
61
61
  return typeof usageLocations.registerScriptArgs !== 'string';
@@ -548,7 +548,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
548
548
  const entry = srcIsDirectory // This being true implies that srcRoot is not an array
549
549
  ? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
550
550
  : () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest, absoluteSrc } } });
551
- plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest.locations, config.useUnifiedLoader, contextPath, entry);
551
+ plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest, config.useUnifiedLoader, contextPath, entry);
552
552
  }
553
553
  else {
554
554
  if (srcIsDirectory) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.83.0",
3
+ "version": "2.84.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build",
@@ -25,7 +25,7 @@
25
25
  "devDependencies": {
26
26
  "@plaudit/gutenberg-api-extensions": "^2.84.3",
27
27
  "@types/browser-sync-webpack-plugin": "^2.2.5",
28
- "@types/node": "^25.0.9",
28
+ "@types/node": "^25.1.0",
29
29
  "@types/postcss-functions": "^4.0.4",
30
30
  "@types/tapable": "^2.3.0",
31
31
  "@types/webpack": "^5.28.5",
@@ -42,9 +42,9 @@
42
42
  "@plaudit/postcss-silent-extend": "^3.0.0",
43
43
  "@plaudit/postcss-strip-units": "^3.0.0",
44
44
  "@plaudit/postcss-variables": "^1.1.0",
45
- "@wordpress/dependency-extraction-webpack-plugin": "^6.38.0",
46
- "@wordpress/scripts": "^31.3.0",
47
- "autoprefixer": "^10.4.23",
45
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.39.0",
46
+ "@wordpress/scripts": "^31.4.0",
47
+ "autoprefixer": "^10.4.24",
48
48
  "browser-sync": "^3.0.4",
49
49
  "copy-webpack-plugin": "10.2.4",
50
50
  "css-minimizer-webpack-plugin": "^6.0.0",