yeoman-environment 2.3.4 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/resolver.js +54 -15
- package/package.json +1 -1
package/lib/resolver.js
CHANGED
|
@@ -28,11 +28,19 @@ const resolver = module.exports;
|
|
|
28
28
|
* So this index file `node_modules/generator-dummy/lib/generators/yo/index.js` would be
|
|
29
29
|
* registered as `dummy:yo` generator.
|
|
30
30
|
*
|
|
31
|
+
* @param {boolean} [localOnly = false] - Set trueto skip lookups of
|
|
32
|
+
* globally-installed generators.
|
|
31
33
|
* @param {function} cb - Callback called once the lookup is done. Take err as first
|
|
32
34
|
* parameter.
|
|
33
35
|
*/
|
|
34
|
-
resolver.lookup = function (cb) {
|
|
35
|
-
|
|
36
|
+
resolver.lookup = function (localOnly = false, cb) {
|
|
37
|
+
// Resolve signature where localOnly is omitted.
|
|
38
|
+
if (typeof localOnly === 'function') {
|
|
39
|
+
cb = localOnly;
|
|
40
|
+
localOnly = false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const generatorsModules = this.findGeneratorsIn(this.getNpmPaths(localOnly).reverse());
|
|
36
44
|
const patterns = [];
|
|
37
45
|
|
|
38
46
|
for (const lookup of this.lookups) {
|
|
@@ -123,9 +131,50 @@ resolver._tryRegistering = function (generatorReference) {
|
|
|
123
131
|
|
|
124
132
|
/**
|
|
125
133
|
* Get the npm lookup directories (`node_modules/`)
|
|
134
|
+
* @param {boolean} [localOnly = false] - Set true to exclude global lookup
|
|
135
|
+
* directories.
|
|
136
|
+
* @return {Array} lookup paths
|
|
137
|
+
*/
|
|
138
|
+
resolver.getNpmPaths = function (localOnly = false) {
|
|
139
|
+
// Start with the local paths.
|
|
140
|
+
let paths = this._getLocalNpmPaths();
|
|
141
|
+
|
|
142
|
+
// Append global paths, unless they should be excluded.
|
|
143
|
+
if (!localOnly) {
|
|
144
|
+
paths = paths.concat(this._getGlobalNpmPaths());
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return _.uniq(paths);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get the local npm lookup directories
|
|
152
|
+
* @private
|
|
126
153
|
* @return {Array} lookup paths
|
|
127
154
|
*/
|
|
128
|
-
resolver.
|
|
155
|
+
resolver._getLocalNpmPaths = function () {
|
|
156
|
+
const paths = [];
|
|
157
|
+
|
|
158
|
+
// Walk up the CWD and add `node_modules/` folder lookup on each level
|
|
159
|
+
process.cwd().split(path.sep).forEach((part, i, parts) => {
|
|
160
|
+
let lookup = path.join(...parts.slice(0, i + 1), 'node_modules');
|
|
161
|
+
|
|
162
|
+
if (!win32) {
|
|
163
|
+
lookup = `/${lookup}`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
paths.push(lookup);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return _.uniq(paths.reverse());
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Get the global npm lookup directories
|
|
174
|
+
* @private
|
|
175
|
+
* @return {Array} lookup paths
|
|
176
|
+
*/
|
|
177
|
+
resolver._getGlobalNpmPaths = function () {
|
|
129
178
|
let paths = [];
|
|
130
179
|
|
|
131
180
|
// Default paths for each system
|
|
@@ -167,7 +216,8 @@ resolver.getNpmPaths = function () {
|
|
|
167
216
|
const testNpm = spawn.sync('npm', ['-g', 'prefix'], {encoding: 'utf8'});
|
|
168
217
|
if (!testNpm.error) {
|
|
169
218
|
const npmBase = testNpm.stdout.trim();
|
|
170
|
-
|
|
219
|
+
const globalInstall = win32 ? `${npmBase}/node_modules` : `${npmBase}/lib/node_modules`;
|
|
220
|
+
paths.push(path.resolve(globalInstall));
|
|
171
221
|
}
|
|
172
222
|
|
|
173
223
|
// Adds support for generator resolving when yeoman-generator has been linked
|
|
@@ -175,17 +225,6 @@ resolver.getNpmPaths = function () {
|
|
|
175
225
|
paths.push(path.join(path.dirname(process.argv[1]), '../..'));
|
|
176
226
|
}
|
|
177
227
|
|
|
178
|
-
// Walk up the CWD and add `node_modules/` folder lookup on each level
|
|
179
|
-
process.cwd().split(path.sep).forEach((part, i, parts) => {
|
|
180
|
-
let lookup = path.join(...parts.slice(0, i + 1), 'node_modules');
|
|
181
|
-
|
|
182
|
-
if (!win32) {
|
|
183
|
-
lookup = `/${lookup}`;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
paths.push(lookup);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
228
|
return _.uniq(paths.reverse());
|
|
190
229
|
};
|
|
191
230
|
|