Skip to content

Commit

Permalink
refactor(config): set default module CommonJS after resolving tscon…
Browse files Browse the repository at this point in the history
…fig (#2280)
  • Loading branch information
ahnpnl committed Jan 15, 2021
1 parent 8ba9d12 commit 067b653
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/config/config-set.spec.ts
Expand Up @@ -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', () => {
Expand Down
8 changes: 7 additions & 1 deletion src/config/config-set.ts
Expand Up @@ -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,
},
}
}

/**
Expand Down

0 comments on commit 067b653

Please sign in to comment.