From 94d6f1a40e160496ace3b7ba5d2811bbd15a102d Mon Sep 17 00:00:00 2001 From: Rens Groothuijsen Date: Sun, 30 Apr 2017 19:14:43 +0200 Subject: [PATCH 1/3] Fix for issue yeoman/yo#518 --- lib/environment.js | 12 +++++++++++- test/environment.js | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/environment.js b/lib/environment.js index 056e2098..e5849452 100644 --- a/lib/environment.js +++ b/lib/environment.js @@ -338,13 +338,23 @@ class Environment extends EventEmitter { const Generator = this.get(namespace); if (typeof Generator !== 'function') { + const scopedNameRegex = new RegExp('@[^@/]*/[^@/]*'); // Check if namespace matches "@foo/bar" pattern + let generatorHint = ''; + if (namespace.match(scopedNameRegex)) { + const prefix = namespace.match(new RegExp('@[^/]*')); + const generatorName = namespace.match(new RegExp('[^/]*$')); + generatorHint = prefix + '/generator-' + generatorName; + } else { + generatorHint = 'generator-' + namespace; + } + return this.error( new Error( chalk.red('You don\'t seem to have a generator with the name “' + namespace + '” installed.') + '\n' + 'But help is on the way:\n\n' + 'You can see available generators via ' + chalk.yellow('npm search yeoman-generator') + ' or via ' + chalk.yellow('http://yeoman.io/generators/') + '. \n' + - 'Install them with ' + chalk.yellow('npm install generator-' + namespace) + '.\n\n' + + 'Install them with ' + chalk.yellow('npm install ' + generatorHint) + '.\n\n' + 'To see all your installed generators run ' + chalk.yellow('yo') + ' without any arguments. ' + 'Adding the ' + chalk.yellow('--help') + ' option will also show subgenerators. \n\n' + 'If ' + chalk.yellow('yo') + ' cannot find the generator, run ' + chalk.yellow('yo doctor') + ' to troubleshoot your system.' diff --git a/test/environment.js b/test/environment.js index 2fd71b30..12bc88a3 100644 --- a/test/environment.js +++ b/test/environment.js @@ -246,6 +246,13 @@ describe('Environment', () => { it('returns the generator', function () { assert.ok(this.env.run('stub:run') instanceof Generator); }); + + it('correctly append scope in generator hint', function () { + this.env.on('error', err => { + assert.ok(err.message.indexOf('@dummyscope/generator-package') >= 0); + }); + this.env.run('@dummyscope/package'); + }); }); describe('#registerModulePath()', () => { From 69cdb3d42e1c5e2c3d35c117b9b92a9b86693611 Mon Sep 17 00:00:00 2001 From: Rens Groothuijsen Date: Sun, 30 Apr 2017 21:07:35 +0200 Subject: [PATCH 2/3] Removed unnecessary '@' filtering in regex --- lib/environment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/environment.js b/lib/environment.js index e5849452..fb57ac7e 100644 --- a/lib/environment.js +++ b/lib/environment.js @@ -338,7 +338,7 @@ class Environment extends EventEmitter { const Generator = this.get(namespace); if (typeof Generator !== 'function') { - const scopedNameRegex = new RegExp('@[^@/]*/[^@/]*'); // Check if namespace matches "@foo/bar" pattern + const scopedNameRegex = new RegExp('@[^/]*/[^/]*'); // Check if namespace matches "@foo/bar" pattern let generatorHint = ''; if (namespace.match(scopedNameRegex)) { const prefix = namespace.match(new RegExp('@[^/]*')); From 24a11c00933e79aed2ce7d0ccb1eb0190fbf8bc3 Mon Sep 17 00:00:00 2001 From: Rens Groothuijsen Date: Mon, 1 May 2017 21:43:14 +0200 Subject: [PATCH 3/3] Processed review comments. --- lib/environment.js | 13 ++++++------- package.json | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/environment.js b/lib/environment.js index fb57ac7e..800e940f 100644 --- a/lib/environment.js +++ b/lib/environment.js @@ -9,6 +9,7 @@ const escapeStrRe = require('escape-string-regexp'); const untildify = require('untildify'); const memFs = require('mem-fs'); const debug = require('debug')('yeoman:environment'); +const isScoped = require('is-scoped'); const Store = require('./store'); const resolver = require('./resolver'); const TerminalAdapter = require('./adapter'); @@ -338,14 +339,12 @@ class Environment extends EventEmitter { const Generator = this.get(namespace); if (typeof Generator !== 'function') { - const scopedNameRegex = new RegExp('@[^/]*/[^/]*'); // Check if namespace matches "@foo/bar" pattern let generatorHint = ''; - if (namespace.match(scopedNameRegex)) { - const prefix = namespace.match(new RegExp('@[^/]*')); - const generatorName = namespace.match(new RegExp('[^/]*$')); - generatorHint = prefix + '/generator-' + generatorName; + if (isScoped(namespace)) { + const splitName = namespace.split('/'); + generatorHint = `${splitName[0]}/generator-${splitName[1]}`; } else { - generatorHint = 'generator-' + namespace; + generatorHint = `generator-${namespace}`; } return this.error( @@ -354,7 +353,7 @@ class Environment extends EventEmitter { 'But help is on the way:\n\n' + 'You can see available generators via ' + chalk.yellow('npm search yeoman-generator') + ' or via ' + chalk.yellow('http://yeoman.io/generators/') + '. \n' + - 'Install them with ' + chalk.yellow('npm install ' + generatorHint) + '.\n\n' + + 'Install them with ' + chalk.yellow(`npm install ${generatorHint}`) + '.\n\n' + 'To see all your installed generators run ' + chalk.yellow('yo') + ' without any arguments. ' + 'Adding the ' + chalk.yellow('--help') + ' option will also show subgenerators. \n\n' + 'If ' + chalk.yellow('yo') + ' cannot find the generator, run ' + chalk.yellow('yo doctor') + ' to troubleshoot your system.' diff --git a/package.json b/package.json index 2ce48674..59d36bae 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "globby": "^6.1.0", "grouped-queue": "^0.3.0", "inquirer": "^3.0.1", + "is-scoped": "^1.0.0", "lodash": "^4.11.1", "log-symbols": "^1.0.1", "mem-fs": "^1.1.0",