Skip to content

Commit 8342487

Browse files
waitingsongczy88840616
authored andcommitted
fix: module path under mono repo
reutrn full path of module #329
1 parent 3a065bb commit 8342487

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

packages/midway-bin/lib/cmd/debug.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const resolver = require('../util').resolveModule;
23

34
class DebugCommand extends require('egg-bin').DebugCommand {
45
constructor(rawArgv) {
@@ -14,13 +15,7 @@ class DebugCommand extends require('egg-bin').DebugCommand {
1415
}
1516

1617
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);
2419
}
2520
}
2621

packages/midway-bin/lib/cmd/dev.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const resolver = require('../util').resolveModule;
23

34
class DevCommand extends require('egg-bin/lib/cmd/dev') {
45
constructor(rawArgv) {
@@ -15,13 +16,7 @@ class DevCommand extends require('egg-bin/lib/cmd/dev') {
1516
}
1617

1718
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);
2520
}
2621
}
2722

packages/midway-bin/lib/util.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
});

0 commit comments

Comments
 (0)