@rollup/plugin-commonjs 22.0.0-3 → 22.0.0-7
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.js → cjs/index.js} +224 -148
- package/dist/cjs/index.js.map +1 -0
- package/dist/{index.es.js → es/index.js} +225 -149
- package/dist/es/index.js.map +1 -0
- package/dist/es/package.json +1 -0
- package/package.json +11 -6
- package/dist/index.es.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -7,9 +7,9 @@ import { walk } from 'estree-walker';
|
|
|
7
7
|
import MagicString from 'magic-string';
|
|
8
8
|
import isReference from 'is-reference';
|
|
9
9
|
|
|
10
|
-
var version = "
|
|
10
|
+
var version = "22.0.0-7";
|
|
11
11
|
var peerDependencies = {
|
|
12
|
-
rollup: "^2.
|
|
12
|
+
rollup: "^2.66.1"
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
function tryParse(parse, code, id) {
|
|
@@ -194,6 +194,9 @@ function getDynamicRequireModules(patterns, dynamicRequireRoot) {
|
|
|
194
194
|
|
|
195
195
|
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.');`;
|
|
196
196
|
|
|
197
|
+
const COMMONJS_REQUIRE_EXPORT = 'commonjsRequire';
|
|
198
|
+
const CREATE_COMMONJS_REQUIRE_EXPORT = 'createCommonjsRequire';
|
|
199
|
+
|
|
197
200
|
function getDynamicModuleRegistry(
|
|
198
201
|
isDynamicRequireModulesEnabled,
|
|
199
202
|
dynamicRequireModules,
|
|
@@ -201,7 +204,7 @@ function getDynamicModuleRegistry(
|
|
|
201
204
|
ignoreDynamicRequires
|
|
202
205
|
) {
|
|
203
206
|
if (!isDynamicRequireModulesEnabled) {
|
|
204
|
-
return `export function
|
|
207
|
+
return `export function ${COMMONJS_REQUIRE_EXPORT}(path) {
|
|
205
208
|
${FAILED_REQUIRE_ERROR}
|
|
206
209
|
}`;
|
|
207
210
|
}
|
|
@@ -231,25 +234,25 @@ ${dynamicModuleProps}
|
|
|
231
234
|
});
|
|
232
235
|
}
|
|
233
236
|
|
|
234
|
-
export function
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
237
|
+
export function ${CREATE_COMMONJS_REQUIRE_EXPORT}(originalModuleDir) {
|
|
238
|
+
function handleRequire(path) {
|
|
239
|
+
var resolvedPath = commonjsResolve(path, originalModuleDir);
|
|
240
|
+
if (resolvedPath !== null) {
|
|
241
|
+
return getDynamicModules()[resolvedPath]();
|
|
242
|
+
}
|
|
243
|
+
${ignoreDynamicRequires ? 'return require(path);' : FAILED_REQUIRE_ERROR}
|
|
238
244
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return resolvedPath;
|
|
245
|
+
handleRequire.resolve = function (path) {
|
|
246
|
+
var resolvedPath = commonjsResolve(path, originalModuleDir);
|
|
247
|
+
if (resolvedPath !== null) {
|
|
248
|
+
return resolvedPath;
|
|
249
|
+
}
|
|
250
|
+
return require.resolve(path);
|
|
246
251
|
}
|
|
247
|
-
return
|
|
252
|
+
return handleRequire;
|
|
248
253
|
}
|
|
249
254
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
function commonjsResolveImpl (path, originalModuleDir) {
|
|
255
|
+
function commonjsResolve (path, originalModuleDir) {
|
|
253
256
|
var shouldTryNodeModules = isPossibleNodeModulesPath(path);
|
|
254
257
|
path = normalize(path);
|
|
255
258
|
var relPath;
|
|
@@ -325,7 +328,8 @@ const WRAPPED_SUFFIX = '?commonjs-wrapped';
|
|
|
325
328
|
const EXTERNAL_SUFFIX = '?commonjs-external';
|
|
326
329
|
const EXPORTS_SUFFIX = '?commonjs-exports';
|
|
327
330
|
const MODULE_SUFFIX = '?commonjs-module';
|
|
328
|
-
const
|
|
331
|
+
const ENTRY_SUFFIX = '?commonjs-entry';
|
|
332
|
+
const ES_IMPORT_SUFFIX = '?commonjs-es-import';
|
|
329
333
|
|
|
330
334
|
const DYNAMIC_MODULES_ID = '\0commonjs-dynamic-modules';
|
|
331
335
|
const HELPERS_ID = '\0commonjsHelpers.js';
|
|
@@ -393,21 +397,15 @@ function getUnknownRequireProxy(id, requireReturnsDefault) {
|
|
|
393
397
|
return `import * as ${name} from ${JSON.stringify(id)}; ${exported}`;
|
|
394
398
|
}
|
|
395
399
|
|
|
396
|
-
async function getStaticRequireProxy(
|
|
397
|
-
id,
|
|
398
|
-
requireReturnsDefault,
|
|
399
|
-
esModulesWithDefaultExport,
|
|
400
|
-
esModulesWithNamedExports,
|
|
401
|
-
loadModule
|
|
402
|
-
) {
|
|
400
|
+
async function getStaticRequireProxy(id, requireReturnsDefault, loadModule) {
|
|
403
401
|
const name = getName(id);
|
|
404
402
|
const {
|
|
405
403
|
meta: { commonjs: commonjsMeta }
|
|
406
404
|
} = await loadModule({ id });
|
|
407
|
-
if (commonjsMeta
|
|
408
|
-
return `export { __moduleExports as default } from ${JSON.stringify(id)};`;
|
|
409
|
-
} else if (!commonjsMeta) {
|
|
405
|
+
if (!commonjsMeta) {
|
|
410
406
|
return getUnknownRequireProxy(id, requireReturnsDefault);
|
|
407
|
+
} else if (commonjsMeta.isCommonJS) {
|
|
408
|
+
return `export { __moduleExports as default } from ${JSON.stringify(id)};`;
|
|
411
409
|
} else if (!requireReturnsDefault) {
|
|
412
410
|
return `import { getAugmentedNamespace } from "${HELPERS_ID}"; import * as ${name} from ${JSON.stringify(
|
|
413
411
|
id
|
|
@@ -415,14 +413,30 @@ async function getStaticRequireProxy(
|
|
|
415
413
|
} else if (
|
|
416
414
|
requireReturnsDefault !== true &&
|
|
417
415
|
(requireReturnsDefault === 'namespace' ||
|
|
418
|
-
!
|
|
419
|
-
(requireReturnsDefault === 'auto' &&
|
|
416
|
+
!commonjsMeta.hasDefaultExport ||
|
|
417
|
+
(requireReturnsDefault === 'auto' && commonjsMeta.hasNamedExports))
|
|
420
418
|
) {
|
|
421
419
|
return `import * as ${name} from ${JSON.stringify(id)}; export default ${name};`;
|
|
422
420
|
}
|
|
423
421
|
return `export { default } from ${JSON.stringify(id)};`;
|
|
424
422
|
}
|
|
425
423
|
|
|
424
|
+
async function getEntryProxy(id, defaultIsModuleExports, loadModule) {
|
|
425
|
+
const {
|
|
426
|
+
meta: { commonjs: commonjsMeta },
|
|
427
|
+
hasDefaultExport
|
|
428
|
+
} = await loadModule({ id, moduleSideEffects: true });
|
|
429
|
+
if (!commonjsMeta || commonjsMeta.isCommonJS !== IS_WRAPPED_COMMONJS) {
|
|
430
|
+
const stringifiedId = JSON.stringify(id);
|
|
431
|
+
let code = `export * from ${stringifiedId};`;
|
|
432
|
+
if (hasDefaultExport) {
|
|
433
|
+
code += `export { default } from ${stringifiedId};`;
|
|
434
|
+
}
|
|
435
|
+
return code;
|
|
436
|
+
}
|
|
437
|
+
return getEsImportProxy(id, defaultIsModuleExports);
|
|
438
|
+
}
|
|
439
|
+
|
|
426
440
|
function getEsImportProxy(id, defaultIsModuleExports) {
|
|
427
441
|
const name = getName(id);
|
|
428
442
|
const exportsName = `${name}Exports`;
|
|
@@ -491,6 +505,7 @@ function getResolveId(extensions) {
|
|
|
491
505
|
}
|
|
492
506
|
|
|
493
507
|
if (
|
|
508
|
+
importee.endsWith(ENTRY_SUFFIX) ||
|
|
494
509
|
isWrappedId(importee, MODULE_SUFFIX) ||
|
|
495
510
|
isWrappedId(importee, EXPORTS_SUFFIX) ||
|
|
496
511
|
isWrappedId(importee, PROXY_SUFFIX) ||
|
|
@@ -507,7 +522,8 @@ function getResolveId(extensions) {
|
|
|
507
522
|
importer === DYNAMIC_MODULES_ID ||
|
|
508
523
|
// Proxies are only importing resolved ids, no need to resolve again
|
|
509
524
|
isWrappedId(importer, PROXY_SUFFIX) ||
|
|
510
|
-
isWrappedId(importer, ES_IMPORT_SUFFIX)
|
|
525
|
+
isWrappedId(importer, ES_IMPORT_SUFFIX) ||
|
|
526
|
+
importer.endsWith(ENTRY_SUFFIX)
|
|
511
527
|
) {
|
|
512
528
|
return importee;
|
|
513
529
|
}
|
|
@@ -540,6 +556,10 @@ function getResolveId(extensions) {
|
|
|
540
556
|
if (!resolved || resolved.external) {
|
|
541
557
|
return resolved;
|
|
542
558
|
}
|
|
559
|
+
if (resolveOptions.isEntry) {
|
|
560
|
+
// We must not precede entry proxies with a `\0` as that will mess up relative external resolution
|
|
561
|
+
return resolved.id + ENTRY_SUFFIX;
|
|
562
|
+
}
|
|
543
563
|
const {
|
|
544
564
|
meta: { commonjs: commonjsMeta }
|
|
545
565
|
} = await this.load(resolved);
|
|
@@ -550,7 +570,7 @@ function getResolveId(extensions) {
|
|
|
550
570
|
};
|
|
551
571
|
}
|
|
552
572
|
|
|
553
|
-
function
|
|
573
|
+
function getRequireResolver(extensions, detectCyclesAndConditional) {
|
|
554
574
|
const knownCjsModuleTypes = Object.create(null);
|
|
555
575
|
const requiredIds = Object.create(null);
|
|
556
576
|
const unconditionallyRequiredIds = Object.create(null);
|
|
@@ -574,11 +594,7 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
|
|
|
574
594
|
|
|
575
595
|
const getTypeForFullyAnalyzedModule = (id) => {
|
|
576
596
|
const knownType = knownCjsModuleTypes[id];
|
|
577
|
-
if (
|
|
578
|
-
knownType === IS_WRAPPED_COMMONJS ||
|
|
579
|
-
!detectCyclesAndConditional ||
|
|
580
|
-
fullyAnalyzedModules[id]
|
|
581
|
-
) {
|
|
597
|
+
if (knownType !== true || !detectCyclesAndConditional || fullyAnalyzedModules[id]) {
|
|
582
598
|
return knownType;
|
|
583
599
|
}
|
|
584
600
|
fullyAnalyzedModules[id] = true;
|
|
@@ -588,26 +604,80 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
|
|
|
588
604
|
return knownType;
|
|
589
605
|
};
|
|
590
606
|
|
|
607
|
+
const setInitialParentType = (id, initialCommonJSType) => {
|
|
608
|
+
// It is possible a transformed module is already fully analyzed when using
|
|
609
|
+
// the cache and one dependency introduces a new cycle. Then transform is
|
|
610
|
+
// run for a fully analzyed module again. Fully analyzed modules may never
|
|
611
|
+
// change their type as importers already trust their type.
|
|
612
|
+
knownCjsModuleTypes[id] = fullyAnalyzedModules[id]
|
|
613
|
+
? knownCjsModuleTypes[id]
|
|
614
|
+
: initialCommonJSType;
|
|
615
|
+
if (
|
|
616
|
+
detectCyclesAndConditional &&
|
|
617
|
+
knownCjsModuleTypes[id] === true &&
|
|
618
|
+
requiredIds[id] &&
|
|
619
|
+
!unconditionallyRequiredIds[id]
|
|
620
|
+
) {
|
|
621
|
+
knownCjsModuleTypes[id] = IS_WRAPPED_COMMONJS;
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
const setTypesForRequiredModules = async (parentId, resolved, isConditional, loadModule) => {
|
|
626
|
+
const childId = resolved.id;
|
|
627
|
+
requiredIds[childId] = true;
|
|
628
|
+
if (!(isConditional || knownCjsModuleTypes[parentId] === IS_WRAPPED_COMMONJS)) {
|
|
629
|
+
unconditionallyRequiredIds[childId] = true;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
getDependencies(parentId).add(childId);
|
|
633
|
+
if (!isCyclic(childId)) {
|
|
634
|
+
// This makes sure the current transform handler waits for all direct dependencies to be
|
|
635
|
+
// loaded and transformed and therefore for all transitive CommonJS dependencies to be
|
|
636
|
+
// loaded as well so that all cycles have been found and knownCjsModuleTypes is reliable.
|
|
637
|
+
await loadModule(resolved);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
|
|
591
641
|
return {
|
|
592
642
|
getWrappedIds: () =>
|
|
593
643
|
Object.keys(knownCjsModuleTypes).filter(
|
|
594
644
|
(id) => knownCjsModuleTypes[id] === IS_WRAPPED_COMMONJS
|
|
595
645
|
),
|
|
596
646
|
isRequiredId: (id) => requiredIds[id],
|
|
597
|
-
|
|
647
|
+
async shouldTransformCachedModule({ id: parentId, meta: { commonjs: parentMeta } }) {
|
|
648
|
+
// Ignore modules that did not pass through the original transformer in a previous build
|
|
649
|
+
if (!(parentMeta && parentMeta.requires)) {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
setInitialParentType(parentId, parentMeta.initialCommonJSType);
|
|
653
|
+
await Promise.all(
|
|
654
|
+
parentMeta.requires.map(({ resolved, isConditional }) =>
|
|
655
|
+
setTypesForRequiredModules(parentId, resolved, isConditional, this.load)
|
|
656
|
+
)
|
|
657
|
+
);
|
|
658
|
+
if (getTypeForFullyAnalyzedModule(parentId) !== parentMeta.isCommonJS) {
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
for (const {
|
|
662
|
+
resolved: { id }
|
|
663
|
+
} of parentMeta.requires) {
|
|
664
|
+
if (getTypeForFullyAnalyzedModule(id) !== parentMeta.isRequiredCommonJS[id]) {
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return false;
|
|
669
|
+
},
|
|
670
|
+
/* eslint-disable no-param-reassign */
|
|
671
|
+
resolveRequireSourcesAndUpdateMeta: (rollupContext) => async (
|
|
598
672
|
parentId,
|
|
599
673
|
isParentCommonJS,
|
|
674
|
+
parentMeta,
|
|
600
675
|
sources
|
|
601
676
|
) => {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
requiredIds[parentId] &&
|
|
607
|
-
!unconditionallyRequiredIds[parentId]
|
|
608
|
-
) {
|
|
609
|
-
knownCjsModuleTypes[parentId] = IS_WRAPPED_COMMONJS;
|
|
610
|
-
}
|
|
677
|
+
parentMeta.initialCommonJSType = isParentCommonJS;
|
|
678
|
+
parentMeta.requires = [];
|
|
679
|
+
parentMeta.isRequiredCommonJS = Object.create(null);
|
|
680
|
+
setInitialParentType(parentId, isParentCommonJS);
|
|
611
681
|
const requireTargets = await Promise.all(
|
|
612
682
|
sources.map(async ({ source, isConditional }) => {
|
|
613
683
|
// Never analyze or proxy internal modules
|
|
@@ -625,59 +695,58 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
|
|
|
625
695
|
if (resolved.external) {
|
|
626
696
|
return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false };
|
|
627
697
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
unconditionallyRequiredIds[childId] = true;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
getDependencies(parentId).add(childId);
|
|
634
|
-
if (!isCyclic(childId)) {
|
|
635
|
-
// This makes sure the current transform handler waits for all direct dependencies to be
|
|
636
|
-
// loaded and transformed and therefore for all transitive CommonJS dependencies to be
|
|
637
|
-
// loaded as well so that all cycles have been found and knownCjsModuleTypes is reliable.
|
|
638
|
-
await rollupContext.load(resolved);
|
|
639
|
-
} else if (detectCyclesAndConditional && knownCjsModuleTypes[parentId]) {
|
|
640
|
-
knownCjsModuleTypes[parentId] = IS_WRAPPED_COMMONJS;
|
|
641
|
-
}
|
|
698
|
+
parentMeta.requires.push({ resolved, isConditional });
|
|
699
|
+
await setTypesForRequiredModules(parentId, resolved, isConditional, rollupContext.load);
|
|
642
700
|
return { id: childId, allowProxy: true };
|
|
643
701
|
})
|
|
644
702
|
);
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
703
|
+
parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId);
|
|
704
|
+
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
|
|
705
|
+
// eslint-disable-next-line no-multi-assign
|
|
706
|
+
const isCommonJS = (parentMeta.isRequiredCommonJS[
|
|
707
|
+
dependencyId
|
|
708
|
+
] = getTypeForFullyAnalyzedModule(dependencyId));
|
|
709
|
+
return {
|
|
710
|
+
source: sources[index].source,
|
|
711
|
+
id: allowProxy
|
|
712
|
+
? isCommonJS === IS_WRAPPED_COMMONJS
|
|
713
|
+
? wrapId(dependencyId, WRAPPED_SUFFIX)
|
|
714
|
+
: wrapId(dependencyId, PROXY_SUFFIX)
|
|
715
|
+
: dependencyId,
|
|
716
|
+
isCommonJS
|
|
717
|
+
};
|
|
718
|
+
});
|
|
660
719
|
}
|
|
661
720
|
};
|
|
662
721
|
}
|
|
663
722
|
|
|
664
|
-
function
|
|
665
|
-
const
|
|
666
|
-
const versionRegexp = /\^(\d+\.\d+)\.\d+/g;
|
|
723
|
+
function validateVersion(actualVersion, peerDependencyVersion, name) {
|
|
724
|
+
const versionRegexp = /\^(\d+\.\d+\.\d+)/g;
|
|
667
725
|
let minMajor = Infinity;
|
|
668
726
|
let minMinor = Infinity;
|
|
727
|
+
let minPatch = Infinity;
|
|
669
728
|
let foundVersion;
|
|
670
729
|
// eslint-disable-next-line no-cond-assign
|
|
671
730
|
while ((foundVersion = versionRegexp.exec(peerDependencyVersion))) {
|
|
672
|
-
const [foundMajor, foundMinor] = foundVersion[1].split('.').map(Number);
|
|
731
|
+
const [foundMajor, foundMinor, foundPatch] = foundVersion[1].split('.').map(Number);
|
|
673
732
|
if (foundMajor < minMajor) {
|
|
674
733
|
minMajor = foundMajor;
|
|
675
734
|
minMinor = foundMinor;
|
|
735
|
+
minPatch = foundPatch;
|
|
676
736
|
}
|
|
677
737
|
}
|
|
678
|
-
if (
|
|
738
|
+
if (!actualVersion) {
|
|
679
739
|
throw new Error(
|
|
680
|
-
`Insufficient
|
|
740
|
+
`Insufficient ${name} version: "@rollup/plugin-commonjs" requires at least ${name}@${minMajor}.${minMinor}.${minPatch}.`
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
const [major, minor, patch] = actualVersion.split('.').map(Number);
|
|
744
|
+
if (
|
|
745
|
+
major < minMajor ||
|
|
746
|
+
(major === minMajor && (minor < minMinor || (minor === minMinor && patch < minPatch)))
|
|
747
|
+
) {
|
|
748
|
+
throw new Error(
|
|
749
|
+
`Insufficient ${name} version: "@rollup/plugin-commonjs" requires at least ${name}@${minMajor}.${minMinor}.${minPatch} but found ${name}@${actualVersion}.`
|
|
681
750
|
);
|
|
682
751
|
}
|
|
683
752
|
}
|
|
@@ -1120,17 +1189,20 @@ function getRequireHandlers() {
|
|
|
1120
1189
|
exportsName,
|
|
1121
1190
|
id,
|
|
1122
1191
|
exportMode,
|
|
1123
|
-
|
|
1192
|
+
resolveRequireSourcesAndUpdateMeta,
|
|
1124
1193
|
needsRequireWrapper,
|
|
1125
1194
|
isEsModule,
|
|
1126
|
-
|
|
1127
|
-
getIgnoreTryCatchRequireStatementMode
|
|
1195
|
+
isDynamicRequireModulesEnabled,
|
|
1196
|
+
getIgnoreTryCatchRequireStatementMode,
|
|
1197
|
+
commonjsMeta
|
|
1128
1198
|
) {
|
|
1129
1199
|
const imports = [];
|
|
1130
1200
|
imports.push(`import * as ${helpersName} from "${HELPERS_ID}";`);
|
|
1131
|
-
if (
|
|
1201
|
+
if (dynamicRequireName) {
|
|
1132
1202
|
imports.push(
|
|
1133
|
-
`import {
|
|
1203
|
+
`import { ${
|
|
1204
|
+
isDynamicRequireModulesEnabled ? CREATE_COMMONJS_REQUIRE_EXPORT : COMMONJS_REQUIRE_EXPORT
|
|
1205
|
+
} as ${dynamicRequireName} } from "${DYNAMIC_MODULES_ID}";`
|
|
1134
1206
|
);
|
|
1135
1207
|
}
|
|
1136
1208
|
if (exportMode === 'module') {
|
|
@@ -1145,9 +1217,10 @@ function getRequireHandlers() {
|
|
|
1145
1217
|
);
|
|
1146
1218
|
}
|
|
1147
1219
|
const requiresBySource = collectSources(requireExpressions);
|
|
1148
|
-
const
|
|
1220
|
+
const requireTargets = await resolveRequireSourcesAndUpdateMeta(
|
|
1149
1221
|
id,
|
|
1150
1222
|
needsRequireWrapper ? IS_WRAPPED_COMMONJS : !isEsModule,
|
|
1223
|
+
commonjsMeta,
|
|
1151
1224
|
Object.keys(requiresBySource).map((source) => {
|
|
1152
1225
|
return {
|
|
1153
1226
|
source,
|
|
@@ -1162,10 +1235,7 @@ function getRequireHandlers() {
|
|
|
1162
1235
|
getIgnoreTryCatchRequireStatementMode,
|
|
1163
1236
|
magicString
|
|
1164
1237
|
);
|
|
1165
|
-
return {
|
|
1166
|
-
importBlock: imports.length ? `${imports.join('\n')}\n\n` : '',
|
|
1167
|
-
usesRequireWrapper
|
|
1168
|
-
};
|
|
1238
|
+
return imports.length ? `${imports.join('\n')}\n\n` : '';
|
|
1169
1239
|
}
|
|
1170
1240
|
|
|
1171
1241
|
return {
|
|
@@ -1268,9 +1338,10 @@ async function transformCommonjs(
|
|
|
1268
1338
|
astCache,
|
|
1269
1339
|
defaultIsModuleExports,
|
|
1270
1340
|
needsRequireWrapper,
|
|
1271
|
-
|
|
1341
|
+
resolveRequireSourcesAndUpdateMeta,
|
|
1272
1342
|
isRequired,
|
|
1273
|
-
checkDynamicRequire
|
|
1343
|
+
checkDynamicRequire,
|
|
1344
|
+
commonjsMeta
|
|
1274
1345
|
) {
|
|
1275
1346
|
const ast = astCache || tryParse(parse, code, id);
|
|
1276
1347
|
const magicString = new MagicString(code);
|
|
@@ -1419,12 +1490,6 @@ async function transformCommonjs(
|
|
|
1419
1490
|
checkDynamicRequire(node.start);
|
|
1420
1491
|
uses.require = true;
|
|
1421
1492
|
const requireNode = node.callee.object;
|
|
1422
|
-
magicString.appendLeft(
|
|
1423
|
-
node.end - 1,
|
|
1424
|
-
`,${JSON.stringify(
|
|
1425
|
-
dirname(id) === '.' ? null /* default behavior */ : virtualDynamicRequirePath
|
|
1426
|
-
)}`
|
|
1427
|
-
);
|
|
1428
1493
|
replacedDynamicRequires.push(requireNode);
|
|
1429
1494
|
return;
|
|
1430
1495
|
}
|
|
@@ -1439,12 +1504,6 @@ async function transformCommonjs(
|
|
|
1439
1504
|
if (hasDynamicArguments(node)) {
|
|
1440
1505
|
if (isDynamicRequireModulesEnabled) {
|
|
1441
1506
|
checkDynamicRequire(node.start);
|
|
1442
|
-
magicString.appendLeft(
|
|
1443
|
-
node.end - 1,
|
|
1444
|
-
`, ${JSON.stringify(
|
|
1445
|
-
dirname(id) === '.' ? null /* default behavior */ : virtualDynamicRequirePath
|
|
1446
|
-
)}`
|
|
1447
|
-
);
|
|
1448
1507
|
}
|
|
1449
1508
|
if (!ignoreDynamicRequires) {
|
|
1450
1509
|
replacedDynamicRequires.push(node.callee);
|
|
@@ -1618,7 +1677,13 @@ async function transformCommonjs(
|
|
|
1618
1677
|
const requireName = deconflict([scope], globals, `require${capitalize(nameBase)}`);
|
|
1619
1678
|
const isRequiredName = deconflict([scope], globals, `hasRequired${capitalize(nameBase)}`);
|
|
1620
1679
|
const helpersName = deconflict([scope], globals, 'commonjsHelpers');
|
|
1621
|
-
const dynamicRequireName =
|
|
1680
|
+
const dynamicRequireName =
|
|
1681
|
+
replacedDynamicRequires.length > 0 &&
|
|
1682
|
+
deconflict(
|
|
1683
|
+
[scope],
|
|
1684
|
+
globals,
|
|
1685
|
+
isDynamicRequireModulesEnabled ? CREATE_COMMONJS_REQUIRE_EXPORT : COMMONJS_REQUIRE_EXPORT
|
|
1686
|
+
);
|
|
1622
1687
|
const deconflictedExportNames = Object.create(null);
|
|
1623
1688
|
for (const [exportName, { scopes }] of exportsAssignmentsByName) {
|
|
1624
1689
|
deconflictedExportNames[exportName] = deconflict([...scopes], globals, exportName);
|
|
@@ -1630,10 +1695,17 @@ async function transformCommonjs(
|
|
|
1630
1695
|
});
|
|
1631
1696
|
}
|
|
1632
1697
|
for (const node of replacedDynamicRequires) {
|
|
1633
|
-
magicString.overwrite(
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1698
|
+
magicString.overwrite(
|
|
1699
|
+
node.start,
|
|
1700
|
+
node.end,
|
|
1701
|
+
isDynamicRequireModulesEnabled
|
|
1702
|
+
? `${dynamicRequireName}(${JSON.stringify(virtualDynamicRequirePath)})`
|
|
1703
|
+
: dynamicRequireName,
|
|
1704
|
+
{
|
|
1705
|
+
contentOnly: true,
|
|
1706
|
+
storeName: true
|
|
1707
|
+
}
|
|
1708
|
+
);
|
|
1637
1709
|
}
|
|
1638
1710
|
|
|
1639
1711
|
// We cannot wrap ES/mixed modules
|
|
@@ -1653,7 +1725,7 @@ async function transformCommonjs(
|
|
|
1653
1725
|
) &&
|
|
1654
1726
|
(ignoreGlobal || !uses.global)
|
|
1655
1727
|
) {
|
|
1656
|
-
return { meta: { commonjs: { isCommonJS: false
|
|
1728
|
+
return { meta: { commonjs: { isCommonJS: false } } };
|
|
1657
1729
|
}
|
|
1658
1730
|
|
|
1659
1731
|
let leadingComment = '';
|
|
@@ -1675,7 +1747,7 @@ async function transformCommonjs(
|
|
|
1675
1747
|
? 'exports'
|
|
1676
1748
|
: 'module';
|
|
1677
1749
|
|
|
1678
|
-
const
|
|
1750
|
+
const importBlock = await rewriteRequireExpressionsAndGetImportBlock(
|
|
1679
1751
|
magicString,
|
|
1680
1752
|
topLevelDeclarations,
|
|
1681
1753
|
reassignedNames,
|
|
@@ -1685,12 +1757,14 @@ async function transformCommonjs(
|
|
|
1685
1757
|
exportsName,
|
|
1686
1758
|
id,
|
|
1687
1759
|
exportMode,
|
|
1688
|
-
|
|
1760
|
+
resolveRequireSourcesAndUpdateMeta,
|
|
1689
1761
|
needsRequireWrapper,
|
|
1690
1762
|
isEsModule,
|
|
1691
|
-
|
|
1692
|
-
getIgnoreTryCatchRequireStatementMode
|
|
1763
|
+
isDynamicRequireModulesEnabled,
|
|
1764
|
+
getIgnoreTryCatchRequireStatementMode,
|
|
1765
|
+
commonjsMeta
|
|
1693
1766
|
);
|
|
1767
|
+
const usesRequireWrapper = commonjsMeta.isCommonJS === IS_WRAPPED_COMMONJS;
|
|
1694
1768
|
const exportBlock = isEsModule
|
|
1695
1769
|
? ''
|
|
1696
1770
|
: rewriteExportsAndGetExportsBlock(
|
|
@@ -1743,12 +1817,7 @@ function ${requireName} () {
|
|
|
1743
1817
|
code: magicString.toString(),
|
|
1744
1818
|
map: sourceMap ? magicString.generateMap() : null,
|
|
1745
1819
|
syntheticNamedExports: isEsModule || usesRequireWrapper ? false : '__moduleExports',
|
|
1746
|
-
meta: {
|
|
1747
|
-
commonjs: {
|
|
1748
|
-
isCommonJS: !isEsModule && (usesRequireWrapper ? IS_WRAPPED_COMMONJS : true),
|
|
1749
|
-
isMixedModule: isEsModule
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1820
|
+
meta: { commonjs: commonjsMeta }
|
|
1752
1821
|
};
|
|
1753
1822
|
}
|
|
1754
1823
|
|
|
@@ -1779,11 +1848,6 @@ function commonjs(options = {}) {
|
|
|
1779
1848
|
const defaultIsModuleExports =
|
|
1780
1849
|
typeof options.defaultIsModuleExports === 'boolean' ? options.defaultIsModuleExports : 'auto';
|
|
1781
1850
|
|
|
1782
|
-
const {
|
|
1783
|
-
resolveRequireSourcesAndGetMeta,
|
|
1784
|
-
getWrappedIds,
|
|
1785
|
-
isRequiredId
|
|
1786
|
-
} = getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndConditional);
|
|
1787
1851
|
const dynamicRequireRoot =
|
|
1788
1852
|
typeof options.dynamicRequireRoot === 'string'
|
|
1789
1853
|
? resolve(options.dynamicRequireRoot)
|
|
@@ -1794,9 +1858,6 @@ function commonjs(options = {}) {
|
|
|
1794
1858
|
);
|
|
1795
1859
|
const isDynamicRequireModulesEnabled = dynamicRequireModules.size > 0;
|
|
1796
1860
|
|
|
1797
|
-
const esModulesWithDefaultExport = new Set();
|
|
1798
|
-
const esModulesWithNamedExports = new Set();
|
|
1799
|
-
|
|
1800
1861
|
const ignoreRequire =
|
|
1801
1862
|
typeof options.ignore === 'function'
|
|
1802
1863
|
? options.ignore
|
|
@@ -1824,25 +1885,31 @@ function commonjs(options = {}) {
|
|
|
1824
1885
|
|
|
1825
1886
|
const sourceMap = options.sourceMap !== false;
|
|
1826
1887
|
|
|
1888
|
+
// Initialized in buildStart
|
|
1889
|
+
let requireResolver;
|
|
1890
|
+
|
|
1827
1891
|
function transformAndCheckExports(code, id) {
|
|
1828
1892
|
const { isEsModule, hasDefaultExport, hasNamedExports, ast } = analyzeTopLevelStatements(
|
|
1829
1893
|
this.parse,
|
|
1830
1894
|
code,
|
|
1831
1895
|
id
|
|
1832
1896
|
);
|
|
1897
|
+
|
|
1898
|
+
const commonjsMeta = this.getModuleInfo(id).meta.commonjs || {};
|
|
1833
1899
|
if (hasDefaultExport) {
|
|
1834
|
-
|
|
1900
|
+
commonjsMeta.hasDefaultExport = true;
|
|
1835
1901
|
}
|
|
1836
1902
|
if (hasNamedExports) {
|
|
1837
|
-
|
|
1903
|
+
commonjsMeta.hasNamedExports = true;
|
|
1838
1904
|
}
|
|
1839
1905
|
|
|
1840
1906
|
if (
|
|
1841
1907
|
!dynamicRequireModules.has(normalizePathSlashes(id)) &&
|
|
1842
|
-
(!(hasCjsKeywords(code, ignoreGlobal) || isRequiredId(id)) ||
|
|
1908
|
+
(!(hasCjsKeywords(code, ignoreGlobal) || requireResolver.isRequiredId(id)) ||
|
|
1843
1909
|
(isEsModule && !options.transformMixedEsModules))
|
|
1844
1910
|
) {
|
|
1845
|
-
|
|
1911
|
+
commonjsMeta.isCommonJS = false;
|
|
1912
|
+
return { meta: { commonjs: commonjsMeta } };
|
|
1846
1913
|
}
|
|
1847
1914
|
|
|
1848
1915
|
const needsRequireWrapper =
|
|
@@ -1881,9 +1948,10 @@ function commonjs(options = {}) {
|
|
|
1881
1948
|
ast,
|
|
1882
1949
|
defaultIsModuleExports,
|
|
1883
1950
|
needsRequireWrapper,
|
|
1884
|
-
|
|
1885
|
-
isRequiredId(id),
|
|
1886
|
-
checkDynamicRequire
|
|
1951
|
+
requireResolver.resolveRequireSourcesAndUpdateMeta(this),
|
|
1952
|
+
requireResolver.isRequiredId(id),
|
|
1953
|
+
checkDynamicRequire,
|
|
1954
|
+
commonjsMeta
|
|
1887
1955
|
);
|
|
1888
1956
|
}
|
|
1889
1957
|
|
|
@@ -1907,18 +1975,23 @@ function commonjs(options = {}) {
|
|
|
1907
1975
|
return { ...rawOptions, plugins };
|
|
1908
1976
|
},
|
|
1909
1977
|
|
|
1910
|
-
buildStart() {
|
|
1911
|
-
|
|
1978
|
+
buildStart({ plugins }) {
|
|
1979
|
+
validateVersion(this.meta.rollupVersion, peerDependencies.rollup, 'rollup');
|
|
1980
|
+
const nodeResolve = plugins.find(({ name }) => name === 'node-resolve');
|
|
1981
|
+
if (nodeResolve) {
|
|
1982
|
+
validateVersion(nodeResolve.version, '^13.0.6', '@rollup/plugin-node-resolve');
|
|
1983
|
+
}
|
|
1912
1984
|
if (options.namedExports != null) {
|
|
1913
1985
|
this.warn(
|
|
1914
1986
|
'The namedExports option from "@rollup/plugin-commonjs" is deprecated. Named exports are now handled automatically.'
|
|
1915
1987
|
);
|
|
1916
1988
|
}
|
|
1989
|
+
requireResolver = getRequireResolver(extensions, detectCyclesAndConditional);
|
|
1917
1990
|
},
|
|
1918
1991
|
|
|
1919
1992
|
buildEnd() {
|
|
1920
1993
|
if (options.strictRequires === 'debug') {
|
|
1921
|
-
const wrappedIds = getWrappedIds();
|
|
1994
|
+
const wrappedIds = requireResolver.getWrappedIds();
|
|
1922
1995
|
if (wrappedIds.length) {
|
|
1923
1996
|
this.warn({
|
|
1924
1997
|
code: 'WRAPPED_IDS',
|
|
@@ -1967,6 +2040,11 @@ function commonjs(options = {}) {
|
|
|
1967
2040
|
);
|
|
1968
2041
|
}
|
|
1969
2042
|
|
|
2043
|
+
// entry suffix is just appended to not mess up relative external resolution
|
|
2044
|
+
if (id.endsWith(ENTRY_SUFFIX)) {
|
|
2045
|
+
return getEntryProxy(id.slice(0, -ENTRY_SUFFIX.length), defaultIsModuleExports, this.load);
|
|
2046
|
+
}
|
|
2047
|
+
|
|
1970
2048
|
if (isWrappedId(id, ES_IMPORT_SUFFIX)) {
|
|
1971
2049
|
return getEsImportProxy(unwrapId(id, ES_IMPORT_SUFFIX), defaultIsModuleExports);
|
|
1972
2050
|
}
|
|
@@ -1982,18 +2060,16 @@ function commonjs(options = {}) {
|
|
|
1982
2060
|
|
|
1983
2061
|
if (isWrappedId(id, PROXY_SUFFIX)) {
|
|
1984
2062
|
const actualId = unwrapId(id, PROXY_SUFFIX);
|
|
1985
|
-
return getStaticRequireProxy(
|
|
1986
|
-
actualId,
|
|
1987
|
-
getRequireReturnsDefault(actualId),
|
|
1988
|
-
esModulesWithDefaultExport,
|
|
1989
|
-
esModulesWithNamedExports,
|
|
1990
|
-
this.load
|
|
1991
|
-
);
|
|
2063
|
+
return getStaticRequireProxy(actualId, getRequireReturnsDefault(actualId), this.load);
|
|
1992
2064
|
}
|
|
1993
2065
|
|
|
1994
2066
|
return null;
|
|
1995
2067
|
},
|
|
1996
2068
|
|
|
2069
|
+
shouldTransformCachedModule(...args) {
|
|
2070
|
+
return requireResolver.shouldTransformCachedModule.call(this, ...args);
|
|
2071
|
+
},
|
|
2072
|
+
|
|
1997
2073
|
transform(code, id) {
|
|
1998
2074
|
const extName = extname(id);
|
|
1999
2075
|
if (extName !== '.cjs' && (!filter(id) || !extensions.includes(extName))) {
|
|
@@ -2010,4 +2086,4 @@ function commonjs(options = {}) {
|
|
|
2010
2086
|
}
|
|
2011
2087
|
|
|
2012
2088
|
export { commonjs as default };
|
|
2013
|
-
//# sourceMappingURL=index.
|
|
2089
|
+
//# sourceMappingURL=index.js.map
|