Skip to content

Commit

Permalink
fix(next): respect extends in tsconfig with exclude and include
Browse files Browse the repository at this point in the history
  • Loading branch information
calmonr committed Aug 27, 2020
1 parent f658b76 commit 2b46dba
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/next/lib/typescript/writeConfigurationDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ export async function writeConfigurationDefaults(
}

const desiredCompilerOptions = getDesiredCompilerOptions(ts)
const effectiveConfiguration = await getTypeScriptConfiguration(
ts,
tsConfigPath
)
const {
options: tsOptions,
raw: rawConfig,
} = await getTypeScriptConfiguration(ts, tsConfigPath)

const userTsConfigContent = await fs.readFile(tsConfigPath, {
encoding: 'utf8',
})
const userTsConfig = CommentJson.parse(userTsConfigContent)
if (userTsConfig.compilerOptions == null) {
if (userTsConfig.compilerOptions == null && !('extends' in rawConfig)) {
userTsConfig.compilerOptions = {}
isFirstTimeSetup = true
}
Expand All @@ -114,14 +114,14 @@ export async function writeConfigurationDefaults(
for (const optionKey of Object.keys(desiredCompilerOptions)) {
const check = desiredCompilerOptions[optionKey]
if ('suggested' in check) {
if (!(optionKey in effectiveConfiguration.options)) {
if (!(optionKey in tsOptions)) {
userTsConfig.compilerOptions[optionKey] = check.suggested
suggestedActions.push(
chalk.cyan(optionKey) + ' was set to ' + chalk.bold(check.suggested)
)
}
} else if ('value' in check) {
const ev = effectiveConfiguration.options[optionKey]
const ev = tsOptions[optionKey]
if (
!('parsedValues' in check
? check.parsedValues?.includes(ev)
Expand All @@ -143,7 +143,7 @@ export async function writeConfigurationDefaults(
}
}

if (userTsConfig.include == null) {
if (!('include' in rawConfig)) {
userTsConfig.include = ['next-env.d.ts', '**/*.ts', '**/*.tsx']
suggestedActions.push(
chalk.cyan('include') +
Expand All @@ -152,7 +152,7 @@ export async function writeConfigurationDefaults(
)
}

if (userTsConfig.exclude == null) {
if (!('exclude' in rawConfig)) {
userTsConfig.exclude = ['node_modules']
suggestedActions.push(
chalk.cyan('exclude') + ' was set to ' + chalk.bold(`['node_modules']`)
Expand Down

0 comments on commit 2b46dba

Please sign in to comment.