Skip to content

Convert to TypeScript #99

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

Merged
merged 2 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
}
}
],
"@babel/preset-flow"
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-transform-flow-strip-types",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on: [push]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 22
uses: actions/setup-node@v2
with:
node-version: "22"
- name: Prepare env
run: yarn install --ignore-scripts --frozen-lockfile
- name: Run linter
run: yarn start lint

prettier:
name: Prettier Check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 22
uses: actions/setup-node@v2
with:
node-version: "22"
- name: Prepare env
run: yarn install --ignore-scripts --frozen-lockfile
- name: Run prettier
run: yarn start prettier

test:
name: Unit Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 22
uses: actions/setup-node@v2
with:
node-version: "22"
- name: Prepare env
run: yarn install --ignore-scripts --frozen-lockfile
- name: Run unit tests
run: yarn start test
- name: Run code coverage
uses: codecov/[email protected]
24 changes: 24 additions & 0 deletions .github/workflows/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Lock Threads"

on:
schedule:
- cron: "0 * * * *"
workflow_dispatch:

permissions:
issues: write
pull-requests: write

concurrency:
group: lock

jobs:
action:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v3
with:
issue-inactive-days: "365"
issue-lock-reason: "resolved"
pr-inactive-days: "365"
pr-lock-reason: "resolved"
44 changes: 44 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import js from '@eslint/js'
import tsPlugin from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import globals from 'globals'

