Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix): correctly read tsconfig esModuleInterop #555

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function createRollupConfig(
// (i.e. import * as namespaceImportObject from...) that are accessed dynamically.
freeze: false,
// Respect tsconfig esModuleInterop when setting __esModule.
esModule: tsCompilerOptions ? tsCompilerOptions.esModuleInterop : false,
esModule: Boolean(tsCompilerOptions?.esModuleInterop),
name: opts.name || safeVariableName(opts.name),
sourcemap: true,
globals: { react: 'React', 'react-native': 'ReactNative' },
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/build-withTsconfig/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"*": ["src/*", "node_modules/*"]
},
"jsx": "react",
"esModuleInterop": true
"esModuleInterop": false
},
"include": ["src", "types"], // test parsing of trailing comma & comment
}
13 changes: 13 additions & 0 deletions test/tests/tsdx-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('tsdx build', () => {

const lib = require(`../../${stageName}/dist`);
expect(lib.foo()).toBe('bar');
expect(lib.__esModule).toBe(true);
});

it('should clean the dist directory before rebuilding', () => {
Expand Down Expand Up @@ -123,6 +124,18 @@ describe('tsdx build', () => {
expect(output.code).toBe(0);
});

it('should set __esModule according to esModuleInterop in tsconfig', () => {
util.setupStageWithFixture(stageName, 'build-withTsconfig');

const output = shell.exec('node ../dist/index.js build --format cjs');

const lib = require(`../../${stageName}/dist/build-withtsconfig.cjs.production.min.js`);
// if esModuleInterop: false, no __esModule is added, therefore undefined
expect(lib.__esModule).toBe(undefined);

expect(output.code).toBe(0);
});

afterEach(() => {
util.teardownStage(stageName);
});
Expand Down