Unverified Commit 02c4ce1a authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

refactor: rename isAppDirEnabled to hasAppDir (#62837)

app dir is always "enabled", but not always exists. Rename to the proper
word to describe. Found this confusion while developing other fetaures

Closes NEXT-2691
parent 405933a0
......@@ -6,12 +6,12 @@ export async function writeAppTypeDeclarations({
baseDir,
imageImportsEnabled,
hasPagesDir,
isAppDirEnabled,
hasAppDir,
}: {
baseDir: string
imageImportsEnabled: boolean
hasPagesDir: boolean
isAppDirEnabled: boolean
hasAppDir: boolean
}): Promise<void> {
// Reference `next` types
const appTypeDeclarations = path.join(baseDir, 'next-env.d.ts')
......@@ -49,7 +49,7 @@ export async function writeAppTypeDeclarations({
directives.push('/// <reference types="next/image-types/global" />')
}
if (isAppDirEnabled && hasPagesDir) {
if (hasAppDir && hasPagesDir) {
directives.push(
'/// <reference types="next/navigation-types/compat/navigation" />'
)
......
......@@ -119,7 +119,7 @@ export async function writeConfigurationDefaults(
ts: typeof import('typescript'),
tsConfigPath: string,
isFirstTimeSetup: boolean,
isAppDirEnabled: boolean,
hasAppDir: boolean,
distDir: string,
hasPagesDir: boolean
): Promise<void> {
......@@ -184,19 +184,19 @@ export async function writeConfigurationDefaults(
const nextAppTypes = `${distDir}/types/**/*.ts`
if (!('include' in rawConfig)) {
userTsConfig.include = isAppDirEnabled
userTsConfig.include = hasAppDir
? ['next-env.d.ts', nextAppTypes, '**/*.ts', '**/*.tsx']
: ['next-env.d.ts', '**/*.ts', '**/*.tsx']
suggestedActions.push(
cyan('include') +
' was set to ' +
bold(
isAppDirEnabled
hasAppDir
? `['next-env.d.ts', '${nextAppTypes}', '**/*.ts', '**/*.tsx']`
: `['next-env.d.ts', '**/*.ts', '**/*.tsx']`
)
)
} else if (isAppDirEnabled && !rawConfig.include.includes(nextAppTypes)) {
} else if (hasAppDir && !rawConfig.include.includes(nextAppTypes)) {
userTsConfig.include.push(nextAppTypes)
suggestedActions.push(
cyan('include') + ' was updated to add ' + bold(`'${nextAppTypes}'`)
......@@ -204,7 +204,7 @@ export async function writeConfigurationDefaults(
}
// Enable the Next.js typescript plugin.
if (isAppDirEnabled) {
if (hasAppDir) {
// Check if the config or the resolved config has the plugin already.
const plugins = [
...(Array.isArray(tsOptions.plugins) ? tsOptions.plugins : []),
......@@ -248,7 +248,7 @@ export async function writeConfigurationDefaults(
// then set `strictNullChecks` to `true`.
if (
hasPagesDir &&
isAppDirEnabled &&
hasAppDir &&
userTsConfig.compilerOptions &&
!userTsConfig.compilerOptions.strict &&
!('strictNullChecks' in userTsConfig.compilerOptions)
......
......@@ -131,7 +131,7 @@ export async function verifyTypeScriptSetup({
baseDir: dir,
imageImportsEnabled: !disableStaticImages,
hasPagesDir,
isAppDirEnabled: hasAppDir,
hasAppDir,
})
let result
......
......@@ -34,7 +34,7 @@ describe('find config', () => {
baseDir: fixtureDir,
imageImportsEnabled,
hasPagesDir: false,
isAppDirEnabled: false,
hasAppDir: false,
})
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content)
})
......@@ -59,7 +59,7 @@ describe('find config', () => {
baseDir: fixtureDir,
imageImportsEnabled,
hasPagesDir: false,
isAppDirEnabled: false,
hasAppDir: false,
})
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content)
})
......@@ -82,7 +82,7 @@ describe('find config', () => {
baseDir: fixtureDir,
imageImportsEnabled,
hasPagesDir: false,
isAppDirEnabled: false,
hasAppDir: false,
})
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content)
})
......@@ -92,7 +92,7 @@ describe('find config', () => {
baseDir: fixtureDir,
imageImportsEnabled,
hasPagesDir: false,
isAppDirEnabled: true,
hasAppDir: true,
})
await expect(fs.readFile(declarationFile, 'utf8')).resolves.not.toContain(
......@@ -103,7 +103,7 @@ describe('find config', () => {
baseDir: fixtureDir,
imageImportsEnabled,
hasPagesDir: true,
isAppDirEnabled: true,
hasAppDir: true,
})
await expect(fs.readFile(declarationFile, 'utf8')).resolves.toContain(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment