Skip to content

Commit

Permalink
fix(TS): support scoped packages (#364)
Browse files Browse the repository at this point in the history
* fix(TS): support scoped packages

Also changed the schema to make it easier to filter based on type

* docs: add to the readme
  • Loading branch information
Haroenv committed Jul 25, 2019
1 parent c99144e commit 655e86a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -118,7 +118,10 @@ For every single NPM package, we create a record in the Algolia index. The resul
],
lastCrawl: '2017-10-24T08:29:24.672Z',
dependents: 3321,
types: { ts: '@types/babel-core' }, // @types/xxx | included | false
types: {
ts: 'definitely-typed', // definitely-typed | included | false
definitelyTyped: '@types/babel__core',
},
humanDependents: '3.3k',
changelogFilename: null, // if babel-core had a changelog, it would be the raw GitHub url here
objectID: 'babel-core',
Expand Down
21 changes: 20 additions & 1 deletion src/__tests__/typescript.test.js
Expand Up @@ -21,7 +21,26 @@ describe('getTypeScriptSupport()', () => {
name: 'my-lib',
types: { ts: false },
});
expect(atTypesSupport).toEqual({ types: { ts: '@types/my-lib' } });
expect(atTypesSupport).toEqual({
types: {
ts: 'definitely-typed',
definitelyTyped: '@types/my-lib',
},
});
});

it('Checks for @types/[scope__name]', async () => {
validatePackageExists.mockResolvedValue(true);
const atTypesSupport = await getTypeScriptSupport({
name: '@my-scope/my-lib',
types: { ts: false },
});
expect(atTypesSupport).toEqual({
types: {
ts: 'definitely-typed',
definitelyTyped: '@types/my-scope__my-lib',
},
});
});

it('Checks for a d.ts resolved version of main ', async () => {
Expand Down
9 changes: 7 additions & 2 deletions src/typescriptSupport.js
Expand Up @@ -24,10 +24,15 @@ export async function getTypeScriptSupport(pkg) {
}

// The 2nd most likely is definitely typed
const defTypeName = `@types/${pkg.name}`;
const defTypeName = `@types/${pkg.name.replace('@', '').replace('/', '__')}`;
const defTyped = await validatePackageExists(defTypeName);
if (defTyped) {
return { types: { ts: defTypeName } };
return {
types: {
ts: 'definitely-typed',
definitelyTyped: defTypeName,
},
};
}

if (pkg.types.ts === false) {
Expand Down

0 comments on commit 655e86a

Please sign in to comment.