yeoman-environment 2.2.0 → 2.3.3

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.
@@ -31,6 +31,25 @@ function splitArgsFromString(argsString) {
31
31
  return result;
32
32
  }
33
33
 
34
+ /**
35
+ * Wrap callback so it can't get called twice
36
+ */
37
+ const callbackWrapper = (generator, done) => {
38
+ if (!done) {
39
+ return _.noop();
40
+ }
41
+ let callbackHandled = false;
42
+ const callback = err => {
43
+ if (!callbackHandled) {
44
+ callbackHandled = true;
45
+ done(err);
46
+ }
47
+ };
48
+ // If error was thrown, make sure it is handled and only once
49
+ generator.on('error', callback);
50
+ return callback;
51
+ };
52
+
34
53
  /**
35
54
  * `Environment` object is responsible of handling the lifecyle and bootstrap
36
55
  * of generators in a specific environment (your app).
@@ -242,11 +261,12 @@ class Environment extends EventEmitter {
242
261
  * functions under the provided namespace. `registerStub` will enforce the function passed
243
262
  * to extend the Base generator automatically.
244
263
  *
245
- * @param {Function} Generator - A Generator constructor or a simple function
246
- * @param {String} namespace - Namespace under which register the generator
264
+ * @param {Function} Generator - A Generator constructor or a simple function
265
+ * @param {String} namespace - Namespace under which register the generator
266
+ * @param {String} [resolved] - The file path to the generator
247
267
  * @return {this}
248
268
  */
249
- registerStub(Generator, namespace) {
269
+ registerStub(Generator, namespace, resolved) {
250
270
  if (typeof Generator !== 'function') {
251
271
  return this.error(new Error('You must provide a stub function to register.'));
252
272
  }
@@ -255,7 +275,7 @@ class Environment extends EventEmitter {
255
275
  return this.error(new Error('You must provide a namespace to register.'));
256
276
  }
257
277
 
258
- this.store.add(namespace, Generator);
278
+ this.store.add(namespace, Generator, resolved);
259
279
 
260
280
  return this;
261
281
  }
@@ -452,7 +472,9 @@ class Environment extends EventEmitter {
452
472
  return console.log(generator.help());
453
473
  }
454
474
 
455
- return generator.run(done);
475
+ const _callbackWrapper = callbackWrapper(generator, done);
476
+
477
+ return generator.run(_callbackWrapper);
456
478
  }
457
479
 
458
480
  /**
package/lib/resolver.js CHANGED
@@ -42,7 +42,7 @@ resolver.lookup = function (cb) {
42
42
  }
43
43
 
44
44
  for (const pattern of patterns) {
45
- for (const filename of globby.sync('*/index.js', {cwd: pattern, absolute: true})) {
45
+ for (const filename of globby.sync('*/index.js', {cwd: pattern, absolute: true, deep: 1})) {
46
46
  this._tryRegistering(filename);
47
47
  }
48
48
  }
