@plaudit/webpack-extensions 3.16.0 → 3.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -1
- package/USER-GUIDE.md +16 -13
- package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +1 -1
- package/dist/plugins/EnhancedBlockJSONPlugin.d.ts +1 -0
- package/dist/plugins/EnhancedBlockJSONPlugin.js +36 -25
- package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +22 -9
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +3 -6
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js +8 -21
- package/dist/shared.d.ts +16 -18
- package/dist/shared.js +28 -40
- package/dist/utils/common-config-helpers.js +10 -7
- package/dist/utils/css-writer.js +3 -3
- package/dist/utils/entrypoint-resolution-logic.d.ts +5 -2
- package/dist/utils/location-encoding-filename-parser.d.ts +0 -1
- package/dist/utils/location-encoding-filename-parser.js +4 -3
- package/dist/utils/path-query-and-related-helpers.d.ts +0 -1
- package/dist/utils/path-query-and-related-helpers.js +0 -4
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts +72 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js +522 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts +56 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js +150 -0
- package/dist/wordpress-scripts-wrapper.js +72 -57
- package/package.json +23 -6
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultRequestToExternal = defaultRequestToExternal;
|
|
4
|
+
exports.defaultRequestToExternalModule = defaultRequestToExternalModule;
|
|
5
|
+
exports.defaultRequestToHandle = defaultRequestToHandle;
|
|
6
|
+
exports.camelCaseDash = camelCaseDash;
|
|
7
|
+
exports.isConcatenatedModule = isConcatenatedModule;
|
|
8
|
+
exports.isEntrypoint = isEntrypoint;
|
|
9
|
+
const WORDPRESS_NAMESPACE = '@wordpress/';
|
|
10
|
+
const BUNDLED_PACKAGES = [
|
|
11
|
+
'@wordpress/admin-ui',
|
|
12
|
+
'@wordpress/dataviews',
|
|
13
|
+
'@wordpress/dataviews/wp',
|
|
14
|
+
'@wordpress/fields',
|
|
15
|
+
'@wordpress/grid',
|
|
16
|
+
'@wordpress/icons',
|
|
17
|
+
'@wordpress/interface',
|
|
18
|
+
'@wordpress/style-runtime',
|
|
19
|
+
'@wordpress/ui',
|
|
20
|
+
'@wordpress/undo-manager',
|
|
21
|
+
'@wordpress/views',
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Default request to global transformation
|
|
25
|
+
*
|
|
26
|
+
* Transform @wordpress dependencies:
|
|
27
|
+
* - request `@wordpress/api-fetch` becomes `[ 'wp', 'apiFetch' ]`
|
|
28
|
+
* - request `@wordpress/i18n` becomes `[ 'wp', 'i18n' ]`
|
|
29
|
+
*
|
|
30
|
+
* @param {string} request Module request (the module name in `import from`) to be transformed
|
|
31
|
+
* @return {string|string[]|undefined} The resulting external definition. Return `undefined`
|
|
32
|
+
* to ignore the request. Return `string|string[]` to map the request to an external.
|
|
33
|
+
*/
|
|
34
|
+
function defaultRequestToExternal(request) {
|
|
35
|
+
switch (request) {
|
|
36
|
+
case 'moment':
|
|
37
|
+
return request;
|
|
38
|
+
case '@babel/runtime/regenerator':
|
|
39
|
+
return 'regeneratorRuntime';
|
|
40
|
+
case 'lodash':
|
|
41
|
+
case 'lodash-es':
|
|
42
|
+
return 'lodash';
|
|
43
|
+
case 'jquery':
|
|
44
|
+
return 'jQuery';
|
|
45
|
+
case 'react':
|
|
46
|
+
return 'React';
|
|
47
|
+
case 'react-dom':
|
|
48
|
+
case 'react-dom/client':
|
|
49
|
+
return 'ReactDOM';
|
|
50
|
+
case 'react/jsx-runtime':
|
|
51
|
+
case 'react/jsx-dev-runtime':
|
|
52
|
+
return 'ReactJSXRuntime';
|
|
53
|
+
}
|
|
54
|
+
if (request.includes('react-refresh/runtime')) {
|
|
55
|
+
return 'ReactRefreshRuntime';
|
|
56
|
+
}
|
|
57
|
+
if (BUNDLED_PACKAGES.includes(request)) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
if (request.startsWith(WORDPRESS_NAMESPACE)) {
|
|
61
|
+
return [
|
|
62
|
+
'wp',
|
|
63
|
+
camelCaseDash(request.substring(WORDPRESS_NAMESPACE.length)),
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Default request to external module transformation
|
|
70
|
+
*
|
|
71
|
+
* Currently only @wordpress/interactivity and `@wordpress/interactivity-router`
|
|
72
|
+
* are supported.
|
|
73
|
+
*
|
|
74
|
+
* Do not use the boolean shorthand here, it's only handled for the
|
|
75
|
+
* `requestToExternalModule` option.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} request Module request (the module name in `import from`) to be transformed
|
|
78
|
+
* @return {string|undefined} The resulting external definition.
|
|
79
|
+
* - Return `undefined` to ignore the request (do not externalize).
|
|
80
|
+
* - Return `string` to map the request to an external.
|
|
81
|
+
* - Return `Error` to emit an error.
|
|
82
|
+
*/
|
|
83
|
+
function defaultRequestToExternalModule(request) {
|
|
84
|
+
if (request === '@wordpress/interactivity') {
|
|
85
|
+
// This is a special case. Interactivity does not support dynamic imports at
|
|
86
|
+
// this time. We add the external "module" type to indicate that webpack
|
|
87
|
+
// should externalize this as a module (instead of our default `import()`
|
|
88
|
+
// external type) which forces @wordpress/interactivity imports to be
|
|
89
|
+
// hoisted to static imports.
|
|
90
|
+
return `module ${request}`;
|
|
91
|
+
}
|
|
92
|
+
switch (request) {
|
|
93
|
+
case '@wordpress/interactivity-router':
|
|
94
|
+
case '@wordpress/a11y':
|
|
95
|
+
return `import ${request}`;
|
|
96
|
+
}
|
|
97
|
+
const isWordPressScript = Boolean(defaultRequestToExternal(request));
|
|
98
|
+
if (isWordPressScript) {
|
|
99
|
+
throw new Error(`Attempted to use WordPress script in a module: ${request}, which is not supported yet.`);
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Default request to WordPress script handle transformation
|
|
105
|
+
*
|
|
106
|
+
* Transform @wordpress dependencies:
|
|
107
|
+
* - request `@wordpress/i18n` becomes `wp-i18n`
|
|
108
|
+
* - request `@wordpress/escape-html` becomes `wp-escape-html`
|
|
109
|
+
*
|
|
110
|
+
* @param {string} request Module request (the module name in `import from`) to be transformed
|
|
111
|
+
* @return {string|undefined} WordPress script handle to map the request to. Return `undefined`
|
|
112
|
+
* to use the same name as the module.
|
|
113
|
+
*/
|
|
114
|
+
function defaultRequestToHandle(request) {
|
|
115
|
+
switch (request) {
|
|
116
|
+
case '@babel/runtime/regenerator':
|
|
117
|
+
return 'regenerator-runtime';
|
|
118
|
+
case 'lodash-es':
|
|
119
|
+
return 'lodash';
|
|
120
|
+
case 'react-dom/client':
|
|
121
|
+
return 'react-dom';
|
|
122
|
+
case 'react/jsx-runtime':
|
|
123
|
+
return 'react-jsx-runtime';
|
|
124
|
+
}
|
|
125
|
+
if (request.includes('react-refresh/runtime')) {
|
|
126
|
+
return 'wp-react-refresh-runtime';
|
|
127
|
+
}
|
|
128
|
+
if (request.startsWith(WORDPRESS_NAMESPACE)) {
|
|
129
|
+
return 'wp-' + request.substring(WORDPRESS_NAMESPACE.length);
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Given a string, returns a new string with dash separators converted to
|
|
135
|
+
* camelCase equivalent. This is not as aggressive as `_.camelCase` in
|
|
136
|
+
* converting to uppercase, where Lodash will also capitalize letters
|
|
137
|
+
* following numbers.
|
|
138
|
+
*
|
|
139
|
+
* @param {string} string Input dash-delimited string.
|
|
140
|
+
* @return {string} Camel-cased string.
|
|
141
|
+
*/
|
|
142
|
+
function camelCaseDash(string) {
|
|
143
|
+
return string.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
144
|
+
}
|
|
145
|
+
function isConcatenatedModule(module) {
|
|
146
|
+
return 'modules' in module && Array.isArray(module.modules);
|
|
147
|
+
}
|
|
148
|
+
function isEntrypoint(group) {
|
|
149
|
+
return !!group && group.constructor.name === 'Entrypoint';
|
|
150
|
+
}
|
|
@@ -90,7 +90,7 @@ function replaceDefaultURLProcessing(useWebpackResourceFiltering) {
|
|
|
90
90
|
}
|
|
91
91
|
function injectPostcssConfigOverrides(rules, config, variables, postcssFunctionsConfig) {
|
|
92
92
|
const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(name => variables(name) ?? (name === 'ENV' ? '' : undefined), postcssFunctionsConfig);
|
|
93
|
-
return
|
|
93
|
+
return rules.map(rule => {
|
|
94
94
|
if (rule && typeof rule === 'object') {
|
|
95
95
|
if (Array.isArray(rule.use)) {
|
|
96
96
|
for (const useItem of rule.use) {
|
|
@@ -130,26 +130,6 @@ function injectPostcssConfigOverrides(rules, config, variables, postcssFunctions
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
return rule;
|
|
133
|
-
}), config);
|
|
134
|
-
}
|
|
135
|
-
function recursivelyAddParentDirectoryStepToImagesAndFonts(rules, config) {
|
|
136
|
-
if (config.outputDir) {
|
|
137
|
-
return rules;
|
|
138
|
-
}
|
|
139
|
-
return rules.map(rule => {
|
|
140
|
-
if (rule && typeof rule === 'object') {
|
|
141
|
-
if (typeof rule.generator === 'object') {
|
|
142
|
-
const ruleGeneratorFilename = rule.generator["filename"];
|
|
143
|
-
if (typeof ruleGeneratorFilename === 'string' && (ruleGeneratorFilename.startsWith("images/") || ruleGeneratorFilename.startsWith("fonts/"))) {
|
|
144
|
-
rule.generator["filename"] = `../${ruleGeneratorFilename}`;
|
|
145
|
-
rule = { ...rule, generator: { ...rule.generator, filename: `../${ruleGeneratorFilename}` } };
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (rule.oneOf) {
|
|
149
|
-
rule = { ...rule, oneOf: recursivelyAddParentDirectoryStepToImagesAndFonts(rule.oneOf, config) };
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return rule;
|
|
153
133
|
});
|
|
154
134
|
}
|
|
155
135
|
function injectSupportForInliningSVGsAsStrings(rules) {
|
|
@@ -167,7 +147,7 @@ function injectSupportForInliningSVGsAsStrings(rules) {
|
|
|
167
147
|
}
|
|
168
148
|
function buildVerifiedConfig(config) {
|
|
169
149
|
config = (0, shared_1.applyStandards)(config);
|
|
170
|
-
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true,
|
|
150
|
+
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, useWebpackResourceFiltering = true, plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = false, omitDistDev = false, onlyRunPostCSSOnPCSS = false, useBlockSupportsAsThemeJsonDefaults = true, } = config;
|
|
171
151
|
let outputDir = config.outputDir ?? "";
|
|
172
152
|
if (outputDir && useUnifiedLoader && !omitDistDev && (process.env['SERVER_MODE'] ?? 'development') === 'development') {
|
|
173
153
|
outputDir += "-dev";
|
|
@@ -183,7 +163,7 @@ function buildVerifiedConfig(config) {
|
|
|
183
163
|
let targetHandlePrefix = config.targetHandlePrefix ?? config.plainEntrypointsHandlePrefix ?? "";
|
|
184
164
|
if (plainEntrypointsVersion > 1) {
|
|
185
165
|
if (!targetHandlePrefix) {
|
|
186
|
-
targetHandlePrefix = deriveDefaultHandlePrefixFromComposerJsonOrThemeName(shared_1.kebabCase);
|
|
166
|
+
targetHandlePrefix = deriveDefaultHandlePrefixFromComposerJsonOrThemeName(shared_1.kebabCase) ?? "";
|
|
187
167
|
if (!targetHandlePrefix) {
|
|
188
168
|
throw new Error("Plain Entrypoints V2 and higher require either 'targetHandlePrefix' to be set or an adjacent composer.json or style.css file to be present");
|
|
189
169
|
}
|
|
@@ -192,7 +172,9 @@ function buildVerifiedConfig(config) {
|
|
|
192
172
|
throw new Error("Plain Entrypoints V2 and higher require 'outputDir' to be set");
|
|
193
173
|
}
|
|
194
174
|
}
|
|
195
|
-
|
|
175
|
+
// Only the lazyLoader emitters read this, so an absence of package metadata is not worth failing a build
|
|
176
|
+
// over: php-writer treats an empty namespace as "emit no namespace", which is what we did before 3.10.0
|
|
177
|
+
const targetNamespace = config.targetNamespace || deriveDefaultHandlePrefixFromComposerJsonOrThemeName(shared_1.camelCaseForPHPLabels, true) || "";
|
|
196
178
|
const { staticEntrypoints, dynamicEntrypoints } = (0, entrypoint_resolution_logic_1.resolveAllConfigLevelEntrypoints)(config);
|
|
197
179
|
const rawSources = [...staticEntrypoints, ...dynamicEntrypoints];
|
|
198
180
|
let variablesFilePath = undefined;
|
|
@@ -205,31 +187,58 @@ function buildVerifiedConfig(config) {
|
|
|
205
187
|
extensionsVersion = 3; // Version 3 is a backwards-compatible upgrade of version 2, so we can automatically upgrade everything
|
|
206
188
|
}
|
|
207
189
|
const cfg = {
|
|
208
|
-
currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries,
|
|
209
|
-
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, srcDir, srcPrefixes, targetHandlePrefix,
|
|
210
|
-
onlyRunPostCSSOnPCSS, targetNamespace, useBlockSupportsAsThemeJsonDefaults
|
|
190
|
+
currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries,
|
|
191
|
+
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, srcDir, srcPrefixes, targetHandlePrefix,
|
|
192
|
+
useUnifiedLoader, includePostInitFallback, omitDistDev, onlyRunPostCSSOnPCSS, targetNamespace, useBlockSupportsAsThemeJsonDefaults
|
|
211
193
|
};
|
|
212
194
|
// Destination -> source map
|
|
213
195
|
const allocatedDestinations = {};
|
|
214
|
-
const partiallyVerifiedSources = rawSources.map(
|
|
215
|
-
const { destination, additionalDependencies = [], assumeGlobalizedPlauditLibraries = cfg.assumeGlobalizedPlauditLibraries, bundleAnalyzer = false, directoryLayout, externalize, withLegacyBlocksIn = false, lazyLoader, pathQueryParameters: rawPathQueryParameters, enqueuingFlags: rawEnqueuingFlags } =
|
|
216
|
-
|
|
217
|
-
|
|
196
|
+
const partiallyVerifiedSources = rawSources.map(([src, config]) => {
|
|
197
|
+
const { destination, additionalDependencies = [], assumeGlobalizedPlauditLibraries = cfg.assumeGlobalizedPlauditLibraries, bundleAnalyzer = false, directoryLayout, externalize, withLegacyBlocksIn = false, lazyLoader, pathQueryParameters: rawPathQueryParameters, enqueuingFlags: rawEnqueuingFlags, locations: rawSourceLocations, } = config;
|
|
198
|
+
// This guards against a crash later on down the line due to trying to run a spread on a boolean
|
|
199
|
+
if (externalize && typeof externalize !== 'string' && typeof externalize !== 'object') {
|
|
200
|
+
throw new TypeError(`externalize must be a string, an array or an object, but "${src}" set externalize to a ${typeof externalize}`);
|
|
201
|
+
}
|
|
202
|
+
const { flags: queryEnqueuingFlags, remainder: pathQueryParameters, handle: pathQueryHandle } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(rawPathQueryParameters, src, 'path query parameters');
|
|
203
|
+
const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(src, rawEnqueuingFlags, queryEnqueuingFlags);
|
|
218
204
|
const normalizedParts = { additionalDependencies, assumeGlobalizedPlauditLibraries, bundleAnalyzer, directoryLayout, externalize, withLegacyBlocksIn, lazyLoader };
|
|
219
|
-
|
|
220
|
-
|
|
205
|
+
let locations;
|
|
206
|
+
if (pathQueryHandle === undefined) {
|
|
207
|
+
locations = typeof rawSourceLocations === 'string' || typeof rawSourceLocations === 'function' || (rawSourceLocations !== undefined && 'niceName' in rawSourceLocations)
|
|
208
|
+
? { handle: rawSourceLocations } : rawSourceLocations ?? {};
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
const rawSourceHandle = typeof rawSourceLocations === 'string' || typeof rawSourceLocations === 'function' || (rawSourceLocations !== undefined && 'niceName' in rawSourceLocations)
|
|
212
|
+
? rawSourceLocations : rawSourceLocations?.handle;
|
|
213
|
+
if (rawSourceHandle === undefined) {
|
|
214
|
+
locations = { handle: pathQueryHandle };
|
|
215
|
+
}
|
|
216
|
+
else if (typeof rawSourceHandle === 'string') {
|
|
217
|
+
if (rawSourceHandle !== pathQueryHandle) {
|
|
218
|
+
throw new ReferenceError(`Encountered mismatched handles "${rawSourceHandle}" and "${pathQueryHandle}" when preparing "${src}"`);
|
|
219
|
+
}
|
|
220
|
+
locations = { handle: pathQueryHandle };
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
throw new ReferenceError(`Encountered a function handle and a path query handle when preparing "${src}"`);
|
|
224
|
+
}
|
|
225
|
+
// This is just a means of merging the new handle into the rawSourceLocations config without mutating the base config
|
|
226
|
+
if (rawSourceLocations !== undefined && typeof rawSourceLocations !== 'function' && typeof rawSourceLocations !== 'string') {
|
|
227
|
+
locations = { ...rawSourceLocations, ...locations };
|
|
228
|
+
}
|
|
229
|
+
}
|
|
221
230
|
if (typeof locations.registerScriptArgs === 'string' && !['lazy', 'eager', 'inline'].includes(locations.registerScriptArgs)) {
|
|
222
231
|
throw new ReferenceError("The only supported string values for registerScriptArgs are 'lazy', 'eager', and 'inline'");
|
|
223
232
|
}
|
|
224
233
|
if (destination !== undefined) {
|
|
225
234
|
const effectiveDestination = toEffectiveWebpackDestination(destination);
|
|
226
|
-
allocatedDestinations[effectiveDestination] =
|
|
227
|
-
return [
|
|
235
|
+
allocatedDestinations[effectiveDestination] = src; // We need to pre-populate the allocatedDestinations map with statically declared destinations
|
|
236
|
+
return [src, { ...normalizedParts, locations, destination, effectiveDestination, staticallyDeclaredDestination: true, pathQueryParameters, enqueuingFlags }];
|
|
228
237
|
}
|
|
229
238
|
else {
|
|
230
|
-
const naiveDestination = deriveNaiveDestinationFromUnverifiedSourceEntry(
|
|
239
|
+
const naiveDestination = deriveNaiveDestinationFromUnverifiedSourceEntry(src, destination, srcPrefixes);
|
|
231
240
|
const effectiveDestination = toEffectiveWebpackDestination(naiveDestination);
|
|
232
|
-
return [
|
|
241
|
+
return [src, { ...normalizedParts, locations, destination: naiveDestination, effectiveDestination, staticallyDeclaredDestination: false, pathQueryParameters, enqueuingFlags }];
|
|
233
242
|
}
|
|
234
243
|
});
|
|
235
244
|
const dynamicEffectiveDestinationsWithExpectedNaiveDuplicates = partiallyVerifiedSources
|
|
@@ -248,7 +257,7 @@ function toEffectiveWebpackDestination(destination) {
|
|
|
248
257
|
const pathParts = (0, node_path_1.parse)(destination);
|
|
249
258
|
return (0, node_path_1.join)(pathParts.dir, pathParts.name);
|
|
250
259
|
}
|
|
251
|
-
function deriveNaiveDestinationFromUnverifiedSourceEntry(
|
|
260
|
+
function deriveNaiveDestinationFromUnverifiedSourceEntry(src, destination, srcPrefixes) {
|
|
252
261
|
if (destination !== undefined) {
|
|
253
262
|
return destination;
|
|
254
263
|
}
|
|
@@ -287,11 +296,14 @@ function finalizeEntryDestination(entry, dynamicEffectiveDestinationsWithExpecte
|
|
|
287
296
|
allocatedDestinations[derivedDestination] = entry[0];
|
|
288
297
|
return [entry[0], { ...entry[1], destination: derivedDestination }];
|
|
289
298
|
}
|
|
290
|
-
|
|
299
|
+
/**
|
|
300
|
+
* TODO: WTF is the bot on about here?
|
|
301
|
+
* Derives a prefix from whichever piece of package metadata sits next to the config. Returns undefined
|
|
302
|
+
* when there is nothing to derive from at all — a caller that cannot proceed without one says so itself,
|
|
303
|
+
* because the ones that can (see `targetNamespace`) would otherwise fail builds that never needed it. A
|
|
304
|
+
* file that *is* present but unusable still throws, since that is a misconfiguration rather than an absence.
|
|
305
|
+
*/
|
|
291
306
|
function deriveDefaultHandlePrefixFromComposerJsonOrThemeName(stringTransformer, keepPlauditSep = false) {
|
|
292
|
-
if (defaultHandlePrefix !== undefined) {
|
|
293
|
-
return defaultHandlePrefix;
|
|
294
|
-
}
|
|
295
307
|
let composerJson;
|
|
296
308
|
try {
|
|
297
309
|
composerJson = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(process.cwd(), "composer.json"), 'utf-8'));
|
|
@@ -306,7 +318,12 @@ function deriveDefaultHandlePrefixFromComposerJsonOrThemeName(stringTransformer,
|
|
|
306
318
|
return stringTransformer(keepPlauditSep ? composerJson.name.replace(/plaudit\/plaudit-/, 'plaudit/') : composerJson.name.replace(/plaudit\/plaudit/, 'plaudit'));
|
|
307
319
|
}
|
|
308
320
|
function deriveDefaultHandlePrefixFromThemeName(stringTransformer) {
|
|
309
|
-
const
|
|
321
|
+
const styleFilePath = (0, node_path_1.join)(process.cwd(), "style.css");
|
|
322
|
+
if (!(0, node_fs_1.existsSync)(styleFilePath)) {
|
|
323
|
+
// Then there is no package metadata to derive anything from
|
|
324
|
+
return undefined;
|
|
325
|
+
}
|
|
326
|
+
const styleFileContents = (0, node_fs_1.readFileSync)(styleFilePath, 'utf-8');
|
|
310
327
|
const themeName = /^\W*Theme\s*Name:\s*(.+)$/im.exec(styleFileContents)?.[1]?.trim();
|
|
311
328
|
if (!themeName) {
|
|
312
329
|
throw new ReferenceError("targetHandlePrefix was not set and the adjacent style.css file does not have a valid name in it");
|
|
@@ -378,7 +395,7 @@ function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGl
|
|
|
378
395
|
?? [];
|
|
379
396
|
plugins.splice(0, 0, new PackageConfigSanityChecker_1.PackageConfigSanityChecker());
|
|
380
397
|
if (bundleAnalyzer) {
|
|
381
|
-
plugins.splice(0, 0, new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({ analyzerMode: 'static' }));
|
|
398
|
+
plugins.splice(0, 0, new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({ analyzerMode: 'static', openAnalyzer: bundleAnalyzer !== 'no-auto-open' }));
|
|
382
399
|
}
|
|
383
400
|
const removeEmptyScriptsPlugin = new webpack_remove_empty_scripts_1.default({
|
|
384
401
|
stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
|
|
@@ -401,8 +418,8 @@ function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGl
|
|
|
401
418
|
console.error("Once those commands have finished, re-run whichever command had this error. If it still doesn't work, report the issue immediately.");
|
|
402
419
|
throw new Error("Cannot apply externals when they have been disabled via CLI flag. This will greatly increase bundle size and will likely cause the build to fail");
|
|
403
420
|
}
|
|
404
|
-
const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(config.externals, assumeGlobalizedPlauditLibraries,
|
|
405
|
-
plugins[dependencyExtractionPluginIndex] = builtDependencyExtractionWebpackPlugin
|
|
421
|
+
const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(config.externals, assumeGlobalizedPlauditLibraries, externalize);
|
|
422
|
+
plugins[dependencyExtractionPluginIndex] = builtDependencyExtractionWebpackPlugin;
|
|
406
423
|
plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin());
|
|
407
424
|
return {
|
|
408
425
|
plugins, removeEmptyScriptsPlugin,
|
|
@@ -431,16 +448,14 @@ function commonConfigProcessingPrep(config, webpackConfig) {
|
|
|
431
448
|
},
|
|
432
449
|
injectSupportForInliningSVGsAsStrings
|
|
433
450
|
].reduce((r, a) => a(r), webpackConfig.module?.rules ?? []);
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
});
|
|
443
|
-
}
|
|
451
|
+
fixedRules.push({
|
|
452
|
+
test: /wpml-config\.xml$/i,
|
|
453
|
+
type: 'asset/resource',
|
|
454
|
+
generator: {
|
|
455
|
+
filename: '[name][ext]',
|
|
456
|
+
emit: false
|
|
457
|
+
}
|
|
458
|
+
});
|
|
444
459
|
return {
|
|
445
460
|
entrypointFields, fixedRules, processingModules, scriptExtension,
|
|
446
461
|
updateCurrentVariables: (value) => currentVariables = value
|
|
@@ -500,7 +515,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
|
|
|
500
515
|
}
|
|
501
516
|
plugin = new EnhancedBlockJSONPlugin_1.EnhancedBlockJSONPlugin(config, dest, removeEmptyScriptsPlugin, contextPath, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
|
|
502
517
|
plugins.push(plugin);
|
|
503
|
-
if (
|
|
518
|
+
if (!processingModules) {
|
|
504
519
|
plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination, plugin));
|
|
505
520
|
}
|
|
506
521
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/plaudit/plaudit-webpack-extensions.git"
|
|
8
|
+
},
|
|
5
9
|
"files": [
|
|
6
10
|
"/dist",
|
|
7
11
|
"README.md",
|
|
@@ -28,7 +32,7 @@
|
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|
|
31
|
-
"@plaudit/gutenberg-api-extensions": "^2.98.
|
|
35
|
+
"@plaudit/gutenberg-api-extensions": "^2.98.2",
|
|
32
36
|
"@types/browser-sync-webpack-plugin": "^2.2.5",
|
|
33
37
|
"@types/jsdom": "^28.0.3",
|
|
34
38
|
"@types/node": "^25.9.5",
|
|
@@ -36,8 +40,16 @@
|
|
|
36
40
|
"@types/postcss-import": "^14.0.3",
|
|
37
41
|
"@types/tapable": "^2.3.0",
|
|
38
42
|
"@types/webpack-sources": "^3.2.3",
|
|
43
|
+
"atob": "^2.1.2",
|
|
44
|
+
"css-loader": "^6.11.0",
|
|
45
|
+
"glob": "^7.2.3",
|
|
46
|
+
"jest": "^30.4.2",
|
|
47
|
+
"lodash": "^4.18.1",
|
|
48
|
+
"mini-css-extract-plugin": "^2.10.2",
|
|
49
|
+
"mkdirp": "^3.0.1",
|
|
39
50
|
"react": "^18.3.1",
|
|
40
51
|
"react-dom": "^18.3.1",
|
|
52
|
+
"rimraf": "^5.0.10",
|
|
41
53
|
"typescript": "^6.0.3",
|
|
42
54
|
"webpack-bundle-analyzer": "^5.3.1"
|
|
43
55
|
},
|
|
@@ -46,7 +58,7 @@
|
|
|
46
58
|
"@plaudit/postcss-color-function": "^5.1.0",
|
|
47
59
|
"@plaudit/postcss-strip-units": "^3.0.0",
|
|
48
60
|
"@plaudit/postcss-variables": "^2.0.1",
|
|
49
|
-
"@wordpress/dependency-extraction-webpack-plugin": "^6.
|
|
61
|
+
"@wordpress/dependency-extraction-webpack-plugin": "^6.53.0",
|
|
50
62
|
"@wordpress/scripts": "^32.6.0",
|
|
51
63
|
"autoprefixer": "^10.5.4",
|
|
52
64
|
"browser-sync": "^3.0.4",
|
|
@@ -57,17 +69,17 @@
|
|
|
57
69
|
"http-proxy-middleware": "^3.0.7",
|
|
58
70
|
"jsdom": "^29.1.1",
|
|
59
71
|
"json2php": "0.0.12",
|
|
60
|
-
"postcss": "^8.5.
|
|
72
|
+
"postcss": "^8.5.26",
|
|
61
73
|
"postcss-calc": "^10.1.1",
|
|
62
74
|
"postcss-functions": "^4.0.2",
|
|
63
|
-
"postcss-import": "^16.
|
|
75
|
+
"postcss-import": "^16.2.0",
|
|
64
76
|
"postcss-loader": "^8.2.1",
|
|
65
77
|
"postcss-mixins": "^12.1.2",
|
|
66
78
|
"postcss-nested": "^7.0.2",
|
|
67
79
|
"postcss-property-lookup": "^3.0.0",
|
|
68
80
|
"postcss-reporter": "^7.1.0",
|
|
69
81
|
"postcss-url": "^10.1.4",
|
|
70
|
-
"webpack": "^5.
|
|
82
|
+
"webpack": "^5.109.2",
|
|
71
83
|
"webpack-remove-empty-scripts": "^1.1.1",
|
|
72
84
|
"xml-formatter": "^3.7.0"
|
|
73
85
|
},
|
|
@@ -79,6 +91,11 @@
|
|
|
79
91
|
"clean": "rm -rf dist",
|
|
80
92
|
"build:clean": "pnpm run clean && pnpm run build",
|
|
81
93
|
"watch": "tsc -w",
|
|
94
|
+
"test": "pnpm run build && pnpm run test:no-build",
|
|
95
|
+
"test:no-build": "rm -rf tests/.tmp/coverage/jest && NODE_V8_COVERAGE=tests/.tmp/coverage/jest jest",
|
|
96
|
+
"test:update": "pnpm run build && rm -rf tests/.tmp/coverage/jest && NODE_V8_COVERAGE=tests/.tmp/coverage/jest jest -u",
|
|
97
|
+
"test:paths": "pnpm run build && jest \"tests/integration-[0-9]+x/paths\"",
|
|
98
|
+
"test:gaps": "node tests/tools/coverage-gaps.js",
|
|
82
99
|
"update": "pnpm add --config '@plaudit/pnpm-plugin-plaudit-config@*' && pnpm up"
|
|
83
100
|
}
|
|
84
101
|
}
|