From 067b653a9ba28db17c9ceffa4fae51cff443a211 Mon Sep 17 00:00:00 2001 From: Ahn Date: Fri, 15 Jan 2021 15:47:37 +0100 Subject: [PATCH] refactor(config): set default module `CommonJS` after resolving tsconfig (#2280) --- src/config/config-set.spec.ts | 7 +++++-- src/config/config-set.ts | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index 53ecf34b0e..0c692491a6 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -43,8 +43,11 @@ describe('parsedTsConfig', () => { expect(get({ tsconfig: { target: 'esnext' } as any }).options.target).toBe(ts.ScriptTarget.ESNext) }) - it('should fallback to ES2015 as default target when no target defined in tsconfig', () => { - expect(get({ tsconfig: 'tsconfig.spec.json' }).options.target).toBe(ts.ScriptTarget.ES2015) + it('should fallback to ES2015 as default target and CommonJS as default module when no target or module defined in tsconfig', () => { + const compilerOptions = get({ tsconfig: 'tsconfig.spec.json' }).options + + expect(compilerOptions.target).toBe(ts.ScriptTarget.ES2015) + expect(compilerOptions.module).toBe(ts.ModuleKind.CommonJS) }) it('should override some options', () => { diff --git a/src/config/config-set.ts b/src/config/config-set.ts index 6e2fb59881..3684087422 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -447,7 +447,13 @@ export class ConfigSet { this.logger.warn(message) } - return result + return { + ...result, + options: { + ...result.options, + module: result.options.module ?? this.compilerModule.ModuleKind.CommonJS, + }, + } } /**