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 .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]
}
},
"postStartCommand": "corepack enable && pnpm install && pnpm build --stub",
"postStartCommand": "corepack enable && pnpm install",
"mounts": [
"type=volume,target=${containerWorkspaceFolder}/node_modules",
"type=volume,target=${containerWorkspaceFolder}/dist"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ All commands are listed on https://nuxt.com/docs/api/commands.
# Install dependencies
pnpm i

# Generate type stubs
pnpm dev:prepare
# Build project and start watcher
pnpm dev

# Go to the playground directory
cd playground

# And run any commands
pnpm nuxi <command>
pnpm nuxt <command>
```

## License
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
"license": "MIT",
"repository": "nuxt/cli",
"scripts": {
"dev:prepare": "pnpm -r dev:prepare",
"build": "pnpm -r build",
"build:stub": "pnpm -r dev:prepare",
"dev": "pnpm -r build --watch",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"nuxi": "node ./packages/nuxi/bin/nuxi.mjs",
"nuxt": "node ./packages/nuxt-cli/bin/nuxi.mjs",
"nuxi-bun": "bun --bun ./packages/nuxi/bin/nuxi.mjs",
"prepack": "pnpm -r build",
"nuxi-bun": "bun --bun ./packages/nuxt-cli/bin/nuxi.mjs",
"postinstall": "pnpm build",
"test:types": "tsc --noEmit",
"test:knip": "knip",
"test:dist": "pnpm -r test:dist",
Expand Down
42 changes: 0 additions & 42 deletions packages/create-nuxt/build.config.ts

This file was deleted.

7 changes: 3 additions & 4 deletions packages/create-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
"node": "^16.10.0 || >=18.0.0"
},
"scripts": {
"dev:prepare": "unbuild --stub",
"build": "unbuild",
"prepack": "unbuild"
"build": "tsdown",
"prepack": "tsdown"
},
"dependencies": {
"citty": "^0.1.6"
Expand All @@ -36,8 +35,8 @@
"@types/node": "^22.18.12",
"rollup": "^4.52.5",
"rollup-plugin-visualizer": "^6.0.5",
"tsdown": "^0.15.9",
"typescript": "^5.9.3",
"unbuild": "^3.6.1",
"unplugin-purge-polyfills": "^0.1.0"
}
}
5 changes: 4 additions & 1 deletion packages/create-nuxt/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CommandDef } from 'citty'
import { defineCommand } from 'citty'
import { provider } from 'std-env'

Expand All @@ -7,7 +8,7 @@ import { checkEngines } from '../../nuxi/src/utils/engines'
import { logger } from '../../nuxi/src/utils/logger'
import { description, name, version } from '../package.json'

export const main = defineCommand({
const _main = defineCommand({
meta: {
name,
version,
Expand All @@ -25,3 +26,5 @@ export const main = defineCommand({
await init.run?.(ctx)
},
})

export const main = _main as CommandDef<any>
4 changes: 2 additions & 2 deletions packages/create-nuxt/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ globalThis.__nuxt_cli__ = globalThis.__nuxt_cli__ || {
),
}

export const runMain = () => _runMain(main)
export const runMain = (): Promise<void> => _runMain(main)

export async function runCommand(
name: 'init',
argv: string[] = process.argv.slice(2),
data: { overrides?: Record<string, any> } = {},
) {
): Promise<{ result: unknown }> {
return await _runCommand(init, {
rawArgs: argv,
data: {
Expand Down
20 changes: 20 additions & 0 deletions packages/create-nuxt/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { UserConfig } from 'tsdown'
import process from 'node:process'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'tsdown'
import { purgePolyfills } from 'unplugin-purge-polyfills'

const isAnalysingSize = process.env.BUNDLE_SIZE === 'true'

export default defineConfig({
entry: ['src/index.ts'],
fixedExtension: true,
dts: !isAnalysingSize && {
oxc: true,
},
failOnWarn: !isAnalysingSize,
plugins: [
purgePolyfills.rolldown({ logLevel: 'verbose' }),
...(isAnalysingSize ? [visualizer({ template: 'raw-data' })] : []),
],
}) satisfies UserConfig as UserConfig
45 changes: 0 additions & 45 deletions packages/nuxi/build.config.ts

This file was deleted.

13 changes: 3 additions & 10 deletions packages/nuxi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,8 @@
"node": "^16.10.0 || >=18.0.0"
},
"scripts": {
"dev:prepare": "unbuild --stub",
"build": "unbuild",
"build:stub": "unbuild --stub",
"dev": "node ./bin/nuxi.mjs dev ./playground",
"dev:bun": "bun --bun ./bin/nuxi.mjs dev ./playground",
"nuxi": "node ./bin/nuxi.mjs",
"nuxi-bun": "bun --bun ./bin/nuxi.mjs",
"prepack": "unbuild",
"test:dist": "node ./bin/nuxi.mjs info ./playground"
"build": "tsdown",
"prepack": "tsdown"
},
"devDependencies": {
"@nuxt/kit": "^4.1.3",
Expand Down Expand Up @@ -72,9 +65,9 @@
"srvx": "^0.8.16",
"std-env": "^3.10.0",
"tinyexec": "^1.0.1",
"tsdown": "^0.15.9",
"typescript": "^5.9.3",
"ufo": "^1.6.1",
"unbuild": "^3.6.1",
"undici": "^7.16.0",
"unplugin-purge-polyfills": "^0.1.0",
"vitest": "^3.2.4",
Expand Down
3 changes: 3 additions & 0 deletions packages/nuxi/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ async function startSubprocess(cwd: string, args: { logLevel: string, clear: boo

async function restart() {
devHandler?.clearError()
if (!globalThis.__nuxt_cli__) {
return
}
// Kill previous process with restart signal (not supported on Windows)
if (process.platform === 'win32') {
kill('SIGTERM')
Expand Down
18 changes: 16 additions & 2 deletions packages/nuxi/src/dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NuxtConfig } from '@nuxt/schema'
import type { ListenOptions } from 'listhen'
import type { Listener, ListenOptions } from 'listhen'
import type { AddressInfo } from 'node:net'
import type { NuxtDevContext, NuxtDevIPCMessage, NuxtParentIPCMessage } from './utils'

import process from 'node:process'
Expand Down Expand Up @@ -47,7 +48,20 @@ class IPC {

const ipc = new IPC()

export async function initialize(devContext: NuxtDevContext, ctx: InitializeOptions = {}, _listenOptions?: true | Partial<ListenOptions>) {
interface InitializeReturn {
listener: Pick<Listener, 'https' | 'server' | 'url' | 'getURLs' | 'close'> & {
_url?: string
address: (Omit<AddressInfo, 'family'> & {
socketPath: string
}) | AddressInfo
}
close: () => Promise<void>
onReady: (callback: (address: string) => void) => void
onRestart: (callback: (devServer: NuxtDevServer) => void) => void

}

export async function initialize(devContext: NuxtDevContext, ctx: InitializeOptions = {}, _listenOptions?: true | Partial<ListenOptions>): Promise<InitializeReturn> {
const devServerOverrides = resolveDevServerOverrides({
public: devContext.public,
})
Expand Down
22 changes: 11 additions & 11 deletions packages/nuxi/src/dev/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
this.listener = undefined
}

_renderError(req: IncomingMessage, res: ServerResponse) {
_renderError(req: IncomingMessage, res: ServerResponse): void {
renderError(req, res, this._loadingError)
}

async _renderLoadingScreen(req: IncomingMessage, res: ServerResponse) {
async _renderLoadingScreen(req: IncomingMessage, res: ServerResponse): Promise<void> {
if (res.headersSent) {
if (!res.writableEnded) {
res.end()
Expand All @@ -178,17 +178,17 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
)
}

async init() {
async init(): Promise<void> {
await this.load()
this._watchConfig()
}

closeWatchers() {
closeWatchers(): void {
this._distWatcher?.close()
this._configWatcher?.()
}

async load(reload?: boolean, reason?: string) {
async load(reload?: boolean, reason?: string): Promise<void> {
try {
this.closeWatchers()
await this._load(reload, reason)
Expand All @@ -204,13 +204,13 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
}
}

async close() {
async close(): Promise<void> {
if (this._currentNuxt) {
await this._currentNuxt.close()
}
}

async _load(reload?: boolean, reason?: string) {
async _load(reload?: boolean, reason?: string): Promise<void> {
const action = reload ? 'Restarting' : 'Starting'
this._loadingMessage = `${reason ? `${reason}. ` : ''}${action} Nuxt...`
this._handler = undefined
Expand Down Expand Up @@ -352,7 +352,7 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
this.emit('ready', 'socketPath' in addr ? formatSocketURL(addr.socketPath, !!this.listener.https) : `http://127.0.0.1:${addr.port}`)
}

