@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.
@@ -0,0 +1,522 @@
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.EnhancedDependencyExtractionWebpackPlugin = void 0;
7
+ const dependency_extraction_webpack_plugin_1 = __importDefault(require("@wordpress/dependency-extraction-webpack-plugin"));
8
+ const webpack_1 = require("webpack");
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ const util_1 = require("./util");
13
+ const defaultExternalizedReportFileName = 'externalized-dependencies.json';
14
+ class EnhancedDependencyExtractionWebpackPlugin {
15
+ /**
16
+ * Track requests that are externalized.
17
+ *
18
+ * Because we don't have a closed set of dependencies, we need to track what has
19
+ * been externalized so we can recognize them in a later phase when the dependency
20
+ * lists are generated.
21
+ */
22
+ externalizedDeps = new Set();
23
+ options;
24
+ /**
25
+ * Track requests that a script build externalizes as script modules.
26
+ *
27
+ * These can only be reached through a runtime `import()`, which requires
28
+ * support for dynamic import in the output environment. The set is used
29
+ * to report an actionable error when that support is missing.
30
+ */
31
+ scriptModuleDepsInScript = new Set();
32
+ /**
33
+ * Whether we should use modules. This will be set later to match webpack's `output.module` option.
34
+ */
35
+ useModules = false;
36
+ constructor(options) {
37
+ if (options instanceof dependency_extraction_webpack_plugin_1.default) {
38
+ options = options.options;
39
+ }
40
+ if (options instanceof EnhancedDependencyExtractionWebpackPlugin) {
41
+ options = options.options;
42
+ }
43
+ this.options = {
44
+ externalizedReport: false,
45
+ injectPolyfill: false,
46
+ outputFilename: undefined,
47
+ useDefaults: true,
48
+ ...options
49
+ };
50
+ }
51
+ /**
52
+ * Convert a script module request to an external suitable for a script
53
+ * build.
54
+ *
55
+ * A classic script cannot contain a static `import`, so the `module`
56
+ * external type is not usable here: the script module has to be reached
57
+ * through a runtime `import()`, which is the `import` external type. The
58
+ * bare specifier is resolved by the import map that WordPress prints for
59
+ * enqueued script modules.
60
+ *
61
+ * @param {string} request Original module request.
62
+ * @param {string|boolean|Error=} external Result of a script module external resolution.
63
+ * @return {string|undefined} The resulting external definition.
64
+ */
65
+ static toScriptModuleExternalInScript(request, external) {
66
+ if (!external) {
67
+ return undefined;
68
+ }
69
+ if (external instanceof Error) {
70
+ throw external;
71
+ }
72
+ // The script module resolvers allow a boolean shorthand.
73
+ const target = external === true ? request : String(external);
74
+ return target.replace(/^module\s+/, 'import ');
75
+ }
76
+ externalizeWpDeps = ({ request }, callback) => {
77
+ let externalRequest;
78
+ let isScriptModule = false;
79
+ try {
80
+ // Handle via options.requestToExternal(Module) first.
81
+ if (this.useModules) {
82
+ if (typeof this.options.requestToExternalModule === 'function') {
83
+ const rawExternalRequest = this.options.requestToExternalModule(request);
84
+ // requestToExternalModule allows a boolean shorthand
85
+ if (rawExternalRequest === false) {
86
+ externalRequest = undefined;
87
+ }
88
+ else if (rawExternalRequest === true) {
89
+ externalRequest = request;
90
+ }
91
+ else {
92
+ externalRequest = rawExternalRequest;
93
+ }
94
+ }
95
+ }
96
+ else {
97
+ if (typeof this.options.requestToExternal === 'function') {
98
+ externalRequest = this.options.requestToExternal(request);
99
+ }
100
+ /*
101
+ * A script can depend on a script module, so fall back to
102
+ * `requestToScriptModule`. An explicit `requestToExternal`
103
+ * mapping wins: it describes a global that is known to exist.
104
+ *
105
+ * This deliberately does not consult `requestToExternalModule`:
106
+ * that option describes a module build, and the same options
107
+ * object is commonly shared by both builds.
108
+ */
109
+ if (typeof externalRequest === 'undefined' &&
110
+ typeof this.options.requestToScriptModule === 'function') {
111
+ externalRequest =
112
+ EnhancedDependencyExtractionWebpackPlugin.toScriptModuleExternalInScript(request, this.options.requestToScriptModule(request));
113
+ isScriptModule = Boolean(externalRequest);
114
+ }
115
+ }
116
+ // Cascade to default if unhandled and enabled.
117
+ if (typeof externalRequest === 'undefined' &&
118
+ this.options.useDefaults) {
119
+ if (this.useModules) {
120
+ externalRequest = (0, util_1.defaultRequestToExternalModule)(request);
121
+ }
122
+ else {
123
+ /*
124
+ * Prefer the script module: a request that is available as
125
+ * a script module is used as one, even when it is also
126
+ * registered as a script.
127
+ */
128
+ try {
129
+ externalRequest =
130
+ EnhancedDependencyExtractionWebpackPlugin.toScriptModuleExternalInScript(request, (0, util_1.defaultRequestToExternalModule)(request));
131
+ isScriptModule = Boolean(externalRequest);
132
+ }
133
+ catch {
134
+ /*
135
+ * `defaultRequestToExternalModule` throws for WordPress
136
+ * scripts, which is exactly what we want to fall back
137
+ * to here.
138
+ */
139
+ }
140
+ if (typeof externalRequest === 'undefined') {
141
+ externalRequest = (0, util_1.defaultRequestToExternal)(request);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ catch (err) {
147
+ if (err instanceof Error) {
148
+ return callback(err);
149
+ }
150
+ throw err;
151
+ }
152
+ if (externalRequest) {
153
+ this.externalizedDeps.add(request);
154
+ if (isScriptModule) {
155
+ this.scriptModuleDepsInScript.add(request);
156
+ }
157
+ return callback(null, externalRequest);
158
+ }
159
+ return callback();
160
+ };
161
+ /**
162
+ * @param {string} request
163
+ * @return {string} Mapped dependency name
164
+ */
165
+ mapRequestToDependency(request) {
166
+ // Handle via options.requestToHandle first.
167
+ if (typeof this.options.requestToHandle === 'function') {
168
+ const scriptDependency = this.options.requestToHandle(request);
169
+ if (scriptDependency) {
170
+ return scriptDependency;
171
+ }
172
+ }
173
+ // Cascade to default if enabled.
174
+ if (this.options.useDefaults) {
175
+ const scriptDependency = (0, util_1.defaultRequestToHandle)(request);
176
+ if (scriptDependency) {
177
+ return scriptDependency;
178
+ }
179
+ }
180
+ // Fall back to the request name.
181
+ return request;
182
+ }
183
+ // noinspection JSUnusedGlobalSymbols
184
+ apply(compiler) {
185
+ this.useModules = Boolean(compiler.options.output?.module);
186
+ /**
187
+ * Offload externalization work to the ExternalsPlugin.
188
+ */
189
+ new webpack_1.ExternalsPlugin(this.useModules ? 'import' : 'window', this.externalizeWpDeps).apply(compiler);
190
+ compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {
191
+ compilation.hooks.processAssets.tap({
192
+ name: this.constructor.name,
193
+ stage: compiler.webpack.Compilation
194
+ .PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY,
195
+ }, () => this.checkForMagicComments(compilation));
196
+ compilation.hooks.processAssets.tap({
197
+ name: this.constructor.name,
198
+ stage: compiler.webpack.Compilation
199
+ .PROCESS_ASSETS_STAGE_ANALYSE,
200
+ }, () => this.addAssets(compilation));
201
+ });
202
+ }
203
+ /**
204
+ * Check for magic comments before minification, so minification doesn't have to preserve them.
205
+ */
206
+ checkForMagicComments(compilation) {
207
+ // Accumulate all entrypoint chunks, some of them shared
208
+ const entrypointChunks = new Set();
209
+ for (const entrypoint of compilation.entrypoints.values()) {
210
+ for (const chunk of entrypoint.chunks) {
211
+ entrypointChunks.add(chunk);
212
+ }
213
+ }
214
+ // Process each entrypoint chunk independently
215
+ for (const chunk of entrypointChunks) {
216
+ const chunkFiles = Array.from(chunk.files);
217
+ const jsExtensionRegExp = this.useModules ? /\.m?js$/i : /\.js$/i;
218
+ const chunkJSFile = chunkFiles.find((f) => jsExtensionRegExp.test(f));
219
+ if (!chunkJSFile) {
220
+ // There's no JS file in this chunk, no work for us. This is typically a `style.css` from cache group.
221
+ continue;
222
+ }
223
+ // Prepare to look for magic comments, in order to decide whether
224
+ // `wp-polyfill` is needed.
225
+ const processContentsForMagicComments = (content) => {
226
+ const magicComments = [];
227
+ if (content.includes('/* wp:polyfill */')) {
228
+ magicComments.push('wp-polyfill');
229
+ }
230
+ return magicComments;
231
+ };
232
+ // Go through the assets to process the sources.
233
+ // This allows us to look for magic comments.
234
+ for (const filename of chunkFiles.sort()) {
235
+ const asset = compilation.getAsset(filename);
236
+ const content = asset?.source.buffer();
237
+ const wpMagicComments = content ? processContentsForMagicComments(content) : [];
238
+ compilation.updateAsset(filename, (v) => v, {
239
+ wpMagicComments,
240
+ });
241
+ }
242
+ }
243
+ }
244
+ addAssets(compilation) {
245
+ const { externalizedReport, injectPolyfill, } = this.options;
246
+ /*
247
+ * A script reaches a script module through a runtime `import()`, so the
248
+ * output environment has to support it. Report this directly: webpack's
249
+ * own error for the underlying external does not explain the cause.
250
+ */
251
+ if (!this.useModules &&
252
+ this.scriptModuleDepsInScript.size &&
253
+ compilation.outputOptions.environment?.dynamicImport === false) {
254
+ compilation.errors.push(new webpack_1.WebpackError(`${this.constructor.name}: ${Array.from(this.scriptModuleDepsInScript)
255
+ .sort()
256
+ .join(', ')} can only be loaded from a script through a dynamic \`import()\`, but the output environment does not support it. ` +
257
+ "Set `target: 'browserslist'` with a browserslist configuration whose browsers support dynamic import (as @wordpress/scripts does), or set `output.environment.dynamicImport: true`."));
258
+ }
259
+ // Dump actually externalized dependencies to a report file.
260
+ if (externalizedReport) {
261
+ const externalizedReportFile = typeof externalizedReport === 'string' ? externalizedReport : defaultExternalizedReportFileName;
262
+ compilation.emitAsset(externalizedReportFile, new webpack_1.sources.RawSource(JSON.stringify(Array.from(this.externalizedDeps).sort())));
263
+ }
264
+ const combinedAssetsData = {};
265
+ const jsExtensionRegExp = this.useModules ? /\.m?js$/i : /\.js$/i;
266
+ // Accumulate all entrypoint chunks, some of them shared
267
+ const entrypointChunks = new Set();
268
+ /**
269
+ * Track the files of each entrypoint's JS-less chunks, typically styles
270
+ * extracted by a `style.css` cache group. Those chunks don't get an
271
+ * asset file of their own, but their content must contribute to the
272
+ * version hash of the entrypoint's entry chunk so that style-only
273
+ * changes still produce a new version.
274
+ */
275
+ const styleFilesByEntryChunk = new Map();
276
+ for (const entrypoint of compilation.entrypoints.values()) {
277
+ const entryChunk = entrypoint.getEntrypointChunk();
278
+ for (const chunk of entrypoint.chunks) {
279
+ entrypointChunks.add(chunk);
280
+ if (chunk === entryChunk ||
281
+ Array.from(chunk.files).some((f) => jsExtensionRegExp.test(f))) {
282
+ continue;
283
+ }
284
+ const styleFiles = styleFilesByEntryChunk.get(entryChunk) ?? new Set();
285
+ for (const file of chunk.files) {
286
+ styleFiles.add(file);
287
+ }
288
+ styleFilesByEntryChunk.set(entryChunk, styleFiles);
289
+ }
290
+ }
291
+ // Process each entrypoint chunk independently
292
+ for (const chunk of entrypointChunks) {
293
+ const chunkFiles = Array.from(chunk.files);
294
+ const chunkJSFile = chunkFiles.find((f) => jsExtensionRegExp.test(f));
295
+ if (!chunkJSFile) {
296
+ // There's no JS file in this chunk, no work for us. This is typically a `style.css` from cache group.
297
+ continue;
298
+ }
299
+ const chunkStaticDeps = new Set();
300
+ const chunkDynamicDeps = new Set();
301
+ const chunkScriptModuleStaticDeps = new Set();
302
+ const chunkScriptModuleDynamicDeps = new Set();
303
+ if (injectPolyfill) {
304
+ chunkStaticDeps.add('wp-polyfill');
305
+ }
306
+ /**
307
+ * @param {webpack.Module} m
308
+ * @param {boolean} [fromAsyncChunk] Module was found in an async chunk of the entry.
309
+ */
310
+ const processModule = (m, fromAsyncChunk) => {
311
+ let viableRequest = typeof m.request === 'string' && m.request !== '__REMOVE_ME__' ? m.request : m.userRequest;
312
+ if (viableRequest !== undefined && !this.externalizedDeps.has(viableRequest) && viableRequest !== m.userRequest) {
313
+ viableRequest = m.userRequest;
314
+ }
315
+ if (viableRequest !== undefined && this.externalizedDeps.has(viableRequest)) {
316
+ if (this.useModules) {
317
+ // A static occurrence (in the entry chunk) wins.
318
+ if (fromAsyncChunk && chunkStaticDeps.has(viableRequest)) {
319
+ return;
320
+ }
321
+ // Externals in an async chunk are reached via a dynamic
322
+ // import by definition.
323
+ const isStatic = !fromAsyncChunk &&
324
+ EnhancedDependencyExtractionWebpackPlugin.hasStaticDependencyPathToRoot(compilation, m);
325
+ (isStatic ? chunkStaticDeps : chunkDynamicDeps).add(viableRequest);
326
+ }
327
+ else if (m instanceof webpack_1.ExternalModule && (m.externalType === 'import' || m.externalType === 'module')) {
328
+ // A static occurrence (in the entry chunk) wins.
329
+ if (fromAsyncChunk && chunkScriptModuleStaticDeps.has(viableRequest)) {
330
+ return;
331
+ }
332
+ // Externals in an async chunk are reached via a dynamic
333
+ // import by definition.
334
+ const isStatic = !fromAsyncChunk &&
335
+ EnhancedDependencyExtractionWebpackPlugin.hasStaticDependencyPathToRoot(compilation, m);
336
+ (isStatic ? chunkScriptModuleStaticDeps : chunkScriptModuleDynamicDeps).add(viableRequest);
337
+ }
338
+ else {
339
+ chunkStaticDeps.add(this.mapRequestToDependency(viableRequest));
340
+ }
341
+ }
342
+ };
343
+ const processChunkModules = (searchChunk, fromAsyncChunk) => {
344
+ for (const chunkModule of compilation.chunkGraph.getChunkModulesIterable(searchChunk)) {
345
+ if (chunkModule instanceof webpack_1.NormalModule || chunkModule instanceof webpack_1.ExternalModule) {
346
+ processModule(chunkModule, fromAsyncChunk);
347
+ }
348
+ if ((0, util_1.isConcatenatedModule)(chunkModule) && chunkModule.modules) {
349
+ // Loop through submodules of ConcatenatedModule.
350
+ for (const concatModule of chunkModule.modules) {
351
+ if (concatModule instanceof webpack_1.NormalModule || concatModule instanceof webpack_1.ExternalModule) {
352
+ processModule(concatModule, fromAsyncChunk);
353
+ }
354
+ }
355
+ }
356
+ }
357
+ };
358
+ processChunkModules(chunk);
359
+ /*
360
+ * Also search the entry's async chunks: webpack can code-split a
361
+ * dynamically imported external into its own chunk.
362
+ */
363
+ for (const group of chunk.groupsIterable) {
364
+ if (!(0, util_1.isEntrypoint)(group) || group.getEntrypointChunk() !== chunk) {
365
+ continue;
366
+ }
367
+ const seenGroups = new Set();
368
+ const groupQueue = [...group.getChildren()];
369
+ for (let childGroup = groupQueue.pop(); childGroup !== undefined; childGroup = groupQueue.pop()) {
370
+ if (!seenGroups.has(childGroup)) {
371
+ seenGroups.add(childGroup);
372
+ for (const asyncChunk of childGroup.chunks) {
373
+ processChunkModules(asyncChunk, true);
374
+ }
375
+ groupQueue.push(...childGroup.getChildren());
376
+ }
377
+ }
378
+ }
379
+ // Prepare to hash the sources. We can't just use
380
+ // `chunk.contentHash` because that's not updated when
381
+ // assets are minified. In practice the hash is updated by
382
+ // `RealContentHashPlugin` after minification, but it only modifies
383
+ // already-produced asset filenames and the updated hash is not
384
+ // available to plugins.
385
+ const { hashFunction, hashDigest, hashDigestLength } = compilation.outputOptions;
386
+ const hashBuilder = webpack_1.util.createHash(hashFunction);
387
+ // Prepare to look for magic comments in order to decide whether `wp-polyfill` is needed.
388
+ const handleMagicComments = (info) => {
389
+ if (info && info.includes('wp-polyfill')) {
390
+ chunkStaticDeps.add('wp-polyfill');
391
+ }
392
+ };
393
+ // Include the files of the entrypoint's JS-less sibling chunks,
394
+ // typically extracted styles, in the version hash so that
395
+ // style-only changes still produce a new version.
396
+ const filesToHash = [
397
+ ...new Set([
398
+ ...chunkFiles,
399
+ ...(styleFilesByEntryChunk.get(chunk) ?? []),
400
+ ]),
401
+ ];
402
+ // Go through the assets to process the sources.
403
+ // This allows us to generate hashes, as well as look for magic comments.
404
+ for (const filename of filesToHash.sort()) {
405
+ const asset = compilation.getAsset(filename);
406
+ if (asset) {
407
+ const content = asset.source.buffer();
408
+ hashBuilder.update(content);
409
+ handleMagicComments(asset.info.wpMagicComments);
410
+ }
411
+ }
412
+ // Finalise hash.
413
+ const contentHash = hashBuilder
414
+ .digest(hashDigest)
415
+ .slice(0, hashDigestLength);
416
+ const assetData = {
417
+ dependencies: [
418
+ // Sort these so we can produce a stable, stringified representation.
419
+ ...Array.from(chunkStaticDeps).sort(),
420
+ ...Array.from(chunkDynamicDeps)
421
+ .sort()
422
+ .map((id) => ({ id, import: 'dynamic' })),
423
+ ],
424
+ };
425
+ /*
426
+ * Merge the script module dependencies into a single list, keyed by
427
+ * script module ID, with an explicit import kind for each. This is
428
+ * the shape WordPress writes for its own assets.
429
+ */
430
+ const scriptModuleDeps = new Map();
431
+ for (const id of chunkScriptModuleDynamicDeps) {
432
+ scriptModuleDeps.set(id, 'dynamic');
433
+ }
434
+ // A static occurrence wins: the script cannot start without it.
435
+ for (const id of chunkScriptModuleStaticDeps) {
436
+ scriptModuleDeps.set(id, 'static');
437
+ }
438
+ if (scriptModuleDeps.size) {
439
+ assetData.module_dependencies = Array.from(scriptModuleDeps.keys())
440
+ // Sort these so we can produce a stable, stringified representation.
441
+ .sort()
442
+ .map((id) => ({
443
+ id,
444
+ import: scriptModuleDeps.get(id),
445
+ }));
446
+ }
447
+ assetData.version = contentHash;
448
+ if (this.useModules) {
449
+ assetData.type = 'module';
450
+ }
451
+ if (compilation.options?.optimization?.runtimeChunk !== false) {
452
+ // Sets the script handle for the shared runtime file so WordPress registers it only once when using the asset file.
453
+ assetData.handle =
454
+ compilation.name +
455
+ '-' +
456
+ chunkJSFile
457
+ .replace(/\\/g, '/')
458
+ .replace(jsExtensionRegExp, '');
459
+ }
460
+ combinedAssetsData[chunkJSFile] = assetData;
461
+ }
462
+ // Add source into compilation for webpack to trigger a phase re-run
463
+ compilation.emitAsset("assets.json", new webpack_1.sources.RawSource(JSON.stringify(combinedAssetsData, undefined, " ")), { "parsed-assets-json": combinedAssetsData });
464
+ }
465
+ static staticDepsCurrent = new WeakSet();
466
+ static staticDepsCache = new WeakMap();
467
+ /**
468
+ * Can we trace a line of static dependencies from an entry to a module
469
+ *
470
+ * @return {boolean} True if there is a static import path to the root
471
+ */
472
+ static hasStaticDependencyPathToRoot(compilation, block) {
473
+ const existingDepsCacheValue = EnhancedDependencyExtractionWebpackPlugin.staticDepsCache.get(block);
474
+ if (existingDepsCacheValue !== undefined) {
475
+ return existingDepsCacheValue;
476
+ }
477
+ if (EnhancedDependencyExtractionWebpackPlugin.staticDepsCurrent.has(block)) {
478
+ return false;
479
+ }
480
+ EnhancedDependencyExtractionWebpackPlugin.staticDepsCurrent.add(block);
481
+ const incomingConnections = [
482
+ ...compilation.moduleGraph.getIncomingConnections(block),
483
+ ].filter((connection) => {
484
+ // Library connections don't have a dependency, this is a root
485
+ return connection.dependency &&
486
+ // Entry dependencies are another root
487
+ connection.dependency.constructor.name !== 'EntryDependency';
488
+ });
489
+ // If we don't have non-entry, non-library incoming connections,
490
+ // we've reached a root of
491
+ if (!incomingConnections.length) {
492
+ EnhancedDependencyExtractionWebpackPlugin.staticDepsCache.set(block, true);
493
+ EnhancedDependencyExtractionWebpackPlugin.staticDepsCurrent.delete(block);
494
+ return true;
495
+ }
496
+ const staticDependentModules = incomingConnections.flatMap((connection) => {
497
+ const { dependency } = connection;
498
+ if (!dependency) {
499
+ return [];
500
+ }
501
+ const parentBlock = compilation.moduleGraph.getParentBlock(dependency);
502
+ return parentBlock && parentBlock.constructor.name !== webpack_1.AsyncDependenciesBlock.name
503
+ ? [compilation.moduleGraph.getParentModule(dependency)]
504
+ : [];
505
+ });
506
+ // All the dependencies were Async, the module was reached via a dynamic import
507
+ if (!staticDependentModules.length) {
508
+ EnhancedDependencyExtractionWebpackPlugin.staticDepsCache.set(block, false);
509
+ EnhancedDependencyExtractionWebpackPlugin.staticDepsCurrent.delete(block);
510
+ return false;
511
+ }
512
+ // Continue to explore any static dependencies
513
+ const result = staticDependentModules.some((parentStaticDependentModule) => {
514
+ return !!parentStaticDependentModule && EnhancedDependencyExtractionWebpackPlugin.hasStaticDependencyPathToRoot(compilation, parentStaticDependentModule);
515
+ });
516
+ EnhancedDependencyExtractionWebpackPlugin.staticDepsCache.set(block, result);
517
+ EnhancedDependencyExtractionWebpackPlugin.staticDepsCurrent.delete(block);
518
+ return result;
519
+ }
520
+ addExternalizedDep = this.externalizedDeps.add.bind(this.externalizedDeps);
521
+ }
522
+ exports.EnhancedDependencyExtractionWebpackPlugin = EnhancedDependencyExtractionWebpackPlugin;
@@ -0,0 +1,56 @@
1
+ import type { ChunkGroup, Entrypoint, Module } from "webpack";
2
+ /**
3
+ * Default request to global transformation
4
+ *
5
+ * Transform @wordpress dependencies:
6
+ * - request `@wordpress/api-fetch` becomes `[ 'wp', 'apiFetch' ]`
7
+ * - request `@wordpress/i18n` becomes `[ 'wp', 'i18n' ]`
8
+ *
9
+ * @param {string} request Module request (the module name in `import from`) to be transformed
10
+ * @return {string|string[]|undefined} The resulting external definition. Return `undefined`
11
+ * to ignore the request. Return `string|string[]` to map the request to an external.
12
+ */
13
+ export declare function defaultRequestToExternal(request: string): string | string[] | undefined;
14
+ /**
15
+ * Default request to external module transformation
16
+ *
17
+ * Currently only @wordpress/interactivity and `@wordpress/interactivity-router`
18
+ * are supported.
19
+ *
20
+ * Do not use the boolean shorthand here, it's only handled for the
21
+ * `requestToExternalModule` option.
22
+ *
23
+ * @param {string} request Module request (the module name in `import from`) to be transformed
24
+ * @return {string|undefined} The resulting external definition.
25
+ * - Return `undefined` to ignore the request (do not externalize).
26
+ * - Return `string` to map the request to an external.
27
+ * - Return `Error` to emit an error.
28
+ */
29
+ export declare function defaultRequestToExternalModule(request: string): string | undefined;
30
+ /**
31
+ * Default request to WordPress script handle transformation
32
+ *
33
+ * Transform @wordpress dependencies:
34
+ * - request `@wordpress/i18n` becomes `wp-i18n`
35
+ * - request `@wordpress/escape-html` becomes `wp-escape-html`
36
+ *
37
+ * @param {string} request Module request (the module name in `import from`) to be transformed
38
+ * @return {string|undefined} WordPress script handle to map the request to. Return `undefined`
39
+ * to use the same name as the module.
40
+ */
41
+ export declare function defaultRequestToHandle(request: string): string | undefined;
42
+ /**
43
+ * Given a string, returns a new string with dash separators converted to
44
+ * camelCase equivalent. This is not as aggressive as `_.camelCase` in
45
+ * converting to uppercase, where Lodash will also capitalize letters
46
+ * following numbers.
47
+ *
48
+ * @param {string} string Input dash-delimited string.
49
+ * @return {string} Camel-cased string.
50
+ */
51
+ export declare function camelCaseDash(string: string): string;
52
+ export interface ConcatenatedModule extends Module {
53
+ get modules(): Module[];
54
+ }
55
+ export declare function isConcatenatedModule(module: Module): module is ConcatenatedModule;
56
+ export declare function isEntrypoint(group: ChunkGroup | undefined | null): group is Entrypoint;