Skip to content

Commit

Permalink
fix(dev): pass programmatic args to sub process
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 3, 2023
1 parent 67d6e1c commit 4fcbd17
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
8 changes: 8 additions & 0 deletions run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { runCommand } from './src/index'

export async function run() {
await runCommand('dev', ['playground'])
return true
}

run()
38 changes: 17 additions & 21 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const command = defineCommand({
if (ctx.args.fork) {
// Fork nuxt dev process
const devProxy = await _createDevProxy(nuxtOptions, listenOptions)
await _startSubprocess(devProxy)
await _startSubprocess(devProxy, ctx.rawArgs)
} else {
// Directly start nuxt dev
const { createNuxtDevServer } = await import('../utils/dev')
Expand Down Expand Up @@ -148,7 +148,7 @@ async function _createDevProxy(
}
}

async function _startSubprocess(devProxy: DevProxy) {
async function _startSubprocess(devProxy: DevProxy, rawArgs: string[]) {
let childProc: ChildProcess | undefined

const kill = (signal: NodeJS.Signals | number) => {
Expand All @@ -163,26 +163,22 @@ async function _startSubprocess(devProxy: DevProxy) {
kill('SIGHUP')

// Start new process
childProc = fork(
globalThis.__nuxt_cli__?.entry!,
['_dev', ...process.argv.slice(3)],
{
execArgv: [
'--enable-source-maps',
process.argv.includes('--inspect') && '--inspect',
].filter(Boolean) as string[],
env: {
...process.env,
__NUXT_DEV__: JSON.stringify({
proxy: {
url: devProxy.listener.url,
urls: await devProxy.listener.getURLs(),
https: devProxy.listener.https,
},
} satisfies NuxtDevContext),
},
childProc = fork(globalThis.__nuxt_cli__?.entry!, ['_dev', ...rawArgs], {
execArgv: [
'--enable-source-maps',
process.argv.includes('--inspect') && '--inspect',
].filter(Boolean) as string[],
env: {
...process.env,
__NUXT_DEV__: JSON.stringify({
proxy: {
url: devProxy.listener.url,
urls: await devProxy.listener.getURLs(),
https: devProxy.listener.https,
},
} satisfies NuxtDevContext),
},
)
})

// Close main process on child exit with error
childProc.on('close', (errorCode) => {
Expand Down

0 comments on commit 4fcbd17

Please sign in to comment.