diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 280cd4b2f..1bc4231f9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,7 +70,7 @@ jobs: cache: pnpm # The repo's `postinstall` runs `scripts/generate-data.ts` to write - # `packages/nuxi/src/data/*.ts` that the build then bundles. uppt's + # `packages/nuxt-cli/src/data/*.ts` that the build then bundles. uppt's # default install path uses `--ignore-scripts`, which would skip it # and produce a stale or broken nuxi tarball, so we install ourselves # and pass `install: false` to uppt/pack. diff --git a/.gitignore b/.gitignore index affa8acf9..e65acd7f1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,5 @@ playground-bun* playground-deno* playground-node* packages/nuxi/src/utils/completions-data.ts -packages/nuxi/src/data/nitro-presets.ts -packages/nuxi/src/data/templates.ts +packages/nuxt-cli/src/data/nitro-presets.ts +packages/nuxt-cli/src/data/templates.ts diff --git a/eslint.config.js b/eslint.config.js index 5a5f24234..e55217b96 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -18,7 +18,7 @@ export default createConfigForNuxt({ regexp: false, })).append( { - ignores: ['packages/nuxi/src/data/**'], + ignores: ['packages/nuxt-cli/src/data/**'], }, { rules: { diff --git a/knip.json b/knip.json index 91765faa9..5b877f8be 100644 --- a/knip.json +++ b/knip.json @@ -30,39 +30,6 @@ "packages/nuxt-cli": { "entry": [ "test/fixtures/*" - ], - "ignoreDependencies": [ - "@bomb.sh/tab", - "@clack/prompts", - "c12", - "confbox", - "consola", - "defu", - "exsolve", - "fuse.js", - "fzf", - "giget", - "h3-next", - "jiti", - "nitro", - "nitropack", - "nypm", - "ofetch", - "obug", - "ohash", - "pathe", - "perfect-debounce", - "pkg-types", - "rc9", - "scule", - "source-map", - "srvx", - "tinyclip", - "ufo", - "uqr", - "verkit", - "youch", - "youch-core" ] }, "packages/create-nuxt": { diff --git a/packages/create-nuxt/src/main.ts b/packages/create-nuxt/src/main.ts index f9e16f9bc..d1a87b6ee 100644 --- a/packages/create-nuxt/src/main.ts +++ b/packages/create-nuxt/src/main.ts @@ -3,10 +3,10 @@ import process from 'node:process' import { defineCommand } from 'citty' import { provider } from 'std-env' -import init from '../../nuxi/src/commands/init' -import { setupInitCompletions } from '../../nuxi/src/completions-init' -import { checkEngines } from '../../nuxi/src/utils/engines' -import { logger } from '../../nuxi/src/utils/logger' +import init from '../../nuxt-cli/src/commands/init' +import { setupInitCompletions } from '../../nuxt-cli/src/completions-init' +import { checkEngines } from '../../nuxt-cli/src/utils/engines' +import { logger } from '../../nuxt-cli/src/utils/logger' import { description, name, version } from '../package.json' const _main = defineCommand({ diff --git a/packages/create-nuxt/src/run.ts b/packages/create-nuxt/src/run.ts index 9b8567351..62a2df839 100644 --- a/packages/create-nuxt/src/run.ts +++ b/packages/create-nuxt/src/run.ts @@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url' import { runCommand as _runCommand, runMain as _runMain } from 'citty' -import init from '../../nuxi/src/commands/init' +import init from '../../nuxt-cli/src/commands/init' import { main } from './main' globalThis.__nuxt_cli__ = globalThis.__nuxt_cli__ || { diff --git a/packages/nuxi/package.json b/packages/nuxi/package.json index e7d7a6c9e..a1221f36e 100644 --- a/packages/nuxi/package.json +++ b/packages/nuxi/package.json @@ -33,53 +33,14 @@ "test:dist": "node ./bin/nuxi.mjs info ../../playground" }, "devDependencies": { - "@bomb.sh/tab": "^0.0.19", - "@clack/prompts": "^1.7.0", - "@nuxt/kit": "^4.4.6", - "@nuxt/schema": "^4.4.6", - "@nuxt/test-utils": "^4.0.3", "@types/node": "^24.13.3", - "c12": "^3.3.4", "citty": "^0.2.2", - "confbox": "^0.2.4", - "consola": "^3.4.2", - "defu": "^6.1.7", - "exsolve": "^1.1.0", - "fuse.js": "^7.4.2", - "fzf": "^0.5.2", - "get-port-please": "^3.2.0", - "giget": "^3.3.0", - "h3": "^1.15.11", - "h3-next": "npm:h3@^2.0.1-rc.25", - "jiti": "^2.7.0", - "magicast": "^0.5.3", - "nitro": "^3.0.1-alpha.2", - "nitropack": "^2.13.4", - "nypm": "^0.6.8", - "obug": "^2.1.1", - "ofetch": "^1.5.1", - "ohash": "^2.0.11", - "pathe": "^2.0.3", - "perfect-debounce": "^2.1.0", "picocolors": "^1.1.1", - "pkg-types": "^2.3.1", - "rc9": "^3.0.1", - "rollup": "^4.62.2", "rollup-plugin-visualizer": "^7.0.1", - "scule": "^1.3.0", - "source-map": "^0.7.6", - "srvx": "^0.11.22", "std-env": "^4.2.0", - "tinyclip": "^0.1.15", "tinyexec": "^1.2.4", "tsdown": "^0.22.7", "typescript": "^6.0.3", - "ufo": "^1.6.4", - "unplugin-purge-polyfills": "^0.1.0", - "uqr": "^0.1.3", - "verkit": "^0.3.0", - "vitest": "^4.1.10", - "youch": "^4.1.1", - "youch-core": "^0.3.3" + "unplugin-purge-polyfills": "^0.1.0" } } diff --git a/packages/nuxi/src/dev/index.ts b/packages/nuxi/src/dev/index.ts index 5daac2335..e2297c119 100644 --- a/packages/nuxi/src/dev/index.ts +++ b/packages/nuxi/src/dev/index.ts @@ -1,164 +1 @@ -import type { NuxtConfig } from '@nuxt/schema' -import type { DevListenOverrides, Listener } from './listen' -import type { NuxtDevContext, NuxtDevIPCMessage, NuxtParentIPCMessage } from './utils' - -import process from 'node:process' -import defu from 'defu' -import { overrideEnv } from '../utils/env.ts' -import { startCpuProfile, stopCpuProfile } from '../utils/profile.ts' -import { NuxtDevServer } from './utils' - -const start = Date.now() - -interface InitializeOptions { - data?: { - overrides?: NuxtConfig - } - listenOverrides?: DevListenOverrides - showBanner?: boolean -} - -// IPC Hooks -class IPC { - enabled = !!process.send && !process.title?.includes('vitest') && process.env.__NUXT__FORK - constructor() { - // only kill process if it is a fork - if (this.enabled) { - process.once('unhandledRejection', (reason) => { - this.send({ type: 'nuxt:internal:dev:rejection', message: reason instanceof Error ? reason.toString() : 'Unhandled Rejection' }) - process.exit() - }) - } - process.on('message', (message: NuxtParentIPCMessage) => { - if (message.type === 'nuxt:internal:dev:context') { - initialize(message.context, { listenOverrides: message.listenOverrides }) - } - }) - this.send({ type: 'nuxt:internal:dev:fork-ready' }) - } - - send(message: T) { - if (this.enabled) { - process.send?.(message) - } - } -} - -const ipc = new IPC() - -interface InitializeReturn { - listener: Listener - close: () => Promise - onReady: (callback: (address: string) => void) => void - onRestart: (callback: (devServer: NuxtDevServer) => void) => void -} - -export async function initialize(devContext: NuxtDevContext, ctx: InitializeOptions = {}): Promise { - overrideEnv('development') - - const profileArg = devContext.args.profile - const perfValue = profileArg === 'verbose' ? true : profileArg ? 'quiet' : undefined - const perfOverrides = perfValue - ? { debug: { perf: perfValue } } as NuxtConfig - : {} - - if (profileArg) { - await startCpuProfile() - } - - const devServer = new NuxtDevServer({ - cwd: devContext.cwd, - overrides: defu( - ctx.data?.overrides, - ({ extends: devContext.args.extends } satisfies NuxtConfig) as NuxtConfig, - perfOverrides, - ), - logLevel: devContext.args.logLevel as 'silent' | 'info' | 'verbose', - clear: devContext.args.clear, - dotenv: { cwd: devContext.cwd, fileName: devContext.args.dotenv }, - envName: devContext.args.envName, - showBanner: ctx.showBanner !== false && !ipc.enabled, - listenOverrides: ctx.listenOverrides, - }) - - let address: string - - if (ipc.enabled) { - devServer.on('loading:error', (_error) => { - ipc.send({ - type: 'nuxt:internal:dev:loading:error', - error: { - message: _error.message, - stack: _error.stack, - name: _error.name, - code: 'code' in _error ? _error.code : undefined, - }, - }) - }) - devServer.on('loading', (message) => { - ipc.send({ type: 'nuxt:internal:dev:loading', message }) - }) - devServer.on('restart', () => { - ipc.send({ type: 'nuxt:internal:dev:restart' }) - }) - devServer.on('ready', (payload) => { - ipc.send({ type: 'nuxt:internal:dev:ready', address: payload }) - }) - } - else { - devServer.on('ready', (payload) => { - address = payload - }) - } - - // Init server - await devServer.init() - - if (process.env.DEBUG) { - // eslint-disable-next-line no-console - console.debug(`Dev server (internal) initialized in ${Date.now() - start}ms`) - } - - if (profileArg) { - for (const signal of [ - 'exit', - 'SIGTERM' /* Graceful shutdown */, - 'SIGINT' /* Ctrl-C */, - 'SIGQUIT' /* Ctrl-\ */, - ] as const) { - process.once(signal, () => stopCpuProfile(devContext.cwd, 'dev')) - } - } - - return { - listener: devServer.listener, - close: async () => { - devServer.closeWatchers() - await Promise.all([ - devServer.listener.close(), - devServer.close(), - ]) - devServer.releaseLock() - }, - onReady: (callback: (address: string) => void) => { - if (address) { - callback(address) - } - else { - devServer.once('ready', payload => callback(payload)) - } - }, - onRestart: (callback: (devServer: NuxtDevServer) => void) => { - let restarted = false - function restart() { - if (!restarted) { - restarted = true - callback(devServer) - } - } - devServer.once('restart', restart) - process.once('uncaughtException', restart) - process.once('unhandledRejection', restart) - }, - } -} +export { initialize } from '../../../nuxt-cli/src/dev' diff --git a/packages/nuxi/src/main.ts b/packages/nuxi/src/main.ts index ed70d2b2f..7033636ce 100644 --- a/packages/nuxi/src/main.ts +++ b/packages/nuxi/src/main.ts @@ -1,5 +1,5 @@ import type { CommandDef } from 'citty' -import type { TemplateName } from './utils/templates/names' +import type { TemplateName } from '../../nuxt-cli/src/utils/templates/names' import nodeCrypto from 'node:crypto' import { builtinModules, createRequire } from 'node:module' @@ -10,14 +10,14 @@ import { runMain as _runMain, defineCommand } from 'citty' import colors from 'picocolors' import { provider } from 'std-env' +import { commands } from '../../nuxt-cli/src/commands' +import { cwdArgs } from '../../nuxt-cli/src/commands/_shared' +import { setupGlobalConsole } from '../../nuxt-cli/src/utils/console' +import { checkEngines } from '../../nuxt-cli/src/utils/engines' +import { debug, logger } from '../../nuxt-cli/src/utils/logger' +import { templateNames } from '../../nuxt-cli/src/utils/templates/names' import { description, name, version } from '../package.json' -import { commands } from './commands' -import { cwdArgs } from './commands/_shared' import { runCommand } from './run' -import { setupGlobalConsole } from './utils/console' -import { checkEngines } from './utils/engines' -import { debug, logger } from './utils/logger' -import { templateNames } from './utils/templates/names' // globalThis.crypto support for Node.js 18 if (!globalThis.crypto) { @@ -70,7 +70,7 @@ const _main = defineCommand({ if (command === 'add' && ctx.rawArgs[1] && templateNames.includes(ctx.rawArgs[1] as TemplateName)) { logger.warn(`${colors.yellow('Deprecated:')} Using ${colors.cyan('nuxt add