Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit e764cd5

Browse files
samoussfrancoischalifour
authored andcommitted
fix(cli): Use latest version when stable unavailable (#57)
1 parent 3bca8bc commit e764cd5

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ yarn-error.log*
1515

1616
# release
1717
/build
18+
/sample

src/cli/__tests__/getConfiguration.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const path = require('path');
2+
const utils = require('../../utils');
23
const getConfiguration = require('../getConfiguration');
34

5+
jest.mock('../../utils', () => ({
6+
...require.requireActual('../../utils'),
7+
fetchLibraryVersions: jest.fn(() => Promise.resolve(['1.0.0'])),
8+
}));
9+
410
test('without template throws', async () => {
511
expect.assertions(1);
612

@@ -42,6 +48,20 @@ test('with options from arguments and prompt merge', async () => {
4248
);
4349
});
4450

51+
test('without stable version available', async () => {
52+
utils.fetchLibraryVersions.mockImplementationOnce(() =>
53+
Promise.resolve(['1.0.0-beta.0'])
54+
);
55+
56+
const configuration = await getConfiguration({
57+
answers: {
58+
template: 'InstantSearch.js',
59+
},
60+
});
61+
62+
expect(configuration.libraryVersion).toBe('1.0.0-beta.0');
63+
});
64+
4565
test('with config file overrides all options', async () => {
4666
const loadJsonFileFn = jest.fn(x => Promise.resolve(x));
4767
const ignoredOptions = {

src/cli/getConfiguration.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ module.exports = async function getConfiguration({
2828

2929
libraryVersion = await fetchLibraryVersions(
3030
templateConfig.libraryName
31-
).then(latestSemver);
31+
).then(
32+
versions =>
33+
// Return the lastest available version when
34+
// the stable version is not available
35+
latestSemver(versions) || versions[0]
36+
);
3237
}
3338

3439
return {

0 commit comments

Comments
 (0)