yeoman-environment 3.8.1 → 3.10.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/command.js CHANGED
@@ -21,7 +21,7 @@ module.exports = cls => class EnvironmentCommand extends cls {
21
21
  .option('--skip-yo-resolve', 'Ignore .yo-resolve files', false)
22
22
  /* Hidden options, used for api */
23
23
  .addOption(new Option('--skip-local-cache', 'Skip local answers cache').default(true).hideHelp())
24
- .addOption(new Option('--skip-parse-options', 'Skip legacy options parsing').default(true).hideHelp())
24
+ .addOption(new Option('--skip-parse-options', 'Skip legacy options parsing').default(false).hideHelp())
25
25
  .addOption(new Option('--experimental', 'Experimental features').default(false).hideHelp())
26
26
  .addOption(new Option('--log-cwd', 'Path for log purpose').hideHelp());
27
27
  }
@@ -147,19 +147,22 @@ class Environment extends Base {
147
147
  * @param {Class} GeneratorClass - Generator to create Command
148
148
  * @return {Command} return command
149
149
  */
150
- static prepareGeneratorCommand(command, GeneratorClass) {
150
+ static prepareGeneratorCommand(command, GeneratorClass, namespace) {
151
151
  const generator = new GeneratorClass([], {help: true, env: {}});
152
152
  Base.addGeneratorOptions(command, generator);
153
153
 
154
154
  command.action(async function () {
155
- command.env = Environment.createEnv(this.opts());
156
-
157
155
  let rootCommand = this;
158
156
  while (rootCommand.parent) {
159
157
  rootCommand = rootCommand.parent;
160
158
  }
159
+ command.env = Environment.createEnv(rootCommand.opts());
160
+
161
161
  rootCommand.emit('yeoman:environment', command.env);
162
162
 
163
+ if (namespace) {
164
+ return command.env.run([namespace, ...(this.args || [])], this.opts()).then(() => command.env);
165
+ }
163
166
  const generator = command.env.instantiate(GeneratorClass, this.args, this.opts());
164
167
  await command.env.queueGenerator(generator);
165
168
  return command.env.start().then(() => command.env);
@@ -561,7 +564,8 @@ class Environment extends Base {
561
564
  * @return {boolean} - true if any generator of the package has been registered
562
565
  */
563
566
  isPackageRegistered(packageNS) {
564
- return this.getRegisteredPackages().includes(packageNS);
567
+ const registeredPackages = this.getRegisteredPackages();
568
+ return registeredPackages.includes(packageNS) || registeredPackages.includes(this.alias(packageNS).split(':', 2)[0]);
565
569
  }
566
570
 
567
571
  /**
@@ -738,9 +742,13 @@ class Environment extends Base {
738
742
  }
739
743
 
740
744
  const checkGenerator = Generator => {
741
- if (namespace && Generator && Generator.namespace && Generator.namespace !== Environment.UNKNOWN_NAMESPACE) {
742
- // Update namespace object in case of aliased namespace.
743
- namespace.namespace = Generator.namespace;
745
+ if (namespace && Generator && Generator.namespace && Generator.namespace !== namespace.namespace && Generator.namespace !== Environment.UNKNOWN_NAMESPACE) {
746
+ // Update namespace object in case of aliased namespace.
747
+ try {
748
+ namespace.namespace = Generator.namespace;
749
+ } catch {
750
+ // Invalid namespace can be aliased to a valid one.
751
+ }
744
752
  }
745
753
 
746
754
  if (typeof Generator !== 'function') {
@@ -761,16 +769,10 @@ class Environment extends Base {
761
769
  };
762
770
 
763
771
  maybeGenerator = maybeGenerator || this.get(namespaceOrPath);
764
- if (maybeGenerator && (maybeGenerator.then || maybeGenerator.prototype._postConstruct)) {
772
+ if (maybeGenerator && maybeGenerator.then) {
765
773
  return Promise.resolve(maybeGenerator)
766
774
  .then(Generator => checkGenerator(Generator))
767
- .then(Generator => this.instantiate(Generator, args, options))
768
- .then(async generator => {
769
- if (!options.help && generator._postConstruct) {
770
- await generator._postConstruct();
771
- }
772
- return generator;
773
- });
775
+ .then(Generator => this.instantiate(Generator, args, options));
774
776
  }
775
777
 
776
778
  return this.instantiate(checkGenerator(maybeGenerator), args, options);
@@ -813,6 +815,10 @@ class Environment extends Base {
813
815
  ...environmentOptions
814
816
  };
815
817
 
818
+ if (!options.help && generator._postConstruct) {
819
+ return Promise.resolve(generator._postConstruct()).then(() => generator);
820
+ }
821
+
816
822
  return generator;
817
823
  }
818
824
 
package/lib/store.js CHANGED
@@ -58,6 +58,9 @@ class Store {
58
58
  packagePath
59
59
  };
60
60
 
61
+ if (this._generators[namespace]) {
62
+ delete this._generators[namespace];
63
+ }
61
64
  this._generators[namespace] = Generator;
62
65
  }
63
66
 
@@ -115,15 +115,20 @@ class Conflicter {
115
115
  *
116
116
  * Based on detect-conflict module
117
117
  *
118
- * @param {Object} file File object respecting this interface: { path, contents }
118
+ * @param {import('vinyl')} file File object respecting this interface: { path, contents }
119
119
  * @return {Boolean} `true` if there's a conflict, `false` otherwise.
120
120
  */
121
121
  _detectConflict(file) {
122
- let {contents} = file;
122
+ let {contents, stat = {}} = file;
123
123
  const filepath = path.resolve(file.path);
124
124
 
125
125
  // If file path point to a directory, then it's not safe to write
126
- if (fs.statSync(filepath).isDirectory()) {
126
+ const diskStat = fs.statSync(filepath);
127
+ if (diskStat.isDirectory()) {
128
+ return true;
129
+ }
130
+
131
+ if (stat.mode && diskStat.mode !== stat.mode) {
127
132
  return true;
128
133
  }
129
134
 
@@ -172,7 +177,7 @@ class Conflicter {
172
177
  * 3. If identical, mark it as is and skip the check
173
178
  * 4. If diverged, prepare and show up the file collision menu
174
179
  *
175
- * @param {Object} file - Vinyl file
180
+ * @param {import('vinyl')} file - Vinyl file
176
181
  * @param {Object} [conflicterStatus] - Conflicter status
177
182
  * @return {Promise<Vinyl>} Promise the Vinyl file
178
183
  */
@@ -254,7 +259,7 @@ class Conflicter {
254
259
  /**
255
260
  * Actual prompting logic
256
261
  * @private
257
- * @param {Object} file vinyl file object
262
+ * @param {import('vinyl')} file vinyl file object
258
263
  * @param {Number} counter prompts
259
264
  */
260
265
  _ask(file, counter, conflicterStatus) {
@@ -97,7 +97,11 @@ module.exports = class YeomanNamespace {
97
97
  }
98
98
 
99
99
  set namespace(namespace) {
100
- this._update(YeomanNamespace.parse(namespace));
100
+ const parsed = YeomanNamespace.parse(namespace);
101
+ if (!parsed) {
102
+ throw new Error(`Error parsing namespace ${namespace}`);
103
+ }
104
+ this._update(parsed);
101
105
  }
102
106
 
103
107
  get unscopedNamespace() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-environment",
3
- "version": "3.8.1",
3
+ "version": "3.10.0",
4
4
  "description": "Handles the lifecyle and bootstrapping of generators in a specific environment",
5
5
  "homepage": "http://yeoman.io",
6
6
  "author": "Yeoman",
@@ -79,6 +79,7 @@
79
79
  "grouped-queue": "^2.0.0",
80
80
  "inquirer": "^8.0.0",
81
81
  "is-scoped": "^2.1.0",
82
+ "isbinaryfile": "^4.0.10",
82
83
  "lodash": "^4.17.10",
83
84
  "log-symbols": "^4.0.0",
84
85
  "mem-fs": "^1.2.0 || ^2.0.0",
@@ -110,10 +111,10 @@
110
111
  "nyc": "^15.0.0",
111
112
  "prettier": "^2.2.1",
112
113
  "proxyquire": "^2.1.3",
113
- "sinon": "^12.0.1",
114
- "sinon-test": "^3.0.0",
114
+ "sinon": "^11.1.2",
115
+ "sinon-test": "^3.1.1",
115
116
  "tui-jsdoc-template": "^1.2.2",
116
- "xo": "^0.37.1",
117
+ "xo": "0.37.1",
117
118
  "yeoman-assert": "^3.1.1",
118
119
  "yeoman-generator": "^5.1.0",
119
120
  "yeoman-test": "^6.2.0"
@@ -126,6 +127,7 @@
126
127
  ],
127
128
  "rules": {
128
129
  "import/no-dynamic-require": "off",
130
+ "import/extensions": "off",
129
131
  "prefer-spread": "off",
130
132
  "padding-line-between-statements": "off",
131
133
  "unicorn/no-hex-escape": "off",