_watchConfig() {
_watchConfig(): void {
this._configWatcher = createConfigWatcher(
this.cwd,
this.options.dotenv.fileName,
Expand All @@ -372,7 +372,7 @@ function getAddressURL(addr: Pick<AddressInfo, 'address' | 'port'>, https: boole
return `${proto}://${host}:${port}/`
}

export function resolveDevServerOverrides(listenOptions: Partial<Pick<ListenOptions, 'public'>>) {
export function resolveDevServerOverrides(listenOptions: Partial<Pick<ListenOptions, 'public'>>): Partial<Pick<NuxtConfig, 'devServer' | 'vite'>> {
if (listenOptions.public || provider === 'codesandbox') {
return {
devServer: { cors: { origin: '*' } },
Expand All @@ -383,7 +383,7 @@ export function resolveDevServerOverrides(listenOptions: Partial<Pick<ListenOpti
return {}
}

export function resolveDevServerDefaults(listenOptions: Partial<Pick<ListenOptions, 'hostname' | 'https'>>, urls: string[] = []) {
export function resolveDevServerDefaults(listenOptions: Partial<Pick<ListenOptions, 'hostname' | 'https'>>, urls: string[] = []): Partial<NuxtConfig> {
const defaultConfig: Partial<NuxtConfig> = {}

if (urls) {
Expand Down Expand Up @@ -453,7 +453,7 @@ function createConfigDirWatcher(cwd: string, onReload: (file: string) => void) {
}

// Nuxt <3.6 did not have the loading template defined in the schema
export async function resolveLoadingTemplate(cwd: string) {
export async function resolveLoadingTemplate(cwd: string): Promise<({ loading }: { loading?: string }) => string> {
const nuxtPath = resolveModulePath('nuxt', { from: cwd, try: true })
const uiTemplatesPath = resolveModulePath('@nuxt/ui-templates', { from: nuxtPath || cwd })
const r: { loading: (opts?: { loading?: string }) => string } = await import(pathToFileURL(uiTemplatesPath).href)
Expand Down
7 changes: 5 additions & 2 deletions packages/nuxi/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CommandDef } from 'citty'
import nodeCrypto from 'node:crypto'
import { builtinModules, createRequire } from 'node:module'
import { resolve } from 'node:path'
Expand Down Expand Up @@ -29,7 +30,7 @@ if (!process.getBuiltinModule) {
}
}

export const main = defineCommand({
const _main = defineCommand({
meta: {
name: name.endsWith('nightly') ? name : 'nuxi',
version,
Expand Down Expand Up @@ -84,4 +85,6 @@ export const main = defineCommand({
},
})

export const runMain = () => _runMain(main)
export const main = _main as CommandDef<any>

export const runMain = (): Promise<void> => _runMain(main)
Loading
Loading