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({ ...@@ -6,12 +6,12 @@ export async function writeAppTypeDeclarations({
baseDir, baseDir,
imageImportsEnabled, imageImportsEnabled,
hasPagesDir, hasPagesDir,
isAppDirEnabled, hasAppDir,
}: { }: {
baseDir: string baseDir: string
imageImportsEnabled: boolean imageImportsEnabled: boolean
hasPagesDir: boolean hasPagesDir: boolean
isAppDirEnabled: boolean hasAppDir: boolean
}): Promise<void> { }): Promise<void> {
// Reference `next` types // Reference `next` types
const appTypeDeclarations = path.join(baseDir, 'next-env.d.ts') const appTypeDeclarations = path.join(baseDir, 'next-env.d.ts')
...@@ -49,7 +49,7 @@ export async function writeAppTypeDeclarations({ ...@@ -49,7 +49,7 @@ export async function writeAppTypeDeclarations({
directives.push('/// <reference types="next/image-types/global" />') directives.push('/// <reference types="next/image-types/global" />')
} }
if (isAppDirEnabled && hasPagesDir) { if (hasAppDir && hasPagesDir) {
directives.push( directives.push(
'/// <reference types="next/navigation-types/compat/navigation" />' '/// <reference types="next/navigation-types/compat/navigation" />'
) )
......
...@@ -119,7 +119,7 @@ export async function writeConfigurationDefaults( ...@@ -119,7 +119,7 @@ export async function writeConfigurationDefaults(
ts: typeof import('typescript'), ts: typeof import('typescript'),
tsConfigPath: string, tsConfigPath: string,
isFirstTimeSetup: boolean, isFirstTimeSetup: boolean,
isAppDirEnabled: boolean, hasAppDir: boolean,
distDir: string, distDir: string,
hasPagesDir: boolean hasPagesDir: boolean
): Promise<void> { ): Promise<void> {
...@@ -184,19 +184,19 @@ export async function writeConfigurationDefaults( ...@@ -184,19 +184,19 @@ export async function writeConfigurationDefaults(
const nextAppTypes = `${distDir}/types/**/*.ts` const nextAppTypes = `${distDir}/types/**/*.ts`
if (!('include' in rawConfig)) { if (!('include' in rawConfig)) {
userTsConfig.include = isAppDirEnabled userTsConfig.include = hasAppDir
? ['next-env.d.ts', nextAppTypes, '**/*.ts', '**/*.tsx'] ? ['next-env.d.ts', nextAppTypes, '**/*.ts', '**/*.tsx']
: ['next-env.d.ts', '**/*.ts', '**/*.tsx'] : ['next-env.d.ts', '**/*.ts', '**/*.tsx']
suggestedActions.push( suggestedActions.push(
cyan('include') + cyan('include') +
' was set to ' + ' was set to ' +
bold( bold(
isAppDirEnabled hasAppDir
? `['next-env.d.ts', '${nextAppTypes}', '**/*.ts', '**/*.tsx']` ? `['next-env.d.ts', '${nextAppTypes}', '**/*.ts', '**/*.tsx']`
: `['next-env.d.ts', '**/*.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) userTsConfig.include.push(nextAppTypes)
suggestedActions.push( suggestedActions.push(
cyan('include') + ' was updated to add ' + bold(`'${nextAppTypes}'`) cyan('include') + ' was updated to add ' + bold(`'${nextAppTypes}'`)
...@@ -204,7 +204,7 @@ export async function writeConfigurationDefaults( ...@@ -204,7 +204,7 @@ export async function writeConfigurationDefaults(
} }
// Enable the Next.js typescript plugin. // Enable the Next.js typescript plugin.
if (isAppDirEnabled) { if (hasAppDir) {
// Check if the config or the resolved config has the plugin already. // Check if the config or the resolved config has the plugin already.
const plugins = [ const plugins = [
...(Array.isArray(tsOptions.plugins) ? tsOptions.plugins : []), ...(Array.isArray(tsOptions.plugins) ? tsOptions.plugins : []),
...@@ -248,7 +248,7 @@ export async function writeConfigurationDefaults( ...@@ -248,7 +248,7 @@ export async function writeConfigurationDefaults(
// then set `strictNullChecks` to `true`. // then set `strictNullChecks` to `true`.
if ( if (
hasPagesDir && hasPagesDir &&
isAppDirEnabled && hasAppDir &&
userTsConfig.compilerOptions && userTsConfig.compilerOptions &&
!userTsConfig.compilerOptions.strict && !userTsConfig.compilerOptions.strict &&
!('strictNullChecks' in userTsConfig.compilerOptions) !('strictNullChecks' in userTsConfig.compilerOptions)
......
...@@ -131,7 +131,7 @@ export async function verifyTypeScriptSetup({ ...@@ -131,7 +131,7 @@ export async function verifyTypeScriptSetup({
baseDir: dir, baseDir: dir,
imageImportsEnabled: !disableStaticImages, imageImportsEnabled: !disableStaticImages,
hasPagesDir, hasPagesDir,
isAppDirEnabled: hasAppDir, hasAppDir,
}) })
let result let result
......
...@@ -34,7 +34,7 @@ describe('find config', () => { ...@@ -34,7 +34,7 @@ describe('find config', () => {
baseDir: fixtureDir, baseDir: fixtureDir,
imageImportsEnabled, imageImportsEnabled,
hasPagesDir: false, hasPagesDir: false,
isAppDirEnabled: false, hasAppDir: false,
}) })
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content) expect(await fs.readFile(declarationFile, 'utf8')).toBe(content)
}) })
...@@ -59,7 +59,7 @@ describe('find config', () => { ...@@ -59,7 +59,7 @@ describe('find config', () => {
baseDir: fixtureDir, baseDir: fixtureDir,
imageImportsEnabled, imageImportsEnabled,
hasPagesDir: false, hasPagesDir: false,
isAppDirEnabled: false, hasAppDir: false,
}) })
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content) expect(await fs.readFile(declarationFile, 'utf8')).toBe(content)
}) })
...@@ -82,7 +82,7 @@ describe('find config', () => { ...@@ -82,7 +82,7 @@ describe('find config', () => {
baseDir: fixtureDir, baseDir: fixtureDir,
imageImportsEnabled, imageImportsEnabled,
hasPagesDir: false, hasPagesDir: false,
isAppDirEnabled: false, hasAppDir: false,
}) })
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content) expect(await fs.readFile(declarationFile, 'utf8')).toBe(content)
}) })
...@@ -92,7 +92,7 @@ describe('find config', () => { ...@@ -92,7 +92,7 @@ describe('find config', () => {
baseDir: fixtureDir, baseDir: fixtureDir,
imageImportsEnabled, imageImportsEnabled,
hasPagesDir: false, hasPagesDir: false,
isAppDirEnabled: true, hasAppDir: true,
}) })
await expect(fs.readFile(declarationFile, 'utf8')).resolves.not.toContain( await expect(fs.readFile(declarationFile, 'utf8')).resolves.not.toContain(
...@@ -103,7 +103,7 @@ describe('find config', () => { ...@@ -103,7 +103,7 @@ describe('find config', () => {
baseDir: fixtureDir, baseDir: fixtureDir,
imageImportsEnabled, imageImportsEnabled,
hasPagesDir: true, hasPagesDir: true,
isAppDirEnabled: true, hasAppDir: true,
}) })
await expect(fs.readFile(declarationFile, 'utf8')).resolves.toContain( 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