Skip to content

Commit 875cac9

Browse files
committed
Require Node.js 8
1 parent d96c6a2 commit 875cac9

File tree

7 files changed

+75
-84
lines changed

7 files changed

+75
-84
lines changed

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: node_js
22
node_js:
3+
- '12'
4+
- '10'
35
- '8'
4-
- '6'
5-
before_install:
6-
- npm i -g npm

cli.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/usr/bin/env node
22
'use strict';
33
const arrExclude = require('arr-exclude');
4-
const init = require('.');
4+
const createAva = require('.');
55

66
const cli = process.argv.slice(2);
7-
const args = arrExclude(cli, ['--next', '--unicorn']);
7+
const args = arrExclude(cli, ['--next']);
8+
const next = cli.includes('--next');
89

9-
const next = cli.indexOf('--next') !== -1;
10-
const unicorn = cli.indexOf('--unicorn') !== -1;
11-
12-
const opts = {args, next, unicorn};
13-
init(opts);
10+
createAva({args, next});

index.js

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
const fs = require('fs');
32
const path = require('path');
43
const execa = require('execa');
54
const hasYarn = require('has-yarn');
@@ -8,23 +7,21 @@ const writePkg = require('write-pkg');
87

98
const DEFAULT_TEST_SCRIPT = 'echo "Error: no test specified" && exit 1';
109

