@plaudit/webpack-extensions 2.89.1 → 3.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 +0 -105
- package/USER-GUIDE.md +81 -117
- package/{dist → build}/plugins/EnhancedBlockJSONPlugin.d.ts +4 -7
- package/{dist → build}/plugins/EnhancedBlockJSONPlugin.js +53 -116
- package/{dist → build}/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +3 -7
- package/{dist → build}/plugins/ExtensionsConfigFileGeneratorPlugin.js +10 -74
- package/{dist → build}/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +1 -1
- package/{dist → build}/plugins/ExtensionsConfigFileGeneratorPluginV1.js +0 -4
- package/{dist → build}/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +20 -46
- package/{dist → build}/plugins/UnifiedLoaderGenerator.d.ts +2 -1
- package/build/plugins/static-configs.d.ts +3 -0
- package/build/plugins/static-configs.js +33 -0
- package/{dist → build}/shared.d.ts +18 -79
- package/{dist → build}/shared.js +4 -94
- package/{dist → build}/utils/common-config-helpers.d.ts +1 -1
- package/{dist → build}/utils/common-config-helpers.js +49 -126
- package/{dist → build}/wordpress-scripts-wrapper.js +36 -70
- package/package.json +26 -36
- package/dist/plugins/static-configs.d.ts +0 -3
- package/dist/plugins/static-configs.js +0 -91
- package/dist/utils/entrypoint-resolution-logic.d.ts +0 -10
- package/dist/utils/entrypoint-resolution-logic.js +0 -84
- package/dist/utils/location-encoding-filename-parser.d.ts +0 -26
- package/dist/utils/location-encoding-filename-parser.js +0 -118
- package/dist/utils/path-query-and-related-helpers.d.ts +0 -58
- package/dist/utils/path-query-and-related-helpers.js +0 -263
- /package/{dist → build}/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +0 -0
- /package/{dist → build}/plugins/AbstractBiPhasicGroupPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/AbstractBiPhasicGroupPlugin.js +0 -0
- /package/{dist → build}/plugins/AdditionalDependencyInjectorPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/AdditionalDependencyInjectorPlugin.js +0 -0
- /package/{dist → build}/plugins/BrowserSyncPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/BrowserSyncPlugin.js +0 -0
- /package/{dist → build}/plugins/EnhancedDynamicEntryPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/EnhancedDynamicEntryPlugin.js +0 -0
- /package/{dist → build}/plugins/MiniCSSExtractPluginErrorCleaner.d.ts +0 -0
- /package/{dist → build}/plugins/MiniCSSExtractPluginErrorCleaner.js +0 -0
- /package/{dist → build}/plugins/PackageConfigSanityChecker.d.ts +0 -0
- /package/{dist → build}/plugins/PackageConfigSanityChecker.js +0 -0
- /package/{dist → build}/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/SpecialAssetHandlingPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/SpecialAssetHandlingPlugin.js +0 -0
- /package/{dist → build}/plugins/UnifiedLoaderGenerator.js +0 -0
- /package/{dist → build}/plugins/VariablesJSMonitorPlugin.d.ts +0 -0
- /package/{dist → build}/plugins/VariablesJSMonitorPlugin.js +0 -0
- /package/{dist → build}/plugins/WPMLConfigBuilder.d.ts +0 -0
- /package/{dist → build}/plugins/WPMLConfigBuilder.js +0 -0
- /package/{dist → build}/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +0 -0
- /package/{dist → build}/plugins/dependency-extraction-webpack-plugin-config-builder.js +0 -0
- /package/{dist → build}/utils/css-writer.d.ts +0 -0
- /package/{dist → build}/utils/css-writer.js +0 -0
- /package/{dist → build}/utils/pseduo-semaphore.d.ts +0 -0
- /package/{dist → build}/utils/pseduo-semaphore.js +0 -0
- /package/{dist → build}/wordpress-scripts-wrapper.d.ts +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.PlainEntrypointsConfigFileGeneratorPlugin = void 0;
|
|
4
|
-
const node_path_1 = require("node:path");
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
5
8
|
const php_writer_1 = require("@plaudit/php-writer");
|
|
6
9
|
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
7
10
|
const shared_1 = require("../shared");
|
|
8
11
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
9
|
-
const path_query_and_related_helpers_1 = require("../utils/path-query-and-related-helpers");
|
|
10
12
|
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
11
13
|
const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
|
|
12
14
|
const webpack_1 = require("webpack");
|
|
@@ -24,10 +26,9 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
24
26
|
this.useUnifiedLoader = useUnifiedLoader;
|
|
25
27
|
}
|
|
26
28
|
generatePlainEntrypointsLoader(compilation, assets) {
|
|
27
|
-
const emitDir =
|
|
29
|
+
const emitDir = node_path_1.default.join(this.buildRoot, this.outputDir);
|
|
28
30
|
const handleLists = {
|
|
29
31
|
register: [],
|
|
30
|
-
inline: [],
|
|
31
32
|
...Object.fromEntries((0, shared_1.constantKeys)(shared_1.standardLocationNamesMeta).map(sln => [sln, []]))
|
|
32
33
|
};
|
|
33
34
|
const allNamedHandles = assets
|
|
@@ -40,21 +41,21 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
40
41
|
.map(handle => [handle.handleName, handle.src]))]));
|
|
41
42
|
const plainEntrypointsConfig = { scriptHandles: {}, script_moduleHandles: {}, styleHandles: {} };
|
|
42
43
|
for (const { handles, handlePrefix } of assets) {
|
|
43
|
-
for (const { src, rest, locations, type, handleName, lazyLoader
|
|
44
|
-
const
|
|
44
|
+
for (const { src, rest, locations, type, handleName, lazyLoader } of handles) {
|
|
45
|
+
const basename = node_path_1.default.basename(src).replace(/_(?:script(?:-\d+)?\.js|style(?:-\d+)?\.css)$|(?<!_(script|style))\.(js|css)$/, "");
|
|
45
46
|
let finalHandleName;
|
|
46
47
|
if (typeof handleName === 'string') {
|
|
47
|
-
finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName,
|
|
48
|
+
finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, basename);
|
|
48
49
|
}
|
|
49
50
|
else {
|
|
50
51
|
const handleNameMap = usedHandleNames[type];
|
|
51
|
-
const baseFinalHandleName = finalHandleName = `${handlePrefix}.${(0, shared_1.convertUsageLocationsHandleToEmittableHandle)((0, shared_1.kebabCase)(
|
|
52
|
+
const baseFinalHandleName = finalHandleName = `${handlePrefix}.${(0, shared_1.convertUsageLocationsHandleToEmittableHandle)((0, shared_1.kebabCase)(basename), basename)}`;
|
|
52
53
|
for (let count = 0; finalHandleName in handleNameMap && handleNameMap[finalHandleName] !== src;) {
|
|
53
54
|
finalHandleName = `${baseFinalHandleName}-${++count}`;
|
|
54
55
|
}
|
|
55
56
|
handleNameMap[finalHandleName] = src;
|
|
56
57
|
}
|
|
57
|
-
plainEntrypointsConfig[`${type}Handles`][finalHandleName] = { src, rest, locations, type, lazyLoader
|
|
58
|
+
plainEntrypointsConfig[`${type}Handles`][finalHandleName] = { src, rest, locations, type, lazyLoader };
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
PlainEntrypointsConfigFileGeneratorPlugin.addHandlesToHandleLists('script', Object.entries(plainEntrypointsConfig.scriptHandles)
|
|
@@ -78,26 +79,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
78
79
|
writer.action("init", writer => {
|
|
79
80
|
writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
|
|
80
81
|
for (const { handle, type, data } of prioritizedHandleList) {
|
|
81
|
-
|
|
82
|
-
const emittedSrc = inlinedAsset === undefined
|
|
83
|
-
? expressions_1.Op.concat(baseUriVar, (0, node_path_1.relative)(emitDir, src))
|
|
84
|
-
: false;
|
|
85
|
-
writer.call(`wp_register_${type}`, [handle, emittedSrc, ...rest]);
|
|
86
|
-
if (inlinedAsset !== undefined) {
|
|
87
|
-
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, inlinedAsset, data, src);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, { priority, accountForAlreadyDoing: this.config.includePostInitFallback });
|
|
91
|
-
}
|
|
92
|
-
for (const [priority, prioritizedHandleList] of PlainEntrypointsConfigFileGeneratorPlugin.separateHandleListByPriority(handleLists.inline)) {
|
|
93
|
-
writer.action("init", writer => {
|
|
94
|
-
writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
|
|
95
|
-
for (const { handle, type, data } of prioritizedHandleList) {
|
|
96
|
-
const { inlinedAsset, rest, src } = data;
|
|
97
|
-
writer.call(`wp_register_${type}`, [handle, false, ...rest]);
|
|
98
|
-
if (inlinedAsset !== undefined) {
|
|
99
|
-
(0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, inlinedAsset, data, src);
|
|
100
|
-
}
|
|
82
|
+
writer.call(`wp_register_${type}`, [handle, expressions_1.Op.concat(baseUriVar, node_path_1.default.relative(emitDir, data.src)), ...data.rest]);
|
|
101
83
|
}
|
|
102
84
|
}, { priority, accountForAlreadyDoing: this.config.includePostInitFallback });
|
|
103
85
|
}
|
|
@@ -114,7 +96,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
114
96
|
if (sortedEditorStyleHandles.length > 0) {
|
|
115
97
|
writer.linebreak();
|
|
116
98
|
for (const handleSrc of sortedEditorStyleHandles) {
|
|
117
|
-
const handlePath =
|
|
99
|
+
const handlePath = node_path_1.default.join(this.outputDir, node_path_1.default.relative(emitDir, handleSrc));
|
|
118
100
|
writer.call("add_editor_style", [(0, shared_1.leadingSlashIt)(handlePath)]);
|
|
119
101
|
}
|
|
120
102
|
}
|
|
@@ -145,9 +127,6 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
145
127
|
if (data.locations.register !== false) {
|
|
146
128
|
handleLists.register.push({ handle, type, data, priority: typeof data.locations.register === 'number' ? data.locations.register : 10 });
|
|
147
129
|
}
|
|
148
|
-
else if (data.inlinedAsset !== undefined) {
|
|
149
|
-
handleLists.inline.push({ handle, type, data, priority: typeof data.locations.inline === 'number' ? data.locations.inline : 10 });
|
|
150
|
-
}
|
|
151
130
|
for (const location of (0, shared_1.constantKeys)(shared_1.standardLocationNamesMeta)) {
|
|
152
131
|
let priority, hook_name;
|
|
153
132
|
const dataLocation = data.locations[location];
|
|
@@ -294,23 +273,18 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
|
|
|
294
273
|
chunkFiles[0][1] = true;
|
|
295
274
|
}
|
|
296
275
|
for (const [file, useHandleName] of chunkFiles) {
|
|
297
|
-
const extension =
|
|
276
|
+
const extension = node_path_1.default.extname(file).toLowerCase();
|
|
298
277
|
const type = extension === ".js" ? 'script' : (extension === ".mjs" ? 'script_module' : 'style');
|
|
299
278
|
const isScript = type !== 'style';
|
|
300
279
|
const dependencies = isScript === entrypointChunkIsScript ? assetData.dependencies : [];
|
|
301
|
-
const {
|
|
302
|
-
const
|
|
303
|
-
const
|
|
304
|
-
const rest = isScript && scriptArgsObject !== undefined ? [dependencies, assetData.version, scriptArgsObject] : [dependencies, assetData.version];
|
|
305
|
-
const destPath = (0, node_path_1.join)(compilation.outputOptions.path, file);
|
|
280
|
+
const { registerScriptArgs } = this.dest.locations;
|
|
281
|
+
const rest = isScript && registerScriptArgs !== undefined ? [dependencies, assetData.version, registerScriptArgs] : [dependencies, assetData.version];
|
|
282
|
+
const destPath = node_path_1.default.join(compilation.outputOptions.path, file);
|
|
306
283
|
handles.push({
|
|
307
|
-
src: destPath,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
handleName: useHandleName ? locations.handle : undefined,
|
|
312
|
-
lazyLoader,
|
|
313
|
-
inlinedAsset
|
|
284
|
+
src: destPath, rest, type,
|
|
285
|
+
locations: this.dest.locations,
|
|
286
|
+
handleName: useHandleName ? this.dest.locations.handle : undefined,
|
|
287
|
+
lazyLoader: this.dest.lazyLoader
|
|
314
288
|
});
|
|
315
289
|
}
|
|
316
290
|
myAssetHandles.push({ handles, handlePrefix: this.config.targetHandlePrefix });
|
|
@@ -3,7 +3,7 @@ import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
|
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
4
|
import { PseudoSemaphore } from "../utils/pseduo-semaphore";
|
|
5
5
|
import { Compilation } from "webpack";
|
|
6
|
-
|
|
6
|
+
type LoaderInfo = {
|
|
7
7
|
group: string;
|
|
8
8
|
action(writer: PHPWriter): void;
|
|
9
9
|
requiresBaseURI: boolean;
|
|
@@ -18,3 +18,4 @@ export declare class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin
|
|
|
18
18
|
private withDistDevLoader;
|
|
19
19
|
private ensureDistExists;
|
|
20
20
|
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Options as PostcssFunctionsOptions } from "postcss-functions";
|
|
2
|
+
import type { PostCSSLoaderOptions } from "postcss-loader/dist/config";
|
|
3
|
+
export declare function postcssConfigBuilder(variables: (name: string) => string | number | undefined, postCSSFunctions: (variables: (name: string) => unknown) => PostcssFunctionsOptions['functions']): PostCSSLoaderOptions;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postcssConfigBuilder = postcssConfigBuilder;
|
|
4
|
+
// Options: calc
|
|
5
|
+
const calcOptions = { precision: 4, mediaQueries: true, selectors: true };
|
|
6
|
+
// Options: autoprefixerOptions
|
|
7
|
+
const autoprefixerOptions = { grid: "autoplace" };
|
|
8
|
+
function makeDefaultPostCSSFunctions(variables) {
|
|
9
|
+
const magnitude = new Intl.NumberFormat("en-US", { maximumFractionDigits: 4 });
|
|
10
|
+
return {
|
|
11
|
+
pxAsRem(value) {
|
|
12
|
+
return value ? `${magnitude.format(parseFloat(value.toString()) / (variables("font_size") || 16))}rem` : "1rem";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function postcssConfigBuilder(variables, postCSSFunctions) {
|
|
17
|
+
return {
|
|
18
|
+
plugins: [
|
|
19
|
+
require("postcss-import")(), // Once
|
|
20
|
+
require("postcss-mixins")(), // Once
|
|
21
|
+
require("@plaudit/postcss-variables")({ variables }), // Once
|
|
22
|
+
require("postcss-functions")({ functions: { ...makeDefaultPostCSSFunctions(variables), ...postCSSFunctions(variables) } }),
|
|
23
|
+
require("postcss-property-lookup")({ logLevel: "warn" }), // Rule
|
|
24
|
+
require("@plaudit/postcss-strip-units")(), // AtRule, Declaration
|
|
25
|
+
require("postcss-nested")(), // Rule
|
|
26
|
+
require("postcss-url")(),
|
|
27
|
+
require("postcss-calc")(calcOptions), // OnceExit
|
|
28
|
+
require("@plaudit/postcss-color-function")(), // OnceExit
|
|
29
|
+
require("autoprefixer")(autoprefixerOptions), // OnceExit
|
|
30
|
+
require("postcss-reporter")({ clearReportedMessages: true }), // OnceExit
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
import { PHPWriter } from "@plaudit/php-writer";
|
|
2
2
|
import type { Options as PostcssFunctionsOptions } from "postcss-functions";
|
|
3
|
-
import {
|
|
4
|
-
import { SourceType } from "./utils/entrypoint-resolution-logic";
|
|
5
|
-
import type { NormalizedEnqueuingControlFlags } from "./utils/path-query-and-related-helpers";
|
|
6
|
-
export * from "./utils/entrypoint-resolution-logic";
|
|
3
|
+
import { AssetInfo, Compilation, Configuration, Entrypoint, WebpackError, Compiler } from "webpack";
|
|
7
4
|
export type ParsedAssetsJson = Record<string, {
|
|
8
5
|
dependencies: string[];
|
|
9
6
|
version: string;
|
|
10
7
|
}>;
|
|
11
8
|
export declare function isParsedAssetsJson(thing: any): thing is ParsedAssetsJson;
|
|
12
|
-
|
|
9
|
+
type ScriptArgsObject = {
|
|
13
10
|
strategy?: 'defer' | 'async';
|
|
14
11
|
in_footer?: boolean;
|
|
15
12
|
fetchpriority?: 'auto' | 'low' | 'high';
|
|
16
13
|
};
|
|
17
14
|
type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
|
|
18
|
-
export type InlinedAsset = {
|
|
19
|
-
contents: string;
|
|
20
|
-
position?: 'before' | 'after';
|
|
21
|
-
};
|
|
22
15
|
export type HandleData = {
|
|
23
16
|
src: string;
|
|
24
|
-
rest: BaseRestType | [...BaseRestType, ScriptArgsObject];
|
|
25
|
-
inlinedAsset?: InlinedAsset;
|
|
17
|
+
rest: BaseRestType | [...BaseRestType, ScriptArgsObject | boolean];
|
|
26
18
|
};
|
|
27
19
|
export declare const standardLocationNamesMeta: {
|
|
28
20
|
readonly clientView: {
|
|
@@ -57,34 +49,34 @@ export type StandardLocationNameMeta = {
|
|
|
57
49
|
};
|
|
58
50
|
};
|
|
59
51
|
export type StandardLocationNames = keyof typeof standardLocationNamesMeta;
|
|
60
|
-
export declare function isStandardLocationName(name: string): name is StandardLocationNames;
|
|
61
52
|
type LocationWithHookNameSupport = boolean | number | string | string[] | {
|
|
62
53
|
hook_name?: string | string[];
|
|
63
54
|
priority?: number;
|
|
64
55
|
};
|
|
65
|
-
type
|
|
66
|
-
export declare function isRegisterScriptArgsShorthandName(name: string): name is Extract<InputRegisterScriptArgs, string>;
|
|
67
|
-
export type RealUsageLocations = {
|
|
56
|
+
export type UsageLocations = {
|
|
68
57
|
[K in StandardLocationNames]?: typeof standardLocationNamesMeta[K] extends {
|
|
69
58
|
supports_hook_name: true;
|
|
70
59
|
} ? LocationWithHookNameSupport : boolean | number;
|
|
71
|
-
}
|
|
72
|
-
export type UsageLocations = RealUsageLocations & {
|
|
60
|
+
} & {
|
|
73
61
|
register?: boolean | number;
|
|
74
|
-
inline?: number;
|
|
75
62
|
handle?: string | ((generatedHandle: string) => string);
|
|
76
|
-
registerScriptArgs?:
|
|
63
|
+
registerScriptArgs?: ScriptArgsObject | boolean | 'lazy';
|
|
77
64
|
};
|
|
78
65
|
export type NormalizedUsageLocations = Omit<UsageLocations, 'registerScriptArgs'> & {
|
|
79
|
-
registerScriptArgs?:
|
|
66
|
+
registerScriptArgs?: ScriptArgsObject | boolean;
|
|
80
67
|
};
|
|
81
68
|
export declare function isNormalizedUsageLocations(usageLocations: UsageLocations): usageLocations is NormalizedUsageLocations;
|
|
82
69
|
export declare function constantKeys<K extends string, V>(object: {
|
|
83
|
-
[k in K]
|
|
70
|
+
[k in K]: V;
|
|
84
71
|
}): K[];
|
|
85
72
|
export declare function constantEntries<K extends string, V>(object: {
|
|
86
73
|
[k in K]: V;
|
|
87
74
|
}): [K, V][];
|
|
75
|
+
export declare const enum SourceType {
|
|
76
|
+
blocks = "blocks",
|
|
77
|
+
extensions = "extensions",
|
|
78
|
+
plain = "plain"
|
|
79
|
+
}
|
|
88
80
|
export declare function determineCurrentSourceType(dest: string | AdvancedOutputConfig, srcIsDirectory: boolean): SourceType;
|
|
89
81
|
export interface WebpackPlugin {
|
|
90
82
|
apply(compiler: Compiler): void;
|
|
@@ -107,21 +99,17 @@ export type AdvancedOutputConfig = {
|
|
|
107
99
|
bundleAnalyzer?: boolean;
|
|
108
100
|
locations?: UsageLocations | UsageLocations['handle'];
|
|
109
101
|
lazyLoader?: string;
|
|
110
|
-
pathQueryParameters?: PathQueryParameters;
|
|
111
|
-
enqueuingFlags?: NormalizedEnqueuingControlFlags;
|
|
112
102
|
};
|
|
113
|
-
type OptionalCfgFields = 'directoryLayout' | 'externalize' | 'lazyLoader'
|
|
114
|
-
export type VerifiedAdvancedOutputConfig = Required<Omit<AdvancedOutputConfig, 'locations' |
|
|
115
|
-
enqueuingFlags: NormalizedEnqueuingControlFlags | undefined;
|
|
103
|
+
type OptionalCfgFields = 'directoryLayout' | 'externalize' | 'lazyLoader';
|
|
104
|
+
export type VerifiedAdvancedOutputConfig = Required<Omit<AdvancedOutputConfig, 'locations' | OptionalCfgFields>> & Pick<AdvancedOutputConfig, OptionalCfgFields> & {
|
|
116
105
|
locations: NormalizedUsageLocations;
|
|
117
106
|
};
|
|
118
107
|
export type SourcesObject = Record<string, string | AdvancedOutputConfig | boolean>;
|
|
119
108
|
export type PlauditWordpressWebpackConfig = {
|
|
120
|
-
standard?: '2026-03-13';
|
|
121
109
|
standaloneBlocks?: boolean;
|
|
122
110
|
variables?: Record<string, any>;
|
|
123
111
|
verbose?: boolean;
|
|
124
|
-
src
|
|
112
|
+
src: string[] | SourcesObject;
|
|
125
113
|
stats?: Configuration['stats'];
|
|
126
114
|
postcss?: {
|
|
127
115
|
functions?: (variables: (name: string) => unknown) => PostcssFunctionsOptions['functions'];
|
|
@@ -142,41 +130,6 @@ export type PlauditWordpressWebpackConfig = {
|
|
|
142
130
|
omitDistDev?: boolean;
|
|
143
131
|
onlyRunPostCSSOnPCSS?: boolean;
|
|
144
132
|
};
|
|
145
|
-
export declare function applyStandards(config: PlauditWordpressWebpackConfig): {
|
|
146
|
-
readonly standard?: "2026-03-13";
|
|
147
|
-
readonly standaloneBlocks?: boolean;
|
|
148
|
-
readonly variables?: Record<string, any>;
|
|
149
|
-
readonly verbose?: boolean;
|
|
150
|
-
readonly src?: string[] | SourcesObject;
|
|
151
|
-
readonly stats?: Configuration["stats"];
|
|
152
|
-
readonly postcss?: {
|
|
153
|
-
functions?: (variables: (name: string) => unknown) => PostcssFunctionsOptions["functions"];
|
|
154
|
-
};
|
|
155
|
-
readonly externals?: Externals;
|
|
156
|
-
readonly assumeGlobalizedPlauditLibraries?: boolean;
|
|
157
|
-
readonly processTranslationConfigs?: boolean;
|
|
158
|
-
readonly combineAssetMetadata?: boolean;
|
|
159
|
-
useWebpackResourceFiltering?: boolean;
|
|
160
|
-
outputDir?: string;
|
|
161
|
-
extensionsVersion?: 1 | 2 | 3;
|
|
162
|
-
readonly targetHandlePrefix?: string;
|
|
163
|
-
plainEntrypointsVersion?: 1 | 2;
|
|
164
|
-
srcDir?: string;
|
|
165
|
-
readonly srcPrefixes?: string[];
|
|
166
|
-
useUnifiedLoader?: boolean;
|
|
167
|
-
readonly includePostInitFallback?: boolean;
|
|
168
|
-
readonly omitDistDev?: boolean;
|
|
169
|
-
onlyRunPostCSSOnPCSS?: boolean;
|
|
170
|
-
};
|
|
171
|
-
export declare function resolveStandard(standard: PlauditWordpressWebpackConfig['standard']): {
|
|
172
|
-
readonly useWebpackResourceFiltering: true;
|
|
173
|
-
readonly extensionsVersion: 3;
|
|
174
|
-
readonly plainEntrypointsVersion: 2;
|
|
175
|
-
readonly srcDir: "src";
|
|
176
|
-
readonly outputDir: "dist";
|
|
177
|
-
readonly useUnifiedLoader: true;
|
|
178
|
-
readonly onlyRunPostCSSOnPCSS: true;
|
|
179
|
-
} | undefined;
|
|
180
133
|
export type FileSegmentBlockEntrypointInfo = {
|
|
181
134
|
blockJsonOrigin: string;
|
|
182
135
|
entrypointField: EntrypointFields[number];
|
|
@@ -186,10 +139,7 @@ export type FileSegmentBlockEntrypointInfo = {
|
|
|
186
139
|
handle: string;
|
|
187
140
|
dest: VerifiedAdvancedOutputConfig;
|
|
188
141
|
absoluteSrc: string;
|
|
189
|
-
pathQueryParameters: PathQueryParameters | undefined;
|
|
190
|
-
enqueuingFlags: NormalizedEnqueuingControlFlags | undefined;
|
|
191
142
|
};
|
|
192
|
-
export type PathQueryParameters = Record<string, unknown | [unknown, ...unknown[]]>;
|
|
193
143
|
export type BlockEntrypointInfo = FileSegmentBlockEntrypointInfo | {
|
|
194
144
|
dest: VerifiedAdvancedOutputConfig;
|
|
195
145
|
purpose: string;
|
|
@@ -209,11 +159,10 @@ export declare const scriptExtension: RegExp;
|
|
|
209
159
|
export declare const scriptWithoutModuleExtension: RegExp;
|
|
210
160
|
export declare const scriptWithModuleExtension: RegExp;
|
|
211
161
|
export declare const styleExtension: RegExp;
|
|
212
|
-
export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "
|
|
162
|
+
export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "style" | "script" | "";
|
|
213
163
|
export declare function isStyleField(field: string): field is 'style' | 'viewStyle' | 'editorStyle';
|
|
214
164
|
export declare function isScriptModuleField(field: string): field is 'viewScriptModule';
|
|
215
165
|
export declare function getHandleGroup(field: string): 'styleHandles' | 'scriptHandles' | 'scriptModuleHandles';
|
|
216
|
-
export type StripFirstTwoItems<A extends any[]> = A extends [any, any, ...rest: infer R] ? R : never;
|
|
217
166
|
export declare function hasAtLeastOneItem<T>(list: T[]): list is [T, ...T[]];
|
|
218
167
|
export type TupleOf<T, N extends number> = N extends N ? number extends N ? T[] : _TupleOf<T, N, []> : never;
|
|
219
168
|
type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, [T, ...R]>;
|
|
@@ -221,7 +170,6 @@ export declare function arrayIsLength<T, N extends number>(arr: T[] | null | und
|
|
|
221
170
|
export declare function kebabCase(value: string): string;
|
|
222
171
|
export declare function loadEnvFile(filePath: string): Promise<Record<string, string>>;
|
|
223
172
|
export declare function parseEnvFile(contents: string): Record<string, string>;
|
|
224
|
-
export declare function newCleanWebpackError(error: string | ConstructorParameters<typeof WebpackError>): WebpackError;
|
|
225
173
|
export declare function newWebpackErrorForFile(error: string | ConstructorParameters<typeof WebpackError>, file: string): WebpackError;
|
|
226
174
|
/**
|
|
227
175
|
* The primary benefit of emitting a function instead of baking its contents into each function that uses it is that it allows us to avoid recomputing the base uri multiple times
|
|
@@ -239,13 +187,4 @@ export declare function getParsedAssetsJsonDataForEntrypoint(compilation: Compil
|
|
|
239
187
|
export declare function emitPHPWriterAsAsset(writer: PHPWriter, compilation: Compilation, file: string, assetInfo?: AssetInfo): void;
|
|
240
188
|
export declare function dedent(text: TemplateStringsArray): string;
|
|
241
189
|
export declare function resolveLegacyBlockScriptsInFolder(folder: string): string[];
|
|
242
|
-
|
|
243
|
-
* @param compilation
|
|
244
|
-
* @param writer
|
|
245
|
-
* @param handle
|
|
246
|
-
* @param type 'script_module' is NOT supported at this time; however, it is *handled* in this function
|
|
247
|
-
* @param inlinedAsset
|
|
248
|
-
* @param handleData
|
|
249
|
-
* @param file something that represents the file that is being inlined (this is purely for error-reporting purposes)
|
|
250
|
-
*/
|
|
251
|
-
export declare function appendAddInlineAssetCall(compilation: Compilation, writer: PHPWriter, handle: string, type: 'script' | 'style' | 'script_module', inlinedAsset: InlinedAsset, handleData: HandleData, file: string): void;
|
|
190
|
+
export {};
|
package/{dist → build}/shared.js
RENAMED
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
4
|
};
|
|
19
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
6
|
exports.styleExtension = exports.scriptWithModuleExtension = exports.scriptWithoutModuleExtension = exports.scriptExtension = exports.entrypointFields = exports.standardLocationNamesMeta = void 0;
|
|
21
7
|
exports.isParsedAssetsJson = isParsedAssetsJson;
|
|
22
|
-
exports.isStandardLocationName = isStandardLocationName;
|
|
23
|
-
exports.isRegisterScriptArgsShorthandName = isRegisterScriptArgsShorthandName;
|
|
24
8
|
exports.isNormalizedUsageLocations = isNormalizedUsageLocations;
|
|
25
9
|
exports.constantKeys = constantKeys;
|
|
26
10
|
exports.constantEntries = constantEntries;
|
|
27
11
|
exports.determineCurrentSourceType = determineCurrentSourceType;
|
|
28
|
-
exports.applyStandards = applyStandards;
|
|
29
|
-
exports.resolveStandard = resolveStandard;
|
|
30
12
|
exports.convertUsageLocationsHandleToEmittableHandle = convertUsageLocationsHandleToEmittableHandle;
|
|
31
13
|
exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
|
|
32
14
|
exports.convertEntrypointFieldForAssetType = convertEntrypointFieldForAssetType;
|
|
@@ -40,7 +22,6 @@ exports.arrayIsLength = arrayIsLength;
|
|
|
40
22
|
exports.kebabCase = kebabCase;
|
|
41
23
|
exports.loadEnvFile = loadEnvFile;
|
|
42
24
|
exports.parseEnvFile = parseEnvFile;
|
|
43
|
-
exports.newCleanWebpackError = newCleanWebpackError;
|
|
44
25
|
exports.newWebpackErrorForFile = newWebpackErrorForFile;
|
|
45
26
|
exports.emitResolveBaseUriFunction = emitResolveBaseUriFunction;
|
|
46
27
|
exports.getAssetsJson = getAssetsJson;
|
|
@@ -48,15 +29,12 @@ exports.getParsedAssetsJsonDataForEntrypoint = getParsedAssetsJsonDataForEntrypo
|
|
|
48
29
|
exports.emitPHPWriterAsAsset = emitPHPWriterAsAsset;
|
|
49
30
|
exports.dedent = dedent;
|
|
50
31
|
exports.resolveLegacyBlockScriptsInFolder = resolveLegacyBlockScriptsInFolder;
|
|
51
|
-
exports.appendAddInlineAssetCall = appendAddInlineAssetCall;
|
|
52
|
-
const node_crypto_1 = require("node:crypto");
|
|
53
32
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
54
33
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
55
34
|
const node_path_1 = __importDefault(require("node:path"));
|
|
56
35
|
const php_writer_1 = require("@plaudit/php-writer");
|
|
57
36
|
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
58
37
|
const webpack_1 = require("webpack");
|
|
59
|
-
__exportStar(require("./utils/entrypoint-resolution-logic"), exports);
|
|
60
38
|
function isParsedAssetsJson(thing) {
|
|
61
39
|
if (!thing || typeof thing !== 'object') {
|
|
62
40
|
return false;
|
|
@@ -79,12 +57,6 @@ exports.standardLocationNamesMeta = {
|
|
|
79
57
|
customizer: { action: "customize_controls_enqueue_scripts" },
|
|
80
58
|
analytics: { action: "plaudit_enqueue_analytics" },
|
|
81
59
|
};
|
|
82
|
-
function isStandardLocationName(name) {
|
|
83
|
-
return name in exports.standardLocationNamesMeta;
|
|
84
|
-
}
|
|
85
|
-
function isRegisterScriptArgsShorthandName(name) {
|
|
86
|
-
return ['lazy', 'eager', 'inline'].includes(name);
|
|
87
|
-
}
|
|
88
60
|
function isNormalizedUsageLocations(usageLocations) {
|
|
89
61
|
return typeof usageLocations.registerScriptArgs !== 'string';
|
|
90
62
|
}
|
|
@@ -110,35 +82,6 @@ function determineCurrentSourceType(dest, srcIsDirectory) {
|
|
|
110
82
|
return dest.directoryLayout;
|
|
111
83
|
}
|
|
112
84
|
}
|
|
113
|
-
function applyStandards(config) {
|
|
114
|
-
switch (config.standard) {
|
|
115
|
-
case '2026-03-13':
|
|
116
|
-
return {
|
|
117
|
-
...resolveStandard('2026-03-13'),
|
|
118
|
-
...config
|
|
119
|
-
};
|
|
120
|
-
case undefined:
|
|
121
|
-
return config;
|
|
122
|
-
default:
|
|
123
|
-
throw `Invalid standard: ${config.standard}`;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function resolveStandard(standard) {
|
|
127
|
-
switch (standard) {
|
|
128
|
-
case "2026-03-13":
|
|
129
|
-
return {
|
|
130
|
-
useWebpackResourceFiltering: true,
|
|
131
|
-
extensionsVersion: 3,
|
|
132
|
-
plainEntrypointsVersion: 2,
|
|
133
|
-
srcDir: "src",
|
|
134
|
-
outputDir: "dist",
|
|
135
|
-
useUnifiedLoader: true,
|
|
136
|
-
onlyRunPostCSSOnPCSS: true,
|
|
137
|
-
};
|
|
138
|
-
default:
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
85
|
function convertUsageLocationsHandleToEmittableHandle(handle, generatedHandle) {
|
|
143
86
|
const emittableHandle = typeof handle === 'string' ? handle : handle?.(generatedHandle) ?? generatedHandle;
|
|
144
87
|
return emittableHandle.replaceAll("{basename}", generatedHandle);
|
|
@@ -160,9 +103,9 @@ function leadingSlashIt(pathOrSomething) {
|
|
|
160
103
|
return pathOrSomething.startsWith('/') ? pathOrSomething : ('/' + pathOrSomething);
|
|
161
104
|
}
|
|
162
105
|
exports.scriptExtension = /(?<filename>.+)(?<extension>\.m?[jt]sx?)$/i;
|
|
163
|
-
exports.scriptWithoutModuleExtension = /(?<filename>.+)(?<extension>\.[jt]sx?)
|
|
164
|
-
exports.scriptWithModuleExtension = /(?<filename>.+)(?<extension>\.m[jt]sx?)
|
|
165
|
-
exports.styleExtension = /(?<filename>.+)(?<extension>\.(
|
|
106
|
+
exports.scriptWithoutModuleExtension = /(?<filename>.+)(?<extension>\.[jt]sx?)$/i;
|
|
107
|
+
exports.scriptWithModuleExtension = /(?<filename>.+)(?<extension>\.m[jt]sx?)$/i;
|
|
108
|
+
exports.styleExtension = /(?<filename>.+)(?<extension>\.(p?c|sa)ss)$/i;
|
|
166
109
|
function scriptOrStyleTest(entryPath, scriptExtension) {
|
|
167
110
|
return scriptExtension.test(entryPath) ? "script" : (exports.styleExtension.test(entryPath) ? "style" : "");
|
|
168
111
|
}
|
|
@@ -202,13 +145,9 @@ function parseEnvFile(contents) {
|
|
|
202
145
|
return equalsPos === -1 ? [line, ""] : [line.substring(0, equalsPos), line.substring(equalsPos + 1)];
|
|
203
146
|
}));
|
|
204
147
|
}
|
|
205
|
-
function
|
|
148
|
+
function newWebpackErrorForFile(error, file) {
|
|
206
149
|
const res = typeof error === 'string' ? new webpack_1.WebpackError(error) : new webpack_1.WebpackError(...error);
|
|
207
150
|
res.hideStack = true;
|
|
208
|
-
return res;
|
|
209
|
-
}
|
|
210
|
-
function newWebpackErrorForFile(error, file) {
|
|
211
|
-
const res = newCleanWebpackError(error);
|
|
212
151
|
res.file = file;
|
|
213
152
|
return res;
|
|
214
153
|
}
|
|
@@ -311,32 +250,3 @@ function resolveLegacyBlockScriptsInFolder(folder) {
|
|
|
311
250
|
}
|
|
312
251
|
return blockScriptEntrypoints;
|
|
313
252
|
}
|
|
314
|
-
/**
|
|
315
|
-
* @param compilation
|
|
316
|
-
* @param writer
|
|
317
|
-
* @param handle
|
|
318
|
-
* @param type 'script_module' is NOT supported at this time; however, it is *handled* in this function
|
|
319
|
-
* @param inlinedAsset
|
|
320
|
-
* @param handleData
|
|
321
|
-
* @param file something that represents the file that is being inlined (this is purely for error-reporting purposes)
|
|
322
|
-
*/
|
|
323
|
-
function appendAddInlineAssetCall(compilation, writer, handle, type, inlinedAsset, handleData, file) {
|
|
324
|
-
if (type === 'script_module') {
|
|
325
|
-
throw newWebpackErrorForFile("WordPress does not support inlined script modules", file);
|
|
326
|
-
}
|
|
327
|
-
if (handleData.rest[0]?.length) { // If there are any dependencies
|
|
328
|
-
compilation.errors.push(newWebpackErrorForFile("Inlined scripts MUST NOT have dependencies. It WILL cause runtime inconsistencies and potentially cause sever performance issues", handleData.src));
|
|
329
|
-
}
|
|
330
|
-
let contents;
|
|
331
|
-
if (compilation.outputOptions.path?.endsWith("-dev")) {
|
|
332
|
-
contents = inlinedAsset.contents;
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
contents = inlinedAsset.contents.replaceAll(/\/\*#\s+sourceMappingURL=.*?\*\/|\/\/#\s+sourceMappingURL=[^\r\n]*?([\r\n]|$)/gis, "$1");
|
|
336
|
-
}
|
|
337
|
-
const args = [handle, new expressions_1.HereOrNowDoc(`plaudit_inlined_${type}_${(0, node_crypto_1.createHash)('md5').update(handle).digest("hex")}`, contents.trim(), false)];
|
|
338
|
-
if (type === 'script' && inlinedAsset.position === 'before') {
|
|
339
|
-
args.push('before');
|
|
340
|
-
}
|
|
341
|
-
writer.call(`wp_add_inline_${type}`, args);
|
|
342
|
-
}
|
|
@@ -3,7 +3,7 @@ import type { AdditionalDependencyInjectorPlugin } from "../plugins/AdditionalDe
|
|
|
3
3
|
import { EntrypointFields, PlauditWordpressWebpackConfig, BlockEntrypointInfo, VerifiedAdvancedOutputConfig, MinimumViableMetadata, WebpackPlugin } from "../shared";
|
|
4
4
|
import type { Compiler, Configuration, DynamicEntryPlugin, WebpackPluginInstance } from "webpack";
|
|
5
5
|
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
6
|
-
export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpressWebpackConfig, 'variables' | 'src' | 'externals'
|
|
6
|
+
export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpressWebpackConfig, 'variables' | 'src' | 'externals'>> & {
|
|
7
7
|
variablesFilePath?: string;
|
|
8
8
|
currentVariables: Record<string, any>;
|
|
9
9
|
} & Pick<PlauditWordpressWebpackConfig, 'externals'>;
|