1 line
28 KiB
Text
1 line
28 KiB
Text
|
|
{"version":3,"sources":["../../src/bin/next.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport '../server/require-hook'\n\nimport {\n Argument,\n Command,\n InvalidArgumentError,\n Option,\n} from 'next/dist/compiled/commander'\n\nimport { warn } from '../build/output/log'\nimport semver from 'next/dist/compiled/semver'\nimport { bold, cyan, italic } from '../lib/picocolors'\nimport { formatCliHelpOutput } from '../lib/format-cli-help-output'\nimport { NON_STANDARD_NODE_ENV } from '../lib/constants'\nimport {\n getParsedDebugAddress,\n parseValidPositiveInteger,\n type DebugAddress,\n} from '../server/lib/utils'\nimport {\n SUPPORTED_TEST_RUNNERS_LIST,\n type NextTestOptions,\n} from '../cli/next-test.js'\nimport type { NextTelemetryOptions } from '../cli/next-telemetry.js'\nimport type { NextStartOptions } from '../cli/next-start.js'\nimport type { NextInfoOptions } from '../cli/next-info.js'\nimport type { NextDevOptions } from '../cli/next-dev.js'\nimport type { NextAnalyzeOptions } from '../cli/next-analyze.js'\nimport type { NextBuildOptions } from '../cli/next-build.js'\nimport type { NextTypegenOptions } from '../cli/next-typegen.js'\n\nif (process.env.NEXT_RSPACK) {\n // silent rspack's schema check\n process.env.RSPACK_CONFIG_VALIDATE = 'loose-silent'\n}\n\nif (\n !semver.satisfies(\n process.versions.node,\n process.env.__NEXT_REQUIRED_NODE_VERSION_RANGE!,\n { includePrerelease: true }\n )\n) {\n console.error(\n `You are using Node.js ${process.versions.node}. For Next.js, Node.js version \"${process.env.__NEXT_REQUIRED_NODE_VERSION_RANGE}\" is required.`\n )\n process.exit(1)\n}\n\nprocess.env.NEXT_PRIVATE_START_TIME = Date.now().toString()\n\nfor (const dependency of ['react', 'react-dom']) {\n try {\n // When 'npm link' is used it checks the clone location. Not the project.\n require.resolve(dependency)\n } catch (err) {\n console.warn(\n `The module '${dependency}' was not found. Next.js requires that you include it in 'dependencies' of your 'package.json'. To add it, run 'npm install ${dependency}'`\n )\n }\n}\n\nclass NextRootCommand extends Command {\n createCommand(name: string) {\n const command = new Command(name)\n\n command.hook('preAction', (event) => {\n const commandName = event.name()\n const defaultEnv = commandName === 'dev' ? 'development' : 'production'\n const standardEnv = ['production', 'development', 'test']\n\n if (process.env.NODE_ENV) {\n const isNotStandard = !standardEnv.includes(process.env.NODE_ENV)\n const shouldWarnCommands =\n process.env.NODE_ENV === 'development'\n ? ['start', 'build']\n : process.env.NODE_ENV === 'production'\n ? ['dev']\n : []\n\n if (isNotStandard || shouldWarnCommands.includes(commandName)) {\n warn(NON_STANDARD_NODE_ENV)\n }\n }\n\n ;(process.env as any).NODE_ENV = process.env.NODE_ENV || defaultEnv\n ;(process.env as any).NEXT_RUNTIME = 'nodejs'\n\n if (\n commandName !== 'dev' &&\n commandName !== 'start' &&\n event.getOptionValue('inspect') === true\n ) {\n console.error(\n `\\`--inspect\\` flag is deprecated. Use env variable NODE_OPTIONS instead: NODE_OPTIONS='--inspect' next ${commandName}`\n )\n process.exit(1)\n }\n })\n\n return command\n }\n}\n\nfunction parseValidInspectAddress(value: string): DebugAddress {\n const address = getParsedDebugAddress(value)\n\n if (Number.isNaN(address.port)) {\n throw new InvalidArgumentError(\n 'The given value is not a valid inspect address. ' +\n 'Did you mean to pass an app path?\\n' +\n `Try switching the order of the arguments or set the default address explicitly e.g.\\n` +\n `next dev ${value} --inspect\\n` +\n `next dev --inspect= ${value}`\n )\n }\n\n return address\n}\n\nconst program = new NextRootCommand()\n\nprogram\n .name('next')\n .description(\n 'The Next.js CLI allows you to develop, build
|