Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [12.x, 14.x, 16.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2.1.4
with:
node-version: ${{ matrix.node-version }}
- run: npm install -g npm@latest
- run: npm ci
- run: npm test
21 changes: 13 additions & 8 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function updateCheck() {
}
}

function pre() {
async function pre() {
// Debugging helper
if (cmd === 'doctor') {
require('yeoman-doctor')();
Expand All @@ -80,7 +80,7 @@ function pre() {
return;
}

init();
await init();
}

function createGeneratorList(env) {
Expand Down Expand Up @@ -117,11 +117,13 @@ const onError = error => {
process.exit(error.code || 1);
};

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

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

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

env.run(generatorName, firstCmd.opts).catch(error => onError(error));
await env.run(generatorName, firstCmd.opts).catch(error => onError(error));

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

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

updateCheck();

pre();
(async function () {
await pre();
})();
15 changes: 5 additions & 10 deletions lib/completion/completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@ class Completer {
return this.generator(data, done);
}

try {
this.env.lookup();
} catch (error) {
done(error);
return;
}

const meta = this.env.getGeneratorsMeta();
const results = Object.keys(meta).map(this.item('yo'), this);
done(null, results);
this.env.lookup().then(() => {
const meta = this.env.getGeneratorsMeta();
const results = Object.keys(meta).map(this.item('yo'), this);
done(null, results);
}, done);
}

/**
Expand Down
19 changes: 11 additions & 8 deletions lib/completion/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#! /usr/bin/env node
'use strict';
const env = require('yeoman-environment').createEnv();
const tabtab = require('tabtab')({
name: 'yo',
cache: !process.env.YO_TEST
});
const Completer = require('./completer');

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

tabtab.completer = completer;
tabtab.completer = completer;

// Lookup installed generator in yeoman environment,
// respond completion results with each generator
tabtab.on('yo', completer.complete.bind(completer));
// Lookup installed generator in yeoman environment,
// respond completion results with each generator
tabtab.on('yo', completer.complete.bind(completer));

// Register complete command
tabtab.start();
// Register complete command
tabtab.start();
})();

module.exports = tabtab;
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const humanizeString = require('humanize-string');
const readPkgUp = require('read-pkg-up');
const updateNotifier = require('update-notifier');
const Configstore = require('configstore');
const {namespaceToName} = require('yeoman-environment');
const {namespaceToName} = require('./utils/namespace');

/**
* The router is in charge of handling `yo` different screens.
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/clear-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
const _ = require('lodash');
const chalk = require('chalk');
const inquirer = require('inquirer');
const {namespaceToName} = require('yeoman-environment');
const globalConfig = require('../utils/global-config');
const {namespaceToName} = require('../utils/namespace');

module.exports = async app => {
const defaultChoices = [
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chalk = require('chalk');
const fullname = require('fullname');
const inquirer = require('inquirer');
const {isString} = require('lodash');
const {namespaceToName} = require('yeoman-environment');
const {namespaceToName} = require('../utils/namespace');
const globalConfigHasContent = require('../utils/global-config').hasContent;

module.exports = async app => {
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ function installGenerator(app, pkgName) {
.on('error', error => {
throw error;
})
.on('close', () => {
.on('close', async () => {
console.log(
'\nI just installed a generator by running:\n' +
chalk.blue.bold('\n npm install -g ' + pkgName + '\n')
);

app.env.lookup();
await app.env.lookup();
app.updateAvailableGenerators();
app.navigate('home');
});
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const chalk = require('chalk');
const {namespaceToName} = require('yeoman-environment');
const {namespaceToName} = require('../utils/namespace');

module.exports = async (app, name) => {
const baseName = namespaceToName(name);
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const spawn = require('cross-spawn');
const successMessage = 'I\'ve just updated your generators. Remember, you can update\na specific generator with npm by running:\n' +
chalk.magenta('\n npm install -g generator-_______');

function updateSuccess(app) {
async function updateSuccess(app) {
console.log(`\n${chalk.cyan(successMessage)}\n`);
app.env.lookup();
app.updateAvailableGenerators();
await app.updateAvailableGenerators();
app.navigate('home');
}

Expand Down
7 changes: 7 additions & 0 deletions lib/utils/namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function namespaceToName(namespace) {
return namespace.split(':')[0];
}

module.exports = {
namespaceToName
};
Loading