Skip to content

Commit

Permalink
debugging ensureExternal
Browse files Browse the repository at this point in the history
  • Loading branch information
galvez committed Dec 18, 2018
1 parent dd72175 commit 87f9ed2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
7 changes: 6 additions & 1 deletion packages/cli/src/command.js
Expand Up @@ -13,7 +13,12 @@ export default class NuxtCommand {
}

static async ensureExternal() {
const command = process.argv.slice(0, 3).join('-')
const parts = process.argv.slice(1, 4)
if (parts[0] !== 'nuxt') {
parts[0] = 'nuxt'
}
const command = parts.join('-')
console.log('command', command)
if (!await commandExists(command)) {
throw new Error(`Module command ${command} failed to load!`)
}
Expand Down
45 changes: 19 additions & 26 deletions packages/cli/src/run.js
Expand Up @@ -7,41 +7,34 @@ import setup from './setup'

export default async function run(custom = null) {
if (custom) {
try {
custom.run()
} catch (error) {
consola.fatal(error)
}
await custom.run()
return
}

const cmd = process.argv[2] || 'dev'
try {
const isExternal = await NuxtCommand.ensure(cmd)
console.log('!')
const isExternal = await NuxtCommand.ensure(cmd)
console.log('isExternal', isExternal)

if (isExternal) {
process.argv.splice(2, 1)
try {
spawn(process.argv[0], process.argv.slice(1))
} catch (error) {
consola.fatal(error)
}
return
}
} catch (notFoundError) {
if (process.argv.includes('--help') || process.argv.includes('-h')) {
return listCommands().then(() => process.exit(0))
} else {
throw notFoundError
if (isExternal) {
process.argv.splice(2, 1)
try {
spawn(process.argv[0], process.argv.slice(1))
} catch (error) {
consola.fatal(error)
}
return
}
// } catch (notFoundError) {
// if (process.argv.includes('--help') || process.argv.includes('-h')) {
// return listCommands().then(() => process.exit(0))
// } else {
// throw notFoundError
// }
// }

process.argv.splice(2, 1)
setup({ dev: cmd === 'dev' })

try {
await NuxtCommand.run(cmd)
} catch (error) {
consola.fatal(error)
}
await NuxtCommand.run(cmd)
}
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -2912,6 +2912,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

command-exists@^1.2.8:
version "1.2.8"
resolved "https://registry.npmjs.org/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291"
integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw==

commander@2.17.x, commander@~2.17.1:
version "2.17.1"
resolved "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
Expand Down

0 comments on commit 87f9ed2

Please sign in to comment.