-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(dev): rewrite dev to support
--no-fork
and improve stabili…
…ty (#153)
- Loading branch information
Showing
8 changed files
with
392 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { resolve } from 'pathe' | ||
import { consola } from 'consola' | ||
import { overrideEnv } from '../utils/env' | ||
import { defineCommand } from 'citty' | ||
import { sharedArgs, legacyRootDirArgs } from './_shared' | ||
import { isTest } from 'std-env' | ||
import { NuxtDevIPCMessage, createNuxtDevServer } from '../utils/dev' | ||
import type { ListenURL, HTTPSOptions } from 'listhen' | ||
|
||
export type DevChildContext = { | ||
url?: string | ||
urls?: ListenURL[] | ||
https?: boolean | HTTPSOptions | ||
} | ||
|
||
export default defineCommand({ | ||
meta: { | ||
name: '_dev', | ||
description: | ||
'Run nuxt development server (internal command to start child process)', | ||
}, | ||
args: { | ||
...sharedArgs, | ||
...legacyRootDirArgs, | ||
}, | ||
async run(ctx) { | ||
const logger = consola.withTag('nuxi') | ||
|
||
if (!process.send && !isTest) { | ||
logger.warn( | ||
'`nuxi _dev` is an internal command and should not be used directly. Please use `nuxi dev` instead.', | ||
) | ||
} | ||
|
||
// Prepare | ||
overrideEnv('development') | ||
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir || '.') | ||
|
||
// Get host info | ||
const devProxyOptions: DevChildContext = | ||
JSON.parse(process.env.__NUXT_DEV_PROXY__ || 'null') || {} | ||
|
||
// Init Nuxt dev | ||
const nuxtDev = await createNuxtDevServer({ | ||
cwd, | ||
overrides: ctx.data?.overrides, | ||
logLevel: ctx.args.logLevel as 'silent' | 'info' | 'verbose', | ||
clear: !!ctx.args.clear, | ||
dotenv: !!ctx.args.dotenv, | ||
https: devProxyOptions.https, | ||
}) | ||
|
||
// IPC Hooks | ||
function sendIPCMessage<T extends NuxtDevIPCMessage>(message: T) { | ||
if (process.send) { | ||
process.send(message) | ||
} else { | ||
logger.info( | ||
'Dev server event:', | ||
Object.entries(message) | ||
.map((e) => e[0] + '=' + JSON.stringify(e[1])) | ||
.join(' '), | ||
) | ||
} | ||
} | ||
nuxtDev.on('loading', (message) => { | ||
sendIPCMessage({ type: 'nuxt:internal:dev:loading', message }) | ||
}) | ||
nuxtDev.on('restart', () => { | ||
sendIPCMessage({ type: 'nuxt:internal:dev:restart' }) | ||
}) | ||
nuxtDev.on('ready', (payload) => { | ||
sendIPCMessage({ type: 'nuxt:internal:dev:ready', port: payload.port }) | ||
}) | ||
|
||
// Init server | ||
await nuxtDev.init() | ||
}, | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.