Skip to content

Commit

Permalink
feat: full TS migration (#626)
Browse files Browse the repository at this point in the history
Co-authored-by: Haroen Viaene <hello@haroen.me>
  • Loading branch information
Samuel Bodin and Haroenv committed Jul 2, 2021
1 parent 78e3617 commit fddc2a8
Show file tree
Hide file tree
Showing 47 changed files with 2,697 additions and 3,859 deletions.
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ jobs:
name: Lint
command: yarn lint

- run:
name: Build
command: yarn build

- run:
name: Test
command: yarn test

- store_test_results:
path: junit/

workflows:
suite:
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lib/
dist/
14 changes: 7 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"extends": [
"algolia",
"algolia/jest"
"algolia/jest",
"algolia/typescript"
],
"rules": {
"valid-jsdoc": "off",
"import/extensions": [
"error",
"always",
{
"ignorePackages": true
"ignorePackages": true,
"pattern": {
"js": "always",
"ts": "never"
}
}
],
// temp during mig
"jsdoc/require-param-description": "off",
"jsdoc/require-description": "off",
"jsdoc/no-undefined-types": "off"
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
lib/
.env
.env
junit/
dist/
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.16.1
14.16.1
11 changes: 0 additions & 11 deletions __mocks__/dotenv.js

This file was deleted.

3 changes: 0 additions & 3 deletions __mocks__/mock.env

This file was deleted.

32 changes: 32 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// eslint-disable-next-line import/no-commonjs
module.exports = {
name: 'npm',

transform: {
'^.+\\.[jt]sx?$': 'ts-jest',
},
testMatch: ['<rootDir>/src/**/*.test.[jt]s'],
globals: {
'ts-jest': {
diagnostics: false,
tsconfig: `tsconfig.json`,
},
},

testEnvironment: 'node',
modulePaths: ['src'],

// reporter for circleci
reporters: [
'default',
[
'jest-junit',
{
outputDirectory: 'junit',
suiteNameTemplate: '{filepath}',
ancestorSeparator: ' › ',
addFileAttribute: 'true',
},
],
],
};
36 changes: 23 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
"name": "npm-search",
"version": "1.0.0",
"private": true,
"type": "module",
"author": {
"name": "Algolia, Inc.",
"url": "https://www.algolia.com"
},
"scripts": {
"start": "node --max-old-space-size=920 src/index.js",
"test": "jest --forceExit",
"test:watch": "jest --watchAll --no-watchman",
"lint": "eslint --ext=jsx,ts,tsx,js .",
"build:hot": "tsc -w --preserveWatchOutput",
"build": "tsc -b",
"clean": "rm -rf dist/",
"dev": "",
"doctoc": "doctoc --notitle --maxlevel 3 README.md",
"prepare": "husky install"
"lint": "eslint --ext=jsx,ts,tsx,js .",
"prepare": "husky install",
"start": "UV_THREADPOOL_SIZE=12 node -r dotenv/config --async-stack-traces --max-old-space-size=920 dist/index.js",
"test:watch": "jest --watchAll --no-watchman",
"test": "jest --forceExit"
},
"renovate": {
"extends": [
Expand All @@ -26,9 +29,6 @@
"@sentry/node": "6.5.1",
"algoliasearch": "4.9.3",
"async": "3.2.0",
"babel-cli": "6.26.0",
"babel-preset-env": "1.7.0",
"babel-preset-stage-2": "6.24.1",
"bunyan": "1.8.15",
"bunyan-debug-stream": "2.0.0",
"dotenv": "10.0.0",
Expand All @@ -49,10 +49,17 @@
"truncate-utf8-bytes": "1.0.2"
},
"devDependencies": {
"@babel/core": "7.14.5",
"@babel/preset-env": "7.14.5",
"babel-eslint": "10.1.0",
"babel-jest": "27.0.2",
"@types/async": "3.2.6",
"@types/escape-html": "1.0.1",
"@types/hosted-git-info": "3.0.1",
"@types/jest": "26.0.23",
"@types/lodash": "4.14.170",
"@types/ms": "0.7.31",
"@types/numeral": "2.0.1",
"@types/traverse": "0.6.32",
"@types/truncate-utf8-bytes": "1.0.0",
"@typescript-eslint/eslint-plugin": "4.26.0",
"@typescript-eslint/parser": "4.26.0",
"doctoc": "2.0.1",
"eslint": "7.27.0",
"eslint-config-algolia": "18.0.0",
Expand All @@ -66,10 +73,13 @@
"eslint-plugin-react": "7.24.0",
"husky": "6.0.0",
"jest": "27.0.4",
"jest-junit": "12.1.0",
"lint-staged": "11.0.0",
"pre-commit": "1.2.2",
"prettier": "2.3.1",
"renovate-config-algolia": "2.1.3",
"ts-jest": "27.0.2",
"typescript": "4.3.2",
"validator": "13.6.0"
},
"engines": {
Expand Down
45 changes: 45 additions & 0 deletions src/@types/nice-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { GetPackage, GetUser, PackageRepo } from '../npm/types';

export interface NicePackageType {
_hasShrinkwrap?: false;
bin?: Record<string, string>;
browser?: string;
bundlesize?: Array<Record<string, unknown>>;
created: string;
dependencies?: Record<string, string>;
deprecated?: boolean;
description: string;
devDependencies?: Record<string, string>;
gitHead?: string;
homepage?: string;
keywords: string[];
lastPublisher?: GetUser;
license?: string | { type: string };
licenseText?: string;
main?: string | string[];
modified: string;
module?: string;
name: string;
other: {
_id?: string;
_rev: string;
'dist-tags': Record<string, string>;
author?: GetUser;
time?: GetPackage['time'];
};
owners?: GetUser[];
readme?: string;
repository?: string | Partial<PackageRepo> | Array<Partial<PackageRepo>>;
scripts: Record<string, string>;
schematics?: string;
starsCount?: number;
type?: 'module' | 'commonjs';
types?: string;
typings?: string;
unpkg?: string;
version?: string;
versions?: Array<{
date: string;
number: string;
}>;
}
86 changes: 86 additions & 0 deletions src/@types/pkg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { GetUser } from '../npm/types';

export interface Owner {
name: string;
email?: string;
avatar?: string;
link?: string;
}

export interface Repo {
url: string;
host: string;
user: string;
project: string;
path: string;
head?: string;
branch?: string;
}
export interface GithubRepo {
user: string;
project: string;
path: string;
head: string;
}

export type TsType =
| {
ts: 'included' | false | { possible: true; dtsMain: string };
}
| {
ts: 'definitely-typed';
definitelyTyped: string;
};

export type ModuleType = 'esm' | 'cjs' | 'unknown';

export type ComputedMeta = {
computedKeywords: string[];
computedMetadata: Record<string, unknown>;
};

export interface RawPkg {
objectID: string;
name: string;
downloadsLast30Days: number;
downloadsRatio: number;
humanDownloadsLast30Days: string;
popular: boolean;
version: string;
versions: Record<string, string>;
tags: Record<string, string>;
description: string | null;
dependencies: Record<string, string>;
devDependencies: Record<string, string>;
originalAuthor?: GetUser;
repository: Repo | null;
githubRepo: GithubRepo | null;
gitHead: string | null;
readme: string;
owner: Owner | null;
deprecated: boolean;
homepage: string | null;
license: string | null;
keywords: string[];
computedKeywords: ComputedMeta['computedKeywords'];
computedMetadata: ComputedMeta['computedMetadata'];
created: number;
modified: number;
lastPublisher: Owner | null;
owners: Owner[];
bin: Record<string, string>;
types: TsType;
moduleTypes: ModuleType[];
lastCrawl: string;
_searchInternal: {
alternativeNames: string[];
};
}

export type FinalPkg = RawPkg & {
_searchInternal: {
downloadsMagnitude?: number;
jsDelivrPopularity?: number;
popularName?: string;
};
};
Loading

0 comments on commit fddc2a8

Please sign in to comment.