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

Commit 4489c35

Browse files
committed
fallback to npx if not locally found
1 parent 2f2f0a2 commit 4489c35

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

packages/nuxi/src/commands/build-module.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@ import { resolve } from 'pathe'
44
import { tryResolveModule } from '../utils/cjs'
55
import { defineNuxtCommand } from './index'
66

7-
// Stub `build-module` until we have proper support for it
8-
// @see https://github.com/nuxt/module-builder/issues/32
7+
const MODULE_BUILDER_PKG = '@nuxt/module-builder'
8+
99
export default defineNuxtCommand({
1010
meta: {
1111
name: 'build-module',
1212
usage: 'npx nuxi build-module [--stub] [rootDir]',
13-
description: 'Helper command for using `@nuxt/module-builder`'
13+
description: `Helper command for using ${MODULE_BUILDER_PKG}`
1414
},
1515
async invoke (args) {
16-
// Execute `@nuxt/module-builder` locally if possible
16+
// Find local installed version
1717
const rootDir = resolve(args._[0] || '.')
18-
const hasLocal = tryResolveModule('@nuxt/module-builder/package.json', rootDir)
18+
const hasLocal = tryResolveModule(`${MODULE_BUILDER_PKG}/package.json`, rootDir)
1919

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

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

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

0 commit comments

Comments
 (0)