@@ -4,27 +4,30 @@ import { resolve } from 'pathe'
4
4
import { tryResolveModule } from '../utils/cjs'
5
5
import { defineNuxtCommand } from './index'
6
6
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
+
9
9
export default defineNuxtCommand ( {
10
10
meta : {
11
11
name : 'build-module' ,
12
12
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 } `
14
14
} ,
15
15
async invoke ( args ) {
16
- // Execute `@nuxt/module-builder` locally if possible
16
+ // Find local installed version
17
17
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 )
19
19
20
20
const execArgs = Object . entries ( {
21
21
'--stub' : args . stub
22
22
} ) . filter ( ( [ , value ] ) => value ) . map ( ( [ key ] ) => key )
23
23
24
+ let cmd = 'nuxt-module-build'
24
25
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 )
26
29
}
27
30
28
- await execa ( 'nuxt-module-build' , execArgs , { preferLocal : true , stdio : 'inherit' , cwd : rootDir } )
31
+ await execa ( cmd , execArgs , { preferLocal : true , stdio : 'inherit' , cwd : rootDir } )
29
32
}
30
33
} )
0 commit comments