next 16.1.0-canary.3 → 16.1.0-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/next +2 -2
- package/dist/build/index.js +3 -3
- package/dist/build/swc/index.js +1 -1
- package/dist/build/webpack-config.js +2 -2
- package/dist/bundle-analyzer/404.html +2 -2
- package/dist/bundle-analyzer/__next.__PAGE__.txt +1 -1
- package/dist/bundle-analyzer/__next._full.txt +1 -1
- package/dist/bundle-analyzer/__next._index.txt +1 -1
- package/dist/bundle-analyzer/__next._tree.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._full.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._index.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._not-found.__PAGE__.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._not-found.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._tree.txt +1 -1
- package/dist/bundle-analyzer/_not-found.html +2 -2
- package/dist/bundle-analyzer/_not-found.txt +1 -1
- package/dist/bundle-analyzer/index.html +2 -2
- package/dist/bundle-analyzer/index.txt +1 -1
- package/dist/client/app-bootstrap.js +1 -1
- package/dist/client/index.js +1 -1
- package/dist/compiled/next-server/pages-api.runtime.prod.js +1 -1
- package/dist/compiled/next-server/pages-api.runtime.prod.js.map +1 -1
- package/dist/compiled/next-server/pages.runtime.prod.js +1 -1
- package/dist/compiled/next-server/pages.runtime.prod.js.map +1 -1
- package/dist/esm/build/index.js +3 -3
- package/dist/esm/build/swc/index.js +1 -1
- package/dist/esm/build/webpack-config.js +2 -2
- package/dist/esm/client/app-bootstrap.js +1 -1
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/lib/typescript/runTypeCheck.js +18 -5
- package/dist/esm/lib/typescript/runTypeCheck.js.map +1 -1
- package/dist/esm/lib/typescript/type-paths.js +37 -0
- package/dist/esm/lib/typescript/type-paths.js.map +1 -0
- package/dist/esm/lib/typescript/writeConfigurationDefaults.js +6 -17
- package/dist/esm/lib/typescript/writeConfigurationDefaults.js.map +1 -1
- package/dist/esm/lib/verify-typescript-setup.js +1 -1
- package/dist/esm/lib/verify-typescript-setup.js.map +1 -1
- package/dist/esm/server/config.js +2 -2
- package/dist/esm/server/config.js.map +1 -1
- package/dist/esm/server/dev/hot-reloader-turbopack.js +1 -1
- package/dist/esm/server/dev/hot-reloader-webpack.js +1 -1
- package/dist/esm/server/lib/app-info-log.js +1 -1
- package/dist/esm/server/lib/start-server.js +1 -1
- package/dist/esm/shared/lib/errors/canary-only-config-error.js +1 -1
- package/dist/lib/typescript/runTypeCheck.d.ts +1 -1
- package/dist/lib/typescript/runTypeCheck.js +18 -5
- package/dist/lib/typescript/runTypeCheck.js.map +1 -1
- package/dist/lib/typescript/type-paths.d.ts +12 -0
- package/dist/lib/typescript/type-paths.js +56 -0
- package/dist/lib/typescript/type-paths.js.map +1 -0
- package/dist/lib/typescript/writeConfigurationDefaults.js +6 -17
- package/dist/lib/typescript/writeConfigurationDefaults.js.map +1 -1
- package/dist/lib/verify-typescript-setup.js +1 -1
- package/dist/lib/verify-typescript-setup.js.map +1 -1
- package/dist/server/config.js +2 -2
- package/dist/server/config.js.map +1 -1
- package/dist/server/dev/hot-reloader-turbopack.js +1 -1
- package/dist/server/dev/hot-reloader-webpack.js +1 -1
- package/dist/server/lib/app-info-log.js +1 -1
- package/dist/server/lib/start-server.js +1 -1
- package/dist/shared/lib/errors/canary-only-config-error.js +1 -1
- package/dist/telemetry/anonymous-meta.js +1 -1
- package/dist/telemetry/events/session-stopped.js +2 -2
- package/dist/telemetry/events/version.js +2 -2
- package/package.json +15 -15
- /package/dist/bundle-analyzer/_next/static/{TnRZ8nGbopg18HtVsbM43 → Aod3729un5YGDrF2l8UjT}/_buildManifest.js +0 -0
- /package/dist/bundle-analyzer/_next/static/{TnRZ8nGbopg18HtVsbM43 → Aod3729un5YGDrF2l8UjT}/_clientMiddlewareManifest.json +0 -0
- /package/dist/bundle-analyzer/_next/static/{TnRZ8nGbopg18HtVsbM43 → Aod3729un5YGDrF2l8UjT}/_ssgManifest.js +0 -0
package/dist/esm/build/index.js
CHANGED
|
@@ -300,7 +300,7 @@ export default async function build(dir, experimentalAnalyze = false, reactProdu
|
|
|
300
300
|
try {
|
|
301
301
|
const nextBuildSpan = trace('next-build', undefined, {
|
|
302
302
|
buildMode: experimentalBuildMode,
|
|
303
|
-
version: "16.1.0-canary.
|
|
303
|
+
version: "16.1.0-canary.4"
|
|
304
304
|
});
|
|
305
305
|
NextBuildContext.nextBuildSpan = nextBuildSpan;
|
|
306
306
|
NextBuildContext.dir = dir;
|
|
@@ -794,7 +794,7 @@ export default async function build(dir, experimentalAnalyze = false, reactProdu
|
|
|
794
794
|
// Files outside of the distDir can be "type": "module"
|
|
795
795
|
await writeFileUtf8(path.join(distDir, 'package.json'), '{"type": "commonjs"}');
|
|
796
796
|
// These are written to distDir, so they need to come after creating and cleaning distDr.
|
|
797
|
-
await recordFrameworkVersion("16.1.0-canary.
|
|
797
|
+
await recordFrameworkVersion("16.1.0-canary.4");
|
|
798
798
|
await updateBuildDiagnostics({
|
|
799
799
|
buildStage: 'start'
|
|
800
800
|
});
|
|
@@ -2471,7 +2471,7 @@ export default async function build(dir, experimentalAnalyze = false, reactProdu
|
|
|
2471
2471
|
configOutDir: path.join(dir, configOutDir),
|
|
2472
2472
|
staticPages,
|
|
2473
2473
|
serverPropsPages,
|
|
2474
|
-
nextVersion: "16.1.0-canary.
|
|
2474
|
+
nextVersion: "16.1.0-canary.4",
|
|
2475
2475
|
tracingRoot: outputFileTracingRoot,
|
|
2476
2476
|
hasNodeMiddleware,
|
|
2477
2477
|
hasInstrumentationHook,
|
|
@@ -10,7 +10,7 @@ import { downloadNativeNextSwc, downloadWasmSwc } from '../../lib/download-swc';
|
|
|
10
10
|
import { isDeepStrictEqual } from 'util';
|
|
11
11
|
import { getDefineEnv } from '../define-env';
|
|
12
12
|
import { throwTurbopackInternalError } from '../../shared/lib/turbopack/internal-error';
|
|
13
|
-
const nextVersion = "16.1.0-canary.
|
|
13
|
+
const nextVersion = "16.1.0-canary.4";
|
|
14
14
|
const ArchName = arch();
|
|
15
15
|
const PlatformName = platform();
|
|
16
16
|
function infoLog(...args) {
|
|
@@ -1622,7 +1622,7 @@ export default async function getBaseWebpackConfig(dir, { buildId, encryptionKey
|
|
|
1622
1622
|
isClient && new CopyFilePlugin({
|
|
1623
1623
|
// file path to build output of `@next/polyfill-nomodule`
|
|
1624
1624
|
filePath: require.resolve('./polyfills/polyfill-nomodule'),
|
|
1625
|
-
cacheKey: "16.1.0-canary.
|
|
1625
|
+
cacheKey: "16.1.0-canary.4",
|
|
1626
1626
|
name: `static/chunks/polyfills${dev ? '' : '-[hash]'}.js`,
|
|
1627
1627
|
minimize: false,
|
|
1628
1628
|
info: {
|
|
@@ -1808,7 +1808,7 @@ export default async function getBaseWebpackConfig(dir, { buildId, encryptionKey
|
|
|
1808
1808
|
// - Next.js location on disk (some loaders use absolute paths and some resolve options depend on absolute paths)
|
|
1809
1809
|
// - Next.js version
|
|
1810
1810
|
// - next.config.js keys that affect compilation
|
|
1811
|
-
version: `${__dirname}|${"16.1.0-canary.
|
|
1811
|
+
version: `${__dirname}|${"16.1.0-canary.4"}|${configVars}`,
|
|
1812
1812
|
cacheDirectory: path.join(distDir, 'cache', 'webpack'),
|
|
1813
1813
|
// For production builds, it's more efficient to compress all cache files together instead of compression each one individually.
|
|
1814
1814
|
// So we disable compression here and allow the build runner to take care of compressing the cache as a whole.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - next/script with `beforeInteractive` strategy
|
|
6
6
|
*/ import { getAssetPrefix } from './asset-prefix';
|
|
7
7
|
import { setAttributesFromProps } from './set-attributes-from-props';
|
|
8
|
-
const version = "16.1.0-canary.
|
|
8
|
+
const version = "16.1.0-canary.4";
|
|
9
9
|
window.next = {
|
|
10
10
|
version,
|
|
11
11
|
appDir: true
|
package/dist/esm/client/index.js
CHANGED
|
@@ -25,7 +25,7 @@ import { SearchParamsContext, PathParamsContext } from '../shared/lib/hooks-clie
|
|
|
25
25
|
import { onRecoverableError } from './react-client-callbacks/on-recoverable-error';
|
|
26
26
|
import tracer from './tracing/tracer';
|
|
27
27
|
import { isNextRouterError } from './components/is-next-router-error';
|
|
28
|
-
export const version = "16.1.0-canary.
|
|
28
|
+
export const version = "16.1.0-canary.4";
|
|
29
29
|
export let router;
|
|
30
30
|
export const emitter = mitt();
|
|
31
31
|
const looseToArray = (input)=>[].slice.call(input);
|
|
@@ -2,11 +2,24 @@ import path from 'path';
|
|
|
2
2
|
import { getFormattedDiagnostic } from './diagnosticFormatter';
|
|
3
3
|
import { getTypeScriptConfiguration } from './getTypeScriptConfiguration';
|
|
4
4
|
import { getRequiredConfiguration } from './writeConfigurationDefaults';
|
|
5
|
+
import { getDevTypesPath } from './type-paths';
|
|
5
6
|
import { CompileError } from '../compile-error';
|
|
6
7
|
import { warn } from '../../build/output/log';
|
|
7
|
-
|
|
8
|
+
import { defaultConfig } from '../../server/config-shared';
|
|
9
|
+
export async function runTypeCheck(typescript, baseDir, distDir, tsConfigPath, cacheDir, isAppDirEnabled, isolatedDevBuild) {
|
|
8
10
|
const effectiveConfiguration = await getTypeScriptConfiguration(typescript, tsConfigPath);
|
|
9
|
-
|
|
11
|
+
// When isolatedDevBuild is enabled, tsconfig includes both .next/types and
|
|
12
|
+
// .next/dev/types to avoid config churn between dev/build modes. During build,
|
|
13
|
+
// we filter out .next/dev/types files to prevent stale dev types from causing
|
|
14
|
+
// errors when routes have been deleted since the last dev session.
|
|
15
|
+
let fileNames = effectiveConfiguration.fileNames;
|
|
16
|
+
const resolvedIsolatedDevBuild = isolatedDevBuild === undefined ? defaultConfig.experimental.isolatedDevBuild : isolatedDevBuild;
|
|
17
|
+
// Get the dev types path to filter (null if not applicable)
|
|
18
|
+
const devTypesDir = getDevTypesPath(baseDir, distDir, resolvedIsolatedDevBuild);
|
|
19
|
+
if (devTypesDir) {
|
|
20
|
+
fileNames = fileNames.filter((fileName)=>!fileName.startsWith(devTypesDir));
|
|
21
|
+
}
|
|
22
|
+
if (fileNames.length < 1) {
|
|
10
23
|
return {
|
|
11
24
|
hasWarnings: false,
|
|
12
25
|
inputFilesCount: 0,
|
|
@@ -30,7 +43,7 @@ export async function runTypeCheck(typescript, baseDir, distDir, tsConfigPath, c
|
|
|
30
43
|
}
|
|
31
44
|
incremental = true;
|
|
32
45
|
program = typescript.createIncrementalProgram({
|
|
33
|
-
rootNames:
|
|
46
|
+
rootNames: fileNames,
|
|
34
47
|
options: {
|
|
35
48
|
...options,
|
|
36
49
|
composite: false,
|
|
@@ -39,7 +52,7 @@ export async function runTypeCheck(typescript, baseDir, distDir, tsConfigPath, c
|
|
|
39
52
|
}
|
|
40
53
|
});
|
|
41
54
|
} else {
|
|
42
|
-
program = typescript.createProgram(
|
|
55
|
+
program = typescript.createProgram(fileNames, options);
|
|
43
56
|
}
|
|
44
57
|
const result = program.emit();
|
|
45
58
|
const ignoreRegex = [
|
|
@@ -71,7 +84,7 @@ export async function runTypeCheck(typescript, baseDir, distDir, tsConfigPath, c
|
|
|
71
84
|
return {
|
|
72
85
|
hasWarnings: true,
|
|
73
86
|
warnings,
|
|
74
|
-
inputFilesCount:
|
|
87
|
+
inputFilesCount: fileNames.length,
|
|
75
88
|
totalFilesCount: program.getSourceFiles().length,
|
|
76
89
|
incremental
|
|
77
90
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/typescript/runTypeCheck.ts"],"sourcesContent":["import path from 'path'\nimport { getFormattedDiagnostic } from './diagnosticFormatter'\nimport { getTypeScriptConfiguration } from './getTypeScriptConfiguration'\nimport { getRequiredConfiguration } from './writeConfigurationDefaults'\n\nimport { CompileError } from '../compile-error'\nimport { warn } from '../../build/output/log'\n\nexport interface TypeCheckResult {\n hasWarnings: boolean\n warnings?: string[]\n inputFilesCount: number\n totalFilesCount: number\n incremental: boolean\n}\n\nexport async function runTypeCheck(\n typescript: typeof import('typescript'),\n baseDir: string,\n distDir: string,\n tsConfigPath: string,\n cacheDir?: string,\n isAppDirEnabled?: boolean\n): Promise<TypeCheckResult> {\n const effectiveConfiguration = await getTypeScriptConfiguration(\n typescript,\n tsConfigPath\n )\n\n if (
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/typescript/runTypeCheck.ts"],"sourcesContent":["import path from 'path'\nimport { getFormattedDiagnostic } from './diagnosticFormatter'\nimport { getTypeScriptConfiguration } from './getTypeScriptConfiguration'\nimport { getRequiredConfiguration } from './writeConfigurationDefaults'\nimport { getDevTypesPath } from './type-paths'\n\nimport { CompileError } from '../compile-error'\nimport { warn } from '../../build/output/log'\nimport { defaultConfig } from '../../server/config-shared'\n\nexport interface TypeCheckResult {\n hasWarnings: boolean\n warnings?: string[]\n inputFilesCount: number\n totalFilesCount: number\n incremental: boolean\n}\n\nexport async function runTypeCheck(\n typescript: typeof import('typescript'),\n baseDir: string,\n distDir: string,\n tsConfigPath: string,\n cacheDir?: string,\n isAppDirEnabled?: boolean,\n isolatedDevBuild?: boolean\n): Promise<TypeCheckResult> {\n const effectiveConfiguration = await getTypeScriptConfiguration(\n typescript,\n tsConfigPath\n )\n\n // When isolatedDevBuild is enabled, tsconfig includes both .next/types and\n // .next/dev/types to avoid config churn between dev/build modes. During build,\n // we filter out .next/dev/types files to prevent stale dev types from causing\n // errors when routes have been deleted since the last dev session.\n let fileNames = effectiveConfiguration.fileNames\n const resolvedIsolatedDevBuild =\n isolatedDevBuild === undefined\n ? defaultConfig.experimental.isolatedDevBuild\n : isolatedDevBuild\n\n // Get the dev types path to filter (null if not applicable)\n const devTypesDir = getDevTypesPath(\n baseDir,\n distDir,\n resolvedIsolatedDevBuild\n )\n if (devTypesDir) {\n fileNames = fileNames.filter(\n (fileName) => !fileName.startsWith(devTypesDir)\n )\n }\n\n if (fileNames.length < 1) {\n return {\n hasWarnings: false,\n inputFilesCount: 0,\n totalFilesCount: 0,\n incremental: false,\n }\n }\n const requiredConfig = getRequiredConfiguration(typescript)\n\n const options = {\n ...requiredConfig,\n ...effectiveConfiguration.options,\n declarationMap: false,\n emitDeclarationOnly: false,\n noEmit: true,\n }\n\n let program:\n | import('typescript').Program\n | import('typescript').BuilderProgram\n let incremental = false\n if ((options.incremental || options.composite) && cacheDir) {\n if (options.composite) {\n warn(\n 'TypeScript project references are not fully supported. Attempting to build in incremental mode.'\n )\n }\n incremental = true\n program = typescript.createIncrementalProgram({\n rootNames: fileNames,\n options: {\n ...options,\n composite: false,\n incremental: true,\n tsBuildInfoFile: path.join(cacheDir, '.tsbuildinfo'),\n },\n })\n } else {\n program = typescript.createProgram(fileNames, options)\n }\n\n const result = program.emit()\n\n const ignoreRegex = [\n // matches **/__(tests|mocks)__/**\n /[\\\\/]__(?:tests|mocks)__[\\\\/]/,\n // matches **/*.(spec|test).*\n /(?<=[\\\\/.])(?:spec|test)\\.[^\\\\/]+$/,\n ]\n const regexIgnoredFile = new RegExp(\n ignoreRegex.map((r) => r.source).join('|')\n )\n\n const allDiagnostics = typescript\n .getPreEmitDiagnostics(program as import('typescript').Program)\n .concat(result.diagnostics)\n .filter((d) => !(d.file && regexIgnoredFile.test(d.file.fileName)))\n\n const firstError =\n allDiagnostics.find(\n (d) =>\n d.category === typescript.DiagnosticCategory.Error && Boolean(d.file)\n ) ??\n allDiagnostics.find(\n (d) => d.category === typescript.DiagnosticCategory.Error\n )\n\n // In test mode, we want to check all diagnostics, not just the first one.\n if (process.env.__NEXT_TEST_MODE) {\n if (firstError) {\n const allErrors = allDiagnostics\n .filter((d) => d.category === typescript.DiagnosticCategory.Error)\n .map(\n (d) =>\n '[Test Mode] ' +\n getFormattedDiagnostic(\n typescript,\n baseDir,\n distDir,\n d,\n isAppDirEnabled\n )\n )\n\n console.error(\n '\\n\\n===== TS errors =====\\n\\n' +\n allErrors.join('\\n\\n') +\n '\\n\\n===== TS errors =====\\n\\n'\n )\n\n // Make sure all stdout is flushed before we exit.\n await new Promise((resolve) => setTimeout(resolve, 100))\n }\n }\n\n if (firstError) {\n throw new CompileError(\n getFormattedDiagnostic(\n typescript,\n baseDir,\n distDir,\n firstError,\n isAppDirEnabled\n )\n )\n }\n\n const warnings = allDiagnostics\n .filter((d) => d.category === typescript.DiagnosticCategory.Warning)\n .map((d) =>\n getFormattedDiagnostic(typescript, baseDir, distDir, d, isAppDirEnabled)\n )\n\n return {\n hasWarnings: true,\n warnings,\n inputFilesCount: fileNames.length,\n totalFilesCount: program.getSourceFiles().length,\n incremental,\n }\n}\n"],"names":["path","getFormattedDiagnostic","getTypeScriptConfiguration","getRequiredConfiguration","getDevTypesPath","CompileError","warn","defaultConfig","runTypeCheck","typescript","baseDir","distDir","tsConfigPath","cacheDir","isAppDirEnabled","isolatedDevBuild","effectiveConfiguration","fileNames","resolvedIsolatedDevBuild","undefined","experimental","devTypesDir","filter","fileName","startsWith","length","hasWarnings","inputFilesCount","totalFilesCount","incremental","requiredConfig","options","declarationMap","emitDeclarationOnly","noEmit","program","composite","createIncrementalProgram","rootNames","tsBuildInfoFile","join","createProgram","result","emit","ignoreRegex","regexIgnoredFile","RegExp","map","r","source","allDiagnostics","getPreEmitDiagnostics","concat","diagnostics","d","file","test","firstError","find","category","DiagnosticCategory","Error","Boolean","process","env","__NEXT_TEST_MODE","allErrors","console","error","Promise","resolve","setTimeout","warnings","Warning","getSourceFiles"],"mappings":"AAAA,OAAOA,UAAU,OAAM;AACvB,SAASC,sBAAsB,QAAQ,wBAAuB;AAC9D,SAASC,0BAA0B,QAAQ,+BAA8B;AACzE,SAASC,wBAAwB,QAAQ,+BAA8B;AACvE,SAASC,eAAe,QAAQ,eAAc;AAE9C,SAASC,YAAY,QAAQ,mBAAkB;AAC/C,SAASC,IAAI,QAAQ,yBAAwB;AAC7C,SAASC,aAAa,QAAQ,6BAA4B;AAU1D,OAAO,eAAeC,aACpBC,UAAuC,EACvCC,OAAe,EACfC,OAAe,EACfC,YAAoB,EACpBC,QAAiB,EACjBC,eAAyB,EACzBC,gBAA0B;IA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AAM;QACjCG,iBAAiBO,QAAQuC,cAAc,GAAGjD,MAAM;QAChDI;IACF;AACF","ignoreList":[0]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* Gets the glob patterns for type definition directories in tsconfig.
|
|
4
|
+
* When isolatedDevBuild is enabled, Next.js uses different distDir paths:
|
|
5
|
+
* - Development: "{distDir}/dev"
|
|
6
|
+
* - Production: "{distDir}"
|
|
7
|
+
*/ export function getTypeDefinitionGlobPatterns(distDir, isolatedDevBuild) {
|
|
8
|
+
const distDirPosix = path.win32.sep === path.sep ? distDir.replaceAll(path.win32.sep, path.posix.sep) : distDir;
|
|
9
|
+
const typeGlobPatterns = [
|
|
10
|
+
`${distDirPosix}/types/**/*.ts`
|
|
11
|
+
];
|
|
12
|
+
// When isolatedDevBuild is enabled, include both .next/types and .next/dev/types
|
|
13
|
+
// to avoid tsconfig churn when switching between dev/build modes
|
|
14
|
+
if (isolatedDevBuild) {
|
|
15
|
+
typeGlobPatterns.push(process.env.NODE_ENV === 'development' ? `${distDirPosix.replace(/\/dev$/, '')}/types/**/*.ts` : `${distDirPosix}/dev/types/**/*.ts`);
|
|
16
|
+
// Sort for consistent order
|
|
17
|
+
typeGlobPatterns.sort((a, b)=>a.length - b.length);
|
|
18
|
+
}
|
|
19
|
+
return typeGlobPatterns;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Gets the absolute path to the dev types directory for filtering during type-checking.
|
|
23
|
+
* Returns null if isolatedDevBuild is disabled or in dev mode (where dev types are the main types).
|
|
24
|
+
*/ export function getDevTypesPath(baseDir, distDir, isolatedDevBuild) {
|
|
25
|
+
if (!isolatedDevBuild) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
29
|
+
if (isDev) {
|
|
30
|
+
// In dev mode, dev types are the main types, so no need to filter
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
// In build mode, dev types are at "{baseDir}/{distDir}/dev/types" and should be filtered
|
|
34
|
+
return path.join(baseDir, distDir, 'dev', 'types');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=type-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/typescript/type-paths.ts"],"sourcesContent":["import path from 'path'\n\n/**\n * Gets the glob patterns for type definition directories in tsconfig.\n * When isolatedDevBuild is enabled, Next.js uses different distDir paths:\n * - Development: \"{distDir}/dev\"\n * - Production: \"{distDir}\"\n */\nexport function getTypeDefinitionGlobPatterns(\n distDir: string,\n isolatedDevBuild: boolean\n): string[] {\n const distDirPosix =\n path.win32.sep === path.sep\n ? distDir.replaceAll(path.win32.sep, path.posix.sep)\n : distDir\n\n const typeGlobPatterns: string[] = [`${distDirPosix}/types/**/*.ts`]\n\n // When isolatedDevBuild is enabled, include both .next/types and .next/dev/types\n // to avoid tsconfig churn when switching between dev/build modes\n if (isolatedDevBuild) {\n typeGlobPatterns.push(\n process.env.NODE_ENV === 'development'\n ? // In dev, distDir is \"{distDir}/dev\", so also include \"{distDir}/types\"\n `${distDirPosix.replace(/\\/dev$/, '')}/types/**/*.ts`\n : // In build, distDir is \"{distDir}\", so also include \"{distDir}/dev/types\"\n `${distDirPosix}/dev/types/**/*.ts`\n )\n // Sort for consistent order\n typeGlobPatterns.sort((a, b) => a.length - b.length)\n }\n\n return typeGlobPatterns\n}\n\n/**\n * Gets the absolute path to the dev types directory for filtering during type-checking.\n * Returns null if isolatedDevBuild is disabled or in dev mode (where dev types are the main types).\n */\nexport function getDevTypesPath(\n baseDir: string,\n distDir: string,\n isolatedDevBuild: boolean\n): string | null {\n if (!isolatedDevBuild) {\n return null\n }\n\n const isDev = process.env.NODE_ENV === 'development'\n if (isDev) {\n // In dev mode, dev types are the main types, so no need to filter\n return null\n }\n\n // In build mode, dev types are at \"{baseDir}/{distDir}/dev/types\" and should be filtered\n return path.join(baseDir, distDir, 'dev', 'types')\n}\n"],"names":["path","getTypeDefinitionGlobPatterns","distDir","isolatedDevBuild","distDirPosix","win32","sep","replaceAll","posix","typeGlobPatterns","push","process","env","NODE_ENV","replace","sort","a","b","length","getDevTypesPath","baseDir","isDev","join"],"mappings":"AAAA,OAAOA,UAAU,OAAM;AAEvB;;;;;CAKC,GACD,OAAO,SAASC,8BACdC,OAAe,EACfC,gBAAyB;IAEzB,MAAMC,eACJJ,KAAKK,KAAK,CAACC,GAAG,KAAKN,KAAKM,GAAG,GACvBJ,QAAQK,UAAU,CAACP,KAAKK,KAAK,CAACC,GAAG,EAAEN,KAAKQ,KAAK,CAACF,GAAG,IACjDJ;IAEN,MAAMO,mBAA6B;QAAC,GAAGL,aAAa,cAAc,CAAC;KAAC;IAEpE,iFAAiF;IACjF,iEAAiE;IACjE,IAAID,kBAAkB;QACpBM,iBAAiBC,IAAI,CACnBC,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBAErB,GAAGT,aAAaU,OAAO,CAAC,UAAU,IAAI,cAAc,CAAC,GAErD,GAAGV,aAAa,kBAAkB,CAAC;QAEzC,4BAA4B;QAC5BK,iBAAiBM,IAAI,CAAC,CAACC,GAAGC,IAAMD,EAAEE,MAAM,GAAGD,EAAEC,MAAM;IACrD;IAEA,OAAOT;AACT;AAEA;;;CAGC,GACD,OAAO,SAASU,gBACdC,OAAe,EACflB,OAAe,EACfC,gBAAyB;IAEzB,IAAI,CAACA,kBAAkB;QACrB,OAAO;IACT;IAEA,MAAMkB,QAAQV,QAAQC,GAAG,CAACC,QAAQ,KAAK;IACvC,IAAIQ,OAAO;QACT,kEAAkE;QAClE,OAAO;IACT;IAEA,yFAAyF;IACzF,OAAOrB,KAAKsB,IAAI,CAACF,SAASlB,SAAS,OAAO;AAC5C","ignoreList":[0]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
2
|
import { bold, cyan, white } from '../picocolors';
|
|
4
3
|
import * as CommentJson from 'next/dist/compiled/comment-json';
|
|
5
4
|
import semver from 'next/dist/compiled/semver';
|
|
6
5
|
import os from 'os';
|
|
6
|
+
import { getTypeDefinitionGlobPatterns } from './type-paths';
|
|
7
7
|
import * as Log from '../../build/output/log';
|
|
8
|
+
import { defaultConfig } from '../../server/config-shared';
|
|
8
9
|
function getDesiredCompilerOptions(typescriptVersion, userTsConfig) {
|
|
9
10
|
var _userTsConfig_compilerOptions_module, _userTsConfig_compilerOptions, _userTsConfig_compilerOptions1;
|
|
10
11
|
// ModuleKind
|
|
@@ -211,22 +212,10 @@ export async function writeConfigurationDefaults(typescriptVersion, tsConfigPath
|
|
|
211
212
|
const _ = check;
|
|
212
213
|
}
|
|
213
214
|
}
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// When isolatedDevBuild is enabled, Next.js uses different distDir paths:
|
|
219
|
-
// - Development: "{distDir}/dev"
|
|
220
|
-
// - Production: "{distDir}"
|
|
221
|
-
// To prevent tsconfig updates when switching between dev/build modes,
|
|
222
|
-
// we proactively include both type paths regardless of current environment.
|
|
223
|
-
if (isolatedDevBuild !== false) {
|
|
224
|
-
nextAppTypes.push(process.env.NODE_ENV === 'development' ? // Here we remove "/dev" at the end of distDir for consistency.
|
|
225
|
-
`${distDirPosix.replace(/\/dev$/, '')}/types/**/*.ts` : // Here we add "/dev" at the end of distDir for consistency.
|
|
226
|
-
`${distDirPosix}/dev/types/**/*.ts`);
|
|
227
|
-
// Sort the array to ensure consistent order.
|
|
228
|
-
nextAppTypes.sort((a, b)=>a.length - b.length);
|
|
229
|
-
}
|
|
215
|
+
const resolvedIsolatedDevBuild = isolatedDevBuild === undefined ? defaultConfig.experimental.isolatedDevBuild : isolatedDevBuild;
|
|
216
|
+
// Get type definition glob patterns using shared utility to ensure consistency
|
|
217
|
+
// with other TypeScript infrastructure (e.g., runTypeCheck.ts)
|
|
218
|
+
const nextAppTypes = getTypeDefinitionGlobPatterns(distDir, resolvedIsolatedDevBuild);
|
|
230
219
|
if (!('include' in userTsConfig)) {
|
|
231
220
|
userTsConfig.include = hasAppDir ? [
|
|
232
221
|
'next-env.d.ts',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/typescript/writeConfigurationDefaults.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs'\nimport * as path from 'path'\nimport { bold, cyan, white } from '../picocolors'\nimport * as CommentJson from 'next/dist/compiled/comment-json'\nimport semver from 'next/dist/compiled/semver'\nimport os from 'os'\nimport type { CompilerOptions } from 'typescript'\nimport * as Log from '../../build/output/log'\n\ntype DesiredCompilerOptionsShape = {\n [K in keyof CompilerOptions]:\n | { suggested: any; reason?: string }\n | {\n parsedValue?: any\n parsedValues?: Array<any>\n value: any\n reason: string\n }\n}\n\nfunction getDesiredCompilerOptions(\n typescriptVersion: string,\n userTsConfig?: Record<string, any>\n): DesiredCompilerOptionsShape {\n // ModuleKind\n const moduleKindESNext = 'esnext'\n const moduleKindES2020 = 'es2020'\n const moduleKindPreserve = 'preserve'\n const moduleKindNodeNext = 'nodenext'\n const moduleKindNode16 = 'node16'\n const moduleKindCommonJS = 'commonjs'\n const moduleKindAMD = 'amd'\n\n // ModuleResolutionKind\n const moduleResolutionKindBundler = 'bundler'\n const moduleResolutionKindNode10 = 'node10'\n const moduleResolutionKindNode12 = 'node12'\n const moduleResolutionKindNodeJs = 'node'\n\n // Jsx\n const jsxEmitReactJSX = 'react-jsx'\n\n return {\n target: {\n suggested: 'ES2017',\n reason:\n 'For top-level `await`. Note: Next.js only polyfills for the esmodules target.',\n },\n // These are suggested values and will be set when not present in the\n // tsconfig.json\n lib: { suggested: ['dom', 'dom.iterable', 'esnext'] },\n allowJs: { suggested: true },\n skipLibCheck: { suggested: true },\n strict: { suggested: false },\n noEmit: { suggested: true },\n incremental: { suggested: true },\n\n // These values are required and cannot be changed by the user\n // Keep this in sync with the webpack config\n // 'parsedValue' matches the output value from ts.parseJsonConfigFileContent()\n module: {\n parsedValue: moduleKindESNext,\n // All of these values work:\n parsedValues: [\n semver.gte(typescriptVersion, '5.4.0') && moduleKindPreserve,\n moduleKindES2020,\n moduleKindESNext,\n moduleKindCommonJS,\n moduleKindAMD,\n moduleKindNodeNext,\n moduleKindNode16,\n ],\n value: 'esnext',\n reason: 'for dynamic import() support',\n },\n // TODO: Semver check not needed once Next.js repo uses 5.4.\n ...(semver.gte(typescriptVersion, '5.4.0') &&\n userTsConfig?.compilerOptions?.module?.toLowerCase() === moduleKindPreserve\n ? {\n // TypeScript 5.4 introduced `Preserve`. Using `Preserve` implies\n // - `moduleResolution` is `Bundler`\n // - `esModuleInterop` is `true`\n // - `resolveJsonModule` is `true`\n // This means that if the user is using Preserve, they don't need these options\n }\n : {\n esModuleInterop: {\n value: true,\n reason: 'requirement for SWC / babel',\n },\n moduleResolution: {\n // In TypeScript 5.0, `NodeJs` has renamed to `Node10`\n parsedValue: moduleResolutionKindBundler,\n // All of these values work:\n parsedValues: [\n moduleResolutionKindNode10,\n moduleResolutionKindNodeJs,\n // only newer TypeScript versions have this field, it\n // will be filtered for new versions of TypeScript\n moduleResolutionKindNode12,\n moduleKindNode16,\n moduleKindNodeNext,\n moduleResolutionKindBundler,\n ].filter((val) => typeof val !== 'undefined'),\n value: 'node',\n reason: 'to match webpack resolution',\n },\n resolveJsonModule: {\n value: true,\n reason: 'to match webpack resolution',\n },\n }),\n ...(userTsConfig?.compilerOptions?.verbatimModuleSyntax === true\n ? undefined\n : {\n isolatedModules: {\n value: true,\n reason: 'requirement for SWC / Babel',\n },\n }),\n jsx: {\n parsedValue: jsxEmitReactJSX,\n value: 'react-jsx',\n reason: 'next.js uses the React automatic runtime',\n },\n } satisfies DesiredCompilerOptionsShape\n}\n\nexport function getRequiredConfiguration(\n typescript: typeof import('typescript')\n): Partial<import('typescript').CompilerOptions> {\n const res: Partial<import('typescript').CompilerOptions> = {}\n const typescriptVersion = typescript.version\n\n const desiredCompilerOptions = getDesiredCompilerOptions(typescriptVersion)\n for (const optionKey of Object.keys(desiredCompilerOptions)) {\n const ev = desiredCompilerOptions[optionKey]\n if (!('value' in ev)) {\n continue\n }\n\n const value = ev.parsedValue ?? ev.value\n\n // Convert string values back to TypeScript enum values\n if (optionKey === 'module' && typeof value === 'string') {\n const moduleMap: Record<string, import('typescript').ModuleKind> = {\n esnext: typescript.ModuleKind.ESNext,\n es2020: typescript.ModuleKind.ES2020,\n ...(typescript.ModuleKind.Preserve !== undefined\n ? { preserve: typescript.ModuleKind.Preserve }\n : {}),\n nodenext: typescript.ModuleKind.NodeNext,\n node16: typescript.ModuleKind.Node16,\n commonjs: typescript.ModuleKind.CommonJS,\n amd: typescript.ModuleKind.AMD,\n }\n res[optionKey] = moduleMap[value.toLowerCase()] ?? value\n } else if (optionKey === 'moduleResolution' && typeof value === 'string') {\n const moduleResolutionMap: Record<\n string,\n import('typescript').ModuleResolutionKind\n > = {\n bundler: typescript.ModuleResolutionKind.Bundler,\n node10: typescript.ModuleResolutionKind.Node10,\n node12: (typescript.ModuleResolutionKind as any).Node12,\n node: typescript.ModuleResolutionKind.NodeJs,\n }\n res[optionKey] = moduleResolutionMap[value.toLowerCase()] ?? value\n } else if (optionKey === 'jsx' && typeof value === 'string') {\n const jsxMap: Record<string, import('typescript').JsxEmit> = {\n 'react-jsx': typescript.JsxEmit.ReactJSX,\n }\n res[optionKey] = jsxMap[value.toLowerCase()] ?? value\n } else {\n res[optionKey] = value\n }\n }\n\n return res\n}\n\nconst localDevTestFilesExcludeAction =\n 'NEXT_PRIVATE_LOCAL_DEV_TEST_FILES_EXCLUDE'\n\nexport async function writeConfigurationDefaults(\n typescriptVersion: string,\n tsConfigPath: string,\n isFirstTimeSetup: boolean,\n hasAppDir: boolean,\n distDir: string,\n hasPagesDir: boolean,\n isolatedDevBuild: boolean | undefined\n): Promise<void> {\n if (isFirstTimeSetup) {\n writeFileSync(tsConfigPath, '{}' + os.EOL)\n }\n\n const userTsConfigContent = readFileSync(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = CommentJson.parse(userTsConfigContent)\n\n // Bail automatic setup when the user has extended or referenced another config\n if ('extends' in userTsConfig || 'references' in userTsConfig) {\n return\n }\n\n if (userTsConfig?.compilerOptions == null) {\n userTsConfig.compilerOptions = {}\n isFirstTimeSetup = true\n }\n\n const desiredCompilerOptions = getDesiredCompilerOptions(\n typescriptVersion,\n userTsConfig\n )\n\n const suggestedActions: string[] = []\n const requiredActions: string[] = []\n for (const optionKey in desiredCompilerOptions) {\n const check = desiredCompilerOptions[optionKey]\n if ('suggested' in check) {\n if (!(optionKey in userTsConfig?.compilerOptions)) {\n userTsConfig.compilerOptions[optionKey] = check.suggested\n suggestedActions.push(\n cyan(optionKey) +\n ' was set to ' +\n bold(check.suggested) +\n (check.reason ? ` (${check.reason})` : '')\n )\n }\n } else if ('value' in check) {\n let existingValue = userTsConfig?.compilerOptions?.[optionKey]\n\n if (typeof existingValue === 'string') {\n existingValue = existingValue.toLowerCase()\n }\n\n const shouldWriteRequiredValue = () => {\n // Check if the option has multiple allowed values\n if (check.parsedValues) {\n return !check.parsedValues.includes(existingValue)\n }\n\n // Check if the option has a single parsed value\n if (check.parsedValue) {\n return check.parsedValue !== existingValue\n }\n\n // Fall back to direct value comparison\n return check.value !== existingValue\n }\n\n if (shouldWriteRequiredValue()) {\n if (!userTsConfig.compilerOptions) {\n userTsConfig.compilerOptions = {}\n }\n userTsConfig.compilerOptions[optionKey] = check.value\n requiredActions.push(\n cyan(optionKey) +\n ' was set to ' +\n bold(check.value) +\n ` (${check.reason})`\n )\n }\n } else {\n const _: never = check\n }\n }\n\n const distDirPosix =\n path.win32.sep === path.sep\n ? distDir.replaceAll(path.win32.sep, path.posix.sep)\n : distDir\n const nextAppTypes: string[] = [`${distDirPosix}/types/**/*.ts`]\n\n // When isolatedDevBuild is enabled, Next.js uses different distDir paths:\n // - Development: \"{distDir}/dev\"\n // - Production: \"{distDir}\"\n // To prevent tsconfig updates when switching between dev/build modes,\n // we proactively include both type paths regardless of current environment.\n if (isolatedDevBuild !== false) {\n nextAppTypes.push(\n process.env.NODE_ENV === 'development'\n ? // In dev, distDir is \"{distDir}/dev\", which is already in the array above, but we also need \"{distDir}/types\".\n // Here we remove \"/dev\" at the end of distDir for consistency.\n `${distDirPosix.replace(/\\/dev$/, '')}/types/**/*.ts`\n : // In build, distDir is \"{distDir}\", which is already in the array above, but we also need \"{distDir}/dev/types\".\n // Here we add \"/dev\" at the end of distDir for consistency.\n `${distDirPosix}/dev/types/**/*.ts`\n )\n // Sort the array to ensure consistent order.\n nextAppTypes.sort((a, b) => a.length - b.length)\n }\n\n if (!('include' in userTsConfig)) {\n userTsConfig.include = hasAppDir\n ? ['next-env.d.ts', ...nextAppTypes, '**/*.mts', '**/*.ts', '**/*.tsx']\n : ['next-env.d.ts', '**/*.mts', '**/*.ts', '**/*.tsx']\n suggestedActions.push(\n cyan('include') +\n ' was set to ' +\n bold(\n hasAppDir\n ? `['next-env.d.ts', ${nextAppTypes.map((type) => `'${type}'`).join(', ')}, '**/*.mts', '**/*.ts', '**/*.tsx']`\n : `['next-env.d.ts', '**/*.mts', '**/*.ts', '**/*.tsx']`\n )\n )\n } else if (hasAppDir) {\n const missingFromResolved = []\n for (const type of nextAppTypes) {\n if (!userTsConfig.include.includes(type)) {\n missingFromResolved.push(type)\n }\n }\n\n if (missingFromResolved.length > 0) {\n if (!Array.isArray(userTsConfig.include)) {\n userTsConfig.include = []\n }\n\n missingFromResolved.forEach((item) => {\n userTsConfig.include.push(item)\n suggestedActions.push(\n cyan('include') + ' was updated to add ' + bold(`'${item}'`)\n )\n })\n }\n }\n\n // Enable the Next.js typescript plugin.\n if (hasAppDir) {\n // Check if the config or the resolved config has the plugin already.\n const plugins = [\n ...(Array.isArray(userTsConfig?.plugins) ? userTsConfig.plugins : []),\n ...(userTsConfig.compilerOptions &&\n Array.isArray(userTsConfig.compilerOptions.plugins)\n ? userTsConfig.compilerOptions.plugins\n : []),\n ]\n const hasNextPlugin = plugins.some(\n ({ name }: { name: string }) => name === 'next'\n )\n\n // If the TS config extends on another config, we can't add the `plugin` field\n // because that will override the parent config's plugins.\n // Instead we have to show a message to the user to add the plugin manually.\n if (\n !userTsConfig.compilerOptions ||\n (plugins.length &&\n !hasNextPlugin &&\n 'extends' in userTsConfig &&\n (!userTsConfig.compilerOptions ||\n !userTsConfig.compilerOptions.plugins))\n ) {\n Log.info(\n `\\nYour ${bold(\n 'tsconfig.json'\n )} extends another configuration, which means we cannot add the Next.js TypeScript plugin automatically. To improve your development experience, we recommend adding the Next.js plugin (\\`${cyan(\n '\"plugins\": [{ \"name\": \"next\" }]'\n )}\\`) manually to your TypeScript configuration. Learn more: https://nextjs.org/docs/app/api-reference/config/typescript#the-typescript-plugin\\n`\n )\n } else if (!hasNextPlugin) {\n if (!('plugins' in userTsConfig.compilerOptions)) {\n userTsConfig.compilerOptions.plugins = []\n }\n userTsConfig.compilerOptions.plugins.push({ name: 'next' })\n suggestedActions.push(\n cyan('plugins') + ' was updated to add ' + bold(`{ name: 'next' }`)\n )\n }\n\n // If `strict` is set to `false` and `strictNullChecks` is set to `false`,\n // then set `strictNullChecks` to `true`.\n if (\n hasPagesDir &&\n hasAppDir &&\n !userTsConfig?.compilerOptions?.strict &&\n !('strictNullChecks' in userTsConfig?.compilerOptions)\n ) {\n userTsConfig.compilerOptions.strictNullChecks = true\n suggestedActions.push(\n cyan('strictNullChecks') + ' was set to ' + bold(`true`)\n )\n }\n }\n\n if (!('exclude' in userTsConfig)) {\n userTsConfig.exclude = ['node_modules']\n suggestedActions.push(\n cyan('exclude') + ' was set to ' + bold(`['node_modules']`)\n )\n }\n\n // During local development inside Next.js repo, exclude the test files coverage by the local tsconfig\n if (process.env.NEXT_PRIVATE_LOCAL_DEV && userTsConfig.exclude) {\n const tsGlob = '**/*.test.ts'\n const tsxGlob = '**/*.test.tsx'\n let hasUpdates = false\n if (!userTsConfig.exclude.includes(tsGlob)) {\n userTsConfig.exclude.push(tsGlob)\n hasUpdates = true\n }\n if (!userTsConfig.exclude.includes(tsxGlob)) {\n userTsConfig.exclude.push(tsxGlob)\n hasUpdates = true\n }\n\n if (hasUpdates) {\n requiredActions.push(localDevTestFilesExcludeAction)\n }\n }\n\n if (suggestedActions.length < 1 && requiredActions.length < 1) {\n return\n }\n\n writeFileSync(\n tsConfigPath,\n CommentJson.stringify(userTsConfig, null, 2) + os.EOL\n )\n\n Log.info('')\n if (isFirstTimeSetup) {\n Log.info(\n `We detected TypeScript in your project and created a ${cyan(\n 'tsconfig.json'\n )} file for you.`\n )\n return\n }\n\n Log.info(\n `We detected TypeScript in your project and reconfigured your ${cyan(\n 'tsconfig.json'\n )} file for you.${\n userTsConfig.compilerOptions?.strict\n ? ''\n : ` Strict-mode is set to ${cyan('false')} by default.`\n }`\n )\n\n if (suggestedActions.length) {\n Log.info(\n `The following suggested values were added to your ${cyan(\n 'tsconfig.json'\n )}. These values ${cyan('can be changed')} to fit your project's needs:\\n`\n )\n\n suggestedActions.forEach((action) => Log.info(`\\t- ${action}`))\n\n Log.info('')\n }\n\n const requiredActionsToBeLogged = process.env.NEXT_PRIVATE_LOCAL_DEV\n ? requiredActions.filter(\n (action) => action !== localDevTestFilesExcludeAction\n )\n : requiredActions\n\n if (requiredActionsToBeLogged.length) {\n Log.info(\n `The following ${white('mandatory changes')} were made to your ${cyan(\n 'tsconfig.json'\n )}:\\n`\n )\n\n requiredActionsToBeLogged.forEach((action) => Log.info(`\\t- ${action}`))\n\n Log.info('')\n }\n}\n"],"names":["readFileSync","writeFileSync","path","bold","cyan","white","CommentJson","semver","os","Log","getDesiredCompilerOptions","typescriptVersion","userTsConfig","moduleKindESNext","moduleKindES2020","moduleKindPreserve","moduleKindNodeNext","moduleKindNode16","moduleKindCommonJS","moduleKindAMD","moduleResolutionKindBundler","moduleResolutionKindNode10","moduleResolutionKindNode12","moduleResolutionKindNodeJs","jsxEmitReactJSX","target","suggested","reason","lib","allowJs","skipLibCheck","strict","noEmit","incremental","module","parsedValue","parsedValues","gte","value","compilerOptions","toLowerCase","esModuleInterop","moduleResolution","filter","val","resolveJsonModule","verbatimModuleSyntax","undefined","isolatedModules","jsx","getRequiredConfiguration","typescript","res","version","desiredCompilerOptions","optionKey","Object","keys","ev","moduleMap","esnext","ModuleKind","ESNext","es2020","ES2020","Preserve","preserve","nodenext","NodeNext","node16","Node16","commonjs","CommonJS","amd","AMD","moduleResolutionMap","bundler","ModuleResolutionKind","Bundler","node10","Node10","node12","Node12","node","NodeJs","jsxMap","JsxEmit","ReactJSX","localDevTestFilesExcludeAction","writeConfigurationDefaults","tsConfigPath","isFirstTimeSetup","hasAppDir","distDir","hasPagesDir","isolatedDevBuild","EOL","userTsConfigContent","encoding","parse","suggestedActions","requiredActions","check","push","existingValue","shouldWriteRequiredValue","includes","_","distDirPosix","win32","sep","replaceAll","posix","nextAppTypes","process","env","NODE_ENV","replace","sort","a","b","length","include","map","type","join","missingFromResolved","Array","isArray","forEach","item","plugins","hasNextPlugin","some","name","info","strictNullChecks","exclude","NEXT_PRIVATE_LOCAL_DEV","tsGlob","tsxGlob","hasUpdates","stringify","action","requiredActionsToBeLogged"],"mappings":"AAAA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAChD,YAAYC,UAAU,OAAM;AAC5B,SAASC,IAAI,EAAEC,IAAI,EAAEC,KAAK,QAAQ,gBAAe;AACjD,YAAYC,iBAAiB,kCAAiC;AAC9D,OAAOC,YAAY,4BAA2B;AAC9C,OAAOC,QAAQ,KAAI;AAEnB,YAAYC,SAAS,yBAAwB;AAa7C,SAASC,0BACPC,iBAAyB,EACzBC,YAAkC;QAuDhCA,sCAAAA,+BAmCIA;IAxFN,aAAa;IACb,MAAMC,mBAAmB;IACzB,MAAMC,mBAAmB;IACzB,MAAMC,qBAAqB;IAC3B,MAAMC,qBAAqB;IAC3B,MAAMC,mBAAmB;IACzB,MAAMC,qBAAqB;IAC3B,MAAMC,gBAAgB;IA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,iBACA,cAAc,CAAC;QAEnB;IACF;IAEAK,IAAI8H,IAAI,CACN,CAAC,6DAA6D,EAAEnI,KAC9D,iBACA,cAAc,EACdQ,EAAAA,gCAAAA,aAAa2B,eAAe,qBAA5B3B,8BAA8BmB,MAAM,IAChC,KACA,CAAC,uBAAuB,EAAE3B,KAAK,SAAS,YAAY,CAAC,EACzD;IAGJ,IAAIgG,iBAAiBqB,MAAM,EAAE;QAC3BhH,IAAI8H,IAAI,CACN,CAAC,kDAAkD,EAAEnI,KACnD,iBACA,eAAe,EAAEA,KAAK,kBAAkB,+BAA+B,CAAC;QAG5EgG,iBAAiB6B,OAAO,CAAC,CAACc,SAAWtI,IAAI8H,IAAI,CAAC,CAAC,IAAI,EAAEQ,QAAQ;QAE7DtI,IAAI8H,IAAI,CAAC;IACX;IAEA,MAAMS,4BAA4B9B,QAAQC,GAAG,CAACuB,sBAAsB,GAChErC,gBAAgB1D,MAAM,CACpB,CAACoG,SAAWA,WAAWvD,kCAEzBa;IAEJ,IAAI2C,0BAA0BvB,MAAM,EAAE;QACpChH,IAAI8H,IAAI,CACN,CAAC,cAAc,EAAElI,MAAM,qBAAqB,mBAAmB,EAAED,KAC/D,iBACA,GAAG,CAAC;QAGR4I,0BAA0Bf,OAAO,CAAC,CAACc,SAAWtI,IAAI8H,IAAI,CAAC,CAAC,IAAI,EAAEQ,QAAQ;QAEtEtI,IAAI8H,IAAI,CAAC;IACX;AACF","ignoreList":[0]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/typescript/writeConfigurationDefaults.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs'\nimport { bold, cyan, white } from '../picocolors'\nimport * as CommentJson from 'next/dist/compiled/comment-json'\nimport semver from 'next/dist/compiled/semver'\nimport os from 'os'\nimport type { CompilerOptions } from 'typescript'\nimport { getTypeDefinitionGlobPatterns } from './type-paths'\nimport * as Log from '../../build/output/log'\nimport { defaultConfig } from '../../server/config-shared'\n\ntype DesiredCompilerOptionsShape = {\n [K in keyof CompilerOptions]:\n | { suggested: any; reason?: string }\n | {\n parsedValue?: any\n parsedValues?: Array<any>\n value: any\n reason: string\n }\n}\n\nfunction getDesiredCompilerOptions(\n typescriptVersion: string,\n userTsConfig?: Record<string, any>\n): DesiredCompilerOptionsShape {\n // ModuleKind\n const moduleKindESNext = 'esnext'\n const moduleKindES2020 = 'es2020'\n const moduleKindPreserve = 'preserve'\n const moduleKindNodeNext = 'nodenext'\n const moduleKindNode16 = 'node16'\n const moduleKindCommonJS = 'commonjs'\n const moduleKindAMD = 'amd'\n\n // ModuleResolutionKind\n const moduleResolutionKindBundler = 'bundler'\n const moduleResolutionKindNode10 = 'node10'\n const moduleResolutionKindNode12 = 'node12'\n const moduleResolutionKindNodeJs = 'node'\n\n // Jsx\n const jsxEmitReactJSX = 'react-jsx'\n\n return {\n target: {\n suggested: 'ES2017',\n reason:\n 'For top-level `await`. Note: Next.js only polyfills for the esmodules target.',\n },\n // These are suggested values and will be set when not present in the\n // tsconfig.json\n lib: { suggested: ['dom', 'dom.iterable', 'esnext'] },\n allowJs: { suggested: true },\n skipLibCheck: { suggested: true },\n strict: { suggested: false },\n noEmit: { suggested: true },\n incremental: { suggested: true },\n\n // These values are required and cannot be changed by the user\n // Keep this in sync with the webpack config\n // 'parsedValue' matches the output value from ts.parseJsonConfigFileContent()\n module: {\n parsedValue: moduleKindESNext,\n // All of these values work:\n parsedValues: [\n semver.gte(typescriptVersion, '5.4.0') && moduleKindPreserve,\n moduleKindES2020,\n moduleKindESNext,\n moduleKindCommonJS,\n moduleKindAMD,\n moduleKindNodeNext,\n moduleKindNode16,\n ],\n value: 'esnext',\n reason: 'for dynamic import() support',\n },\n // TODO: Semver check not needed once Next.js repo uses 5.4.\n ...(semver.gte(typescriptVersion, '5.4.0') &&\n userTsConfig?.compilerOptions?.module?.toLowerCase() === moduleKindPreserve\n ? {\n // TypeScript 5.4 introduced `Preserve`. Using `Preserve` implies\n // - `moduleResolution` is `Bundler`\n // - `esModuleInterop` is `true`\n // - `resolveJsonModule` is `true`\n // This means that if the user is using Preserve, they don't need these options\n }\n : {\n esModuleInterop: {\n value: true,\n reason: 'requirement for SWC / babel',\n },\n moduleResolution: {\n // In TypeScript 5.0, `NodeJs` has renamed to `Node10`\n parsedValue: moduleResolutionKindBundler,\n // All of these values work:\n parsedValues: [\n moduleResolutionKindNode10,\n moduleResolutionKindNodeJs,\n // only newer TypeScript versions have this field, it\n // will be filtered for new versions of TypeScript\n moduleResolutionKindNode12,\n moduleKindNode16,\n moduleKindNodeNext,\n moduleResolutionKindBundler,\n ].filter((val) => typeof val !== 'undefined'),\n value: 'node',\n reason: 'to match webpack resolution',\n },\n resolveJsonModule: {\n value: true,\n reason: 'to match webpack resolution',\n },\n }),\n ...(userTsConfig?.compilerOptions?.verbatimModuleSyntax === true\n ? undefined\n : {\n isolatedModules: {\n value: true,\n reason: 'requirement for SWC / Babel',\n },\n }),\n jsx: {\n parsedValue: jsxEmitReactJSX,\n value: 'react-jsx',\n reason: 'next.js uses the React automatic runtime',\n },\n } satisfies DesiredCompilerOptionsShape\n}\n\nexport function getRequiredConfiguration(\n typescript: typeof import('typescript')\n): Partial<import('typescript').CompilerOptions> {\n const res: Partial<import('typescript').CompilerOptions> = {}\n const typescriptVersion = typescript.version\n\n const desiredCompilerOptions = getDesiredCompilerOptions(typescriptVersion)\n for (const optionKey of Object.keys(desiredCompilerOptions)) {\n const ev = desiredCompilerOptions[optionKey]\n if (!('value' in ev)) {\n continue\n }\n\n const value = ev.parsedValue ?? ev.value\n\n // Convert string values back to TypeScript enum values\n if (optionKey === 'module' && typeof value === 'string') {\n const moduleMap: Record<string, import('typescript').ModuleKind> = {\n esnext: typescript.ModuleKind.ESNext,\n es2020: typescript.ModuleKind.ES2020,\n ...(typescript.ModuleKind.Preserve !== undefined\n ? { preserve: typescript.ModuleKind.Preserve }\n : {}),\n nodenext: typescript.ModuleKind.NodeNext,\n node16: typescript.ModuleKind.Node16,\n commonjs: typescript.ModuleKind.CommonJS,\n amd: typescript.ModuleKind.AMD,\n }\n res[optionKey] = moduleMap[value.toLowerCase()] ?? value\n } else if (optionKey === 'moduleResolution' && typeof value === 'string') {\n const moduleResolutionMap: Record<\n string,\n import('typescript').ModuleResolutionKind\n > = {\n bundler: typescript.ModuleResolutionKind.Bundler,\n node10: typescript.ModuleResolutionKind.Node10,\n node12: (typescript.ModuleResolutionKind as any).Node12,\n node: typescript.ModuleResolutionKind.NodeJs,\n }\n res[optionKey] = moduleResolutionMap[value.toLowerCase()] ?? value\n } else if (optionKey === 'jsx' && typeof value === 'string') {\n const jsxMap: Record<string, import('typescript').JsxEmit> = {\n 'react-jsx': typescript.JsxEmit.ReactJSX,\n }\n res[optionKey] = jsxMap[value.toLowerCase()] ?? value\n } else {\n res[optionKey] = value\n }\n }\n\n return res\n}\n\nconst localDevTestFilesExcludeAction =\n 'NEXT_PRIVATE_LOCAL_DEV_TEST_FILES_EXCLUDE'\n\nexport async function writeConfigurationDefaults(\n typescriptVersion: string,\n tsConfigPath: string,\n isFirstTimeSetup: boolean,\n hasAppDir: boolean,\n distDir: string,\n hasPagesDir: boolean,\n isolatedDevBuild: boolean | undefined\n): Promise<void> {\n if (isFirstTimeSetup) {\n writeFileSync(tsConfigPath, '{}' + os.EOL)\n }\n\n const userTsConfigContent = readFileSync(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = CommentJson.parse(userTsConfigContent)\n\n // Bail automatic setup when the user has extended or referenced another config\n if ('extends' in userTsConfig || 'references' in userTsConfig) {\n return\n }\n\n if (userTsConfig?.compilerOptions == null) {\n userTsConfig.compilerOptions = {}\n isFirstTimeSetup = true\n }\n\n const desiredCompilerOptions = getDesiredCompilerOptions(\n typescriptVersion,\n userTsConfig\n )\n\n const suggestedActions: string[] = []\n const requiredActions: string[] = []\n for (const optionKey in desiredCompilerOptions) {\n const check = desiredCompilerOptions[optionKey]\n if ('suggested' in check) {\n if (!(optionKey in userTsConfig?.compilerOptions)) {\n userTsConfig.compilerOptions[optionKey] = check.suggested\n suggestedActions.push(\n cyan(optionKey) +\n ' was set to ' +\n bold(check.suggested) +\n (check.reason ? ` (${check.reason})` : '')\n )\n }\n } else if ('value' in check) {\n let existingValue = userTsConfig?.compilerOptions?.[optionKey]\n\n if (typeof existingValue === 'string') {\n existingValue = existingValue.toLowerCase()\n }\n\n const shouldWriteRequiredValue = () => {\n // Check if the option has multiple allowed values\n if (check.parsedValues) {\n return !check.parsedValues.includes(existingValue)\n }\n\n // Check if the option has a single parsed value\n if (check.parsedValue) {\n return check.parsedValue !== existingValue\n }\n\n // Fall back to direct value comparison\n return check.value !== existingValue\n }\n\n if (shouldWriteRequiredValue()) {\n if (!userTsConfig.compilerOptions) {\n userTsConfig.compilerOptions = {}\n }\n userTsConfig.compilerOptions[optionKey] = check.value\n requiredActions.push(\n cyan(optionKey) +\n ' was set to ' +\n bold(check.value) +\n ` (${check.reason})`\n )\n }\n } else {\n const _: never = check\n }\n }\n\n const resolvedIsolatedDevBuild =\n isolatedDevBuild === undefined\n ? defaultConfig.experimental.isolatedDevBuild\n : isolatedDevBuild\n\n // Get type definition glob patterns using shared utility to ensure consistency\n // with other TypeScript infrastructure (e.g., runTypeCheck.ts)\n const nextAppTypes = getTypeDefinitionGlobPatterns(\n distDir,\n resolvedIsolatedDevBuild\n )\n\n if (!('include' in userTsConfig)) {\n userTsConfig.include = hasAppDir\n ? ['next-env.d.ts', ...nextAppTypes, '**/*.mts', '**/*.ts', '**/*.tsx']\n : ['next-env.d.ts', '**/*.mts', '**/*.ts', '**/*.tsx']\n suggestedActions.push(\n cyan('include') +\n ' was set to ' +\n bold(\n hasAppDir\n ? `['next-env.d.ts', ${nextAppTypes.map((type) => `'${type}'`).join(', ')}, '**/*.mts', '**/*.ts', '**/*.tsx']`\n : `['next-env.d.ts', '**/*.mts', '**/*.ts', '**/*.tsx']`\n )\n )\n } else if (hasAppDir) {\n const missingFromResolved = []\n for (const type of nextAppTypes) {\n if (!userTsConfig.include.includes(type)) {\n missingFromResolved.push(type)\n }\n }\n\n if (missingFromResolved.length > 0) {\n if (!Array.isArray(userTsConfig.include)) {\n userTsConfig.include = []\n }\n\n missingFromResolved.forEach((item) => {\n userTsConfig.include.push(item)\n suggestedActions.push(\n cyan('include') + ' was updated to add ' + bold(`'${item}'`)\n )\n })\n }\n }\n\n // Enable the Next.js typescript plugin.\n if (hasAppDir) {\n // Check if the config or the resolved config has the plugin already.\n const plugins = [\n ...(Array.isArray(userTsConfig?.plugins) ? userTsConfig.plugins : []),\n ...(userTsConfig.compilerOptions &&\n Array.isArray(userTsConfig.compilerOptions.plugins)\n ? userTsConfig.compilerOptions.plugins\n : []),\n ]\n const hasNextPlugin = plugins.some(\n ({ name }: { name: string }) => name === 'next'\n )\n\n // If the TS config extends on another config, we can't add the `plugin` field\n // because that will override the parent config's plugins.\n // Instead we have to show a message to the user to add the plugin manually.\n if (\n !userTsConfig.compilerOptions ||\n (plugins.length &&\n !hasNextPlugin &&\n 'extends' in userTsConfig &&\n (!userTsConfig.compilerOptions ||\n !userTsConfig.compilerOptions.plugins))\n ) {\n Log.info(\n `\\nYour ${bold(\n 'tsconfig.json'\n )} extends another configuration, which means we cannot add the Next.js TypeScript plugin automatically. To improve your development experience, we recommend adding the Next.js plugin (\\`${cyan(\n '\"plugins\": [{ \"name\": \"next\" }]'\n )}\\`) manually to your TypeScript configuration. Learn more: https://nextjs.org/docs/app/api-reference/config/typescript#the-typescript-plugin\\n`\n )\n } else if (!hasNextPlugin) {\n if (!('plugins' in userTsConfig.compilerOptions)) {\n userTsConfig.compilerOptions.plugins = []\n }\n userTsConfig.compilerOptions.plugins.push({ name: 'next' })\n suggestedActions.push(\n cyan('plugins') + ' was updated to add ' + bold(`{ name: 'next' }`)\n )\n }\n\n // If `strict` is set to `false` and `strictNullChecks` is set to `false`,\n // then set `strictNullChecks` to `true`.\n if (\n hasPagesDir &&\n hasAppDir &&\n !userTsConfig?.compilerOptions?.strict &&\n !('strictNullChecks' in userTsConfig?.compilerOptions)\n ) {\n userTsConfig.compilerOptions.strictNullChecks = true\n suggestedActions.push(\n cyan('strictNullChecks') + ' was set to ' + bold(`true`)\n )\n }\n }\n\n if (!('exclude' in userTsConfig)) {\n userTsConfig.exclude = ['node_modules']\n suggestedActions.push(\n cyan('exclude') + ' was set to ' + bold(`['node_modules']`)\n )\n }\n\n // During local development inside Next.js repo, exclude the test files coverage by the local tsconfig\n if (process.env.NEXT_PRIVATE_LOCAL_DEV && userTsConfig.exclude) {\n const tsGlob = '**/*.test.ts'\n const tsxGlob = '**/*.test.tsx'\n let hasUpdates = false\n if (!userTsConfig.exclude.includes(tsGlob)) {\n userTsConfig.exclude.push(tsGlob)\n hasUpdates = true\n }\n if (!userTsConfig.exclude.includes(tsxGlob)) {\n userTsConfig.exclude.push(tsxGlob)\n hasUpdates = true\n }\n\n if (hasUpdates) {\n requiredActions.push(localDevTestFilesExcludeAction)\n }\n }\n\n if (suggestedActions.length < 1 && requiredActions.length < 1) {\n return\n }\n\n writeFileSync(\n tsConfigPath,\n CommentJson.stringify(userTsConfig, null, 2) + os.EOL\n )\n\n Log.info('')\n if (isFirstTimeSetup) {\n Log.info(\n `We detected TypeScript in your project and created a ${cyan(\n 'tsconfig.json'\n )} file for you.`\n )\n return\n }\n\n Log.info(\n `We detected TypeScript in your project and reconfigured your ${cyan(\n 'tsconfig.json'\n )} file for you.${\n userTsConfig.compilerOptions?.strict\n ? ''\n : ` Strict-mode is set to ${cyan('false')} by default.`\n }`\n )\n\n if (suggestedActions.length) {\n Log.info(\n `The following suggested values were added to your ${cyan(\n 'tsconfig.json'\n )}. These values ${cyan('can be changed')} to fit your project's needs:\\n`\n )\n\n suggestedActions.forEach((action) => Log.info(`\\t- ${action}`))\n\n Log.info('')\n }\n\n const requiredActionsToBeLogged = process.env.NEXT_PRIVATE_LOCAL_DEV\n ? requiredActions.filter(\n (action) => action !== localDevTestFilesExcludeAction\n )\n : requiredActions\n\n if (requiredActionsToBeLogged.length) {\n Log.info(\n `The following ${white('mandatory changes')} were made to your ${cyan(\n 'tsconfig.json'\n )}:\\n`\n )\n\n requiredActionsToBeLogged.forEach((action) => Log.info(`\\t- ${action}`))\n\n Log.info('')\n }\n}\n"],"names":["readFileSync","writeFileSync","bold","cyan","white","CommentJson","semver","os","getTypeDefinitionGlobPatterns","Log","defaultConfig","getDesiredCompilerOptions","typescriptVersion","userTsConfig","moduleKindESNext","moduleKindES2020","moduleKindPreserve","moduleKindNodeNext","moduleKindNode16","moduleKindCommonJS","moduleKindAMD","moduleResolutionKindBundler","moduleResolutionKindNode10","moduleResolutionKindNode12","moduleResolutionKindNodeJs","jsxEmitReactJSX","target","suggested","reason","lib","allowJs","skipLibCheck","strict","noEmit","incremental","module","parsedValue","parsedValues","gte","value","compilerOptions","toLowerCase","esModuleInterop","moduleResolution","filter","val","resolveJsonModule","verbatimModuleSyntax","undefined","isolatedModules","jsx","getRequiredConfiguration","typescript","res","version","desiredCompilerOptions","optionKey","Object","keys","ev","moduleMap","esnext","ModuleKind","ESNext","es2020","ES2020","Preserve","preserve","nodenext","NodeNext","node16","Node16","commonjs","CommonJS","amd","AMD","moduleResolutionMap","bundler","ModuleResolutionKind","Bundler","node10","Node10","node12","Node12","node","NodeJs","jsxMap","JsxEmit","ReactJSX","localDevTestFilesExcludeAction","writeConfigurationDefaults","tsConfigPath","isFirstTimeSetup","hasAppDir","distDir","hasPagesDir","isolatedDevBuild","EOL","userTsConfigContent","encoding","parse","suggestedActions","requiredActions","check","push","existingValue","shouldWriteRequiredValue","includes","_","resolvedIsolatedDevBuild","experimental","nextAppTypes","include","map","type","join","missingFromResolved","length","Array","isArray","forEach","item","plugins","hasNextPlugin","some","name","info","strictNullChecks","exclude","process","env","NEXT_PRIVATE_LOCAL_DEV","tsGlob","tsxGlob","hasUpdates","stringify","action","requiredActionsToBeLogged"],"mappings":"AAAA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAChD,SAASC,IAAI,EAAEC,IAAI,EAAEC,KAAK,QAAQ,gBA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AAE3H,KAC9D,iBACA,cAAc,EACdU,EAAAA,gCAAAA,aAAa2B,eAAe,qBAA5B3B,8BAA8BmB,MAAM,IAChC,KACA,CAAC,uBAAuB,EAAE7B,KAAK,SAAS,YAAY,CAAC,EACzD;IAGJ,IAAIkG,iBAAiBgB,MAAM,EAAE;QAC3B5G,IAAIqH,IAAI,CACN,CAAC,kDAAkD,EAAE3H,KACnD,iBACA,eAAe,EAAEA,KAAK,kBAAkB,+BAA+B,CAAC;QAG5EkG,iBAAiBmB,OAAO,CAAC,CAACgB,SAAW/H,IAAIqH,IAAI,CAAC,CAAC,IAAI,EAAEU,QAAQ;QAE7D/H,IAAIqH,IAAI,CAAC;IACX;IAEA,MAAMW,4BAA4BR,QAAQC,GAAG,CAACC,sBAAsB,GAChE7B,gBAAgB1D,MAAM,CACpB,CAAC4F,SAAWA,WAAW/C,kCAEzBa;IAEJ,IAAImC,0BAA0BpB,MAAM,EAAE;QACpC5G,IAAIqH,IAAI,CACN,CAAC,cAAc,EAAE1H,MAAM,qBAAqB,mBAAmB,EAAED,KAC/D,iBACA,GAAG,CAAC;QAGRsI,0BAA0BjB,OAAO,CAAC,CAACgB,SAAW/H,IAAIqH,IAAI,CAAC,CAAC,IAAI,EAAEU,QAAQ;QAEtE/H,IAAIqH,IAAI,CAAC;IACX;AACF","ignoreList":[0]}
|
|
@@ -80,7 +80,7 @@ export async function verifyTypeScriptSetup({ dir, distDir, cacheDir, intentDirs
|
|
|
80
80
|
const tsPath = deps.resolved.get('typescript');
|
|
81
81
|
const typescript = await Promise.resolve(require(tsPath));
|
|
82
82
|
// Verify the project passes type-checking before we go to webpack phase:
|
|
83
|
-
result = await runTypeCheck(typescript, dir, distDir, resolvedTsConfigPath, cacheDir, hasAppDir);
|
|
83
|
+
result = await runTypeCheck(typescript, dir, distDir, resolvedTsConfigPath, cacheDir, hasAppDir, isolatedDevBuild);
|
|
84
84
|
}
|
|
85
85
|
return {
|
|
86
86
|
result,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/verify-typescript-setup.ts"],"sourcesContent":["import { bold, cyan, red, yellow } from './picocolors'\nimport path, { join } from 'path'\n\nimport { hasNecessaryDependencies } from './has-necessary-dependencies'\nimport type { NecessaryDependencies } from './has-necessary-dependencies'\nimport semver from 'next/dist/compiled/semver'\nimport { CompileError } from './compile-error'\nimport * as log from '../build/output/log'\n\nimport { getTypeScriptIntent } from './typescript/getTypeScriptIntent'\nimport type { TypeCheckResult } from './typescript/runTypeCheck'\nimport { writeAppTypeDeclarations } from './typescript/writeAppTypeDeclarations'\nimport { writeConfigurationDefaults } from './typescript/writeConfigurationDefaults'\nimport { installDependencies } from './install-dependencies'\nimport { isCI } from '../server/ci-info'\nimport { missingDepsError } from './typescript/missingDependencyError'\n\nconst requiredPackages = [\n {\n file: 'typescript/lib/typescript.js',\n pkg: 'typescript',\n exportsRestrict: true,\n },\n {\n file: '@types/react/index.d.ts',\n pkg: '@types/react',\n exportsRestrict: true,\n },\n {\n file: '@types/node/index.d.ts',\n pkg: '@types/node',\n exportsRestrict: true,\n },\n]\n\nexport async function verifyTypeScriptSetup({\n dir,\n distDir,\n cacheDir,\n intentDirs,\n tsconfigPath,\n typeCheckPreflight,\n disableStaticImages,\n hasAppDir,\n hasPagesDir,\n isolatedDevBuild,\n}: {\n dir: string\n distDir: string\n cacheDir?: string\n tsconfigPath: string | undefined\n intentDirs: string[]\n typeCheckPreflight: boolean\n disableStaticImages: boolean\n hasAppDir: boolean\n hasPagesDir: boolean\n isolatedDevBuild: boolean | undefined\n}): Promise<{ result?: TypeCheckResult; version: string | null }> {\n const tsConfigFileName = tsconfigPath || 'tsconfig.json'\n const resolvedTsConfigPath = path.join(dir, tsConfigFileName)\n\n try {\n // Check if the project uses TypeScript:\n const intent = await getTypeScriptIntent(dir, intentDirs, tsConfigFileName)\n if (!intent) {\n return { version: null }\n }\n\n // Ensure TypeScript and necessary `@types/*` are installed:\n let deps: NecessaryDependencies = hasNecessaryDependencies(\n dir,\n requiredPackages\n )\n\n if (deps.missing?.length > 0) {\n if (isCI) {\n // we don't attempt auto install in CI to avoid side-effects\n // and instead log the error for installing needed packages\n missingDepsError(dir, deps.missing)\n }\n console.log(\n bold(\n yellow(\n `It looks like you're trying to use TypeScript but do not have the required package(s) installed.`\n )\n ) +\n '\\n' +\n 'Installing dependencies' +\n '\\n\\n' +\n bold(\n 'If you are not trying to use TypeScript, please remove the ' +\n cyan('tsconfig.json') +\n ' file from your package root (and any TypeScript files in your app and pages directories).'\n ) +\n '\\n'\n )\n await installDependencies(dir, deps.missing, true).catch((err) => {\n if (err && typeof err === 'object' && 'command' in err) {\n console.error(\n `Failed to install required TypeScript dependencies, please install them manually to continue:\\n` +\n (err as any).command +\n '\\n'\n )\n }\n throw err\n })\n deps = hasNecessaryDependencies(dir, requiredPackages)\n }\n\n // Load TypeScript after we're sure it exists:\n const tsPackageJsonPath = deps.resolved.get(\n join('typescript', 'package.json')\n )!\n const typescriptPackageJson = require(tsPackageJsonPath)\n\n const typescriptVersion = typescriptPackageJson.version\n\n if (semver.lt(typescriptVersion, '5.1.0')) {\n log.warn(\n `Minimum recommended TypeScript version is v5.1.0, older versions can potentially be incompatible with Next.js. Detected: ${typescriptVersion}`\n )\n }\n\n // Reconfigure (or create) the user's `tsconfig.json` for them:\n await writeConfigurationDefaults(\n typescriptVersion,\n resolvedTsConfigPath,\n intent.firstTimeSetup,\n hasAppDir,\n distDir,\n hasPagesDir,\n isolatedDevBuild\n )\n // Write out the necessary `next-env.d.ts` file to correctly register\n // Next.js' types:\n await writeAppTypeDeclarations({\n baseDir: dir,\n distDir,\n imageImportsEnabled: !disableStaticImages,\n hasPagesDir,\n hasAppDir,\n })\n\n let result\n if (typeCheckPreflight) {\n const { runTypeCheck } =\n require('./typescript/runTypeCheck') as typeof import('./typescript/runTypeCheck')\n\n const tsPath = deps.resolved.get('typescript')!\n const typescript = (await Promise.resolve(\n require(tsPath)\n )) as typeof import('typescript')\n\n // Verify the project passes type-checking before we go to webpack phase:\n result = await runTypeCheck(\n typescript,\n dir,\n distDir,\n resolvedTsConfigPath,\n cacheDir,\n hasAppDir\n )\n }\n return { result, version: typescriptVersion }\n } catch (err) {\n // These are special errors that should not show a stack trace:\n if (err instanceof CompileError) {\n console.error(red('Failed to compile.\\n'))\n console.error(err.message)\n process.exit(1)\n }\n\n /**\n * verifyTypeScriptSetup can be either invoked directly in the main thread (during next dev / next lint)\n * or run in a worker (during next build). In the latter case, we need to print the error message, as the\n * parent process will only receive an `Jest worker encountered 1 child process exceptions, exceeding retry limit`.\n */\n\n // we are in a worker, print the error message and exit the process\n if (process.env.IS_NEXT_WORKER) {\n if (err instanceof Error) {\n console.error(err.message)\n } else {\n console.error(err)\n }\n process.exit(1)\n }\n // we are in the main thread, throw the error and it will be handled by the caller\n throw err\n }\n}\n"],"names":["bold","cyan","red","yellow","path","join","hasNecessaryDependencies","semver","CompileError","log","getTypeScriptIntent","writeAppTypeDeclarations","writeConfigurationDefaults","installDependencies","isCI","missingDepsError","requiredPackages","file","pkg","exportsRestrict","verifyTypeScriptSetup","dir","distDir","cacheDir","intentDirs","tsconfigPath","typeCheckPreflight","disableStaticImages","hasAppDir","hasPagesDir","isolatedDevBuild","tsConfigFileName","resolvedTsConfigPath","deps","intent","version","missing","length","console","catch","err","error","command","tsPackageJsonPath","resolved","get","typescriptPackageJson","require","typescriptVersion","lt","warn","firstTimeSetup","baseDir","imageImportsEnabled","result","runTypeCheck","tsPath","typescript","Promise","resolve","message","process","exit","env","IS_NEXT_WORKER","Error"],"mappings":"AAAA,SAASA,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAEC,MAAM,QAAQ,eAAc;AACtD,OAAOC,QAAQC,IAAI,QAAQ,OAAM;AAEjC,SAASC,wBAAwB,QAAQ,+BAA8B;AAEvE,OAAOC,YAAY,4BAA2B;AAC9C,SAASC,YAAY,QAAQ,kBAAiB;AAC9C,YAAYC,SAAS,sBAAqB;AAE1C,SAASC,mBAAmB,QAAQ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AAaA,KAAK;oBACtDF,QAAQG,KAAK,CACX,CAAC,+FAA+F,CAAC,GAC/F,AAACD,IAAYE,OAAO,GACpB;gBAEN;gBACA,MAAMF;YACR;YACAP,OAAO3B,yBAAyBe,KAAKL;QACvC;QAEA,8CAA8C;QAC9C,MAAM2B,oBAAoBV,KAAKW,QAAQ,CAACC,GAAG,CACzCxC,KAAK,cAAc;QAErB,MAAMyC,wBAAwBC,QAAQJ;QAEtC,MAAMK,oBAAoBF,sBAAsBX,OAAO;QAEvD,IAAI5B,OAAO0C,EAAE,CAACD,mBAAmB,UAAU;YACzCvC,IAAIyC,IAAI,CACN,CAAC,yHAAyH,EAAEF,mBAAmB;QAEnJ;QAEA,+DAA+D;QAC/D,MAAMpC,2BACJoC,mBACAhB,sBACAE,OAAOiB,cAAc,EACrBvB,WACAN,SACAO,aACAC;QAEF,qEAAqE;QACrE,kBAAkB;QAClB,MAAMnB,yBAAyB;YAC7ByC,SAAS/B;YACTC;YACA+B,qBAAqB,CAAC1B;YACtBE;YACAD;QACF;QAEA,IAAI0B;QACJ,IAAI5B,oBAAoB;YACtB,MAAM,EAAE6B,YAAY,EAAE,GACpBR,QAAQ;YAEV,MAAMS,SAASvB,KAAKW,QAAQ,CAACC,GAAG,CAAC;YACjC,MAAMY,aAAc,MAAMC,QAAQC,OAAO,CACvCZ,QAAQS;YAGV,yEAAyE;YACzEF,SAAS,MAAMC,aACbE,YACApC,KACAC,SACAU,sBACAT,UACAK;QAEJ;QACA,OAAO;
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/verify-typescript-setup.ts"],"sourcesContent":["import { bold, cyan, red, yellow } from './picocolors'\nimport path, { join } from 'path'\n\nimport { hasNecessaryDependencies } from './has-necessary-dependencies'\nimport type { NecessaryDependencies } from './has-necessary-dependencies'\nimport semver from 'next/dist/compiled/semver'\nimport { CompileError } from './compile-error'\nimport * as log from '../build/output/log'\n\nimport { getTypeScriptIntent } from './typescript/getTypeScriptIntent'\nimport type { TypeCheckResult } from './typescript/runTypeCheck'\nimport { writeAppTypeDeclarations } from './typescript/writeAppTypeDeclarations'\nimport { writeConfigurationDefaults } from './typescript/writeConfigurationDefaults'\nimport { installDependencies } from './install-dependencies'\nimport { isCI } from '../server/ci-info'\nimport { missingDepsError } from './typescript/missingDependencyError'\n\nconst requiredPackages = [\n {\n file: 'typescript/lib/typescript.js',\n pkg: 'typescript',\n exportsRestrict: true,\n },\n {\n file: '@types/react/index.d.ts',\n pkg: '@types/react',\n exportsRestrict: true,\n },\n {\n file: '@types/node/index.d.ts',\n pkg: '@types/node',\n exportsRestrict: true,\n },\n]\n\nexport async function verifyTypeScriptSetup({\n dir,\n distDir,\n cacheDir,\n intentDirs,\n tsconfigPath,\n typeCheckPreflight,\n disableStaticImages,\n hasAppDir,\n hasPagesDir,\n isolatedDevBuild,\n}: {\n dir: string\n distDir: string\n cacheDir?: string\n tsconfigPath: string | undefined\n intentDirs: string[]\n typeCheckPreflight: boolean\n disableStaticImages: boolean\n hasAppDir: boolean\n hasPagesDir: boolean\n isolatedDevBuild: boolean | undefined\n}): Promise<{ result?: TypeCheckResult; version: string | null }> {\n const tsConfigFileName = tsconfigPath || 'tsconfig.json'\n const resolvedTsConfigPath = path.join(dir, tsConfigFileName)\n\n try {\n // Check if the project uses TypeScript:\n const intent = await getTypeScriptIntent(dir, intentDirs, tsConfigFileName)\n if (!intent) {\n return { version: null }\n }\n\n // Ensure TypeScript and necessary `@types/*` are installed:\n let deps: NecessaryDependencies = hasNecessaryDependencies(\n dir,\n requiredPackages\n )\n\n if (deps.missing?.length > 0) {\n if (isCI) {\n // we don't attempt auto install in CI to avoid side-effects\n // and instead log the error for installing needed packages\n missingDepsError(dir, deps.missing)\n }\n console.log(\n bold(\n yellow(\n `It looks like you're trying to use TypeScript but do not have the required package(s) installed.`\n )\n ) +\n '\\n' +\n 'Installing dependencies' +\n '\\n\\n' +\n bold(\n 'If you are not trying to use TypeScript, please remove the ' +\n cyan('tsconfig.json') +\n ' file from your package root (and any TypeScript files in your app and pages directories).'\n ) +\n '\\n'\n )\n await installDependencies(dir, deps.missing, true).catch((err) => {\n if (err && typeof err === 'object' && 'command' in err) {\n console.error(\n `Failed to install required TypeScript dependencies, please install them manually to continue:\\n` +\n (err as any).command +\n '\\n'\n )\n }\n throw err\n })\n deps = hasNecessaryDependencies(dir, requiredPackages)\n }\n\n // Load TypeScript after we're sure it exists:\n const tsPackageJsonPath = deps.resolved.get(\n join('typescript', 'package.json')\n )!\n const typescriptPackageJson = require(tsPackageJsonPath)\n\n const typescriptVersion = typescriptPackageJson.version\n\n if (semver.lt(typescriptVersion, '5.1.0')) {\n log.warn(\n `Minimum recommended TypeScript version is v5.1.0, older versions can potentially be incompatible with Next.js. Detected: ${typescriptVersion}`\n )\n }\n\n // Reconfigure (or create) the user's `tsconfig.json` for them:\n await writeConfigurationDefaults(\n typescriptVersion,\n resolvedTsConfigPath,\n intent.firstTimeSetup,\n hasAppDir,\n distDir,\n hasPagesDir,\n isolatedDevBuild\n )\n // Write out the necessary `next-env.d.ts` file to correctly register\n // Next.js' types:\n await writeAppTypeDeclarations({\n baseDir: dir,\n distDir,\n imageImportsEnabled: !disableStaticImages,\n hasPagesDir,\n hasAppDir,\n })\n\n let result\n if (typeCheckPreflight) {\n const { runTypeCheck } =\n require('./typescript/runTypeCheck') as typeof import('./typescript/runTypeCheck')\n\n const tsPath = deps.resolved.get('typescript')!\n const typescript = (await Promise.resolve(\n require(tsPath)\n )) as typeof import('typescript')\n\n // Verify the project passes type-checking before we go to webpack phase:\n result = await runTypeCheck(\n typescript,\n dir,\n distDir,\n resolvedTsConfigPath,\n cacheDir,\n hasAppDir,\n isolatedDevBuild\n )\n }\n return { result, version: typescriptVersion }\n } catch (err) {\n // These are special errors that should not show a stack trace:\n if (err instanceof CompileError) {\n console.error(red('Failed to compile.\\n'))\n console.error(err.message)\n process.exit(1)\n }\n\n /**\n * verifyTypeScriptSetup can be either invoked directly in the main thread (during next dev / next lint)\n * or run in a worker (during next build). In the latter case, we need to print the error message, as the\n * parent process will only receive an `Jest worker encountered 1 child process exceptions, exceeding retry limit`.\n */\n\n // we are in a worker, print the error message and exit the process\n if (process.env.IS_NEXT_WORKER) {\n if (err instanceof Error) {\n console.error(err.message)\n } else {\n console.error(err)\n }\n process.exit(1)\n }\n // we are in the main thread, throw the error and it will be handled by the caller\n throw err\n }\n}\n"],"names":["bold","cyan","red","yellow","path","join","hasNecessaryDependencies","semver","CompileError","log","getTypeScriptIntent","writeAppTypeDeclarations","writeConfigurationDefaults","installDependencies","isCI","missingDepsError","requiredPackages","file","pkg","exportsRestrict","verifyTypeScriptSetup","dir","distDir","cacheDir","intentDirs","tsconfigPath","typeCheckPreflight","disableStaticImages","hasAppDir","hasPagesDir","isolatedDevBuild","tsConfigFileName","resolvedTsConfigPath","deps","intent","version","missing","length","console","catch","err","error","command","tsPackageJsonPath","resolved","get","typescriptPackageJson","require","typescriptVersion","lt","warn","firstTimeSetup","baseDir","imageImportsEnabled","result","runTypeCheck","tsPath","typescript","Promise","resolve","message","process","exit","env","IS_NEXT_WORKER","Error"],"mappings":"AAAA,SAASA,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAEC,MAAM,QAAQ,eAAc;AACtD,OAAOC,QAAQC,IAAI,QAAQ,OAAM;AAEjC,SAASC,wBAAwB,QAAQ,+BAA8B;AAEvE,OAAOC,YAAY,4BAA2B;AAC9C,SAASC,YAAY,QAAQ,kBAAiB;AAC9C,YAAYC,SAAS,sBAAqB;AAE1C,SAASC,mBAAmB,QAAQ,mCAAkC;AAEtE,SAASC,wBAAwB,QAAQ,wCAAuC;AAChF,SAASC,0BAA0B,QAAQ,0CAAyC;AACpF,SAASC,mBAAmB,QAAQ,yBAAwB;AAC5D,SAASC,IAAI,QAAQ,oBAAmB;AACxC,SAASC,gBAAgB,QAAQ,sCAAqC;AAEtE,MAAMC,mBAAmB;IACvB;QACEC,MAAM;QACNC,KAAK;QACLC,iBAAiB;IACnB;IACA;QACEF,MAAM;QACNC,KAAK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oBF,sBAAsBX,OAAO;QAEvD,IAAI5B,OAAO0C,EAAE,CAACD,mBAAmB,UAAU;YACzCvC,IAAIyC,IAAI,CACN,CAAC,yHAAyH,EAAEF,mBAAmB;QAEnJ;QAEA,+DAA+D;QAC/D,MAAMpC,2BACJoC,mBACAhB,sBACAE,OAAOiB,cAAc,EACrBvB,WACAN,SACAO,aACAC;QAEF,qEAAqE;QACrE,kBAAkB;QAClB,MAAMnB,yBAAyB;YAC7ByC,SAAS/B;YACTC;YACA+B,qBAAqB,CAAC1B;YACtBE;YACAD;QACF;QAEA,IAAI0B;QACJ,IAAI5B,oBAAoB;YACtB,MAAM,EAAE6B,YAAY,EAAE,GACpBR,QAAQ;YAEV,MAAMS,SAASvB,KAAKW,QAAQ,CAACC,GAAG,CAAC;YACjC,MAAMY,aAAc,MAAMC,QAAQC,OAAO,CACvCZ,QAAQS;YAGV,yEAAyE;YACzEF,SAAS,MAAMC,aACbE,YACApC,KACAC,SACAU,sBACAT,UACAK,WACAE;QAEJ;QACA,OAAO;YAAEwB;YAAQnB,SAASa;QAAkB;IAC9C,EAAE,OAAOR,KAAK;QACZ,+DAA+D;QAC/D,IAAIA,eAAehC,cAAc;YAC/B8B,QAAQG,KAAK,CAACvC,IAAI;YAClBoC,QAAQG,KAAK,CAACD,IAAIoB,OAAO;YACzBC,QAAQC,IAAI,CAAC;QACf;QAEA;;;;KAIC,GAED,mEAAmE;QACnE,IAAID,QAAQE,GAAG,CAACC,cAAc,EAAE;YAC9B,IAAIxB,eAAeyB,OAAO;gBACxB3B,QAAQG,KAAK,CAACD,IAAIoB,OAAO;YAC3B,OAAO;gBACLtB,QAAQG,KAAK,CAACD;YAChB;YACAqB,QAAQC,IAAI,CAAC;QACf;QACA,kFAAkF;QAClF,MAAMtB;IACR;AACF","ignoreList":[0]}
|
|
@@ -141,7 +141,7 @@ function warnCustomizedOption(config, key, defaultValue, customMessage, configFi
|
|
|
141
141
|
* @param silent - Whether to suppress warnings.
|
|
142
142
|
* @returns The complete config.
|
|
143
143
|
*/ function assignDefaultsAndValidate(dir, userConfig, silent, phase) {
|
|
144
|
-
var _result_experimental, _result_experimental1, _result_experimental_serverActions, _result_experimental2, _userConfig_experimental, _userConfig_experimental1, _userConfig_experimental2, _userConfig_experimental3, _userConfig_experimental4, _userConfig_experimental5, _userConfig_experimental6, _userConfig_experimental7, _userConfig_experimental8, _userConfig_experimental9, _userConfig_experimental10, _userConfig_experimental11, _userConfig_experimental12, _userConfig_experimental13, _userConfig_experimental14, _userConfig_experimental15, _result_experimental3, _result_turbopack, _result_turbopack1, _result_devIndicators, _result_experimental4
|
|
144
|
+
var _result_experimental, _result_experimental1, _result_experimental_serverActions, _result_experimental2, _userConfig_experimental, _userConfig_experimental1, _userConfig_experimental2, _userConfig_experimental3, _userConfig_experimental4, _userConfig_experimental5, _userConfig_experimental6, _userConfig_experimental7, _userConfig_experimental8, _userConfig_experimental9, _userConfig_experimental10, _userConfig_experimental11, _userConfig_experimental12, _userConfig_experimental13, _userConfig_experimental14, _userConfig_experimental15, _result_experimental3, _result_turbopack, _result_turbopack1, _result_devIndicators, _result_experimental4;
|
|
145
145
|
const configFileName = userConfig.configFileName;
|
|
146
146
|
if (typeof userConfig.exportTrailingSlash !== 'undefined') {
|
|
147
147
|
if (!silent) {
|
|
@@ -962,7 +962,7 @@ function warnCustomizedOption(config, key, defaultValue, customMessage, configFi
|
|
|
962
962
|
// Store the distDirRoot in the config before it is modified by the isolatedDevBuild flag
|
|
963
963
|
;
|
|
964
964
|
result.distDirRoot = result.distDir;
|
|
965
|
-
if (phase === PHASE_DEVELOPMENT_SERVER &&
|
|
965
|
+
if (phase === PHASE_DEVELOPMENT_SERVER && result.experimental.isolatedDevBuild) {
|
|
966
966
|
result.distDir = join(result.distDir, 'dev');
|
|
967
967
|
}
|
|
968
968
|
return result;
|