Skip to content

Commit 27de9ae

Browse files
committed
fix: support node 18
1 parent abe415d commit 27de9ae

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ npm i jike-sdk
7777
```ts
7878
// index.mjs
7979

80-
// 自带 node-fetch
80+
// 自带 node-fetch。node < 18 使用此版本。
8181
import { setApiConfig } from 'jike-sdk'
8282

83-
// 不带 node-fetch,需要自行 ployfill 或使用最新 Node.js,且需要自行安装 ky
83+
// 不带 node-fetch。自行 ployfill 或 node >= 18 使用此版本。
8484
// import { setApiConfig } from 'jike-sdk/index'
8585

8686
setApiConfig({

src/node-shim.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,11 @@ if (!globals.FormData) {
2727
if (!globals.crypto) globals.crypto = {}
2828
if (!globals.crypto.randomUUID) globals.crypto.randomUUID = randomUUID
2929

30-
export { fetch, Headers, Request, Response, FormData, randomUUID }
30+
export const _nodeShim = {
31+
fetch,
32+
Headers,
33+
Request,
34+
Response,
35+
FormData,
36+
randomUUID,
37+
}

tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const modern = (): Options => {
2828
esbuildOptions: (options) => {
2929
options.outExtension = {}
3030
},
31-
external: ['node-fetch', 'ky'],
3231
clean: true,
3332
}
3433
}
@@ -43,5 +42,6 @@ const node = (): Options => ({
4342
IS_NODE: 'true',
4443
},
4544
minifySyntax: true,
45+
noExternal: ['ky'],
4646
inject: [$r('src/node-shim.ts')],
4747
})

0 commit comments

Comments
 (0)