File tree Expand file tree Collapse file tree 4 files changed +31
-24
lines changed Expand file tree Collapse file tree 4 files changed +31
-24
lines changed Original file line number Diff line number Diff line change 30
30
* );
31
31
* ```
32
32
*
33
+ * ## `fetch` API in Node.js
34
+ *
35
+ * Node.js v18 has a native browser-like fetch interface. Versions
36
+ * below are normally using [`node-fetch`](https://github.com/node-fetch/node-fetch)
37
+ * to circumvent this issue.
38
+ *
39
+ * For environments using Node v18 and earlier, Tpy uses the native
40
+ * fetch without requiring the package. Environments containing earlier
41
+ * versions of Node will require the package.
42
+ *
33
43
* @module
34
44
*/
35
45
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " tpy" ,
3
- "version" : " v1.0.0-pre-release-4 " ,
3
+ "version" : " v1.0.0-pre-release-5 " ,
4
4
"description" : " 🔑 A strongly typed Pylon API client." ,
5
5
"license" : " MIT" ,
6
6
"type" : " commonjs" ,
30
30
"bugs" : {
31
31
"url" : " https://github.com/insyri/tpy/issues"
32
32
},
33
- "dependencies " : {
33
+ "peerDependencies " : {
34
34
"@types/node" : " 18.11.3" ,
35
- "discord-api-types" : " 0.37.14"
35
+ "discord-api-types" : " 0.37.14" ,
36
+ "node-fetch" : " 3.2.10"
37
+ },
38
+ "peerDependenciesMeta" : {
39
+ "node-fetch" : {
40
+ "optional" : true
41
+ }
36
42
},
37
43
"devDependencies" : {
38
44
"typescript" : " 4.8.4"
39
- },
40
- "optionalDependencies" : {
41
- "node-fetch" : " 3.2.10"
42
45
}
43
46
}
Original file line number Diff line number Diff line change 1
- import fetch , {
2
- Blob ,
3
- blobFrom ,
4
- blobFromSync ,
5
- File ,
6
- fileFrom ,
7
- fileFromSync ,
8
- FormData ,
9
- Headers ,
10
- Request ,
11
- Response ,
12
- } from 'node-fetch' ;
1
+ // This file is meant to be read by Node.js, Deno stops at line 5.
2
+ // If Deno extension enabled, ignore errors.
13
3
14
- if ( ! globalThis . fetch ) {
15
- Object . defineProperty ( globalThis , 'fetch' , fetch ) ;
16
- Object . defineProperty ( globalThis , 'Headers' , Headers ) ;
17
- Object . defineProperty ( globalThis , 'Request' , Request ) ;
18
- Object . defineProperty ( globalThis , 'Response' , Response ) ;
4
+ if (
5
+ 'process' in globalThis && // If Node
6
+ Number ( globalThis . process . version . substring ( 1 , 3 ) ) < 18
7
+ ) {
8
+ Object . defineProperty (
9
+ globalThis ,
10
+ 'fetch' ,
11
+ require ( 'node-fetch' ) ,
12
+ ) ;
19
13
}
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import TpyWs from './ws.ts';
12
12
import TpyKV from './kv.ts' ;
13
13
import Context from './context.ts' ;
14
14
15
- if ( ! Deno ) await import ( './fetch_polyfill.ts' ) ;
15
+ import './fetch_polyfill.ts' ;
16
16
17
17
/**
18
18
* The central entity for interacting with the Pylon API; the entrypoint.
You can’t perform that action at this time.
0 commit comments