Skip to content

Commit

Permalink
[v3.0] Remove warning when using implicit default export mode (#4624)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Sep 6, 2022
1 parent 37af402 commit 52250a3
Show file tree
Hide file tree
Showing 10 changed files with 3,210 additions and 3,163 deletions.
2 changes: 0 additions & 2 deletions docs/999-big-list-of-options.md
Expand Up @@ -1483,8 +1483,6 @@ Note: There are some tools such as Babel, TypeScript, Webpack, and `@rollup/plug
In other words for those tools, you cannot create a package interface where `const lib = require("your-lib")` yields the same as `import lib from "your-lib"`. With named export mode however, `const {lib} = require("your-lib")` will be equivalent to `import {lib} from "your-lib"`.
To alert you to this, Rollup will generate a warning when you encounter such a situation and did not select an explicit value for `output.exports`.
#### output.externalLiveBindings
Type: `boolean`<br> CLI: `--externalLiveBindings`/`--no-externalLiveBindings`<br> Default: `true`
Expand Down
2,142 changes: 965 additions & 1,177 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Expand Up @@ -57,29 +57,29 @@
"devDependencies": {
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-typescript": "^8.3.3",
"@rollup/plugin-typescript": "^8.4.0",
"@rollup/pluginutils": "^4.2.1",
"@types/estree": "0.0.52",
"@types/node": "^14.18.21",
"@types/estree": "1.0.0",
"@types/node": "^14.18.26",
"@types/signal-exit": "^3.0.1",
"@types/yargs-parser": "^21.0.0",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"acorn": "^8.7.1",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"acorn": "^8.8.0",
"acorn-jsx": "^5.3.2",
"acorn-walk": "^8.2.0",
"buble": "^0.20.0",
"chokidar": "^3.5.3",
"colorette": "^2.0.19",
"core-js": "^3.23.5",
"core-js": "^3.25.0",
"date-time": "^4.0.0",
"es5-shim": "^4.6.7",
"es6-shim": "^0.35.6",
"eslint": "^8.20.0",
"eslint": "^8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
Expand All @@ -88,18 +88,18 @@
"github-api": "^3.4.0",
"hash.js": "^1.1.7",
"husky": "^8.0.1",
"inquirer": "^9.0.2",
"inquirer": "^9.1.0",
"is-reference": "^3.0.0",
"lint-staged": "^13.0.3",
"locate-character": "^2.0.5",
"magic-string": "^0.26.2",
"magic-string": "^0.26.3",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"pretty-bytes": "^6.0.0",
"pretty-ms": "^8.0.0",
"requirejs": "^2.3.6",
"rollup": "^2.77.0",
"rollup": "^2.79.0",
"rollup-plugin-license": "^2.8.1",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
Expand All @@ -110,12 +110,12 @@
"source-map": "^0.7.4",
"source-map-support": "^0.5.21",
"sourcemap-codec": "^1.4.8",
"systemjs": "^6.12.1",
"terser": "^5.14.2",
"systemjs": "^6.12.4",
"terser": "^5.15.0",
"tslib": "^2.4.0",
"typescript": "^4.7.4",
"typescript": "^4.8.2",
"weak-napi": "^2.0.2",
"yargs-parser": "^21.0.1"
"yargs-parser": "^21.1.1"
},
"files": [
"dist/**/*.js",
Expand Down
1 change: 0 additions & 1 deletion src/Chunk.ts
Expand Up @@ -332,7 +332,6 @@ export default class Chunk {
this.exportMode = getExportMode(
this,
this.outputOptions,
this.unsetOptions,
this.facadeModule!.id,
this.inputOptions.onwarn
);
Expand Down
11 changes: 0 additions & 11 deletions src/utils/error.ts
Expand Up @@ -95,7 +95,6 @@ const ADDON_ERROR = 'ADDON_ERROR',
ONLY_INLINE_SOURCEMAPS = 'ONLY_INLINE_SOURCEMAPS',
PARSE_ERROR = 'PARSE_ERROR',
PLUGIN_ERROR = 'PLUGIN_ERROR',
PREFER_NAMED_EXPORTS = 'PREFER_NAMED_EXPORTS',
SHIMMED_EXPORT = 'SHIMMED_EXPORT',
SOURCEMAP_BROKEN = 'SOURCEMAP_BROKEN',
SOURCEMAP_ERROR = 'SOURCEMAP_ERROR',
Expand Down Expand Up @@ -710,16 +709,6 @@ export function errPluginError(
return error;
}

export function errPreferNamedExports(facadeModuleId: string): RollupLog {
const file = relativeId(facadeModuleId);
return {
code: PREFER_NAMED_EXPORTS,
id: facadeModuleId,
message: `Entry module "${file}" is implicitly using "default" export mode, which means for CommonJS output that its default export is assigned to "module.exports". For many tools, such CommonJS output will not be interchangeable with the original ES module. If this is intended, explicitly set "output.exports" to either "auto" or "default", otherwise you might want to consider changing the signature of "${file}" to use named exports only.`,
url: `https://rollupjs.org/guide/en/#outputexports`
};
}

export function errShimmedExport(id: string, binding: string): RollupLog {
return {
binding,
Expand Down
11 changes: 1 addition & 10 deletions src/utils/getExportMode.ts
@@ -1,16 +1,10 @@
import type Chunk from '../Chunk';
import type { NormalizedOutputOptions, WarningHandler } from '../rollup/types';
import {
errIncompatibleExportOptionValue,
errMixedExport,
error,
errPreferNamedExports
} from './error';
import { errIncompatibleExportOptionValue, errMixedExport, error } from './error';

export default function getExportMode(
chunk: Chunk,
{ exports: exportMode, name, format }: NormalizedOutputOptions,
unsetOptions: ReadonlySet<string>,
facadeModuleId: string,
warn: WarningHandler
): 'default' | 'named' | 'none' {
Expand All @@ -28,9 +22,6 @@ export default function getExportMode(
if (exportKeys.length === 0) {
exportMode = 'none';
} else if (exportKeys.length === 1 && exportKeys[0] === 'default') {
if (format === 'cjs' && unsetOptions.has('exports')) {
warn(errPreferNamedExports(facadeModuleId));
}
exportMode = 'default';
} else {
if (format !== 'es' && format !== 'system' && exportKeys.includes('default')) {
Expand Down
8 changes: 4 additions & 4 deletions test/form/samples/amd-keep-extension/_expected/system.js
Expand Up @@ -3,13 +3,13 @@ System.register(['./relative', 'abso/lute', './relative.js', 'abso/lute.js'], (f
var relative, absolute, relativeExtension, absoluteExtension;
return {
setters: [function (module) {
relative = module["default"];
relative = module.default;
}, function (module) {
absolute = module["default"];
absolute = module.default;
}, function (module) {
relativeExtension = module["default"];
relativeExtension = module.default;
}, function (module) {
absoluteExtension = module["default"];
absoluteExtension = module.default;
}],
execute: (function () {

Expand Down

0 comments on commit 52250a3

Please sign in to comment.