Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: compatibility with node@22.13.1 types #414

Merged
merged 8 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const envConfig = env(nodeless, {});
- ✅ [node:https](https://nodejs.org/api/https.html)
- ✅ [node:inspector](https://nodejs.org/api/inspector.html)
- 🚧 [node:inspector/promises](https://nodejs.org/api/inspector.html)
- 🚧 [node:module](https://nodejs.org/api/module.html) <!-- missing stripTypeScriptTypes exports -->
- [node:module](https://nodejs.org/api/module.html)
- ✅ [node:net](https://nodejs.org/api/net.html)
- ✅ [node:os](https://nodejs.org/api/os.html)
- ✅ [node:path](https://nodejs.org/api/path.html)
Expand All @@ -127,14 +127,14 @@ const envConfig = env(nodeless, {});
- ✅ [node:stream/promises](https://nodejs.org/api/stream.html)
- ✅ [node:stream/web](https://nodejs.org/api/stream.html)
- ✅ [node:string_decoder](https://nodejs.org/api/string_decoder.html)
- 🚧 [node:sys](https://nodejs.org/api/sys.html) <!-- missing getCallSites, getSystemErrorMessage exports -->
- [node:sys](https://nodejs.org/api/sys.html)
- ✅ [node:timers](https://nodejs.org/api/timers.html)
- ✅ [node:timers/promises](https://nodejs.org/api/timers.html)
- ✅ [node:tls](https://nodejs.org/api/tls.html)
- ✅ [node:trace_events](https://nodejs.org/api/trace_events.html)
- ✅ [node:tty](https://nodejs.org/api/tty.html)
- ✅ [node:url](https://nodejs.org/api/url.html)
- 🚧 [node:util](https://nodejs.org/api/util.html) <!-- missing getCallSites, getSystemErrorMessage exports -->
- [node:util](https://nodejs.org/api/util.html)
- ✅ [node:util/types](https://nodejs.org/api/util.html)
- ✅ [node:v8](https://nodejs.org/api/v8.html)
- ✅ [node:vm](https://nodejs.org/api/vm.html)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"devDependencies": {
"@parcel/watcher": "^2.5.1",
"@types/node": "^22.10.10",
"@types/node": "^22.13.1",
"automd": "^0.3.12",
"changelogen": "^0.5.7",
"consola": "^3.4.0",
Expand All @@ -59,9 +59,9 @@
"prettier": "^3.4.2",
"typescript": "^5.7.3",
"unbuild": "^3.3.1",
"vitest": "^3.0.4",
"vitest": "^3.0.5",
"workerd": "^1.20250204.0",
"wrangler": "^3.107.3"
},
"packageManager": "pnpm@9.15.5"
"packageManager": "pnpm@10.2.0"
}
567 changes: 150 additions & 417 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/runtime/node/assert/strict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ export default Object.assign(ok, {
notEqual,
deepStrictEqual,
deepEqual,
}) satisfies typeof nodeAssert.strict;
}) as typeof nodeAssert.strict; // TODO: utils are strict by default so should be typed as strict!
5 changes: 5 additions & 0 deletions src/runtime/node/internal/net/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export class SocketAddress implements net.SocketAddress {
family: "ipv4" | "ipv6";
port: number;
flowlabel: number;

static parse(_address: string, _port?: number) {
return undefined; // successful
}

constructor(options: net.SocketAddress) {
this.address = options.address;
this.family = options.family;
Expand Down
42 changes: 18 additions & 24 deletions src/runtime/node/internal/perf_hooks/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type perf_hooks from "node:perf_hooks";
import { createNotImplementedError } from "../../../_internal/utils";
import {
_Performance,
_PerformanceEntry,
_PerformanceMark,
_PerformanceMeasure,
_PerformanceObserver,
Expand All @@ -14,6 +13,8 @@ import {
export {
PerformanceResourceTiming,
PerformanceObserverEntryList,
PerformanceEntry,
PerformanceMeasure,
} from "../../../web/performance/index";

const nodeTiming = {
Expand Down Expand Up @@ -108,37 +109,30 @@ export const PerformanceMark: typeof perf_hooks.PerformanceMark = class Performa
}
};

// PerformanceEntry
export const PerformanceEntry: typeof perf_hooks.PerformanceEntry = class PerformanceEntry
extends _PerformanceEntry
implements perf_hooks.PerformanceEntry
{
entryType = "event" as any;
constructor() {
// @ts-ignore
super(...arguments);
}
};

// PerformanceMeasure
export const PerformanceMeasure: typeof perf_hooks.PerformanceMeasure = class PerformanceMeasure
extends _PerformanceMeasure
implements perf_hooks.PerformanceMeasure
{
constructor() {
// @ts-ignore
super(...arguments);
}
};

// PerformanceObserver
export const PerformanceObserver: typeof perf_hooks.PerformanceObserver = class PerformanceObserver
extends _PerformanceObserver
implements perf_hooks.PerformanceObserver
{
static override supportedEntryTypes = [
// Web
"event",
"mark",
"measure",
"resource",
// Node
"dns",
"function",
"gc",
"http",
"http2",
"net",
] as any[] /* sadly types mismatch */;

constructor(callback: perf_hooks.PerformanceObserverCallback) {
super(callback as any);
}

observe(options: any): void {
throw createNotImplementedError("PerformanceObserver.observe");
}
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/node/internal/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const isArgumentsObject = notImplemented<
typeof utilTypes.isArgumentsObject
>("util.types.isArgumentsObject");

export const isBigIntObject = (val: any): val is Date => val instanceof BigInt;
export const isBigIntObject = (val: any): val is bigint =>
val instanceof BigInt;

export const isBooleanObject: typeof utilTypes.isBooleanObject = (
val,
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/node/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ export const wrap: typeof nodeModule.wrap = function (source) {
return `(function (exports, require, module, __filename, __dirname) { ${source}\n});`;
};

export const stripTypeScriptTypes: typeof nodeModule.stripTypeScriptTypes =
notImplemented<typeof nodeModule.stripTypeScriptTypes>(
"module.stripTypeScriptTypes",
);

export const SourceMap = notImplementedClass(
"module.SourceMap",
) as typeof nodeModule.SourceMap;
Expand Down Expand Up @@ -166,6 +171,7 @@ export const Module = {
syncBuiltinESMExports,
wrap,
flushCompileCache,
stripTypeScriptTypes,
} satisfies Omit<typeof nodeModule.Module, "Module" | "prototype"> &
Record<string, any>;

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const _setSimultaneousAccepts = notImplemented(

export const exports: typeof net = {
Socket: Socket,
// @ts-expect-error (missing types?)
// @ts-expect-error (deprecated alias)
Stream: Socket,
Server,
BlockList,
Expand Down
8 changes: 5 additions & 3 deletions src/runtime/node/perf_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ export const createHistogram: typeof perf_hooks.createHistogram = function (

export default {
Performance,
PerformanceEntry,
PerformanceMark,
// @ts-expect-error TODO: resolve type-mismatch between web and node
PerformanceEntry,
// @ts-expect-error TODO: resolve type-mismatch between web and node
PerformanceMeasure,
// @ts-expect-error TODO: resolve type-mismatch between web and node PerformanceObserverEntryList
// @ts-expect-error TODO: resolve type-mismatch between web and node
PerformanceObserverEntryList,
PerformanceObserver,
// @ts-expect-error TODO: resolve type-mismatch between web and node PerformanceObserverEntryList
// @ts-expect-error TODO: resolve type-mismatch between web and node
PerformanceResourceTiming,
constants,
createHistogram,
Expand Down
13 changes: 11 additions & 2 deletions src/runtime/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ export const parseEnv = notImplemented<typeof util.parseEnv>("util.parseEnv");
export const styleText =
notImplemented<typeof util.styleText>("util.styleText");

export const getCallSite =
notImplemented<typeof util.getCallSite>("util.getCallSites");
/** @deprecated */
export const getCallSite = notImplemented("util.getCallSite");

export const getCallSites =
notImplemented<typeof util.getCallSites>("util.getCallSites");

export const getSystemErrorMessage = notImplemented<
typeof util.getSystemErrorMessage
>("util.getSystemErrorMessage");

export default <typeof util>{
_errnoException,
Expand All @@ -70,6 +77,8 @@ export default <typeof util>{
callbackify,
deprecate,
getCallSite,
getCallSites,
getSystemErrorMessage,
getSystemErrorMap,
getSystemErrorName,
inherits,
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/web/performance/_entry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export type _PerformanceEntryType = "mark" | "measure" | "resource" | "event";

// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/supportedEntryTypes_static
export const _supportedEntryTypes = [
export const _supportedEntryTypes: _PerformanceEntryType[] = [
"event", // PerformanceEntry
"mark", // PerformanceMark
"measure", // PerformanceMeasure
"resource", // PerformanceResourceTiming
] as const;
export type _PerformanceEntryType = (typeof _supportedEntryTypes)[number];

// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry
export class _PerformanceEntry implements globalThis.PerformanceEntry {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/web/performance/_observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class _PerformanceObserver implements globalThis.PerformanceObserver {
this._callback = callback;
}

takeRecords(): PerformanceEntryList {
takeRecords() {
return [];
}

Expand Down