Skip to content

Commit 75f37e0

Browse files
committed
fix: add types field back to support legacy moduleResolution
1 parent c2f4392 commit 75f37e0

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

docs/pages/build.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ To configure your project manually, follow these steps:
7979
```json
8080
"source": "./src/index.tsx",
8181
"main": "./lib/module/index.js",
82+
"types": "./lib/typescript/src/index.d.ts",
8283
"exports": {
8384
".": {
8485
"types": "./lib/typescript/src/index.d.ts",
@@ -95,9 +96,10 @@ To configure your project manually, follow these steps:
9596
Here is what each of these fields mean:
9697

9798
- `source`: The path to the source code. It is used by `react-native-builder-bob` to detect the correct output files and provide better error messages.
98-
- `main`: The entry point for the CommonJS build. This is used by Node - such as tests, SSR etc.
99-
- `files`: The files to include in the package when publishing with `npm`.
99+
- `main`: The entry point for legacy setups that don't support the `exports` field. See [Compatibility](./esm.md#compatibility) for more details.
100+
- `types`: The entry point for the TypeScript definitions for legacy setups with `moduleResolution: node10` or `moduleResolution: node`.
100101
- `exports`: The entry points for tools that support the `exports` field in `package.json` - such as Node.js 12+, modern browsers and tools. See [the ESM support guide](./esm.md) for more details.
102+
- `files`: The files to include in the package when publishing with `npm`.
101103

102104
Make sure to change specify correct files according to the targets you have enabled.
103105

docs/pages/esm.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ To make use of the output files, ensure that your `package.json` file contains t
3737

3838
```json
3939
"main": "./lib/module/index.js",
40+
"types": "./lib/typescript/src/index.d.ts",
4041
"exports": {
4142
".": {
4243
"types": "./lib/typescript/src/index.d.ts",
@@ -132,11 +133,12 @@ To configure a dual package setup, you can follow these steps:
132133

133134
The `module` field is a non-standard field that some tools use to determine the ESM entry point.
134135

135-
5. Optionally add a `types` field in your `package.json` to point to the CommonJS type definitions:
136+
5. Optionally change the `types` field in your `package.json` to point to the CommonJS type definitions:
136137

137138
```diff
138139
"main": "./lib/commonjs/index.js",
139140
"module": "./lib/module/index.js",
141+
- "types": "./lib/typescript/src/index.d.ts",
140142
+ "types": "./lib/typescript/commonjs/src/index.d.ts",
141143
```
142144

packages/create-react-native-library/templates/common/$package.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "<%- project.description %>",
55
"source": "./src/index.tsx",
66
"main": "./lib/module/index.js",
7+
"types": "./lib/typescript/src/index.d.ts",
78
"exports": {
89
".": {
910
"types": "./lib/typescript/src/index.d.ts",

packages/react-native-builder-bob/src/__tests__/__snapshots__/init.test.ts.snap

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exports[`initializes the configuration 1`] = `
1616
},
1717
"source": "./src/index.ts",
1818
"main": "./lib/module/index.js",
19+
"types": "./lib/typescript/src/index.d.ts",
1920
"scripts": {
2021
"prepare": "bob build"
2122
},

packages/react-native-builder-bob/src/init.ts

+12
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,22 @@ export async function init() {
293293
if (targets.includes('commonjs') && targets.includes('module')) {
294294
entryFields.main = entries.commonjs;
295295
entryFields.module = entries.module;
296+
297+
if (targets.includes('typescript')) {
298+
entryFields.types = types.require;
299+
}
296300
} else if (targets.includes('commonjs')) {
297301
entryFields.main = entries.commonjs;
302+
303+
if (targets.includes('typescript')) {
304+
entryFields.types = types.require;
305+
}
298306
} else if (targets.includes('module')) {
299307
entryFields.main = entries.module;
308+
309+
if (targets.includes('typescript')) {
310+
entryFields.types = types.import;
311+
}
300312
}
301313

302314
for (const key in entryFields) {

0 commit comments

Comments
 (0)