@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.
Files changed (61) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/USER-GUIDE.md +2 -1
  3. package/package.json +27 -49
  4. package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +0 -25
  5. package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +0 -86
  6. package/dist/plugins/AbstractBiPhasicGroupPlugin.d.ts +0 -31
  7. package/dist/plugins/AbstractBiPhasicGroupPlugin.js +0 -91
  8. package/dist/plugins/AdditionalDependencyInjectorPlugin.d.ts +0 -11
  9. package/dist/plugins/AdditionalDependencyInjectorPlugin.js +0 -58
  10. package/dist/plugins/EnhancedBlockJSONPlugin.d.ts +0 -47
  11. package/dist/plugins/EnhancedBlockJSONPlugin.js +0 -657
  12. package/dist/plugins/EnhancedDynamicEntryPlugin.d.ts +0 -8
  13. package/dist/plugins/EnhancedDynamicEntryPlugin.js +0 -14
  14. package/dist/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +0 -20
  15. package/dist/plugins/ExtensionsConfigFileGeneratorPlugin.js +0 -191
  16. package/dist/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +0 -9
  17. package/dist/plugins/ExtensionsConfigFileGeneratorPluginV1.js +0 -45
  18. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts +0 -4
  19. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.js +0 -15
  20. package/dist/plugins/MixableBiPhasicGroupAndEntryPlugin.d.ts +0 -6
  21. package/dist/plugins/MixableBiPhasicGroupAndEntryPlugin.js +0 -13
  22. package/dist/plugins/MixableBiPhasicGroupPlugin.d.ts +0 -6
  23. package/dist/plugins/MixableBiPhasicGroupPlugin.js +0 -13
  24. package/dist/plugins/PackageConfigSanityChecker.d.ts +0 -4
  25. package/dist/plugins/PackageConfigSanityChecker.js +0 -30
  26. package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +0 -26
  27. package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +0 -392
  28. package/dist/plugins/SpecialAssetHandlingPlugin.d.ts +0 -12
  29. package/dist/plugins/SpecialAssetHandlingPlugin.js +0 -134
  30. package/dist/plugins/UnifiedLoaderGenerator.d.ts +0 -21
  31. package/dist/plugins/UnifiedLoaderGenerator.js +0 -144
  32. package/dist/plugins/VariablesJSMonitorPlugin.d.ts +0 -7
  33. package/dist/plugins/VariablesJSMonitorPlugin.js +0 -20
  34. package/dist/plugins/WPMLConfigBuilder.d.ts +0 -17
  35. package/dist/plugins/WPMLConfigBuilder.js +0 -472
  36. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +0 -4
  37. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js +0 -147
  38. package/dist/plugins/index.d.ts +0 -8
  39. package/dist/plugins/index.js +0 -24
  40. package/dist/plugins/static-configs.d.ts +0 -3
  41. package/dist/plugins/static-configs.js +0 -44
  42. package/dist/shared.d.ts +0 -311
  43. package/dist/shared.js +0 -536
  44. package/dist/utils/common-config-helpers.d.ts +0 -28
  45. package/dist/utils/common-config-helpers.js +0 -489
  46. package/dist/utils/css-writer.d.ts +0 -4
  47. package/dist/utils/css-writer.js +0 -46
  48. package/dist/utils/entrypoint-resolution-logic.d.ts +0 -13
  49. package/dist/utils/entrypoint-resolution-logic.js +0 -82
  50. package/dist/utils/location-encoding-filename-parser.d.ts +0 -30
  51. package/dist/utils/location-encoding-filename-parser.js +0 -120
  52. package/dist/utils/path-query-and-related-helpers.d.ts +0 -64
  53. package/dist/utils/path-query-and-related-helpers.js +0 -269
  54. package/dist/utils/pseudo-semaphore.d.ts +0 -14
  55. package/dist/utils/pseudo-semaphore.js +0 -79
  56. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts +0 -72
  57. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js +0 -518
  58. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts +0 -56
  59. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js +0 -155
  60. package/dist/wordpress-scripts-wrapper.d.ts +0 -4
  61. package/dist/wordpress-scripts-wrapper.js +0 -698