export default [
js.configs.recommended,
{
files: ['**/*.{js,jsx,ts,tsx,mjs}'],
languageOptions: {
parser: tsParser,
ecmaVersion: 2020,
sourceType: 'module',
globals: {
...globals.browser,
...globals.node,
...globals.jest
}
},
plugins: {
'@typescript-eslint': tsPlugin
},
rules: {
...tsPlugin.configs.recommended.rules,
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' }
],
'no-unused-vars': 'off'
}
},
{
ignores: [
'node_modules/**',
'dist/**',
'coverage/**',
'.nyc_output/**',
'*.config.js',
'package-scripts.js',
'src/index.d.test.ts'
]
}
]
30 changes: 8 additions & 22 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
)
),
es: {
description: 'run the build with rollup (uses rollup.config.js)',
description: 'run the build with rollup (uses rollup.config.mjs)',
script: 'rollup --config --environment FORMAT:es'
},
cjs: {
Expand All @@ -57,37 +57,23 @@ module.exports = {
description: 'Generates table of contents in README',
script: 'doctoc README.md'
},
copyTypes: series(
npsUtils.copy('src/*.js.flow src/*.d.ts dist'),
npsUtils.copy(
'dist/index.js.flow dist --rename="final-form-arrays.cjs.js.flow"'
),
npsUtils.copy(
'dist/index.js.flow dist --rename="final-form-arrays.es.js.flow"'
)
),
prettier: {
description: 'Runs prettier on everything',
script: 'prettier --write "**/*.([jt]s*)"'
},
copyTypes: series('tsc --declaration --emitDeclarationOnly --outDir dist'),
lint: {
description: 'lint the entire project',
script: 'eslint .'
},
flow: {
description: 'flow check the entire project',
script: 'flow check'
},
typescript: {
description: 'typescript check the entire project',
script: 'tsc'
script: 'tsc --noEmit'
},
validate: {
description:
'This runs several scripts to make sure things look good before committing or on clean install',
default: concurrent.nps(
'lint',
'flow',
'typescript',
'build.andTest',
'test'
)
default: concurrent.nps('lint', 'typescript', 'build.andTest', 'test')
}
},
options: {
Expand Down
104 changes: 60 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"scripts": {
"start": "nps",
"test": "nps test",
"precommit": "lint-staged && npm start validate"
"precommit": "lint-staged && npm start validate",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir dist",
"prebuild": "yarn build:types"
},
"author": "Erik Rasmussen <[email protected]> (http://github.com/erikras)",
"license": "MIT",
Expand All @@ -25,52 +27,55 @@
},
"homepage": "https://github.com/final-form/final-form-arrays#readme",
"devDependencies": {
"@babel/core": "^7.5.4",
"@babel/plugin-external-helpers": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.5.0",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-proposal-export-namespace-from": "^7.5.2",
"@babel/plugin-proposal-function-sent": "^7.5.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
"@babel/plugin-transform-runtime": "^7.5.0",
"@babel/preset-env": "^7.5.4",
"@babel/preset-flow": "^7.0.0",
"@types/jest": "^29.5.14",
"@babel/core": "^7.27.1",
"@babel/plugin-external-helpers": "^7.27.1",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.27.1",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/plugin-proposal-function-sent": "^7.27.1",
"@babel/plugin-proposal-json-strings": "^7.18.6",
"@babel/plugin-proposal-numeric-separator": "^7.18.6",
"@babel/plugin-proposal-throw-expressions": "^7.27.1",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-transform-flow-strip-types": "^7.27.1",
"@babel/plugin-transform-runtime": "^7.27.1",
"@babel/preset-env": "^7.27.2",
"@babel/preset-typescript": "^7.27.1",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.2",
"babel-jest": "^24.8.0",
"bundlesize": "^0.18.0",
"doctoc": "^1.3.0",
"eslint": "^6.0.1",
"eslint-config-react-app": "^3.0.6",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-flowtype": "^3.2.1",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.13.0",
"final-form": "^4.20.8",
"flow-bin": "^0.102.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^29.7.0",
"bundlesize": "^0.18.2",
"doctoc": "^2.2.1",
"@eslint/js": "^9.27.0",
"@typescript-eslint/eslint-plugin": "^8.32.1",
"@typescript-eslint/parser": "^8.32.1",
"eslint": "^9.27.0",
"globals": "^16.2.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-react": "^7.37.5",
"final-form": "^5.0.0-3",
"glow": "^1.2.2",
"husky": "^3.0.0",
"jest": "^24.8.0",
"lint-staged": "^9.2.0",
"nps": "^5.9.5",
"nps-utils": "^1.5.0",
"prettier": "^1.18.2",
"prettier-eslint-cli": "^5.0.0",
"react": "^16.8.6",
"rollup": "^1.16.7",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.1",
"husky": "^9.1.7",
"jest": "^29.7.0",
"lint-staged": "^16.0.0",
"nps": "^5.10.0",
"nps-utils": "^1.7.0",
"prettier": "^3.5.3",
"prettier-eslint-cli": "^8.0.1",
"react": "^19.1.0",
"rollup": "^4.41.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-flow": "^1.1.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.2",
"typescript": "^3.5.3"
"rollup-plugin-uglify": "^6.0.4",
"rollup-plugin-typescript2": "^0.36.0",
"typescript": "^5.8.3",
"ts-jest": "^29.2.5"
},
"peerDependencies": {
"final-form": "^4.20.8"
Expand All @@ -82,10 +87,21 @@
]
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testPathIgnorePatterns": [
".*\\.ts"
]
"/node_modules/",
"src/index.d.test.ts"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx"
],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
}
},
"bundlesize": [
{
Expand Down
26 changes: 19 additions & 7 deletions rollup.config.js → rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import flow from 'rollup-plugin-flow'
import typescript from 'rollup-plugin-typescript2'
import commonjs from 'rollup-plugin-commonjs'
import { uglify } from 'rollup-plugin-uglify'
import replace from 'rollup-plugin-replace'
import ts from 'typescript'

const minify = process.env.MINIFY
const format = process.env.FORMAT
Expand Down Expand Up @@ -33,7 +34,7 @@ if (es) {
}

export default {
input: 'src/index.js',
input: 'src/index.ts',
output: Object.assign(
{
name: 'final-form-arrays',
Expand All @@ -43,8 +44,21 @@ export default {
),
external: [],
plugins: [
resolve({ jsnext: true, main: true }),
flow(),
resolve({
mainFields: ['module', 'jsnext:main', 'main'],
browser: true,
preferBuiltins: false
}),
typescript({
typescript: ts,
clean: true,
tsconfigOverride: {
compilerOptions: {
declaration: false,
declarationMap: false
}
}
}),
commonjs({ include: 'node_modules/**' }),
babel({
exclude: 'node_modules/**',
Expand All @@ -57,12 +71,10 @@ export default {
modules: false,
loose: true
}
],
'@babel/preset-flow'
]
],
plugins: [
['@babel/plugin-transform-runtime', { useESModules: !cjs }],
'@babel/plugin-transform-flow-strip-types',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
'@babel/plugin-proposal-class-properties',
Expand Down
Loading
Loading