Skip to content

Commit c961095

Browse files
authored
bump xo to v0.60.0 (#876)
* bump xo to v0.60.0 * recreate package-lock.json
1 parent c8782d5 commit c961095

29 files changed

+2883
-6306
lines changed

lib/cli.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
#!/usr/bin/env node
2-
'use strict';
32
import fs from 'node:fs';
43
import path from 'node:path';
4+
import process from 'node:process';
55
import chalk from 'chalk';
66
import updateNotifier from 'update-notifier';
77
import yosay from 'yosay';
88
import stringLength from 'string-length';
99
import rootCheck from 'root-check';
1010
import meow from 'meow';
1111
import list from 'cli-list';
12+
import {bootstrap} from 'global-agent';
1213
import tabtab from './completion/tabtab.cjs';
1314
import pkg from './utils/project-package.js';
1415
import Router from './router.js';
15-
import {bootstrap} from 'global-agent';
1616
import * as routes from './routes/index.js';
1717
import {getDirname} from './utils/node-shims.js';
1818

1919
const __dirname = getDirname(import.meta.url);
20-
const gens = list(process.argv.slice(2));
20+
const generators = list(process.argv.slice(2));
2121

2222
bootstrap();
2323

24-
const cli = gens.map(gen => {
25-
const minicli = meow({autoHelp: false, autoVersion: true, pkg, argv: gen, importMeta: import.meta});
24+
const cli = generators.map(generator => {
25+
const minicli = meow({
26+
autoHelp: false, autoVersion: true, pkg, argv: generator, importMeta: import.meta,
27+
});
2628
const options = minicli.flags;
27-
const args = minicli.input;
29+
const arguments_ = minicli.input;
2830

2931
// Add un-camelized options too, for legacy
3032
// TODO: Remove some time in the future when generators have upgraded
3133
for (const key of Object.keys(options)) {
32-
const legacyKey = key.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
34+
const legacyKey = key.replaceAll(/[A-Z]/g, m => `-${m.toLowerCase()}`);
3335
options[legacyKey] = options[key];
3436
}
3537

36-
return {opts: options, args};
38+
return {opts: options, args: arguments_};
3739
});
3840

3941
const firstCmd = cli[0] || {opts: {}, args: {}};
@@ -46,7 +48,7 @@ function updateCheck() {
4648
if (notifier.update) {
4749
message.push(
4850
'Update available: ' + chalk.green.bold(notifier.update.latest) + chalk.gray(' (current: ' + notifier.update.current + ')'),
49-
'Run ' + chalk.magenta('npm install -g ' + pkg.name) + ' to update.'
51+
'Run ' + chalk.magenta('npm install -g ' + pkg.name) + ' to update.',
5052
);
5153
console.log(yosay(message.join(' '), {maxLength: stringLength(message[0])}));
5254
}
@@ -55,8 +57,7 @@ function updateCheck() {
5557
async function pre() {
5658
// Debugging helper
5759
if (cmd === 'doctor') {
58-
// eslint-disable-next-line node/no-unsupported-features/es-syntax
59-
const yeomanDoctor = (await import('yeoman-doctor')).default;
60+
const {default: yeomanDoctor} = await import('yeoman-doctor');
6061
yeomanDoctor();
6162
return;
6263
}
@@ -67,8 +68,7 @@ async function pre() {
6768

6869
// Easteregg
6970
if (cmd === 'yeoman' || cmd === 'yo') {
70-
// eslint-disable-next-line node/no-unsupported-features/es-syntax
71-
const yeomanCharacter = (await import('yeoman-character')).default;
71+
const {default: yeomanCharacter} = await import('yeoman-character');
7272
console.log(yeomanCharacter);
7373
return;
7474
}
@@ -82,9 +82,7 @@ function createGeneratorList(env) {
8282
const generatorName = parts.shift();
8383

8484
// If first time we found this generator, prepare to save all its sub-generators
85-
if (!namesByGenerator[generatorName]) {
86-
namesByGenerator[generatorName] = [];
87-
}
85+
namesByGenerator[generatorName] ||= [];
8886

8987
// If sub-generator (!== app), save it
9088
if (parts[0] !== 'app') {
@@ -111,7 +109,6 @@ const onError = error => {
111109
};
112110

113111
async function init() {
114-
// eslint-disable-next-line node/no-unsupported-features/es-syntax
115112
const {createEnv} = await import('yeoman-environment');
116113
const env = createEnv();
117114

@@ -156,9 +153,9 @@ async function init() {
156153
// Note: at some point, nopt needs to know about the generator options, the
157154
// one that will be triggered by the below args. Maybe the nopt parsing
158155
// should be done internally, from the args.
159-
for (const gen of cli) {
156+
for (const generator of cli) {
160157
// eslint-disable-next-line no-await-in-loop
161-
await env.run(gen.args, gen.opts).catch(error => onError(error));
158+
await env.run(generator.args, generator.opts).catch(error => onError(error));
162159
}
163160
}
164161

@@ -182,6 +179,7 @@ rootCheck('\n' + chalk.red('Easy with the `sudo`. Yeoman is the master around he
182179

183180
updateCheck();
184181

182+
// eslint-disable-next-line unicorn/prefer-top-level-await
185183
(async function () {
186184
await pre();
187185
})();

lib/completion/completer.cjs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use strict';
2-
const path = require('path');
3-
const {execFile} = require('child_process');
1+
const path = require('node:path');
2+
const {execFile} = require('node:child_process');
43
const parseHelp = require('parse-help');
54

65
/**
@@ -39,9 +38,9 @@ class Completer {
3938
*/
4039
generator(data, done) {
4140
const {last} = data;
42-
const bin = path.resolve(__dirname, '../cli.js');
41+
const binary = path.resolve(__dirname, '../cli.js');
4342

44-
execFile('node', [bin, last, '--help'], (error, out) => {
43+
execFile('node', [binary, last, '--help'], (error, out) => {
4544
if (error) {
4645
done(error);
4746
return;
@@ -62,13 +61,13 @@ class Completer {
6261
return item => {
6362
const name = typeof item === 'string' ? item : item.name;
6463
desc = typeof item !== 'string' && item.description ? item.description : desc;
65-
desc = desc.replace(/^#?\s*/g, '');
66-
desc = desc.replace(/:/g, '->');
67-
desc = desc.replace(/'/g, ' ');
64+
desc = desc.replaceAll(/^#?\s*/g, '');
65+
desc = desc.replaceAll(':', '->');
66+
desc = desc.replaceAll('\'', ' ');
6867

6968
return {
7069
name: prefix + name,
71-
description: desc
70+
description: desc,
7271
};
7372
};
7473
}

lib/completion/index.cjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#! /usr/bin/env node
2-
'use strict';
32
const tabtab = require('tabtab')({
43
name: 'yo',
5-
cache: !process.env.YO_TEST
4+
cache: !require('node:process').env.YO_TEST,
65
});
76
const Completer = require('./completer.cjs');
87

98
(async () => {
10-
// eslint-disable-next-line node/no-unsupported-features/es-syntax
119
const {createEnv} = await import('yeoman-environment');
1210
const completer = new Completer(createEnv());
1311

lib/completion/tabtab.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Tabtab = require('tabtab');
44
const tabtab = new Tabtab.Commands.default({
55
name: 'yo',
66
completer: 'yo-complete',
7-
cache: false
7+
cache: false,
88
});
99

1010
module.exports = tabtab;

lib/router.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
'use strict';
2-
import path from 'path';
1+
import path from 'node:path';
32
import titleize from 'titleize';
43
import humanizeString from 'humanize-string';
54
import {readPackageUpSync} from 'read-pkg-up';
@@ -15,11 +14,11 @@ import pkg from './utils/project-package.js';
1514
* @param {Configstore} [conf] An optional config store instance
1615
*/
1716
export default class Router {
18-
constructor(env, conf) {
17+
constructor(env, config) {
1918
this.routes = {};
2019
this.env = env;
21-
this.conf = conf || new Configstore(pkg.name, {
22-
generatorRunCount: {}
20+
this.conf = config || new Configstore(pkg.name, {
21+
generatorRunCount: {},
2322
});
2423
}
2524

@@ -29,9 +28,9 @@ export default class Router {
2928
* @param {*} arg A single argument to pass to the route handler
3029
* @return {Promise} Promise this.
3130
*/
32-
navigate(name, arg) {
31+
navigate(name, argument) {
3332
if (typeof this.routes[name] === 'function') {
34-
return this.routes[name].call(null, this, arg).then(() => this);
33+
return this.routes[name].call(null, this, argument).then(() => this);
3534
}
3635

3736
throw new Error(`No routes called: ${name}`);
@@ -60,22 +59,22 @@ export default class Router {
6059
return;
6160
}
6261

63-
const {packageJson: pkg} = readPackageUpSync({cwd: path.dirname(generator.resolved)});
62+
const {packageJson: package_} = readPackageUpSync({cwd: path.dirname(generator.resolved)});
6463

65-
if (!pkg) {
64+
if (!package_) {
6665
return;
6766
}
6867

69-
pkg.namespace = generator.namespace;
70-
pkg.appGenerator = true;
71-
pkg.prettyName = titleize(humanizeString(namespaceToName(generator.namespace)));
72-
pkg.update = updateNotifier({pkg}).update;
68+
package_.namespace = generator.namespace;
69+
package_.appGenerator = true;
70+
package_.prettyName = titleize(humanizeString(namespaceToName(generator.namespace)));
71+
package_.update = updateNotifier({pkg: package_}).update;
7372

74-
if (pkg.update && pkg.version !== pkg.update.latest) {
75-
pkg.updateAvailable = true;
73+
if (package_.update && package_.version !== package_.update.latest) {
74+
package_.updateAvailable = true;
7675
}
7776

78-
this.generators[pkg.name] = pkg;
77+
this.generators[package_.name] = package_;
7978
};
8079

8180
for (const generator of Object.values(this.env.getGeneratorsMeta())) {

lib/routes/clear-config.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use strict';
21
import _ from 'lodash';
32
import chalk from 'chalk';
43
import inquirer from 'inquirer';
@@ -9,8 +8,8 @@ export const clearConfig = async app => {
98
const defaultChoices = [
109
{
1110
name: 'Take me back home, Yo!',
12-
value: 'home'
13-
}
11+
value: 'home',
12+
},
1413
];
1514

1615
const generatorList = _.chain(globalConfig.getAll()).map((value, key) => {
@@ -32,26 +31,26 @@ export const clearConfig = async app => {
3231
return {
3332
name: prettyName,
3433
sort,
35-
value: key
34+
value: key,
3635
};
3736
}).compact().sortBy(generatorName => generatorName.sort).value();
3837

3938
if (generatorList.length > 0) {
4039
generatorList.push(new inquirer.Separator());
4140
defaultChoices.unshift({
4241
name: 'Clear all',
43-
value: '*'
42+
value: '*',
4443
});
4544
}
4645

4746
return inquirer.prompt([{
4847
name: 'whatNext',
4948
type: 'list',
5049
message: 'Which store would you like to clear?',
51-
choices: _.flatten([
50+
choices: [
5251
generatorList,
53-
defaultChoices
54-
])
52+
defaultChoices,
53+
].flat(),
5554
}]).then(answer => {
5655
if (answer.whatNext === 'home') {
5756
return app.navigate('home');

lib/routes/exit.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use strict';
21
import yosay from 'yosay';
32

43
export const exit = async () => {
@@ -8,11 +7,11 @@ export const exit = async () => {
87
const newLine = ' '.repeat(maxLength);
98

109
console.log(yosay(
11-
'Bye from us!' +
12-
newLine +
13-
'Chat soon.' +
14-
newLine +
15-
'Yeoman team ' + url,
16-
{maxLength}
10+
'Bye from us!'
11+
+ newLine
12+
+ 'Chat soon.'
13+
+ newLine
14+
+ 'Yeoman team ' + url,
15+
{maxLength},
1716
));
1817
};

lib/routes/help.js

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
'use strict';
21
import inquirer from 'inquirer';
32
import open from 'open';
43

5-
export const help = async app => {
6-
return inquirer.prompt([{
7-
name: 'whereTo',
8-
type: 'list',
9-
message: 'Here are a few helpful resources.\n\nI will open the link you select in your browser for you',
10-
choices: [{
11-
name: 'Take me to the documentation',
12-
value: 'http://yeoman.io/learning/'
13-
}, {
14-
name: 'View Frequently Asked Questions',
15-
value: 'http://yeoman.io/learning/faq.html'
16-
}, {
17-
name: 'File an issue on GitHub',
18-
value: 'http://yeoman.io/contributing/opening-issues.html'
19-
}, {
20-
name: 'Take me back home, Yo!',
21-
value: 'home'
22-
}]
23-
}]).then(async answer => {
24-
if (answer.whereTo === 'home') {
25-
console.log('I get it, you like learning on your own. I respect that.');
26-
return app.navigate('home');
27-
}
4+
export const help = async app => inquirer.prompt([{
5+
name: 'whereTo',
6+
type: 'list',
7+
message: 'Here are a few helpful resources.\n\nI will open the link you select in your browser for you',
8+
choices: [{
9+
name: 'Take me to the documentation',
10+
value: 'http://yeoman.io/learning/',
11+
}, {
12+
name: 'View Frequently Asked Questions',
13+
value: 'http://yeoman.io/learning/faq.html',
14+
}, {
15+
name: 'File an issue on GitHub',
16+
value: 'http://yeoman.io/contributing/opening-issues.html',
17+
}, {
18+
name: 'Take me back home, Yo!',
19+
value: 'home',
20+
}],
21+
}]).then(async answer => {
22+
if (answer.whereTo === 'home') {
23+
console.log('I get it, you like learning on your own. I respect that.');
24+
return app.navigate('home');
25+
}
2826

29-
open(answer.whereTo);
30-
});
31-
};
27+
open(answer.whereTo);
28+
});

0 commit comments

Comments
 (0)