@plaudit/webpack-extensions 2.90.1 → 2.92.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 +8 -0
- package/dist/plugins/EnhancedBlockJSONPlugin.d.ts +1 -1
- package/dist/plugins/EnhancedBlockJSONPlugin.js +65 -12
- package/dist/plugins/ExtensionsConfigFileGeneratorPlugin.js +3 -2
- package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +3 -2
- package/dist/shared.d.ts +7 -0
- package/dist/shared.js +30 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -60,6 +60,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
60
60
|
- Legacy PostCSS features that have been integrated into modern CSS
|
|
61
61
|
- `@extends` support
|
|
62
62
|
|
|
63
|
+
## [2.92.0] - 2026-05-20
|
|
64
|
+
### Added
|
|
65
|
+
- Support for marking `block.json` attributes with `"supports-bindings": true` to enable block binding support in the editor
|
|
66
|
+
|
|
67
|
+
## [2.91.0] - 2026-05-20
|
|
68
|
+
### Added
|
|
69
|
+
- Support for the `module_dependencies` property on `script` assets
|
|
70
|
+
|
|
63
71
|
## [2.90.1] - 2026-05-08
|
|
64
72
|
### Fixed
|
|
65
73
|
- `postcss-loader` being a dev dependency
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Compilation } from "webpack";
|
|
2
2
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
3
3
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
4
|
-
import {
|
|
4
|
+
import { BlockEntrypointInfo, FileSegmentBlockEntrypointInfo, InlinedAsset, ParsedAssetJsonProvider, ParsedAssetsJson, ScriptArgsObject, VerifiedAdvancedOutputConfig } from "../shared";
|
|
5
5
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
6
6
|
type WorkableBlockEntrypointInfo = Omit<FileSegmentBlockEntrypointInfo, 'originalValue' | 'pathQueryParameters'> & Partial<Pick<FileSegmentBlockEntrypointInfo, 'originalValue'>> & {
|
|
7
7
|
outputPath: string;
|
|
@@ -155,6 +155,33 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
155
155
|
this.callRegisterFunction('script', writer, baseUriVar, Object.entries(finalizedScriptHandles));
|
|
156
156
|
this.callRegisterFunction('style', writer, baseUriVar, Object.entries(finalizedStyleHandles));
|
|
157
157
|
this.callRegisterFunction('script_module', writer, baseUriVar, Object.entries(metadata.scriptModuleHandles));
|
|
158
|
+
const entries = Object.entries(metadata.bindableBlockAttributes);
|
|
159
|
+
const supportedAttributes = new expressions_1.Var("supported_block_attributes", "?array");
|
|
160
|
+
if ((0, shared_1.arrayIsLength)(entries, 1)) {
|
|
161
|
+
writer.filter(`block_bindings_supported_attributes_${entries[0][0]}`, writer => {
|
|
162
|
+
const parameters = entries[0][1];
|
|
163
|
+
if (parameters.length === 1) {
|
|
164
|
+
writer.appendExpr(new expressions_1.Assignment(supportedAttributes, parameters[0], true));
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
writer.call("array_push", [supportedAttributes, ...parameters]);
|
|
168
|
+
}
|
|
169
|
+
writer.return(supportedAttributes);
|
|
170
|
+
}, { functionArgParameters: [supportedAttributes] });
|
|
171
|
+
}
|
|
172
|
+
else if (entries.length > 1) {
|
|
173
|
+
const compiledBindingSupportingAttributes = new expressions_1.Var("compiled_binding_supporting_attributes");
|
|
174
|
+
writer.assign(compiledBindingSupportingAttributes, metadata.bindableBlockAttributes);
|
|
175
|
+
const blockType = new expressions_1.Var("block_type", "?string");
|
|
176
|
+
writer.filter(`block_bindings_supported_attributes`, writer => {
|
|
177
|
+
writer
|
|
178
|
+
.if(expressions_1.Op.binary(new expressions_1.Call("empty", [blockType]), " || ", new expressions_1.Call("empty", [new expressions_1.ArrayAccess(compiledBindingSupportingAttributes, blockType)])))
|
|
179
|
+
.return(supportedAttributes)
|
|
180
|
+
.endIf()
|
|
181
|
+
.call("array_push", [supportedAttributes, new expressions_1.Op("...", new expressions_1.ArrayAccess(compiledBindingSupportingAttributes, blockType))])
|
|
182
|
+
.return(supportedAttributes);
|
|
183
|
+
}, { functionArgParameters: [supportedAttributes, blockType], useVars: [compiledBindingSupportingAttributes] });
|
|
184
|
+
}
|
|
158
185
|
writer.call("\\Plaudit\\Common\\ACF\\BlockManager::autoloadSubfoldersV3", [
|
|
159
186
|
expressions_1.Constants.__DIR__, // string $dir
|
|
160
187
|
new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockData, false, "\t")), // array $blockdirConfig
|
|
@@ -185,6 +212,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
185
212
|
.flatMap(bi => bi.workableBlockEntrypointsInfo)
|
|
186
213
|
.sort((a, b) => a.handle.localeCompare(b.handle) || a.entrypointField.localeCompare(b.entrypointField));
|
|
187
214
|
const blockData = {};
|
|
215
|
+
const bindableBlockAttributes = {};
|
|
188
216
|
for (const [blockJsonAssetName, { sourcePath: blockJsonSourcePath, workableBlockEntrypointsInfo, blockJsonText }] of Object.entries(collatedWorkableBlockInfo)) {
|
|
189
217
|
if (!blockJsonSourcePath) {
|
|
190
218
|
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`${blockJsonAssetName} does not have a source path`, blockJsonAssetName));
|
|
@@ -208,6 +236,19 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
208
236
|
else {
|
|
209
237
|
blockJson["version"] = hashForVersion;
|
|
210
238
|
}
|
|
239
|
+
if (typeof blockJson["name"] === 'string' && typeof blockJson["attributes"] === 'object' && blockJson["attributes"]) {
|
|
240
|
+
for (const [name, attr] of Object.entries(blockJson["attributes"])) {
|
|
241
|
+
if (attr["supports-bindings"]) {
|
|
242
|
+
delete attr["supports-bindings"];
|
|
243
|
+
if (bindableBlockAttributes[blockJson["name"]] !== undefined) {
|
|
244
|
+
bindableBlockAttributes[blockJson["name"]].push(name);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
bindableBlockAttributes[blockJson["name"]] = [name];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
211
252
|
EnhancedBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
|
|
212
253
|
const blockDirName = (0, node_path_1.dirname)((0, node_path_1.relative)(this.dest.destination, blockJsonAssetName));
|
|
213
254
|
blockData[blockDirName] = EnhancedBlockJSONPlugin
|
|
@@ -226,7 +267,8 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
226
267
|
styleHandles: Object.fromEntries(handleData.filter(hd => (0, shared_1.isStyleField)(hd.entrypointField))
|
|
227
268
|
.map(hd => {
|
|
228
269
|
return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], inlinedAsset: hd.inlinedAsset }];
|
|
229
|
-
}))
|
|
270
|
+
})),
|
|
271
|
+
bindableBlockAttributes
|
|
230
272
|
},
|
|
231
273
|
...Object.fromEntries(Object.entries(blockData).sort((a, b) => a[0].localeCompare(b[0])))
|
|
232
274
|
};
|
|
@@ -237,21 +279,32 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
237
279
|
}
|
|
238
280
|
static convertToScriptHandles(handleData) {
|
|
239
281
|
return handleData.map(hd => {
|
|
240
|
-
const
|
|
282
|
+
const { inlinedAsset, originalValue, outputPath, entrypointField, scriptArgsObject: rawScriptArgsObject, assetData, handle } = hd;
|
|
283
|
+
const { dependencies = [], module_dependencies = undefined } = originalValue !== undefined ? assetData : {};
|
|
241
284
|
let scriptArgsObject;
|
|
242
|
-
if (
|
|
243
|
-
scriptArgsObject =
|
|
244
|
-
}
|
|
245
|
-
else if (hd.inlinedAsset !== undefined) {
|
|
246
|
-
scriptArgsObject = hd.inlinedAsset.position === 'before' ? { strategy: "defer" } : undefined;
|
|
247
|
-
}
|
|
248
|
-
else if (!hd.entrypointField.startsWith("editor")) {
|
|
249
|
-
scriptArgsObject = { strategy: "defer" };
|
|
285
|
+
if (rawScriptArgsObject !== undefined) {
|
|
286
|
+
scriptArgsObject = { ...rawScriptArgsObject, module_dependencies: (0, shared_1.mergeModuleDependencyArrays)(rawScriptArgsObject.module_dependencies, module_dependencies) };
|
|
250
287
|
}
|
|
251
288
|
else {
|
|
252
|
-
|
|
289
|
+
if (inlinedAsset !== undefined) {
|
|
290
|
+
scriptArgsObject = inlinedAsset.position === 'before' ? { strategy: "defer" } : undefined;
|
|
291
|
+
}
|
|
292
|
+
else if (!entrypointField.startsWith("editor")) {
|
|
293
|
+
scriptArgsObject = { strategy: "defer" };
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
scriptArgsObject = undefined;
|
|
297
|
+
}
|
|
298
|
+
if (module_dependencies?.length) {
|
|
299
|
+
if (scriptArgsObject === undefined) {
|
|
300
|
+
scriptArgsObject = { module_dependencies };
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
scriptArgsObject.module_dependencies = module_dependencies;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
253
306
|
}
|
|
254
|
-
return [
|
|
307
|
+
return [handle, { src: outputPath, rest: scriptArgsObject !== undefined ? [dependencies, assetData.version, scriptArgsObject] : [dependencies, assetData.version], inlinedAsset }];
|
|
255
308
|
});
|
|
256
309
|
}
|
|
257
310
|
static doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, getter) {
|
|
@@ -96,11 +96,12 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
96
96
|
const isCss = (0, shared_1.isStyleField)(assetType);
|
|
97
97
|
const handleGroup = isCss ? 'styleHandles'
|
|
98
98
|
: ((0, shared_1.isScriptModuleField)(assetType) ? 'scriptModuleHandles' : 'scriptHandles');
|
|
99
|
+
const { dependencies, module_dependencies } = assetData;
|
|
99
100
|
blockExtensionsConfig[handleGroup][handle] = {
|
|
100
101
|
src: isCss ? assetPath.replace(/\.js$/, ".css") : assetPath,
|
|
101
102
|
rest: isCss || key.startsWith("editor")
|
|
102
|
-
? [assetData.dependencies, assetData.version]
|
|
103
|
-
: [
|
|
103
|
+
? (module_dependencies?.length ? [dependencies, assetData.version, { in_footer: true, module_dependencies }] : [dependencies, assetData.version])
|
|
104
|
+
: [dependencies, assetData.version, { strategy: 'defer', module_dependencies: module_dependencies?.length ? module_dependencies : undefined }]
|
|
104
105
|
};
|
|
105
106
|
(blockExtensionsConfig.blocks[blockSlug] ?? (blockExtensionsConfig.blocks[blockSlug] = {}))[key] = handle;
|
|
106
107
|
}
|
|
@@ -297,11 +297,12 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
297
297
|
const extension = (0, node_path_1.extname)(file).toLowerCase();
|
|
298
298
|
const type = extension === ".js" ? 'script' : (extension === ".mjs" ? 'script_module' : 'style');
|
|
299
299
|
const isScript = type !== 'style';
|
|
300
|
-
const dependencies = isScript === entrypointChunkIsScript ? assetData
|
|
300
|
+
const { dependencies = [], module_dependencies = undefined } = isScript === entrypointChunkIsScript ? assetData : {};
|
|
301
301
|
const { lazyLoader, locations } = this.dest;
|
|
302
302
|
const { flags } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(typeof locations.registerScriptArgs === 'object' ? locations.registerScriptArgs : { strategy: locations.registerScriptArgs }, file, "registerScriptArgs");
|
|
303
303
|
const { inlinedAsset, scriptArgsObject } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(file, flags, this.dest.enqueuingFlags));
|
|
304
|
-
const
|
|
304
|
+
const completeScriptArgsObject = module_dependencies?.length ? { ...scriptArgsObject, module_dependencies } : scriptArgsObject;
|
|
305
|
+
const rest = isScript && completeScriptArgsObject !== undefined ? [dependencies, assetData.version, completeScriptArgsObject] : [dependencies, assetData.version];
|
|
305
306
|
const destPath = (0, node_path_1.join)(compilation.outputOptions.path, file);
|
|
306
307
|
handles.push({
|
|
307
308
|
src: destPath,
|
package/dist/shared.d.ts
CHANGED
|
@@ -4,15 +4,21 @@ import { type AssetInfo, type Compilation, type Configuration, type Entrypoint,
|
|
|
4
4
|
import { SourceType } from "./utils/entrypoint-resolution-logic";
|
|
5
5
|
import type { NormalizedEnqueuingControlFlags } from "./utils/path-query-and-related-helpers";
|
|
6
6
|
export * from "./utils/entrypoint-resolution-logic";
|
|
7
|
+
export type WPModuleDependency = {
|
|
8
|
+
id: string;
|
|
9
|
+
import?: string;
|
|
10
|
+
};
|
|
7
11
|
export type ParsedAssetsJson = Record<string, {
|
|
8
12
|
dependencies: string[];
|
|
9
13
|
version: string;
|
|
14
|
+
module_dependencies?: (string | WPModuleDependency)[];
|
|
10
15
|
}>;
|
|
11
16
|
export declare function isParsedAssetsJson(thing: any): thing is ParsedAssetsJson;
|
|
12
17
|
export type ScriptArgsObject = {
|
|
13
18
|
strategy?: 'defer' | 'async';
|
|
14
19
|
in_footer?: boolean;
|
|
15
20
|
fetchpriority?: 'auto' | 'low' | 'high';
|
|
21
|
+
module_dependencies?: (string | WPModuleDependency)[];
|
|
16
22
|
};
|
|
17
23
|
type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
|
|
18
24
|
export type InlinedAsset = {
|
|
@@ -212,6 +218,7 @@ export declare const styleExtension: RegExp;
|
|
|
212
218
|
export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "script" | "style" | "";
|
|
213
219
|
export declare function isStyleField(field: string): field is 'style' | 'viewStyle' | 'editorStyle';
|
|
214
220
|
export declare function isScriptModuleField(field: string): field is 'viewScriptModule';
|
|
221
|
+
export declare function mergeModuleDependencyArrays(a: (string | WPModuleDependency)[] | undefined, b: (string | WPModuleDependency)[] | undefined): (string | WPModuleDependency)[] | undefined;
|
|
215
222
|
export declare function getHandleGroup(field: string): 'styleHandles' | 'scriptHandles' | 'scriptModuleHandles';
|
|
216
223
|
export type StripFirstTwoItems<A extends any[]> = A extends [any, any, ...rest: infer R] ? R : never;
|
|
217
224
|
export declare function hasAtLeastOneItem<T>(list: T[]): list is [T, ...T[]];
|
package/dist/shared.js
CHANGED
|
@@ -34,6 +34,7 @@ exports.leadingSlashIt = leadingSlashIt;
|
|
|
34
34
|
exports.scriptOrStyleTest = scriptOrStyleTest;
|
|
35
35
|
exports.isStyleField = isStyleField;
|
|
36
36
|
exports.isScriptModuleField = isScriptModuleField;
|
|
37
|
+
exports.mergeModuleDependencyArrays = mergeModuleDependencyArrays;
|
|
37
38
|
exports.getHandleGroup = getHandleGroup;
|
|
38
39
|
exports.hasAtLeastOneItem = hasAtLeastOneItem;
|
|
39
40
|
exports.arrayIsLength = arrayIsLength;
|
|
@@ -65,7 +66,7 @@ function isParsedAssetsJson(thing) {
|
|
|
65
66
|
}
|
|
66
67
|
for (const value of Object.values(thing)) {
|
|
67
68
|
if ((!value || typeof value !== 'object') ||
|
|
68
|
-
(!('dependencies' in value) || !Array.isArray(value.dependencies) || value.dependencies.
|
|
69
|
+
(!('dependencies' in value) || !Array.isArray(value.dependencies) || (value.dependencies.length > 0 && !value.dependencies.every(d => typeof d === 'string' || (d && typeof d === 'object' && typeof d.id === 'string')))) ||
|
|
69
70
|
(!('version' in value) || !value.version || typeof value.version !== 'string')) {
|
|
70
71
|
return false;
|
|
71
72
|
}
|
|
@@ -174,6 +175,34 @@ function isStyleField(field) {
|
|
|
174
175
|
function isScriptModuleField(field) {
|
|
175
176
|
return field.includes("odule");
|
|
176
177
|
}
|
|
178
|
+
function mergeModuleDependencyArrays(a, b) {
|
|
179
|
+
if (a === undefined || a.length === 0) {
|
|
180
|
+
return b;
|
|
181
|
+
}
|
|
182
|
+
if (b === undefined || b.length === 0) {
|
|
183
|
+
return a;
|
|
184
|
+
}
|
|
185
|
+
const seenModuleDeps = new Map();
|
|
186
|
+
return [...a, ...b].filter(dep => {
|
|
187
|
+
let id, type;
|
|
188
|
+
if (typeof dep === 'string') {
|
|
189
|
+
id = dep;
|
|
190
|
+
type = 'static';
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
id = dep.id;
|
|
194
|
+
type = dep.import ?? 'static';
|
|
195
|
+
}
|
|
196
|
+
if (seenModuleDeps.has(id)) {
|
|
197
|
+
if (type !== seenModuleDeps.get(id)) {
|
|
198
|
+
throw newCleanWebpackError(`Encountered conflicting import types for the "${id}" module dependency`);
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
seenModuleDeps.set(id, type);
|
|
203
|
+
return true;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
177
206
|
function getHandleGroup(field) {
|
|
178
207
|
if (isStyleField(field)) {
|
|
179
208
|
return 'styleHandles';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.92.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"/dist",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@plaudit/gutenberg-api-extensions": "^2.97.
|
|
31
|
+
"@plaudit/gutenberg-api-extensions": "^2.97.1",
|
|
32
32
|
"@types/browser-sync-webpack-plugin": "^2.2.5",
|
|
33
|
-
"@types/node": "^25.
|
|
33
|
+
"@types/node": "^25.9.1",
|
|
34
34
|
"@types/postcss-functions": "^4.0.4",
|
|
35
35
|
"@types/tapable": "^2.3.0",
|
|
36
36
|
"@types/webpack-sources": "^3.2.3",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@plaudit/postcss-silent-extend": "^3.0.0",
|
|
45
45
|
"@plaudit/postcss-strip-units": "^3.0.0",
|
|
46
46
|
"@plaudit/postcss-variables": "^1.1.0",
|
|
47
|
-
"@wordpress/dependency-extraction-webpack-plugin": "^6.
|
|
48
|
-
"@wordpress/scripts": "^32.
|
|
47
|
+
"@wordpress/dependency-extraction-webpack-plugin": "^6.46.0",
|
|
48
|
+
"@wordpress/scripts": "^32.2.0",
|
|
49
49
|
"autoprefixer": "^10.5.0",
|
|
50
50
|
"browser-sync": "^3.0.4",
|
|
51
51
|
"copy-webpack-plugin": "10.2.4",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"fork-ts-checker-webpack-plugin": "^9.1.0",
|
|
54
54
|
"http-proxy-middleware": "^3.0.5",
|
|
55
55
|
"json2php": "^0.0.12",
|
|
56
|
-
"postcss": "^8.5.
|
|
56
|
+
"postcss": "^8.5.15",
|
|
57
57
|
"postcss-calc": "^9.0.1",
|
|
58
58
|
"postcss-discard-comments": "^6.0.2",
|
|
59
59
|
"postcss-functions": "^4.0.2",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"postcss-reporter": "^7.1.0",
|
|
68
68
|
"postcss-simple-vars": "^7.0.1",
|
|
69
69
|
"postcss-url": "^10.1.3",
|
|
70
|
-
"webpack": "^5.
|
|
70
|
+
"webpack": "^5.107.0",
|
|
71
71
|
"webpack-remove-empty-scripts": "^1.1.1",
|
|
72
72
|
"xml-formatter": "^3.7.0"
|
|
73
73
|
},
|