Skip to content

Commit 9466731

Browse files
authoredApr 30, 2024··
feat(node-builtins): Add node globals (#261)
1 parent 2f71e08 commit 9466731

File tree

5 files changed

+297
-42
lines changed

5 files changed

+297
-42
lines changed
 

‎lib/rules/no-unsupported-features/node-builtins.js

+2-37
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
"use strict"
66

7-
const { READ } = require("@eslint-community/eslint-utils")
87
const {
98
checkUnsupportedBuiltins,
109
messages,
@@ -13,48 +12,14 @@ const enumeratePropertyNames = require("../../util/enumerate-property-names")
1312
const getConfiguredNodeVersion = require("../../util/get-configured-node-version")
1413

1514
const {
15+
NodeBuiltinGlobals,
1616
NodeBuiltinModules,
1717
} = require("../../unsupported-features/node-builtins.js")
1818

19-
/**
20-
* @typedef TraceMap
21-
* @property {import('@eslint-community/eslint-utils').TraceMap<boolean>} globals
22-
* @property {import('@eslint-community/eslint-utils').TraceMap<boolean>} modules
23-
*/
2419
const traceMap = {
25-
globals: {
26-
queueMicrotask: {
27-
[READ]: { supported: ["12.0.0"], experimental: ["11.0.0"] },
28-
},
29-
require: {
30-
resolve: {
31-
paths: { [READ]: { supported: ["8.9.0"] } },
32-
},
33-
},
34-
},
20+
globals: NodeBuiltinGlobals,
3521
modules: NodeBuiltinModules,
3622
}
37-
Object.assign(traceMap.globals, {
38-
Buffer: traceMap.modules.buffer.Buffer,
39-
TextDecoder: {
40-
...traceMap.modules.util.TextDecoder,
41-
[READ]: { supported: ["11.0.0"] },
42-
},
43-
TextEncoder: {
44-
...traceMap.modules.util.TextEncoder,
45-
[READ]: { supported: ["11.0.0"] },
46-
},
47-
URL: {
48-
...traceMap.modules.url.URL,
49-
[READ]: { supported: ["10.0.0"] },
50-
},
51-
URLSearchParams: {
52-
...traceMap.modules.url.URLSearchParams,
53-
[READ]: { supported: ["10.0.0"] },
54-
},
55-
console: traceMap.modules.console,
56-
process: traceMap.modules.process,
57-
})
5823

5924
/** @type {import('eslint').Rule.RuleModule} */
6025
module.exports = {

‎lib/unsupported-features/node-builtins-modules/buffer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict"
22

3-
const { READ } = require("@eslint-community/eslint-utils")
3+
const { CONSTRUCT, READ } = require("@eslint-community/eslint-utils")
44

55
/** @type {import('../types.js').SupportVersionTraceMap} */
66
const buffer = {
@@ -23,6 +23,7 @@ const buffer = {
2323
},
2424
Buffer: {
2525
[READ]: { supported: ["0.1.90"] },
26+
[CONSTRUCT]: { deprecated: ["6.0.0"] },
2627
alloc: { [READ]: { supported: ["5.10.0", "4.5.0"] } },
2728
allocUnsafe: { [READ]: { supported: ["5.10.0", "4.5.0"] } },
2829
allocUnsafeSlow: { [READ]: { supported: ["5.12.0", "4.5.0"] } },

‎lib/unsupported-features/node-builtins-modules/stream.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const Stream = {
5959
}
6060

6161
/** @type {import('../types.js').SupportVersionTraceMap} */
62-
const StreamWeb = {
62+
const WebStream = {
6363
ReadableStream: {
6464
[READ]: { supported: ["16.5.0"] },
6565
from: { [READ]: { supported: ["20.6.0"] } },
@@ -107,11 +107,11 @@ module.exports = {
107107

108108
"stream/web": {
109109
[READ]: { experimental: ["16.5.0"], supported: ["21.0.0"] },
110-
...StreamWeb,
110+
...WebStream,
111111
},
112112
"node:stream/web": {
113113
[READ]: { experimental: ["16.5.0"], supported: ["21.0.0"] },
114-
...StreamWeb,
114+
...WebStream,
115115
},
116116

117117
"stream/consumers": { ...StreamConsumer },

‎lib/unsupported-features/node-builtins.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"use strict"
22

3+
/** @type {import('./types.js').SupportVersionTraceMap} */
4+
const NodeBuiltinGlobals = require("./node-globals.js")
5+
36
/** @type {import('./types.js').SupportVersionTraceMap} */
47
const NodeBuiltinModules = {
58
...require("./node-builtins-modules/assert.js"),
@@ -45,4 +48,4 @@ const NodeBuiltinModules = {
4548
...require("./node-builtins-modules/zlib.js"),
4649
}
4750

48-
module.exports = { NodeBuiltinModules }
51+
module.exports = { NodeBuiltinGlobals, NodeBuiltinModules }
+286
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
"use strict"
2+
3+
const bufferModule = require("./node-builtins-modules/buffer.js")
4+
const consoleModule = require("./node-builtins-modules/console.js")
5+
const cryptoModule = require("./node-builtins-modules/crypto.js")
6+
const eventsModule = require("./node-builtins-modules/events.js")
7+
const processModule = require("./node-builtins-modules/process.js")
8+
const perfModule = require("./node-builtins-modules/perf_hooks.js")
9+
const streamModule = require("./node-builtins-modules/stream.js")
10+
const timersModule = require("./node-builtins-modules/timers.js")
11+
const urlModule = require("./node-builtins-modules/url.js")
12+
const utilModule = require("./node-builtins-modules/util.js")
13+
const workerThreadsModule = require("./node-builtins-modules/worker_threads.js")
14+
15+
const { buffer } = bufferModule
16+
const { console } = consoleModule
17+
const { crypto } = cryptoModule
18+
const { events } = eventsModule
19+
const { process } = processModule
20+
const { perf_hooks } = perfModule
21+
const { ["stream/web"]: WebStream } = streamModule
22+
const { timers } = timersModule
23+
const { url } = urlModule
24+
const { util } = utilModule
25+
const { worker_threads } = workerThreadsModule
26+
27+
const { READ } = require("@eslint-community/eslint-utils")
28+
29+
/** @type {import('./types.js').SupportVersionTraceMap} */
30+
const nodeGlobals = {
31+
__filename: { [READ]: { supported: ["0.0.1"] } },
32+
__dirname: { [READ]: { supported: ["0.1.27"] } },
33+
require: {
34+
[READ]: { supported: ["0.1.13"] },
35+
cache: { [READ]: { supported: ["0.3.0"] } },
36+
extensions: {
37+
[READ]: {
38+
supported: ["0.3.0"],
39+
deprecated: ["0.10.6"],
40+
},
41+
},
42+
main: { [READ]: { supported: ["0.1.17"] } },
43+
resolve: {
44+
[READ]: { supported: ["0.3.0"] },
45+
paths: { [READ]: { supported: ["8.9.0"] } },
46+
},
47+
},
48+
module: {
49+
[READ]: { supported: ["0.1.16"] },
50+
children: { [READ]: { supported: ["0.1.16"] } },
51+
exports: { [READ]: { supported: ["0.1.16"] } },
52+
filename: { [READ]: { supported: ["0.1.16"] } },
53+
id: { [READ]: { supported: ["0.1.16"] } },
54+
isPreloading: { [READ]: { supported: ["15.4.0", "14.17.0"] } },
55+
loaded: { [READ]: { supported: ["0.1.16"] } },
56+
parent: {
57+
[READ]: {
58+
supported: ["0.1.16"],
59+
deprecated: ["14.6.0", "12.19.0"],
60+
},
61+
},
62+
path: { [READ]: { supported: ["11.14.0"] } },
63+
paths: { [READ]: { supported: ["0.4.0"] } },
64+
require: { [READ]: { supported: ["0.5.1"] } },
65+
},
66+
exports: { [READ]: { supported: ["0.1.12"] } },
67+
68+
AbortController: {
69+
[READ]: { experimental: ["15.0.0", "14.17.0"], supported: ["15.4.0"] },
70+
},
71+
AbortSignal: {
72+
[READ]: { supported: ["15.0.0", "14.17.0"] },
73+
abort: { [READ]: { supported: ["15.12.0", "14.17.0"] } },
74+
timeout: { [READ]: { supported: ["17.3.0", "16.14.0"] } },
75+
any: { [READ]: { supported: ["20.3.0", "18.17.0"] } },
76+
},
77+
DOMException: { [READ]: { supported: ["17.0.0"] } },
78+
FormData: {
79+
[READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] },
80+
},
81+
Headers: {
82+
[READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] },
83+
},
84+
MessageEvent: { [READ]: { supported: ["15.0.0"] } },
85+
Navigator: { [READ]: { experimental: ["21.0.0"] } },
86+
Request: {
87+
[READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] },
88+
},
89+
Response: {
90+
[READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] },
91+
},
92+
WebAssembly: { [READ]: { supported: ["8.0.0"] } },
93+
WebSocket: { [READ]: { experimental: ["21.0.0", "20.10.0"] } },
94+
95+
fetch: {
96+
[READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] },
97+
},
98+
global: { [READ]: { supported: ["0.1.27"], deprecated: ["12.0.0"] } },
99+
queueMicrotask: {
100+
[READ]: { supported: ["12.0.0"], experimental: ["11.0.0"] },
101+
},
102+
navigator: {
103+
[READ]: { experimental: ["21.0.0"] },
104+
hardwareConcurrency: { [READ]: { supported: ["21.0.0"] } },
105+
language: { [READ]: { supported: ["21.2.0"] } },
106+
languages: { [READ]: { supported: ["21.2.0"] } },
107+
platform: { [READ]: { supported: ["21.2.0"] } },
108+
userAgent: { [READ]: { supported: ["21.1.0"] } },
109+
},
110+
structuredClone: { [READ]: { supported: ["17.0.0"] } },
111+
112+
// module.buffer
113+
Blob: buffer.Blob,
114+
Buffer: {
115+
...buffer.Buffer,
116+
[READ]: { supported: ["0.1.103"] },
117+
},
118+
File: buffer.File,
119+
atob: { [READ]: { supported: ["16.0.0"] } },
120+
btoa: { [READ]: { supported: ["16.0.0"] } },
121+
122+
// module.console
123+
console: console,
124+
125+
// module.crypto
126+
crypto: {
127+
...crypto.webcrypto,
128+
[READ]: { experimental: ["17.6.0", "16.15.0"] },
129+
},
130+
Crypto: { [READ]: { experimental: ["17.6.0", "16.15.0"] } },
131+
CryptoKey: { [READ]: { experimental: ["17.6.0", "16.15.0"] } },
132+
SubtleCrypto: { [READ]: { experimental: ["17.6.0", "16.15.0"] } },
133+
134+
// module.events
135+
CustomEvent: events.CustomEvent,
136+
Event: events.Event,
137+
EventTarget: events.EventTarget,
138+
139+
// module.perf_hooks
140+
PerformanceEntry: {
141+
...perf_hooks.PerformanceEntry,
142+
[READ]: { supported: ["19.0.0"] },
143+
},
144+
PerformanceMark: {
145+
...perf_hooks.PerformanceMark,
146+
[READ]: { supported: ["19.0.0"] },
147+
},
148+
PerformanceMeasure: {
149+
...perf_hooks.PerformanceMeasure,
150+
[READ]: { supported: ["19.0.0"] },
151+
},
152+
PerformanceObserver: {
153+
...perf_hooks.PerformanceObserver,
154+
[READ]: { supported: ["19.0.0"] },
155+
},
156+
PerformanceObserverEntryList: {
157+
...perf_hooks.PerformanceObserverEntryList,
158+
[READ]: { supported: ["19.0.0"] },
159+
},
160+
PerformanceResourceTiming: {
161+
...perf_hooks.PerformanceResourceTiming,
162+
[READ]: { supported: ["19.0.0"] },
163+
},
164+
performance: {
165+
...perf_hooks.performance,
166+
[READ]: { supported: ["16.0.0"] },
167+
},
168+
169+
// module.process
170+
process: process,
171+
172+
// module.stream
173+
ReadableStream: {
174+
...WebStream.ReadableStream,
175+
[READ]: { experimental: ["18.0.0"] },
176+
},
177+
ReadableStreamDefaultReader: {
178+
...WebStream.ReadableStreamDefaultReader,
179+
[READ]: { experimental: ["18.0.0"] },
180+
},
181+
ReadableStreamBYOBReader: {
182+
...WebStream.ReadableStreamBYOBReader,
183+
[READ]: { experimental: ["18.0.0"] },
184+
},
185+
ReadableStreamDefaultController: {
186+
...WebStream.ReadableStreamDefaultController,
187+
[READ]: { experimental: ["18.0.0"] },
188+
},
189+
ReadableByteStreamController: {
190+
...WebStream.ReadableByteStreamController,
191+
[READ]: { experimental: ["18.0.0"] },
192+
},
193+
ReadableStreamBYOBRequest: {
194+
...WebStream.ReadableStreamBYOBRequest,
195+
[READ]: { experimental: ["18.0.0"] },
196+
},
197+
WritableStream: {
198+
...WebStream.WritableStream,
199+
[READ]: { experimental: ["18.0.0"] },
200+
},
201+
WritableStreamDefaultWriter: {
202+
...WebStream.WritableStreamDefaultWriter,
203+
[READ]: { experimental: ["18.0.0"] },
204+
},
205+
WritableStreamDefaultController: {
206+
...WebStream.WritableStreamDefaultController,
207+
[READ]: { experimental: ["18.0.0"] },
208+
},
209+
TransformStream: {
210+
...WebStream.TransformStream,
211+
[READ]: { experimental: ["18.0.0"] },
212+
},
213+
TransformStreamDefaultController: {
214+
...WebStream.TransformStreamDefaultController,
215+
[READ]: { experimental: ["18.0.0"] },
216+
},
217+
ByteLengthQueuingStrategy: {
218+
...WebStream.ByteLengthQueuingStrategy,
219+
[READ]: { experimental: ["18.0.0"] },
220+
},
221+
CountQueuingStrategy: {
222+
...WebStream.CountQueuingStrategy,
223+
[READ]: { experimental: ["18.0.0"] },
224+
},
225+
TextEncoderStream: {
226+
...WebStream.TextEncoderStream,
227+
[READ]: { experimental: ["18.0.0"] },
228+
},
229+
TextDecoderStream: {
230+
...WebStream.TextDecoderStream,
231+
[READ]: { experimental: ["18.0.0"] },
232+
},
233+
CompressionStream: {
234+
...WebStream.CompressionStream,
235+
[READ]: { experimental: ["18.0.0"] },
236+
},
237+
DecompressionStream: {
238+
...WebStream.DecompressionStream,
239+
[READ]: { experimental: ["18.0.0"] },
240+
},
241+
242+
// module.timers
243+
setInterval: timers.setInterval,
244+
clearInterval: timers.clearInterval,
245+
setTimeout: timers.setTimeout,
246+
clearTimeout: timers.clearTimeout,
247+
setImmediate: timers.setImmediate,
248+
clearImmediate: timers.clearImmediate,
249+
250+
// module.url
251+
URL: {
252+
...url.URL,
253+
[READ]: { supported: ["10.0.0"] },
254+
},
255+
URLSearchParams: {
256+
...url.URLSearchParams,
257+
[READ]: { supported: ["10.0.0"] },
258+
},
259+
260+
// module.util
261+
TextDecoder: {
262+
...util.TextDecoder,
263+
[READ]: { supported: ["11.0.0"] },
264+
},
265+
TextEncoder: {
266+
...util.TextEncoder,
267+
[READ]: { supported: ["11.0.0"] },
268+
},
269+
270+
// module.worker_threads
271+
BroadcastChannel: {
272+
...worker_threads.BroadcastChannel,
273+
[READ]: { supported: ["18.0.0"] },
274+
},
275+
MessageChannel: {
276+
...worker_threads.MessageChannel,
277+
[READ]: { supported: ["15.0.0"] },
278+
},
279+
MessagePort: {
280+
...worker_threads.MessagePort,
281+
[READ]: { supported: ["15.0.0"] },
282+
},
283+
}
284+
285+
/** @type {import('./types.js').SupportVersionTraceMap} */
286+
module.exports = nodeGlobals

0 commit comments

Comments
 (0)
Please sign in to comment.