Skip to content

Commit fddc2a8

Browse files
Samuel BodinHaroenv
Samuel Bodin
andauthored
feat: full TS migration (#626)
Co-authored-by: Haroen Viaene <[email protected]>
1 parent 78e3617 commit fddc2a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2697
-3859
lines changed

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

.circleci/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ jobs:
2020
name: Lint
2121
command: yarn lint
2222

23+
- run:
24+
name: Build
25+
command: yarn build
26+
2327
- run:
2428
name: Test
2529
command: yarn test
2630

31+
- store_test_results:
32+
path: junit/
2733

2834
workflows:
2935
suite:

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
lib/
2+
dist/

.eslintrc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"extends": [
33
"algolia",
4-
"algolia/jest"
4+
"algolia/jest",
5+
"algolia/typescript"
56
],
67
"rules": {
78
"valid-jsdoc": "off",
89
"import/extensions": [
910
"error",
10-
"always",
1111
{
12-
"ignorePackages": true
12+
"ignorePackages": true,
13+
"pattern": {
14+
"js": "always",
15+
"ts": "never"
16+
}
1317
}
1418
],
15-
// temp during mig
16-
"jsdoc/require-param-description": "off",
17-
"jsdoc/require-description": "off",
18-
"jsdoc/no-undefined-types": "off"
1919
}
2020
}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules/
22
lib/
3-
.env
3+
.env
4+
junit/
5+
dist/

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14.16.1
1+
14.16.1

__mocks__/dotenv.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

__mocks__/mock.env

Lines changed: 0 additions & 3 deletions
This file was deleted.

jest.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// eslint-disable-next-line import/no-commonjs
2+
module.exports = {
3+
name: 'npm',
4+
5+
transform: {
6+
'^.+\\.[jt]sx?$': 'ts-jest',
7+
},
8+
testMatch: ['<rootDir>/src/**/*.test.[jt]s'],
9+
globals: {
10+
'ts-jest': {
11+
diagnostics: false,
12+
tsconfig: `tsconfig.json`,
13+
},
14+
},
15+
16+
testEnvironment: 'node',
17+
modulePaths: ['src'],
18+
19+
// reporter for circleci
20+
reporters: [
21+
'default',
22+
[
23+
'jest-junit',
24+
{
25+
outputDirectory: 'junit',
26+
suiteNameTemplate: '{filepath}',
27+
ancestorSeparator: ' › ',
28+
addFileAttribute: 'true',
29+
},
30+
],
31+
],
32+
};

