Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default createConfigForNuxt({
regexp: false,
})).append(
{
ignores: ['packages/nuxi/src/data/**'],
ignores: ['packages/nuxt-cli/src/data/**'],
},
{
rules: {
Expand Down
33 changes: 0 additions & 33 deletions knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions packages/create-nuxt/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/create-nuxt/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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__ || {
Expand Down
41 changes: 1 addition & 40 deletions packages/nuxi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
165 changes: 1 addition & 164 deletions packages/nuxi/src/dev/index.ts
Original file line number Diff line number Diff line change
@@ -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<T extends NuxtDevIPCMessage>(message: T) {
if (this.enabled) {
process.send?.(message)
}
}
}

const ipc = new IPC()

interface InitializeReturn {
listener: Listener
close: () => Promise<void>
onReady: (callback: (address: string) => void) => void
onRestart: (callback: (devServer: NuxtDevServer) => void) => void
}

export async function initialize(devContext: NuxtDevContext, ctx: InitializeOptions = {}): Promise<InitializeReturn> {
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'
18 changes: 9 additions & 9 deletions packages/nuxi/src/main.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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) {
Expand Down Expand Up @@ -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 <template> <name>')} is deprecated.`)
logger.info(`Please use ${colors.cyan('nuxt add-template <template> <name>')} instead.`)
const addTemplate = await import('./commands/add-template').then(m => m.default || m)
const addTemplate = await import('../../nuxt-cli/src/commands/add-template').then(m => m.default || m)
await runCommand(addTemplate, [...ctx.rawArgs.slice(1)]).catch((err) => {
console.error(err.message)
process.exit(1)
Expand Down Expand Up @@ -104,7 +104,7 @@ export const main = _main as CommandDef<any>

export async function runMain(): Promise<void> {
if (process.argv[2] === 'complete') {
const { initCompletions } = await import('./completions')
const { initCompletions } = await import('../../nuxt-cli/src/completions')
await initCompletions(main)
}

Expand Down
30 changes: 1 addition & 29 deletions packages/nuxi/src/run.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import type { ArgsDef, CommandDef } from 'citty'
import process from 'node:process'

import { fileURLToPath } from 'node:url'
import { runCommand as _runCommand } from 'citty'

import { isNuxiCommand } from './commands/_utils'

globalThis.__nuxt_cli__ = globalThis.__nuxt_cli__ || {
// Programmatic usage fallback
Expand All @@ -18,26 +12,4 @@ globalThis.__nuxt_cli__ = globalThis.__nuxt_cli__ || {
}

// To provide subcommands call it as `runCommand(<command>, [<subcommand>, ...])`
export async function runCommand<T extends ArgsDef = ArgsDef>(
command: CommandDef<T>,
argv: string[] = process.argv.slice(2),
data: { overrides?: Record<string, any> } = {},
): Promise<{ result: unknown }> {
argv.push('--no-clear') // Dev
if (command.meta && 'name' in command.meta && typeof command.meta.name === 'string') {
const name = command.meta.name
if (!(isNuxiCommand(name))) {
throw new Error(`Invalid command ${name}`)
}
}
else {
throw new Error(`Invalid command, must be named`)
}

return await _runCommand(command, {
rawArgs: argv,
data: {
overrides: data.overrides || {},
},
})
}
export { runCommandDef as runCommand } from '../../nuxt-cli/src/run'
Loading
Loading