Skip to content

Commit e9f8e2b

Browse files
agilgur5paul-vd
authored andcommitted
(fix): correctly read tsconfig esModuleInterop (jaredpalmer#555)
- it's a property of compilerOptions, not of overall tsconfig - i.e. tsconfig.compilerOptions.esModuleInterop - because this was incorrectly read, Rollup's esModule would always be set to `undefined`, and Rollup would then default to `true` - so esModuleInterop still wasn't being respected properly, I just shifted the defaults when I incorrectly patched this :/ (test): add tests for the default tsconfig as well as for when it's explicitly set to false
1 parent c9f7eb3 commit e9f8e2b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/createRollupConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export async function createRollupConfig(
9999
// (i.e. import * as namespaceImportObject from...) that are accessed dynamically.
100100
freeze: false,
101101
// Respect tsconfig esModuleInterop when setting __esModule.
102-
esModule: tsCompilerOptions ? tsCompilerOptions.esModuleInterop : false,
102+
esModule: Boolean(tsCompilerOptions?.esModuleInterop),
103103
name: opts.name || safeVariableName(opts.name),
104104
sourcemap: true,
105105
globals: { react: 'React', 'react-native': 'ReactNative' },

test/fixtures/build-withTsconfig/tsconfig.base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"*": ["src/*", "node_modules/*"]
2525
},
2626
"jsx": "react",
27-
"esModuleInterop": true
27+
"esModuleInterop": false
2828
},
2929
"include": ["src", "types"], // test parsing of trailing comma & comment
3030
}

test/tests/tsdx-build.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe('tsdx build', () => {
7878

7979
const lib = require(`../../${stageName}/dist`);
8080
expect(lib.foo()).toBe('bar');
81+
expect(lib.__esModule).toBe(true);
8182
});
8283

8384
it('should clean the dist directory before rebuilding', () => {
@@ -161,6 +162,18 @@ describe('tsdx build', () => {
161162
expect(output.code).toBe(0);
162163
});
163164

165+
it('should set __esModule according to esModuleInterop in tsconfig', () => {
166+
util.setupStageWithFixture(stageName, 'build-withTsconfig');
167+
168+
const output = shell.exec('node ../dist/index.js build --format cjs');
169+
170+
const lib = require(`../../${stageName}/dist/build-withtsconfig.cjs.production.min.js`);
171+
// if esModuleInterop: false, no __esModule is added, therefore undefined
172+
expect(lib.__esModule).toBe(undefined);
173+
174+
expect(output.code).toBe(0);
175+
});
176+
164177
afterEach(() => {
165178
util.teardownStage(stageName);
166179
});

0 commit comments

Comments
 (0)