Skip to content

Commit 586e6ea

Browse files
iamdeyErik Rasmussen
andauthored
fix types exposure in build process (#186)
* fix types exposure in build process - ignore rollup dynamic files - remove outdated copy script - fix path of the generated type definition - remove outdated index.d.ts that contain incoherent duplicated types (probably old type definition) * move exposed definitions directly at the root of dist instead of dist/src this fixes typescript error in userland - restore path of the exposed type definition * Add types field to package.json Fixes the types exposure by pointing package.json 'types' field to the generated index.d.ts file. This ensures TypeScript consumers can find the type definitions. * Extract version to src/version.ts module Addresses CodeRabbit's concern about rootDir: 'src' constraint. Instead of importing ../package.json directly from src/FieldArray.ts (which violates the rootDir boundary), we now: 1. Create src/version.ts that imports package.json and exports version 2. Have FieldArray import from ./version instead This keeps all TypeScript imports within the src/ directory and generates cleaner .d.ts files that don't reference ../package.json. --------- Co-authored-by: Erik Rasmussen <erik@mini.local>
1 parent 34cb258 commit 586e6ea

File tree

7 files changed

+13
-80
lines changed

7 files changed

+13
-80
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ es
1010
npm-debug.log
1111
.DS_Store
1212
.idea
13-
yarn.lock
13+
yarn.lock
14+
rollup.config-*.cjs

package-scripts.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ module.exports = {
2727
'build.es',
2828
'build.cjs',
2929
'build.umd.main',
30-
'build.umd.min',
31-
'copyTypes'
30+
'build.umd.min'
3231
)
3332
),
3433
es: {
@@ -53,7 +52,6 @@ module.exports = {
5352
},
5453
andTest: series.nps('build', 'test.size')
5554
},
56-
copyTypes: npsUtils.copy('src/*.d.ts dist'),
5755
docs: {
5856
description: 'Generates table of contents in README',
5957
script: 'doctoc README.md'

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,6 @@
122122
],
123123
"dependencies": {
124124
"@babel/runtime": "^7.19.4"
125-
}
125+
},
126+
"types": "dist/index.d.ts"
126127
}

src/FieldArray.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { FieldArrayProps } from './types'
44
import renderComponent from './renderComponent'
55
import useFieldArray from './useFieldArray'
66
import copyPropertyDescriptors from './copyPropertyDescriptors'
7-
// @ts-ignore
8-
import { version } from '../package.json'
7+
import { version } from './version'
98

109
export { version }
1110

@@ -45,4 +44,4 @@ const FieldArray = ({
4544
)
4645
}
4746

48-
export default FieldArray
47+
export default FieldArray

src/index.d.ts

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

src/version.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import packageJson from '../package.json'
2+
3+
export const version: string = packageJson.version

tsconfig.build.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"compilerOptions": {
44
"noEmit": false,
55
"declaration": true,
6-
"declarationMap": true
6+
"declarationMap": true,
7+
"rootDir": "src"
78
},
89
"exclude": [
910
"./src/**/*.test.ts",
1011
"./src/**/*.test.tsx",
1112
"./src/**/*.d.test.tsx"
1213
]
13-
}
14+
}

0 commit comments

Comments
 (0)