Skip to content

Commit

Permalink
chore!: migrate to typescript and vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
westeezy committed Nov 23, 2022
1 parent 661321e commit 5341713
Show file tree
Hide file tree
Showing 47 changed files with 751 additions and 847 deletions.
10 changes: 7 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* @flow */

module.exports = {
extends: "@krakenjs/eslint-config-grumbler/eslintrc-browser",
extends:
"./node_modules/@krakenjs/eslint-config-grumbler/eslintrc-typescript.js",

rules: {
"@typescript-eslint/keyword-spacing": "off",
// off for initial ts conversion
},
};
14 changes: 0 additions & 14 deletions .flowconfig

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ jobs:
- name: 👕 Lint commit messages
uses: wagoid/commitlint-github-action@v4

- name: ▶️ Run flow-typed script
run: npm run flow-typed

- name: ▶️ Run build script
run: npm run build

Expand Down
4 changes: 4 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extends: "@krakenjs/babel-config-grumbler/babelrc-browser",
presets: ["@krakenjs/babel-config-grumbler/flow-ts-babel-preset"],
};
3 changes: 0 additions & 3 deletions babel.config.json

This file was deleted.

15 changes: 0 additions & 15 deletions karma.conf.js

This file was deleted.

58 changes: 34 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
"version": "2.0.0",
"description": "Javascript module template.",
"main": "index.js",
"types": "dist/types/index.d.ts",
"scripts": {
"setup": "npm install && npm run flow-typed",
"lint": "eslint src/ test/ *.js --ext .js,.jsx",
"flow-typed": "rm -rf ./flow-typed && flow-typed install && flow-typed install mocha@4",
"flow": "flow",
"build": "npm run test && npm run babel && npm run webpack && npm run build:types",
"build:flow": "find ./dist -type f -not -path './node_modules/*' -name '*.d.ts' -exec sh -c 'flowgen --add-flow-header $1 -o ${1%.*.*}.js.flow' _ '{}' \\;",
"build:tsc": "tsc src/**/** --outDir ./dist/esm --declaration --emitDeclarationOnly --strict",
"build:types": "npm run build:tsc && npm run build:flow",
"webpack": "cross-env NODE_ENV=production babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress",
"babel": "cross-env NODE_ENV=production babel src/ --out-dir ./dist/esm/ --extensions .ts,.tsx",
"tsc": "tsc",
"format": "prettier --write --ignore-unknown .",
"format:check": "prettier --check .",
"karma": "cross-env NODE_ENV=test babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/karma start",
"babel": "babel src/ --out-dir dist/module",
"webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress",
"test": "npm run format:check && npm run lint && npm run flow-typed && npm run flow && npm run karma",
"build": "npm run test && npm run babel && npm run webpack",
"test": "npm run format:check && npm run lint && npm run tsc --no-emit && npm run vitest",
"lint": "eslint --ext ts,tsx,js,jsx src/ test/",
"clean": "rimraf dist coverage",
"reinstall": "rimraf flow-typed && rimraf node_modules && npm install && flow-typed install",
"debug": "cross-env NODE_ENV=debug",
"prepare": "husky install",
"prerelease": "npm run clean && npm run build && git add dist && git commit -m 'ci: check in dist folder' || echo 'Nothing to distribute'",
"release": "standard-version",
"postrelease": "git push && git push --follow-tags && npm publish"
"postrelease": "git push && git push --follow-tags && npm publish",
"debug": "cross-env NODE_ENV=debug",
"prepare": "husky install",
"vitest": "vitest run --dom --coverage",
"vitest:watch": "vitest watch --dom --coverage --ui"
},
"standard-version": {
"types": [
Expand Down Expand Up @@ -89,17 +91,25 @@
],
"readmeFilename": "README.md",
"devDependencies": {
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"@krakenjs/grumbler-scripts": "^8.0.4",
"cross-env": "^7.0.3",
"flow-bin": "0.155.0",
"flow-typed": "^3.8.0",
"husky": "^7.0.4",
"jest": "^29.3.1",
"lint-staged": "^12.4.0",
"prettier": "^2.6.2",
"standard-version": "^9.3.2"
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@krakenjs/babel-config-grumbler": "^8.0.7",
"@krakenjs/eslint-config-grumbler": "^8.0.7",
"@krakenjs/typescript-config-grumbler": "^8.0.7",
"@krakenjs/webpack-config-grumbler": "^8.1.0-alpha.1",
"@vitest/coverage-c8": "^0.25.3",
"@vitest/ui": "^0.25.3",
"flowgen": "^1.20.1",
"happy-dom": "^7.7.0",
"husky": "^8.0.2",
"lint-staged": "^13.0.3",
"prettier": "^2.8.0",
"standard-version": "^9.5.0",
"ts-node": "^10.9.1",
"typescript": "4.9.3",
"utility-types": "^3.10.0",
"vite": "^3.2.4",
"vitest": "^0.25.3"
},
"lint-staged": {
"*": "prettier --write --ignore-unknown"
Expand Down
14 changes: 8 additions & 6 deletions src/common.js → src/common.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
/* @flow */
import type { $Values } from "utility-types";

import { TYPE } from "./constants";
import type { CustomSerializedType } from "./types";

export function isSerializedType(item: mixed): boolean {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
export function isSerializedType(item: any): boolean {
return (
typeof item === "object" &&
item !== null &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
typeof item.__type__ === "string"
);
}

export function determineType(val: mixed): $Values<typeof TYPE> | void {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
export function determineType(val: any): $Values<typeof TYPE> | undefined {
if (typeof val === "undefined") {
return TYPE.UNDEFINED;
}
Expand All @@ -33,16 +36,15 @@ export function determineType(val: mixed): $Values<typeof TYPE> | void {
return TYPE.ERROR;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (typeof val.then === "function") {
return TYPE.PROMISE;
}

// $FlowFixMe method-unbinding
if (Object.prototype.toString.call(val) === "[object RegExp]") {
return TYPE.REGEX;
}

// $FlowFixMe method-unbinding
if (Object.prototype.toString.call(val) === "[object Date]") {
return TYPE.DATE;
}
Expand All @@ -63,7 +65,7 @@ export function determineType(val: mixed): $Values<typeof TYPE> | void {
}
}

export function serializeType<T: string, V: mixed>(
export function serializeType<T extends string, V>(
type: T,
val: V
): CustomSerializedType<T, V> {
Expand Down
16 changes: 0 additions & 16 deletions src/constants.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const TYPE = {
FUNCTION: "function",
ERROR: "error",
PROMISE: "promise",
REGEX: "regex",
DATE: "date",
ARRAY: "array",
OBJECT: "object",
STRING: "string",
NUMBER: "number",
BOOLEAN: "boolean",
NULL: "null",
UNDEFINED: "undefined",
} as const;
102 changes: 0 additions & 102 deletions src/deserialize.js

This file was deleted.

Loading

0 comments on commit 5341713

Please sign in to comment.