Skip to content

Commit 8749847

Browse files
authored
update yeoman-environment to v4.0.0 (#793)
* update yeoman-environment to v4.0.0 * update supported node versions * remove npm update from workflow
1 parent f03ca42 commit 8749847

21 files changed

+6966
-2588
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
os: [ubuntu-latest, windows-latest, macos-latest]
23-
node-version: [12.x, 14.x, 16.x]
23+
node-version: [18.x, 20.x]
2424

2525
steps:
2626
- uses: actions/checkout@v2
2727
- uses: actions/[email protected]
2828
with:
2929
node-version: ${{ matrix.node-version }}
30-
- run: npm install -g npm@latest
3130
- run: npm ci
3231
- run: npm test

lib/cli.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function updateCheck() {
6363
}
6464
}
6565

66-
function pre() {
66+
async function pre() {
6767
// Debugging helper
6868
if (cmd === 'doctor') {
6969
require('yeoman-doctor')();
@@ -80,7 +80,7 @@ function pre() {
8080
return;
8181
}
8282

83-
init();
83+
await init();
8484
}
8585

8686
function createGeneratorList(env) {
@@ -117,11 +117,13 @@ const onError = error => {
117117
process.exit(error.code || 1);
118118
};
119119

120-
function init() {
121-
const env = require('yeoman-environment').createEnv();
120+
async function init() {
121+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
122+
const {createEnv} = await import('yeoman-environment');
123+
const env = createEnv();
122124

123125
// Lookup for every namespaces, within the environments.paths and lookups
124-
env.lookup(firstCmd.opts.localOnly || false);
126+
await env.lookup(firstCmd.opts.localOnly || false);
125127
const generatorList = createGeneratorList(env);
126128

127129
// List generators
@@ -153,7 +155,7 @@ function init() {
153155
console.log(chalk.red('Installed generators don\'t need the "generator-" prefix.'));
154156
console.log(`In the future, run ${generatorCommand} instead!\n`);
155157

156-
env.run(generatorName, firstCmd.opts).catch(error => onError(error));
158+
await env.run(generatorName, firstCmd.opts).catch(error => onError(error));
157159

158160
return;
159161
}
@@ -162,7 +164,8 @@ function init() {
162164
// one that will be triggered by the below args. Maybe the nopt parsing
163165
// should be done internally, from the args.
164166
for (const gen of cli) {
165-
env.run(gen.args, gen.opts).catch(error => onError(error));
167+
// eslint-disable-next-line no-await-in-loop
168+
await env.run(gen.args, gen.opts).catch(error => onError(error));
166169
}
167170
}
168171

@@ -186,4 +189,6 @@ rootCheck('\n' + chalk.red('Easy with the `sudo`. Yeoman is the master around he
186189

187190
updateCheck();
188191

189-
pre();
192+
(async function () {
193+
await pre();
194+
})();

lib/completion/completer.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,11 @@ class Completer {
2424
return this.generator(data, done);
2525
}
2626

27-
try {
28-
this.env.lookup();
29-
} catch (error) {
30-
done(error);
31-
return;
32-
}
33-
34-
const meta = this.env.getGeneratorsMeta();
35-
const results = Object.keys(meta).map(this.item('yo'), this);
36-
done(null, results);
27+
this.env.lookup().then(() => {
28+
const meta = this.env.getGeneratorsMeta();
29+
const results = Object.keys(meta).map(this.item('yo'), this);
30+
done(null, results);
31+
}, done);
3732
}
3833

3934
/**

lib/completion/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
#! /usr/bin/env node
22
'use strict';
3-
const env = require('yeoman-environment').createEnv();
43
const tabtab = require('tabtab')({
54
name: 'yo',
65
cache: !process.env.YO_TEST
76
});
87
const Completer = require('./completer');
98

10-
const completer = new Completer(env);
9+
(async () => {
10+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
11+
const {createEnv} = await import('yeoman-environment');
12+
const completer = new Completer(createEnv());
1113

12-
tabtab.completer = completer;
14+
tabtab.completer = completer;
1315

14-
// Lookup installed generator in yeoman environment,
15-
// respond completion results with each generator
16-
tabtab.on('yo', completer.complete.bind(completer));
16+
// Lookup installed generator in yeoman environment,
17+
// respond completion results with each generator
18+
tabtab.on('yo', completer.complete.bind(completer));
1719

18-
// Register complete command
19-
tabtab.start();
20+
// Register complete command
21+
tabtab.start();
22+
})();
2023

2124
module.exports = tabtab;

lib/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const humanizeString = require('humanize-string');
55
const readPkgUp = require('read-pkg-up');
66
const updateNotifier = require('update-notifier');
77
const Configstore = require('configstore');
8-
const {namespaceToName} = require('yeoman-environment');
8+
const {namespaceToName} = require('./utils/namespace');
99

1010
/**
1111
* The router is in charge of handling `yo` different screens.

lib/routes/clear-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
const _ = require('lodash');
33
const chalk = require('chalk');
44
const inquirer = require('inquirer');
5-
const {namespaceToName} = require('yeoman-environment');
65
const globalConfig = require('../utils/global-config');
6+
const {namespaceToName} = require('../utils/namespace');
77

88
module.exports = async app => {
99
const defaultChoices = [

lib/routes/home.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const chalk = require('chalk');
44
const fullname = require('fullname');
55
const inquirer = require('inquirer');
66
const {isString} = require('lodash');
7-
const {namespaceToName} = require('yeoman-environment');
7+
const {namespaceToName} = require('../utils/namespace');
88
const globalConfigHasContent = require('../utils/global-config').hasContent;
99

1010
module.exports = async app => {

lib/routes/install.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ function installGenerator(app, pkgName) {
133133
.on('error', error => {
134134
throw error;
135135
})
136-
.on('close', () => {
136+
.on('close', async () => {
137137
console.log(
138138
'\nI just installed a generator by running:\n' +
139139
chalk.blue.bold('\n npm install -g ' + pkgName + '\n')
140140
);
141141

142-
app.env.lookup();
142+
await app.env.lookup();
143143
app.updateAvailableGenerators();
144144
app.navigate('home');
145145
});

lib/routes/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const chalk = require('chalk');
3-
const {namespaceToName} = require('yeoman-environment');
3+
const {namespaceToName} = require('../utils/namespace');
44

55
module.exports = async (app, name) => {
66
const baseName = namespaceToName(name);

lib/routes/update.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const spawn = require('cross-spawn');
66
const successMessage = 'I\'ve just updated your generators. Remember, you can update\na specific generator with npm by running:\n' +
77
chalk.magenta('\n npm install -g generator-_______');
88

9-
function updateSuccess(app) {
9+
async function updateSuccess(app) {
1010
console.log(`\n${chalk.cyan(successMessage)}\n`);
1111
app.env.lookup();
12-
app.updateAvailableGenerators();
12+
await app.updateAvailableGenerators();
1313
app.navigate('home');
1414
}
1515

0 commit comments

Comments
 (0)