Skip to content

Commit 2b10860

Browse files
committed
Merge pull request #31 from final-form/ts
Convert to TypeScript
2 parents c21e696 + 03cab8d commit 2b10860

22 files changed

+10804
-903
lines changed

.babelrc.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,19 @@ const loose = true
44

55
module.exports = {
66
presets: [
7-
[
8-
'@babel/preset-env',
9-
{
10-
loose,
11-
...(test ? { targets: { node: '8' } } : {})
12-
}
13-
],
7+
['@babel/preset-env', { modules: false }],
148
'@babel/preset-react',
15-
'@babel/preset-flow'
9+
'@babel/preset-typescript'
1610
],
1711
plugins: [
18-
'@babel/plugin-transform-flow-strip-types',
19-
'@babel/plugin-syntax-dynamic-import',
20-
'@babel/plugin-syntax-import-meta',
21-
['@babel/plugin-proposal-class-properties', { loose }],
22-
'@babel/plugin-proposal-json-strings',
23-
[
24-
'@babel/plugin-proposal-decorators',
25-
{
26-
legacy: true
27-
}
28-
],
29-
'@babel/plugin-proposal-function-sent',
12+
'@babel/plugin-proposal-class-properties',
13+
'@babel/plugin-proposal-decorators',
3014
'@babel/plugin-proposal-export-namespace-from',
15+
'@babel/plugin-proposal-function-sent',
16+
'@babel/plugin-proposal-json-strings',
3117
'@babel/plugin-proposal-numeric-separator',
3218
'@babel/plugin-proposal-throw-expressions',
33-
test && '@babel/plugin-transform-react-jsx-source'
34-
].filter(Boolean)
19+
'@babel/plugin-syntax-dynamic-import',
20+
'@babel/plugin-syntax-import-meta'
21+
]
3522
}

.eslintrc

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
{
2-
"extends": "react-app",
2+
"extends": ["react-app"],
3+
"plugins": ["babel", "react"],
34
"rules": {
4-
"jsx-a11y/href-no-hash": 0
5-
}
5+
"no-unused-vars": "off",
6+
"@typescript-eslint/no-unused-vars": [
7+
"error",
8+
{
9+
"varsIgnorePattern": "^_",
10+
"argsIgnorePattern": "^_"
11+
}
12+
],
13+
"jsx-a11y/href-no-hash": 0,
14+
"react/jsx-uses-react": "off",
15+
"react/react-in-jsx-scope": "off"
16+
},
17+
"overrides": [
18+
{
19+
"files": ["**/*.test.ts", "**/*.test.tsx"],
20+
"rules": {
21+
"@typescript-eslint/no-unused-vars": "off"
22+
}
23+
}
24+
]
625
}

.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 ${{ matrix.node_version }}
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 ${{ matrix.node_version }}
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 ${{ matrix.node_version }}
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"

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
*.iml
33
.nyc_output
44
coverage
5-
flow-coverage
65
node_modules
76
dist
87
lib
98
es
109
npm-debug.log
1110
.DS_Store
1211
.idea
13-
yarn.lock
14-
package-lock.json

eslint.config.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import parser from '@typescript-eslint/parser'
2+
import plugin from '@typescript-eslint/eslint-plugin'
3+
4+
export default [
5+
{
6+
ignores: [
7+
'dist/**',
8+
'node_modules/**',
9+
'coverage/**',
10+
'*.config.js',
11+
'*.config.cjs',
12+
'*.config.mjs',
13+
'package-scripts.js',
14+
'package-scripts.cjs',
15+
'.babelrc.js',
16+
'src/**/*.test.tsx'
17+
]
18+
},
19+
{
20+
files: ['src/**/*.{js,ts,tsx}', 'tests/**/*.{js,ts,tsx}'],
21+
languageOptions: {
22+
ecmaVersion: 'latest',
23+
sourceType: 'module',
24+
parser,
25+
parserOptions: {
26+
project: './tsconfig.json'
27+
}
28+
},
29+
plugins: {
30+
'@typescript-eslint': plugin
31+
},
32+
rules: {
33+
'@typescript-eslint/no-explicit-any': 'warn',
34+
'@typescript-eslint/explicit-function-return-type': 'off',
35+
'@typescript-eslint/explicit-module-boundary-types': 'off'
36+
}
37+
}
38+
]

package-scripts.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
const npsUtils = require('nps-utils')
1+
import npsUtils from 'nps-utils'
22

3-
const series = npsUtils.series
4-
const concurrent = npsUtils.concurrent
5-
const rimraf = npsUtils.rimraf
6-
const crossEnv = npsUtils.crossEnv
3+
const { series, concurrent, rimraf, crossEnv } = npsUtils
74

8-
module.exports = {
5+
export default {
96
scripts: {
107
test: {
118
default: crossEnv('NODE_ENV=test jest --coverage'),
@@ -52,13 +49,8 @@ module.exports = {
5249
andTest: series.nps('build', 'test.size')
5350
},
5451
copyTypes: series(
55-
npsUtils.copy('src/*.js.flow dist'),
56-
npsUtils.copy(
57-
'dist/index.js.flow dist --rename="react-final-form-listeners.cjs.js.flow"'
58-
),
59-
npsUtils.copy(
60-
'dist/index.js.flow dist --rename="react-final-form-listeners.es.js.flow"'
61-
)
52+
rimraf('dist/*.d.ts'),
53+
'tsc --emitDeclarationOnly --outDir dist'
6254
),
6355
docs: {
6456
description: 'Generates table of contents in README',
@@ -68,9 +60,9 @@ module.exports = {
6860
description: 'lint the entire project',
6961
script: 'eslint .'
7062
},
71-
flow: {
72-
description: 'flow check the entire project',
73-
script: 'flow check'
63+
prettier: {
64+
description: 'Runs prettier on everything',
65+
script: 'prettier --write "**/*.([jt]s*)"'
7466
},
7567
validate: {
7668
description:

0 commit comments

Comments
 (0)