@plaudit/webpack-extensions 3.14.1 → 3.15.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 +18 -0
- package/dist/plugins/EnhancedBlockJSONPlugin.d.ts +5 -3
- package/dist/plugins/EnhancedBlockJSONPlugin.js +17 -8
- package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +22 -19
- package/dist/shared.d.ts +17 -10
- package/dist/shared.js +11 -13
- package/dist/utils/path-query-and-related-helpers.d.ts +9 -2
- package/dist/utils/path-query-and-related-helpers.js +14 -4
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.15.1] - 2026-07-20
|
|
9
|
+
### Fixed
|
|
10
|
+
- A bug that caused all styles bound for editor use to be emitted as inline CSS
|
|
11
|
+
- This comes from version `2.94.1`
|
|
12
|
+
|
|
13
|
+
## [3.15.0] - 2026-07-17
|
|
14
|
+
### Changed
|
|
15
|
+
- The `add_editor_style()` enqueue path to use `block_editor_settings_all` to avoid a litany of bugs courtesy of WordPress's high-quality code
|
|
16
|
+
- This comes from version `2.94.0`
|
|
17
|
+
|
|
8
18
|
## [3.14.1] - 2026-07-15
|
|
9
19
|
### Fixed
|
|
10
20
|
- The new supported features code overriding unintended data in theme.json
|
|
@@ -209,6 +219,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
209
219
|
- Legacy PostCSS features that have been integrated into modern CSS
|
|
210
220
|
- `@extends` support
|
|
211
221
|
|
|
222
|
+
## [2.94.1] - 2026-07-20
|
|
223
|
+
### Fixed
|
|
224
|
+
- A bug that caused all styles bound for editor use to be emitted as inline CSS
|
|
225
|
+
|
|
226
|
+
## [2.94.0] - 2026-07-17
|
|
227
|
+
### Changed
|
|
228
|
+
- The `add_editor_style()` enqueue path to use `block_editor_settings_all` to avoid a litany of bugs courtesy of WordPress's high-quality code
|
|
229
|
+
|
|
212
230
|
## [2.93.1] - 2026-07-15
|
|
213
231
|
### Fixed
|
|
214
232
|
- The new supported features code overriding unintended data in theme.json
|
|
@@ -1,15 +1,17 @@
|
|
|
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 { BlockEntrypointInfo, FileSegmentBlockEntrypointInfo,
|
|
4
|
+
import { AssetMetaSegment, BlockEntrypointInfo, FileSegmentBlockEntrypointInfo, 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;
|
|
8
8
|
assetData: ParsedAssetsJson[string];
|
|
9
9
|
hash: string;
|
|
10
10
|
scriptArgsObject: ScriptArgsObject | undefined;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
} & (AssetMetaSegment | {
|
|
12
|
+
inlinedAsset?: undefined;
|
|
13
|
+
assetContents?: string;
|
|
14
|
+
});
|
|
13
15
|
type CollatedWorkableBlockInfo = Record<string, {
|
|
14
16
|
sourcePath?: string;
|
|
15
17
|
workableBlockEntrypointsInfo: WorkableBlockEntrypointInfo[];
|
|
@@ -65,8 +65,8 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
65
65
|
.filter((item) => item[1] !== '')
|
|
66
66
|
.map(([file, assetType]) => {
|
|
67
67
|
const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(file, metadata.enqueuingFlags, this.dest.enqueuingFlags);
|
|
68
|
-
const { scriptArgsObject,
|
|
69
|
-
if (inlinedAsset !== undefined) {
|
|
68
|
+
const { scriptArgsObject, assetMeta } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, enqueuingFlags);
|
|
69
|
+
if (assetMeta?.inlinedAsset !== undefined) {
|
|
70
70
|
staticallyLoadedEntrypoints.push(file);
|
|
71
71
|
}
|
|
72
72
|
const wasOriginallyAStyleField = (0, shared_1.isStyleField)(metadata.entrypointField);
|
|
@@ -75,10 +75,10 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
75
75
|
const entrypointField = (0, shared_1.convertEntrypointFieldForAssetType)(metadata.entrypointField, assetType);
|
|
76
76
|
return {
|
|
77
77
|
...metadata, outputPath, assetData, originalValue: undefined, hash: entrypointChunk.hash ?? "",
|
|
78
|
-
entrypointField, handleGroup: (0, shared_1.getHandleGroup)(entrypointField), scriptArgsObject,
|
|
78
|
+
entrypointField, handleGroup: (0, shared_1.getHandleGroup)(entrypointField), scriptArgsObject, ...assetMeta
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
return { ...metadata, outputPath, assetData, hash: entrypointChunk.hash ?? "", scriptArgsObject,
|
|
81
|
+
return { ...metadata, outputPath, assetData, hash: entrypointChunk.hash ?? "", scriptArgsObject, ...assetMeta };
|
|
82
82
|
});
|
|
83
83
|
if (applicableBlockJsonFiles[epBlockJson]) {
|
|
84
84
|
applicableBlockJsonFiles[epBlockJson].workableBlockEntrypointsInfo.push(...workableBlockEntrypointsInfo);
|
|
@@ -127,7 +127,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
127
127
|
const { inlinedAsset, ...finalizedHandle } = handleData;
|
|
128
128
|
if (inlinedAsset !== undefined) {
|
|
129
129
|
finalizedHandle.src = false;
|
|
130
|
-
inlinedAssets.push([handle, type,
|
|
130
|
+
inlinedAssets.push([handle, type, handleData]);
|
|
131
131
|
}
|
|
132
132
|
registerableHandles[handle] = finalizedHandle;
|
|
133
133
|
}
|
|
@@ -327,7 +327,10 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
327
327
|
.convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && (0, shared_1.isScriptModuleField)(hd.entrypointField)))),
|
|
328
328
|
styleHandles: Object.fromEntries(handleData.filter(hd => (0, shared_1.isStyleField)(hd.entrypointField))
|
|
329
329
|
.map(hd => {
|
|
330
|
-
|
|
330
|
+
if (hd.inlinedAsset === undefined) {
|
|
331
|
+
return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], assetContents: hd.assetContents }];
|
|
332
|
+
}
|
|
333
|
+
return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], inlinedAsset: hd.inlinedAsset, assetContents: hd.assetContents }];
|
|
331
334
|
})),
|
|
332
335
|
bindableBlockAttributes
|
|
333
336
|
},
|
|
@@ -340,7 +343,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
340
343
|
}
|
|
341
344
|
static convertToScriptHandles(handleData) {
|
|
342
345
|
return handleData.map(hd => {
|
|
343
|
-
const { inlinedAsset, originalValue, outputPath, entrypointField, scriptArgsObject: rawScriptArgsObject, assetData, handle } = hd;
|
|
346
|
+
const { assetContents, inlinedAsset, originalValue, outputPath, entrypointField, scriptArgsObject: rawScriptArgsObject, assetData, handle } = hd;
|
|
344
347
|
const { dependencies = [], module_dependencies = undefined } = originalValue !== undefined ? assetData : {};
|
|
345
348
|
let scriptArgsObject;
|
|
346
349
|
if (rawScriptArgsObject !== undefined) {
|
|
@@ -366,7 +369,13 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
366
369
|
}
|
|
367
370
|
}
|
|
368
371
|
}
|
|
369
|
-
|
|
372
|
+
const rest = scriptArgsObject !== undefined ? [dependencies, assetData.version, scriptArgsObject] : [dependencies, assetData.version];
|
|
373
|
+
if (inlinedAsset) {
|
|
374
|
+
return [handle, { src: outputPath, rest, inlinedAsset, assetContents }];
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
return [handle, { src: outputPath, rest, assetContents }];
|
|
378
|
+
}
|
|
370
379
|
});
|
|
371
380
|
}
|
|
372
381
|
static doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, getter) {
|
|
@@ -70,13 +70,12 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
70
70
|
writer.action("init", writer => {
|
|
71
71
|
writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
|
|
72
72
|
for (const { handle, type, data } of prioritizedHandleList) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, inlinedAsset, data, src);
|
|
73
|
+
if (data.inlinedAsset !== undefined) {
|
|
74
|
+
writer.call(`wp_register_${type}`, [handle, false, ...data.rest]);
|
|
75
|
+
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, data);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
writer.call(`wp_register_${type}`, [handle, expressions_1.Op.concat(baseUriVar, (0, node_path_1.relative)(emitDir, data.src)), ...data.rest]);
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
}, { priority, accountForAlreadyDoing: this.config.includePostInitFallback });
|
|
@@ -85,10 +84,9 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
85
84
|
writer.action("init", writer => {
|
|
86
85
|
writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
|
|
87
86
|
for (const { handle, type, data } of prioritizedHandleList) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, inlinedAsset, data, src);
|
|
87
|
+
writer.call(`wp_register_${type}`, [handle, false, ...data.rest]);
|
|
88
|
+
if (data.inlinedAsset !== undefined) {
|
|
89
|
+
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, data);
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
}, { priority, accountForAlreadyDoing: this.config.includePostInitFallback });
|
|
@@ -101,14 +99,19 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
101
99
|
const aPriority = typeof a[1].locations.clientEditor === 'boolean' ? 10 : a[1].locations.clientEditor;
|
|
102
100
|
const bPriority = typeof b[1].locations.clientEditor === 'boolean' ? 10 : b[1].locations.clientEditor;
|
|
103
101
|
return aPriority - bPriority;
|
|
104
|
-
})
|
|
105
|
-
.map(info => info[1].src);
|
|
102
|
+
});
|
|
106
103
|
if (sortedEditorStyleHandles.length > 0) {
|
|
107
104
|
writer.linebreak();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
const editorSettings = new expressions_1.Var("editor_settings");
|
|
106
|
+
writer.filter("block_editor_settings_all", writer => {
|
|
107
|
+
for (const [handle, data] of sortedEditorStyleHandles) {
|
|
108
|
+
const contents = data.assetContents;
|
|
109
|
+
if (contents) {
|
|
110
|
+
writer.appendExpr(new expressions_1.Assignment(new expressions_1.ArrayAccess(editorSettings, "styles"), new expressions_1.PHPArray({ css: (0, shared_1.wrapInlineAssetContents)(compilation, "plaudit_editor_style", handle, contents) }), true));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
writer.return(editorSettings);
|
|
114
|
+
}, { functionArgParameters: [editorSettings], accountForAlreadyDoing: false });
|
|
112
115
|
}
|
|
113
116
|
const lazyLoadedHandles = Object.values(handleLists)
|
|
114
117
|
.flatMap(handleList => handleList.map(handle => [handle.data.lazyLoader, handle]))
|
|
@@ -297,7 +300,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
297
300
|
const { dependencies = [], module_dependencies = undefined } = isScript === entrypointChunkIsScript ? assetData : {};
|
|
298
301
|
const { lazyLoader, locations } = this.dest;
|
|
299
302
|
const { flags } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(typeof locations.registerScriptArgs === 'object' ? locations.registerScriptArgs : { strategy: locations.registerScriptArgs }, file, "registerScriptArgs");
|
|
300
|
-
const {
|
|
303
|
+
const { assetMeta, scriptArgsObject } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(file, flags, this.dest.enqueuingFlags), type === 'style' && (!!locations.clientEditor || locations.clientEditor === 0));
|
|
301
304
|
const completeScriptArgsObject = module_dependencies?.length ? { ...scriptArgsObject, module_dependencies } : scriptArgsObject;
|
|
302
305
|
const rest = isScript && completeScriptArgsObject !== undefined ? [dependencies, assetData.version, completeScriptArgsObject] : [dependencies, assetData.version];
|
|
303
306
|
const destPath = (0, node_path_1.join)(compilation.outputOptions.path, file);
|
|
@@ -308,7 +311,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
308
311
|
locations,
|
|
309
312
|
handleName: useHandleName ? locations.handle : undefined,
|
|
310
313
|
lazyLoader,
|
|
311
|
-
|
|
314
|
+
...assetMeta
|
|
312
315
|
});
|
|
313
316
|
}
|
|
314
317
|
myAssetHandles.push({ handles, handlePrefix: this.config.targetHandlePrefix });
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PHPFile, PHPWriter } from "@plaudit/php-writer";
|
|
2
|
+
import { HereOrNowDoc } from "@plaudit/php-writer/expressions";
|
|
2
3
|
import type { Options as PostcssFunctionsOptions } from "postcss-functions";
|
|
3
4
|
import { type AssetInfo, type Compilation, type Configuration, type Entrypoint, WebpackError, type Compiler } from "webpack";
|
|
4
5
|
import { SourceType } from "./utils/entrypoint-resolution-logic";
|
|
@@ -14,22 +15,29 @@ export type ParsedAssetsJson = Record<string, {
|
|
|
14
15
|
module_dependencies?: (string | WPModuleDependency)[];
|
|
15
16
|
}>;
|
|
16
17
|
export declare function isParsedAssetsJson(thing: any): thing is ParsedAssetsJson;
|
|
18
|
+
type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
|
|
19
|
+
export type AssetMetaSegment = {
|
|
20
|
+
inlinedAsset: InlinedAsset;
|
|
21
|
+
assetContents: string;
|
|
22
|
+
};
|
|
23
|
+
export type BaseHandleData = {
|
|
24
|
+
src: string;
|
|
25
|
+
rest: BaseRestType | [...BaseRestType, ScriptArgsObject];
|
|
26
|
+
};
|
|
17
27
|
export type ScriptArgsObject = {
|
|
18
28
|
strategy?: 'defer' | 'async';
|
|
19
29
|
in_footer?: boolean;
|
|
20
30
|
fetchpriority?: 'auto' | 'low' | 'high';
|
|
21
31
|
module_dependencies?: (string | WPModuleDependency)[];
|
|
22
32
|
};
|
|
23
|
-
type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
|
|
24
33
|
export type InlinedAsset = {
|
|
25
|
-
contents: string;
|
|
26
34
|
position?: 'before' | 'after';
|
|
27
35
|
};
|
|
28
|
-
export type
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
36
|
+
export type IAHandleData = BaseHandleData & AssetMetaSegment;
|
|
37
|
+
export type HandleData = BaseHandleData & (AssetMetaSegment | {
|
|
38
|
+
inlinedAsset?: undefined;
|
|
39
|
+
assetContents?: string;
|
|
40
|
+
});
|
|
33
41
|
export declare const standardLocationNamesMeta: {
|
|
34
42
|
readonly clientView: {
|
|
35
43
|
readonly action: "wp_enqueue_scripts";
|
|
@@ -259,11 +267,10 @@ export declare function resolveLegacyBlockScriptsInFolder(folder: string): strin
|
|
|
259
267
|
* @param writer
|
|
260
268
|
* @param handle
|
|
261
269
|
* @param type 'script_module' is NOT supported at this time; however, it is *handled* in this function
|
|
262
|
-
* @param inlinedAsset
|
|
263
270
|
* @param handleData
|
|
264
|
-
* @param file something that represents the file that is being inlined (this is purely for error-reporting purposes)
|
|
265
271
|
*/
|
|
266
|
-
export declare function appendAddInlineAssetCall(compilation: Compilation, writer: PHPWriter, handle: string, type: 'script' | 'style' | 'script_module',
|
|
272
|
+
export declare function appendAddInlineAssetCall(compilation: Compilation, writer: PHPWriter, handle: string, type: 'script' | 'style' | 'script_module', handleData: IAHandleData): void;
|
|
273
|
+
export declare function wrapInlineAssetContents(compilation: Compilation, wrapperIdPrefix: string, handle: string, contents: string): HereOrNowDoc;
|
|
267
274
|
export declare function synchronousDirIterator(dirPath: string): Generator<import("node:fs").Dirent<string>, void, unknown>;
|
|
268
275
|
/**
|
|
269
276
|
* A type-guarded version of `instanceof Error` for Node.js.
|
package/dist/shared.js
CHANGED
|
@@ -52,6 +52,7 @@ exports.emitPHPWriterAsAsset = emitPHPWriterAsAsset;
|
|
|
52
52
|
exports.dedent = dedent;
|
|
53
53
|
exports.resolveLegacyBlockScriptsInFolder = resolveLegacyBlockScriptsInFolder;
|
|
54
54
|
exports.appendAddInlineAssetCall = appendAddInlineAssetCall;
|
|
55
|
+
exports.wrapInlineAssetContents = wrapInlineAssetContents;
|
|
55
56
|
exports.synchronousDirIterator = synchronousDirIterator;
|
|
56
57
|
exports.instanceOfNodeError = instanceOfNodeError;
|
|
57
58
|
const node_crypto_1 = require("node:crypto");
|
|
@@ -389,30 +390,27 @@ function resolveLegacyBlockScriptsInFolder(folder) {
|
|
|
389
390
|
* @param writer
|
|
390
391
|
* @param handle
|
|
391
392
|
* @param type 'script_module' is NOT supported at this time; however, it is *handled* in this function
|
|
392
|
-
* @param inlinedAsset
|
|
393
393
|
* @param handleData
|
|
394
|
-
* @param file something that represents the file that is being inlined (this is purely for error-reporting purposes)
|
|
395
394
|
*/
|
|
396
|
-
function appendAddInlineAssetCall(compilation, writer, handle, type,
|
|
395
|
+
function appendAddInlineAssetCall(compilation, writer, handle, type, handleData) {
|
|
397
396
|
if (type === 'script_module') {
|
|
398
|
-
throw newWebpackErrorForFile("WordPress does not support inlined script modules",
|
|
397
|
+
throw newWebpackErrorForFile("WordPress does not support inlined script modules", handleData.src);
|
|
399
398
|
}
|
|
400
399
|
if (handleData.rest[0]?.length) { // If there are any dependencies
|
|
401
400
|
compilation.errors.push(newWebpackErrorForFile("Inlined scripts MUST NOT have dependencies. It WILL cause runtime inconsistencies and potentially cause sever performance issues", handleData.src));
|
|
402
401
|
}
|
|
403
|
-
|
|
404
|
-
if (
|
|
405
|
-
contents = inlinedAsset.contents;
|
|
406
|
-
}
|
|
407
|
-
else {
|
|
408
|
-
contents = inlinedAsset.contents.replaceAll(/\/\*#\s+sourceMappingURL=.*?\*\/|\/\/#\s+sourceMappingURL=[^\r\n]*?([\r\n]|$)/gis, "$1");
|
|
409
|
-
}
|
|
410
|
-
const args = [handle, new expressions_1.HereOrNowDoc(`plaudit_inlined_${type}_${(0, node_crypto_1.createHash)('md5').update(handle).digest("hex")}`, contents.trim(), false)];
|
|
411
|
-
if (type === 'script' && inlinedAsset.position === 'before') {
|
|
402
|
+
const args = [handle, wrapInlineAssetContents(compilation, `plaudit_inlined_${type}`, handle, handleData.assetContents)];
|
|
403
|
+
if (type === 'script' && handleData.inlinedAsset.position === 'before') {
|
|
412
404
|
args.push('before');
|
|
413
405
|
}
|
|
414
406
|
writer.call(`wp_add_inline_${type}`, args);
|
|
415
407
|
}
|
|
408
|
+
function wrapInlineAssetContents(compilation, wrapperIdPrefix, handle, contents) {
|
|
409
|
+
if (!compilation.outputOptions.path?.endsWith("-dev")) {
|
|
410
|
+
contents = contents.replaceAll(/\/\*#\s+sourceMappingURL=.*?\*\/|\/\/#\s+sourceMappingURL=[^\r\n]*?([\r\n]|$)/gis, "$1");
|
|
411
|
+
}
|
|
412
|
+
return new expressions_1.HereOrNowDoc(`${wrapperIdPrefix}_${(0, node_crypto_1.createHash)('md5').update(handle).digest("hex")}`, contents.trim(), false);
|
|
413
|
+
}
|
|
416
414
|
function* synchronousDirIterator(dirPath) {
|
|
417
415
|
try {
|
|
418
416
|
using dir = (0, node_fs_1.opendirSync)(dirPath);
|
|
@@ -51,8 +51,15 @@ export declare function unpackEnqueuingControlFlagsFromPathQueryParameters(pathQ
|
|
|
51
51
|
* @param compilation
|
|
52
52
|
* @param file
|
|
53
53
|
* @param flags
|
|
54
|
+
* @param forceRecordContents
|
|
54
55
|
*/
|
|
55
|
-
export declare function convertEnqueuingControlFlagsToScriptArgsObject(compilation: Compilation, file: string, flags: NormalizedEnqueuingControlFlags | undefined): {
|
|
56
|
+
export declare function convertEnqueuingControlFlagsToScriptArgsObject(compilation: Compilation, file: string, flags: NormalizedEnqueuingControlFlags | undefined, forceRecordContents?: boolean): {
|
|
56
57
|
scriptArgsObject?: ScriptArgsObject;
|
|
57
|
-
|
|
58
|
+
assetMeta?: {
|
|
59
|
+
inlinedAsset: InlinedAsset;
|
|
60
|
+
assetContents: string;
|
|
61
|
+
} | {
|
|
62
|
+
inlinedAsset?: undefined;
|
|
63
|
+
assetContents: string | undefined;
|
|
64
|
+
};
|
|
58
65
|
};
|
|
@@ -192,14 +192,19 @@ function unpackEnqueuingControlFlagsFromPathQueryParameters(pathQueryParameters,
|
|
|
192
192
|
* @param compilation
|
|
193
193
|
* @param file
|
|
194
194
|
* @param flags
|
|
195
|
+
* @param forceRecordContents
|
|
195
196
|
*/
|
|
196
|
-
function convertEnqueuingControlFlagsToScriptArgsObject(compilation, file, flags) {
|
|
197
|
+
function convertEnqueuingControlFlagsToScriptArgsObject(compilation, file, flags, forceRecordContents = false) {
|
|
197
198
|
if (flags === undefined) {
|
|
199
|
+
if (forceRecordContents) {
|
|
200
|
+
return { assetMeta: { assetContents: getAssetFileContents(compilation, file) } };
|
|
201
|
+
}
|
|
198
202
|
return {};
|
|
199
203
|
}
|
|
200
204
|
const { strategy, in_footer, inline, position, fetchpriority } = flags;
|
|
201
205
|
const scriptArgsObject = {};
|
|
202
206
|
let inlinedAsset = undefined;
|
|
207
|
+
let assetContents = undefined;
|
|
203
208
|
switch (strategy) {
|
|
204
209
|
case 'async':
|
|
205
210
|
case 'defer':
|
|
@@ -230,7 +235,8 @@ function convertEnqueuingControlFlagsToScriptArgsObject(compilation, file, flags
|
|
|
230
235
|
scriptArgsObject.in_footer = in_footer;
|
|
231
236
|
}
|
|
232
237
|
if (inline) {
|
|
233
|
-
inlinedAsset = {
|
|
238
|
+
inlinedAsset = {};
|
|
239
|
+
assetContents = getAssetFileContents(compilation, file);
|
|
234
240
|
removeFileAndAssetPHP(compilation, file);
|
|
235
241
|
if (position !== undefined) {
|
|
236
242
|
if (!isValidPositionForInlineStrategy(position)) {
|
|
@@ -245,16 +251,20 @@ function convertEnqueuingControlFlagsToScriptArgsObject(compilation, file, flags
|
|
|
245
251
|
scriptArgsObject.in_footer = true;
|
|
246
252
|
}
|
|
247
253
|
}
|
|
254
|
+
else if (forceRecordContents) {
|
|
255
|
+
assetContents = getAssetFileContents(compilation, file);
|
|
256
|
+
}
|
|
248
257
|
if (fetchpriority !== undefined) {
|
|
249
258
|
if (!isValidFetchPriority(fetchpriority)) {
|
|
250
259
|
throw newInvalidFetchPriorityError(fetchpriority, file);
|
|
251
260
|
}
|
|
252
|
-
if (
|
|
261
|
+
if (inline) {
|
|
253
262
|
compilation.warnings.push((0, shared_1.newWebpackErrorForFile)("Fetchpriority has no effect on inlined assets", file));
|
|
254
263
|
}
|
|
255
264
|
scriptArgsObject.fetchpriority = fetchpriority;
|
|
256
265
|
}
|
|
257
|
-
|
|
266
|
+
const assetMeta = inlinedAsset ? { inlinedAsset, assetContents: assetContents } : { assetContents };
|
|
267
|
+
return Object.keys(scriptArgsObject).length > 0 ? { scriptArgsObject, assetMeta } : { assetMeta };
|
|
258
268
|
}
|
|
259
269
|
function removeFileAndAssetPHP(compilation, file) {
|
|
260
270
|
const pathParts = (0, node_path_1.parse)(file);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.15.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"/dist",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@plaudit/gutenberg-api-extensions": "^2.
|
|
31
|
+
"@plaudit/gutenberg-api-extensions": "^2.98.0",
|
|
32
32
|
"@types/browser-sync-webpack-plugin": "^2.2.5",
|
|
33
33
|
"@types/jsdom": "^28.0.3",
|
|
34
34
|
"@types/node": "^25.9.5",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"webpack-bundle-analyzer": "^5.3.1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@plaudit/php-writer": "^1.5.
|
|
45
|
+
"@plaudit/php-writer": "^1.5.5",
|
|
46
46
|
"@plaudit/postcss-color-function": "^5.1.0",
|
|
47
47
|
"@plaudit/postcss-strip-units": "^3.0.0",
|
|
48
48
|
"@plaudit/postcss-variables": "^2.0.1",
|
|
49
49
|
"@wordpress/dependency-extraction-webpack-plugin": "^6.51.0",
|
|
50
50
|
"@wordpress/scripts": "^32.6.0",
|
|
51
|
-
"autoprefixer": "^10.5.
|
|
51
|
+
"autoprefixer": "^10.5.4",
|
|
52
52
|
"browser-sync": "^3.0.4",
|
|
53
53
|
"copy-webpack-plugin": "10.2.4",
|
|
54
54
|
"css-minimizer-webpack-plugin": "^8.0.0",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"fork-ts-checker-webpack-plugin": "^9.1.0",
|
|
57
57
|
"http-proxy-middleware": "^3.0.7",
|
|
58
58
|
"jsdom": "^29.1.1",
|
|
59
|
-
"json2php": "
|
|
60
|
-
"postcss": "^8.5.
|
|
59
|
+
"json2php": "0.0.12",
|
|
60
|
+
"postcss": "^8.5.20",
|
|
61
61
|
"postcss-calc": "^10.1.1",
|
|
62
62
|
"postcss-functions": "^4.0.2",
|
|
63
63
|
"postcss-import": "^16.1.1",
|