-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds whether there are types for a package to an index
- Loading branch information
Showing
7 changed files
with
149 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,94 +39,94 @@ For every single NPM package, we create a record in the Algolia index. The resul | |
|
||
```json5 | ||
{ | ||
"name": "babel-core", | ||
"concatenatedName": "babelcore", | ||
"downloadsLast30Days": 10978749, | ||
"downloadsRatio": 0.08310651682685861, | ||
"humanDownloadsLast30Days": "11m", | ||
"jsDelivrHits": 11684192, | ||
"popular": true, | ||
"version": "6.26.0", | ||
"versions": { | ||
name: 'babel-core', | ||
concatenatedName: 'babelcore', | ||
downloadsLast30Days: 10978749, | ||
downloadsRatio: 0.08310651682685861, | ||
humanDownloadsLast30Days: '11m', | ||
jsDelivrHits: 11684192, | ||
popular: true, | ||
version: '6.26.0', | ||
versions: { | ||
// [...] | ||
"7.0.0-beta.3": "2017-10-15T13:12:35.166Z" | ||
'7.0.0-beta.3': '2017-10-15T13:12:35.166Z', | ||
}, | ||
"tags": { | ||
"latest": "6.26.0", | ||
"old": "5.8.38", | ||
"next": "7.0.0-beta.3" | ||
tags: { | ||
latest: '6.26.0', | ||
old: '5.8.38', | ||
next: '7.0.0-beta.3', | ||
}, | ||
"description": "Babel compiler core.", | ||
"dependencies": { | ||
"babel-code-frame": "^6.26.0" | ||
description: 'Babel compiler core.', | ||
dependencies: { | ||
'babel-code-frame': '^6.26.0', | ||
// [...] | ||
}, | ||
"devDependencies": { | ||
"babel-helper-fixtures": "^6.26.0" | ||
devDependencies: { | ||
'babel-helper-fixtures': '^6.26.0', | ||
// [...] | ||
}, | ||
"repository": { | ||
"url": "https://github.com/babel/babel/tree/master/packages/babel-core", | ||
"host": "github.com", | ||
"user": "babel", | ||
"project": "babel", | ||
"path": "/tree/master/packages/babel-core", | ||
"branch": "master" | ||
repository: { | ||
url: 'https://github.com/babel/babel/tree/master/packages/babel-core', | ||
host: 'github.com', | ||
user: 'babel', | ||
project: 'babel', | ||
path: '/tree/master/packages/babel-core', | ||
branch: 'master', | ||
}, | ||
"readme": | ||
"# babel-core\n\n> Babel compiler core.\n\n\n [... truncated at 200kb]", | ||
"owner": { | ||
readme: '# babel-core\n\n> Babel compiler core.\n\n\n [... truncated at 200kb]', | ||
owner: { | ||
// either GitHub owner or npm owner | ||
"name": "babel", | ||
"avatar": "https://github.com/babel.png", | ||
"link": "https://github.com/babel" | ||
name: 'babel', | ||
avatar: 'https://github.com/babel.png', | ||
link: 'https://github.com/babel', | ||
}, | ||
"deprecated": false, | ||
"badPackage": false, | ||
"homepage": "https://babeljs.io/", | ||
"license": "MIT", | ||
"keywords": [ | ||
"6to5", | ||
"babel", | ||
"classes", | ||
"const", | ||
"es6", | ||
"harmony", | ||
"let", | ||
"modules", | ||
"transpile", | ||
"transpiler", | ||
"var", | ||
"babel-core", | ||
"compiler" | ||
deprecated: false, | ||
badPackage: false, | ||
homepage: 'https://babeljs.io/', | ||
license: 'MIT', | ||
keywords: [ | ||
'6to5', | ||
'babel', | ||
'classes', | ||
'const', | ||
'es6', | ||
'harmony', | ||
'let', | ||
'modules', | ||
'transpile', | ||
'transpiler', | ||
'var', | ||
'babel-core', | ||
'compiler', | ||
], | ||
"created": 1424009748555, | ||
"modified": 1508833762239, | ||
"lastPublisher": { | ||
"name": "hzoo", | ||
"email": "[email protected]", | ||
"avatar": "https://gravatar.com/avatar/851fb4fa7ca479bce1ae0cdf80d6e042", | ||
"link": "https://www.npmjs.com/~hzoo" | ||
created: 1424009748555, | ||
modified: 1508833762239, | ||
lastPublisher: { | ||
name: 'hzoo', | ||
email: '[email protected]', | ||
avatar: 'https://gravatar.com/avatar/851fb4fa7ca479bce1ae0cdf80d6e042', | ||
link: 'https://www.npmjs.com/~hzoo', | ||
}, | ||
"owners": [ | ||
owners: [ | ||
{ | ||
"email": "[email protected]", | ||
"name": "thejameskyle", | ||
"avatar": "https://gravatar.com/avatar/8a00efb48d632ae449794c094f7d5c38", | ||
"link": "https://www.npmjs.com/~thejameskyle" | ||
} | ||
email: '[email protected]', | ||
name: 'thejameskyle', | ||
avatar: 'https://gravatar.com/avatar/8a00efb48d632ae449794c094f7d5c38', | ||
link: 'https://www.npmjs.com/~thejameskyle', | ||
}, | ||
// [...] | ||
], | ||
"lastCrawl": "2017-10-24T08:29:24.672Z", | ||
"dependents": 3321, | ||
"humanDependents": "3.3k", | ||
"changelogFilename": null, // if babel-core had a changelog, it would be the raw GitHub url here | ||
"objectID": "babel-core", | ||
"_searchInternal": { | ||
"popularName": "babel-core", | ||
"downloadsMagnitude": 8, | ||
"jsDelivrPopularity": 5 | ||
} | ||
lastCrawl: '2017-10-24T08:29:24.672Z', | ||
dependents: 3321, | ||
ts: undefined, | ||
humanDependents: '3.3k', | ||
changelogFilename: null, // if babel-core had a changelog, it would be the raw GitHub url here | ||
objectID: 'babel-core', | ||
_searchInternal: { | ||
popularName: 'babel-core', | ||
downloadsMagnitude: 8, | ||
jsDelivrPopularity: 5, | ||
}, | ||
} | ||
``` | ||
|
||
|
@@ -182,7 +182,7 @@ apiKey=... yarn start | |
|
||
### Restart | ||
|
||
To restart from a particular point (or from the begining): | ||
To restart from a particular point (or from the beginning): | ||
|
||
```sh | ||
seq=0 apiKey=... yarn start | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// @ts-check | ||
|
||
import { validatePackageExists } from './npm.js'; | ||
import { fileExistsInUnpkg } from './unpkg.js'; | ||
|
||
/** | ||
* Basically either | ||
* - { ts: undefined } for no existing TypeScript support | ||
* - { ts: "@types/module" } - for definitely typed support | ||
* - { ts: "included" } - for types shipped with the module | ||
* */ | ||
export async function getTypeScriptSupportString(pkg) { | ||
// The cheap and simple (+ recommended by TS) way | ||
// of adding a types section to your package.json | ||
if (pkg.types) { | ||
return { ts: 'included' }; | ||
} | ||
|
||
// Older, but still works way of defining your types | ||
if (pkg.typings) { | ||
return { ts: 'included' }; | ||
} | ||
|
||
// The 2nd most likely is definitely typed | ||
const defTypeName = `@types/${pkg.name}`; | ||
const defTyped = await validatePackageExists(defTypeName); | ||
if (defTyped) { | ||
return { ts: defTypeName }; | ||
} | ||
|
||
// Check if main's JS file can be resolved to a d.ts file instead | ||
const main = pkg.main || 'index.js'; | ||
if (main.endsWith('.js')) { | ||
const dtsMain = main.replace(/js$/, 'd.ts'); | ||
const resolved = await fileExistsInUnpkg(pkg.name, pkg.version, dtsMain); | ||
if (resolved) { | ||
return { ts: 'included' }; | ||
} | ||
} | ||
|
||
return { ts: undefined }; | ||
} | ||
|
||
export function getTSSupport(pkgs) { | ||
return Promise.all(pkgs.map(getTypeScriptSupportString)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @ts-check | ||
import c from './config.js'; | ||
import got from 'got'; | ||
|
||
// make a head request to a route like: | ||
// https://unpkg.com/[email protected]/_LazyWrapper.js | ||
// to validate the existence of a particular file | ||
export function fileExistsInUnpkg(pkg, version, path) { | ||
const uri = `${c.unpkgRoot}/${pkg}@${version}/${path}`; | ||
return got(uri, { | ||
json: true, | ||
method: 'HEAD', | ||
}).then(response => response.statusCode === 200); | ||
} |