From ad8abc301fd4f5db9ad212e615e0472589383532 Mon Sep 17 00:00:00 2001 From: Sebastian Good <2230835+scagood@users.noreply.github.com> Date: Tue, 30 Apr 2024 10:45:08 +0200 Subject: [PATCH 1/2] chore: Update buffer + stream modules --- lib/unsupported-features/node-builtins-modules/buffer.js | 3 ++- lib/unsupported-features/node-builtins-modules/stream.js | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/unsupported-features/node-builtins-modules/buffer.js b/lib/unsupported-features/node-builtins-modules/buffer.js index dddd12ba..639c8ac1 100644 --- a/lib/unsupported-features/node-builtins-modules/buffer.js +++ b/lib/unsupported-features/node-builtins-modules/buffer.js @@ -1,6 +1,6 @@ "use strict" -const { READ } = require("@eslint-community/eslint-utils") +const { CONSTRUCT, READ } = require("@eslint-community/eslint-utils") /** @type {import('../types.js').SupportVersionTraceMap} */ const buffer = { @@ -23,6 +23,7 @@ const buffer = { }, Buffer: { [READ]: { supported: ["0.1.90"] }, + [CONSTRUCT]: { deprecated: ["6.0.0"] }, alloc: { [READ]: { supported: ["5.10.0", "4.5.0"] } }, allocUnsafe: { [READ]: { supported: ["5.10.0", "4.5.0"] } }, allocUnsafeSlow: { [READ]: { supported: ["5.12.0", "4.5.0"] } }, diff --git a/lib/unsupported-features/node-builtins-modules/stream.js b/lib/unsupported-features/node-builtins-modules/stream.js index f60e17da..6eece3b5 100644 --- a/lib/unsupported-features/node-builtins-modules/stream.js +++ b/lib/unsupported-features/node-builtins-modules/stream.js @@ -59,7 +59,7 @@ const Stream = { } /** @type {import('../types.js').SupportVersionTraceMap} */ -const StreamWeb = { +const WebStream = { ReadableStream: { [READ]: { supported: ["16.5.0"] }, from: { [READ]: { supported: ["20.6.0"] } }, @@ -107,11 +107,11 @@ module.exports = { "stream/web": { [READ]: { experimental: ["16.5.0"], supported: ["21.0.0"] }, - ...StreamWeb, + ...WebStream, }, "node:stream/web": { [READ]: { experimental: ["16.5.0"], supported: ["21.0.0"] }, - ...StreamWeb, + ...WebStream, }, "stream/consumers": { ...StreamConsumer }, From 547a36aa34abe728c557db2f0408c904daaf2777 Mon Sep 17 00:00:00 2001 From: Sebastian Good <2230835+scagood@users.noreply.github.com> Date: Tue, 30 Apr 2024 10:45:48 +0200 Subject: [PATCH 2/2] feat(node-builtins): Add node globals --- .../no-unsupported-features/node-builtins.js | 39 +-- lib/unsupported-features/node-builtins.js | 5 +- lib/unsupported-features/node-globals.js | 286 ++++++++++++++++++ 3 files changed, 292 insertions(+), 38 deletions(-) create mode 100644 lib/unsupported-features/node-globals.js diff --git a/lib/rules/no-unsupported-features/node-builtins.js b/lib/rules/no-unsupported-features/node-builtins.js index be648555..68edaea6 100644 --- a/lib/rules/no-unsupported-features/node-builtins.js +++ b/lib/rules/no-unsupported-features/node-builtins.js @@ -4,7 +4,6 @@ */ "use strict" -const { READ } = require("@eslint-community/eslint-utils") const { checkUnsupportedBuiltins, messages, @@ -13,48 +12,14 @@ const enumeratePropertyNames = require("../../util/enumerate-property-names") const getConfiguredNodeVersion = require("../../util/get-configured-node-version") const { + NodeBuiltinGlobals, NodeBuiltinModules, } = require("../../unsupported-features/node-builtins.js") -/** - * @typedef TraceMap - * @property {import('@eslint-community/eslint-utils').TraceMap} globals - * @property {import('@eslint-community/eslint-utils').TraceMap} modules - */ const traceMap = { - globals: { - queueMicrotask: { - [READ]: { supported: ["12.0.0"], experimental: ["11.0.0"] }, - }, - require: { - resolve: { - paths: { [READ]: { supported: ["8.9.0"] } }, - }, - }, - }, + globals: NodeBuiltinGlobals, modules: NodeBuiltinModules, } -Object.assign(traceMap.globals, { - Buffer: traceMap.modules.buffer.Buffer, - TextDecoder: { - ...traceMap.modules.util.TextDecoder, - [READ]: { supported: ["11.0.0"] }, - }, - TextEncoder: { - ...traceMap.modules.util.TextEncoder, - [READ]: { supported: ["11.0.0"] }, - }, - URL: { - ...traceMap.modules.url.URL, - [READ]: { supported: ["10.0.0"] }, - }, - URLSearchParams: { - ...traceMap.modules.url.URLSearchParams, - [READ]: { supported: ["10.0.0"] }, - }, - console: traceMap.modules.console, - process: traceMap.modules.process, -}) /** @type {import('eslint').Rule.RuleModule} */ module.exports = { diff --git a/lib/unsupported-features/node-builtins.js b/lib/unsupported-features/node-builtins.js index 2729f0eb..f484096e 100644 --- a/lib/unsupported-features/node-builtins.js +++ b/lib/unsupported-features/node-builtins.js @@ -1,5 +1,8 @@ "use strict" +/** @type {import('./types.js').SupportVersionTraceMap} */ +const NodeBuiltinGlobals = require("./node-globals.js") + /** @type {import('./types.js').SupportVersionTraceMap} */ const NodeBuiltinModules = { ...require("./node-builtins-modules/assert.js"), @@ -45,4 +48,4 @@ const NodeBuiltinModules = { ...require("./node-builtins-modules/zlib.js"), } -module.exports = { NodeBuiltinModules } +module.exports = { NodeBuiltinGlobals, NodeBuiltinModules } diff --git a/lib/unsupported-features/node-globals.js b/lib/unsupported-features/node-globals.js new file mode 100644 index 00000000..bf19c4cd --- /dev/null +++ b/lib/unsupported-features/node-globals.js @@ -0,0 +1,286 @@ +"use strict" + +const bufferModule = require("./node-builtins-modules/buffer.js") +const consoleModule = require("./node-builtins-modules/console.js") +const cryptoModule = require("./node-builtins-modules/crypto.js") +const eventsModule = require("./node-builtins-modules/events.js") +const processModule = require("./node-builtins-modules/process.js") +const perfModule = require("./node-builtins-modules/perf_hooks.js") +const streamModule = require("./node-builtins-modules/stream.js") +const timersModule = require("./node-builtins-modules/timers.js") +const urlModule = require("./node-builtins-modules/url.js") +const utilModule = require("./node-builtins-modules/util.js") +const workerThreadsModule = require("./node-builtins-modules/worker_threads.js") + +const { buffer } = bufferModule +const { console } = consoleModule +const { crypto } = cryptoModule +const { events } = eventsModule +const { process } = processModule +const { perf_hooks } = perfModule +const { ["stream/web"]: WebStream } = streamModule +const { timers } = timersModule +const { url } = urlModule +const { util } = utilModule +const { worker_threads } = workerThreadsModule + +const { READ } = require("@eslint-community/eslint-utils") + +/** @type {import('./types.js').SupportVersionTraceMap} */ +const nodeGlobals = { + __filename: { [READ]: { supported: ["0.0.1"] } }, + __dirname: { [READ]: { supported: ["0.1.27"] } }, + require: { + [READ]: { supported: ["0.1.13"] }, + cache: { [READ]: { supported: ["0.3.0"] } }, + extensions: { + [READ]: { + supported: ["0.3.0"], + deprecated: ["0.10.6"], + }, + }, + main: { [READ]: { supported: ["0.1.17"] } }, + resolve: { + [READ]: { supported: ["0.3.0"] }, + paths: { [READ]: { supported: ["8.9.0"] } }, + }, + }, + module: { + [READ]: { supported: ["0.1.16"] }, + children: { [READ]: { supported: ["0.1.16"] } }, + exports: { [READ]: { supported: ["0.1.16"] } }, + filename: { [READ]: { supported: ["0.1.16"] } }, + id: { [READ]: { supported: ["0.1.16"] } }, + isPreloading: { [READ]: { supported: ["15.4.0", "14.17.0"] } }, + loaded: { [READ]: { supported: ["0.1.16"] } }, + parent: { + [READ]: { + supported: ["0.1.16"], + deprecated: ["14.6.0", "12.19.0"], + }, + }, + path: { [READ]: { supported: ["11.14.0"] } }, + paths: { [READ]: { supported: ["0.4.0"] } }, + require: { [READ]: { supported: ["0.5.1"] } }, + }, + exports: { [READ]: { supported: ["0.1.12"] } }, + + AbortController: { + [READ]: { experimental: ["15.0.0", "14.17.0"], supported: ["15.4.0"] }, + }, + AbortSignal: { + [READ]: { supported: ["15.0.0", "14.17.0"] }, + abort: { [READ]: { supported: ["15.12.0", "14.17.0"] } }, + timeout: { [READ]: { supported: ["17.3.0", "16.14.0"] } }, + any: { [READ]: { supported: ["20.3.0", "18.17.0"] } }, + }, + DOMException: { [READ]: { supported: ["17.0.0"] } }, + FormData: { + [READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] }, + }, + Headers: { + [READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] }, + }, + MessageEvent: { [READ]: { supported: ["15.0.0"] } }, + Navigator: { [READ]: { experimental: ["21.0.0"] } }, + Request: { + [READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] }, + }, + Response: { + [READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] }, + }, + WebAssembly: { [READ]: { supported: ["8.0.0"] } }, + WebSocket: { [READ]: { experimental: ["21.0.0", "20.10.0"] } }, + + fetch: { + [READ]: { experimental: ["17.5.0", "16.15.0"], supported: ["21.0.0"] }, + }, + global: { [READ]: { supported: ["0.1.27"], deprecated: ["12.0.0"] } }, + queueMicrotask: { + [READ]: { supported: ["12.0.0"], experimental: ["11.0.0"] }, + }, + navigator: { + [READ]: { experimental: ["21.0.0"] }, + hardwareConcurrency: { [READ]: { supported: ["21.0.0"] } }, + language: { [READ]: { supported: ["21.2.0"] } }, + languages: { [READ]: { supported: ["21.2.0"] } }, + platform: { [READ]: { supported: ["21.2.0"] } }, + userAgent: { [READ]: { supported: ["21.1.0"] } }, + }, + structuredClone: { [READ]: { supported: ["17.0.0"] } }, + + // module.buffer + Blob: buffer.Blob, + Buffer: { + ...buffer.Buffer, + [READ]: { supported: ["0.1.103"] }, + }, + File: buffer.File, + atob: { [READ]: { supported: ["16.0.0"] } }, + btoa: { [READ]: { supported: ["16.0.0"] } }, + + // module.console + console: console, + + // module.crypto + crypto: { + ...crypto.webcrypto, + [READ]: { experimental: ["17.6.0", "16.15.0"] }, + }, + Crypto: { [READ]: { experimental: ["17.6.0", "16.15.0"] } }, + CryptoKey: { [READ]: { experimental: ["17.6.0", "16.15.0"] } }, + SubtleCrypto: { [READ]: { experimental: ["17.6.0", "16.15.0"] } }, + + // module.events + CustomEvent: events.CustomEvent, + Event: events.Event, + EventTarget: events.EventTarget, + + // module.perf_hooks + PerformanceEntry: { + ...perf_hooks.PerformanceEntry, + [READ]: { supported: ["19.0.0"] }, + }, + PerformanceMark: { + ...perf_hooks.PerformanceMark, + [READ]: { supported: ["19.0.0"] }, + }, + PerformanceMeasure: { + ...perf_hooks.PerformanceMeasure, + [READ]: { supported: ["19.0.0"] }, + }, + PerformanceObserver: { + ...perf_hooks.PerformanceObserver, + [READ]: { supported: ["19.0.0"] }, + }, + PerformanceObserverEntryList: { + ...perf_hooks.PerformanceObserverEntryList, + [READ]: { supported: ["19.0.0"] }, + }, + PerformanceResourceTiming: { + ...perf_hooks.PerformanceResourceTiming, + [READ]: { supported: ["19.0.0"] }, + }, + performance: { + ...perf_hooks.performance, + [READ]: { supported: ["16.0.0"] }, + }, + + // module.process + process: process, + + // module.stream + ReadableStream: { + ...WebStream.ReadableStream, + [READ]: { experimental: ["18.0.0"] }, + }, + ReadableStreamDefaultReader: { + ...WebStream.ReadableStreamDefaultReader, + [READ]: { experimental: ["18.0.0"] }, + }, + ReadableStreamBYOBReader: { + ...WebStream.ReadableStreamBYOBReader, + [READ]: { experimental: ["18.0.0"] }, + }, + ReadableStreamDefaultController: { + ...WebStream.ReadableStreamDefaultController, + [READ]: { experimental: ["18.0.0"] }, + }, + ReadableByteStreamController: { + ...WebStream.ReadableByteStreamController, + [READ]: { experimental: ["18.0.0"] }, + }, + ReadableStreamBYOBRequest: { + ...WebStream.ReadableStreamBYOBRequest, + [READ]: { experimental: ["18.0.0"] }, + }, + WritableStream: { + ...WebStream.WritableStream, + [READ]: { experimental: ["18.0.0"] }, + }, + WritableStreamDefaultWriter: { + ...WebStream.WritableStreamDefaultWriter, + [READ]: { experimental: ["18.0.0"] }, + }, + WritableStreamDefaultController: { + ...WebStream.WritableStreamDefaultController, + [READ]: { experimental: ["18.0.0"] }, + }, + TransformStream: { + ...WebStream.TransformStream, + [READ]: { experimental: ["18.0.0"] }, + }, + TransformStreamDefaultController: { + ...WebStream.TransformStreamDefaultController, + [READ]: { experimental: ["18.0.0"] }, + }, + ByteLengthQueuingStrategy: { + ...WebStream.ByteLengthQueuingStrategy, + [READ]: { experimental: ["18.0.0"] }, + }, + CountQueuingStrategy: { + ...WebStream.CountQueuingStrategy, + [READ]: { experimental: ["18.0.0"] }, + }, + TextEncoderStream: { + ...WebStream.TextEncoderStream, + [READ]: { experimental: ["18.0.0"] }, + }, + TextDecoderStream: { + ...WebStream.TextDecoderStream, + [READ]: { experimental: ["18.0.0"] }, + }, + CompressionStream: { + ...WebStream.CompressionStream, + [READ]: { experimental: ["18.0.0"] }, + }, + DecompressionStream: { + ...WebStream.DecompressionStream, + [READ]: { experimental: ["18.0.0"] }, + }, + + // module.timers + setInterval: timers.setInterval, + clearInterval: timers.clearInterval, + setTimeout: timers.setTimeout, + clearTimeout: timers.clearTimeout, + setImmediate: timers.setImmediate, + clearImmediate: timers.clearImmediate, + + // module.url + URL: { + ...url.URL, + [READ]: { supported: ["10.0.0"] }, + }, + URLSearchParams: { + ...url.URLSearchParams, + [READ]: { supported: ["10.0.0"] }, + }, + + // module.util + TextDecoder: { + ...util.TextDecoder, + [READ]: { supported: ["11.0.0"] }, + }, + TextEncoder: { + ...util.TextEncoder, + [READ]: { supported: ["11.0.0"] }, + }, + + // module.worker_threads + BroadcastChannel: { + ...worker_threads.BroadcastChannel, + [READ]: { supported: ["18.0.0"] }, + }, + MessageChannel: { + ...worker_threads.MessageChannel, + [READ]: { supported: ["15.0.0"] }, + }, + MessagePort: { + ...worker_threads.MessagePort, + [READ]: { supported: ["15.0.0"] }, + }, +} + +/** @type {import('./types.js').SupportVersionTraceMap} */ +module.exports = nodeGlobals