diff --git a/packages/commonjs/README.md b/packages/commonjs/README.md
index 6dfaeeec5..0d6f353a6 100644
--- a/packages/commonjs/README.md
+++ b/packages/commonjs/README.md
@@ -106,47 +106,6 @@ Default: `true`
If false, skips source map generation for CommonJS modules.
-### `namedExports`
-
-Type: `Object`
-Default: `null`
-
-Explicitly specify unresolvable named exports.
-
-This plugin will attempt to create named exports, where appropriate, so you can do this...
-
-```js
-// importer.js
-import { named } from './exporter.js';
-
-// exporter.js
-module.exports = { named: 42 }; // or `exports.named = 42;`
-```
-
-...but that's not always possible:
-
-```js
-// importer.js
-import { named } from 'my-lib';
-
-// my-lib.js
-var myLib = exports;
-myLib.named = "you can't see me";
-```
-
-In those cases, you can specify custom named exports:
-
-```js
-commonjs({
- namedExports: {
- // left-hand side can be an absolute path, a path
- // relative to the current directory, or the name
- // of a module in node_modules
- 'my-lib': ['named']
- }
-});
-```
-
### `ignore`
Type: `Array[...String | (String) => Boolean]`
diff --git a/packages/commonjs/package.json b/packages/commonjs/package.json
index b8c77451e..9f3dc0c8f 100644
--- a/packages/commonjs/package.json
+++ b/packages/commonjs/package.json
@@ -46,7 +46,7 @@
"require"
],
"peerDependencies": {
- "rollup": "^1.20.0||^2.0.0"
+ "rollup": "^2.3.4"
},
"dependencies": {
"@rollup/pluginutils": "^3.0.8",
@@ -67,7 +67,7 @@
"locate-character": "^2.0.5",
"prettier": "^1.19.1",
"require-relative": "^0.8.7",
- "rollup": "^2.0.0",
+ "rollup": "^2.3.4",
"rollup-plugin-babel": "^4.3.3",
"shx": "^0.3.2",
"source-map": "^0.6.1",
diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js
index 6556cbc02..d4f53ff75 100644
--- a/packages/commonjs/src/index.js
+++ b/packages/commonjs/src/index.js
@@ -1,7 +1,6 @@
-import { realpathSync, existsSync, readFileSync } from 'fs';
-import { extname, resolve, normalize, join } from 'path';
+import { existsSync, readFileSync } from 'fs';
+import { extname, join } from 'path';
-import { sync as nodeResolveSync, isCore } from 'resolve';
import { createFilter } from '@rollup/pluginutils';
import getCommonDir from 'commondir';
@@ -48,40 +47,6 @@ export default function commonjs(options = {}) {
? getCommonDir(null, Array.from(dynamicRequireModuleSet).concat(process.cwd()))
: null;
- const customNamedExports = {};
- if (options.namedExports) {
- Object.keys(options.namedExports).forEach((id) => {
- let resolveId = id;
- let resolvedId;
-
- if (isCore(id)) {
- // resolve will not find npm modules with the same name as
- // core modules without a trailing slash. Since core modules
- // must be external, we can assume any core modules defined
- // here are npm modules by that name.
- resolveId += '/';
- }
-
- try {
- resolvedId = nodeResolveSync(resolveId, { basedir: process.cwd() });
- } catch (err) {
- resolvedId = resolve(id);
- }
-
- // Note: customNamedExport's keys must be normalized file paths.
- // resolve and nodeResolveSync both return normalized file paths
- // so no additional normalization is necessary.
- customNamedExports[resolvedId] = options.namedExports[id];
-
- if (existsSync(resolvedId)) {
- const realpath = realpathSync(resolvedId);
- if (realpath !== resolvedId) {
- customNamedExports[realpath] = options.namedExports[id];
- }
- }
- });
- }
-
const esModulesWithoutDefaultExport = new Set();
const esModulesWithDefaultExport = new Set();
@@ -111,8 +76,6 @@ export default function commonjs(options = {}) {
return null;
}
- const normalizedId = normalize(id);
-
const transformed = transformCommonjs(
this.parse,
code,
@@ -121,7 +84,6 @@ export default function commonjs(options = {}) {
isEsModule,
ignoreGlobal || isEsModule,
ignoreRequire,
- customNamedExports[normalizedId],
sourceMap,
isDynamicRequireModulesEnabled,
dynamicRequireModuleSet,
@@ -143,6 +105,12 @@ export default function commonjs(options = {}) {
name: 'commonjs',
buildStart() {
+ if (options.namedExports != null) {
+ this.warn(
+ 'The namedExports option from "@rollup/plugin-commonjs" is deprecated. Named exports are now handled automatically.'
+ );
+ }
+
const [major, minor] = this.meta.rollupVersion.split('.').map(Number);
const minVersion = peerDependencies.rollup.slice(2);
const [minMajor, minMinor] = minVersion.split('.').map(Number);
diff --git a/packages/commonjs/src/transform.js b/packages/commonjs/src/transform.js
index 20e14f1e2..7209e765a 100644
--- a/packages/commonjs/src/transform.js
+++ b/packages/commonjs/src/transform.js
@@ -109,7 +109,6 @@ export function transformCommonjs(
isEsModule,
ignoreGlobal,
ignoreRequire,
- customNamedExports,
sourceMap,
isDynamicRequireModulesEnabled,
dynamicRequireModuleSet,
@@ -562,8 +561,6 @@ export function transformCommonjs(
});
}
- if (customNamedExports) customNamedExports.forEach(addExport);
-
const defaultExportPropertyAssignments = [];
let hasDefaultExport = false;
@@ -648,12 +645,13 @@ export function transformCommonjs(
.trim()
.append(wrapperEnd);
- if (hasDefaultExport || named.length > 0 || shouldWrap || (!isEntry && !isEsModule)) {
+ const injectExportBlock = hasDefaultExport || named.length > 0 || shouldWrap || !isEntry;
+ if (injectExportBlock) {
magicString.append(exportBlock);
}
code = magicString.toString();
const map = sourceMap ? magicString.generateMap() : null;
- return { code, map };
+ return { code, map, syntheticNamedExports: injectExportBlock };
}
diff --git a/packages/commonjs/test/fixtures/.eslintrc b/packages/commonjs/test/fixtures/.eslintrc
index 8cd798500..a280042d1 100644
--- a/packages/commonjs/test/fixtures/.eslintrc
+++ b/packages/commonjs/test/fixtures/.eslintrc
@@ -6,6 +6,7 @@
"func-names": "off",
"no-console": "off",
"no-undefined": "off",
+ "no-undef": "off",
"import/prefer-default-export": "off",
"import/extensions": "off",
"import/no-unresolved": "off",
diff --git a/packages/commonjs/test/fixtures/function/__esModule/main.js b/packages/commonjs/test/fixtures/function/__esModule/main.js
index be3be5c54..6ef314f3a 100644
--- a/packages/commonjs/test/fixtures/function/__esModule/main.js
+++ b/packages/commonjs/test/fixtures/function/__esModule/main.js
@@ -2,4 +2,3 @@ import * as x from './answer';
t.truthy('answer' in x);
t.truthy('default' in x);
-t.truthy(!('__esModule' in x));
diff --git a/packages/commonjs/test/fixtures/function/named-exports-conditional/main.js b/packages/commonjs/test/fixtures/function/named-exports-conditional/main.js
new file mode 100644
index 000000000..b469d5837
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-conditional/main.js
@@ -0,0 +1,3 @@
+import { named } from './x.js';
+
+t.is(named, 'foo');
diff --git a/packages/commonjs/test/fixtures/function/named-exports-conditional/x.js b/packages/commonjs/test/fixtures/function/named-exports-conditional/x.js
new file mode 100644
index 000000000..883fb344a
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-conditional/x.js
@@ -0,0 +1,5 @@
+if (typeof someUnknownGlobal !== 'undefined') {
+ module.exports = { named: 'bar' };
+} else {
+ module.exports = { named: 'foo' };
+}
diff --git a/packages/commonjs/test/fixtures/function/named-exports-dynamic/_config.js b/packages/commonjs/test/fixtures/function/named-exports-dynamic/_config.js
new file mode 100644
index 000000000..643cb9d34
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-dynamic/_config.js
@@ -0,0 +1,5 @@
+module.exports = {
+ context: {
+ window: {}
+ }
+};
diff --git a/packages/commonjs/test/fixtures/function/named-exports-dynamic/main.js b/packages/commonjs/test/fixtures/function/named-exports-dynamic/main.js
new file mode 100644
index 000000000..29659b582
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-dynamic/main.js
@@ -0,0 +1,7 @@
+import { named } from './x.js';
+
+t.is(named, undefined);
+
+window.addExport('named', 'foo');
+
+t.is(named, 'foo');
diff --git a/packages/commonjs/test/fixtures/function/named-exports-dynamic/x.js b/packages/commonjs/test/fixtures/function/named-exports-dynamic/x.js
new file mode 100644
index 000000000..0a84c7333
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-dynamic/x.js
@@ -0,0 +1,3 @@
+window.addExport = (key, value) => {
+ module.exports[key] = value;
+};
diff --git a/packages/commonjs/test/fixtures/function/named-exports-object-define/main.js b/packages/commonjs/test/fixtures/function/named-exports-object-define/main.js
new file mode 100644
index 000000000..b469d5837
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-object-define/main.js
@@ -0,0 +1,3 @@
+import { named } from './x.js';
+
+t.is(named, 'foo');
diff --git a/packages/commonjs/test/fixtures/function/named-exports-object-define/x.js b/packages/commonjs/test/fixtures/function/named-exports-object-define/x.js
new file mode 100644
index 000000000..c8dcd764b
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-object-define/x.js
@@ -0,0 +1,6 @@
+Object.defineProperty(module.exports, 'named', {
+ enumerable: true,
+ get: function get() {
+ return 'foo';
+ }
+});
diff --git a/packages/commonjs/test/fixtures/samples/reexport/export.js b/packages/commonjs/test/fixtures/function/named-exports-reexport-default/export.js
similarity index 100%
rename from packages/commonjs/test/fixtures/samples/reexport/export.js
rename to packages/commonjs/test/fixtures/function/named-exports-reexport-default/export.js
diff --git a/packages/commonjs/test/fixtures/samples/reexport/main.js b/packages/commonjs/test/fixtures/function/named-exports-reexport-default/main.js
similarity index 100%
rename from packages/commonjs/test/fixtures/samples/reexport/main.js
rename to packages/commonjs/test/fixtures/function/named-exports-reexport-default/main.js
diff --git a/packages/commonjs/test/fixtures/samples/reexport/reexport.js b/packages/commonjs/test/fixtures/function/named-exports-reexport-default/reexport.js
similarity index 100%
rename from packages/commonjs/test/fixtures/samples/reexport/reexport.js
rename to packages/commonjs/test/fixtures/function/named-exports-reexport-default/reexport.js
diff --git a/packages/commonjs/test/fixtures/function/named-exports-reexport-named/export.js b/packages/commonjs/test/fixtures/function/named-exports-reexport-named/export.js
new file mode 100644
index 000000000..5cb323723
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-reexport-named/export.js
@@ -0,0 +1 @@
+exports.named = 2;
diff --git a/packages/commonjs/test/fixtures/function/named-exports-reexport-named/main.js b/packages/commonjs/test/fixtures/function/named-exports-reexport-named/main.js
new file mode 100644
index 000000000..28abb9a60
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-reexport-named/main.js
@@ -0,0 +1,3 @@
+import { named } from './reexport.js';
+
+t.is(named, 2);
diff --git a/packages/commonjs/test/fixtures/function/named-exports-reexport-named/reexport.js b/packages/commonjs/test/fixtures/function/named-exports-reexport-named/reexport.js
new file mode 100644
index 000000000..ba56c12b5
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-reexport-named/reexport.js
@@ -0,0 +1,3 @@
+const myModule = require('./export.js');
+
+module.exports.named = myModule.named;
diff --git a/packages/commonjs/test/fixtures/function/named-exports-unexported/main.js b/packages/commonjs/test/fixtures/function/named-exports-unexported/main.js
new file mode 100644
index 000000000..8b713b667
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-unexported/main.js
@@ -0,0 +1,3 @@
+import { nonExisting } from './x.js';
+
+t.is(nonExisting, undefined);
diff --git a/packages/commonjs/test/fixtures/function/named-exports-unexported/x.js b/packages/commonjs/test/fixtures/function/named-exports-unexported/x.js
new file mode 100644
index 000000000..5cb323723
--- /dev/null
+++ b/packages/commonjs/test/fixtures/function/named-exports-unexported/x.js
@@ -0,0 +1 @@
+exports.named = 2;
diff --git a/packages/commonjs/test/fixtures/function/reexports/_config.js b/packages/commonjs/test/fixtures/function/reexports/_config.js
deleted file mode 100644
index ae2a6deec..000000000
--- a/packages/commonjs/test/fixtures/function/reexports/_config.js
+++ /dev/null
@@ -1,9 +0,0 @@
-const path = require('path');
-
-module.exports = {
- pluginOptions: {
- namedExports: {
- [path.resolve(__dirname, 'foo.js')]: ['named']
- }
- }
-};
diff --git a/packages/commonjs/test/fixtures/function/reexports/bar.js b/packages/commonjs/test/fixtures/function/reexports/bar.js
deleted file mode 100644
index cbf3e94a5..000000000
--- a/packages/commonjs/test/fixtures/function/reexports/bar.js
+++ /dev/null
@@ -1 +0,0 @@
-exports.named = 42;
diff --git a/packages/commonjs/test/fixtures/function/reexports/foo.js b/packages/commonjs/test/fixtures/function/reexports/foo.js
deleted file mode 100644
index 8cb411907..000000000
--- a/packages/commonjs/test/fixtures/function/reexports/foo.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = require('./bar.js');
diff --git a/packages/commonjs/test/fixtures/function/reexports/main.js b/packages/commonjs/test/fixtures/function/reexports/main.js
deleted file mode 100644
index 65d3053db..000000000
--- a/packages/commonjs/test/fixtures/function/reexports/main.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import { named } from './foo.js';
-
-t.is(named, 42);
diff --git a/packages/commonjs/test/fixtures/samples/custom-named-exports-browser-shims/main.js b/packages/commonjs/test/fixtures/samples/custom-named-exports-browser-shims/main.js
deleted file mode 100644
index e1783ae5a..000000000
--- a/packages/commonjs/test/fixtures/samples/custom-named-exports-browser-shims/main.js
+++ /dev/null
@@ -1,4 +0,0 @@
-import { message, foo } from 'events';
-
-t.is(message, 'this is not builtin');
-t.is(foo, 'this is a hidden export');
diff --git a/packages/commonjs/test/fixtures/samples/custom-named-exports-false-positive/main.js b/packages/commonjs/test/fixtures/samples/custom-named-exports-false-positive/main.js
deleted file mode 100644
index dc5314327..000000000
--- a/packages/commonjs/test/fixtures/samples/custom-named-exports-false-positive/main.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import { thing } from './other.js';
-
-t.is(thing, 'yes');
diff --git a/packages/commonjs/test/fixtures/samples/custom-named-exports-false-positive/other.js b/packages/commonjs/test/fixtures/samples/custom-named-exports-false-positive/other.js
deleted file mode 100644
index b559a9cc8..000000000
--- a/packages/commonjs/test/fixtures/samples/custom-named-exports-false-positive/other.js
+++ /dev/null
@@ -1,3 +0,0 @@
-/* require (https://github.com/rollup/rollup-plugin-commonjs/issues/36) */
-/* eslint-disable */
-export var thing = 'yes';
diff --git a/packages/commonjs/test/fixtures/samples/custom-named-exports-warn-builtins/main.js b/packages/commonjs/test/fixtures/samples/custom-named-exports-warn-builtins/main.js
deleted file mode 100644
index 6620ad1be..000000000
--- a/packages/commonjs/test/fixtures/samples/custom-named-exports-warn-builtins/main.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import { message } from 'events';
-
-t.is(message, 'this is not builtin');
diff --git a/packages/commonjs/test/fixtures/samples/custom-named-exports/main.js b/packages/commonjs/test/fixtures/samples/custom-named-exports/main.js
deleted file mode 100644
index 70db426d5..000000000
--- a/packages/commonjs/test/fixtures/samples/custom-named-exports/main.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import { message } from 'external';
-
-import { named } from './secret-named-exporter.js';
-
-t.is(named, 42);
-t.is(message, 'it works');
diff --git a/packages/commonjs/test/fixtures/samples/custom-named-exports/secret-named-exporter.js b/packages/commonjs/test/fixtures/samples/custom-named-exports/secret-named-exporter.js
deleted file mode 100644
index 275a85813..000000000
--- a/packages/commonjs/test/fixtures/samples/custom-named-exports/secret-named-exporter.js
+++ /dev/null
@@ -1,2 +0,0 @@
-const myLib = exports;
-myLib.named = 42;
diff --git a/packages/commonjs/test/fixtures/samples/define-property/foo.js b/packages/commonjs/test/fixtures/samples/define-property/foo.js
deleted file mode 100644
index 84086fe7a..000000000
--- a/packages/commonjs/test/fixtures/samples/define-property/foo.js
+++ /dev/null
@@ -1,6 +0,0 @@
-Object.defineProperty(exports, 'foo', {
- enumerable: true,
- get: function get() {
- return 'bar';
- }
-});
diff --git a/packages/commonjs/test/fixtures/samples/define-property/main.js b/packages/commonjs/test/fixtures/samples/define-property/main.js
deleted file mode 100644
index de89f2b76..000000000
--- a/packages/commonjs/test/fixtures/samples/define-property/main.js
+++ /dev/null
@@ -1 +0,0 @@
-export { foo } from './foo';
diff --git a/packages/commonjs/test/snapshots/function.js.md b/packages/commonjs/test/snapshots/function.js.md
index e6c6b5bf2..411acaaef 100644
--- a/packages/commonjs/test/snapshots/function.js.md
+++ b/packages/commonjs/test/snapshots/function.js.md
@@ -28,16 +28,14 @@ Generated by [AVA](https://ava.li).
var answer$1 = unwrapExports(answer);␊
var answer_1 = answer.answer;␊
␊
- var x = /*#__PURE__*/Object.freeze({␊
- __proto__: null,␊
+ var x = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null), answer$1, {␊
'default': answer$1,␊
__moduleExports: answer,␊
answer: answer_1␊
- });␊
+ }));␊
␊
t.truthy('answer' in x);␊
t.truthy('default' in x);␊
- t.truthy(!('__esModule' in x));␊
`,
}
@@ -2693,6 +2691,134 @@ Generated by [AVA](https://ava.li).
`,
}
+## named-exports-conditional
+
+> Snapshot 1
+
+ {
+ 'main.js': `'use strict';␊
+ ␊
+ function createCommonjsModule(fn, module) {␊
+ return module = { exports: {} }, fn(module, module.exports), module.exports;␊
+ }␊
+ ␊
+ var x = createCommonjsModule(function (module) {␊
+ if (typeof someUnknownGlobal !== 'undefined') {␊
+ module.exports = { named: 'bar' };␊
+ } else {␊
+ module.exports = { named: 'foo' };␊
+ }␊
+ });␊
+ var x_1 = x.named;␊
+ ␊
+ t.is(x_1, 'foo');␊
+ `,
+ }
+
+## named-exports-dynamic
+
+> Snapshot 1
+
+ {
+ 'main.js': `'use strict';␊
+ ␊
+ function createCommonjsModule(fn, module) {␊
+ return module = { exports: {} }, fn(module, module.exports), module.exports;␊
+ }␊
+ ␊
+ var x = createCommonjsModule(function (module) {␊
+ window.addExport = (key, value) => {␊
+ module.exports[key] = value;␊
+ };␊
+ });␊
+ ␊
+ t.is(x.named, undefined);␊
+ ␊
+ window.addExport('named', 'foo');␊
+ ␊
+ t.is(x.named, 'foo');␊
+ `,
+ }
+
+## named-exports-object-define
+
+> Snapshot 1
+
+ {
+ 'main.js': `'use strict';␊
+ ␊
+ function createCommonjsModule(fn, module) {␊
+ return module = { exports: {} }, fn(module, module.exports), module.exports;␊
+ }␊
+ ␊
+ var x = createCommonjsModule(function (module) {␊
+ Object.defineProperty(module.exports, 'named', {␊
+ enumerable: true,␊
+ get: function get() {␊
+ return 'foo';␊
+ }␊
+ });␊
+ });␊
+ ␊
+ t.is(x.named, 'foo');␊
+ `,
+ }
+
+## named-exports-reexport-default
+
+> Snapshot 1
+
+ {
+ 'main.js': `'use strict';␊
+ ␊
+ var named = 2;␊
+ ␊
+ var _export = {␊
+ named: named␊
+ };␊
+ ␊
+ var reexport = _export;␊
+ ␊
+ t.is(reexport.named, 2);␊
+ `,
+ }
+
+## named-exports-reexport-named
+
+> Snapshot 1
+
+ {
+ 'main.js': `'use strict';␊
+ ␊
+ var named = 2;␊
+ ␊
+ var _export = {␊
+ named: named␊
+ };␊
+ ␊
+ var named$1 = _export.named;␊
+ ␊
+ t.is(named$1, 2);␊
+ `,
+ }
+
+## named-exports-unexported
+
+> Snapshot 1
+
+ {
+ 'main.js': `'use strict';␊
+ ␊
+ var named = 2;␊
+ ␊
+ var x = {␊
+ named: named␊
+ };␊
+ ␊
+ t.is(x.nonExisting, undefined);␊
+ `,
+ }
+
## ordering
> Snapshot 1
@@ -2778,26 +2904,6 @@ Generated by [AVA](https://ava.li).
`,
}
-## reexports
-
-> Snapshot 1
-
- {
- 'main.js': `'use strict';␊
- ␊
- var named = 42;␊
- ␊
- var bar = {␊
- named: named␊
- };␊
- ␊
- var foo = bar;␊
- var foo_1 = foo.named;␊
- ␊
- t.is(foo_1, 42);␊
- `,
- }
-
## resolve-is-cjs-extension
> Snapshot 1
diff --git a/packages/commonjs/test/snapshots/function.js.snap b/packages/commonjs/test/snapshots/function.js.snap
index 7d57a0ebd..204228585 100644
Binary files a/packages/commonjs/test/snapshots/function.js.snap and b/packages/commonjs/test/snapshots/function.js.snap differ
diff --git a/packages/commonjs/test/test.js b/packages/commonjs/test/test.js
index 6dd9b8b8f..0eaea1db5 100644
--- a/packages/commonjs/test/test.js
+++ b/packages/commonjs/test/test.js
@@ -180,39 +180,6 @@ test('handles successive builds', async (t) => {
t.is(module.exports, 'foobar', code);
});
-test('allows named exports to be added explicitly via config', async (t) => {
- const bundle = await rollup({
- input: 'fixtures/samples/custom-named-exports/main.js',
- plugins: [
- resolve(),
- commonjs({
- namedExports: {
- 'fixtures/samples/custom-named-exports/secret-named-exporter.js': ['named'],
- external: ['message']
- }
- })
- ]
- });
-
- await t.notThrowsAsync(executeBundle(bundle, t));
-});
-
-test('handles warnings without error when resolving named exports', async (t) => {
- await t.notThrowsAsync(
- rollup({
- input: 'fixtures/samples/custom-named-exports-warn-builtins/main.js',
- plugins: [
- resolve(),
- commonjs({
- namedExports: {
- events: ['message']
- }
- })
- ]
- })
- );
-});
-
test.serial('handles symlinked node_modules with preserveSymlinks: false', (t) => {
const cwd = process.cwd();
@@ -233,11 +200,7 @@ test.serial('handles symlinked node_modules with preserveSymlinks: false', (t) =
preserveSymlinks: false,
preferBuiltins: false
}),
- commonjs({
- namedExports: {
- events: ['foo']
- }
- })
+ commonjs()
]
})
.then((v) => {
@@ -251,40 +214,6 @@ test.serial('handles symlinked node_modules with preserveSymlinks: false', (t) =
);
});
-test('handles named exports for built-in shims', async (t) => {
- const bundle = await rollup({
- input: 'fixtures/samples/custom-named-exports-browser-shims/main.js',
- plugins: [
- resolve({
- preferBuiltins: false
- }),
- commonjs({
- namedExports: {
- events: ['foo']
- }
- })
- ]
- });
-
- await t.notThrowsAsync(executeBundle(bundle, t));
-});
-
-test('ignores false positives with namedExports (#36)', async (t) => {
- const bundle = await rollup({
- input: 'fixtures/samples/custom-named-exports-false-positive/main.js',
- plugins: [
- resolve(),
- commonjs({
- namedExports: {
- irrelevant: ['lol']
- }
- })
- ]
- });
-
- await t.notThrowsAsync(executeBundle(bundle, t));
-});
-
test('converts a CommonJS module with custom file extension', async (t) => {
const bundle = await rollup({
input: 'fixtures/samples/extension/main.coffee',
@@ -395,30 +324,6 @@ test('does not process the entry file when it has a leading "." (issue #63)', as
await t.notThrowsAsync(executeBundle(bundle, t));
});
-test('does not reexport named contents', async (t) => {
- try {
- await rollup({
- input: 'fixtures/samples/reexport/main.js',
- plugins: [commonjs()]
- });
- } catch (error) {
- t.is(
- error.message,
- `'named' is not exported by fixtures${path.sep}samples${path.sep}reexport${path.sep}reexport.js, ` +
- `imported by fixtures${path.sep}samples${path.sep}reexport${path.sep}main.js`
- );
- }
-});
-
-test(`exports props defined by 'Object.defineProperty'`, async (t) => {
- const bundle = await rollup({
- input: 'fixtures/samples/define-property/main.js',
- plugins: [commonjs()]
- });
- const m = await executeBundle(bundle, t);
- t.is(m.exports.foo, 'bar');
-});
-
test('respects other plugins', async (t) => {
const bundle = await rollup({
input: 'fixtures/samples/other-transforms/main.js',
@@ -716,40 +621,6 @@ exports.shuffleArray = shuffleArray_1;
);
});
-test('normalizes paths used in the named export map', async (t) => {
- // Deliberately denormalizes file paths and ensures named exports
- // continue to work.
- function hookedResolve() {
- const resolvePlugin = resolve();
- const oldResolve = resolvePlugin.resolveId;
- resolvePlugin.resolveId = async (...args) => {
- const result = await oldResolve.apply(resolvePlugin, args);
- if (result) {
- result.id = result.id.replace(/\/|\\/, path.sep);
- }
-
- return result;
- };
-
- return resolvePlugin;
- }
-
- const bundle = await rollup({
- input: 'fixtures/samples/custom-named-exports/main.js',
- plugins: [
- hookedResolve(),
- commonjs({
- namedExports: {
- 'fixtures/samples/custom-named-exports/secret-named-exporter.js': ['named'],
- external: ['message']
- }
- })
- ]
- });
-
- await t.notThrowsAsync(executeBundle(bundle, t));
-});
-
test('can spread an object into module.exports', async (t) => {
const bundle = await rollup({
input: 'fixtures/samples/module-exports-spread/main.js',
@@ -758,3 +629,20 @@ test('can spread an object into module.exports', async (t) => {
const code = await getCodeFromBundle(bundle);
t.snapshot(code);
});
+
+test('logs a warning when the deprecated namedExports option is used', async (t) => {
+ let message;
+ const bundle = await rollup({
+ onwarn(warning) {
+ message = warning.message;
+ },
+ input: 'fixtures/samples/sourcemap/main.js',
+ plugins: [commonjs({ namedExports: { foo: ['bar'] } })]
+ });
+
+ await getCodeFromBundle(bundle);
+ t.is(
+ message,
+ 'The namedExports option from "@rollup/plugin-commonjs" is deprecated. Named exports are now handled automatically.'
+ );
+});
diff --git a/packages/commonjs/test/types.ts b/packages/commonjs/test/types.ts
index a34d1f43a..7a0b16eb8 100644
--- a/packages/commonjs/test/types.ts
+++ b/packages/commonjs/test/types.ts
@@ -13,7 +13,6 @@ const config: import('rollup').RollupOptions = {
extensions: ['.js', '.coffee'],
ignoreGlobal: false,
sourceMap: false,
- namedExports: { './module.js': ['foo', 'bar'] },
ignore: ['conditional-runtime-dependency'],
dynamicRequireTargets: ['node_modules/logform/*.js']
})
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index fb2929f02..1fdeb13b7 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -107,7 +107,7 @@ importers:
typescript: ^3.7.4
packages/commonjs:
dependencies:
- '@rollup/pluginutils': 3.0.8_rollup@2.2.0
+ '@rollup/pluginutils': 3.0.8_rollup@2.6.0
commondir: 1.0.1
estree-walker: 1.0.1
glob: 7.1.6
@@ -118,14 +118,14 @@ importers:
'@babel/core': 7.9.0
'@babel/preset-env': 7.9.0_@babel+core@7.9.0
'@babel/register': 7.9.0_@babel+core@7.9.0
- '@rollup/plugin-json': 4.0.2_rollup@2.2.0
- '@rollup/plugin-node-resolve': 7.1.1_rollup@2.2.0
+ '@rollup/plugin-json': 4.0.2_rollup@2.6.0
+ '@rollup/plugin-node-resolve': 7.1.1_rollup@2.6.0
acorn: 7.1.1
locate-character: 2.0.5
prettier: 1.19.1
require-relative: 0.8.7
- rollup: 2.2.0
- rollup-plugin-babel: 4.3.3_@babel+core@7.9.0+rollup@2.2.0
+ rollup: 2.6.0
+ rollup-plugin-babel: 4.3.3_@babel+core@7.9.0+rollup@2.6.0
shx: 0.3.2
source-map: 0.6.1
source-map-support: 0.5.16
@@ -147,7 +147,7 @@ importers:
prettier: ^1.19.1
require-relative: ^0.8.7
resolve: ^1.11.0
- rollup: ^2.0.0
+ rollup: ^2.3.4
rollup-plugin-babel: ^4.3.3
shx: ^0.3.2
source-map: ^0.6.1
@@ -1617,6 +1617,15 @@ packages:
rollup: ^1.20.0
resolution:
integrity: sha512-t4zJMc98BdH42mBuzjhQA7dKh0t4vMJlUka6Fz0c+iO5IVnWaEMiYBy1uBj9ruHZzXBW23IPDGL9oCzBkQ9Udg==
+ /@rollup/plugin-json/4.0.2_rollup@2.6.0:
+ dependencies:
+ '@rollup/pluginutils': 3.0.8_rollup@2.6.0
+ rollup: 2.6.0
+ dev: true
+ peerDependencies:
+ rollup: ^1.20.0
+ resolution:
+ integrity: sha512-t4zJMc98BdH42mBuzjhQA7dKh0t4vMJlUka6Fz0c+iO5IVnWaEMiYBy1uBj9ruHZzXBW23IPDGL9oCzBkQ9Udg==
/@rollup/plugin-node-resolve/7.1.1:
dependencies:
'@rollup/pluginutils': 3.0.8
@@ -1646,6 +1655,21 @@ packages:
rollup: ^1.20.0
resolution:
integrity: sha512-14ddhD7TnemeHE97a4rLOhobfYvUVcaYuqTnL8Ti7Jxi9V9Jr5LY7Gko4HZ5k4h4vqQM0gBQt6tsp9xXW94WPA==
+ /@rollup/plugin-node-resolve/7.1.1_rollup@2.6.0:
+ dependencies:
+ '@rollup/pluginutils': 3.0.8_rollup@2.6.0
+ '@types/resolve': 0.0.8
+ builtin-modules: 3.1.0
+ is-module: 1.0.0
+ resolve: 1.15.1
+ rollup: 2.6.0
+ dev: true
+ engines:
+ node: '>= 8.0.0'
+ peerDependencies:
+ rollup: ^1.20.0
+ resolution:
+ integrity: sha512-14ddhD7TnemeHE97a4rLOhobfYvUVcaYuqTnL8Ti7Jxi9V9Jr5LY7Gko4HZ5k4h4vqQM0gBQt6tsp9xXW94WPA==
/@rollup/plugin-typescript/3.0.0_b32f28c91b7d5afb3a4e5593fb670831:
dependencies:
'@rollup/pluginutils': 3.0.8_rollup@2.2.0
@@ -1724,6 +1748,16 @@ packages:
rollup: ^1.20.0
resolution:
integrity: sha512-rYGeAc4sxcZ+kPG/Tw4/fwJODC3IXHYDH4qusdN/b6aLw5LPUbzpecYbEJh4sVQGPFJxd2dBU4kc1H3oy9/bnw==
+ /@rollup/pluginutils/3.0.8_rollup@2.6.0:
+ dependencies:
+ estree-walker: 1.0.1
+ rollup: 2.6.0
+ engines:
+ node: '>= 8.0.0'
+ peerDependencies:
+ rollup: ^1.20.0
+ resolution:
+ integrity: sha512-rYGeAc4sxcZ+kPG/Tw4/fwJODC3IXHYDH4qusdN/b6aLw5LPUbzpecYbEJh4sVQGPFJxd2dBU4kc1H3oy9/bnw==
/@samverschueren/stream-to-observable/0.3.0:
dependencies:
any-observable: 0.3.0
@@ -6781,6 +6815,18 @@ packages:
rollup: '>=0.60.0 <2'
resolution:
integrity: sha512-tKzWOCmIJD/6aKNz0H1GMM+lW1q9KyFubbWzGiOG540zxPPifnEAHTZwjo0g991Y+DyOZcLqBgqOdqazYE5fkw==
+ /rollup-plugin-babel/4.3.3_@babel+core@7.9.0+rollup@2.6.0:
+ dependencies:
+ '@babel/core': 7.9.0
+ '@babel/helper-module-imports': 7.8.3
+ rollup: 2.6.0
+ rollup-pluginutils: 2.8.2
+ dev: true
+ peerDependencies:
+ '@babel/core': 7 || ^7.0.0-rc.2
+ rollup: '>=0.60.0 <2'
+ resolution:
+ integrity: sha512-tKzWOCmIJD/6aKNz0H1GMM+lW1q9KyFubbWzGiOG540zxPPifnEAHTZwjo0g991Y+DyOZcLqBgqOdqazYE5fkw==
/rollup-plugin-babel/4.4.0_@babel+core@7.9.0+rollup@2.2.0:
dependencies:
'@babel/core': 7.9.0
@@ -6842,6 +6888,14 @@ packages:
fsevents: 2.1.2
resolution:
integrity: sha512-iAu/j9/WJ0i+zT0sAMuQnsEbmOKzdQ4Yxu5rbPs9aUCyqveI1Kw3H4Fi9NWfCOpb8luEySD2lDyFWL9CrLE8iw==
+ /rollup/2.6.0:
+ engines:
+ node: '>=10.0.0'
+ hasBin: true
+ optionalDependencies:
+ fsevents: 2.1.2
+ resolution:
+ integrity: sha512-qbvQ9ZbvbhBdtRBZ/A4g+9z3iJQ1rHAtjinn3FiN+j5tfz8xiNyTE1JEEMcFWqlH7+NHadI9ieeqKdp8HwYLnQ==
/run-async/2.4.0:
dependencies:
is-promise: 2.1.0