Skip to content

Commit fbab5b3

Browse files
committed
chore: add support for both cjs and esm builds
1 parent 8fd333a commit fbab5b3

File tree

6 files changed

+250
-924
lines changed

6 files changed

+250
-924
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.19.6
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import npsUtils from 'nps-utils'
1+
const npsUtils = require('nps-utils')
22

3-
const { series, rimraf, concurrent } = npsUtils
3+
const { series, rimraf } = npsUtils
44

5-
export default {
5+
const nps = (script) => `nps -c ./package-scripts.cjs ${script}`
6+
7+
module.exports = {
68
scripts: {
79
test: {
810
default: 'jest --coverage',
@@ -17,14 +19,14 @@ export default {
1719
},
1820
build: {
1921
description: 'delete the dist directory and run all builds',
20-
default: series(rimraf('dist'), 'nps build.rollup'),
22+
default: series(rimraf('dist'), nps('build.rollup')),
2123
rollup: {
2224
description: 'Run all rollup builds sequentially',
23-
default: series.nps(
24-
'build.rollup.es',
25-
'build.rollup.cjs',
26-
'build.rollup.umd.main',
27-
'build.rollup.umd.min'
25+
default: series(
26+
nps('build.rollup.es'),
27+
nps('build.rollup.cjs'),
28+
nps('build.rollup.umd.main'),
29+
nps('build.rollup.umd.min')
2830
),
2931
es: {
3032
description: 'run the build with rollup (uses rollup.config.js)',
@@ -47,7 +49,7 @@ export default {
4749
}
4850
}
4951
},
50-
andTest: series.nps('build', 'test.size')
52+
andTest: series(nps('build'), nps('test.size'))
5153
},
5254
docs: {
5355
description: 'Generates table of contents in README',
@@ -65,7 +67,7 @@ export default {
6567
validate: {
6668
description:
6769
'This runs several scripts to make sure things look good before committing or on clean install',
68-
default: series.nps('lint', 'build.andTest', 'test')
70+
default: series(nps('lint'), nps('build.andTest'), nps('test'))
6971
},
7072
clean: {
7173
description: 'delete the dist directory',

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
"name": "final-form-focus",
33
"version": "2.0.0",
44
"description": "Decorator that will attempt to apply focus to the first field with an error upon an attempted form submission in 🏁 Final Form",
5-
"main": "dist/final-form-focus.cjs.js",
5+
"main": "dist/final-form-focus.cjs",
66
"jsnext:main": "dist/final-form-focus.es.js",
77
"module": "dist/final-form-focus.es.js",
88
"type": "module",
9+
"exports": {
10+
".": {
11+
"import": "./dist/final-form-focus.es.js",
12+
"require": "./dist/final-form-focus.cjs"
13+
}
14+
},
915
"files": [
1016
"dist"
1117
],
1218
"scripts": {
13-
"start": "nps",
14-
"test": "nps test",
19+
"start": "nps -c ./package-scripts.cjs",
20+
"test": "nps -c ./package-scripts.cjs test",
1521
"precommit": "lint-staged && npm start validate"
1622
},
1723
"author": "Erik Rasmussen <rasmussenerik@gmail.com> (http://github.com/erikras)",
@@ -41,21 +47,19 @@
4147
"@babel/preset-env": "^7.27.2",
4248
"@babel/preset-typescript": "^7.27.1",
4349
"@eslint/js": "^9.27.0",
50+
"@rollup/plugin-babel": "^6.0.4",
51+
"@rollup/plugin-commonjs": "^28.0.3",
52+
"@rollup/plugin-node-resolve": "^16.0.1",
53+
"@rollup/plugin-replace": "^6.0.2",
54+
"@rollup/plugin-terser": "^0.4.4",
4455
"@types/jest": "^29.5.14",
4556
"@types/node": "^22.15.27",
4657
"@typescript-eslint/eslint-plugin": "^8.33.0",
4758
"@typescript-eslint/parser": "^8.33.0",
48-
"babel-core": "^7.0.0-bridge.0",
49-
"babel-eslint": "^10.1.0",
5059
"babel-jest": "^29.7.0",
5160
"bundlesize": "^0.18.2",
5261
"doctoc": "^2.2.1",
5362
"eslint": "^9.27.0",
54-
"eslint-config-react-app": "^7.0.1",
55-
"eslint-plugin-babel": "^5.3.1",
56-
"eslint-plugin-import": "^2.31.0",
57-
"eslint-plugin-jsx-a11y": "^6.10.2",
58-
"eslint-plugin-react": "^7.37.5",
5963
"final-form": "^5.0.0",
6064
"husky": "^9.1.7",
6165
"jest": "^29.7.0",
@@ -66,10 +70,6 @@
6670
"prettier": "^3.5.3",
6771
"prettier-eslint-cli": "^8.0.1",
6872
"rollup": "^4.41.1",
69-
"rollup-plugin-babel": "^4.4.0",
70-
"rollup-plugin-commonjs": "^10.1.0",
71-
"rollup-plugin-node-resolve": "^5.2.0",
72-
"rollup-plugin-replace": "^2.2.0",
7373
"rollup-plugin-uglify": "^6.0.4",
7474
"typescript": "^5.8.3"
7575
},
@@ -92,7 +92,7 @@
9292
"threshold": "1.2kB"
9393
},
9494
{
95-
"path": "dist/final-form-focus.cjs.js",
95+
"path": "dist/final-form-focus.cjs",
9696
"threshold": "1.2kB"
9797
}
9898
]

rollup.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import resolve from 'rollup-plugin-node-resolve'
2-
import babel from 'rollup-plugin-babel'
3-
import commonjs from 'rollup-plugin-commonjs'
1+
import resolve from '@rollup/plugin-node-resolve'
2+
import babel from '@rollup/plugin-babel'
3+
import commonjs from '@rollup/plugin-commonjs'
44
import { uglify } from 'rollup-plugin-uglify'
5-
import replace from 'rollup-plugin-replace'
5+
import replace from '@rollup/plugin-replace'
66
import { createRequire } from 'module'
77
const require = createRequire(import.meta.url)
88
const pkg = require('./package.json')
@@ -27,7 +27,7 @@ if (es) {
2727
output = { file: `dist/final-form-focus.umd.js`, format: 'umd' }
2828
}
2929
} else if (cjs) {
30-
output = { file: `dist/final-form-focus.cjs.js`, format: 'cjs' }
30+
output = { file: `dist/final-form-focus.cjs`, format: 'cjs' }
3131
} else if (format) {
3232
throw new Error(`invalid format specified: "${format}".`)
3333
} else {
@@ -58,7 +58,7 @@ export default {
5858
babel({
5959
exclude: 'node_modules/**',
6060
babelrc: false,
61-
runtimeHelpers: true,
61+
babelHelpers: 'runtime',
6262
extensions: ['.js', '.jsx', '.ts', '.tsx'],
6363
presets: [
6464
[

0 commit comments

Comments
 (0)