create-instantsearch-app 6.4.1 → 6.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-instantsearch-app",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "⚡️ Build InstantSearch apps at the speed of thought",
|
|
6
6
|
"keywords": [
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"jest-image-snapshot": "2.12.0",
|
|
53
53
|
"walk-sync": "2.0.2"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "c0a9fe132d2c64939763f64f7c265ed8ceb89ae2"
|
|
56
56
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
|
|
3
|
+
const { fetchLibraryVersions } = require('../fetchLibraryVersions');
|
|
4
|
+
|
|
5
|
+
describe('fetchLibraryVersions', () => {
|
|
6
|
+
test('return versions for a library', async () => {
|
|
7
|
+
expect(await fetchLibraryVersions('react-instantsearch')).toEqual(
|
|
8
|
+
expect.arrayContaining([expect.any(String)])
|
|
9
|
+
);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('return versions from cache if available', async () => {
|
|
13
|
+
const httpsSpy = jest.spyOn(https, 'get');
|
|
14
|
+
|
|
15
|
+
await fetchLibraryVersions('react-instantsearch-core');
|
|
16
|
+
expect(httpsSpy).toHaveBeenCalledTimes(1);
|
|
17
|
+
|
|
18
|
+
await fetchLibraryVersions('react-instantsearch-core');
|
|
19
|
+
expect(httpsSpy).toHaveBeenCalledTimes(1);
|
|
20
|
+
|
|
21
|
+
await fetchLibraryVersions('instantsearch.js');
|
|
22
|
+
expect(httpsSpy).toHaveBeenCalledTimes(2);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
|
|
3
|
+
function fetchCachedLibraryVersions() {
|
|
4
|
+
const cache = new Map();
|
|
5
|
+
return function fetchLibraryVersions(libraryName) {
|
|
6
|
+
if (cache.has(libraryName)) {
|
|
7
|
+
return Promise.resolve(cache.get(libraryName));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
https
|
|
12
|
+
.get(`https://registry.npmjs.org/${libraryName}`, (res) => {
|
|
13
|
+
let body = '';
|
|
14
|
+
res.on('data', (chunk) => {
|
|
15
|
+
body += chunk;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
res.on('end', () => {
|
|
19
|
+
try {
|
|
20
|
+
const library = JSON.parse(body);
|
|
21
|
+
const versions = Object.keys(library.versions).reverse();
|
|
22
|
+
|
|
23
|
+
cache.set(libraryName, versions);
|
|
24
|
+
resolve(versions);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
reject(err);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
})
|
|
30
|
+
.on('error', reject);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
fetchLibraryVersions: fetchCachedLibraryVersions(),
|
|
37
|
+
};
|
package/src/utils/index.js
CHANGED
|
@@ -2,22 +2,13 @@ const { execSync } = require('child_process');
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
|
|
5
|
-
const algoliasearch = require('algoliasearch');
|
|
6
5
|
const chalk = require('chalk');
|
|
7
6
|
const semver = require('semver');
|
|
8
7
|
const validateProjectName = require('validate-npm-package-name');
|
|
9
8
|
|
|
9
|
+
const { fetchLibraryVersions } = require('./fetchLibraryVersions');
|
|
10
10
|
const TEMPLATES_FOLDER = path.join(__dirname, '../templates');
|
|
11
11
|
|
|
12
|
-
const algoliaConfig = {
|
|
13
|
-
appId: 'OFCNCOG2CU',
|
|
14
|
-
apiKey: 'f54e21fa3a2a0160595bb058179bfb1e',
|
|
15
|
-
indexName: 'npm-search',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const client = algoliasearch(algoliaConfig.appId, algoliaConfig.apiKey);
|
|
19
|
-
const index = client.initIndex(algoliaConfig.indexName);
|
|
20
|
-
|
|
21
12
|
function checkAppName(appName) {
|
|
22
13
|
const validationResult = validateProjectName(appName);
|
|
23
14
|
|
|
@@ -130,14 +121,6 @@ function getTemplatePath(templateName) {
|
|
|
130
121
|
return templateName;
|
|
131
122
|
}
|
|
132
123
|
|
|
133
|
-
async function fetchLibraryVersions(libraryName) {
|
|
134
|
-
const library = await index.getObject(libraryName, {
|
|
135
|
-
attributesToRetrieve: ['versions'],
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
return Object.keys(library.versions).reverse();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
124
|
function getLibraryVersion({ libraryName, supportedVersion = '' }) {
|
|
142
125
|
return async (getVersion) => {
|
|
143
126
|
const versions = await fetchLibraryVersions(libraryName);
|