@@ -1,489 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.joinPossiblyAbsolutePaths = joinPossiblyAbsolutePaths;
7
- exports.groupEntrypointsByAssetFile = groupEntrypointsByAssetFile;
8
- exports.resolveEntryFromDirectory = resolveEntryFromDirectory;
9
- exports.commonMakeWebpackConfig = commonMakeWebpackConfig;
10
- const node_fs_1 = __importDefault(require("node:fs"));
11
- const promises_1 = require("node:fs/promises");
12
- const node_path_1 = require("node:path");
13
- const location_encoding_filename_parser_1 = require("./location-encoding-filename-parser");
14
- const path_query_and_related_helpers_1 = require("./path-query-and-related-helpers");
15
- const shared_1 = require("../shared");
16
- const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
17
- function joinPossiblyAbsolutePaths(...paths) {
18
- return paths.filter((p) => !!p)
19
- .reduce((res, p) => !res || (0, node_path_1.isAbsolute)(p) ? p : (0, node_path_1.join)(res, p), '') || '.';
20
- }
21
- function groupEntrypointsByAssetFile(entrypoints, entrypointNameExtractor) {
22
- const seenPaths = new Map();
23
- for (const entrypoint of entrypoints) {
24
- const entrypointName = entrypointNameExtractor(entrypoint);
25
- const key = entrypointName.substring(0, entrypointName.length - (0, node_path_1.extname)(entrypointName).length);
26
- let seen = seenPaths.get(key);
27
- if (seen === undefined) {
28
- seenPaths.set(key, seen = []);
29
- }
30
- seen.push(entrypoint);
31
- }
32
- return seenPaths;
33
- }
34
- function mapToRealEntrypoints(entrypoint, dir, supportedExtensions, args) {
35
- const { mapper = ep => ep, dest } = args;
36
- return (Array.isArray(entrypoint) ? entrypoint : [entrypoint])
37
- .map(ep => joinPossiblyAbsolutePaths(dir, mapper(ep)))
38
- .filter(ep => supportedExtensions(ep) && node_fs_1.default.statSync(ep, { throwIfNoEntry: false })?.isFile())
39
- .map(path_query_and_related_helpers_1.unpackPotentiallyPrefixedFilePath)
40
- .map(([ep, rawPathQueryParameters]) => {
41
- const parsedEntrypoint = (0, node_path_1.parse)(ep);
42
- const entrypointField = shared_1.styleExtension.test(ep) ? 'style' : shared_1.scriptWithModuleExtension.test(ep) ? 'viewScriptModule' : 'script';
43
- const { flags: enqueuingFlags, remainder: pathQueryParameters, handle } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(rawPathQueryParameters, ep, 'path query parameters');
44
- const fakeEntrypointInfo = {
45
- blockJsonOrigin: args.entrypointJsonOrigin,
46
- entrypointField,
47
- originalValue: ep,
48
- entrypointName: parsedEntrypoint.name,
49
- handle: handle ?? dest.locations.handle ? (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handle ?? dest.locations.handle, parsedEntrypoint.name, parsedEntrypoint.name) : parsedEntrypoint.name,
50
- handleGroup: (0, shared_1.getHandleGroup)(entrypointField),
51
- dest,
52
- absoluteSrc: ep,
53
- pathQueryParameters,
54
- enqueuingFlags,
55
- };
56
- return [joinPossiblyAbsolutePaths(dest.destination, (0, node_path_1.basename)(parsedEntrypoint.dir), parsedEntrypoint.name),
57
- { import: [ep], plauditMetadata: fakeEntrypointInfo }];
58
- });
59
- }
60
- function parseEntrypointsJSON(dir, dest, supportedExtensions) {
61
- const entrypointJsonOrigin = (0, node_path_1.join)(dir, 'entrypoints.json');
62
- const entrypointsJSON = JSON.parse(node_fs_1.default.readFileSync(entrypointJsonOrigin, 'utf8'));
63
- if (Array.isArray(entrypointsJSON)) {
64
- return mapToRealEntrypoints(entrypointsJSON, dir, supportedExtensions, { dest, entrypointJsonOrigin });
65
- }
66
- else {
67
- return Object.entries(entrypointsJSON).flatMap(([name, config]) => {
68
- if (Array.isArray(config)) {
69
- return config.flatMap(c => mapToRealEntrypoints(c, dir, supportedExtensions, { dest, entrypointJsonOrigin }));
70
- }
71
- else {
72
- return [[name, config]];
73
- /* TODO: Fix compat with entrypoints.json in object mode
74
- if (typeof config.import === 'string') {
75
- config.import = joinPossiblyAbsolutePaths(dir, config.import);
76
- } else {
77
- config.import = config.import.map(c => joinPossiblyAbsolutePaths(dir, c));
78
- }
79
- return [name, config];
80
- */
81
- }
82
- });
83
- }
84
- }
85
- function determineEntrypointType(entrypoint, scriptExtension) {
86
- let res = (0, shared_1.scriptOrStyleTest)(entrypoint[0], scriptExtension);
87
- if (res) {
88
- return res;
89
- }
90
- if (typeof entrypoint[1] === 'string') {
91
- return (0, shared_1.scriptOrStyleTest)(entrypoint[1], scriptExtension);
92
- }
93
- else if (Array.isArray(entrypoint[1])) {
94
- return entrypoint[1].reduce((prior, ep) => prior || (0, shared_1.scriptOrStyleTest)(ep, scriptExtension), "");
95
- }
96
- else if (typeof entrypoint[1].import === 'string') {
97
- return (0, shared_1.scriptOrStyleTest)(entrypoint[1].import, scriptExtension);
98
- }
99
- else {
100
- return entrypoint[1].import.reduce((prior, ep) => prior || (0, shared_1.scriptOrStyleTest)(ep, scriptExtension), "");
101
- }
102
- }
103
- function injectTypeAndCountToEntrypointName(entrypointName, type, typeCounts) {
104
- const entrypointBasename = entrypointName.substring(0, entrypointName.length - (0, node_path_1.extname)(entrypointName).length);
105
- const parts = [];
106
- if (type) {
107
- parts.push(type);
108
- }
109
- if (typeCounts[type] ?? (typeCounts[type] = 0)) {
110
- parts.push(typeCounts[type].toString());
111
- }
112
- typeCounts[type] += 1;
113
- return `${entrypointBasename}_${parts.join('-')}${(0, node_path_1.extname)(entrypointName)}`;
114
- }
115
- function addPotentiallyDuplicatedEntrypointName(entry, entrypoint, typeCounts, scriptExtension) {
116
- const type = determineEntrypointType(entrypoint, scriptExtension);
117
- let potentialKey = injectTypeAndCountToEntrypointName(entrypoint[0], type, typeCounts);
118
- while (entry[potentialKey]) {
119
- potentialKey = injectTypeAndCountToEntrypointName(entrypoint[0], type, typeCounts);
120
- }
121
- entry[potentialKey] = entrypoint[1];
122
- }
123
- function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
124
- const { entrypointFields, processingModules, scriptExtension } = commonConfig;
125
- return async () => {
126
- const seenExplicitHandles = { scriptHandles: {}, styleHandles: {}, scriptModuleHandles: {} };
127
- const loadingEntrypoints = [];
128
- for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
129
- if (!dirent.isDirectory() || (0, shared_1.shouldBeSkipped)(dirent.name)) {
130
- continue;
131
- }
132
- const dir = joinPossiblyAbsolutePaths(srcRoot, dirent.name);
133
- loadingEntrypoints.push(new Promise(async (resolve) => {
134
- const rawEntrypoints = [];
135
- const wpmlFiles = [];
136
- try {
137
- const blockJsonOrigin = (0, node_path_1.join)(dir, 'block.json');
138
- const blockJson = JSON.parse(await (0, promises_1.readFile)(blockJsonOrigin, 'utf8'));
139
- const blockJsonChunkName = (0, node_path_1.join)(dest.destination, (0, node_path_1.relative)(srcRoot, dir), "block");
140
- const filesRegisteredByJson = [];
141
- const presentEntrypoints = (await Promise.all(entrypointFields
142
- .filter(entrypointField => (0, shared_1.isScriptModuleField)(entrypointField) === processingModules && entrypointField in blockJson)
143
- .flatMap(entrypointField => {
144
- return (Array.isArray(blockJson[entrypointField]) ? blockJson[entrypointField] : [blockJson[entrypointField]])
145
- .filter(originalValue => typeof originalValue === 'string')
146
- .filter(originalValue => originalValue?.startsWith("file:"))
147
- .map(async (originalValue) => {
148
- const [entrypointPath, rawLocalPathQueryParameters] = (0, path_query_and_related_helpers_1.unpackPotentiallyPrefixedFilePath)(originalValue);
149
- const absoluteSrc = (0, node_path_1.normalize)((0, node_path_1.join)(dir, entrypointPath));
150
- filesRegisteredByJson.push(absoluteSrc);
151
- const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilenameForBlock)(absoluteSrc);
152
- const { flags: localEnqueuingFlags, handle, remainder: localPathQueryParameters } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(rawLocalPathQueryParameters, absoluteSrc, "path query parameters");
153
- const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(absoluteSrc, localEnqueuingFlags, parsedFilename?.flags, dest.enqueuingFlags);
154
- const pathQueryParameters = { ...dest.pathQueryParameters, ...localPathQueryParameters };
155
- try {
156
- const stats = await (0, promises_1.stat)(absoluteSrc);
157
- if (!stats.isFile()) {
158
- return undefined;
159
- }
160
- //TODO: Handle alternate methods of declaring a handle
161
- const parsedEntrypoint = (0, node_path_1.parse)((0, node_path_1.normalize)((0, node_path_1.join)(dest.destination, (0, node_path_1.relative)(srcRoot, dir), entrypointPath)));
162
- const extensionlessExpectedSrc = (0, node_path_1.normalize)((0, node_path_1.join)(parsedEntrypoint.dir, parsedEntrypoint.name));
163
- const entrypointName = (0, node_path_1.normalize)(joinPossiblyAbsolutePaths(parsedEntrypoint.dir, parsedEntrypoint.name));
164
- return { entrypointField, originalValue, entrypointName, extensionlessExpectedSrc, absoluteSrc, pathQueryParameters, enqueuingFlags, handle };
165
- }
166
- catch {
167
- return undefined;
168
- }
169
- });
170
- })))
171
- .filter(pe => pe !== undefined);
172
- for await (const dirent of await (0, promises_1.opendir)(dir)) {
173
- if (!dirent.isFile()) {
174
- continue;
175
- }
176
- const absoluteSrc = (0, node_path_1.normalize)((0, node_path_1.join)(dir, dirent.name));
177
- if (filesRegisteredByJson.includes(absoluteSrc)) {
178
- continue;
179
- }
180
- const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilenameForBlock)(absoluteSrc);
181
- if (!parsedFilename) {
182
- continue;
183
- }
184
- const { type, locations, handle, flags } = parsedFilename;
185
- if (((type === 'script-module') !== processingModules)) {
186
- continue;
187
- }
188
- let entrypointField;
189
- if (Object.keys(locations).length === 2) {
190
- if (type === 'script-module') {
191
- console.error(`Blocks cannot have script modules enqueued in editor mode. Found one enqueued in both editor and view in ${dirent.parentPath}. It will be enqueued in view alone.`);
192
- entrypointField = 'viewScriptModule';
193
- }
194
- else {
195
- entrypointField = type;
196
- }
197
- }
198
- else {
199
- const location = (0, shared_1.constantKeys)(locations)[0];
200
- if (type === 'script-module') {
201
- if (location !== 'clientView') {
202
- console.error(`Blocks cannot have script modules enqueued in editor mode. Found one in ${dirent.parentPath}. It will be ignored`);
203
- continue;
204
- }
205
- entrypointField = 'viewScriptModule';
206
- }
207
- else {
208
- entrypointField = (location.substring(6).toLowerCase() + type.substring(0, 1).toUpperCase() + type.substring(1));
209
- }
210
- }
211
- const parsedEntrypoint = (0, node_path_1.parse)((0, node_path_1.normalize)((0, node_path_1.join)(dest.destination, (0, node_path_1.relative)(srcRoot, dir), `./${dirent.name}`)));
212
- const extensionlessExpectedSrc = (0, node_path_1.normalize)((0, node_path_1.join)(parsedEntrypoint.dir, parsedEntrypoint.name));
213
- const entrypointName = (0, node_path_1.normalize)(joinPossiblyAbsolutePaths(parsedEntrypoint.dir, parsedEntrypoint.name));
214
- const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(absoluteSrc, flags, dest.enqueuingFlags);
215
- presentEntrypoints.push({
216
- entrypointField,
217
- originalValue: dirent.name,
218
- entrypointName,
219
- extensionlessExpectedSrc,
220
- absoluteSrc,
221
- pathQueryParameters: dest.pathQueryParameters,
222
- enqueuingFlags,
223
- handle
224
- });
225
- }
226
- const entrypointNamesWithEffectiveDuplicates = presentEntrypoints
227
- .reduce((a, entry) => {
228
- // If it's undefined, then this is the first instance, otherwise, it's not the first instance and, therefore, is expected to be a duplicate
229
- a[entry.entrypointName] = (a[entry.entrypointName] !== undefined);
230
- return a;
231
- }, {});
232
- const getDefaultHandle = (presentEntrypoint) => {
233
- const baseSuffix = `_${(0, shared_1.isStyleField)(presentEntrypoint.entrypointField) ? "style" : "script"}`;
234
- let count = 0, suffix = baseSuffix, deduplicatedEntrypointName;
235
- while (((deduplicatedEntrypointName = (presentEntrypoint.entrypointName + suffix)) in allocatedDestinations)
236
- && allocatedDestinations[deduplicatedEntrypointName] !== presentEntrypoint.originalValue) {
237
- suffix = baseSuffix + "_" + (++count);
238
- }
239
- return { count, suffix, deduplicatedEntrypointName };
240
- };
241
- const handlePrefix = blockJson['name']?.toString() ?? `__UNKNOWN_PREFIX__/${dirent.name}`;
242
- const allocatedDestinations = {};
243
- const resolvedBlockEntrypoints = presentEntrypoints
244
- .map(presentEntrypoint => {
245
- const overallSource = (0, node_path_1.dirname)(blockJsonOrigin);
246
- // The handle suffix is the asset's extensionless name relative to its own block, so it
247
- // has to come off the real on-disk path rather than the destination-relative expected src.
248
- const parsedAbsoluteSrc = (0, node_path_1.parse)(presentEntrypoint.absoluteSrc);
249
- const overallSourceRelativeName = (0, node_path_1.normalize)((0, node_path_1.join)((0, node_path_1.relative)(overallSource, parsedAbsoluteSrc.dir), parsedAbsoluteSrc.name));
250
- const handleGroup = (0, shared_1.getHandleGroup)(presentEntrypoint.entrypointField);
251
- let explicitlySetHandle;
252
- if (presentEntrypoint.handle) {
253
- if (typeof presentEntrypoint.handle === 'string') {
254
- explicitlySetHandle = presentEntrypoint.handle;
255
- }
256
- else if ('niceName' in presentEntrypoint.handle) {
257
- explicitlySetHandle = `${handlePrefix}/${presentEntrypoint.handle.niceName}`;
258
- }
259
- else {
260
- explicitlySetHandle = presentEntrypoint.handle(`${handlePrefix}/${getDefaultHandle(presentEntrypoint)}`);
261
- }
262
- if (explicitlySetHandle.length < 5) {
263
- throw (0, shared_1.newWebpackErrorForFile)(`The handle was invalid. Received: ${explicitlySetHandle}. Expected: a string that is at least 5 characters long`, overallSourceRelativeName);
264
- }
265
- (seenExplicitHandles[handleGroup][explicitlySetHandle] ??= []).push(overallSource);
266
- }
267
- else {
268
- explicitlySetHandle = undefined;
269
- }
270
- const emittableHandle = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(dest.locations.handle, handlePrefix, explicitlySetHandle ? explicitlySetHandle.substring(handlePrefix.length + 1) : overallSourceRelativeName);
271
- if (!entrypointNamesWithEffectiveDuplicates[presentEntrypoint.entrypointName]) {
272
- return { blockJsonOrigin, ...presentEntrypoint, handle: emittableHandle, dest, handleGroup };
273
- }
274
- const baseSuffix = `_${(0, shared_1.isStyleField)(presentEntrypoint.entrypointField) ? "style" : "script"}`;
275
- let count = 0, suffix = baseSuffix, deduplicatedEntrypointName;
276
- while (((deduplicatedEntrypointName = (presentEntrypoint.entrypointName + suffix)) in allocatedDestinations)
277
- && allocatedDestinations[deduplicatedEntrypointName] !== presentEntrypoint.originalValue) {
278
- suffix = baseSuffix + "_" + (++count);
279
- }
280
- allocatedDestinations[deduplicatedEntrypointName] = presentEntrypoint.originalValue;
281
- const deduplicatedExtensionlessExpectedSrc = presentEntrypoint.extensionlessExpectedSrc + suffix;
282
- return {
283
- blockJsonOrigin,
284
- ...presentEntrypoint,
285
- entrypointName: deduplicatedEntrypointName,
286
- extensionlessExpectedSrc: deduplicatedExtensionlessExpectedSrc,
287
- handle: emittableHandle,
288
- handleGroup,
289
- dest
290
- };
291
- });
292
- rawEntrypoints.push(...resolvedBlockEntrypoints
293
- .map(resolvedBlockEntrypoint => {
294
- return [
295
- resolvedBlockEntrypoint.entrypointName,
296
- {
297
- import: [resolvedBlockEntrypoint.absoluteSrc],
298
- plauditMetadata: resolvedBlockEntrypoint
299
- }
300
- ];
301
- }));
302
- rawEntrypoints.push([blockJsonChunkName, { import: [blockJsonOrigin], plauditMetadata: { purpose: "block-json-inclusion-assurance", dest, absoluteSrc: blockJsonOrigin } }]);
303
- wpmlFiles.push((0, node_path_1.join)(dir, 'block.json'));
304
- }
305
- catch (e) {
306
- try {
307
- const packageJsonOrigin = (0, node_path_1.join)(dir, 'package.json');
308
- const packageJson = JSON.parse(await (0, promises_1.readFile)(packageJsonOrigin, 'utf8'));
309
- if (packageJson['main']) {
310
- rawEntrypoints.push(...mapToRealEntrypoints(packageJson['main'], dir, s => commonConfig.scriptExtension.test(s), { dest, entrypointJsonOrigin: packageJsonOrigin }));
311
- }
312
- if (!processingModules && packageJson['style']) {
313
- rawEntrypoints.push(...mapToRealEntrypoints(packageJson['style'], dir, s => shared_1.styleExtension.test(s), { dest, entrypointJsonOrigin: packageJsonOrigin }));
314
- }
315
- }
316
- catch (e) {
317
- try {
318
- rawEntrypoints.push(...parseEntrypointsJSON(dir, dest, ep => commonConfig.scriptExtension.test(ep) || (!processingModules && shared_1.styleExtension.test(ep))));
319
- }
320
- catch (e) {
321
- // This just means that the directory doesn't contain any declared entrypoints.
322
- }
323
- }
324
- }
325
- if (!processingModules) {
326
- try {
327
- const wpmlFilePath = (0, node_path_1.join)(dir, "wpml-config.xml");
328
- await (0, promises_1.access)(wpmlFilePath);
329
- wpmlFiles.push(wpmlFilePath);
330
- }
331
- catch (e) {
332
- // This just means that the file doesn't exist
333
- }
334
- }
335
- resolve([rawEntrypoints, wpmlFiles]);
336
- }));
337
- }
338
- const allEntrypoints = await Promise.all(loadingEntrypoints);
339
- const perAssetPathGroupedEntrypoints = groupEntrypointsByAssetFile(allEntrypoints.flatMap(e => e[0]), e => e[0]);
340
- const conflictingHandles = Object.values(seenExplicitHandles)
341
- .flatMap(handles => Object.entries(handles))
342
- .filter(([, sources]) => sources.length > 1)
343
- .map(([handle, sources]) => `${handle}: ${sources.join(", ")}`);
344
- if (conflictingHandles.length > 0) {
345
- throw (0, shared_1.newCleanWebpackError)("Encountered conflicting explicitly-set handles:\n" + conflictingHandles.join("\n"));
346
- }
347
- const currentEntry = {};
348
- for (const groupedEntrypoints of perAssetPathGroupedEntrypoints.values()) {
349
- if (groupedEntrypoints.length === 1 && groupedEntrypoints[0] !== undefined) {
350
- currentEntry[groupedEntrypoints[0][0]] = groupedEntrypoints[0][1];
351
- }
352
- else {
353
- const typeCounts = {};
354
- for (const entrypoint of groupedEntrypoints) {
355
- addPotentiallyDuplicatedEntrypointName(currentEntry, entrypoint, typeCounts, scriptExtension);
356
- }
357
- }
358
- }
359
- if (!processingModules) {
360
- const wpmlEntrypointFiles = allEntrypoints.flatMap(e => e[1]);
361
- const absoluteSrc = (0, node_path_1.join)(srcRoot, "wpml-config.xml");
362
- try {
363
- await (0, promises_1.access)(absoluteSrc);
364
- currentEntry["wpml-config.xml"] = { import: [(0, node_path_1.join)(srcRoot, "wpml-config.xml"), ...wpmlEntrypointFiles], plauditMetadata: { purpose: "wpml-config-xml", dest, absoluteSrc } };
365
- }
366
- catch (e) {
367
- // If the wpml-config.xml file does not exist, just "import" the other files that will be used to build the emitted version
368
- if (wpmlEntrypointFiles.length) {
369
- currentEntry["wpml-config.xml"] = { import: wpmlEntrypointFiles, plauditMetadata: { purpose: "wpml-config-xml", dest, absoluteSrc } };
370
- }
371
- }
372
- }
373
- return currentEntry;
374
- };
375
- }
376
- function commonMakeWebpackConfig(config, commonConfig, webpackConfig, externalize, plugins, canClean) {
377
- const { variablesFilePath } = config;
378
- const { fixedRules, processingModules, updateCurrentVariables } = commonConfig;
379
- const outPath = joinPossiblyAbsolutePaths(process.cwd(), config.outputDir);
380
- let publicPath = webpackConfig.output?.publicPath;
381
- let viableRoots = [...(Array.isArray(webpackConfig.context) ? webpackConfig.context : [webpackConfig.context ?? process.cwd()])];
382
- let wpContentHolderDirectory = process.cwd();
383
- while (wpContentHolderDirectory.length > 5) {
384
- if ((0, node_path_1.basename)(wpContentHolderDirectory) === 'wp-content') {
385
- wpContentHolderDirectory = (0, node_path_1.dirname)(wpContentHolderDirectory);
386
- if (wpContentHolderDirectory.length > 5) {
387
- viableRoots.push(wpContentHolderDirectory);
388
- }
389
- break;
390
- }
391
- wpContentHolderDirectory = (0, node_path_1.dirname)(wpContentHolderDirectory);
392
- }
393
- const distinctViableRoots = new Set();
394
- viableRoots = viableRoots.filter(value => distinctViableRoots.has(value) ? false : distinctViableRoots.add(value) && true);
395
- let outputLibrary;
396
- if (externalize) {
397
- if (Array.isArray(externalize) || typeof externalize === 'string') {
398
- outputLibrary = {
399
- name: externalize,
400
- type: "window"
401
- };
402
- }
403
- else {
404
- const originalLibrary = webpackConfig.output?.library;
405
- if (originalLibrary && typeof originalLibrary === 'object' && !Array.isArray(originalLibrary)) {
406
- outputLibrary = {
407
- ...originalLibrary,
408
- ...externalize
409
- };
410
- }
411
- else {
412
- outputLibrary = externalize;
413
- }
414
- }
415
- }
416
- else {
417
- outputLibrary = webpackConfig.output?.library;
418
- }
419
- const extensions = processingModules ? ['.mjsx', '.mjs', '.mtsx', '.mts', '...'] : ['.jsx', '.tsx', '.ts', '...'];
420
- // `dist` (SERVER_MODE=production, or omitDistDev) is always minified production. `dist-dev` follows NODE_ENV so `wp-scripts start` stays fast.
421
- const isProductionBuild = !(0, shared_1.isDistDevOutputPath)(config.outputDir) || process.env['NODE_ENV'] === 'production';
422
- return {
423
- ...webpackConfig,
424
- devtool: isProductionBuild ? 'source-map' : (webpackConfig.devtool ?? 'eval-cheap-module-source-map'),
425
- mode: isProductionBuild ? 'production' : 'development',
426
- output: {
427
- ...webpackConfig.output,
428
- path: outPath,
429
- chunkFilename: 'webpack-chunks/[id].js',
430
- publicPath: publicPath,
431
- library: outputLibrary,
432
- clean: canClean ? webpackConfig.output?.clean : false
433
- },
434
- optimization: {
435
- ...webpackConfig.optimization,
436
- minimize: isProductionBuild,
437
- splitChunks: {
438
- ...(webpackConfig.optimization?.splitChunks || {}),
439
- cacheGroups: {
440
- style: {
441
- // This is a flagrant abuse of cache groups, but it fixes a persistent problem wherein the dependencies and versions of scripts and styles were bleeding into each other
442
- type: 'css/mini-extract',
443
- chunks: 'all',
444
- enforce: true,
445
- name(_, chunks, cacheGroupKey) {
446
- const chunkName = chunks.find(chunk => chunk.name)?.name;
447
- // We use "__${cacheGroupKey}__" instead of "${cacheGroupKey}-" to make it easier to remove when generating the filename
448
- const filename = `__${cacheGroupKey}__${(0, node_path_1.basename)(chunkName)}`;
449
- const chunkDirname = (0, node_path_1.dirname)(chunkName);
450
- return chunkDirname === '.' ? filename : `${chunkDirname}/${filename}`;
451
- }
452
- },
453
- default: false
454
- }
455
- },
456
- minimizer: isProductionBuild
457
- ? [
458
- ...(webpackConfig.optimization?.minimizer || []),
459
- new css_minimizer_webpack_plugin_1.default()
460
- ]
461
- : webpackConfig.optimization?.minimizer
462
- },
463
- module: {
464
- ...webpackConfig.module,
465
- rules: fixedRules
466
- },
467
- resolve: {
468
- ...webpackConfig.resolve,
469
- roots: viableRoots,
470
- extensions
471
- },
472
- stats: config.stats,
473
- plugins,
474
- entry() {
475
- if (variablesFilePath) {
476
- delete require.cache[require.resolve(variablesFilePath)];
477
- updateCurrentVariables(require(variablesFilePath));
478
- }
479
- return {};
480
- },
481
- performance: {
482
- ...webpackConfig.performance,
483
- assetFilter(assetFilename) {
484
- // We don't want to warn about the sizes of incompressible assets
485
- return !/\.(map|svg|png|jpe?g|gif)$/i.test(assetFilename);
486
- }
487
- }
488
- };
489
- }
@@ -1,4 +0,0 @@
1
- export type WritableCSSObject = {
2
- [property: string]: string | WritableCSSObject;
3
- };
4
- export declare function convertToCSS(writableCSSObject: WritableCSSObject, pretty?: string | boolean): string;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToCSS = convertToCSS;
4
- function convertToCSS(writableCSSObject, pretty = true) {
5
- if (typeof pretty === 'string') {
6
- return convertToCSSPretty(writableCSSObject, pretty);
7
- }
8
- else if (pretty) {
9
- return convertToCSSPretty(writableCSSObject, "");
10
- }
11
- else {
12
- return convertToCSSUgly(writableCSSObject);
13
- }
14
- }
15
- function convertToCSSPretty(writableCSSObject, indentation) {
16
- let res = "";
17
- const entries = Object.entries(writableCSSObject)
18
- .sort(([a], [b]) => a.localeCompare(b));
19
- for (const [selectorOrAttribute, value] of entries) {
20
- res += `${indentation}${selectorOrAttribute}`;
21
- if (typeof value === 'string') {
22
- res += `: ${value};\n`;
23
- }
24
- else {
25
- res += " {\n";
26
- res += convertToCSSPretty(value, indentation + "\t");
27
- res += indentation + "}\n";
28
- }
29
- }
30
- return res;
31
- }
32
- function convertToCSSUgly(writableCSSObject) {
33
- let res = "";
34
- const entries = Object.entries(writableCSSObject)
35
- .sort(([a], [b]) => a.localeCompare(b));
36
- for (const [selectorOrAttribute, value] of entries) {
37
- res += selectorOrAttribute;
38
- if (typeof value === 'string') {
39
- res += `:${value};`;
40
- }
41
- else {
42
- res += "{" + convertToCSSUgly(value) + "}";
43
- }
44
- }
45
- return res;
46
- }
@@ -1,13 +0,0 @@
1
- import { type AdvancedOutputConfig, type PathQueryParameters, type PlauditWordpressWebpackConfig } from "../shared";
2
- export declare const enum SourceType {
3
- blocks = "blocks",
4
- extensions = "extensions",
5
- plain = "plain"
6
- }
7
- export declare function isSourceType(str: string): str is SourceType;
8
- type ResolvedSourceConfig = AdvancedOutputConfig & {
9
- pathQueryParameters?: PathQueryParameters;
10
- };
11
- type Entrypoints = [string, ResolvedSourceConfig][];
12
- export declare function resolveAllConfigLevelEntrypoints(config: PlauditWordpressWebpackConfig, projectRoot?: string): Record<'staticEntrypoints' | 'dynamicEntrypoints', Entrypoints>;
13
- export {};
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSourceType = isSourceType;
4
- exports.resolveAllConfigLevelEntrypoints = resolveAllConfigLevelEntrypoints;
5
- const node_path_1 = require("node:path");
6
- const location_encoding_filename_parser_1 = require("./location-encoding-filename-parser");
7
- const path_query_and_related_helpers_1 = require("./path-query-and-related-helpers");
8
- const shared_1 = require("../shared");
9
- function isSourceType(str) {
10
- return str === "blocks" /* SourceType.blocks */ || str === "extensions" /* SourceType.extensions */ || str === "plain" /* SourceType.plain */;
11
- }
12
- function resolveAllConfigLevelEntrypoints(config, projectRoot = process.cwd()) {
13
- const srcDir = config.srcDir ?? "";
14
- const normalizeSrcAndDestination = ([rawSrc, dest]) => {
15
- let [src, pathQueryParameters] = (0, path_query_and_related_helpers_1.unpackPotentiallyPrefixedFilePath)(rawSrc);
16
- if (srcDir) {
17
- src = (0, node_path_1.join)(srcDir, src);
18
- }
19
- src = (0, node_path_1.isAbsolute)(src) ? (0, node_path_1.relative)(projectRoot, src) : src;
20
- let resultObject;
21
- if (dest.destination !== undefined && (0, node_path_1.isAbsolute)(dest.destination)) {
22
- resultObject = { ...dest, destination: (0, node_path_1.relative)(projectRoot, dest.destination) };
23
- }
24
- else {
25
- resultObject = { ...dest };
26
- }
27
- return [src, pathQueryParameters ? { ...resultObject, pathQueryParameters } : resultObject];
28
- };
29
- if (Array.isArray(config.src)) {
30
- return {
31
- staticEntrypoints: config.src.map(s => normalizeSrcAndDestination([s, { destination: s }])),
32
- dynamicEntrypoints: []
33
- };
34
- }
35
- else {
36
- const configSrc = config.src ?? {};
37
- // We check for files with location-encoding filenames and add the pertinent ones to the sources
38
- const dynamicallyIncludedEntrypoints = [];
39
- if (srcDir) { // This will only work if we have a unified src root
40
- const dynamicallyIncludedEntrypointsRoot = (0, node_path_1.isAbsolute)(srcDir) ? srcDir : (0, node_path_1.join)(projectRoot, srcDir);
41
- for (const dirent of (0, shared_1.synchronousDirIterator)(dynamicallyIncludedEntrypointsRoot)) {
42
- if (dirent.name in configSrc || `./${dirent.name}` in configSrc) {
43
- continue;
44
- }
45
- if (dirent.isDirectory()) {
46
- // If it's a directory that does not have an existing config entry, but does correspond to one of the non-plain SourceTypes, assume that it matches that source type
47
- if (isSourceType(dirent.name) && dirent.name !== "plain" /* SourceType.plain */) {
48
- dynamicallyIncludedEntrypoints.push([dirent.name, { directoryLayout: dirent.name }]);
49
- continue;
50
- }
51
- for (const nestedDirent of (0, shared_1.synchronousDirIterator)((0, node_path_1.join)(dynamicallyIncludedEntrypointsRoot, dirent.name))) {
52
- if (!nestedDirent.isFile()) {
53
- continue;
54
- }
55
- const cfgName = (0, node_path_1.join)(dirent.name, nestedDirent.name);
56
- if (cfgName in configSrc || `./${cfgName}` in configSrc) {
57
- continue;
58
- }
59
- const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(cfgName);
60
- if (parsedFilename === undefined) {
61
- continue;
62
- }
63
- dynamicallyIncludedEntrypoints.push([cfgName, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
64
- }
65
- }
66
- else if (dirent.isFile()) {
67
- const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(dirent.name);
68
- if (parsedFilename === undefined) {
69
- continue;
70
- }
71
- dynamicallyIncludedEntrypoints.push([dirent.name, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
72
- }
73
- }
74
- }
75
- return {
76
- staticEntrypoints: Object.entries(configSrc).map(([k, v]) => {
77
- return normalizeSrcAndDestination([k, typeof v === 'boolean' ? {} : (typeof v === 'string' ? { destination: v } : v)]);
78
- }),
79
- dynamicEntrypoints: dynamicallyIncludedEntrypoints.map(normalizeSrcAndDestination)
80
- };
81
- }
82
- }