Skip to content

Commit c5fe17a

Browse files
author
Robert Jackson
committed
Remove co.wrap usage in favor of using async/await directly.
Used codemod to do the conversion: ``` npx jscodeshift --transform https://raw.githubusercontent.com/albinekb/co-to-async/master/codemod.js path/to/files/*.js works ```
1 parent 08f72f3 commit c5fe17a

File tree

7 files changed

+68
-77
lines changed

7 files changed

+68
-77
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
],
88
parserOptions: {
99
sourceType: 'script',
10-
ecmaVersion: 2015
10+
ecmaVersion: 2017
1111
},
1212
env: {
1313
browser: false,

commands/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const VersionChecker = require('ember-cli-version-checker');
55

66
const chalk = require('chalk');
7-
const co = require('co');
87
const fs = require('fs');
98
const mkdirp = require('mkdirp');
109
const path = require('path');
@@ -47,7 +46,7 @@ const SHARED = {
4746
return configPath;
4847
},
4948

50-
_setFeature: co.wrap(function *(name, value) {
49+
_setFeature: async function (name, value) {
5150
let feature = FEATURES[name];
5251

5352
if (feature === undefined) {
@@ -63,7 +62,7 @@ const SHARED = {
6362
}
6463

6564
if (typeof feature.callback === 'function') {
66-
yield feature.callback(this.project, value);
65+
await feature.callback(this.project, value);
6766
}
6867

6968
let config = {};
@@ -81,7 +80,7 @@ const SHARED = {
8180
let state = value ? 'Enabled' : 'Disabled';
8281

8382
console.log(chalk.green(`${state} ${chalk.bold(name)}. Be sure to commit ${chalk.underline('config/optional-features.json')} to source control!`));
84-
})
83+
}
8584
};
8685

8786
const USAGE = Object.assign({

features/application-template-wrapper.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'use strict';
33

44
const chalk = require('chalk');
5-
const co = require('co');
65
const fs = require('fs');
76
const inquirer = require('inquirer');
87
const p = require('util.promisify');
@@ -14,7 +13,7 @@ module.exports = {
1413
url: 'https://github.com/emberjs/rfcs/pull/280',
1514
default: true,
1615
since: '3.1.0',
17-
callback: co.wrap(function *(project, value) {
16+
callback: async function (project, value) {
1817
if (value !== false) {
1918
return;
2019
}
@@ -36,7 +35,7 @@ module.exports = {
3635
let absolutePath = path.join(root, templatePath);
3736

3837
try {
39-
originalContent = yield p(fs.readFile)(absolutePath, { encoding: 'UTF-8' });
38+
originalContent = await p(fs.readFile)(absolutePath, { encoding: 'UTF-8' });
4039
} catch(err) {
4140
if (err.code === 'ENOENT') {
4241
return;
@@ -63,7 +62,7 @@ module.exports = {
6362
To be very conservative, I could add the \`<div class="ember-view">\` wrapper to your application.hbs. (You can always remove it later.)
6463
`);
6564

66-
let response = yield inquirer.prompt({
65+
let response = await inquirer.prompt({
6766
type: 'confirm',
6867
name: 'shouldRewrite',
6968
message: 'Would you like me to do that for you?',
@@ -102,9 +101,9 @@ module.exports = {
102101

103102
console.log(` ${chalk.yellow('overwrite')} ${templatePath}`);
104103

105-
yield p(fs.writeFile)(templatePath, content.join('\n'), { encoding: 'UTF-8' });
104+
await p(fs.writeFile)(templatePath, content.join('\n'), { encoding: 'UTF-8' });
106105

107106
console.log();
108107
}
109-
})
108+
}
110109
};

features/template-only-glimmer-components.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'use strict';
33

44
const chalk = require('chalk');
5-
const co = require('co');
65
const fs = require('fs');
76
const inquirer = require('inquirer');
87
const glob = require('glob');
@@ -26,7 +25,7 @@ module.exports = {
2625
url: 'https://github.com/emberjs/rfcs/pull/278',
2726
default: false,
2827
since: '3.1.0',
29-
callback: co.wrap(function *(project, value) {
28+
callback: async function (project, value) {
3029
if (value !== true) {
3130
return;
3231
}
@@ -54,7 +53,7 @@ module.exports = {
5453

5554
// Handle "Classic" layout
5655
let templatesRoot = path.join(root, 'app/templates/components');
57-
let templateCandidates = yield p(glob)('**/*.hbs', { cwd: templatesRoot });
56+
let templateCandidates = await p(glob)('**/*.hbs', { cwd: templatesRoot });
5857

5958
templateCandidates.forEach(template => {
6059
let templatePath = path.join('app/templates/components', template);
@@ -72,7 +71,7 @@ module.exports = {
7271
// Handle "Pods" layout without prefix
7372

7473
let componentsRoot = path.join(root, 'app/components');
75-
templateCandidates = yield p(glob)('**/template.hbs', { cwd: componentsRoot });
74+
templateCandidates = await p(glob)('**/template.hbs', { cwd: componentsRoot });
7675

7776
templateCandidates.forEach(template => {
7877
let templatePath = path.join('app/components', template);
@@ -90,7 +89,7 @@ module.exports = {
9089
// Handle "Pods" layout *with* prefix
9190

9291
componentsRoot = path.join(root, `app/${podsFolder}/components`);
93-
templateCandidates = yield p(glob)('**/template.hbs', { cwd: componentsRoot });
92+
templateCandidates = await p(glob)('**/template.hbs', { cwd: componentsRoot });
9493

9594
templateCandidates.forEach(template => {
9695
let templatePath = path.join(`app/${podsFolder}/components`, template);
@@ -138,7 +137,7 @@ module.exports = {
138137
`);
139138
}
140139

141-
let response = yield inquirer.prompt({
140+
let response = await inquirer.prompt({
142141
type: 'confirm',
143142
name: 'shouldGenerate',
144143
message: 'Would you like me to generate these component files for you?',
@@ -152,11 +151,11 @@ module.exports = {
152151
let componentPath = components[i];
153152
console.log(` ${chalk.green('create')} ${componentPath}`);
154153
let absolutePath = path.join(project.root, componentPath);
155-
yield p(mkdirp)(path.dirname(absolutePath));
156-
yield p(fs.writeFile)(absolutePath, ComponentFile, { encoding: 'UTF-8' });
154+
await p(mkdirp)(path.dirname(absolutePath));
155+
await p(fs.writeFile)(absolutePath, ComponentFile, { encoding: 'UTF-8' });
157156
}
158157

159158
console.log();
160159
}
161-
})
160+
}
162161
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
},
2626
"dependencies": {
2727
"chalk": "^3.0.0",
28-
"co": "^4.6.0",
2928
"ember-cli-version-checker": "^3.1.3",
3029
"glob": "^7.1.6",
3130
"inquirer": "^7.0.1",

0 commit comments

Comments
 (0)