Skip to content

Commit

Permalink
Remove warning when using implicit default export mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 30, 2022
1 parent e0bdf9c commit d27724e
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 40 deletions.
2 changes: 0 additions & 2 deletions docs/999-big-list-of-options.md
Expand Up @@ -1466,8 +1466,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
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
15 changes: 0 additions & 15 deletions test/function/samples/warn-implicit-cjs-auto/_config.js

This file was deleted.

1 change: 0 additions & 1 deletion test/function/samples/warn-implicit-cjs-auto/main.js

This file was deleted.

0 comments on commit d27724e

Please sign in to comment.