@@ -73,9 +73,24 @@ resolver.findGeneratorsIn = function (searchPaths) {
73
73
  // restricted folders.
74
74
  try {
75
75
  modules = modules.concat(globby.sync(
76
- ['generator-*', '@*/generator-*'],
77
- {cwd: root, onlyFiles: false, absolute: true}
76
+ ['generator-*'],
77
+ {cwd: root, onlyFiles: false, absolute: true, deep: 0}
78
78
  ));
79
+
80
+ // To limit recursive lookups into non-namespace folders within globby,
81
+ // fetch all namespaces in root, then search each namespace separately
82
+ // for generator modules
83
+ const namespaces = globby.sync(
84
+ ['@*'],
85
+ {cwd: root, onlyFiles: false, absolute: true, deep: 0}
86
+ );
87
+
88
+ for (const namespace of namespaces) {
89
+ modules = modules.concat(globby.sync(
90
+ ['generator-*'],
91
+ {cwd: namespace, onlyFiles: false, absolute: true, deep: 0}
92
+ ));
93
+ }
79
94
  } catch (err) {
80
95
  debug('Could not access %s (%s)', root, err);
81
96
  }
package/lib/store.js CHANGED
@@ -15,16 +15,17 @@ class Store {
15
15
 
16
16
  /**
17
17
  * Store a module under the namespace key
18
- * @param {String} namespace - The key under which the generator can be retrieved
19
- * @param {String|Function} generator - A generator module or a module path
18
+ * @param {String} namespace - The key under which the generator can be retrieved
19
+ * @param {String|Function} generator - A generator module or a module path
20
+ * @param {String} [resolved] - The file path to the generator (used only if generator is a module)
20
21
  */
21
- add(namespace, generator) {
22
+ add(namespace, generator, resolved) {
22
23
  if (typeof generator === 'string') {
23
24
  this._storeAsPath(namespace, generator);
24
25
  return;
25
26
  }
26
27
 
27
- this._storeAsModule(namespace, generator);
28
+ this._storeAsModule(namespace, generator, resolved);
28
29
  }
29
30
 
30
31
  _storeAsPath(namespace, path) {
@@ -43,9 +44,9 @@ class Store {
43
44
  });
44
45
  }
45
46
 
46
- _storeAsModule(namespace, Generator) {
47
+ _storeAsModule(namespace, Generator, resolved = 'unknown') {
47
48
  this._meta[namespace] = {
48
- resolved: 'unknown',
49
+ resolved,
49
50
  namespace
50
51
  };
51
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-environment",
3
- "version": "2.2.0",
3
+ "version": "2.3.3",
4
4
  "description": "Handles the lifecyle and bootstrapping of generators in a specific environment",
5
5
  "homepage": "http://yeoman.io",
6
6
  "author": "Yeoman",
@@ -28,37 +28,35 @@
28
28
  "test": "nyc mocha",
29
29
  "doc": "jsdoc -c ./jsdoc.json ./readme.md",
30
30
  "benchmark": "matcha benchmark/**",
31
- "prepublish": "nsp check",
32
31
  "coverage": "nyc report --reporter=text-lcov | coveralls"
33
32
  },
34
33
  "dependencies": {
35
- "chalk": "^2.1.0",
34
+ "chalk": "^2.4.1",
36
35
  "cross-spawn": "^6.0.5",
37
36
  "debug": "^3.1.0",
38
- "diff": "^3.3.1",
37
+ "diff": "^3.5.0",
39
38
  "escape-string-regexp": "^1.0.2",
40
39
  "globby": "^8.0.1",
41
40
  "grouped-queue": "^0.3.3",
42
- "inquirer": "^5.2.0",
41
+ "inquirer": "^6.0.0",
43
42
  "is-scoped": "^1.0.0",
44
43
  "lodash": "^4.17.10",
45
- "log-symbols": "^2.1.0",
44
+ "log-symbols": "^2.2.0",
46
45
  "mem-fs": "^1.1.0",
47
46
  "strip-ansi": "^4.0.0",
48
47
  "text-table": "^0.2.0",
49
- "untildify": "^3.0.2"
48
+ "untildify": "^3.0.3"
50
49
  },
51
50
  "devDependencies": {
52
- "coveralls": "^3.0.1",
51
+ "coveralls": "^3.0.2",
53
52
  "jsdoc": "^3.5.5",
54
53
  "matcha": "^0.7.0",
55
- "mocha": "^5.1.1",
56
- "nsp": "^3.2.1",
57
- "nyc": "^11.7.3",
58
- "sinon": "^5.0.7",
59
- "sinon-test": "^2.1.3",
60
- "xo": "^0.18.1",
61
- "yeoman-assert": "^3.0.0",
54
+ "mocha": "^5.2.0",
55
+ "nyc": "^11.9.0",
56
+ "sinon": "^5.1.1",
57
+ "sinon-test": "^2.2.1",
58
+ "xo": "^0.18.2",
59
+ "yeoman-assert": "^3.1.1",
62
60
  "yeoman-generator": "^2.0.5"
63
61
  },
64
62
  "xo": {