Skip to content

Commit e3554bc

Browse files
committed
feat(plugin): 添加搜寻全局插件模式
1 parent 2e68857 commit e3554bc

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/models/Project.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var _createClass = function () { function defineProperties(target, props) { for
77
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
88

99
var webpack = require('webpack');
10+
var requireg = require('requireg');
1011

1112
var Config = require('./Config.js'),
1213
Manager = require('../modules/manager.js'),
@@ -78,7 +79,22 @@ var Project = function () {
7879
if (this.extendConfig != 'config') {
7980
var _ret = function () {
8081
var moduleName = 'ykit-config-' + _this.extendConfig,
81-
modulePath = sysPath.join(_this.cwd, 'node_modules', moduleName);
82+
modulePath = '';
83+
84+
var localSearchPath = sysPath.join(_this.cwd, 'node_modules/', moduleName);
85+
var localSearchPathQnpm = sysPath.join(_this.cwd, 'node_modules/', '@qnpm/' + moduleName);
86+
87+
if (requireg.resolve(moduleName)) {
88+
modulePath = requireg.resolve(moduleName);
89+
} else if (requireg.resolve(localSearchPath)) {
90+
modulePath = localSearchPath;
91+
} else if (requireg.resolve('@qnpm/' + moduleName)) {
92+
modulePath = requireg.resolve('@qnpm/' + moduleName);
93+
moduleName = '@qnpm/' + moduleName;
94+
} else if (requireg.resolve(localSearchPathQnpm)) {
95+
modulePath = localSearchPathQnpm;
96+
moduleName = '@qnpm/' + moduleName;
97+
}
8298

8399
extend(true, userConfig.eslintConfig, Manager.loadEslintConfig(modulePath));
84100
extend(true, userConfig.stylelintConfig, Manager.loadStylelintConfig(modulePath));

src/models/Project.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
let webpack = require('webpack');
4+
let requireg = require('requireg');
45

56
let Config = require('./Config.js'),
67
Manager = require('../modules/manager.js'),
@@ -60,7 +61,22 @@ class Project {
6061

6162
if (this.extendConfig != 'config') {
6263
let moduleName = 'ykit-config-' + this.extendConfig,
63-
modulePath = sysPath.join(this.cwd, 'node_modules', moduleName);
64+
modulePath = '';
65+
66+
const localSearchPath = sysPath.join(this.cwd, 'node_modules/', moduleName)
67+
const localSearchPathQnpm = sysPath.join(this.cwd, 'node_modules/', '@qnpm/' + moduleName)
68+
69+
if(requireg.resolve(moduleName)) {
70+
modulePath = requireg.resolve(moduleName)
71+
} else if(requireg.resolve(localSearchPath)) {
72+
modulePath = localSearchPath
73+
} else if(requireg.resolve('@qnpm/' + moduleName)) {
74+
modulePath = requireg.resolve('@qnpm/' + moduleName)
75+
moduleName = '@qnpm/' + moduleName
76+
} else if(requireg.resolve(localSearchPathQnpm)) {
77+
modulePath = localSearchPathQnpm
78+
moduleName = '@qnpm/' + moduleName
79+
}
6480

6581
extend(true, userConfig.eslintConfig, Manager.loadEslintConfig(modulePath));
6682
extend(true, userConfig.stylelintConfig, Manager.loadStylelintConfig(modulePath));

0 commit comments

Comments
 (0)