From 9991aae002c85188b5b19dc91304bbc43673aae7 Mon Sep 17 00:00:00 2001 From: Lars den Bakker Date: Wed, 22 Apr 2020 13:38:05 +0200 Subject: [PATCH] feat(commonjs): set syntheticNamedExports for commonjs modules (#149) BREAKING CHANGE: The namedExports option has been removed, now requires rollup >= 2.3.4. Instead of manually defining named exports, rollup now handles this automatically for you. * feat(commonjs): set syntheticNamedExports for commonjs modules * feat(commonjs): remove namedExports option * chore: merge with upstream * chore(commonjs): restrict rollup version * chore(commonjs): remove unused fixtures --- packages/commonjs/README.md | 41 ----- packages/commonjs/package.json | 4 +- packages/commonjs/src/index.js | 48 +----- packages/commonjs/src/transform.js | 8 +- packages/commonjs/test/fixtures/.eslintrc | 1 + .../test/fixtures/function/__esModule/main.js | 1 - .../named-exports-conditional/main.js | 3 + .../function/named-exports-conditional/x.js | 5 + .../function/named-exports-dynamic/_config.js | 5 + .../function/named-exports-dynamic/main.js | 7 + .../function/named-exports-dynamic/x.js | 3 + .../named-exports-object-define/main.js | 3 + .../function/named-exports-object-define/x.js | 6 + .../named-exports-reexport-default}/export.js | 0 .../named-exports-reexport-default}/main.js | 0 .../reexport.js | 0 .../named-exports-reexport-named/export.js | 1 + .../named-exports-reexport-named/main.js | 3 + .../named-exports-reexport-named/reexport.js | 3 + .../function/named-exports-unexported/main.js | 3 + .../function/named-exports-unexported/x.js | 1 + .../fixtures/function/reexports/_config.js | 9 - .../test/fixtures/function/reexports/bar.js | 1 - .../test/fixtures/function/reexports/foo.js | 1 - .../test/fixtures/function/reexports/main.js | 3 - .../main.js | 4 - .../main.js | 3 - .../other.js | 3 - .../main.js | 3 - .../samples/custom-named-exports/main.js | 6 - .../secret-named-exporter.js | 2 - .../fixtures/samples/define-property/foo.js | 6 - .../fixtures/samples/define-property/main.js | 1 - .../commonjs/test/snapshots/function.js.md | 154 +++++++++++++++--- .../commonjs/test/snapshots/function.js.snap | Bin 6808 -> 7178 bytes packages/commonjs/test/test.js | 148 ++--------------- packages/commonjs/test/types.ts | 1 - pnpm-lock.yaml | 66 +++++++- 38 files changed, 265 insertions(+), 292 deletions(-) create mode 100644 packages/commonjs/test/fixtures/function/named-exports-conditional/main.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-conditional/x.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-dynamic/_config.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-dynamic/main.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-dynamic/x.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-object-define/main.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-object-define/x.js rename packages/commonjs/test/fixtures/{samples/reexport => function/named-exports-reexport-default}/export.js (100%) rename packages/commonjs/test/fixtures/{samples/reexport => function/named-exports-reexport-default}/main.js (100%) rename packages/commonjs/test/fixtures/{samples/reexport => function/named-exports-reexport-default}/reexport.js (100%) create mode 100644 packages/commonjs/test/fixtures/function/named-exports-reexport-named/export.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-reexport-named/main.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-reexport-named/reexport.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-unexported/main.js create mode 100644 packages/commonjs/test/fixtures/function/named-exports-unexported/x.js delete mode 100644 packages/commonjs/test/fixtures/function/reexports/_config.js delete mode 100644 packages/commonjs/test/fixtures/function/reexports/bar.js delete mode 100644 packages/commonjs/test/fixtures/function/reexports/foo.js delete mode 100644 packages/commonjs/test/fixtures/function/reexports/main.js delete mode 100644 packages/commonjs/test/fixtures/samples/custom-named-exports-browser-shims/main.js delete mode 100644 packages/commonjs/test/fixtures/samples/custom-named-exports-false-positive/main.js delete mode 100644 packages/commonjs/test/fixtures/samples/custom-named-exports-false-positive/other.js delete mode 100644 packages/commonjs/test/fixtures/samples/custom-named-exports-warn-builtins/main.js delete mode 100644 packages/commonjs/test/fixtures/samples/custom-named-exports/main.js delete mode 100644 packages/commonjs/test/fixtures/samples/custom-named-exports/secret-named-exporter.js delete mode 100644 packages/commonjs/test/fixtures/samples/define-property/foo.js delete mode 100644 packages/commonjs/test/fixtures/samples/define-property/main.js 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 7d57a0ebda9e9bd972e095d2201e3d0e50db9dca..204228585062c2af2b18a0df7280a58147ca943a 100644 GIT binary patch delta 7025 zcmZ9KWgs1n8}BvKF-+GP=IEN~?(XjHIC40;Yw9rFOt;DDoH}Ya)7>07aew!|yZ`6q z=gsr2EWS7au!ODzt(L2WyO+Hih}MT26A9sLYu69_i{ag=n@ltHon8e^JO;x5JLEGH ztSm~I)^pYOO$^BZ;Y5tQhElsUe`_YX31y@xYa&l6emcNbV{F>r?7uJt+b+ma{;Bhl z%zGRTe=`DUlvvUW9eN}dW(*cJ)OrF*@f3(K3b-HRn|X(^sL1Vc-TBcU6-J>y!V@zM z&f=0Oa|>C{K1j|LyYK zDF>^0o8*Yt{Ya>K%VJUhKYH$jzI6u=qE@Wm4)pAlpo_3r9hW#Lbh=MGv_fjmg-;Wq zZX4Ivsk^#lS{p`m3ctZsN~ZUBQyKT`4G-%Kn(fjy$}kQFh4G34@V(MnQvNFE3Eks^ zk=8ADIdx`6X;R|ohW{Pg=bqa!qGW0hDEN@gpG*ty;#;XwK>ktw+g+F1OZgdmt<9R| zH6o#k#)L)Th$HC4OHDNvmx9ZCVFc29{~*F$-s@KaaCtiEpJ5Z(nmE*(SrOizdD8;- zB~;yS&?(@Fw$yof*dJdcQMB!Cwc`f)r2c2UPb)PkC;(R7eBitBy88XGuY0cv{LP!Y z{Pn6L72Z`}|A~Zx{X2iqN%wN`Xe|w$mE)R8DrgeOv3@A($Z(Tqa$I%@uS{+AUx^0_fvWwW8 z%utPrdaWAVQoOaAjx5aerI&8e)QZ)V`AtNsnECI9p5W=D88RG4m??ngPaw|uDK7;F)>f!#WoY?pE6{;3=mw6 zcv9cvxYo2|qnvk5VGmyB5~Kd|x;w1*yz4X?k-YIdB*a}VdSj$;Y^-VMzu)4^p8c|W z%(d40{I6g#E1=&h6?BhYb;?omwq_e7BH|SI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WuFuu1${na#ZQgai0}b}|kxZo7lJtoQa}B$TRk1(9$dND*IwX9!=# z^_>=FAJPBYf)seXcNj9$M1E!>j?6-c5)&_I<;SeIt&JP!D-+EuK$=Ns3i3FS@e(+3 z^kz@)O}Y|FA&F;S2P@I`w3YCiK4co-SiGIimi`)_PgL83z`E8^G6UZ?TEHkrT+}@l&HlAlTie^~ z#?oH0#Jq?O7llEu7+W(ra;R#q*#g1))FfL1-0T|($3yW#`ahom8i?AW0l_Ia@J?vF~eaMG7O(?6Tr1WwcGG_!SkjI(VIP6_nj8X-0vm@MTGa~n!Waqqx1{F zuYc80pMvqn)1r)-KaCQ!4FmNY(mCy_LJKQ+@yzT~vC^+pcXKmBS=y%x;&ixF@QUf% z*+ZA&Jbm)}*QD%~R^QbPcpo2cjB|V)TK#k5$0Y%I;aKx?v^?&zfkn$NTO2vBS9bD zH%h`4+Z8gIZyVXJ4{g8%Ta}h)E&g}`v92Q4EKz;alI1D`x*G} z=D4ZE&Ab-=eyFOqdy2a5LaQ(y$&=_ui8K|;G3!@_5K&B+#{YpvYTh4@1}++9l~1vB z{|mk9)*?+xOC7)se|UC4ufx9y+u+ oG`4mb`70b{^haKwYj}@Pr28vYI(U1K9Q{MaT;3x93m_u=4;94a!~g&Q 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