Skip to content

Commit

Permalink
feat(typescript): foundation (#590)
Browse files Browse the repository at this point in the history
* feat(typescript): foundation

* fix(foo): files only for test setup

* feat(eslint): support typescript

* feat(compile): with typescript

* feat(webpack): with typescript

* fix(webpack): name the bundle mson

* refactor(webpack.config): need to ignore require lint error

* build(typescript): also output definitions

* fix(typescript): combine config and target es6 for generators

* refactor(typescript): nODE_ENV not needed to transpile

* test(just-test): interactively

* fix(just-test): clean up watching

* feat(prettier): define rc

* feat(bundle-size): much smaller with es5 target

* fix(typescript): commonjs needed for mson-server

* feat(registrar): add getters and setters for typescript

* fix(registrar): registrar not register

* refactor(registrar): default client to any until migrate to typescript

* fix(registrar): back out changes for typescript as not needed now
  • Loading branch information
redgeoff authored Jan 27, 2022
1 parent 6ba5089 commit f43465f
Show file tree
Hide file tree
Showing 12 changed files with 2,444 additions and 9,786 deletions.
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

0 comments on commit f43465f

Please sign in to comment.