package.json

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
"name": "npm-search",
33
"version": "1.0.0",
44
"private": true,
5-
"type": "module",
65
"author": {
76
"name": "Algolia, Inc.",
87
"url": "https://www.algolia.com"
98
},
109
"scripts": {
11-
"start": "node --max-old-space-size=920 src/index.js",
12-
"test": "jest --forceExit",
13-
"test:watch": "jest --watchAll --no-watchman",
14-
"lint": "eslint --ext=jsx,ts,tsx,js .",
10+
"build:hot": "tsc -w --preserveWatchOutput",
11+
"build": "tsc -b",
12+
"clean": "rm -rf dist/",
13+
"dev": "",
1514
"doctoc": "doctoc --notitle --maxlevel 3 README.md",
16-
"prepare": "husky install"
15+
"lint": "eslint --ext=jsx,ts,tsx,js .",
16+
"prepare": "husky install",
17+
"start": "UV_THREADPOOL_SIZE=12 node -r dotenv/config --async-stack-traces --max-old-space-size=920 dist/index.js",
18+
"test:watch": "jest --watchAll --no-watchman",
19+
"test": "jest --forceExit"
1720
},
1821
"renovate": {
1922
"extends": [
@@ -26,9 +29,6 @@
2629
"@sentry/node": "6.5.1",
2730
"algoliasearch": "4.9.3",
2831
"async": "3.2.0",
29-
"babel-cli": "6.26.0",
30-
"babel-preset-env": "1.7.0",
31-
"babel-preset-stage-2": "6.24.1",
3232
"bunyan": "1.8.15",
3333
"bunyan-debug-stream": "2.0.0",
3434
"dotenv": "10.0.0",
@@ -49,10 +49,17 @@
4949
"truncate-utf8-bytes": "1.0.2"
5050
},
5151
"devDependencies": {
52-
"@babel/core": "7.14.5",
53-
"@babel/preset-env": "7.14.5",
54-
"babel-eslint": "10.1.0",
55-
"babel-jest": "27.0.2",
52+
"@types/async": "3.2.6",
53+
"@types/escape-html": "1.0.1",
54+
"@types/hosted-git-info": "3.0.1",
55+
"@types/jest": "26.0.23",
56+
"@types/lodash": "4.14.170",
57+
"@types/ms": "0.7.31",
58+
"@types/numeral": "2.0.1",
59+
"@types/traverse": "0.6.32",
60+
"@types/truncate-utf8-bytes": "1.0.0",
61+
"@typescript-eslint/eslint-plugin": "4.26.0",
62+
"@typescript-eslint/parser": "4.26.0",
5663
"doctoc": "2.0.1",
5764
"eslint": "7.27.0",
5865
"eslint-config-algolia": "18.0.0",
@@ -66,10 +73,13 @@
6673
"eslint-plugin-react": "7.24.0",
6774
"husky": "6.0.0",
6875
"jest": "27.0.4",
76+
"jest-junit": "12.1.0",
6977
"lint-staged": "11.0.0",
7078
"pre-commit": "1.2.2",
7179
"prettier": "2.3.1",
7280
"renovate-config-algolia": "2.1.3",
81+
"ts-jest": "27.0.2",
82+
"typescript": "4.3.2",
7383
"validator": "13.6.0"
7484
},
7585
"engines": {

src/@types/nice-package.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { GetPackage, GetUser, PackageRepo } from '../npm/types';
2+
3+
export interface NicePackageType {
4+
_hasShrinkwrap?: false;
5+
bin?: Record<string, string>;
6+
browser?: string;
7+
bundlesize?: Array<Record<string, unknown>>;
8+
created: string;
9+
dependencies?: Record<string, string>;
10+
deprecated?: boolean;
11+
description: string;
12+
devDependencies?: Record<string, string>;
13+
gitHead?: string;
14+
homepage?: string;
15+
keywords: string[];
16+
lastPublisher?: GetUser;
17+
license?: string | { type: string };
18+
licenseText?: string;
19+
main?: string | string[];
20+
modified: string;
21+
module?: string;
22+
name: string;
23+
other: {
24+
_id?: string;
25+
_rev: string;
26+
'dist-tags': Record<string, string>;
27+
author?: GetUser;
28+
time?: GetPackage['time'];
29+
};
30+
owners?: GetUser[];
31+
readme?: string;
32+
repository?: string | Partial<PackageRepo> | Array<Partial<PackageRepo>>;
33+
scripts: Record<string, string>;
34+
schematics?: string;
35+
starsCount?: number;
36+
type?: 'module' | 'commonjs';
37+
types?: string;
38+
typings?: string;
39+
unpkg?: string;
40+
version?: string;
41+
versions?: Array<{
42+
date: string;
43+
number: string;
44+
}>;
45+
}

src/@types/pkg.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import type { GetUser } from '../npm/types';
2+
3+
export interface Owner {
4+
name: string;
5+
email?: string;
6+
avatar?: string;
7+
link?: string;
8+
}
9+
10+
export interface Repo {
11+
url: string;
12+
host: string;
13+
user: string;
14+
project: string;
15+
path: string;
16+
head?: string;
17+
branch?: string;
18+
}
19+
export interface GithubRepo {
20+
user: string;
21+
project: string;
22+
path: string;
23+
head: string;
24+
}
25+
26+
export type TsType =
27+
| {
28+
ts: 'included' | false | { possible: true; dtsMain: string };
29+
}
30+
| {
31+
ts: 'definitely-typed';
32+
definitelyTyped: string;
33+
};
34+
35+
export type ModuleType = 'esm' | 'cjs' | 'unknown';
36+
37+
export type ComputedMeta = {
38+
computedKeywords: string[];
39+
computedMetadata: Record<string, unknown>;
40+
};
41+
42+
export interface RawPkg {
43+
objectID: string;
44+
name: string;
45+
downloadsLast30Days: number;
46+
downloadsRatio: number;
47+
humanDownloadsLast30Days: string;
48+
popular: boolean;
49+
version: string;
50+
versions: Record<string, string>;
51+
tags: Record<string, string>;
52+
description: string | null;
53+
dependencies: Record<string, string>;
54+
devDependencies: Record<string, string>;
55+
originalAuthor?: GetUser;
56+
repository: Repo | null;
57+
githubRepo: GithubRepo | null;
58+
gitHead: string | null;
59+
readme: string;
60+
owner: Owner | null;
61+
deprecated: boolean;
62+
homepage: string | null;
63+
license: string | null;
64+
keywords: string[];
65+
computedKeywords: ComputedMeta['computedKeywords'];
66+
computedMetadata: ComputedMeta['computedMetadata'];
67+
created: number;
68+
modified: number;
69+
lastPublisher: Owner | null;
70+
owners: Owner[];
71+
bin: Record<string, string>;
72+
types: TsType;
73+
moduleTypes: ModuleType[];
74+
lastCrawl: string;
75+
_searchInternal: {
76+
alternativeNames: string[];
77+
};
78+
}
79+
80+
export type FinalPkg = RawPkg & {
81+
_searchInternal: {
82+
downloadsMagnitude?: number;
83+
jsDelivrPopularity?: number;
84+
popularName?: string;
85+
};
86+
};

0 commit comments

Comments
 (0)