/opt/canhelp/node_modules/next/dist/build/next-config-ts
Edit: /opt/canhelp/node_modules/next/dist/build/next-config-ts/transpile-config.js.map (6691B)
{"version":3,"sources":["../../../src/build/next-config-ts/transpile-config.ts"],"sourcesContent":["import type { Options as SWCOptions } from '@swc/core'\nimport type { CompilerOptions } from 'typescript'\n\nimport { resolve } from 'node:path'\nimport { readFile } from 'node:fs/promises'\nimport { deregisterHook, registerHook, requireFromString } from './require-hook'\nimport { warn } from '../output/log'\nimport { installDependencies } from '../../lib/install-dependencies'\n\nfunction resolveSWCOptions(\n cwd: string,\n compilerOptions: CompilerOptions\n): SWCOptions {\n const resolvedBaseUrl = resolve(cwd, compilerOptions.baseUrl ?? '.')\n return {\n jsc: {\n target: 'es5',\n parser: {\n syntax: 'typescript',\n },\n paths: compilerOptions.paths,\n baseUrl: resolvedBaseUrl,\n },\n module: {\n type: 'commonjs',\n },\n isModule: 'unknown',\n } satisfies SWCOptions\n}\n\n// Ported from next/src/lib/verify-typescript-setup.ts\n// Although this overlaps with the later `verifyTypeScriptSetup`,\n// it is acceptable since the time difference in the worst case is trivial,\n// as we are only preparing to install the dependencies once more.\nasync function verifyTypeScriptSetup(cwd: string, configFileName: string) {\n try {\n // Quick module check.\n require.resolve('typescript', { paths: [cwd] })\n } catch (error) {\n if (\n error &&\n typeof error === 'object' &&\n 'code' in error &&\n error.code === 'MODULE_NOT_FOUND'\n ) {\n warn(\n `Installing TypeScript as it was not found while loading \"${configFileName}\".`\n )\n\n await installDependencies(cwd, [{ pkg: 'typescript' }], true).catch(\n (err) => {\n if (err && typeof err === 'object' && 'command' in err) {\n console.error(\n `Failed to install TypeScript, please install it manually to continue:\\n` +\n (err as any).command +\n '\\n'\n )\n }\n throw err\n }\n )\n }\n }\n}\n\nasync function getTsConfig(cwd: string): Promise
{\n const ts: typeof import('typescript') = require(\n require.resolve('typescript', { paths: [cwd] })\n )\n\n // NOTE: This doesn't fully cover the edge case for setting\n // \"typescript.tsconfigPath\" in next config which is currently\n // a restriction.\n const tsConfigPath = ts.findConfigFile(\n cwd,\n ts.sys.fileExists,\n 'tsconfig.json'\n )\n\n if (!tsConfigPath) {\n // It is ok to not return ts.getDefaultCompilerOptions() because\n // we are only lookfing for paths and baseUrl from tsConfig.\n return {}\n }\n\n const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile)\n const parsedCommandLine = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n cwd\n )\n\n return parsedCommandLine.options\n}\n\nexport async function transpileConfig({\n nextConfigPath,\n configFileName,\n cwd,\n}: {\n nextConfigPath: string\n configFileName: string\n cwd: string\n}) {\n let hasRequire = false\n try {\n // Ensure TypeScript is installed to use the API.\n await verifyTypeScriptSetup(cwd, configFileName)\n\n const compilerOptions = await getTsConfig(cwd)\n const swcOptions = resolveSWCOptions(cwd, compilerOptions)\n\n const nextConfigString = await readFile(nextConfigPath, 'utf8')\n // lazy require swc since it loads React before even setting NODE_ENV\n // resulting loading Development React on Production\n const { transform } = require('../swc') as typeof import('../swc')\n const { code } = await transform(nextConfigString, swcOptions)\n\n // register require hook only if require exists\n if (code.includes('require(')) {\n registerHook(swcOptions)\n hasRequire = true\n }\n\n // filename & extension don't matter here\n return requireFromString(code, resolve(cwd, 'next.config.compiled.js'))\n } catch (error) {\n throw error\n } finally {\n if (hasRequire) {\n deregisterHook()\n }\n }\n}\n"],"names":["transpileConfig","resolveSWCOptions","cwd","compilerOptions","resolvedBaseUrl","resolve","baseUrl","jsc","target","parser","syntax","paths","module","type","isModule","verifyTypeScriptSetup","configFileName","require","error","code","warn","installDependencies","pkg","catch","err","console","command","getTsConfig","ts","tsConfigPath","findConfigFile","sys","fileExists","configFile","readConfigFile","readFile","parsedCommandLine","parseJsonConfigFileContent","config","options","nextConfigPath","hasRequire","swcOptions","nextConfigString","transform","includes","registerHook","requireFromString","deregisterHook"],"mappings":";;;;+BA+FsBA;;;eAAAA;;;0BA5FE;0BACC;6BACuC;qBAC3C;qCACe;AAEpC,SAASC,kBACPC,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