@rollup/plugin-commonjs 22.0.0-0 → 22.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.es.js +39 -12
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +39 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,9 +51,9 @@ When used together with the node-resolve plugin
|
|
|
51
51
|
Type: `"auto" | boolean | "debug" | string[]`<br>
|
|
52
52
|
Default: `"auto"`
|
|
53
53
|
|
|
54
|
-
By default, this plugin will try to hoist `require` statements as imports to the top of each file. While this works well for many code bases and allows for very efficient ESM output, it does not perfectly capture CommonJS semantics as the order of side effects
|
|
54
|
+
By default, this plugin will try to hoist `require` statements as imports to the top of each file. While this works well for many code bases and allows for very efficient ESM output, it does not perfectly capture CommonJS semantics as the initialisation order of required modules will be different. The resultant side effects can include log statements being emitted in a different order, and some code that is dependent on the initialisation order of polyfills in require statements may not work. But it is especially problematic when there are circular `require` calls between CommonJS modules as those often rely on the lazy execution of nested `require` calls.
|
|
55
55
|
|
|
56
|
-
Setting this option to `true` will wrap all CommonJS files in functions which are executed when they are required for the first time, preserving NodeJS semantics. Note that
|
|
56
|
+
Setting this option to `true` will wrap all CommonJS files in functions which are executed when they are required for the first time, preserving NodeJS semantics. This is the safest setting and should be used if the generated code does not work correctly with `"auto"`. Note that `strictRequires: true` can have a small impact on the size and performance of generated code, but less so if the code is minified.
|
|
57
57
|
|
|
58
58
|
The default value of `"auto"` will only wrap CommonJS files when they are part of a CommonJS dependency cycle, e.g. an index file that is required by some of its dependencies, or if they are only required in a potentially "conditional" way like from within an if-statement or a function. All other CommonJS files are hoisted. This is the recommended setting for most code bases. Note that the detection of conditional requires can be subject to race conditions if there are both conditional and unconditional requires of the same file, which in edge cases may result in inconsistencies between builds. If you think this is a problem for you, you can avoid this by using any value other than `"auto"` or `"debug"`.
|
|
59
59
|
|
package/dist/index.es.js
CHANGED
|
@@ -7,7 +7,7 @@ import { walk } from 'estree-walker';
|
|
|
7
7
|
import MagicString from 'magic-string';
|
|
8
8
|
import isReference from 'is-reference';
|
|
9
9
|
|
|
10
|
-
var version = "22.0.0-
|
|
10
|
+
var version = "22.0.0-1";
|
|
11
11
|
var peerDependencies = {
|
|
12
12
|
rollup: "^2.60.0"
|
|
13
13
|
};
|
|
@@ -478,6 +478,13 @@ function resolveExtensions(importee, importer, extensions) {
|
|
|
478
478
|
|
|
479
479
|
function getResolveId(extensions) {
|
|
480
480
|
return async function resolveId(importee, importer, resolveOptions) {
|
|
481
|
+
if (
|
|
482
|
+
resolveOptions.custom &&
|
|
483
|
+
resolveOptions.custom.commonjs &&
|
|
484
|
+
resolveOptions.custom.commonjs.skipResolver
|
|
485
|
+
) {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
481
488
|
if (isWrappedId(importee, WRAPPED_SUFFIX)) {
|
|
482
489
|
return unwrapId(importee, WRAPPED_SUFFIX);
|
|
483
490
|
}
|
|
@@ -497,7 +504,7 @@ function getResolveId(extensions) {
|
|
|
497
504
|
if (importer) {
|
|
498
505
|
if (
|
|
499
506
|
importer === DYNAMIC_MODULES_ID ||
|
|
500
|
-
//
|
|
507
|
+
// Proxies are only importing resolved ids, no need to resolve again
|
|
501
508
|
isWrappedId(importer, PROXY_SUFFIX) ||
|
|
502
509
|
isWrappedId(importer, ES_IMPORT_SUFFIX)
|
|
503
510
|
) {
|
|
@@ -546,9 +553,10 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
|
|
|
546
553
|
const knownCjsModuleTypes = Object.create(null);
|
|
547
554
|
const requiredIds = Object.create(null);
|
|
548
555
|
const unconditionallyRequiredIds = Object.create(null);
|
|
549
|
-
const
|
|
550
|
-
const
|
|
551
|
-
|
|
556
|
+
const parentModules = Object.create(null);
|
|
557
|
+
const childModules = Object.create(null);
|
|
558
|
+
const getParentModules = (id) => parentModules[id] || (parentModules[id] = Object.create(null));
|
|
559
|
+
const getChildModules = (id) => childModules[id] || (childModules[id] = Object.create(null));
|
|
552
560
|
|
|
553
561
|
return {
|
|
554
562
|
getWrappedIds: () =>
|
|
@@ -578,7 +586,8 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
|
|
|
578
586
|
const resolved =
|
|
579
587
|
(await rollupContext.resolve(source, parentId, {
|
|
580
588
|
custom: {
|
|
581
|
-
'node-resolve': { isRequire: true }
|
|
589
|
+
'node-resolve': { isRequire: true },
|
|
590
|
+
commonjs: { skipResolver: true }
|
|
582
591
|
}
|
|
583
592
|
})) || resolveExtensions(source, parentId, extensions);
|
|
584
593
|
if (!resolved) {
|
|
@@ -597,20 +606,38 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
|
|
|
597
606
|
) {
|
|
598
607
|
unconditionallyRequiredIds[childId] = true;
|
|
599
608
|
}
|
|
600
|
-
const parentDependentModules =
|
|
601
|
-
const childDependentModules =
|
|
602
|
-
|
|
609
|
+
const parentDependentModules = getParentModules(parentId);
|
|
610
|
+
const childDependentModules = getParentModules(childId);
|
|
611
|
+
|
|
612
|
+
// Copy the parents of the current parent to the child
|
|
603
613
|
for (const dependentId of Object.keys(parentDependentModules)) {
|
|
604
614
|
childDependentModules[dependentId] = true;
|
|
605
615
|
}
|
|
616
|
+
|
|
617
|
+
// Add the current parent to the child as well. If the child module already has known
|
|
618
|
+
// dependencies because it has already been loaded, add the current parent module to their
|
|
619
|
+
// parent modules
|
|
620
|
+
childDependentModules[parentId] = true;
|
|
621
|
+
const dependenciesToUpdate = new Set(Object.keys(getChildModules(childId)));
|
|
622
|
+
for (const dependencyId of dependenciesToUpdate) {
|
|
623
|
+
getParentModules(dependencyId)[parentId] = true;
|
|
624
|
+
for (const subDependencyId of Object.keys(getChildModules(dependencyId))) {
|
|
625
|
+
dependenciesToUpdate.add(subDependencyId);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Add the child as a dependency to the parent
|
|
630
|
+
getChildModules(parentId)[childId] = true;
|
|
631
|
+
|
|
632
|
+
// If we depend on one of our dependencies, we have a cycle. Then all modules that
|
|
633
|
+
// we depend on that also depend on the same module are part of a cycle as well. Trying
|
|
634
|
+
// to wait for loading this module would lead to a deadlock.
|
|
606
635
|
if (parentDependentModules[childId]) {
|
|
607
|
-
// If we depend on one of our dependencies, we have a cycle. Then all modules that
|
|
608
|
-
// we depend on that also depend on the same module are part of a cycle as well.
|
|
609
636
|
if (detectCyclesAndConditional && isParentCommonJS) {
|
|
610
637
|
knownCjsModuleTypes[parentId] = IS_WRAPPED_COMMONJS;
|
|
611
638
|
knownCjsModuleTypes[childId] = IS_WRAPPED_COMMONJS;
|
|
612
639
|
for (const dependentId of Object.keys(parentDependentModules)) {
|
|
613
|
-
if (
|
|
640
|
+
if (getParentModules(dependentId)[childId]) {
|
|
614
641
|
knownCjsModuleTypes[dependentId] = IS_WRAPPED_COMMONJS;
|
|
615
642
|
}
|
|
616
643
|
}
|