Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fallback to npx if not locally found
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 16, 2022
1 parent 2f2f0a2 commit 4489c35
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/nuxi/src/commands/build-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@ import { resolve } from 'pathe'
import { tryResolveModule } from '../utils/cjs'
import { defineNuxtCommand } from './index'

// Stub `build-module` until we have proper support for it
// @see https://github.com/nuxt/module-builder/issues/32
const MODULE_BUILDER_PKG = '@nuxt/module-builder'

export default defineNuxtCommand({
meta: {
name: 'build-module',
usage: 'npx nuxi build-module [--stub] [rootDir]',
description: 'Helper command for using `@nuxt/module-builder`'
description: `Helper command for using ${MODULE_BUILDER_PKG}`
},
async invoke (args) {
// Execute `@nuxt/module-builder` locally if possible
// Find local installed version
const rootDir = resolve(args._[0] || '.')
const hasLocal = tryResolveModule('@nuxt/module-builder/package.json', rootDir)
const hasLocal = tryResolveModule(`${MODULE_BUILDER_PKG}/package.json`, rootDir)

const execArgs = Object.entries({
'--stub': args.stub
}).filter(([, value]) => value).map(([key]) => key)

let cmd = 'nuxt-module-build'
if (!hasLocal) {
return consola.error('Missing `@nuxt/module-builder` dependency, please install it first to use this command')
consola.warn(`Cannot find locally installed version of \`${MODULE_BUILDER_PKG}\` (>=0.2.0). Falling back to \`npx ${MODULE_BUILDER_PKG}\``)
cmd = 'npx'
execArgs.unshift(MODULE_BUILDER_PKG)
}

await execa('nuxt-module-build', execArgs, { preferLocal: true, stdio: 'inherit', cwd: rootDir })
await execa(cmd, execArgs, { preferLocal: true, stdio: 'inherit', cwd: rootDir })
}
})

0 comments on commit 4489c35

Please sign in to comment.