Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript): foundation #590

Merged
merged 20 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
lib
dist
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
env: {
node: true,
browser: true,
'jest/globals': true
},
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'jest'
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
rules: {
'@typescript-eslint/no-empty-function': 'off',
'no-prototype-builtins': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-this-alias': 'off'
}
};
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
2 changes: 1 addition & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can then view the code coverage at `coverage/lcov-report/index.html`

Run the tests interactively:

$ yarn just-test
$ yarn just-test:watch

## Analyzing the Bundle

Expand Down
16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
collectCoverageFrom: [
'src/**/*.{ts,js}'
],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
},
// globalSetup: '<rootDir>/setup.ts',
// globalTeardown: '<rootDir>/teardown.ts'
};
52 changes: 22 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"license": "Apache-2.0",
"main": "lib/index.js",
"dependencies": {
"@babel/runtime": "^7.12.5",
"country-telephone-data": "^0.6.3",
"date-fns": "^2.15.0",
"events": "^3.2.0",
Expand All @@ -17,58 +16,51 @@
"vanilla-text-mask": "^5.1.1"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-transform-classes": "^7.12.1",
"@babel/plugin-transform-runtime": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"babel-loader": "8.1.0",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"commitizen": "^4.2.3",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^26.0.0",
"jest": "^27.4.7",
"lint-staged": "^12.1.6",
"prettier": "^2.2.1",
"react-scripts": "^4.0.1",
"semantic-release": "^19.0.2",
"source-map-loader": "^3.0.1",
"ts-jest": "^27.1.3",
"ts-loader": "^9.2.6",
"typescript": "^4.5.5",
"webpack": "^5.67.0",
"webpack-bundle-analyzer": "^4.4.0",
"webpack-cli": "^4.4.0"
},
"lint-staged": {
"src/**/*.{js,jsx,json,css}": [
"prettier --single-quote --write"
"src/**/*.{js,ts,json,css}": [
"prettier --write"
]
},
"scripts": {
"lint": "eslint --max-warnings=0 src",
"just-test": "react-scripts test --env=jsdom --maxWorkers=3 --testPathPattern='^((?!performance).)*test.js$'",
"just-test:debug": "npm run just-test --inspect-brk --runInBand --no-cache",
"test:performance": "react-scripts test --env=jsdom --maxWorkers=1 --testPathPattern='performance.test.js$'",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings=0 src",
"just-test": "jest --env=jsdom --maxWorkers=3 --testPathPattern='^((?!performance).)*test.js$'",
"just-test:watch": "npm run just-test -- --watch",
"just-test:debug": "npm run just-test:watch --inspect-brk --runInBand --no-cache",
"test:performance": "jest --env=jsdom --maxWorkers=1 --testPathPattern='performance.test.js$'",
"test:coverage": "npm run just-test -- --coverage",
"test": "npm run lint && CI=true npm run test:coverage && CI=true npm run test:performance",
"test": "npm run lint && npm run test:coverage && npm run test:performance",
"copy-json": "copyfiles -u 1 src/**/*.json lib",
"compile": "cross-env NODE_ENV=production babel src --ignore '**/*.test.js' -d lib && npm run copy-json",
"compile": "tsc && npm run copy-json",
"bundle": "webpack",
"touch": "find src -exec touch {} \\;",
"analyze-bundle": "webpack --json > ./dist/stats.json && webpack-bundle-analyzer ./dist/stats.json",
"prepublishOnly": "cross-env NODE_OPTIONS=--openssl-legacy-provider && yarn compile && yarn bundle",
"semantic-release": "semantic-release",
"prepare": "git config core.hooksPath ./git-hooks"
},
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
],
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
},
"repository": {
"type": "git",
"url": "https://github.com/redgeoff/mson.git"
Expand Down
2 changes: 1 addition & 1 deletion scripts/bundle-size.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

maxBytes=444000
maxBytes=305000

if [ $(wc -c < dist/mson.js) -gt ${maxBytes} ]; then
echo 'Error: bundle too large!'
Expand Down
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"outDir": "./lib",
"allowJs": true,
"target": "es6",
"strict": true,
"esModuleInterop": true,
"declaration": true,
"moduleResolution": "node",
"module": "commonjs"
},
"include": ["./src/**/*"],
"exclude": [
"src/**/*.test.ts",
"src/**/*.test.js"
]
}
20 changes: 12 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
// eslint-disable-next-line
const path = require('path');

module.exports = {
mode: 'production',
entry: {
mson: './src/index.js',
},

output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
library: '[name]',
},

devtool: "source-map",

resolve: {
extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"],
},

module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{ test: /\.tsx?$/, loader: "ts-loader" },
{ test: /\.js$/, loader: "source-map-loader" },
],
},
}
};
Loading