11-
module.exports = opts => {
12-
opts = opts || {};
13-
14-
const ret = readPkgUp.sync({
15-
cwd: opts.cwd,
10+
module.exports = async (options = {}) => {
11+
const packageResult = readPkgUp.sync({
12+
cwd: options.cwd,
1613
normalize: false
17-
});
18-
const pkg = ret.pkg || {};
19-
const pkgPath = ret.path || path.resolve(opts.cwd || process.cwd(), 'package.json');
20-
const pkgCwd = path.dirname(pkgPath);
21-
const next = Boolean(opts.next) || false;
22-
const args = opts.args || [];
14+
}) || {};
15+
const packageJson = packageResult.package || {};
16+
const packagePath = packageResult.path || path.resolve(options.cwd || process.cwd(), 'package.json');
17+
const packageCwd = path.dirname(packagePath);
18+
const next = Boolean(options.next);
19+
const args = options.args || [];
2320
const cmd = 'ava' + (args.length > 0 ? ' ' + args.join(' ') : '');
2421

25-
pkg.scripts = pkg.scripts ? pkg.scripts : {};
22+
packageJson.scripts = packageJson.scripts ? packageJson.scripts : {};
2623

27-
const s = pkg.scripts;
24+
const s = packageJson.scripts;
2825
if (s.test && s.test !== DEFAULT_TEST_SCRIPT) {
2926
s.test = s.test.replace(/\bnode (test\/)?test\.js\b/, cmd);
3027

@@ -35,38 +32,46 @@ module.exports = opts => {
3532
s.test = cmd;
3633
}
3734

38-
writePkg.sync(pkgPath, pkg, {normalize: false});
39-
40-
const post = () => {
41-
// For personal use
42-
if (opts.unicorn) {
43-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
44-
pkg.devDependencies.ava = '*';
45-
writePkg.sync(pkgPath, pkg, {normalize: false});
46-
}
47-
};
35+
writePkg.sync(packagePath, packageJson, {normalize: false});
4836

49-
if (opts.skipInstall) {
50-
return Promise.resolve(post);
37+
if (options.skipInstall) {
38+
return;
5139
}
5240

5341
const avaTag = next ? 'ava@next' : 'ava';
5442

55-
if (hasYarn(pkgCwd)) {
56-
const yarnArgs = ['add', avaTag, '--dev'];
43+
if (hasYarn(packageCwd)) {
44+
const yarnArguments = ['add', avaTag, '--dev', '--ignore-workspace-root-check', 'ava'];
5745
if (next) {
58-
yarnArgs.push('--exact');
46+
yarnArguments.push('--exact');
5947
}
60-
return execa('yarn', yarnArgs, {cwd: pkgCwd}).then(post);
48+
49+
try {
50+
await execa('yarn', yarnArguments, {
51+
cwd: packageCwd,
52+
stdio: 'inherit'
53+
});
54+
} catch (error) {
55+
if (error.code === 'ENOENT') {
56+
console.error('This project uses Yarn but you don\'t seem to have Yarn installed.\nRun `npm install --global yarn` to install it.');
57+
return;
58+
}
59+
60+
throw error;
61+
}
62+
63+
return;
6164
}
6265

63-
const npmArgs = ['install', '--save-dev'];
66+
const npmArguments = ['install', '--save-dev'];
6467
if (next) {
65-
npmArgs.push('--save-exact');
68+
npmArguments.push('--save-exact');
6669
}
67-
npmArgs.push(avaTag);
68-
return execa('npm', npmArgs, {
69-
cwd: pkgCwd,
70+
71+
npmArguments.push(avaTag);
72+
73+
await execa('npm', npmArguments, {
74+
cwd: packageCwd,
7075
stdio: 'inherit'
71-
}).then(post);
76+
});
7277
};

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=6.12.3 <7 || >=8.9.4"
13+
"node": ">=8.9.4 <9 || >=10.0.0 <11 || >=12.0.0"
1414
},
1515
"scripts": {
1616
"test": "xo && ava"
@@ -36,15 +36,15 @@
3636
"dependencies": {
3737
"arr-exclude": "^1.0.0",
3838
"execa": "^0.7.0",
39-
"has-yarn": "^1.0.0",
40-
"read-pkg-up": "^2.0.0",
41-
"write-pkg": "^3.2.0"
39+
"has-yarn": "^2.1.0",
40+
"read-pkg-up": "^6.0.0",
41+
"write-pkg": "^4.0.0"
4242
},
4343
"devDependencies": {
44-
"ava": "*",
45-
"dot-prop": "^4.1.0",
46-
"temp-write": "^3.3.0",
47-
"xo": "*",
44+
"ava": "^2.4.0",
45+
"dot-prop": "^5.1.0",
46+
"temp-write": "^4.0.0",
47+
"xo": "^0.25.3",
4848
"yarn": "^1.5.1"
4949
}
5050
}

readme.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,34 @@
66
## CLI
77

88
```
9-
$ npx create-ava [<options>]
9+
$ npm init ava [options]
1010
```
1111

1212

13-
## Install
13+
## API
1414

1515
```
1616
$ npm install create-ava
1717
```
1818

19-
20-
## Usage
19+
### Usage
2120

2221
```js
2322
const createAva = require('create-ava');
2423

25-
createAva().then(() => {
26-
console.log('done');
27-
});
24+
(async () => {
25+
await createAva();
26+
})();
2827
```
2928

30-
31-
## API
32-
33-
### createAva([options])
29+
### createAva(options?)
3430

3531
Returns a `Promise`.
3632

3733
#### options
3834

35+
Type: `object`
36+
3937
#### cwd
4038

4139
Type: `string`<br>
@@ -45,7 +43,7 @@ Current working directory.
4543

4644
#### args
4745

48-
Type: `Array`<br>
46+
Type: `string[]`<br>
4947
Default: CLI arguments *(`process.argv.slice(2)`)*
5048

5149
For instance, with the arguments `['--foo', '--bar']`, the following will be put in package.json:
@@ -65,8 +63,3 @@ Type: `boolean`<br>
6563
Default: `false`
6664

6765
Install `ava@next` instead of `ava`.
68-
69-
70-
## License
71-
72-
MIT © [Sindre Sorhus](https://sindresorhus.com)

test.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
import path from 'path';
22
import fs from 'fs';
3-
43
import test from 'ava';
54
import dotProp from 'dot-prop';
65
import execa from 'execa';
76
import tempWrite from 'temp-write';
8-
97
import createAva from '.';
108

119
const {get} = dotProp;
1210

13-
async function runWithoutInstall(pkg, additionalOpts) {
14-
const filepath = tempWrite.sync(JSON.stringify(pkg), 'package.json');
11+
const runWithoutInstall = async (packageJson, additionalOptions) => {
12+
const filePath = tempWrite.sync(JSON.stringify(packageJson), 'package.json');
1513

16-
const opts = Object.assign({
17-
cwd: path.dirname(filepath),
18-
skipInstall: true
19-
}, additionalOpts);
14+
await createAva({
15+
cwd: path.dirname(filePath),
16+
skipInstall: true,
17+
...additionalOptions
18+
});
2019

21-
await createAva(opts);
22-
return JSON.parse(fs.readFileSync(filepath, 'utf8'));
23-
}
20+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
21+
};
2422

2523
test('empty package.json', async t => {
2624
t.is(get(await runWithoutInstall({}), 'scripts.test'), 'ava');

0 commit comments

Comments
 (0)