Skip to content

Commit 4e3d9ff

Browse files
committed
Save exact versions when installing ava@next
Pre-releases may have breaking changes. Users should pin exact versions.
1 parent 4b25980 commit 4e3d9ff

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,19 @@ module.exports = opts => {
5353
const avaTag = next ? 'ava@next' : 'ava';
5454

5555
if (hasYarn(pkgCwd)) {
56-
return execa('yarn', ['add', '--dev', avaTag], {cwd: pkgCwd}).then(post);
56+
const yarnArgs = ['add', avaTag, '--dev'];
57+
if (next) {
58+
yarnArgs.push('--exact');
59+
}
60+
return execa('yarn', yarnArgs, {cwd: pkgCwd}).then(post);
5761
}
5862

59-
return execa('npm', ['install', '--save-dev', avaTag], {
63+
const npmArgs = ['install', '--save-dev'];
64+
if (next) {
65+
npmArgs.push('--save-exact');
66+
}
67+
npmArgs.push(avaTag);
68+
return execa('npm', npmArgs, {
6069
cwd: pkgCwd,
6170
stdio: 'inherit'
6271
}).then(post);

test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,19 @@ test('installs the AVA dependency', async t => {
9191

9292
await m({cwd: path.dirname(filepath)});
9393

94-
t.truthy(get(JSON.parse(fs.readFileSync(filepath, 'utf8')), 'devDependencies.ava'));
94+
const installed = get(JSON.parse(fs.readFileSync(filepath, 'utf8')), 'devDependencies.ava');
95+
t.truthy(installed);
96+
t.regex(installed, /^\^/);
9597
});
9698

9799
test('installs AVA@next', async t => {
98100
const filepath = tempWrite.sync(JSON.stringify({}), 'package.json');
99101

100102
await m({cwd: path.dirname(filepath), next: true});
101103

102-
t.truthy(get(JSON.parse(fs.readFileSync(filepath, 'utf8')), 'devDependencies.ava'));
104+
const installed = get(JSON.parse(fs.readFileSync(filepath, 'utf8')), 'devDependencies.ava');
105+
t.truthy(installed);
106+
t.regex(installed, /^\d/);
103107
});
104108

105109
test('installs via yarn if there\'s a lockfile', async t => {
@@ -110,6 +114,20 @@ test('installs via yarn if there\'s a lockfile', async t => {
110114
t.regex(fs.readFileSync(yarnLock, 'utf8'), /ava/);
111115
});
112116

117+
test('installs AVA@next via yarn if there\'s a lockfile', async t => {
118+
const filepath = tempWrite.sync(JSON.stringify({}), 'package.json');
119+
const yarnLock = path.join(path.dirname(filepath), 'yarn.lock');
120+
fs.writeFileSync(yarnLock, '');
121+
122+
await m({cwd: path.dirname(yarnLock), next: true});
123+
124+
t.regex(fs.readFileSync(yarnLock, 'utf8'), /ava/);
125+
126+
const installed = get(JSON.parse(fs.readFileSync(filepath, 'utf8')), 'devDependencies.ava');
127+
t.truthy(installed);
128+
t.regex(installed, /^\d/);
129+
});
130+
113131
test('invokes via cli', async t => {
114132
const cliFilepath = path.resolve(__dirname, './cli.js');
115133
const filepath = tempWrite.sync(JSON.stringify({}), 'package.json');

0 commit comments

Comments
 (0)