File tree Expand file tree Collapse file tree 4 files changed +45
-14
lines changed Expand file tree Collapse file tree 4 files changed +45
-14
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
+ const resolver = require ( '../util' ) . resolveModule ;
2
3
3
4
class DebugCommand extends require ( 'egg-bin' ) . DebugCommand {
4
5
constructor ( rawArgv ) {
@@ -14,13 +15,7 @@ class DebugCommand extends require('egg-bin').DebugCommand {
14
15
}
15
16
16
17
findFramework ( module ) {
17
- try {
18
- if ( require . resolve ( module ) ) {
19
- return module ;
20
- }
21
- } catch ( err ) {
22
- console . log ( `[midway-bin] Not found framework ${ module } and skip.` ) ;
23
- }
18
+ return resolver ( module ) ;
24
19
}
25
20
}
26
21
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
+ const resolver = require ( '../util' ) . resolveModule ;
2
3
3
4
class DevCommand extends require ( 'egg-bin/lib/cmd/dev' ) {
4
5
constructor ( rawArgv ) {
@@ -15,13 +16,7 @@ class DevCommand extends require('egg-bin/lib/cmd/dev') {
15
16
}
16
17
17
18
findFramework ( module ) {
18
- try {
19
- if ( require . resolve ( module ) ) {
20
- return module ;
21
- }
22
- } catch ( err ) {
23
- console . log ( `[midway-bin] Not found framework ${ module } and skip.` ) ;
24
- }
19
+ return resolver ( module ) ;
25
20
}
26
21
}
27
22
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ const path = require ( 'path' ) ;
3
+
4
+ function resolveModule ( moduleName ) {
5
+ if ( ! moduleName ) {
6
+ console . log ( '[midway-bin] value of framework is blank and skipped.' ) ;
7
+ return ;
8
+ }
9
+
10
+ try {
11
+ require . resolve ( moduleName ) ;
12
+ const moduleDir = path . join ( __dirname , '../../' ) ;
13
+ const moduleFullPath = path . join ( moduleDir , moduleName ) ;
14
+ return moduleFullPath ;
15
+ } catch ( err ) {
16
+ console . log ( `[midway-bin] Not found framework ${ moduleName } and skip.` ) ;
17
+ }
18
+ }
19
+
20
+ exports . resolveModule = resolveModule ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const assert = require ( 'assert' ) ;
4
+
5
+ const util = require ( '../../lib/util.js' ) ;
6
+
7
+ describe ( 'test/lib/util.test.js' , ( ) => {
8
+
9
+ it ( 'should return full path of module' , function ( ) {
10
+ const moduleName = 'egg'
11
+ const path = util . resolveModule ( moduleName )
12
+ assert ( path && path . length > moduleName . length ) ;
13
+ } ) ;
14
+
15
+ it ( 'should return void with invalid input' , function ( ) {
16
+ const moduleName = 'egg' + Math . random ( )
17
+ const path = util . resolveModule ( moduleName )
18
+ assert ( ! path ) ;
19
+ } ) ;
20
+
21
+ } ) ;
You can’t perform that action at this time.
0 commit comments