Skip to content

Commit 067b653

Browse files
authored
refactor(config): set default module CommonJS after resolving tsconfig (#2280)
1 parent 8ba9d12 commit 067b653

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/config/config-set.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ describe('parsedTsConfig', () => {
4343
expect(get({ tsconfig: { target: 'esnext' } as any }).options.target).toBe(ts.ScriptTarget.ESNext)
4444
})
4545

46-
it('should fallback to ES2015 as default target when no target defined in tsconfig', () => {
47-
expect(get({ tsconfig: 'tsconfig.spec.json' }).options.target).toBe(ts.ScriptTarget.ES2015)
46+
it('should fallback to ES2015 as default target and CommonJS as default module when no target or module defined in tsconfig', () => {
47+
const compilerOptions = get({ tsconfig: 'tsconfig.spec.json' }).options
48+
49+
expect(compilerOptions.target).toBe(ts.ScriptTarget.ES2015)
50+
expect(compilerOptions.module).toBe(ts.ModuleKind.CommonJS)
4851
})
4952

5053
it('should override some options', () => {

src/config/config-set.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,13 @@ export class ConfigSet {
447447
this.logger.warn(message)
448448
}
449449

450-
return result
450+
return {
451+
...result,
452+
options: {
453+
...result.options,
454+
module: result.options.module ?? this.compilerModule.ModuleKind.CommonJS,
455+
},
456+
}
451457
}
452458

453459
/**

0 commit comments

Comments
 (0)