1
0
mirror of synced 2025-12-19 18:11:23 -05:00
Files
blitz/nextjs/packages/next/server/lib/utils.ts

30 lines
703 B
TypeScript

import findUp from 'next/dist/compiled/find-up'
import { dirname } from 'path'
export function printAndExit(message: string, code = 1) {
if (code === 0) {
console.log(message)
} else {
console.error(message)
}
process.exit(code)
}
export function getNodeOptionsWithoutInspect() {
const NODE_INSPECT_RE = /--inspect(-brk)?(=\S+)?( |$)/
return (process.env.NODE_OPTIONS || '').replace(NODE_INSPECT_RE, '')
}
export async function getProjectRoot(dir: string) {
const pkgJsonPath = await findUp('package.json', { cwd: dir })
if (!pkgJsonPath) {
throw new Error(
'Unable to find project root by looking for your package.json'
)
}
return dirname(pkgJsonPath)
}