@plaudit/webpack-extensions 3.21.2 → 4.0.0-rc.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 +9 -1
- package/USER-GUIDE.md +2 -1
- package/package.json +27 -49
- package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +0 -25
- package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +0 -86
- package/dist/plugins/AbstractBiPhasicGroupPlugin.d.ts +0 -31
- package/dist/plugins/AbstractBiPhasicGroupPlugin.js +0 -91
- package/dist/plugins/AdditionalDependencyInjectorPlugin.d.ts +0 -11
- package/dist/plugins/AdditionalDependencyInjectorPlugin.js +0 -58
- package/dist/plugins/EnhancedBlockJSONPlugin.d.ts +0 -47
- package/dist/plugins/EnhancedBlockJSONPlugin.js +0 -657
- package/dist/plugins/EnhancedDynamicEntryPlugin.d.ts +0 -8
- package/dist/plugins/EnhancedDynamicEntryPlugin.js +0 -14
- package/dist/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +0 -20
- package/dist/plugins/ExtensionsConfigFileGeneratorPlugin.js +0 -191
- package/dist/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +0 -9
- package/dist/plugins/ExtensionsConfigFileGeneratorPluginV1.js +0 -45
- package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts +0 -4
- package/dist/plugins/MiniCSSExtractPluginErrorCleaner.js +0 -15
- package/dist/plugins/MixableBiPhasicGroupAndEntryPlugin.d.ts +0 -6
- package/dist/plugins/MixableBiPhasicGroupAndEntryPlugin.js +0 -13
- package/dist/plugins/MixableBiPhasicGroupPlugin.d.ts +0 -6
- package/dist/plugins/MixableBiPhasicGroupPlugin.js +0 -13
- package/dist/plugins/PackageConfigSanityChecker.d.ts +0 -4
- package/dist/plugins/PackageConfigSanityChecker.js +0 -30
- package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +0 -26
- package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +0 -392
- package/dist/plugins/SpecialAssetHandlingPlugin.d.ts +0 -12
- package/dist/plugins/SpecialAssetHandlingPlugin.js +0 -134
- package/dist/plugins/UnifiedLoaderGenerator.d.ts +0 -21
- package/dist/plugins/UnifiedLoaderGenerator.js +0 -144
- package/dist/plugins/VariablesJSMonitorPlugin.d.ts +0 -7
- package/dist/plugins/VariablesJSMonitorPlugin.js +0 -20
- package/dist/plugins/WPMLConfigBuilder.d.ts +0 -17
- package/dist/plugins/WPMLConfigBuilder.js +0 -472
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +0 -4
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js +0 -147
- package/dist/plugins/index.d.ts +0 -8
- package/dist/plugins/index.js +0 -24
- package/dist/plugins/static-configs.d.ts +0 -3
- package/dist/plugins/static-configs.js +0 -44
- package/dist/shared.d.ts +0 -311
- package/dist/shared.js +0 -536
- package/dist/utils/common-config-helpers.d.ts +0 -28
- package/dist/utils/common-config-helpers.js +0 -489
- package/dist/utils/css-writer.d.ts +0 -4
- package/dist/utils/css-writer.js +0 -46
- package/dist/utils/entrypoint-resolution-logic.d.ts +0 -13
- package/dist/utils/entrypoint-resolution-logic.js +0 -82
- package/dist/utils/location-encoding-filename-parser.d.ts +0 -30
- package/dist/utils/location-encoding-filename-parser.js +0 -120
- package/dist/utils/path-query-and-related-helpers.d.ts +0 -64
- package/dist/utils/path-query-and-related-helpers.js +0 -269
- package/dist/utils/pseudo-semaphore.d.ts +0 -14
- package/dist/utils/pseudo-semaphore.js +0 -79
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts +0 -72
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js +0 -518
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts +0 -56
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js +0 -155
- package/dist/wordpress-scripts-wrapper.d.ts +0 -4
- package/dist/wordpress-scripts-wrapper.js +0 -698
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { RealUsageLocations } from "../shared";
|
|
2
|
-
import { NormalizedEnqueuingControlFlags } from "./path-query-and-related-helpers";
|
|
3
|
-
export type ParsedLocationEncodingFilename = {
|
|
4
|
-
type: 'script' | 'style' | 'script-module';
|
|
5
|
-
locations: RealUsageLocations & {
|
|
6
|
-
register?: boolean | number;
|
|
7
|
-
} & {
|
|
8
|
-
handle?: {
|
|
9
|
-
niceName: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
flags: NormalizedEnqueuingControlFlags;
|
|
13
|
-
};
|
|
14
|
-
export declare function parseLocationEncodingFilename(filename: string): ParsedLocationEncodingFilename | undefined;
|
|
15
|
-
export declare function parseLocationEncodingFilenameForBlock(filename: string, errorBuilder?: (message: string, filename: string) => unknown): (Omit<ParsedLocationEncodingFilename, 'locations'> & {
|
|
16
|
-
locations: Pick<RealUsageLocations, 'clientEditor' | 'clientView'>;
|
|
17
|
-
handle: ParsedLocationEncodingFilename['locations']['handle'];
|
|
18
|
-
}) | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* This handles detecting all keys of standardLocationNamesMeta as well as the values listed in their associated alternate_names properties
|
|
21
|
-
* It MUST be kept in sync with standardLocationNamesMeta
|
|
22
|
-
* @param segment
|
|
23
|
-
*/
|
|
24
|
-
export declare function extractLocationFromPropertyEncodingFilenameSegment(segment: string): {
|
|
25
|
-
readonly locationName: false;
|
|
26
|
-
readonly priority?: undefined;
|
|
27
|
-
} | {
|
|
28
|
-
readonly locationName: "admin" | "analytics" | "blockAssets" | "clientEditor" | "clientView" | "customizer" | "login" | "register";
|
|
29
|
-
readonly priority: number | true;
|
|
30
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseLocationEncodingFilename = parseLocationEncodingFilename;
|
|
4
|
-
exports.parseLocationEncodingFilenameForBlock = parseLocationEncodingFilenameForBlock;
|
|
5
|
-
exports.extractLocationFromPropertyEncodingFilenameSegment = extractLocationFromPropertyEncodingFilenameSegment;
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
const shared_1 = require("../shared");
|
|
8
|
-
function parseLocationEncodingFilename(filename) {
|
|
9
|
-
const { name, ext } = (0, node_path_1.parse)(filename);
|
|
10
|
-
if ((0, shared_1.shouldBeSkipped)(name)) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
let type = /^\.(?:s[ac]|p?c)ss$/i.test(ext) ? 'style' : /^\.m[jt]sx?/i.test(ext) ? 'script-module' : /^\.[jt]sx?/i.test(ext) ? 'script' : false;
|
|
14
|
-
if (type === false) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
const locations = {};
|
|
18
|
-
const flags = {};
|
|
19
|
-
const nameSegments = name.split("."); //Split always returns at least one string
|
|
20
|
-
const typeOverrideMatch = /^(?<enqueuePosition>.+)-(?<typeOverride>script|style|script-module)$|^(?<typeOverride>script|style|script-module)$/.exec(nameSegments[0]);
|
|
21
|
-
if (typeOverrideMatch) {
|
|
22
|
-
nameSegments[0] = typeOverrideMatch.groups?.["enqueuePosition"] ?? "both"; // We override the first segment with the version without the type override
|
|
23
|
-
type = typeOverrideMatch.groups?.["typeOverride"];
|
|
24
|
-
}
|
|
25
|
-
const inlinePattern = /^(?<inline>inline)(?:[-=](?<position>before|after))?$|^strategy[-=](?<inline>inline)(?:-(?<position>before|after))?$/;
|
|
26
|
-
const strategyPattern = /^strategy[-=](?<strategy>eager|lazy|defer|async)$|^(?<strategy>lazy|eager)$/;
|
|
27
|
-
const fetchpriorityPattern = /^fetchpriority[-=](auto|low|high)$/;
|
|
28
|
-
const bothViewAndEditorLocationPattern = /^(?:client-)?(?<both>both)(?:[-=](?<priority>-?\d+))?$/;
|
|
29
|
-
let niceName = undefined;
|
|
30
|
-
for (const segment of nameSegments) {
|
|
31
|
-
const { locationName, priority } = extractLocationFromPropertyEncodingFilenameSegment(segment);
|
|
32
|
-
if (locationName) {
|
|
33
|
-
locations[locationName] = priority;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
const lcSegment = segment.toLowerCase();
|
|
37
|
-
const { both, priority: bothPriority } = bothViewAndEditorLocationPattern.exec(lcSegment)?.groups ?? {};
|
|
38
|
-
if (both) {
|
|
39
|
-
const priority = bothPriority !== undefined ? parseInt(bothPriority) : true;
|
|
40
|
-
locations.clientView = priority;
|
|
41
|
-
locations.clientEditor = priority;
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const { inline, position: inlinePosition } = (inlinePattern.exec(lcSegment)?.groups ?? {});
|
|
45
|
-
if (inline) {
|
|
46
|
-
flags.inline = true;
|
|
47
|
-
flags.position = inlinePosition;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
const strategy = strategyPattern.exec(lcSegment)?.groups?.['strategy']?.toLowerCase();
|
|
51
|
-
if (strategy) {
|
|
52
|
-
flags.strategy = strategy;
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
const fetchpriority = fetchpriorityPattern.exec(lcSegment)?.[1];
|
|
56
|
-
if (fetchpriority !== undefined) {
|
|
57
|
-
flags.fetchpriority = fetchpriority;
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
switch (segment.toLowerCase()) {
|
|
61
|
-
// Loading flags
|
|
62
|
-
case "in-footer":
|
|
63
|
-
case "in_footer":
|
|
64
|
-
flags.in_footer = true;
|
|
65
|
-
break;
|
|
66
|
-
case "in-header":
|
|
67
|
-
case "in_header":
|
|
68
|
-
flags.in_footer = false;
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
if (niceName === undefined) {
|
|
72
|
-
niceName = segment;
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// This means that it wasn't a location-encoding filename
|
|
78
|
-
if (Object.values(locations).length === 0) {
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
if (niceName !== undefined) {
|
|
82
|
-
// We need to kebab-case the nice name value for web-safety
|
|
83
|
-
locations.handle = { niceName: (0, shared_1.kebabCase)(niceName) };
|
|
84
|
-
}
|
|
85
|
-
return { type, locations, flags };
|
|
86
|
-
}
|
|
87
|
-
function parseLocationEncodingFilenameForBlock(filename, errorBuilder = shared_1.newWebpackErrorForFile) {
|
|
88
|
-
const parsedFilename = parseLocationEncodingFilename(filename);
|
|
89
|
-
if (parsedFilename !== undefined) {
|
|
90
|
-
const { handle, ...locations } = parsedFilename.locations;
|
|
91
|
-
if ((0, shared_1.constantKeys)(locations).some(value => value !== 'clientView' && value !== 'clientEditor')) {
|
|
92
|
-
throw errorBuilder(`Block assets cannot be enqueued anywhere other than view, editor, or both. Saw: ${(0, shared_1.constantKeys)(parsedFilename.locations).join(", ")}`, filename);
|
|
93
|
-
}
|
|
94
|
-
if (Object.values(locations).some(value => typeof value === 'number')) {
|
|
95
|
-
throw errorBuilder(`Block assets cannot be enqueued with a priority`, filename);
|
|
96
|
-
}
|
|
97
|
-
return { ...parsedFilename, handle, locations };
|
|
98
|
-
}
|
|
99
|
-
return parsedFilename;
|
|
100
|
-
}
|
|
101
|
-
let standardLocationNamesAndPriorityPatternInFilenameSegment;
|
|
102
|
-
/**
|
|
103
|
-
* This handles detecting all keys of standardLocationNamesMeta as well as the values listed in their associated alternate_names properties
|
|
104
|
-
* It MUST be kept in sync with standardLocationNamesMeta
|
|
105
|
-
* @param segment
|
|
106
|
-
*/
|
|
107
|
-
function extractLocationFromPropertyEncodingFilenameSegment(segment) {
|
|
108
|
-
if (!standardLocationNamesAndPriorityPatternInFilenameSegment) {
|
|
109
|
-
const matchableLocationNames = (0, shared_1.iterableStandardLocationNamesMeta)()
|
|
110
|
-
.flatMap(([standardName, { alternate_names = [] }]) => [standardName, ...alternate_names])
|
|
111
|
-
.join("|");
|
|
112
|
-
standardLocationNamesAndPriorityPatternInFilenameSegment = new RegExp(`^(?<locationName>${matchableLocationNames}|register)(?:[-=](?<priority>-?\\d+))?$`);
|
|
113
|
-
}
|
|
114
|
-
const { locationName, priority: rawPriority } = standardLocationNamesAndPriorityPatternInFilenameSegment.exec(segment)?.groups ?? {};
|
|
115
|
-
if (!locationName) {
|
|
116
|
-
return { locationName: false };
|
|
117
|
-
}
|
|
118
|
-
const priority = rawPriority !== undefined ? parseInt(rawPriority) : true;
|
|
119
|
-
return { locationName: (0, shared_1.normalizeLocationName)(locationName), priority };
|
|
120
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { Compilation } from "webpack";
|
|
2
|
-
import { type InlinedAsset, type PathQueryParameters, type ScriptArgsObject, type UsageLocations } from "../shared";
|
|
3
|
-
export declare function getAssetFileContents(compilation: Compilation, name: string): string;
|
|
4
|
-
export declare function unpackPotentiallyPrefixedFilePath(filePath: string): [string, PathQueryParameters | undefined];
|
|
5
|
-
/**
|
|
6
|
-
* The following substitutions are performed:
|
|
7
|
-
* <ul>
|
|
8
|
-
* <li>parameters without an assigned value -> a boolean parameter set to true</li>
|
|
9
|
-
* <li>true and false -> their boolean equivalents</li>
|
|
10
|
-
* <li>numeric values -> their number equivalents</li>
|
|
11
|
-
* </ul>
|
|
12
|
-
*
|
|
13
|
-
* @param pathQuery the part after the "?" in a webpack inclusion path
|
|
14
|
-
* @return the query as an object with common string -> JS type conversions already performed
|
|
15
|
-
*/
|
|
16
|
-
export declare function unpackPathQuery(pathQuery: string): PathQueryParameters | undefined;
|
|
17
|
-
export type LoadingStrategy = boolean | 'defer' | 'async' | 'eager' | 'lazy' | 'inline';
|
|
18
|
-
export declare function newInvalidLoadingStrategyError(strategy: unknown, file: string): import("webpack").WebpackError;
|
|
19
|
-
export type InFooter = boolean;
|
|
20
|
-
export declare function isValidInFooter(in_footer: unknown): in_footer is InFooter;
|
|
21
|
-
export declare function newInvalidInFooterError(in_footer: unknown, file: string): import("webpack").WebpackError;
|
|
22
|
-
export type FetchPriority = 'auto' | 'low' | 'high';
|
|
23
|
-
export declare function isValidFetchPriority(fetchpriority: unknown): fetchpriority is FetchPriority;
|
|
24
|
-
export declare function newInvalidFetchPriorityError(fetchpriority: unknown, file: string): import("webpack").WebpackError;
|
|
25
|
-
export type PositionForInlineStrategy = 'before' | 'after';
|
|
26
|
-
export declare function isValidPositionForInlineStrategy(position: unknown): position is PositionForInlineStrategy;
|
|
27
|
-
export declare function newInvalidPositionForInlineStrategyError(position: unknown, file: string): import("webpack").WebpackError;
|
|
28
|
-
/**
|
|
29
|
-
* This function ensures that the passed pathQueryParameters are normalized for the config-loading step, NOT the emission step
|
|
30
|
-
*/
|
|
31
|
-
export type NormalizedEnqueuingControlFlags = {
|
|
32
|
-
strategy?: Exclude<LoadingStrategy, 'inline'>;
|
|
33
|
-
in_footer?: InFooter;
|
|
34
|
-
inline?: boolean;
|
|
35
|
-
fetchpriority?: FetchPriority;
|
|
36
|
-
position?: 'before' | 'after';
|
|
37
|
-
};
|
|
38
|
-
export declare function mergeTwoEnqueuingControlFlagSets(file: string, ...argsBlocks: (NormalizedEnqueuingControlFlags | undefined)[]): NormalizedEnqueuingControlFlags | undefined;
|
|
39
|
-
export declare function unpackEnqueuingControlFlagsFromPathQueryParameters(pathQueryParameters: PathQueryParameters | undefined, file: string, sourceType: 'registerScriptArgs' | 'path query parameters'): {
|
|
40
|
-
flags?: NormalizedEnqueuingControlFlags;
|
|
41
|
-
handle?: UsageLocations['handle'];
|
|
42
|
-
remainder?: PathQueryParameters;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* This function does a few things:
|
|
46
|
-
* <ol>
|
|
47
|
-
* <li>It converts the strategy, in_footer, and fetchpriority flags into a valid script args object</li>
|
|
48
|
-
* <li>If inline is true, it records the contents of the asset and the value of the position flag for later injection and removes the asset from the compilation output</li>
|
|
49
|
-
* </ol>
|
|
50
|
-
* @param compilation
|
|
51
|
-
* @param file
|
|
52
|
-
* @param flags
|
|
53
|
-
* @param forceRecordContents
|
|
54
|
-
*/
|
|
55
|
-
export declare function convertEnqueuingControlFlagsToScriptArgsObject(compilation: Compilation, file: string, flags: NormalizedEnqueuingControlFlags | undefined, forceRecordContents?: boolean): {
|
|
56
|
-
scriptArgsObject?: ScriptArgsObject;
|
|
57
|
-
assetMeta?: {
|
|
58
|
-
inlinedAsset: InlinedAsset;
|
|
59
|
-
assetContents: string;
|
|
60
|
-
} | {
|
|
61
|
-
inlinedAsset?: undefined;
|
|
62
|
-
assetContents: string | undefined;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAssetFileContents = getAssetFileContents;
|
|
4
|
-
exports.unpackPotentiallyPrefixedFilePath = unpackPotentiallyPrefixedFilePath;
|
|
5
|
-
exports.unpackPathQuery = unpackPathQuery;
|
|
6
|
-
exports.newInvalidLoadingStrategyError = newInvalidLoadingStrategyError;
|
|
7
|
-
exports.isValidInFooter = isValidInFooter;
|
|
8
|
-
exports.newInvalidInFooterError = newInvalidInFooterError;
|
|
9
|
-
exports.isValidFetchPriority = isValidFetchPriority;
|
|
10
|
-
exports.newInvalidFetchPriorityError = newInvalidFetchPriorityError;
|
|
11
|
-
exports.isValidPositionForInlineStrategy = isValidPositionForInlineStrategy;
|
|
12
|
-
exports.newInvalidPositionForInlineStrategyError = newInvalidPositionForInlineStrategyError;
|
|
13
|
-
exports.mergeTwoEnqueuingControlFlagSets = mergeTwoEnqueuingControlFlagSets;
|
|
14
|
-
exports.unpackEnqueuingControlFlagsFromPathQueryParameters = unpackEnqueuingControlFlagsFromPathQueryParameters;
|
|
15
|
-
exports.convertEnqueuingControlFlagsToScriptArgsObject = convertEnqueuingControlFlagsToScriptArgsObject;
|
|
16
|
-
const node_path_1 = require("node:path");
|
|
17
|
-
const shared_1 = require("../shared");
|
|
18
|
-
function getAssetFileContents(compilation, name) {
|
|
19
|
-
const asset = compilation.getAsset(name);
|
|
20
|
-
if (!asset) {
|
|
21
|
-
throw new Error(`${name} is unexpectedly missing`);
|
|
22
|
-
}
|
|
23
|
-
const assetSource = asset.source.source();
|
|
24
|
-
return typeof assetSource === 'string' ? assetSource : assetSource?.toString('utf-8');
|
|
25
|
-
}
|
|
26
|
-
function unpackPotentiallyPrefixedFilePath(filePath) {
|
|
27
|
-
if (filePath.startsWith("file:")) {
|
|
28
|
-
filePath = filePath.substring(5);
|
|
29
|
-
}
|
|
30
|
-
const queryStart = filePath.indexOf("?");
|
|
31
|
-
if (queryStart === -1) {
|
|
32
|
-
return [filePath, undefined];
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return [filePath.substring(0, queryStart), unpackPathQuery(filePath.substring(queryStart + 1))];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* The following substitutions are performed:
|
|
40
|
-
* <ul>
|
|
41
|
-
* <li>parameters without an assigned value -> a boolean parameter set to true</li>
|
|
42
|
-
* <li>true and false -> their boolean equivalents</li>
|
|
43
|
-
* <li>numeric values -> their number equivalents</li>
|
|
44
|
-
* </ul>
|
|
45
|
-
*
|
|
46
|
-
* @param pathQuery the part after the "?" in a webpack inclusion path
|
|
47
|
-
* @return the query as an object with common string -> JS type conversions already performed
|
|
48
|
-
*/
|
|
49
|
-
function unpackPathQuery(pathQuery) {
|
|
50
|
-
if (!pathQuery) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
return new URLSearchParams(pathQuery.replaceAll(/((?:[&?]|^)\w+)(&|$)/g, "$1=true$2")).entries()
|
|
54
|
-
.map(([key, value]) => {
|
|
55
|
-
if (value === 'true') {
|
|
56
|
-
return [key, true];
|
|
57
|
-
}
|
|
58
|
-
if (value === 'false') {
|
|
59
|
-
return [key, false];
|
|
60
|
-
}
|
|
61
|
-
if (Number.isFinite(+value)) {
|
|
62
|
-
return [key, +value];
|
|
63
|
-
}
|
|
64
|
-
return [key, value];
|
|
65
|
-
})
|
|
66
|
-
.reduce((collector, [key, value]) => {
|
|
67
|
-
if (collector[key] instanceof Array) {
|
|
68
|
-
collector[key].push(value);
|
|
69
|
-
}
|
|
70
|
-
else if (key in collector) {
|
|
71
|
-
collector[key] = [collector[key], value];
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
collector[key] = value;
|
|
75
|
-
}
|
|
76
|
-
return collector;
|
|
77
|
-
}, {});
|
|
78
|
-
}
|
|
79
|
-
const namedStrategies = ['defer', 'async', 'eager', 'lazy', 'inline'];
|
|
80
|
-
function newInvalidLoadingStrategyError(strategy, file) {
|
|
81
|
-
return (0, shared_1.newWebpackErrorForFile)(`The strategy was invalid. Received: ${strategy}, Expected: undefined|boolean|'${namedStrategies.join("'|'")}'`, file);
|
|
82
|
-
}
|
|
83
|
-
function isValidInFooter(in_footer) {
|
|
84
|
-
return typeof in_footer === 'boolean';
|
|
85
|
-
}
|
|
86
|
-
function newInvalidInFooterError(in_footer, file) {
|
|
87
|
-
return (0, shared_1.newWebpackErrorForFile)(`The in_footer value was invalid. Received: ${in_footer}, Expected: undefined|boolean`, file);
|
|
88
|
-
}
|
|
89
|
-
function isValidFetchPriority(fetchpriority) {
|
|
90
|
-
return typeof fetchpriority === 'string' && ["auto", "low", "high"].includes(fetchpriority);
|
|
91
|
-
}
|
|
92
|
-
function newInvalidFetchPriorityError(fetchpriority, file) {
|
|
93
|
-
return (0, shared_1.newWebpackErrorForFile)(`The fetchpriority value was invalid. Received: ${fetchpriority}, Expected: undefined|'auto'|'low'|'high'`, file);
|
|
94
|
-
}
|
|
95
|
-
function isValidPositionForInlineStrategy(position) {
|
|
96
|
-
return typeof position === 'string' && ["before", "after"].includes(position);
|
|
97
|
-
}
|
|
98
|
-
function newInvalidPositionForInlineStrategyError(position, file) {
|
|
99
|
-
return (0, shared_1.newWebpackErrorForFile)(`The position value for the inlined asset was invalid. Received: ${position}, Expected: undefined|'before'|'after'`, file);
|
|
100
|
-
}
|
|
101
|
-
function mergeTwoEnqueuingControlFlagSets(file, ...argsBlocks) {
|
|
102
|
-
const filteredArgsBlocks = argsBlocks.filter(argsBlock => argsBlock !== undefined);
|
|
103
|
-
if (filteredArgsBlocks.length === 0) {
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
if ((0, shared_1.arrayIsLength)(filteredArgsBlocks, 1)) {
|
|
107
|
-
return filteredArgsBlocks[0];
|
|
108
|
-
}
|
|
109
|
-
const res = {};
|
|
110
|
-
for (const key of ['strategy', 'in_footer', 'fetchpriority', 'inline', 'position']) {
|
|
111
|
-
for (const argsBlock of filteredArgsBlocks) {
|
|
112
|
-
if (key in argsBlock) {
|
|
113
|
-
if (!(key in res)) {
|
|
114
|
-
res[key] = argsBlock[key];
|
|
115
|
-
}
|
|
116
|
-
else if (argsBlock[key] !== res[key]) {
|
|
117
|
-
throw (0, shared_1.newWebpackErrorForFile)(`The ${key} values in the control flag sets for the file conflict`, file);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return res;
|
|
123
|
-
}
|
|
124
|
-
function unpackEnqueuingControlFlagsFromPathQueryParameters(pathQueryParameters, file, sourceType) {
|
|
125
|
-
if (pathQueryParameters === undefined) {
|
|
126
|
-
return {};
|
|
127
|
-
}
|
|
128
|
-
const { strategy, in_footer: normalizedInFooter, 'in-footer': alternateInFooter, fetchpriority, position, handle, ...remainder } = pathQueryParameters;
|
|
129
|
-
let flags;
|
|
130
|
-
switch (strategy) {
|
|
131
|
-
case 'defer':
|
|
132
|
-
case 'async':
|
|
133
|
-
flags = { strategy };
|
|
134
|
-
break;
|
|
135
|
-
case 'eager':
|
|
136
|
-
flags = { strategy: 'eager' };
|
|
137
|
-
break;
|
|
138
|
-
case 'lazy':
|
|
139
|
-
flags = { strategy: 'defer', in_footer: true };
|
|
140
|
-
break;
|
|
141
|
-
case 'inline':
|
|
142
|
-
flags = { inline: true };
|
|
143
|
-
break;
|
|
144
|
-
case true:
|
|
145
|
-
case false:
|
|
146
|
-
flags = { in_footer: strategy };
|
|
147
|
-
break;
|
|
148
|
-
case null:
|
|
149
|
-
case undefined:
|
|
150
|
-
flags = {};
|
|
151
|
-
break;
|
|
152
|
-
default:
|
|
153
|
-
throw newInvalidLoadingStrategyError(strategy, file);
|
|
154
|
-
}
|
|
155
|
-
if (flags.inline === undefined && pathQueryParameters['inline'] !== undefined) {
|
|
156
|
-
flags.inline = !!pathQueryParameters['inline'];
|
|
157
|
-
}
|
|
158
|
-
const in_footer = normalizedInFooter ?? alternateInFooter;
|
|
159
|
-
if (in_footer !== undefined) {
|
|
160
|
-
if (!isValidInFooter(in_footer)) {
|
|
161
|
-
throw newInvalidInFooterError(in_footer, file);
|
|
162
|
-
}
|
|
163
|
-
flags.in_footer = in_footer;
|
|
164
|
-
}
|
|
165
|
-
if (pathQueryParameters['fetchpriority'] !== undefined) {
|
|
166
|
-
if (!isValidFetchPriority(pathQueryParameters['fetchpriority'])) {
|
|
167
|
-
throw newInvalidFetchPriorityError(pathQueryParameters['fetchpriority'], file);
|
|
168
|
-
}
|
|
169
|
-
if (flags.fetchpriority !== undefined && flags.fetchpriority !== pathQueryParameters['fetchpriority']) {
|
|
170
|
-
throw (0, shared_1.newWebpackErrorForFile)(`The strategy and fetchpriority values in the ${sourceType} for the file conflict. Got ${strategy} and ${pathQueryParameters['fetchpriority']}`, file);
|
|
171
|
-
}
|
|
172
|
-
flags.fetchpriority = pathQueryParameters['fetchpriority'];
|
|
173
|
-
}
|
|
174
|
-
if (flags.inline && (pathQueryParameters['position'] === 'before' || pathQueryParameters['position'] === 'after')) {
|
|
175
|
-
flags.position = pathQueryParameters['position'];
|
|
176
|
-
}
|
|
177
|
-
if (handle !== undefined && (typeof handle !== 'string' || handle.length < 5)) {
|
|
178
|
-
throw (0, shared_1.newWebpackErrorForFile)(`The handle was invalid. Received: ${handle}. Expected: a string that is at least 5 characters long`, file);
|
|
179
|
-
}
|
|
180
|
-
return Object.keys(flags).length > 0 ? { flags, handle, remainder } : { handle, remainder };
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* This function does a few things:
|
|
184
|
-
* <ol>
|
|
185
|
-
* <li>It converts the strategy, in_footer, and fetchpriority flags into a valid script args object</li>
|
|
186
|
-
* <li>If inline is true, it records the contents of the asset and the value of the position flag for later injection and removes the asset from the compilation output</li>
|
|
187
|
-
* </ol>
|
|
188
|
-
* @param compilation
|
|
189
|
-
* @param file
|
|
190
|
-
* @param flags
|
|
191
|
-
* @param forceRecordContents
|
|
192
|
-
*/
|
|
193
|
-
function convertEnqueuingControlFlagsToScriptArgsObject(compilation, file, flags, forceRecordContents = false) {
|
|
194
|
-
if (flags === undefined) {
|
|
195
|
-
if (forceRecordContents) {
|
|
196
|
-
return { assetMeta: { assetContents: getAssetFileContents(compilation, file) } };
|
|
197
|
-
}
|
|
198
|
-
return {};
|
|
199
|
-
}
|
|
200
|
-
const { strategy, in_footer, inline, position, fetchpriority } = flags;
|
|
201
|
-
const scriptArgsObject = {};
|
|
202
|
-
let inlinedAsset = undefined;
|
|
203
|
-
let assetContents = undefined;
|
|
204
|
-
switch (strategy) {
|
|
205
|
-
case 'async':
|
|
206
|
-
case 'defer':
|
|
207
|
-
scriptArgsObject.strategy = strategy;
|
|
208
|
-
break;
|
|
209
|
-
case 'eager':
|
|
210
|
-
scriptArgsObject.in_footer = false;
|
|
211
|
-
break;
|
|
212
|
-
case 'lazy':
|
|
213
|
-
scriptArgsObject.strategy = 'defer';
|
|
214
|
-
scriptArgsObject.in_footer = true;
|
|
215
|
-
break;
|
|
216
|
-
case true:
|
|
217
|
-
case false:
|
|
218
|
-
scriptArgsObject.in_footer = strategy;
|
|
219
|
-
break;
|
|
220
|
-
case null:
|
|
221
|
-
case undefined:
|
|
222
|
-
// This is included because are effectively validating the strategy value with this switch statement, and "not defined" is a valid state
|
|
223
|
-
break;
|
|
224
|
-
default:
|
|
225
|
-
throw newInvalidLoadingStrategyError(strategy, file);
|
|
226
|
-
}
|
|
227
|
-
if (in_footer !== undefined) {
|
|
228
|
-
if (!isValidInFooter(in_footer)) {
|
|
229
|
-
throw newInvalidInFooterError(in_footer, file);
|
|
230
|
-
}
|
|
231
|
-
scriptArgsObject.in_footer = in_footer;
|
|
232
|
-
}
|
|
233
|
-
if (inline) {
|
|
234
|
-
inlinedAsset = {};
|
|
235
|
-
assetContents = getAssetFileContents(compilation, file);
|
|
236
|
-
removeFileAndAssetPHP(compilation, file);
|
|
237
|
-
if (position !== undefined) {
|
|
238
|
-
if (!isValidPositionForInlineStrategy(position)) {
|
|
239
|
-
throw newInvalidPositionForInlineStrategyError(position, file);
|
|
240
|
-
}
|
|
241
|
-
inlinedAsset.position = position;
|
|
242
|
-
}
|
|
243
|
-
if (inlinedAsset.position !== 'before' && scriptArgsObject.strategy !== undefined) {
|
|
244
|
-
compilation.warnings.push((0, shared_1.newWebpackErrorForFile)("Deferred and async scripts that have inlined JS attached in the 'after' position will cause WordPress to convert all of their dependencies to eager scripts at runtime", file));
|
|
245
|
-
}
|
|
246
|
-
if (scriptArgsObject.in_footer === undefined) {
|
|
247
|
-
scriptArgsObject.in_footer = true;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
else if (forceRecordContents) {
|
|
251
|
-
assetContents = getAssetFileContents(compilation, file);
|
|
252
|
-
}
|
|
253
|
-
if (fetchpriority !== undefined) {
|
|
254
|
-
if (!isValidFetchPriority(fetchpriority)) {
|
|
255
|
-
throw newInvalidFetchPriorityError(fetchpriority, file);
|
|
256
|
-
}
|
|
257
|
-
if (inline) {
|
|
258
|
-
compilation.warnings.push((0, shared_1.newWebpackErrorForFile)("Fetchpriority has no effect on inlined assets", file));
|
|
259
|
-
}
|
|
260
|
-
scriptArgsObject.fetchpriority = fetchpriority;
|
|
261
|
-
}
|
|
262
|
-
const assetMeta = inlinedAsset ? { inlinedAsset, assetContents: assetContents } : { assetContents };
|
|
263
|
-
return Object.keys(scriptArgsObject).length > 0 ? { scriptArgsObject, assetMeta } : { assetMeta };
|
|
264
|
-
}
|
|
265
|
-
function removeFileAndAssetPHP(compilation, file) {
|
|
266
|
-
const pathParts = (0, node_path_1.parse)(file);
|
|
267
|
-
compilation.deleteAsset((0, node_path_1.join)(pathParts.dir, pathParts.name) + ".asset.php");
|
|
268
|
-
compilation.deleteAsset(file);
|
|
269
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare class PseudoSemaphore<T> {
|
|
2
|
-
private readonly name;
|
|
3
|
-
private flagSet;
|
|
4
|
-
private readonly flags;
|
|
5
|
-
private readonly debugMode;
|
|
6
|
-
constructor(name: string);
|
|
7
|
-
register(id: string): void;
|
|
8
|
-
resolve(id: string, value: T | undefined): void;
|
|
9
|
-
reject(id: string): void;
|
|
10
|
-
reset(id: string): void;
|
|
11
|
-
private getFlag;
|
|
12
|
-
private initializeFlag;
|
|
13
|
-
wait(): Promise<T[]>;
|
|
14
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PseudoSemaphore = void 0;
|
|
4
|
-
class PseudoSemaphore {
|
|
5
|
-
name;
|
|
6
|
-
flagSet = 0;
|
|
7
|
-
flags = new Map();
|
|
8
|
-
debugMode = false;
|
|
9
|
-
constructor(name) {
|
|
10
|
-
this.name = name;
|
|
11
|
-
}
|
|
12
|
-
register(id) {
|
|
13
|
-
if (this.flags.has(id)) {
|
|
14
|
-
throw new Error(`A semaphore with an id of "${id}" already exists`);
|
|
15
|
-
}
|
|
16
|
-
this.initializeFlag(id);
|
|
17
|
-
this.resolve(id, undefined);
|
|
18
|
-
}
|
|
19
|
-
resolve(id, value) {
|
|
20
|
-
if (this.debugMode) {
|
|
21
|
-
console.error("RESOLVED:", this.name, id);
|
|
22
|
-
}
|
|
23
|
-
const flag = this.getFlag(id);
|
|
24
|
-
flag[1].resolve(value); // This is deliberately unsafe - I would rather see a cascading failure than a silent one
|
|
25
|
-
flag[2] = true;
|
|
26
|
-
}
|
|
27
|
-
reject(id) {
|
|
28
|
-
if (this.debugMode) {
|
|
29
|
-
console.error("REJECTED:", this.name, id);
|
|
30
|
-
}
|
|
31
|
-
const flag = this.getFlag(id);
|
|
32
|
-
flag[1].reject(); // This is deliberately unsafe - I would rather see a cascading failure than a silent one
|
|
33
|
-
flag[2] = true;
|
|
34
|
-
}
|
|
35
|
-
reset(id) {
|
|
36
|
-
if (this.debugMode) {
|
|
37
|
-
console.error("RESET:", this.name, id);
|
|
38
|
-
}
|
|
39
|
-
const flag = this.getFlag(id);
|
|
40
|
-
// We reject if we reset early to avoid any permanently-hanging promises
|
|
41
|
-
if (!flag[2]) {
|
|
42
|
-
flag[1].reject(); // This is deliberately unsafe - I would rather see a cascading failure than a silent one
|
|
43
|
-
}
|
|
44
|
-
this.initializeFlag(id);
|
|
45
|
-
}
|
|
46
|
-
getFlag(id) {
|
|
47
|
-
const flag = this.flags.get(id);
|
|
48
|
-
if (flag === undefined) {
|
|
49
|
-
throw new Error(`A semaphore with an id of "${id}" does not exist`);
|
|
50
|
-
}
|
|
51
|
-
return flag;
|
|
52
|
-
}
|
|
53
|
-
initializeFlag(id) {
|
|
54
|
-
const controller = {};
|
|
55
|
-
const promise = new Promise((resolve, reject) => {
|
|
56
|
-
controller.resolve = resolve;
|
|
57
|
-
controller.reject = reject;
|
|
58
|
-
});
|
|
59
|
-
this.flags.set(id, [promise, controller, false]);
|
|
60
|
-
this.flagSet++;
|
|
61
|
-
promise.catch(() => { });
|
|
62
|
-
}
|
|
63
|
-
async wait() {
|
|
64
|
-
let currentFlagSet;
|
|
65
|
-
let res;
|
|
66
|
-
do {
|
|
67
|
-
currentFlagSet = this.flagSet;
|
|
68
|
-
if (this.debugMode) {
|
|
69
|
-
console.log("WAITING FOR:", this.name, currentFlagSet);
|
|
70
|
-
}
|
|
71
|
-
res = (await Promise.all(this.flags.values().map(flag => flag[0]))).filter(r => r !== undefined);
|
|
72
|
-
if (this.debugMode) {
|
|
73
|
-
console.log("POSSIBLY FINISHED WAITING FOR:", this.name, currentFlagSet);
|
|
74
|
-
}
|
|
75
|
-
} while (currentFlagSet !== this.flagSet);
|
|
76
|
-
return res;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.PseudoSemaphore = PseudoSemaphore;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type LegacyDependencyExtractionWebpackPlugin from "@wordpress/dependency-extraction-webpack-plugin";
|
|
2
|
-
import { Compilation, Compiler, Module, type TemplatePath } from "webpack";
|
|
3
|
-
export interface EnhancedDependencyExtractionWebpackPluginOptions {
|
|
4
|
-
injectPolyfill?: boolean;
|
|
5
|
-
useDefaults?: boolean;
|
|
6
|
-
outputFilename?: TemplatePath;
|
|
7
|
-
requestToExternal?: (request: string) => string | string[] | undefined;
|
|
8
|
-
requestToExternalModule?: (request: string) => string | boolean | undefined;
|
|
9
|
-
requestToHandle?: (request: string) => string | undefined;
|
|
10
|
-
requestToScriptModule?: (request: string) => string | boolean | Error | undefined;
|
|
11
|
-
externalizedReport?: string | boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare class EnhancedDependencyExtractionWebpackPlugin {
|
|
14
|
-
/**
|
|
15
|
-
* Track requests that are externalized.
|
|
16
|
-
*
|
|
17
|
-
* Because we don't have a closed set of dependencies, we need to track what has
|
|
18
|
-
* been externalized so we can recognize them in a later phase when the dependency
|
|
19
|
-
* lists are generated.
|
|
20
|
-
*/
|
|
21
|
-
private readonly externalizedDeps;
|
|
22
|
-
private readonly options;
|
|
23
|
-
/**
|
|
24
|
-
* Track requests that a script build externalizes as script modules.
|
|
25
|
-
*
|
|
26
|
-
* These can only be reached through a runtime `import()`, which requires
|
|
27
|
-
* support for dynamic import in the output environment. The set is used
|
|
28
|
-
* to report an actionable error when that support is missing.
|
|
29
|
-
*/
|
|
30
|
-
private readonly scriptModuleDepsInScript;
|
|
31
|
-
/**
|
|
32
|
-
* Whether we should use modules. This will be set later to match webpack's `output.module` option.
|
|
33
|
-
*/
|
|
34
|
-
private useModules;
|
|
35
|
-
constructor(options: EnhancedDependencyExtractionWebpackPluginOptions | LegacyDependencyExtractionWebpackPlugin | EnhancedDependencyExtractionWebpackPlugin);
|
|
36
|
-
/**
|
|
37
|
-
* Convert a script module request to an external suitable for a script
|
|
38
|
-
* build.
|
|
39
|
-
*
|
|
40
|
-
* A classic script cannot contain a static `import`, so the `module`
|
|
41
|
-
* external type is not usable here: the script module has to be reached
|
|
42
|
-
* through a runtime `import()`, which is the `import` external type. The
|
|
43
|
-
* bare specifier is resolved by the import map that WordPress prints for
|
|
44
|
-
* enqueued script modules.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} request Original module request.
|
|
47
|
-
* @param {string|boolean|Error=} external Result of a script module external resolution.
|
|
48
|
-
* @return {string|undefined} The resulting external definition.
|
|
49
|
-
*/
|
|
50
|
-
static toScriptModuleExternalInScript(request: string, external?: string | boolean | Error): string | undefined;
|
|
51
|
-
private readonly externalizeWpDeps;
|
|
52
|
-
/**
|
|
53
|
-
* @param {string} request
|
|
54
|
-
* @return {string} Mapped dependency name
|
|
55
|
-
*/
|
|
56
|
-
protected mapRequestToDependency(request: string): string;
|
|
57
|
-
apply(compiler: Compiler): void;
|
|
58
|
-
/**
|
|
59
|
-
* Check for magic comments before minification, so minification doesn't have to preserve them.
|
|
60
|
-
*/
|
|
61
|
-
checkForMagicComments(compilation: Compilation): void;
|
|
62
|
-
addAssets(compilation: Compilation): void;
|
|
63
|
-
private static readonly staticDepsCurrent;
|
|
64
|
-
private static readonly staticDepsCache;
|
|
65
|
-
/**
|
|
66
|
-
* Can we trace a line of static dependencies from an entry to a module
|
|
67
|
-
*
|
|
68
|
-
* @return {boolean} True if there is a static import path to the root
|
|
69
|
-
*/
|
|
70
|
-
static hasStaticDependencyPathToRoot(compilation: Compilation, block: Module): boolean;
|
|
71
|
-
readonly addExternalizedDep: (value: string) => Set<string>;
|
|
72
|
-
}
|