Skip to content

Commit

Permalink
fix: use vitest, update deps, security fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ruicsh committed Feb 18, 2023
1 parent acfa9ee commit 493ca72
Show file tree
Hide file tree
Showing 14 changed files with 993 additions and 1,813 deletions.
7 changes: 2 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
"airbnb-typescript/base",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"plugin:jest/all"
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"jest"
"@typescript-eslint"
],
"parserOptions": {
"ecmaVersion": 9,
Expand All @@ -21,7 +19,6 @@
"jest": true
},
"rules": {
"jest/prefer-expect-assertions": "off",
"import/no-extraneous-dependencies": "off",
"import/prefer-default-export": "off"
},
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
19.6.0
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

8 changes: 0 additions & 8 deletions jest.config.ts

This file was deleted.

47 changes: 22 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
"fetch"
],
"types": "dist/index.d.ts",
"module": "./dist/index.esm.js",
"main": "./dist/index.cjs.js",
"module": "./dist/index.mjs",
"main": "./dist/index.cjs",
"exports": {
".": [
{
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js",
"default": "./dist/index.esm.js"
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
},
"./dist/index.esm.js"
"./dist/index.mjs"
]
},
"files": [
"dist/index.esm.js",
"dist/index.cjs.js",
"dist/index.mjs",
"dist/index.cjs",
"dist/index.d.ts",
"dist/fetch.d.ts"
],
Expand All @@ -36,30 +36,27 @@
"format": "prettier --write src sh",
"lint:ts": "tsc --noEmit",
"lint": "eslint src --ext ts",
"test:ci": "jest --ci",
"test": "jest --watch"
"test:ci": "vitest run",
"test": "vitest --watch"
},
"devDependencies": {
"@types/debug": "4.1.7",
"@types/jest": "29.2.5",
"@types/node": "18.11.18",
"@typescript-eslint/eslint-plugin": "5.48.0",
"@typescript-eslint/parser": "5.48.0",
"esbuild": "0.16.15",
"eslint": "8.31.0",
"@types/node": "18.14.0",
"@typescript-eslint/eslint-plugin": "5.52.0",
"@typescript-eslint/parser": "5.52.0",
"@vitest/coverage-c8": "0.28.5",
"esbuild": "0.17.8",
"eslint": "8.34.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "27.2.1",
"jest": "29.3.1",
"msw": "0.49.2",
"eslint-plugin-import": "2.27.5",
"msw": "1.0.1",
"nyc": "15.1.0",
"prettier": "2.8.2",
"ts-jest": "29.0.3",
"ts-node": "10.9.1",
"tsx": "3.12.1",
"typescript": "4.9.4",
"prettier": "2.8.4",
"tsx": "3.12.3",
"typescript": "4.9.5",
"vitest": "0.28.5",
"zx": "7.1.1"
},
"publishConfig": {
Expand Down
14 changes: 3 additions & 11 deletions sh/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ async function main() {
await $`rm -rf dist`;
await $`tsc --build tsconfig.build.json`;

const formats = ["cjs", "esm"];
for await (const format of formats) {
const flags = [
"--bundle",
"--platform=node",
`--format=${format}`,
`--minify`,
`--outfile=dist/index.${format}.js`,
];
const flags = ["--bundle", "--platform=node", "--minify"];

await $`esbuild src/index.ts ${flags}`;
}
await $`esbuild src/index.ts --outfile=dist/index.cjs ${flags}`;
await $`esbuild src/index.ts --format=esm --outfile=dist/index.mjs ${flags}`;

await $`cp src/fetch.d.ts dist/fetch.d.ts`;
await $`rm -rf dist/mocks`;
Expand Down
3 changes: 2 additions & 1 deletion sh/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ async function main() {
await $`rm -rf coverage/`;
await $`rm -rf .nyc_output/`;

await $`NODE_ENV=test LOG_LEVEL=silent nyc yarn test:ci --coverage true --coverageReporters lcov`;
const flags = ["--coverage true"].flatMap((f) => f.split(" "));
await $`NODE_ENV=test LOG_LEVEL=silent nyc yarn test:ci ${flags}`;
}

main();
2 changes: 1 addition & 1 deletion src/fetch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type HttpMethod = "GET" | "POST" | "DELETE" | "PUT" | "HEAD" | "PATCH";
export type HeadersInit = Record<string, string>;

export interface FetchOptions extends RequestOptions {
body: string;
body?: BodyInit | null;
headers: HeadersInit;
method: HttpMethod;
}
Expand Down
14 changes: 12 additions & 2 deletions src/headers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import type { Headers } from "./fetch.d";

export function fromRawHeaders(rawHeaders: string[]): Headers {
// const headers = rawHeaders.reduce((acc, _, index, array) => {
// if (index % 2 === 0) {
// const entry = array.slice(index, index + 2);
// acc.push(entry);
// }

// return acc;
// }, [] as string[][]);

const headers = rawHeaders.reduce((acc, _, index, array) => {
if (index % 2 === 0) {
const entry = array.slice(index, index + 2);
acc.push(entry);
const [key, value] = entry;
acc[key] = value;
}

return acc;
}, [] as string[][]);
}, {} as Record<string, string>);

return new URLSearchParams(headers) as Headers;
}
1 change: 1 addition & 0 deletions src/mocks/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { setupServer } from "msw/node";

import { handlers } from "./handlers";

export const server = setupServer(...handlers);
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"outDir": "./dist",
"removeComments": true,
"strict": true,
"target": "es6"
"target": "es6",
"types": ["vitest/globals"]
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
"exclude": ["node_modules/**/*"]
}
17 changes: 17 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from "node:path";
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
setupFiles: "./vitest.setup.ts",
coverage: {
reporter: ["lcov"],
},
},
resolve: {
alias: {
src: path.resolve(__dirname, "./src/"),
},
},
});
File renamed without changes.
Loading

0 comments on commit 493ca72

Please sign in to comment.