appandflow / appandflow/react-native-safe-area-context

[RN 0.88] Add modern exports field to package.json

未关闭
#742 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
2.8k
派生
258
平均合并
3 天 1 小时
30 天内合并 PR
2

描述

Sub-issue of
- https://github.com/AppAndFlow/react-native-safe-area-context/issues/741

the strict TS API breaks packages that point their package.json legacy "react-native" cond to TS sources

https://github.com/AppAndFlow/react-native-safe-area-context/blob/ae0e83f67bae458e22ce128fd05be01ab1021a03/package.json#L7

which tells tsgo/tsc (via tsconfig, moduleResolution: bundler) to resolve imports to type-check .tsx source files

hitting the errors from deep RN internal imports (error log in parent issue)

the easiest fix is modern package.json exports, without touching the source files

```json
{
"exports": {
".": {
"types": "./lib/typescript/src/index.d.ts",
"import": "./lib/module/index.js",
"require": "./lib/commonjs/index.js"
},
"./jest/mock": {
"types": "./lib/typescript/jest/mock.d.ts",
"import": "./src/jest/mock.tsx",
"require": "./src/jest/mock.tsx"
},
"./package.json": "./package.json"
}
}
```

while preserving the harmless legacy "react-native" condition to keep older bundlers/toolchains working

example patch

```diff
diff --git a/package.json b/package.json
index 59b8a5d..79da3e3 100644
--- a/package.json
+++ b/package.json
@@ -147,5 +147,18 @@
"type": "all",
"jsSrcsDir": "./src/specs"
},
- "packageManager": "yarn@1.22.22"
+ "packageManager": "yarn@1.22.22",
+ "exports": {
+ ".": {
+ "types": "./lib/typescript/src/index.d.ts",
+ "import": "./lib/module/index.js",
+ "require": "./lib/commonjs/index.js"
+ },
+ "./jest/mock": {
+ "types": "./lib/typescript/jest/mock.d.ts",
+ "import": "./src/jest/mock.tsx",
+ "require": "./src/jest/mock.tsx"
+ },
+ "./package.json": "./package.json"
+ }
}
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。