Skip to content

Commit f982260

Browse files
authored
Development: Clarify TypescriptStatus in watcher (#83857)
## What? Makes it easier to reason about given there's only one variable to keep track off instead of `usingTypeScript` vs `enabledTypeScript`.
1 parent 009e30d commit f982260

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

packages/next/src/server/lib/router-utils/setup-dev-bundler.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ export type ServerFields = {
133133
}
134134

135135
async function verifyTypeScript(opts: SetupOpts) {
136-
let usingTypeScript = false
137136
const verifyResult = await verifyTypeScriptSetup({
138137
dir: opts.dir,
139138
distDir: opts.nextConfig.distDir,
@@ -146,9 +145,9 @@ async function verifyTypeScript(opts: SetupOpts) {
146145
})
147146

148147
if (verifyResult.version) {
149-
usingTypeScript = true
148+
return true
150149
}
151-
return usingTypeScript
150+
return false
152151
}
153152

154153
export async function propagateServerField(
@@ -242,8 +241,6 @@ async function startWatcher(
242241
opts.nextConfig
243242
)
244243

245-
const usingTypeScript = await verifyTypeScript(opts)
246-
247244
const routesManifestPath = path.join(distDir, ROUTES_MANIFEST)
248245
const routesManifest: DevRoutesManifest = {
249246
version: 3,
@@ -348,14 +345,15 @@ async function startWatcher(
348345
},
349346
})
350347
const fileWatchTimes = new Map()
351-
let enabledTypeScript = usingTypeScript
348+
let enabledTypeScript = await verifyTypeScript(opts)
352349
let previousClientRouterFilters: any
353350
let previousConflictingPagePaths: Set<string> = new Set()
354351

355352
const routeTypesFilePath = path.join(distDir, 'types', 'routes.d.ts')
356353
const validatorFilePath = path.join(distDir, 'types', 'validator.ts')
357354

358355
wp.on('aggregated', async () => {
356+
let typescriptStatusFromLastAggregation = enabledTypeScript
359357
let middlewareMatchers: MiddlewareMatcher[] | undefined
360358
const routedPages: string[] = []
361359
const knownFiles = wp.getTimeInfoEntries()
@@ -728,7 +726,8 @@ async function startWatcher(
728726
}
729727
}
730728

731-
if (!usingTypeScript && enabledTypeScript) {
729+
// Using === false to make the check clearer.
730+
if (typescriptStatusFromLastAggregation === false && enabledTypeScript) {
732731
// we tolerate the error here as this is best effort
733732
// and the manual install command will be shown
734733
await verifyTypeScript(opts)
@@ -753,7 +752,7 @@ async function startWatcher(
753752
}
754753
)
755754

756-
if (usingTypeScript && nextConfig.experimental?.typedEnv) {
755+
if (enabledTypeScript && nextConfig.experimental?.typedEnv) {
757756
// do not await, this is not essential for further process
758757
createEnvDefinitions({
759758
distDir,
@@ -1091,7 +1090,7 @@ async function startWatcher(
10911090
}
10921091
prevSortedRoutes = sortedRoutes
10931092

1094-
if (usingTypeScript) {
1093+
if (enabledTypeScript) {
10951094
const routeTypesManifest = await createRouteTypesManifest({
10961095
dir,
10971096
pageRoutes,

0 commit comments

Comments
 (0)