@rollup/plugin-commonjs 21.0.0 → 22.0.0-10

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/dist/index.es.js DELETED
@@ -1,1904 +0,0 @@
1
- import { basename, extname, dirname, join, resolve, sep } from 'path';
2
- import { makeLegalIdentifier, attachScopes, extractAssignedNames, createFilter } from '@rollup/pluginutils';
3
- import getCommonDir from 'commondir';
4
- import { existsSync, readFileSync, statSync } from 'fs';
5
- import glob from 'glob';
6
- import { walk } from 'estree-walker';
7
- import MagicString from 'magic-string';
8
- import isReference from 'is-reference';
9
- import { sync } from 'resolve';
10
-
11
- var peerDependencies = {
12
- rollup: "^2.38.3"
13
- };
14
-
15
- function tryParse(parse, code, id) {
16
- try {
17
- return parse(code, { allowReturnOutsideFunction: true });
18
- } catch (err) {
19
- err.message += ` in ${id}`;
20
- throw err;
21
- }
22
- }
23
-
24
- const firstpassGlobal = /\b(?:require|module|exports|global)\b/;
25
-
26
- const firstpassNoGlobal = /\b(?:require|module|exports)\b/;
27
-
28
- function hasCjsKeywords(code, ignoreGlobal) {
29
- const firstpass = ignoreGlobal ? firstpassNoGlobal : firstpassGlobal;
30
- return firstpass.test(code);
31
- }
32
-
33
- /* eslint-disable no-underscore-dangle */
34
-
35
- function analyzeTopLevelStatements(parse, code, id) {
36
- const ast = tryParse(parse, code, id);
37
-
38
- let isEsModule = false;
39
- let hasDefaultExport = false;
40
- let hasNamedExports = false;
41
-
42
- for (const node of ast.body) {
43
- switch (node.type) {
44
- case 'ExportDefaultDeclaration':
45
- isEsModule = true;
46
- hasDefaultExport = true;
47
- break;
48
- case 'ExportNamedDeclaration':
49
- isEsModule = true;
50
- if (node.declaration) {
51
- hasNamedExports = true;
52
- } else {
53
- for (const specifier of node.specifiers) {
54
- if (specifier.exported.name === 'default') {
55
- hasDefaultExport = true;
56
- } else {
57
- hasNamedExports = true;
58
- }
59
- }
60
- }
61
- break;
62
- case 'ExportAllDeclaration':
63
- isEsModule = true;
64
- if (node.exported && node.exported.name === 'default') {
65
- hasDefaultExport = true;
66
- } else {
67
- hasNamedExports = true;
68
- }
69
- break;
70
- case 'ImportDeclaration':
71
- isEsModule = true;
72
- break;
73
- }
74
- }
75
-
76
- return { isEsModule, hasDefaultExport, hasNamedExports, ast };
77
- }
78
-
79
- const isWrappedId = (id, suffix) => id.endsWith(suffix);
80
- const wrapId = (id, suffix) => `\0${id}${suffix}`;
81
- const unwrapId = (wrappedId, suffix) => wrappedId.slice(1, -suffix.length);
82
-
83
- const PROXY_SUFFIX = '?commonjs-proxy';
84
- const REQUIRE_SUFFIX = '?commonjs-require';
85
- const EXTERNAL_SUFFIX = '?commonjs-external';
86
- const EXPORTS_SUFFIX = '?commonjs-exports';
87
- const MODULE_SUFFIX = '?commonjs-module';
88
-
89
- const DYNAMIC_REGISTER_SUFFIX = '?commonjs-dynamic-register';
90
- const DYNAMIC_JSON_PREFIX = '\0commonjs-dynamic-json:';
91
- const DYNAMIC_PACKAGES_ID = '\0commonjs-dynamic-packages';
92
-
93
- const HELPERS_ID = '\0commonjsHelpers.js';
94
-
95
- // `x['default']` is used instead of `x.default` for backward compatibility with ES3 browsers.
96
- // Minifiers like uglify will usually transpile it back if compatibility with ES3 is not enabled.
97
- // This will no longer be necessary once Rollup switches to ES6 output, likely
98
- // in Rollup 3
99
-
100
- const HELPERS = `
101
- export var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
102
-
103
- export function getDefaultExportFromCjs (x) {
104
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
105
- }
106
-
107
- export function getDefaultExportFromNamespaceIfPresent (n) {
108
- return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n['default'] : n;
109
- }
110
-
111
- export function getDefaultExportFromNamespaceIfNotNamed (n) {
112
- return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
113
- }
114
-
115
- export function getAugmentedNamespace(n) {
116
- if (n.__esModule) return n;
117
- var a = Object.defineProperty({}, '__esModule', {value: true});
118
- Object.keys(n).forEach(function (k) {
119
- var d = Object.getOwnPropertyDescriptor(n, k);
120
- Object.defineProperty(a, k, d.get ? d : {
121
- enumerable: true,
122
- get: function () {
123
- return n[k];
124
- }
125
- });
126
- });
127
- return a;
128
- }
129
- `;
130
-
131
- const FAILED_REQUIRE_ERROR = `throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');`;
132
-
133
- const HELPER_NON_DYNAMIC = `
134
- export function commonjsRequire (path) {
135
- ${FAILED_REQUIRE_ERROR}
136
- }
137
- `;
138
-
139
- const getDynamicHelpers = (ignoreDynamicRequires) => `
140
- export function createModule(modulePath) {
141
- return {
142
- path: modulePath,
143
- exports: {},
144
- require: function (path, base) {
145
- return commonjsRequire(path, base == null ? modulePath : base);
146
- }
147
- };
148
- }
149
-
150
- export function commonjsRegister (path, loader) {
151
- DYNAMIC_REQUIRE_LOADERS[path] = loader;
152
- }
153
-
154
- export function commonjsRegisterOrShort (path, to) {
155
- const resolvedPath = commonjsResolveImpl(path, null, true);
156
- if (resolvedPath !== null && DYNAMIC_REQUIRE_CACHE[resolvedPath]) {
157
- DYNAMIC_REQUIRE_CACHE[path] = DYNAMIC_REQUIRE_CACHE[resolvedPath];
158
- } else {
159
- DYNAMIC_REQUIRE_SHORTS[path] = to;
160
- }
161
- }
162
-
163
- const DYNAMIC_REQUIRE_LOADERS = Object.create(null);
164
- const DYNAMIC_REQUIRE_CACHE = Object.create(null);
165
- const DYNAMIC_REQUIRE_SHORTS = Object.create(null);
166
- const DEFAULT_PARENT_MODULE = {
167
- id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []
168
- };
169
- const CHECKED_EXTENSIONS = ['', '.js', '.json'];
170
-
171
- function normalize (path) {
172
- path = path.replace(/\\\\/g, '/');
173
- const parts = path.split('/');
174
- const slashed = parts[0] === '';
175
- for (let i = 1; i < parts.length; i++) {
176
- if (parts[i] === '.' || parts[i] === '') {
177
- parts.splice(i--, 1);
178
- }
179
- }
180
- for (let i = 1; i < parts.length; i++) {
181
- if (parts[i] !== '..') continue;
182
- if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {
183
- parts.splice(--i, 2);
184
- i--;
185
- }
186
- }
187
- path = parts.join('/');
188
- if (slashed && path[0] !== '/')
189
- path = '/' + path;
190
- else if (path.length === 0)
191
- path = '.';
192
- return path;
193
- }
194
-
195
- function join () {
196
- if (arguments.length === 0)
197
- return '.';
198
- let joined;
199
- for (let i = 0; i < arguments.length; ++i) {
200
- let arg = arguments[i];
201
- if (arg.length > 0) {
202
- if (joined === undefined)
203
- joined = arg;
204
- else
205
- joined += '/' + arg;
206
- }
207
- }
208
- if (joined === undefined)
209
- return '.';
210
-
211
- return joined;
212
- }
213
-
214
- function isPossibleNodeModulesPath (modulePath) {
215
- let c0 = modulePath[0];
216
- if (c0 === '/' || c0 === '\\\\') return false;
217
- let c1 = modulePath[1], c2 = modulePath[2];
218
- if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||
219
- (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;
220
- if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))
221
- return false;
222
- return true;
223
- }
224
-
225
- function dirname (path) {
226
- if (path.length === 0)
227
- return '.';
228
-
229
- let i = path.length - 1;
230
- while (i > 0) {
231
- const c = path.charCodeAt(i);
232
- if ((c === 47 || c === 92) && i !== path.length - 1)
233
- break;
234
- i--;
235
- }
236
-
237
- if (i > 0)
238
- return path.substr(0, i);
239
-
240
- if (path.chartCodeAt(0) === 47 || path.chartCodeAt(0) === 92)
241
- return path.charAt(0);
242
-
243
- return '.';
244
- }
245
-
246
- export function commonjsResolveImpl (path, originalModuleDir, testCache) {
247
- const shouldTryNodeModules = isPossibleNodeModulesPath(path);
248
- path = normalize(path);
249
- let relPath;
250
- if (path[0] === '/') {
251
- originalModuleDir = '/';
252
- }
253
- while (true) {
254
- if (!shouldTryNodeModules) {
255
- relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;
256
- } else if (originalModuleDir) {
257
- relPath = normalize(originalModuleDir + '/node_modules/' + path);
258
- } else {
259
- relPath = normalize(join('node_modules', path));
260
- }
261
-
262
- if (relPath.endsWith('/..')) {
263
- break; // Travelled too far up, avoid infinite loop
264
- }
265
-
266
- for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {
267
- const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];
268
- if (DYNAMIC_REQUIRE_CACHE[resolvedPath]) {
269
- return resolvedPath;
270
- }
271
- if (DYNAMIC_REQUIRE_SHORTS[resolvedPath]) {
272
- return resolvedPath;
273
- }
274
- if (DYNAMIC_REQUIRE_LOADERS[resolvedPath]) {
275
- return resolvedPath;
276
- }
277
- }
278
- if (!shouldTryNodeModules) break;
279
- const nextDir = normalize(originalModuleDir + '/..');
280
- if (nextDir === originalModuleDir) break;
281
- originalModuleDir = nextDir;
282
- }
283
- return null;
284
- }
285
-
286
- export function commonjsResolve (path, originalModuleDir) {
287
- const resolvedPath = commonjsResolveImpl(path, originalModuleDir);
288
- if (resolvedPath !== null) {
289
- return resolvedPath;
290
- }
291
- return require.resolve(path);
292
- }
293
-
294
- export function commonjsRequire (path, originalModuleDir) {
295
- let resolvedPath = commonjsResolveImpl(path, originalModuleDir, true);
296
- if (resolvedPath !== null) {
297
- let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];
298
- if (cachedModule) return cachedModule.exports;
299
- let shortTo = DYNAMIC_REQUIRE_SHORTS[resolvedPath];
300
- if (shortTo) {
301
- cachedModule = DYNAMIC_REQUIRE_CACHE[shortTo];
302
- if (cachedModule)
303
- return cachedModule.exports;
304
- resolvedPath = commonjsResolveImpl(shortTo, null, true);
305
- }
306
- const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];
307
- if (loader) {
308
- DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {
309
- id: resolvedPath,
310
- filename: resolvedPath,
311
- path: dirname(resolvedPath),
312
- exports: {},
313
- parent: DEFAULT_PARENT_MODULE,
314
- loaded: false,
315
- children: [],
316
- paths: [],
317
- require: function (path, base) {
318
- return commonjsRequire(path, (base === undefined || base === null) ? cachedModule.path : base);
319
- }
320
- };
321
- try {
322
- loader.call(commonjsGlobal, cachedModule, cachedModule.exports);
323
- } catch (error) {
324
- delete DYNAMIC_REQUIRE_CACHE[resolvedPath];
325
- throw error;
326
- }
327
- cachedModule.loaded = true;
328
- return cachedModule.exports;
329
- };
330
- }
331
- ${ignoreDynamicRequires ? 'return require(path);' : FAILED_REQUIRE_ERROR}
332
- }
333
-
334
- commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;
335
- commonjsRequire.resolve = commonjsResolve;
336
- `;
337
-
338
- function getHelpersModule(isDynamicRequireModulesEnabled, ignoreDynamicRequires) {
339
- return `${HELPERS}${
340
- isDynamicRequireModulesEnabled ? getDynamicHelpers(ignoreDynamicRequires) : HELPER_NON_DYNAMIC
341
- }`;
342
- }
343
-
344
- /* eslint-disable import/prefer-default-export */
345
-
346
- function deconflict(scopes, globals, identifier) {
347
- let i = 1;
348
- let deconflicted = makeLegalIdentifier(identifier);
349
- const hasConflicts = () =>
350
- scopes.some((scope) => scope.contains(deconflicted)) || globals.has(deconflicted);
351
-
352
- while (hasConflicts()) {
353
- deconflicted = makeLegalIdentifier(`${identifier}_${i}`);
354
- i += 1;
355
- }
356
-
357
- for (const scope of scopes) {
358
- scope.declarations[deconflicted] = true;
359
- }
360
-
361
- return deconflicted;
362
- }
363
-
364
- function getName(id) {
365
- const name = makeLegalIdentifier(basename(id, extname(id)));
366
- if (name !== 'index') {
367
- return name;
368
- }
369
- return makeLegalIdentifier(basename(dirname(id)));
370
- }
371
-
372
- function normalizePathSlashes(path) {
373
- return path.replace(/\\/g, '/');
374
- }
375
-
376
- const VIRTUAL_PATH_BASE = '/$$rollup_base$$';
377
- const getVirtualPathForDynamicRequirePath = (path, commonDir) => {
378
- const normalizedPath = normalizePathSlashes(path);
379
- return normalizedPath.startsWith(commonDir)
380
- ? VIRTUAL_PATH_BASE + normalizedPath.slice(commonDir.length)
381
- : normalizedPath;
382
- };
383
-
384
- function getPackageEntryPoint(dirPath) {
385
- let entryPoint = 'index.js';
386
-
387
- try {
388
- if (existsSync(join(dirPath, 'package.json'))) {
389
- entryPoint =
390
- JSON.parse(readFileSync(join(dirPath, 'package.json'), { encoding: 'utf8' })).main ||
391
- entryPoint;
392
- }
393
- } catch (ignored) {
394
- // ignored
395
- }
396
-
397
- return entryPoint;
398
- }
399
-
400
- function getDynamicPackagesModule(dynamicRequireModuleDirPaths, commonDir) {
401
- let code = `const commonjsRegisterOrShort = require('${HELPERS_ID}?commonjsRegisterOrShort');`;
402
- for (const dir of dynamicRequireModuleDirPaths) {
403
- const entryPoint = getPackageEntryPoint(dir);
404
-
405
- code += `\ncommonjsRegisterOrShort(${JSON.stringify(
406
- getVirtualPathForDynamicRequirePath(dir, commonDir)
407
- )}, ${JSON.stringify(getVirtualPathForDynamicRequirePath(join(dir, entryPoint), commonDir))});`;
408
- }
409
- return code;
410
- }
411
-
412
- function getDynamicPackagesEntryIntro(
413
- dynamicRequireModuleDirPaths,
414
- dynamicRequireModuleSet
415
- ) {
416
- let dynamicImports = Array.from(
417
- dynamicRequireModuleSet,
418
- (dynamicId) => `require(${JSON.stringify(wrapId(dynamicId, DYNAMIC_REGISTER_SUFFIX))});`
419
- ).join('\n');
420
-
421
- if (dynamicRequireModuleDirPaths.length) {
422
- dynamicImports += `require(${JSON.stringify(
423
- wrapId(DYNAMIC_PACKAGES_ID, DYNAMIC_REGISTER_SUFFIX)
424
- )});`;
425
- }
426
-
427
- return dynamicImports;
428
- }
429
-
430
- function isDynamicModuleImport(id, dynamicRequireModuleSet) {
431
- const normalizedPath = normalizePathSlashes(id);
432
- return dynamicRequireModuleSet.has(normalizedPath) && !normalizedPath.endsWith('.json');
433
- }
434
-
435
- function isDirectory(path) {
436
- try {
437
- if (statSync(path).isDirectory()) return true;
438
- } catch (ignored) {
439
- // Nothing to do here
440
- }
441
- return false;
442
- }
443
-
444
- function getDynamicRequirePaths(patterns) {
445
- const dynamicRequireModuleSet = new Set();
446
- for (const pattern of !patterns || Array.isArray(patterns) ? patterns || [] : [patterns]) {
447
- const isNegated = pattern.startsWith('!');
448
- const modifySet = Set.prototype[isNegated ? 'delete' : 'add'].bind(dynamicRequireModuleSet);
449
- for (const path of glob.sync(isNegated ? pattern.substr(1) : pattern)) {
450
- modifySet(normalizePathSlashes(resolve(path)));
451
- if (isDirectory(path)) {
452
- modifySet(normalizePathSlashes(resolve(join(path, getPackageEntryPoint(path)))));
453
- }
454
- }
455
- }
456
- const dynamicRequireModuleDirPaths = Array.from(dynamicRequireModuleSet.values()).filter((path) =>
457
- isDirectory(path)
458
- );
459
- return { dynamicRequireModuleSet, dynamicRequireModuleDirPaths };
460
- }
461
-
462
- function getCommonJSMetaPromise(commonJSMetaPromises, id) {
463
- let commonJSMetaPromise = commonJSMetaPromises.get(id);
464
- if (commonJSMetaPromise) return commonJSMetaPromise.promise;
465
-
466
- const promise = new Promise((resolve) => {
467
- commonJSMetaPromise = {
468
- resolve,
469
- promise: null
470
- };
471
- commonJSMetaPromises.set(id, commonJSMetaPromise);
472
- });
473
- commonJSMetaPromise.promise = promise;
474
-
475
- return promise;
476
- }
477
-
478
- function setCommonJSMetaPromise(commonJSMetaPromises, id, commonjsMeta) {
479
- const commonJSMetaPromise = commonJSMetaPromises.get(id);
480
- if (commonJSMetaPromise) {
481
- if (commonJSMetaPromise.resolve) {
482
- commonJSMetaPromise.resolve(commonjsMeta);
483
- commonJSMetaPromise.resolve = null;
484
- }
485
- } else {
486
- commonJSMetaPromises.set(id, { promise: Promise.resolve(commonjsMeta), resolve: null });
487
- }
488
- }
489
-
490
- // e.g. id === "commonjsHelpers?commonjsRegister"
491
- function getSpecificHelperProxy(id) {
492
- return `export {${id.split('?')[1]} as default} from "${HELPERS_ID}";`;
493
- }
494
-
495
- function getUnknownRequireProxy(id, requireReturnsDefault) {
496
- if (requireReturnsDefault === true || id.endsWith('.json')) {
497
- return `export {default} from ${JSON.stringify(id)};`;
498
- }
499
- const name = getName(id);
500
- const exported =
501
- requireReturnsDefault === 'auto'
502
- ? `import {getDefaultExportFromNamespaceIfNotNamed} from "${HELPERS_ID}"; export default /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(${name});`
503
- : requireReturnsDefault === 'preferred'
504
- ? `import {getDefaultExportFromNamespaceIfPresent} from "${HELPERS_ID}"; export default /*@__PURE__*/getDefaultExportFromNamespaceIfPresent(${name});`
505
- : !requireReturnsDefault
506
- ? `import {getAugmentedNamespace} from "${HELPERS_ID}"; export default /*@__PURE__*/getAugmentedNamespace(${name});`
507
- : `export default ${name};`;
508
- return `import * as ${name} from ${JSON.stringify(id)}; ${exported}`;
509
- }
510
-
511
- function getDynamicJsonProxy(id, commonDir) {
512
- const normalizedPath = normalizePathSlashes(id.slice(DYNAMIC_JSON_PREFIX.length));
513
- return `const commonjsRegister = require('${HELPERS_ID}?commonjsRegister');\ncommonjsRegister(${JSON.stringify(
514
- getVirtualPathForDynamicRequirePath(normalizedPath, commonDir)
515
- )}, function (module, exports) {
516
- module.exports = require(${JSON.stringify(normalizedPath)});
517
- });`;
518
- }
519
-
520
- function getDynamicRequireProxy(normalizedPath, commonDir) {
521
- return `const commonjsRegister = require('${HELPERS_ID}?commonjsRegister');\ncommonjsRegister(${JSON.stringify(
522
- getVirtualPathForDynamicRequirePath(normalizedPath, commonDir)
523
- )}, function (module, exports) {
524
- ${readFileSync(normalizedPath, { encoding: 'utf8' })}
525
- });`;
526
- }
527
-
528
- async function getStaticRequireProxy(
529
- id,
530
- requireReturnsDefault,
531
- esModulesWithDefaultExport,
532
- esModulesWithNamedExports,
533
- commonJsMetaPromises
534
- ) {
535
- const name = getName(id);
536
- const commonjsMeta = await getCommonJSMetaPromise(commonJsMetaPromises, id);
537
- if (commonjsMeta && commonjsMeta.isCommonJS) {
538
- return `export { __moduleExports as default } from ${JSON.stringify(id)};`;
539
- } else if (commonjsMeta === null) {
540
- return getUnknownRequireProxy(id, requireReturnsDefault);
541
- } else if (!requireReturnsDefault) {
542
- return `import { getAugmentedNamespace } from "${HELPERS_ID}"; import * as ${name} from ${JSON.stringify(
543
- id
544
- )}; export default /*@__PURE__*/getAugmentedNamespace(${name});`;
545
- } else if (
546
- requireReturnsDefault !== true &&
547
- (requireReturnsDefault === 'namespace' ||
548
- !esModulesWithDefaultExport.has(id) ||
549
- (requireReturnsDefault === 'auto' && esModulesWithNamedExports.has(id)))
550
- ) {
551
- return `import * as ${name} from ${JSON.stringify(id)}; export default ${name};`;
552
- }
553
- return `export { default } from ${JSON.stringify(id)};`;
554
- }
555
-
556
- /* eslint-disable no-param-reassign, no-undefined */
557
-
558
- function getCandidatesForExtension(resolved, extension) {
559
- return [resolved + extension, `${resolved}${sep}index${extension}`];
560
- }
561
-
562
- function getCandidates(resolved, extensions) {
563
- return extensions.reduce(
564
- (paths, extension) => paths.concat(getCandidatesForExtension(resolved, extension)),
565
- [resolved]
566
- );
567
- }
568
-
569
- function getResolveId(extensions) {
570
- function resolveExtensions(importee, importer) {
571
- // not our problem
572
- if (importee[0] !== '.' || !importer) return undefined;
573
-
574
- const resolved = resolve(dirname(importer), importee);
575
- const candidates = getCandidates(resolved, extensions);
576
-
577
- for (let i = 0; i < candidates.length; i += 1) {
578
- try {
579
- const stats = statSync(candidates[i]);
580
- if (stats.isFile()) return { id: candidates[i] };
581
- } catch (err) {
582
- /* noop */
583
- }
584
- }
585
-
586
- return undefined;
587
- }
588
-
589
- return function resolveId(importee, rawImporter) {
590
- if (isWrappedId(importee, MODULE_SUFFIX) || isWrappedId(importee, EXPORTS_SUFFIX)) {
591
- return importee;
592
- }
593
-
594
- const importer =
595
- rawImporter && isWrappedId(rawImporter, DYNAMIC_REGISTER_SUFFIX)
596
- ? unwrapId(rawImporter, DYNAMIC_REGISTER_SUFFIX)
597
- : rawImporter;
598
-
599
- // Except for exports, proxies are only importing resolved ids,
600
- // no need to resolve again
601
- if (importer && isWrappedId(importer, PROXY_SUFFIX)) {
602
- return importee;
603
- }
604
-
605
- const isProxyModule = isWrappedId(importee, PROXY_SUFFIX);
606
- const isRequiredModule = isWrappedId(importee, REQUIRE_SUFFIX);
607
- let isModuleRegistration = false;
608
-
609
- if (isProxyModule) {
610
- importee = unwrapId(importee, PROXY_SUFFIX);
611
- } else if (isRequiredModule) {
612
- importee = unwrapId(importee, REQUIRE_SUFFIX);
613
-
614
- isModuleRegistration = isWrappedId(importee, DYNAMIC_REGISTER_SUFFIX);
615
- if (isModuleRegistration) {
616
- importee = unwrapId(importee, DYNAMIC_REGISTER_SUFFIX);
617
- }
618
- }
619
-
620
- if (
621
- importee.startsWith(HELPERS_ID) ||
622
- importee === DYNAMIC_PACKAGES_ID ||
623
- importee.startsWith(DYNAMIC_JSON_PREFIX)
624
- ) {
625
- return importee;
626
- }
627
-
628
- if (importee.startsWith('\0')) {
629
- return null;
630
- }
631
-
632
- return this.resolve(importee, importer, {
633
- skipSelf: true,
634
- custom: { 'node-resolve': { isRequire: isProxyModule || isRequiredModule } }
635
- }).then((resolved) => {
636
- if (!resolved) {
637
- resolved = resolveExtensions(importee, importer);
638
- }
639
- if (resolved && isProxyModule) {
640
- resolved.id = wrapId(resolved.id, resolved.external ? EXTERNAL_SUFFIX : PROXY_SUFFIX);
641
- resolved.external = false;
642
- } else if (resolved && isModuleRegistration) {
643
- resolved.id = wrapId(resolved.id, DYNAMIC_REGISTER_SUFFIX);
644
- } else if (!resolved && (isProxyModule || isRequiredModule)) {
645
- return { id: wrapId(importee, EXTERNAL_SUFFIX), external: false };
646
- }
647
- return resolved;
648
- });
649
- };
650
- }
651
-
652
- function validateRollupVersion(rollupVersion, peerDependencyVersion) {
653
- const [major, minor] = rollupVersion.split('.').map(Number);
654
- const versionRegexp = /\^(\d+\.\d+)\.\d+/g;
655
- let minMajor = Infinity;
656
- let minMinor = Infinity;
657
- let foundVersion;
658
- // eslint-disable-next-line no-cond-assign
659
- while ((foundVersion = versionRegexp.exec(peerDependencyVersion))) {
660
- const [foundMajor, foundMinor] = foundVersion[1].split('.').map(Number);
661
- if (foundMajor < minMajor) {
662
- minMajor = foundMajor;
663
- minMinor = foundMinor;
664
- }
665
- }
666
- if (major < minMajor || (major === minMajor && minor < minMinor)) {
667
- throw new Error(
668
- `Insufficient Rollup version: "@rollup/plugin-commonjs" requires at least rollup@${minMajor}.${minMinor} but found rollup@${rollupVersion}.`
669
- );
670
- }
671
- }
672
-
673
- const operators = {
674
- '==': (x) => equals(x.left, x.right, false),
675
-
676
- '!=': (x) => not(operators['=='](x)),
677
-
678
- '===': (x) => equals(x.left, x.right, true),
679
-
680
- '!==': (x) => not(operators['==='](x)),
681
-
682
- '!': (x) => isFalsy(x.argument),
683
-
684
- '&&': (x) => isTruthy(x.left) && isTruthy(x.right),
685
-
686
- '||': (x) => isTruthy(x.left) || isTruthy(x.right)
687
- };
688
-
689
- function not(value) {
690
- return value === null ? value : !value;
691
- }
692
-
693
- function equals(a, b, strict) {
694
- if (a.type !== b.type) return null;
695
- // eslint-disable-next-line eqeqeq
696
- if (a.type === 'Literal') return strict ? a.value === b.value : a.value == b.value;
697
- return null;
698
- }
699
-
700
- function isTruthy(node) {
701
- if (!node) return false;
702
- if (node.type === 'Literal') return !!node.value;
703
- if (node.type === 'ParenthesizedExpression') return isTruthy(node.expression);
704
- if (node.operator in operators) return operators[node.operator](node);
705
- return null;
706
- }
707
-
708
- function isFalsy(node) {
709
- return not(isTruthy(node));
710
- }
711
-
712
- function getKeypath(node) {
713
- const parts = [];
714
-
715
- while (node.type === 'MemberExpression') {
716
- if (node.computed) return null;
717
-
718
- parts.unshift(node.property.name);
719
- // eslint-disable-next-line no-param-reassign
720
- node = node.object;
721
- }
722
-
723
- if (node.type !== 'Identifier') return null;
724
-
725
- const { name } = node;
726
- parts.unshift(name);
727
-
728
- return { name, keypath: parts.join('.') };
729
- }
730
-
731
- const KEY_COMPILED_ESM = '__esModule';
732
-
733
- function isDefineCompiledEsm(node) {
734
- const definedProperty =
735
- getDefinePropertyCallName(node, 'exports') || getDefinePropertyCallName(node, 'module.exports');
736
- if (definedProperty && definedProperty.key === KEY_COMPILED_ESM) {
737
- return isTruthy(definedProperty.value);
738
- }
739
- return false;
740
- }
741
-
742
- function getDefinePropertyCallName(node, targetName) {
743
- const {
744
- callee: { object, property }
745
- } = node;
746
- if (!object || object.type !== 'Identifier' || object.name !== 'Object') return;
747
- if (!property || property.type !== 'Identifier' || property.name !== 'defineProperty') return;
748
- if (node.arguments.length !== 3) return;
749
-
750
- const targetNames = targetName.split('.');
751
- const [target, key, value] = node.arguments;
752
- if (targetNames.length === 1) {
753
- if (target.type !== 'Identifier' || target.name !== targetNames[0]) {
754
- return;
755
- }
756
- }
757
-
758
- if (targetNames.length === 2) {
759
- if (
760
- target.type !== 'MemberExpression' ||
761
- target.object.name !== targetNames[0] ||
762
- target.property.name !== targetNames[1]
763
- ) {
764
- return;
765
- }
766
- }
767
-
768
- if (value.type !== 'ObjectExpression' || !value.properties) return;
769
-
770
- const valueProperty = value.properties.find((p) => p.key && p.key.name === 'value');
771
- if (!valueProperty || !valueProperty.value) return;
772
-
773
- // eslint-disable-next-line consistent-return
774
- return { key: key.value, value: valueProperty.value };
775
- }
776
-
777
- function isShorthandProperty(parent) {
778
- return parent && parent.type === 'Property' && parent.shorthand;
779
- }
780
-
781
- function hasDefineEsmProperty(node) {
782
- return node.properties.some((property) => {
783
- if (
784
- property.type === 'Property' &&
785
- property.key.type === 'Identifier' &&
786
- property.key.name === '__esModule' &&
787
- isTruthy(property.value)
788
- ) {
789
- return true;
790
- }
791
- return false;
792
- });
793
- }
794
-
795
- function wrapCode(magicString, uses, moduleName, exportsName) {
796
- const args = [];
797
- const passedArgs = [];
798
- if (uses.module) {
799
- args.push('module');
800
- passedArgs.push(moduleName);
801
- }
802
- if (uses.exports) {
803
- args.push('exports');
804
- passedArgs.push(exportsName);
805
- }
806
- magicString
807
- .trim()
808
- .prepend(`(function (${args.join(', ')}) {\n`)
809
- .append(`\n}(${passedArgs.join(', ')}));`);
810
- }
811
-
812
- function rewriteExportsAndGetExportsBlock(
813
- magicString,
814
- moduleName,
815
- exportsName,
816
- wrapped,
817
- moduleExportsAssignments,
818
- firstTopLevelModuleExportsAssignment,
819
- exportsAssignmentsByName,
820
- topLevelAssignments,
821
- defineCompiledEsmExpressions,
822
- deconflictedExportNames,
823
- code,
824
- HELPERS_NAME,
825
- exportMode,
826
- detectWrappedDefault,
827
- defaultIsModuleExports
828
- ) {
829
- const exports = [];
830
- const exportDeclarations = [];
831
-
832
- if (exportMode === 'replace') {
833
- getExportsForReplacedModuleExports(
834
- magicString,
835
- exports,
836
- exportDeclarations,
837
- moduleExportsAssignments,
838
- firstTopLevelModuleExportsAssignment,
839
- exportsName
840
- );
841
- } else {
842
- exports.push(`${exportsName} as __moduleExports`);
843
- if (wrapped) {
844
- getExportsWhenWrapping(
845
- exportDeclarations,
846
- exportsName,
847
- detectWrappedDefault,
848
- HELPERS_NAME,
849
- defaultIsModuleExports
850
- );
851
- } else {
852
- getExports(
853
- magicString,
854
- exports,
855
- exportDeclarations,
856
- moduleExportsAssignments,
857
- exportsAssignmentsByName,
858
- deconflictedExportNames,
859
- topLevelAssignments,
860
- moduleName,
861
- exportsName,
862
- defineCompiledEsmExpressions,
863
- HELPERS_NAME,
864
- defaultIsModuleExports
865
- );
866
- }
867
- }
868
- if (exports.length) {
869
- exportDeclarations.push(`export { ${exports.join(', ')} };`);
870
- }
871
-
872
- return `\n\n${exportDeclarations.join('\n')}`;
873
- }
874
-
875
- function getExportsForReplacedModuleExports(
876
- magicString,
877
- exports,
878
- exportDeclarations,
879
- moduleExportsAssignments,
880
- firstTopLevelModuleExportsAssignment,
881
- exportsName
882
- ) {
883
- for (const { left } of moduleExportsAssignments) {
884
- magicString.overwrite(left.start, left.end, exportsName);
885
- }
886
- magicString.prependRight(firstTopLevelModuleExportsAssignment.left.start, 'var ');
887
- exports.push(`${exportsName} as __moduleExports`);
888
- exportDeclarations.push(`export default ${exportsName};`);
889
- }
890
-
891
- function getExportsWhenWrapping(
892
- exportDeclarations,
893
- exportsName,
894
- detectWrappedDefault,
895
- HELPERS_NAME,
896
- defaultIsModuleExports
897
- ) {
898
- exportDeclarations.push(
899
- `export default ${
900
- detectWrappedDefault && defaultIsModuleExports === 'auto'
901
- ? `/*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName})`
902
- : defaultIsModuleExports === false
903
- ? `${exportsName}.default`
904
- : exportsName
905
- };`
906
- );
907
- }
908
-
909
- function getExports(
910
- magicString,
911
- exports,
912
- exportDeclarations,
913
- moduleExportsAssignments,
914
- exportsAssignmentsByName,
915
- deconflictedExportNames,
916
- topLevelAssignments,
917
- moduleName,
918
- exportsName,
919
- defineCompiledEsmExpressions,
920
- HELPERS_NAME,
921
- defaultIsModuleExports
922
- ) {
923
- let deconflictedDefaultExportName;
924
- // Collect and rewrite module.exports assignments
925
- for (const { left } of moduleExportsAssignments) {
926
- magicString.overwrite(left.start, left.end, `${moduleName}.exports`);
927
- }
928
-
929
- // Collect and rewrite named exports
930
- for (const [exportName, { nodes }] of exportsAssignmentsByName) {
931
- const deconflicted = deconflictedExportNames[exportName];
932
- let needsDeclaration = true;
933
- for (const node of nodes) {
934
- let replacement = `${deconflicted} = ${exportsName}.${exportName}`;
935
- if (needsDeclaration && topLevelAssignments.has(node)) {
936
- replacement = `var ${replacement}`;
937
- needsDeclaration = false;
938
- }
939
- magicString.overwrite(node.start, node.left.end, replacement);
940
- }
941
- if (needsDeclaration) {
942
- magicString.prepend(`var ${deconflicted};\n`);
943
- }
944
-
945
- if (exportName === 'default') {
946
- deconflictedDefaultExportName = deconflicted;
947
- } else {
948
- exports.push(exportName === deconflicted ? exportName : `${deconflicted} as ${exportName}`);
949
- }
950
- }
951
-
952
- // Collect and rewrite exports.__esModule assignments
953
- let isRestorableCompiledEsm = false;
954
- for (const expression of defineCompiledEsmExpressions) {
955
- isRestorableCompiledEsm = true;
956
- const moduleExportsExpression =
957
- expression.type === 'CallExpression' ? expression.arguments[0] : expression.left.object;
958
- magicString.overwrite(moduleExportsExpression.start, moduleExportsExpression.end, exportsName);
959
- }
960
-
961
- if (!isRestorableCompiledEsm || defaultIsModuleExports === true) {
962
- exportDeclarations.push(`export default ${exportsName};`);
963
- } else if (moduleExportsAssignments.length === 0 || defaultIsModuleExports === false) {
964
- exports.push(`${deconflictedDefaultExportName || exportsName} as default`);
965
- } else {
966
- exportDeclarations.push(
967
- `export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName});`
968
- );
969
- }
970
- }
971
-
972
- function isRequireStatement(node, scope) {
973
- if (!node) return false;
974
- if (node.type !== 'CallExpression') return false;
975
-
976
- // Weird case of `require()` or `module.require()` without arguments
977
- if (node.arguments.length === 0) return false;
978
-
979
- return isRequire(node.callee, scope);
980
- }
981
-
982
- function isRequire(node, scope) {
983
- return (
984
- (node.type === 'Identifier' && node.name === 'require' && !scope.contains('require')) ||
985
- (node.type === 'MemberExpression' && isModuleRequire(node, scope))
986
- );
987
- }
988
-
989
- function isModuleRequire({ object, property }, scope) {
990
- return (
991
- object.type === 'Identifier' &&
992
- object.name === 'module' &&
993
- property.type === 'Identifier' &&
994
- property.name === 'require' &&
995
- !scope.contains('module')
996
- );
997
- }
998
-
999
- function isStaticRequireStatement(node, scope) {
1000
- if (!isRequireStatement(node, scope)) return false;
1001
- return !hasDynamicArguments(node);
1002
- }
1003
-
1004
- function hasDynamicArguments(node) {
1005
- return (
1006
- node.arguments.length > 1 ||
1007
- (node.arguments[0].type !== 'Literal' &&
1008
- (node.arguments[0].type !== 'TemplateLiteral' || node.arguments[0].expressions.length > 0))
1009
- );
1010
- }
1011
-
1012
- const reservedMethod = { resolve: true, cache: true, main: true };
1013
-
1014
- function isNodeRequirePropertyAccess(parent) {
1015
- return parent && parent.property && reservedMethod[parent.property.name];
1016
- }
1017
-
1018
- function isIgnoredRequireStatement(requiredNode, ignoreRequire) {
1019
- return ignoreRequire(requiredNode.arguments[0].value);
1020
- }
1021
-
1022
- function getRequireStringArg(node) {
1023
- return node.arguments[0].type === 'Literal'
1024
- ? node.arguments[0].value
1025
- : node.arguments[0].quasis[0].value.cooked;
1026
- }
1027
-
1028
- function hasDynamicModuleForPath(source, id, dynamicRequireModuleSet) {
1029
- if (!/^(?:\.{0,2}[/\\]|[A-Za-z]:[/\\])/.test(source)) {
1030
- try {
1031
- const resolvedPath = normalizePathSlashes(sync(source, { basedir: dirname(id) }));
1032
- if (dynamicRequireModuleSet.has(resolvedPath)) {
1033
- return true;
1034
- }
1035
- } catch (ex) {
1036
- // Probably a node.js internal module
1037
- return false;
1038
- }
1039
-
1040
- return false;
1041
- }
1042
-
1043
- for (const attemptExt of ['', '.js', '.json']) {
1044
- const resolvedPath = normalizePathSlashes(resolve(dirname(id), source + attemptExt));
1045
- if (dynamicRequireModuleSet.has(resolvedPath)) {
1046
- return true;
1047
- }
1048
- }
1049
-
1050
- return false;
1051
- }
1052
-
1053
- function getRequireHandlers() {
1054
- const requiredSources = [];
1055
- const requiredBySource = Object.create(null);
1056
- const requiredByNode = new Map();
1057
- const requireExpressionsWithUsedReturnValue = [];
1058
-
1059
- function addRequireStatement(sourceId, node, scope, usesReturnValue) {
1060
- const required = getRequired(sourceId);
1061
- requiredByNode.set(node, { scope, required });
1062
- if (usesReturnValue) {
1063
- required.nodesUsingRequired.push(node);
1064
- requireExpressionsWithUsedReturnValue.push(node);
1065
- }
1066
- }
1067
-
1068
- function getRequired(sourceId) {
1069
- if (!requiredBySource[sourceId]) {
1070
- requiredSources.push(sourceId);
1071
-
1072
- requiredBySource[sourceId] = {
1073
- source: sourceId,
1074
- name: null,
1075
- nodesUsingRequired: []
1076
- };
1077
- }
1078
-
1079
- return requiredBySource[sourceId];
1080
- }
1081
-
1082
- function rewriteRequireExpressionsAndGetImportBlock(
1083
- magicString,
1084
- topLevelDeclarations,
1085
- topLevelRequireDeclarators,
1086
- reassignedNames,
1087
- helpersName,
1088
- dynamicRegisterSources,
1089
- moduleName,
1090
- exportsName,
1091
- id,
1092
- exportMode
1093
- ) {
1094
- setRemainingImportNamesAndRewriteRequires(
1095
- requireExpressionsWithUsedReturnValue,
1096
- requiredByNode,
1097
- magicString
1098
- );
1099
- const imports = [];
1100
- imports.push(`import * as ${helpersName} from "${HELPERS_ID}";`);
1101
- if (exportMode === 'module') {
1102
- imports.push(
1103
- `import { __module as ${moduleName}, exports as ${exportsName} } from ${JSON.stringify(
1104
- wrapId(id, MODULE_SUFFIX)
1105
- )}`
1106
- );
1107
- } else if (exportMode === 'exports') {
1108
- imports.push(
1109
- `import { __exports as ${exportsName} } from ${JSON.stringify(wrapId(id, EXPORTS_SUFFIX))}`
1110
- );
1111
- }
1112
- for (const source of dynamicRegisterSources) {
1113
- imports.push(`import ${JSON.stringify(wrapId(source, REQUIRE_SUFFIX))};`);
1114
- }
1115
- for (const source of requiredSources) {
1116
- if (!source.startsWith('\0')) {
1117
- imports.push(`import ${JSON.stringify(wrapId(source, REQUIRE_SUFFIX))};`);
1118
- }
1119
- const { name, nodesUsingRequired } = requiredBySource[source];
1120
- imports.push(
1121
- `import ${nodesUsingRequired.length ? `${name} from ` : ''}${JSON.stringify(
1122
- source.startsWith('\0') ? source : wrapId(source, PROXY_SUFFIX)
1123
- )};`
1124
- );
1125
- }
1126
- return imports.length ? `${imports.join('\n')}\n\n` : '';
1127
- }
1128
-
1129
- return {
1130
- addRequireStatement,
1131
- requiredSources,
1132
- rewriteRequireExpressionsAndGetImportBlock
1133
- };
1134
- }
1135
-
1136
- function setRemainingImportNamesAndRewriteRequires(
1137
- requireExpressionsWithUsedReturnValue,
1138
- requiredByNode,
1139
- magicString
1140
- ) {
1141
- let uid = 0;
1142
- for (const requireExpression of requireExpressionsWithUsedReturnValue) {
1143
- const { required } = requiredByNode.get(requireExpression);
1144
- if (!required.name) {
1145
- let potentialName;
1146
- const isUsedName = (node) => requiredByNode.get(node).scope.contains(potentialName);
1147
- do {
1148
- potentialName = `require$$${uid}`;
1149
- uid += 1;
1150
- } while (required.nodesUsingRequired.some(isUsedName));
1151
- required.name = potentialName;
1152
- }
1153
- magicString.overwrite(requireExpression.start, requireExpression.end, required.name);
1154
- }
1155
- }
1156
-
1157
- /* eslint-disable no-param-reassign, no-shadow, no-underscore-dangle, no-continue */
1158
-
1159
- const exportsPattern = /^(?:module\.)?exports(?:\.([a-zA-Z_$][a-zA-Z_$0-9]*))?$/;
1160
-
1161
- const functionType = /^(?:FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/;
1162
-
1163
- function transformCommonjs(
1164
- parse,
1165
- code,
1166
- id,
1167
- isEsModule,
1168
- ignoreGlobal,
1169
- ignoreRequire,
1170
- ignoreDynamicRequires,
1171
- getIgnoreTryCatchRequireStatementMode,
1172
- sourceMap,
1173
- isDynamicRequireModulesEnabled,
1174
- dynamicRequireModuleSet,
1175
- disableWrap,
1176
- commonDir,
1177
- astCache,
1178
- defaultIsModuleExports
1179
- ) {
1180
- const ast = astCache || tryParse(parse, code, id);
1181
- const magicString = new MagicString(code);
1182
- const uses = {
1183
- module: false,
1184
- exports: false,
1185
- global: false,
1186
- require: false
1187
- };
1188
- let usesDynamicRequire = false;
1189
- const virtualDynamicRequirePath =
1190
- isDynamicRequireModulesEnabled && getVirtualPathForDynamicRequirePath(dirname(id), commonDir);
1191
- let scope = attachScopes(ast, 'scope');
1192
- let lexicalDepth = 0;
1193
- let programDepth = 0;
1194
- let currentTryBlockEnd = null;
1195
- let shouldWrap = false;
1196
-
1197
- const globals = new Set();
1198
-
1199
- // TODO technically wrong since globals isn't populated yet, but ¯\_(ツ)_/¯
1200
- const HELPERS_NAME = deconflict([scope], globals, 'commonjsHelpers');
1201
- const dynamicRegisterSources = new Set();
1202
- let hasRemovedRequire = false;
1203
-
1204
- const {
1205
- addRequireStatement,
1206
- requiredSources,
1207
- rewriteRequireExpressionsAndGetImportBlock
1208
- } = getRequireHandlers();
1209
-
1210
- // See which names are assigned to. This is necessary to prevent
1211
- // illegally replacing `var foo = require('foo')` with `import foo from 'foo'`,
1212
- // where `foo` is later reassigned. (This happens in the wild. CommonJS, sigh)
1213
- const reassignedNames = new Set();
1214
- const topLevelDeclarations = [];
1215
- const topLevelRequireDeclarators = new Set();
1216
- const skippedNodes = new Set();
1217
- const moduleAccessScopes = new Set([scope]);
1218
- const exportsAccessScopes = new Set([scope]);
1219
- const moduleExportsAssignments = [];
1220
- let firstTopLevelModuleExportsAssignment = null;
1221
- const exportsAssignmentsByName = new Map();
1222
- const topLevelAssignments = new Set();
1223
- const topLevelDefineCompiledEsmExpressions = [];
1224
-
1225
- walk(ast, {
1226
- enter(node, parent) {
1227
- if (skippedNodes.has(node)) {
1228
- this.skip();
1229
- return;
1230
- }
1231
-
1232
- if (currentTryBlockEnd !== null && node.start > currentTryBlockEnd) {
1233
- currentTryBlockEnd = null;
1234
- }
1235
-
1236
- programDepth += 1;
1237
- if (node.scope) ({ scope } = node);
1238
- if (functionType.test(node.type)) lexicalDepth += 1;
1239
- if (sourceMap) {
1240
- magicString.addSourcemapLocation(node.start);
1241
- magicString.addSourcemapLocation(node.end);
1242
- }
1243
-
1244
- // eslint-disable-next-line default-case
1245
- switch (node.type) {
1246
- case 'TryStatement':
1247
- if (currentTryBlockEnd === null) {
1248
- currentTryBlockEnd = node.block.end;
1249
- }
1250
- return;
1251
- case 'AssignmentExpression':
1252
- if (node.left.type === 'MemberExpression') {
1253
- const flattened = getKeypath(node.left);
1254
- if (!flattened || scope.contains(flattened.name)) return;
1255
-
1256
- const exportsPatternMatch = exportsPattern.exec(flattened.keypath);
1257
- if (!exportsPatternMatch || flattened.keypath === 'exports') return;
1258
-
1259
- const [, exportName] = exportsPatternMatch;
1260
- uses[flattened.name] = true;
1261
-
1262
- // we're dealing with `module.exports = ...` or `[module.]exports.foo = ...` –
1263
- if (flattened.keypath === 'module.exports') {
1264
- moduleExportsAssignments.push(node);
1265
- if (programDepth > 3) {
1266
- moduleAccessScopes.add(scope);
1267
- } else if (!firstTopLevelModuleExportsAssignment) {
1268
- firstTopLevelModuleExportsAssignment = node;
1269
- }
1270
-
1271
- if (defaultIsModuleExports === false) {
1272
- shouldWrap = true;
1273
- } else if (defaultIsModuleExports === 'auto') {
1274
- if (node.right.type === 'ObjectExpression') {
1275
- if (hasDefineEsmProperty(node.right)) {
1276
- shouldWrap = true;
1277
- }
1278
- } else if (defaultIsModuleExports === false) {
1279
- shouldWrap = true;
1280
- }
1281
- }
1282
- } else if (exportName === KEY_COMPILED_ESM) {
1283
- if (programDepth > 3) {
1284
- shouldWrap = true;
1285
- } else {
1286
- topLevelDefineCompiledEsmExpressions.push(node);
1287
- }
1288
- } else {
1289
- const exportsAssignments = exportsAssignmentsByName.get(exportName) || {
1290
- nodes: [],
1291
- scopes: new Set()
1292
- };
1293
- exportsAssignments.nodes.push(node);
1294
- exportsAssignments.scopes.add(scope);
1295
- exportsAccessScopes.add(scope);
1296
- exportsAssignmentsByName.set(exportName, exportsAssignments);
1297
- if (programDepth <= 3) {
1298
- topLevelAssignments.add(node);
1299
- }
1300
- }
1301
-
1302
- skippedNodes.add(node.left);
1303
- } else {
1304
- for (const name of extractAssignedNames(node.left)) {
1305
- reassignedNames.add(name);
1306
- }
1307
- }
1308
- return;
1309
- case 'CallExpression': {
1310
- if (isDefineCompiledEsm(node)) {
1311
- if (programDepth === 3 && parent.type === 'ExpressionStatement') {
1312
- // skip special handling for [module.]exports until we know we render this
1313
- skippedNodes.add(node.arguments[0]);
1314
- topLevelDefineCompiledEsmExpressions.push(node);
1315
- } else {
1316
- shouldWrap = true;
1317
- }
1318
- return;
1319
- }
1320
-
1321
- if (
1322
- node.callee.object &&
1323
- node.callee.object.name === 'require' &&
1324
- node.callee.property.name === 'resolve' &&
1325
- hasDynamicModuleForPath(id, '/', dynamicRequireModuleSet)
1326
- ) {
1327
- const requireNode = node.callee.object;
1328
- magicString.appendLeft(
1329
- node.end - 1,
1330
- `,${JSON.stringify(
1331
- dirname(id) === '.' ? null /* default behavior */ : virtualDynamicRequirePath
1332
- )}`
1333
- );
1334
- magicString.overwrite(
1335
- requireNode.start,
1336
- requireNode.end,
1337
- `${HELPERS_NAME}.commonjsRequire`,
1338
- {
1339
- storeName: true
1340
- }
1341
- );
1342
- return;
1343
- }
1344
-
1345
- if (!isStaticRequireStatement(node, scope)) return;
1346
- if (!isDynamicRequireModulesEnabled) {
1347
- skippedNodes.add(node.callee);
1348
- }
1349
- if (!isIgnoredRequireStatement(node, ignoreRequire)) {
1350
- skippedNodes.add(node.callee);
1351
- const usesReturnValue = parent.type !== 'ExpressionStatement';
1352
-
1353
- let canConvertRequire = true;
1354
- let shouldRemoveRequireStatement = false;
1355
-
1356
- if (currentTryBlockEnd !== null) {
1357
- ({
1358
- canConvertRequire,
1359
- shouldRemoveRequireStatement
1360
- } = getIgnoreTryCatchRequireStatementMode(node.arguments[0].value));
1361
-
1362
- if (shouldRemoveRequireStatement) {
1363
- hasRemovedRequire = true;
1364
- }
1365
- }
1366
-
1367
- let sourceId = getRequireStringArg(node);
1368
- const isDynamicRegister = isWrappedId(sourceId, DYNAMIC_REGISTER_SUFFIX);
1369
- if (isDynamicRegister) {
1370
- sourceId = unwrapId(sourceId, DYNAMIC_REGISTER_SUFFIX);
1371
- if (sourceId.endsWith('.json')) {
1372
- sourceId = DYNAMIC_JSON_PREFIX + sourceId;
1373
- }
1374
- dynamicRegisterSources.add(wrapId(sourceId, DYNAMIC_REGISTER_SUFFIX));
1375
- } else {
1376
- if (
1377
- !sourceId.endsWith('.json') &&
1378
- hasDynamicModuleForPath(sourceId, id, dynamicRequireModuleSet)
1379
- ) {
1380
- if (shouldRemoveRequireStatement) {
1381
- magicString.overwrite(node.start, node.end, `undefined`);
1382
- } else if (canConvertRequire) {
1383
- magicString.overwrite(
1384
- node.start,
1385
- node.end,
1386
- `${HELPERS_NAME}.commonjsRequire(${JSON.stringify(
1387
- getVirtualPathForDynamicRequirePath(sourceId, commonDir)
1388
- )}, ${JSON.stringify(
1389
- dirname(id) === '.' ? null /* default behavior */ : virtualDynamicRequirePath
1390
- )})`
1391
- );
1392
- usesDynamicRequire = true;
1393
- }
1394
- return;
1395
- }
1396
-
1397
- if (canConvertRequire) {
1398
- addRequireStatement(sourceId, node, scope, usesReturnValue);
1399
- }
1400
- }
1401
-
1402
- if (usesReturnValue) {
1403
- if (shouldRemoveRequireStatement) {
1404
- magicString.overwrite(node.start, node.end, `undefined`);
1405
- return;
1406
- }
1407
-
1408
- if (
1409
- parent.type === 'VariableDeclarator' &&
1410
- !scope.parent &&
1411
- parent.id.type === 'Identifier'
1412
- ) {
1413
- // This will allow us to reuse this variable name as the imported variable if it is not reassigned
1414
- // and does not conflict with variables in other places where this is imported
1415
- topLevelRequireDeclarators.add(parent);
1416
- }
1417
- } else {
1418
- // This is a bare import, e.g. `require('foo');`
1419
-
1420
- if (!canConvertRequire && !shouldRemoveRequireStatement) {
1421
- return;
1422
- }
1423
-
1424
- magicString.remove(parent.start, parent.end);
1425
- }
1426
- }
1427
- return;
1428
- }
1429
- case 'ConditionalExpression':
1430
- case 'IfStatement':
1431
- // skip dead branches
1432
- if (isFalsy(node.test)) {
1433
- skippedNodes.add(node.consequent);
1434
- } else if (node.alternate && isTruthy(node.test)) {
1435
- skippedNodes.add(node.alternate);
1436
- }
1437
- return;
1438
- case 'Identifier': {
1439
- const { name } = node;
1440
- if (!(isReference(node, parent) && !scope.contains(name))) return;
1441
- switch (name) {
1442
- case 'require':
1443
- if (isNodeRequirePropertyAccess(parent)) {
1444
- if (hasDynamicModuleForPath(id, '/', dynamicRequireModuleSet)) {
1445
- if (parent.property.name === 'cache') {
1446
- magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsRequire`, {
1447
- storeName: true
1448
- });
1449
- }
1450
- }
1451
-
1452
- return;
1453
- }
1454
-
1455
- if (isDynamicRequireModulesEnabled && isRequireStatement(parent, scope)) {
1456
- magicString.appendLeft(
1457
- parent.end - 1,
1458
- `,${JSON.stringify(
1459
- dirname(id) === '.' ? null /* default behavior */ : virtualDynamicRequirePath
1460
- )}`
1461
- );
1462
- }
1463
- if (!ignoreDynamicRequires) {
1464
- if (isShorthandProperty(parent)) {
1465
- magicString.appendRight(node.end, `: ${HELPERS_NAME}.commonjsRequire`);
1466
- } else {
1467
- magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsRequire`, {
1468
- storeName: true
1469
- });
1470
- }
1471
- }
1472
- usesDynamicRequire = true;
1473
- return;
1474
- case 'module':
1475
- case 'exports':
1476
- shouldWrap = true;
1477
- uses[name] = true;
1478
- return;
1479
- case 'global':
1480
- uses.global = true;
1481
- if (!ignoreGlobal) {
1482
- magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsGlobal`, {
1483
- storeName: true
1484
- });
1485
- }
1486
- return;
1487
- case 'define':
1488
- magicString.overwrite(node.start, node.end, 'undefined', {
1489
- storeName: true
1490
- });
1491
- return;
1492
- default:
1493
- globals.add(name);
1494
- return;
1495
- }
1496
- }
1497
- case 'MemberExpression':
1498
- if (!isDynamicRequireModulesEnabled && isModuleRequire(node, scope)) {
1499
- magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsRequire`, {
1500
- storeName: true
1501
- });
1502
- skippedNodes.add(node.object);
1503
- skippedNodes.add(node.property);
1504
- }
1505
- return;
1506
- case 'ReturnStatement':
1507
- // if top-level return, we need to wrap it
1508
- if (lexicalDepth === 0) {
1509
- shouldWrap = true;
1510
- }
1511
- return;
1512
- case 'ThisExpression':
1513
- // rewrite top-level `this` as `commonjsHelpers.commonjsGlobal`
1514
- if (lexicalDepth === 0) {
1515
- uses.global = true;
1516
- if (!ignoreGlobal) {
1517
- magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsGlobal`, {
1518
- storeName: true
1519
- });
1520
- }
1521
- }
1522
- return;
1523
- case 'UnaryExpression':
1524
- // rewrite `typeof module`, `typeof module.exports` and `typeof exports` (https://github.com/rollup/rollup-plugin-commonjs/issues/151)
1525
- if (node.operator === 'typeof') {
1526
- const flattened = getKeypath(node.argument);
1527
- if (!flattened) return;
1528
-
1529
- if (scope.contains(flattened.name)) return;
1530
-
1531
- if (
1532
- flattened.keypath === 'module.exports' ||
1533
- flattened.keypath === 'module' ||
1534
- flattened.keypath === 'exports'
1535
- ) {
1536
- magicString.overwrite(node.start, node.end, `'object'`, {
1537
- storeName: false
1538
- });
1539
- }
1540
- }
1541
- return;
1542
- case 'VariableDeclaration':
1543
- if (!scope.parent) {
1544
- topLevelDeclarations.push(node);
1545
- }
1546
- }
1547
- },
1548
-
1549
- leave(node) {
1550
- programDepth -= 1;
1551
- if (node.scope) scope = scope.parent;
1552
- if (functionType.test(node.type)) lexicalDepth -= 1;
1553
- }
1554
- });
1555
-
1556
- const nameBase = getName(id);
1557
- const exportsName = deconflict([...exportsAccessScopes], globals, nameBase);
1558
- const moduleName = deconflict([...moduleAccessScopes], globals, `${nameBase}Module`);
1559
- const deconflictedExportNames = Object.create(null);
1560
- for (const [exportName, { scopes }] of exportsAssignmentsByName) {
1561
- deconflictedExportNames[exportName] = deconflict([...scopes], globals, exportName);
1562
- }
1563
-
1564
- // We cannot wrap ES/mixed modules
1565
- shouldWrap =
1566
- !isEsModule &&
1567
- !disableWrap &&
1568
- (shouldWrap || (uses.exports && moduleExportsAssignments.length > 0));
1569
- const detectWrappedDefault =
1570
- shouldWrap &&
1571
- (topLevelDefineCompiledEsmExpressions.length > 0 || code.indexOf('__esModule') >= 0);
1572
-
1573
- if (
1574
- !(
1575
- requiredSources.length ||
1576
- dynamicRegisterSources.size ||
1577
- uses.module ||
1578
- uses.exports ||
1579
- uses.require ||
1580
- usesDynamicRequire ||
1581
- hasRemovedRequire ||
1582
- topLevelDefineCompiledEsmExpressions.length > 0
1583
- ) &&
1584
- (ignoreGlobal || !uses.global)
1585
- ) {
1586
- return { meta: { commonjs: { isCommonJS: false } } };
1587
- }
1588
-
1589
- let leadingComment = '';
1590
- if (code.startsWith('/*')) {
1591
- const commentEnd = code.indexOf('*/', 2) + 2;
1592
- leadingComment = `${code.slice(0, commentEnd)}\n`;
1593
- magicString.remove(0, commentEnd).trim();
1594
- }
1595
-
1596
- const exportMode = shouldWrap
1597
- ? uses.module
1598
- ? 'module'
1599
- : 'exports'
1600
- : firstTopLevelModuleExportsAssignment
1601
- ? exportsAssignmentsByName.size === 0 && topLevelDefineCompiledEsmExpressions.length === 0
1602
- ? 'replace'
1603
- : 'module'
1604
- : moduleExportsAssignments.length === 0
1605
- ? 'exports'
1606
- : 'module';
1607
-
1608
- const importBlock = rewriteRequireExpressionsAndGetImportBlock(
1609
- magicString,
1610
- topLevelDeclarations,
1611
- topLevelRequireDeclarators,
1612
- reassignedNames,
1613
- HELPERS_NAME,
1614
- dynamicRegisterSources,
1615
- moduleName,
1616
- exportsName,
1617
- id,
1618
- exportMode
1619
- );
1620
-
1621
- const exportBlock = isEsModule
1622
- ? ''
1623
- : rewriteExportsAndGetExportsBlock(
1624
- magicString,
1625
- moduleName,
1626
- exportsName,
1627
- shouldWrap,
1628
- moduleExportsAssignments,
1629
- firstTopLevelModuleExportsAssignment,
1630
- exportsAssignmentsByName,
1631
- topLevelAssignments,
1632
- topLevelDefineCompiledEsmExpressions,
1633
- deconflictedExportNames,
1634
- code,
1635
- HELPERS_NAME,
1636
- exportMode,
1637
- detectWrappedDefault,
1638
- defaultIsModuleExports
1639
- );
1640
-
1641
- if (shouldWrap) {
1642
- wrapCode(magicString, uses, moduleName, exportsName);
1643
- }
1644
-
1645
- magicString
1646
- .trim()
1647
- .prepend(leadingComment + importBlock)
1648
- .append(exportBlock);
1649
-
1650
- return {
1651
- code: magicString.toString(),
1652
- map: sourceMap ? magicString.generateMap() : null,
1653
- syntheticNamedExports: isEsModule ? false : '__moduleExports',
1654
- meta: { commonjs: { isCommonJS: !isEsModule } }
1655
- };
1656
- }
1657
-
1658
- function commonjs(options = {}) {
1659
- const extensions = options.extensions || ['.js'];
1660
- const filter = createFilter(options.include, options.exclude);
1661
- const {
1662
- ignoreGlobal,
1663
- ignoreDynamicRequires,
1664
- requireReturnsDefault: requireReturnsDefaultOption,
1665
- esmExternals
1666
- } = options;
1667
- const getRequireReturnsDefault =
1668
- typeof requireReturnsDefaultOption === 'function'
1669
- ? requireReturnsDefaultOption
1670
- : () => requireReturnsDefaultOption;
1671
- let esmExternalIds;
1672
- const isEsmExternal =
1673
- typeof esmExternals === 'function'
1674
- ? esmExternals
1675
- : Array.isArray(esmExternals)
1676
- ? ((esmExternalIds = new Set(esmExternals)), (id) => esmExternalIds.has(id))
1677
- : () => esmExternals;
1678
- const defaultIsModuleExports =
1679
- typeof options.defaultIsModuleExports === 'boolean' ? options.defaultIsModuleExports : 'auto';
1680
-
1681
- const { dynamicRequireModuleSet, dynamicRequireModuleDirPaths } = getDynamicRequirePaths(
1682
- options.dynamicRequireTargets
1683
- );
1684
- const isDynamicRequireModulesEnabled = dynamicRequireModuleSet.size > 0;
1685
- const commonDir = isDynamicRequireModulesEnabled
1686
- ? getCommonDir(null, Array.from(dynamicRequireModuleSet).concat(process.cwd()))
1687
- : null;
1688
-
1689
- const esModulesWithDefaultExport = new Set();
1690
- const esModulesWithNamedExports = new Set();
1691
- const commonJsMetaPromises = new Map();
1692
-
1693
- const ignoreRequire =
1694
- typeof options.ignore === 'function'
1695
- ? options.ignore
1696
- : Array.isArray(options.ignore)
1697
- ? (id) => options.ignore.includes(id)
1698
- : () => false;
1699
-
1700
- const getIgnoreTryCatchRequireStatementMode = (id) => {
1701
- const mode =
1702
- typeof options.ignoreTryCatch === 'function'
1703
- ? options.ignoreTryCatch(id)
1704
- : Array.isArray(options.ignoreTryCatch)
1705
- ? options.ignoreTryCatch.includes(id)
1706
- : typeof options.ignoreTryCatch !== 'undefined'
1707
- ? options.ignoreTryCatch
1708
- : true;
1709
-
1710
- return {
1711
- canConvertRequire: mode !== 'remove' && mode !== true,
1712
- shouldRemoveRequireStatement: mode === 'remove'
1713
- };
1714
- };
1715
-
1716
- const resolveId = getResolveId(extensions);
1717
-
1718
- const sourceMap = options.sourceMap !== false;
1719
-
1720
- function transformAndCheckExports(code, id) {
1721
- if (isDynamicRequireModulesEnabled && this.getModuleInfo(id).isEntry) {
1722
- // eslint-disable-next-line no-param-reassign
1723
- code =
1724
- getDynamicPackagesEntryIntro(dynamicRequireModuleDirPaths, dynamicRequireModuleSet) + code;
1725
- }
1726
-
1727
- const { isEsModule, hasDefaultExport, hasNamedExports, ast } = analyzeTopLevelStatements(
1728
- this.parse,
1729
- code,
1730
- id
1731
- );
1732
- if (hasDefaultExport) {
1733
- esModulesWithDefaultExport.add(id);
1734
- }
1735
- if (hasNamedExports) {
1736
- esModulesWithNamedExports.add(id);
1737
- }
1738
-
1739
- if (
1740
- !dynamicRequireModuleSet.has(normalizePathSlashes(id)) &&
1741
- (!hasCjsKeywords(code, ignoreGlobal) || (isEsModule && !options.transformMixedEsModules))
1742
- ) {
1743
- return { meta: { commonjs: { isCommonJS: false } } };
1744
- }
1745
-
1746
- // avoid wrapping as this is a commonjsRegister call
1747
- const disableWrap = isWrappedId(id, DYNAMIC_REGISTER_SUFFIX);
1748
- if (disableWrap) {
1749
- // eslint-disable-next-line no-param-reassign
1750
- id = unwrapId(id, DYNAMIC_REGISTER_SUFFIX);
1751
- }
1752
-
1753
- return transformCommonjs(
1754
- this.parse,
1755
- code,
1756
- id,
1757
- isEsModule,
1758
- ignoreGlobal || isEsModule,
1759
- ignoreRequire,
1760
- ignoreDynamicRequires && !isDynamicRequireModulesEnabled,
1761
- getIgnoreTryCatchRequireStatementMode,
1762
- sourceMap,
1763
- isDynamicRequireModulesEnabled,
1764
- dynamicRequireModuleSet,
1765
- disableWrap,
1766
- commonDir,
1767
- ast,
1768
- defaultIsModuleExports
1769
- );
1770
- }
1771
-
1772
- return {
1773
- name: 'commonjs',
1774
-
1775
- buildStart() {
1776
- validateRollupVersion(this.meta.rollupVersion, peerDependencies.rollup);
1777
- if (options.namedExports != null) {
1778
- this.warn(
1779
- 'The namedExports option from "@rollup/plugin-commonjs" is deprecated. Named exports are now handled automatically.'
1780
- );
1781
- }
1782
- },
1783
-
1784
- resolveId,
1785
-
1786
- load(id) {
1787
- if (id === HELPERS_ID) {
1788
- return getHelpersModule(isDynamicRequireModulesEnabled, ignoreDynamicRequires);
1789
- }
1790
-
1791
- if (id.startsWith(HELPERS_ID)) {
1792
- return getSpecificHelperProxy(id);
1793
- }
1794
-
1795
- if (isWrappedId(id, MODULE_SUFFIX)) {
1796
- const actualId = unwrapId(id, MODULE_SUFFIX);
1797
- let name = getName(actualId);
1798
- let code;
1799
- if (isDynamicRequireModulesEnabled) {
1800
- if (['modulePath', 'commonjsRequire', 'createModule'].includes(name)) {
1801
- name = `${name}_`;
1802
- }
1803
- code =
1804
- `import {commonjsRequire, createModule} from "${HELPERS_ID}";\n` +
1805
- `var ${name} = createModule(${JSON.stringify(
1806
- getVirtualPathForDynamicRequirePath(dirname(actualId), commonDir)
1807
- )});\n` +
1808
- `export {${name} as __module}`;
1809
- } else {
1810
- code = `var ${name} = {exports: {}}; export {${name} as __module}`;
1811
- }
1812
- return {
1813
- code,
1814
- syntheticNamedExports: '__module',
1815
- meta: { commonjs: { isCommonJS: false } }
1816
- };
1817
- }
1818
-
1819
- if (isWrappedId(id, EXPORTS_SUFFIX)) {
1820
- const actualId = unwrapId(id, EXPORTS_SUFFIX);
1821
- const name = getName(actualId);
1822
- return {
1823
- code: `var ${name} = {}; export {${name} as __exports}`,
1824
- meta: { commonjs: { isCommonJS: false } }
1825
- };
1826
- }
1827
-
1828
- if (isWrappedId(id, EXTERNAL_SUFFIX)) {
1829
- const actualId = unwrapId(id, EXTERNAL_SUFFIX);
1830
- return getUnknownRequireProxy(
1831
- actualId,
1832
- isEsmExternal(actualId) ? getRequireReturnsDefault(actualId) : true
1833
- );
1834
- }
1835
-
1836
- if (id === DYNAMIC_PACKAGES_ID) {
1837
- return getDynamicPackagesModule(dynamicRequireModuleDirPaths, commonDir);
1838
- }
1839
-
1840
- if (id.startsWith(DYNAMIC_JSON_PREFIX)) {
1841
- return getDynamicJsonProxy(id, commonDir);
1842
- }
1843
-
1844
- if (isDynamicModuleImport(id, dynamicRequireModuleSet)) {
1845
- return `export default require(${JSON.stringify(normalizePathSlashes(id))});`;
1846
- }
1847
-
1848
- if (isWrappedId(id, DYNAMIC_REGISTER_SUFFIX)) {
1849
- return getDynamicRequireProxy(
1850
- normalizePathSlashes(unwrapId(id, DYNAMIC_REGISTER_SUFFIX)),
1851
- commonDir
1852
- );
1853
- }
1854
-
1855
- if (isWrappedId(id, PROXY_SUFFIX)) {
1856
- const actualId = unwrapId(id, PROXY_SUFFIX);
1857
- return getStaticRequireProxy(
1858
- actualId,
1859
- getRequireReturnsDefault(actualId),
1860
- esModulesWithDefaultExport,
1861
- esModulesWithNamedExports,
1862
- commonJsMetaPromises
1863
- );
1864
- }
1865
-
1866
- return null;
1867
- },
1868
-
1869
- transform(code, rawId) {
1870
- let id = rawId;
1871
-
1872
- if (isWrappedId(id, DYNAMIC_REGISTER_SUFFIX)) {
1873
- id = unwrapId(id, DYNAMIC_REGISTER_SUFFIX);
1874
- }
1875
-
1876
- const extName = extname(id);
1877
- if (
1878
- extName !== '.cjs' &&
1879
- id !== DYNAMIC_PACKAGES_ID &&
1880
- !id.startsWith(DYNAMIC_JSON_PREFIX) &&
1881
- (!filter(id) || !extensions.includes(extName))
1882
- ) {
1883
- return null;
1884
- }
1885
-
1886
- try {
1887
- return transformAndCheckExports.call(this, code, rawId);
1888
- } catch (err) {
1889
- return this.error(err, err.loc);
1890
- }
1891
- },
1892
-
1893
- moduleParsed({ id, meta: { commonjs: commonjsMeta } }) {
1894
- if (commonjsMeta && commonjsMeta.isCommonJS != null) {
1895
- setCommonJSMetaPromise(commonJsMetaPromises, id, commonjsMeta);
1896
- return;
1897
- }
1898
- setCommonJSMetaPromise(commonJsMetaPromises, id, null);
1899
- }
1900
- };
1901
- }
1902
-
1903
- export default commonjs;
1904
- //# sourceMappingURL=index.es.js.map