Commit 6bc2550c authored by Tim Neutkens's avatar Tim Neutkens

Development: Don't block on TypeScript validation

parent e5afc390
...@@ -344,7 +344,7 @@ async function startWatcher( ...@@ -344,7 +344,7 @@ async function startWatcher(
}, },
}) })
const fileWatchTimes = new Map() const fileWatchTimes = new Map()
let enabledTypeScript = await verifyTypeScript(opts) let enabledTypeScript: Promise<boolean> = verifyTypeScript(opts)
let previousClientRouterFilters: any let previousClientRouterFilters: any
let previousConflictingPagePaths: Set<string> = new Set() let previousConflictingPagePaths: Set<string> = new Set()
...@@ -411,7 +411,7 @@ async function startWatcher( ...@@ -411,7 +411,7 @@ async function startWatcher(
if (tsconfigPaths.includes(fileName)) { if (tsconfigPaths.includes(fileName)) {
if (fileName.endsWith('tsconfig.json')) { if (fileName.endsWith('tsconfig.json')) {
enabledTypeScript = true enabledTypeScript = Promise.resolve(true)
} }
if (watchTimeChange) { if (watchTimeChange) {
tsconfigChange = true tsconfigChange = true
...@@ -487,7 +487,7 @@ async function startWatcher( ...@@ -487,7 +487,7 @@ async function startWatcher(
} }
if (fileName.endsWith('.ts') || fileName.endsWith('.tsx')) { if (fileName.endsWith('.ts') || fileName.endsWith('.tsx')) {
enabledTypeScript = true enabledTypeScript = Promise.resolve(true)
} }
if (!(isAppPath || isPagePath)) { if (!(isAppPath || isPagePath)) {
...@@ -1054,69 +1054,76 @@ async function startWatcher( ...@@ -1054,69 +1054,76 @@ async function startWatcher(
} }
prevSortedRoutes = sortedRoutes prevSortedRoutes = sortedRoutes
if (enabledTypeScript) { enabledTypeScript
// Using === false to make the check clearer. .then(async (enabled) => {
if (typescriptStatusFromLastAggregation === false) { if (!enabled) {
// we tolerate the error here as this is best effort return
// and the manual install command will be shown }
await verifyTypeScript(opts) // Using === false to make the check clearer.
.then(() => { if ((await typescriptStatusFromLastAggregation) === false) {
tsconfigChange = true // we tolerate the error here as this is best effort
// and the manual install command will be shown
await verifyTypeScript(opts)
.then(() => {
tsconfigChange = true
})
.catch(() => {})
}
if (writeEnvDefinitions && nextConfig.experimental?.typedEnv) {
// TODO: The call to propagateServerField 'loadEnvConfig' causes the env to be loaded twice on env file changes.
const loadEnvConfig = (
require('@next/env') as typeof import('@next/env')
).loadEnvConfig
const { loadedEnvFiles } = loadEnvConfig(
dir,
process.env.NODE_ENV === 'development',
// Silent as it's the second time `loadEnvConfig` is called in this pass.
undefined,
true
)
const createEnvDefinitions = (
require('../experimental/create-env-definitions') as typeof import('../experimental/create-env-definitions')
).createEnvDefinitions
await createEnvDefinitions({
distDir,
loadedEnvFiles: [
...loadedEnvFiles,
{
path: nextConfig.configFileName,
env: nextConfig.env,
contents: '',
},
],
}) })
.catch(() => {}) }
}
if (writeEnvDefinitions && nextConfig.experimental?.typedEnv) { const routeTypesManifest = await createRouteTypesManifest({
// TODO: The call to propagateServerField 'loadEnvConfig' causes the env to be loaded twice on env file changes.
const loadEnvConfig = (
require('@next/env') as typeof import('@next/env')
).loadEnvConfig
const { loadedEnvFiles } = loadEnvConfig(
dir, dir,
process.env.NODE_ENV === 'development', pageRoutes,
// Silent as it's the second time `loadEnvConfig` is called in this pass. appRoutes,
undefined, layoutRoutes,
true slots,
) redirects: opts.nextConfig.redirects,
rewrites: opts.nextConfig.rewrites,
const createEnvDefinitions = ( // Ensure relative paths in validator.ts are computed from validatorFilePath,
require('../experimental/create-env-definitions') as typeof import('../experimental/create-env-definitions') // matching behavior of build and CLI typegen.
).createEnvDefinitions validatorFilePath,
await createEnvDefinitions({ appRouteHandlers,
distDir, pageApiRoutes,
loadedEnvFiles: [
...loadedEnvFiles,
{
path: nextConfig.configFileName,
env: nextConfig.env,
contents: '',
},
],
}) })
}
const routeTypesManifest = await createRouteTypesManifest({ await writeRouteTypesManifest(
dir, routeTypesManifest,
pageRoutes, routeTypesFilePath,
appRoutes, opts.nextConfig
layoutRoutes, )
slots, await writeValidatorFile(routeTypesManifest, validatorFilePath)
redirects: opts.nextConfig.redirects, })
rewrites: opts.nextConfig.rewrites, .catch((err) => {
// Ensure relative paths in validator.ts are computed from validatorFilePath, Log.warn('Failed to create TypeScript setup', err)
// matching behavior of build and CLI typegen.
validatorFilePath,
appRouteHandlers,
pageApiRoutes,
}) })
await writeRouteTypesManifest(
routeTypesManifest,
routeTypesFilePath,
opts.nextConfig
)
await writeValidatorFile(routeTypesManifest, validatorFilePath)
}
if (!resolved) { if (!resolved) {
resolve() resolve()
......
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