Skip to content

Commit 30133eb

Browse files
authored
Convert to TypeScript (#99)
* Convert to TypeScript * CI
1 parent fe3c260 commit 30133eb

40 files changed

+912
-705
lines changed

.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
}
1010
}
1111
],
12-
"@babel/preset-flow"
12+
"@babel/preset-typescript"
1313
],
1414
"plugins": [
15-
"@babel/plugin-transform-flow-strip-types",
1615
"@babel/plugin-syntax-dynamic-import",
1716
"@babel/plugin-syntax-import-meta",
1817
"@babel/plugin-proposal-class-properties",

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
name: Lint
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Use Node.js 22
13+
uses: actions/setup-node@v2
14+
with:
15+
node-version: "22"
16+
- name: Prepare env
17+
run: yarn install --ignore-scripts --frozen-lockfile
18+
- name: Run linter
19+
run: yarn start lint
20+
21+
prettier:
22+
name: Prettier Check
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Use Node.js 22
28+
uses: actions/setup-node@v2
29+
with:
30+
node-version: "22"
31+
- name: Prepare env
32+
run: yarn install --ignore-scripts --frozen-lockfile
33+
- name: Run prettier
34+
run: yarn start prettier
35+
36+
test:
37+
name: Unit Tests
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v2
42+
- name: Use Node.js 22
43+
uses: actions/setup-node@v2
44+
with:
45+
node-version: "22"
46+
- name: Prepare env
47+
run: yarn install --ignore-scripts --frozen-lockfile
48+
- name: Run unit tests
49+
run: yarn start test
50+
- name: Run code coverage
51+
uses: codecov/codecov-action@v2.1.0

.github/workflows/lock.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Lock Threads"
2+
3+
on:
4+
schedule:
5+
- cron: "0 * * * *"
6+
workflow_dispatch:
7+
8+
permissions:
9+
issues: write
10+
pull-requests: write
11+
12+
concurrency:
13+
group: lock
14+
15+
jobs:
16+
action:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: dessant/lock-threads@v3
20+
with:
21+
issue-inactive-days: "365"
22+
issue-lock-reason: "resolved"
23+
pr-inactive-days: "365"
24+
pr-lock-reason: "resolved"

eslint.config.mjs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import js from '@eslint/js'
2+
import tsPlugin from '@typescript-eslint/eslint-plugin'
3+
import tsParser from '@typescript-eslint/parser'
4+
import globals from 'globals'
5+
6+
export default [
7+
js.configs.recommended,
8+
{
9+
files: ['**/*.{js,jsx,ts,tsx,mjs}'],
10+
languageOptions: {
11+
parser: tsParser,
12+
ecmaVersion: 2020,
13+
sourceType: 'module',
14+
globals: {
15+
...globals.browser,
16+
...globals.node,
17+
...globals.jest
18+
}
19+
},
20+
plugins: {
21+
'@typescript-eslint': tsPlugin
22+
},
23+
rules: {
24+
...tsPlugin.configs.recommended.rules,
25+
'@typescript-eslint/no-explicit-any': 'off',
26+
'@typescript-eslint/no-unused-vars': [
27+
'error',
28+
{ argsIgnorePattern: '^_' }
29+
],
30+
'no-unused-vars': 'off'
31+
}
32+
},
33+
{
34+
ignores: [
35+
'node_modules/**',
36+
'dist/**',
37+
'coverage/**',
38+
'.nyc_output/**',
39+
'*.config.js',
40+
'package-scripts.js',
41+
'src/index.d.test.ts'
42+
]
43+
}
44+
]

package-scripts.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
)
3535
),
3636
es: {
37-
description: 'run the build with rollup (uses rollup.config.js)',
37+
description: 'run the build with rollup (uses rollup.config.mjs)',
3838
script: 'rollup --config --environment FORMAT:es'
3939
},
4040
cjs: {
@@ -57,37 +57,23 @@ module.exports = {
5757
description: 'Generates table of contents in README',
5858
script: 'doctoc README.md'
5959
},
60-
copyTypes: series(
61-
npsUtils.copy('src/*.js.flow src/*.d.ts dist'),
62-
npsUtils.copy(
63-
'dist/index.js.flow dist --rename="final-form-arrays.cjs.js.flow"'
64-
),
65-
npsUtils.copy(
66-
'dist/index.js.flow dist --rename="final-form-arrays.es.js.flow"'
67-
)
68-
),
60+
prettier: {
61+
description: 'Runs prettier on everything',
62+
script: 'prettier --write "**/*.([jt]s*)"'
63+
},
64+
copyTypes: series('tsc --declaration --emitDeclarationOnly --outDir dist'),
6965
lint: {
7066
description: 'lint the entire project',
7167
script: 'eslint .'
7268
},
73-
flow: {
74-
description: 'flow check the entire project',
75-
script: 'flow check'
76-
},
7769
typescript: {
7870
description: 'typescript check the entire project',
79-
script: 'tsc'
71+
script: 'tsc --noEmit'
8072
},
8173
validate: {
8274
description:
8375
'This runs several scripts to make sure things look good before committing or on clean install',
84-
default: concurrent.nps(
85-
'lint',
86-
'flow',
87-
'typescript',
88-
'build.andTest',
89-
'test'
90-
)
76+
default: concurrent.nps('lint', 'typescript', 'build.andTest', 'test')
9177
}
9278
},
9379
options: {

package.json

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"scripts": {
1313
"start": "nps",
1414
"test": "nps test",
15-
"precommit": "lint-staged && npm start validate"
15+
"precommit": "lint-staged && npm start validate",
16+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir dist",
17+
"prebuild": "yarn build:types"
1618
},
1719
"author": "Erik Rasmussen <rasmussenerik@gmail.com> (http://github.com/erikras)",
1820
"license": "MIT",
@@ -25,52 +27,55 @@
2527
},
2628
"homepage": "https://github.com/final-form/final-form-arrays#readme",
2729
"devDependencies": {
28-
"@babel/core": "^7.5.4",
29-
"@babel/plugin-external-helpers": "^7.0.0",
30-
"@babel/plugin-proposal-class-properties": "^7.5.0",
31-
"@babel/plugin-proposal-decorators": "^7.4.4",
32-
"@babel/plugin-proposal-export-namespace-from": "^7.5.2",
33-
"@babel/plugin-proposal-function-sent": "^7.5.0",
34-
"@babel/plugin-proposal-json-strings": "^7.0.0",
35-
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
36-
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
37-
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
38-
"@babel/plugin-syntax-import-meta": "^7.0.0",
39-
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
40-
"@babel/plugin-transform-runtime": "^7.5.0",
41-
"@babel/preset-env": "^7.5.4",
42-
"@babel/preset-flow": "^7.0.0",
30+
"@types/jest": "^29.5.14",
31+
"@babel/core": "^7.27.1",
32+
"@babel/plugin-external-helpers": "^7.27.1",
33+
"@babel/plugin-proposal-class-properties": "^7.18.6",
34+
"@babel/plugin-proposal-decorators": "^7.27.1",
35+
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
36+
"@babel/plugin-proposal-function-sent": "^7.27.1",
37+
"@babel/plugin-proposal-json-strings": "^7.18.6",
38+
"@babel/plugin-proposal-numeric-separator": "^7.18.6",
39+
"@babel/plugin-proposal-throw-expressions": "^7.27.1",
40+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
41+
"@babel/plugin-syntax-import-meta": "^7.10.4",
42+
"@babel/plugin-transform-flow-strip-types": "^7.27.1",
43+
"@babel/plugin-transform-runtime": "^7.27.1",
44+
"@babel/preset-env": "^7.27.2",
45+
"@babel/preset-typescript": "^7.27.1",
4346
"babel-core": "^7.0.0-bridge.0",
44-
"babel-eslint": "^10.0.2",
45-
"babel-jest": "^24.8.0",
46-
"bundlesize": "^0.18.0",
47-
"doctoc": "^1.3.0",
48-
"eslint": "^6.0.1",
49-
"eslint-config-react-app": "^3.0.6",
50-
"eslint-plugin-babel": "^5.3.0",
51-
"eslint-plugin-flowtype": "^3.2.1",
52-
"eslint-plugin-import": "^2.16.0",
53-
"eslint-plugin-jsx-a11y": "^6.2.1",
54-
"eslint-plugin-react": "^7.13.0",
55-
"final-form": "^4.20.8",
56-
"flow-bin": "^0.102.0",
47+
"babel-eslint": "^10.1.0",
48+
"babel-jest": "^29.7.0",
49+
"bundlesize": "^0.18.2",
50+
"doctoc": "^2.2.1",
51+
"@eslint/js": "^9.27.0",
52+
"@typescript-eslint/eslint-plugin": "^8.32.1",
53+
"@typescript-eslint/parser": "^8.32.1",
54+
"eslint": "^9.27.0",
55+
"globals": "^16.2.0",
56+
"eslint-plugin-import": "^2.31.0",
57+
"eslint-plugin-jsx-a11y": "^6.10.2",
58+
"eslint-plugin-react": "^7.37.5",
59+
"final-form": "^5.0.0-3",
5760
"glow": "^1.2.2",
58-
"husky": "^3.0.0",
59-
"jest": "^24.8.0",
60-
"lint-staged": "^9.2.0",
61-
"nps": "^5.9.5",
62-
"nps-utils": "^1.5.0",
63-
"prettier": "^1.18.2",
64-
"prettier-eslint-cli": "^5.0.0",
65-
"react": "^16.8.6",
66-
"rollup": "^1.16.7",
67-
"rollup-plugin-babel": "^4.3.3",
68-
"rollup-plugin-commonjs": "^10.0.1",
61+
"husky": "^9.1.7",
62+
"jest": "^29.7.0",
63+
"lint-staged": "^16.0.0",
64+
"nps": "^5.10.0",
65+
"nps-utils": "^1.7.0",
66+
"prettier": "^3.5.3",
67+
"prettier-eslint-cli": "^8.0.1",
68+
"react": "^19.1.0",
69+
"rollup": "^4.41.1",
70+
"rollup-plugin-babel": "^4.4.0",
71+
"rollup-plugin-commonjs": "^10.1.0",
6972
"rollup-plugin-flow": "^1.1.1",
7073
"rollup-plugin-node-resolve": "^5.2.0",
7174
"rollup-plugin-replace": "^2.2.0",
72-
"rollup-plugin-uglify": "^6.0.2",
73-
"typescript": "^3.5.3"
75+
"rollup-plugin-uglify": "^6.0.4",
76+
"rollup-plugin-typescript2": "^0.36.0",
77+
"typescript": "^5.8.3",
78+
"ts-jest": "^29.2.5"
7479
},
7580
"peerDependencies": {
7681
"final-form": "^4.20.8"
@@ -82,10 +87,21 @@
8287
]
8388
},
8489
"jest": {
90+
"preset": "ts-jest",
8591
"testEnvironment": "node",
8692
"testPathIgnorePatterns": [
87-
".*\\.ts"
88-
]
93+
"/node_modules/",
94+
"src/index.d.test.ts"
95+
],
96+
"moduleFileExtensions": [
97+
"ts",
98+
"tsx",
99+
"js",
100+
"jsx"
101+
],
102+
"transform": {
103+
"^.+\\.(ts|tsx)$": "ts-jest"
104+
}
89105
},
90106
"bundlesize": [
91107
{

rollup.config.js renamed to rollup.config.mjs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import resolve from 'rollup-plugin-node-resolve'
22
import babel from 'rollup-plugin-babel'
3-
import flow from 'rollup-plugin-flow'
3+
import typescript from 'rollup-plugin-typescript2'
44
import commonjs from 'rollup-plugin-commonjs'
55
import { uglify } from 'rollup-plugin-uglify'
66
import replace from 'rollup-plugin-replace'
7+
import ts from 'typescript'
78

89
const minify = process.env.MINIFY
910
const format = process.env.FORMAT
@@ -33,7 +34,7 @@ if (es) {
3334
}
3435

3536
export default {
36-
input: 'src/index.js',
37+
input: 'src/index.ts',
3738
output: Object.assign(
3839
{
3940
name: 'final-form-arrays',
@@ -43,8 +44,21 @@ export default {
4344
),
4445
external: [],
4546
plugins: [
46-
resolve({ jsnext: true, main: true }),
47-
flow(),
47+
resolve({
48+
mainFields: ['module', 'jsnext:main', 'main'],
49+
browser: true,
50+
preferBuiltins: false
51+
}),
52+
typescript({
53+
typescript: ts,
54+
clean: true,
55+
tsconfigOverride: {
56+
compilerOptions: {
57+
declaration: false,
58+
declarationMap: false
59+
}
60+
}
61+
}),
4862
commonjs({ include: 'node_modules/**' }),
4963
babel({
5064
exclude: 'node_modules/**',
@@ -57,12 +71,10 @@ export default {
5771
modules: false,
5872
loose: true
5973
}
60-
],
61-
'@babel/preset-flow'
74+
]
6275
],
6376
plugins: [
6477
['@babel/plugin-transform-runtime', { useESModules: !cjs }],
65-
'@babel/plugin-transform-flow-strip-types',
6678
'@babel/plugin-syntax-dynamic-import',
6779
'@babel/plugin-syntax-import-meta',
6880
'@babel/plugin-proposal-class-properties',

0 commit comments

Comments
 (0)