UNPKG

4.64 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../lib/verifyTypeScriptSetup.ts"],"names":["verifyTypeScriptSetup","dir","pagesDir","typeCheckPreflight","imageImportsEnabled","cacheDir","tsConfigPath","path","join","intent","version","firstTimeSetup","deps","ts","resolved","get","semver","lt","log","warn","result","runTypeCheck","require","err","CompileError","console","error","chalk","red","message","process","exit","FatalError"],"mappings":"yFAAA,oDACA,kDACA,sEAIA,yEACA,6CACA,yCACA,gEAEA,qEAEA,+EACA,mF,w4BAEO,cAAeA,CAAAA,qBAAf,CACLC,GADK,CAELC,QAFK,CAGLC,kBAHK,CAILC,mBAJK,CAKLC,QALK,CAM0D,CAC/D,KAAMC,CAAAA,YAAY,CAAGC,cAAKC,IAAL,CAAUP,GAAV,CAAe,eAAf,CAArB,CAEA,GAAI,CACF;AACA,KAAMQ,CAAAA,MAAM,CAAG,KAAM,6CAAoBR,GAApB,CAAyBC,QAAzB,CAArB,CACA,GAAI,CAACO,MAAL,CAAa,CACX,MAAO,CAAEC,OAAO,CAAE,IAAX,CAAP,CACD,CACD,KAAMC,CAAAA,cAAc,CAAGF,MAAM,CAACE,cAA9B,CAEA;AACA,KAAMC,CAAAA,IAA2B,CAAG,KAAM,uDACxCX,GADwC,CAExC,CAAC,CAACQ,MAFsC,CAGxC,KAHwC,CAA1C,CAMA;AACA,KAAMI,CAAAA,EAAE,CAAI,yBACVD,IAAI,CAACE,QAAL,CAAcC,GAAd,CAAkB,YAAlB,CADU,gDAAZ,CAIA,GAAIC,gBAAOC,EAAP,CAAUJ,EAAE,CAACH,OAAb,CAAsB,OAAtB,CAAJ,CAAoC,CAClCQ,GAAG,CAACC,IAAJ,CACG,4HAA2HN,EAAE,CAACH,OAAQ,EADzI,EAGD,CAED;AACA,KAAM,2DAA2BG,EAA3B,CAA+BP,YAA/B,CAA6CK,cAA7C,CAAN,CACA;AACA;AACA,KAAM,uDAAyBV,GAAzB,CAA8BG,mBAA9B,CAAN,CAEA,GAAIgB,CAAAA,MAAJ,CACA,GAAIjB,kBAAJ,CAAwB,CACtB,KAAM,CAAEkB,YAAF,EAAmBC,OAAO,CAAC,2BAAD,CAAhC,CAEA;AACAF,MAAM,CAAG,KAAMC,CAAAA,YAAY,CAACR,EAAD,CAAKZ,GAAL,CAAUK,YAAV,CAAwBD,QAAxB,CAA3B,CACD,CACD,MAAO,CAAEe,MAAF,CAAUV,OAAO,CAAEG,EAAE,CAACH,OAAtB,CAAP,CACD,CAAC,MAAOa,GAAP,CAAY,CACZ;AACA,GAAIA,GAAG,WAAYC,2BAAnB,CAAiC,CAC/BC,OAAO,CAACC,KAAR,CAAcC,eAAMC,GAAN,CAAU,sBAAV,CAAd,EACAH,OAAO,CAACC,KAAR,CAAcH,GAAG,CAACM,OAAlB,EACAC,OAAO,CAACC,IAAR,CAAa,CAAb,EACD,CAJD,IAIO,IAAIR,GAAG,WAAYS,uBAAnB,CAA+B,CACpCP,OAAO,CAACC,KAAR,CAAcH,GAAG,CAACM,OAAlB,EACAC,OAAO,CAACC,IAAR,CAAa,CAAb,EACD,CACD,KAAMR,CAAAA,GAAN,CACD,CACF","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport {\n hasNecessaryDependencies,\n NecessaryDependencies,\n} from './has-necessary-dependencies'\nimport semver from 'next/dist/compiled/semver'\nimport { CompileError } from './compile-error'\nimport { FatalError } from './fatal-error'\nimport * as log from '../build/output/log'\n\nimport { getTypeScriptIntent } from './typescript/getTypeScriptIntent'\nimport { TypeCheckResult } from './typescript/runTypeCheck'\nimport { writeAppTypeDeclarations } from './typescript/writeAppTypeDeclarations'\nimport { writeConfigurationDefaults } from './typescript/writeConfigurationDefaults'\n\nexport async function verifyTypeScriptSetup(\n dir: string,\n pagesDir: string,\n typeCheckPreflight: boolean,\n imageImportsEnabled: boolean,\n cacheDir?: string\n): Promise<{ result?: TypeCheckResult; version: string | null }> {\n const tsConfigPath = path.join(dir, 'tsconfig.json')\n\n try {\n // Check if the project uses TypeScript:\n const intent = await getTypeScriptIntent(dir, pagesDir)\n if (!intent) {\n return { version: null }\n }\n const firstTimeSetup = intent.firstTimeSetup\n\n // Ensure TypeScript and necessary `@types/*` are installed:\n const deps: NecessaryDependencies = await hasNecessaryDependencies(\n dir,\n !!intent,\n false\n )\n\n // Load TypeScript after we're sure it exists:\n const ts = (await import(\n deps.resolved.get('typescript')!\n )) as typeof import('typescript')\n\n if (semver.lt(ts.version, '4.3.2')) {\n log.warn(\n `Minimum recommended TypeScript version is v4.3.2, older versions can potentially be incompatible with Next.js. Detected: ${ts.version}`\n )\n }\n\n // Reconfigure (or create) the user's `tsconfig.json` for them:\n await writeConfigurationDefaults(ts, tsConfigPath, firstTimeSetup)\n // Write out the necessary `next-env.d.ts` file to correctly register\n // Next.js' types:\n await writeAppTypeDeclarations(dir, imageImportsEnabled)\n\n let result\n if (typeCheckPreflight) {\n const { runTypeCheck } = require('./typescript/runTypeCheck')\n\n // Verify the project passes type-checking before we go to webpack phase:\n result = await runTypeCheck(ts, dir, tsConfigPath, cacheDir)\n }\n return { result, version: ts.version }\n } catch (err) {\n // These are special errors that should not show a stack trace:\n if (err instanceof CompileError) {\n console.error(chalk.red('Failed to compile.\\n'))\n console.error(err.message)\n process.exit(1)\n } else if (err instanceof FatalError) {\n console.error(err.message)\n process.exit(1)\n }\n throw err\n }\n}\n"]}
\No newline at end of file