@plaudit/webpack-extensions 2.76.2 → 2.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -52
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +2 -2
- package/build/plugins/UnifiedLoaderGenerator.js +12 -0
- package/build/plugins/dependency-extraction-webpack-plugin-config-builder.js +12 -0
- package/build/shared.d.ts +7 -3
- package/build/shared.js +5 -3
- package/build/wordpress-scripts-wrapper.js +17 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -23,58 +23,7 @@ This suite generates loader code that uses the most efficient mechanisms availab
|
|
|
23
23
|
The same file structure (both in the webpack.config.js file and the actual directory tree) can be used in plugins and themes.
|
|
24
24
|
|
|
25
25
|
# Usage
|
|
26
|
-
|
|
27
|
-
NOTE: This config assumes that `require_once __DIR__.'/dist/unified-loader.php';` has been added to the theme's functions.php file or the plugin's main PHP file
|
|
28
|
-
|
|
29
|
-
```javascript
|
|
30
|
-
module.exports = require("@plaudit/webpack-extensions/wordpress-scripts-wrapper")({
|
|
31
|
-
src: {
|
|
32
|
-
"blocks": true, // By default, a directory is assumed to contain WordPress blocks, so we don't need to do anything other than tell WebPack to include it
|
|
33
|
-
"extensions": { // Extensions need to have their directory layout specified, but the loader is automatically generated, so there's no need to specify an output path
|
|
34
|
-
directoryLayout: 'extensions'
|
|
35
|
-
},
|
|
36
|
-
"site/index-header.ts": { // "Plain" entrypoints (i.e. those not associated with a block or extension) can have their usage locations specified, at which point they will also be automatically loaded
|
|
37
|
-
locations: {
|
|
38
|
-
clientView: true,
|
|
39
|
-
registerScriptArgs: false
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"site/index-footer.ts": {
|
|
43
|
-
withLegacyBlocksIn: "blocks",
|
|
44
|
-
locations: {
|
|
45
|
-
clientView: true,
|
|
46
|
-
registerScriptArgs: {strategy: "defer", in_footer: true}
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
"site/wp-admin.ts": {
|
|
50
|
-
locations: {
|
|
51
|
-
admin: true
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
"site/wp-admin.pcss": {
|
|
55
|
-
locations: {
|
|
56
|
-
admin: true
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
"site/block-editor.pcss": {
|
|
60
|
-
locations: {
|
|
61
|
-
clientEditor: true
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
"site/public.pcss": {
|
|
65
|
-
locations: {
|
|
66
|
-
clientView: true
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
useWebpackResourceFiltering: true,
|
|
71
|
-
extensionsVersion: 2,
|
|
72
|
-
plainEntrypointsVersion: 2,
|
|
73
|
-
srcDir: "src",
|
|
74
|
-
outputDir: "dist",
|
|
75
|
-
useUnifiedLoader: true
|
|
76
|
-
});
|
|
77
|
-
```
|
|
26
|
+
Check out the [User Guide](USER-GUIDE.md) file.
|
|
78
27
|
|
|
79
28
|
# Development
|
|
80
29
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockEntrypointInfo,
|
|
1
|
+
import { BlockEntrypointInfo, ParsedAssetJsonProvider, NormalizedUsageLocations } from "../shared";
|
|
2
2
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
3
3
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
4
4
|
import { Compilation } from "webpack";
|
|
@@ -8,7 +8,7 @@ export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractB
|
|
|
8
8
|
private readonly usageLocations;
|
|
9
9
|
private readonly useUnifiedLoader;
|
|
10
10
|
private static readonly semaphore;
|
|
11
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations:
|
|
11
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: NormalizedUsageLocations, useUnifiedLoader: boolean, context: string, entry: EntryProvider<BlockEntrypointInfo>);
|
|
12
12
|
private generatePlainEntrypointsLoader;
|
|
13
13
|
private static addHandlesToHandleLists;
|
|
14
14
|
private static appendEnqueuingHandleLists;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.UnifiedLoaderGenerator = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const php_writer_1 = require("@plaudit/php-writer");
|
|
9
|
+
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
9
10
|
const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
|
|
10
11
|
const shared_1 = require("../shared");
|
|
11
12
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
@@ -59,6 +60,17 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
|
|
|
59
60
|
if (this.config.useUnifiedLoader) {
|
|
60
61
|
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
61
62
|
const writer = new php_writer_1.PHPWriter();
|
|
63
|
+
if (compilation.outputOptions.path?.endsWith("-dev")) {
|
|
64
|
+
compilation['.gitignore' in compilation.assets ? 'updateAsset' : 'emitAsset']('.gitignore', new webpack_1.sources.RawSource('**'), { size: 2 });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const devLoaderPath = expressions_1.Op.concat(expressions_1.Constants.__DIR__, '-dev/unified-loader.php');
|
|
68
|
+
writer
|
|
69
|
+
.if(expressions_1.Op.binary(expressions_1.Op.binary(expressions_1.Expr.call('wp_get_environment_type', []), ' === ', 'development'), ' && ', expressions_1.Expr.call('file_exists', [devLoaderPath])))
|
|
70
|
+
.require(devLoaderPath, { once: true })
|
|
71
|
+
.append("return;")
|
|
72
|
+
.endIf();
|
|
73
|
+
}
|
|
62
74
|
if (groupedLoaderInfo.some(wc => wc.requiresBaseURI)) {
|
|
63
75
|
(0, shared_1.emitResolveBaseUriFunction)(writer);
|
|
64
76
|
}
|
|
@@ -98,6 +98,12 @@ function plauditRequestToExternal(ext) {
|
|
|
98
98
|
else if (request.startsWith('@plaudit/gutenberg-api-extensions')) {
|
|
99
99
|
return handleExternalizingEqualsPossibleExternal({ import: ['plaudit', 'gutenbergApiExtensions'], handle: "" }, ext)?.import;
|
|
100
100
|
}
|
|
101
|
+
else if (request.startsWith('@plaudit/wp-consent-api')) {
|
|
102
|
+
return handleExternalizingEqualsPossibleExternal({ import: ['plaudit'], handle: "" }, ext)?.import;
|
|
103
|
+
}
|
|
104
|
+
else if (request.startsWith('@plaudit/analytics-integrations-api')) {
|
|
105
|
+
return handleExternalizingEqualsPossibleExternal({ import: ['plaudit', 'analyticsIntegrations', 'api'], handle: "" }, ext)?.import;
|
|
106
|
+
}
|
|
101
107
|
return undefined;
|
|
102
108
|
};
|
|
103
109
|
}
|
|
@@ -108,6 +114,12 @@ function plauditRequestToHandle(request) {
|
|
|
108
114
|
else if (request.startsWith('@plaudit/gutenberg-api-extensions')) {
|
|
109
115
|
return 'plaudit-gutenberg-api-extensions';
|
|
110
116
|
}
|
|
117
|
+
else if (request.startsWith('@plaudit/wp-consent-api')) {
|
|
118
|
+
return 'wp-consent-api';
|
|
119
|
+
}
|
|
120
|
+
else if (request.startsWith('@plaudit/analytics-integrations-api')) {
|
|
121
|
+
return 'plaudit/analytics-integrations/api';
|
|
122
|
+
}
|
|
111
123
|
return undefined;
|
|
112
124
|
}
|
|
113
125
|
function curryRequestHandlers(primary, secondary) {
|
package/build/shared.d.ts
CHANGED
|
@@ -45,8 +45,12 @@ export type UsageLocations = {
|
|
|
45
45
|
} & {
|
|
46
46
|
register?: boolean | number;
|
|
47
47
|
handle?: string | ((generatedHandle: string) => string);
|
|
48
|
+
registerScriptArgs?: ScriptArgsObject | boolean | 'lazy';
|
|
49
|
+
};
|
|
50
|
+
export type NormalizedUsageLocations = Omit<UsageLocations, 'registerScriptArgs'> & {
|
|
48
51
|
registerScriptArgs?: ScriptArgsObject | boolean;
|
|
49
52
|
};
|
|
53
|
+
export declare function isNormalizedUsageLocations(usageLocations: UsageLocations): usageLocations is NormalizedUsageLocations;
|
|
50
54
|
export declare function constantKeys<K extends string, V>(object: {
|
|
51
55
|
[k in K]: V;
|
|
52
56
|
}): K[];
|
|
@@ -79,7 +83,7 @@ export type AdvancedOutputConfig = {
|
|
|
79
83
|
};
|
|
80
84
|
type OptionalCfgFields = 'directoryLayout' | 'externalize' | 'lazyLoader';
|
|
81
85
|
export type VerifiedAdvancedOutputConfig = Required<Omit<AdvancedOutputConfig, 'locations' | OptionalCfgFields>> & Pick<AdvancedOutputConfig, OptionalCfgFields> & {
|
|
82
|
-
locations:
|
|
86
|
+
locations: NormalizedUsageLocations;
|
|
83
87
|
};
|
|
84
88
|
export type SourcesObject = Record<string, string | AdvancedOutputConfig | boolean>;
|
|
85
89
|
export type PlauditWordpressWebpackConfig = {
|
|
@@ -126,8 +130,8 @@ export type MinimumViableMetadata = {
|
|
|
126
130
|
};
|
|
127
131
|
export declare function convertUsageLocationsHandleToEmittableHandle(handle: UsageLocations['handle'], generatedHandle: string): string;
|
|
128
132
|
export declare function makeEmittableConfigPHP(data: any, asFullFile: boolean, parentIndent?: string): string;
|
|
129
|
-
export
|
|
130
|
-
export
|
|
133
|
+
export declare const entrypointFields: readonly ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script", "viewScriptModule", "scriptModule"];
|
|
134
|
+
export type EntrypointFields = (typeof entrypointFields[number])[];
|
|
131
135
|
export declare function convertEntrypointFieldForAssetType(entrypointField: EntrypointFields[number], assetType: 'script' | 'style'): EntrypointFields[number];
|
|
132
136
|
export declare function leadingSlashIt(pathOrSomething: string): string;
|
|
133
137
|
export declare const scriptExtension: RegExp;
|
package/build/shared.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.styleExtension = exports.scriptWithModuleExtension = exports.scriptWithoutModuleExtension = exports.scriptExtension = exports.entrypointFields = exports.standardLocationNamesMeta = void 0;
|
|
7
7
|
exports.isParsedAssetsJson = isParsedAssetsJson;
|
|
8
|
+
exports.isNormalizedUsageLocations = isNormalizedUsageLocations;
|
|
8
9
|
exports.constantKeys = constantKeys;
|
|
9
10
|
exports.constantEntries = constantEntries;
|
|
10
11
|
exports.determineCurrentSourceType = determineCurrentSourceType;
|
|
@@ -52,6 +53,9 @@ exports.standardLocationNamesMeta = {
|
|
|
52
53
|
admin: { action: "admin_enqueue_scripts" }, login: { action: "login_enqueue_scripts" }, customizer: { action: "customize_controls_enqueue_scripts" },
|
|
53
54
|
analytics: { action: "plaudit_enqueue_analytics" }
|
|
54
55
|
};
|
|
56
|
+
function isNormalizedUsageLocations(usageLocations) {
|
|
57
|
+
return typeof usageLocations.registerScriptArgs !== 'string';
|
|
58
|
+
}
|
|
55
59
|
function constantKeys(object) {
|
|
56
60
|
return Object.keys(object);
|
|
57
61
|
}
|
|
@@ -85,9 +89,7 @@ function makeEmittableConfigPHP(data, asFullFile, parentIndent = "") {
|
|
|
85
89
|
.replaceAll(/'rest' => \[\n\t+(\[(?:'[^']+')?]),\n\t+('[^']+')(?:,\n\t+(\[[^\n]+]))?\n\t+]/gs, (_, deps, hash, args) => `'rest' => [${[deps, hash, args].filter(value => !!value).join(", ")}]`);
|
|
86
90
|
return asFullFile ? `<?php return ${prettyPrintedMetadata};` : prettyPrintedMetadata.trim();
|
|
87
91
|
}
|
|
88
|
-
exports.entrypointFields = [
|
|
89
|
-
"editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script", "viewScriptModule", "scriptModule"
|
|
90
|
-
];
|
|
92
|
+
exports.entrypointFields = ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script", "viewScriptModule", "scriptModule"];
|
|
91
93
|
function convertEntrypointFieldForAssetType(entrypointField, assetType) {
|
|
92
94
|
// Using these word fragments instead of the full words allows us to avoid having to deal with the capitalization of the first letter
|
|
93
95
|
const searchRep = assetType === 'script' ? ['tyle', 'cript'] : ['cript', 'tyle'];
|
|
@@ -157,7 +157,11 @@ function injectSupportForInliningSVGsAsStrings(rules) {
|
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
function buildVerifiedConfig(config) {
|
|
160
|
-
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true,
|
|
160
|
+
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = false } = config;
|
|
161
|
+
let outputDir = config.outputDir ?? "";
|
|
162
|
+
if (outputDir && useUnifiedLoader && (process.env['SERVER_MODE'] ?? 'development') === 'development') {
|
|
163
|
+
outputDir += "-dev";
|
|
164
|
+
}
|
|
161
165
|
let srcPrefixes;
|
|
162
166
|
const trailingSlashedSrcDir = srcDir && !srcDir.endsWith("/") ? srcDir + "/" : srcDir;
|
|
163
167
|
if (config.srcPrefixes === undefined) {
|
|
@@ -214,15 +218,25 @@ function buildVerifiedConfig(config) {
|
|
|
214
218
|
const normalizedParts = { additionalDependencies, assumeGlobalizedPlauditLibraries, bundleAnalyzer, directoryLayout, externalize, withLegacyBlocksIn, lazyLoader };
|
|
215
219
|
const locations = typeof rawSource[1].locations === 'string' || typeof rawSource[1].locations === 'function'
|
|
216
220
|
? { handle: rawSource[1].locations } : rawSource[1].locations ?? {};
|
|
221
|
+
let normalizedLocations;
|
|
222
|
+
if ((0, shared_1.isNormalizedUsageLocations)(locations)) {
|
|
223
|
+
normalizedLocations = locations;
|
|
224
|
+
}
|
|
225
|
+
else if (locations.registerScriptArgs === 'lazy') {
|
|
226
|
+
normalizedLocations = { ...locations, registerScriptArgs: { strategy: 'defer', in_footer: true } };
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
throw new ReferenceError("The only supported string value for registerScript args is 'lazy'");
|
|
230
|
+
}
|
|
217
231
|
if (destination !== undefined) {
|
|
218
232
|
const effectiveDestination = toEffectiveWebpackDestination(destination);
|
|
219
233
|
allocatedDestinations[effectiveDestination] = rawSource[0]; // We need to pre-populate the allocatedDestinations map with statically-declared destinations
|
|
220
|
-
return [rawSource[0], { ...normalizedParts, locations, destination, effectiveDestination, staticallyDeclaredDestination: true }];
|
|
234
|
+
return [rawSource[0], { ...normalizedParts, locations: normalizedLocations, destination, effectiveDestination, staticallyDeclaredDestination: true }];
|
|
221
235
|
}
|
|
222
236
|
else {
|
|
223
237
|
const naiveDestination = deriveNaiveDestinationFromUnverifiedSourceEntry(rawSource, srcPrefixes);
|
|
224
238
|
const effectiveDestination = toEffectiveWebpackDestination(naiveDestination);
|
|
225
|
-
return [rawSource[0], { ...normalizedParts, locations, destination: naiveDestination, effectiveDestination, staticallyDeclaredDestination: false }];
|
|
239
|
+
return [rawSource[0], { ...normalizedParts, locations: normalizedLocations, destination: naiveDestination, effectiveDestination, staticallyDeclaredDestination: false }];
|
|
226
240
|
}
|
|
227
241
|
});
|
|
228
242
|
const dynamicEffectiveDestinationsWithExpectedNaiveDuplicates = partiallyVerifiedSources
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.78.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"/build"
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@plaudit/gutenberg-api-extensions": "^2.
|
|
23
|
+
"@plaudit/gutenberg-api-extensions": "^2.81.0",
|
|
24
24
|
"@types/browser-sync-webpack-plugin": "^2.2.5",
|
|
25
|
-
"@types/node": "^24.10.
|
|
25
|
+
"@types/node": "^24.10.4",
|
|
26
26
|
"@types/postcss-functions": "^4.0.4",
|
|
27
27
|
"@types/tapable": "^2.3.0",
|
|
28
28
|
"@types/webpack": "^5.28.5",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@plaudit/postcss-variables": "^1.1.0",
|
|
42
42
|
"@wordpress/dependency-extraction-webpack-plugin": "^6.36.0",
|
|
43
43
|
"@wordpress/scripts": "^30.27.0",
|
|
44
|
-
"autoprefixer": "^10.4.
|
|
44
|
+
"autoprefixer": "^10.4.23",
|
|
45
45
|
"browser-sync": "^3.0.4",
|
|
46
46
|
"copy-webpack-plugin": "10.2.4",
|
|
47
47
|
"cssnano": "^6.1.2",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"postcss-reporter": "^7.1.0",
|
|
62
62
|
"postcss-simple-vars": "^7.0.1",
|
|
63
63
|
"postcss-url": "^10.1.3",
|
|
64
|
-
"webpack": "^5.
|
|
64
|
+
"webpack": "^5.104.0",
|
|
65
65
|
"webpack-remove-empty-scripts": "^1.1.1",
|
|
66
66
|
"xml-formatter": "^3.6.7"
|
|
67
67
|
},
|