Skip to content

Commit 3814113

Browse files
committed
fix: fix the types of node builtin modules
1 parent 3a8e462 commit 3814113

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

src/utils/compat/node.d.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// the installed @types/node package is version 12 so that backwards compatibility is maintained
2+
// node: prefix is removed by Babel, so define the types of those packages here so that TypeScript can find them
3+
4+
declare module "node:fs" {
5+
import fs from "fs"
6+
export = fs
7+
}
8+
9+
declare module "node:path" {
10+
import path from "path"
11+
export = path
12+
}
13+
14+
declare module "node:child_process" {
15+
import child_process from "child_process"
16+
export = child_process
17+
}
18+
19+
declare module "node:os" {
20+
import os from "os"
21+
export = os
22+
}
23+
24+
declare module "node:util" {
25+
import util from "util"
26+
export = util
27+
}
28+
29+
declare module "node:stream" {
30+
import stream from "stream"
31+
export = stream
32+
}
33+
34+
declare module "node:zlib" {
35+
import zlib from "zlib"
36+
export = zlib
37+
}
38+
39+
declare module "node:crypto" {
40+
import crypto from "crypto"
41+
export = crypto
42+
}
43+
declare module "node:http" {
44+
import http from "http"
45+
export = http
46+
}
47+
48+
declare module "node:https" {
49+
import https from "https"
50+
export = https
51+
}
52+
53+
declare module "node:events" {
54+
import events from "events"
55+
export = events
56+
}
57+
58+
declare module "node:assert" {
59+
import assert from "assert"
60+
export = assert
61+
}
62+
63+
declare module "node:constants" {
64+
import constants from "constants"
65+
export = constants
66+
}
67+
68+
declare module "node:querystring" {
69+
import querystring from "querystring"
70+
export = querystring
71+
}
72+
73+
declare module "node:url" {
74+
import url from "url"
75+
export = url
76+
}
77+
78+
declare module "node:fs/promises" {
79+
import fsPromises from "fs/promises"
80+
export = fsPromises
81+
}
82+
83+
declare module "node:path/posix" {
84+
import pathPosix from "path/posix"
85+
export = pathPosix
86+
}
87+
88+
declare module "node:path/win32" {
89+
import pathWin32 from "path/win32"
90+
export = pathWin32
91+
}

tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
"skipLibCheck": true,
2121
"allowImportingTsExtensions": true,
2222
"noEmit": true,
23-
// target Node.js 12 https://node.green/#ES2019
2423
"lib": [
25-
"ES2019"
24+
// target Node.js 12 https://node.green/#ES2019
25+
"ES2019",
26+
// https://node.green/#ES2020-features-String-prototype-matchAll
27+
"ES2020.String"
2628
],
2729
"target": "ESNext",
2830
"allowJs": true,

0 commit comments

Comments
 (0)