UNPKG

@nuxt/cli

Version:
52 lines (51 loc) • 1.81 kB
import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.mjs"; import { n as resolveDotenvFileNames } from "./args-CAT9qhaw.mjs"; import { D as ActionableError } from "./startup-clock-SyYej6uN.mjs"; import { t as loadKit } from "./kit-CAB8i9G1.mjs"; import process from "node:process"; import { fileURLToPath } from "node:url"; import { once } from "node:events"; import { spawn } from "node:child_process"; // src/utils/write-types.ts var write_types_exports = /* @__PURE__ */ __exportAll({ writeTypes: () => writeTypes, writeTypesInChild: () => writeTypesInChild }); /** Load Nuxt in this process, write its types and build its templates. */ async function writeTypes(options) { const { cwd, dotenv, logLevel, overrides } = options; const { loadNuxt, buildNuxt, writeTypes } = await loadKit(cwd); const nuxt = await loadNuxt({ cwd, dotenv: { cwd, fileName: resolveDotenvFileNames(dotenv) }, overrides: { _prepare: true, logLevel, ...overrides } }); try { await writeTypes(nuxt); await buildNuxt(nuxt); } finally { await nuxt.close(); } } /** * Run {@link writeTypes} in a short-lived Node.js process, so this one does not * keep Nuxt in memory afterwards. `options` must be JSON-serialisable. */ async function writeTypesInChild(options) { const entry = fileURLToPath(new URL("./write-types.mjs", import.meta.url)); const child = spawn(process.execPath, [entry, JSON.stringify(options)], { cwd: options.cwd, stdio: "inherit" }); const [code, signal] = await once(child, "exit"); if (signal) throw new ActionableError(`Generating types was terminated by ${signal}.`); if (code !== 0) throw new ActionableError(`Generating types failed with exit code ${code}. Fix the error above and try again.`); } export { write_types_exports as n, writeTypes as t };