mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 05:12:29 +00:00
Update types, partially fix typecheck (#3551)
* Update types * Remove caret
This commit is contained in:
6
packages/bun-types/assert.d.ts
vendored
6
packages/bun-types/assert.d.ts
vendored
@@ -931,7 +931,11 @@ declare module "assert" {
|
||||
* instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
||||
*/
|
||||
// FIXME: assert.doesNotMatch is typed, but not in the browserify polyfill?
|
||||
// function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
|
||||
function doesNotMatch(
|
||||
value: string,
|
||||
regExp: RegExp,
|
||||
message?: string | Error,
|
||||
): void;
|
||||
|
||||
const strict: Omit<
|
||||
typeof assert,
|
||||
|
||||
1
packages/bun-types/ffi.d.ts
vendored
1
packages/bun-types/ffi.d.ts
vendored
@@ -344,6 +344,7 @@ declare module "bun:ffi" {
|
||||
*
|
||||
*/
|
||||
u64_fast = 16,
|
||||
function = 17,
|
||||
}
|
||||
|
||||
type UNTYPED = never;
|
||||
|
||||
213
packages/bun-types/fs.d.ts
vendored
213
packages/bun-types/fs.d.ts
vendored
@@ -3932,100 +3932,141 @@ declare module "fs" {
|
||||
}
|
||||
|
||||
export interface FSWatcher extends EventEmitter {
|
||||
/**
|
||||
* Stop watching for changes on the given `fs.FSWatcher`. Once stopped, the `fs.FSWatcher` object is no longer usable.
|
||||
* @since v0.6.8
|
||||
*/
|
||||
close(): void;
|
||||
|
||||
/**
|
||||
* When called, requests that the Node.js event loop not exit so long as the <fs.FSWatcher> is active. Calling watcher.ref() multiple times will have no effect.
|
||||
*/
|
||||
ref(): void;
|
||||
|
||||
/**
|
||||
* When called, the active <fs.FSWatcher> object will not require the Node.js event loop to remain active. If there is no other activity keeping the event loop running, the process may exit before the <fs.FSWatcher> object's callback is invoked. Calling watcher.unref() multiple times will have no effect.
|
||||
*/
|
||||
unref(): void;
|
||||
|
||||
/**
|
||||
* events.EventEmitter
|
||||
* 1. change
|
||||
* 2. error
|
||||
*/
|
||||
addListener(event: string, listener: (...args: any[]) => void): this;
|
||||
addListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
||||
addListener(event: 'error', listener: (error: Error) => void): this;
|
||||
addListener(event: 'close', listener: () => void): this;
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
||||
on(event: 'error', listener: (error: Error) => void): this;
|
||||
on(event: 'close', listener: () => void): this;
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
||||
once(event: 'error', listener: (error: Error) => void): this;
|
||||
once(event: 'close', listener: () => void): this;
|
||||
prependListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
||||
prependListener(event: 'error', listener: (error: Error) => void): this;
|
||||
prependListener(event: 'close', listener: () => void): this;
|
||||
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependOnceListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
||||
prependOnceListener(event: 'error', listener: (error: Error) => void): this;
|
||||
prependOnceListener(event: 'close', listener: () => void): this;
|
||||
}
|
||||
/**
|
||||
* Watch for changes on `filename`, where `filename` is either a file or a
|
||||
* directory.
|
||||
*
|
||||
* The second argument is optional. If `options` is provided as a string, it
|
||||
* specifies the `encoding`. Otherwise `options` should be passed as an object.
|
||||
*
|
||||
* The listener callback gets two arguments `(eventType, filename)`. `eventType`is either `'rename'` or `'change'`, and `filename` is the name of the file
|
||||
* which triggered the event.
|
||||
*
|
||||
* On most platforms, `'rename'` is emitted whenever a filename appears or
|
||||
* disappears in the directory.
|
||||
*
|
||||
* The listener callback is attached to the `'change'` event fired by `fs.FSWatcher`, but it is not the same thing as the `'change'` value of`eventType`.
|
||||
*
|
||||
* If a `signal` is passed, aborting the corresponding AbortController will close
|
||||
* the returned `fs.FSWatcher`.
|
||||
/**
|
||||
* Stop watching for changes on the given `fs.FSWatcher`. Once stopped, the `fs.FSWatcher` object is no longer usable.
|
||||
* @since v0.6.8
|
||||
* @param listener
|
||||
*/
|
||||
export function watch(
|
||||
filename: PathLike,
|
||||
options:
|
||||
| (WatchOptions & {
|
||||
encoding: 'buffer';
|
||||
})
|
||||
| 'buffer',
|
||||
listener?: WatchListener<Buffer>
|
||||
): FSWatcher;
|
||||
close(): void;
|
||||
|
||||
/**
|
||||
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
||||
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
||||
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
|
||||
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
||||
* If `persistent` is not supplied, the default of `true` is used.
|
||||
* If `recursive` is not supplied, the default of `false` is used.
|
||||
* When called, requests that the Node.js event loop not exit so long as the <fs.FSWatcher> is active. Calling watcher.ref() multiple times will have no effect.
|
||||
*/
|
||||
export function watch(filename: PathLike, options?: WatchOptions | BufferEncoding | null, listener?: WatchListener<string>): FSWatcher;
|
||||
ref(): void;
|
||||
|
||||
/**
|
||||
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
||||
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
||||
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
|
||||
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
||||
* If `persistent` is not supplied, the default of `true` is used.
|
||||
* If `recursive` is not supplied, the default of `false` is used.
|
||||
* When called, the active <fs.FSWatcher> object will not require the Node.js event loop to remain active. If there is no other activity keeping the event loop running, the process may exit before the <fs.FSWatcher> object's callback is invoked. Calling watcher.unref() multiple times will have no effect.
|
||||
*/
|
||||
export function watch(filename: PathLike, options: WatchOptions | string, listener?: WatchListener<string | Buffer>): FSWatcher;
|
||||
unref(): void;
|
||||
|
||||
/**
|
||||
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
||||
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
||||
* events.EventEmitter
|
||||
* 1. change
|
||||
* 2. error
|
||||
*/
|
||||
export function watch(filename: PathLike, listener?: WatchListener<string>): FSWatcher;
|
||||
addListener(event: string, listener: (...args: any[]) => void): this;
|
||||
addListener(
|
||||
event: "change",
|
||||
listener: (eventType: string, filename: string | Buffer) => void,
|
||||
): this;
|
||||
addListener(event: "error", listener: (error: Error) => void): this;
|
||||
addListener(event: "close", listener: () => void): this;
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(
|
||||
event: "change",
|
||||
listener: (eventType: string, filename: string | Buffer) => void,
|
||||
): this;
|
||||
on(event: "error", listener: (error: Error) => void): this;
|
||||
on(event: "close", listener: () => void): this;
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(
|
||||
event: "change",
|
||||
listener: (eventType: string, filename: string | Buffer) => void,
|
||||
): this;
|
||||
once(event: "error", listener: (error: Error) => void): this;
|
||||
once(event: "close", listener: () => void): this;
|
||||
prependListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependListener(
|
||||
event: "change",
|
||||
listener: (eventType: string, filename: string | Buffer) => void,
|
||||
): this;
|
||||
prependListener(event: "error", listener: (error: Error) => void): this;
|
||||
prependListener(event: "close", listener: () => void): this;
|
||||
prependOnceListener(
|
||||
event: string,
|
||||
listener: (...args: any[]) => void,
|
||||
): this;
|
||||
prependOnceListener(
|
||||
event: "change",
|
||||
listener: (eventType: string, filename: string | Buffer) => void,
|
||||
): this;
|
||||
prependOnceListener(event: "error", listener: (error: Error) => void): this;
|
||||
prependOnceListener(event: "close", listener: () => void): this;
|
||||
}
|
||||
|
||||
type WatchOptions = {
|
||||
encoding?: BufferEncoding;
|
||||
persistent?: boolean;
|
||||
recursive?: boolean;
|
||||
signal?: AbortSignal;
|
||||
};
|
||||
type WatchEventType = "rename" | "change" | "error" | "close";
|
||||
type WatchListener<T> = (
|
||||
event: WatchEventType,
|
||||
filename: T | Error | undefined,
|
||||
) => void;
|
||||
/**
|
||||
* Watch for changes on `filename`, where `filename` is either a file or a
|
||||
* directory.
|
||||
*
|
||||
* The second argument is optional. If `options` is provided as a string, it
|
||||
* specifies the `encoding`. Otherwise `options` should be passed as an object.
|
||||
*
|
||||
* The listener callback gets two arguments `(eventType, filename)`. `eventType`is either `'rename'` or `'change'`, and `filename` is the name of the file
|
||||
* which triggered the event.
|
||||
*
|
||||
* On most platforms, `'rename'` is emitted whenever a filename appears or
|
||||
* disappears in the directory.
|
||||
*
|
||||
* The listener callback is attached to the `'change'` event fired by `fs.FSWatcher`, but it is not the same thing as the `'change'` value of`eventType`.
|
||||
*
|
||||
* If a `signal` is passed, aborting the corresponding AbortController will close
|
||||
* the returned `fs.FSWatcher`.
|
||||
* @since v0.6.8
|
||||
* @param listener
|
||||
*/
|
||||
export function watch(
|
||||
filename: PathLike,
|
||||
options:
|
||||
| (WatchOptions & {
|
||||
encoding: "buffer";
|
||||
})
|
||||
| "buffer",
|
||||
listener?: WatchListener<Buffer>,
|
||||
): FSWatcher;
|
||||
/**
|
||||
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
||||
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
||||
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
|
||||
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
||||
* If `persistent` is not supplied, the default of `true` is used.
|
||||
* If `recursive` is not supplied, the default of `false` is used.
|
||||
*/
|
||||
export function watch(
|
||||
filename: PathLike,
|
||||
options?: WatchOptions | BufferEncoding | null,
|
||||
listener?: WatchListener<string>,
|
||||
): FSWatcher;
|
||||
/**
|
||||
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
||||
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
||||
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
|
||||
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
||||
* If `persistent` is not supplied, the default of `true` is used.
|
||||
* If `recursive` is not supplied, the default of `false` is used.
|
||||
*/
|
||||
export function watch(
|
||||
filename: PathLike,
|
||||
options: WatchOptions | string,
|
||||
listener?: WatchListener<string | Buffer>,
|
||||
): FSWatcher;
|
||||
/**
|
||||
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
||||
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
||||
*/
|
||||
export function watch(
|
||||
filename: PathLike,
|
||||
listener?: WatchListener<string>,
|
||||
): FSWatcher;
|
||||
}
|
||||
|
||||
declare module "node:fs" {
|
||||
|
||||
31
packages/bun-types/globals.d.ts
vendored
31
packages/bun-types/globals.d.ts
vendored
@@ -1401,21 +1401,6 @@ declare function clearTimeout(id?: number | Timer): void;
|
||||
declare function clearImmediate(id?: number | Timer): void;
|
||||
// declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
|
||||
// declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
|
||||
/**
|
||||
* Send a HTTP(s) request
|
||||
*
|
||||
* @param url URL string
|
||||
* @param init A structured value that contains settings for the fetch() request.
|
||||
*
|
||||
* @returns A promise that resolves to {@link Response} object.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare function fetch(
|
||||
url: string | URL | Request,
|
||||
init?: FetchRequestInit,
|
||||
): Promise<Response>;
|
||||
|
||||
/**
|
||||
* Send a HTTP(s) request
|
||||
@@ -1429,6 +1414,20 @@ declare function fetch(
|
||||
*/
|
||||
// tslint:disable-next-line:unified-signatures
|
||||
declare function fetch(request: Request, init?: RequestInit): Promise<Response>;
|
||||
/**
|
||||
* Send a HTTP(s) request
|
||||
*
|
||||
* @param url URL string
|
||||
* @param init A structured value that contains settings for the fetch() request.
|
||||
*
|
||||
* @returns A promise that resolves to {@link Response} object.
|
||||
*
|
||||
*
|
||||
*/
|
||||
declare function fetch(
|
||||
url: string | URL | Request,
|
||||
init?: FetchRequestInit,
|
||||
): Promise<Response>;
|
||||
|
||||
declare function queueMicrotask(callback: (...args: any[]) => void): void;
|
||||
/**
|
||||
@@ -1951,7 +1950,7 @@ interface URLSearchParams {
|
||||
): void;
|
||||
/** Returns a string containing a query string suitable for use in a URL. Does not include the question mark. */
|
||||
toString(): string;
|
||||
[Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>;
|
||||
[Symbol.iterator](): IterableIterator<[string, string]>;
|
||||
}
|
||||
|
||||
declare var URLSearchParams: {
|
||||
|
||||
18
packages/bun-types/http.d.ts
vendored
18
packages/bun-types/http.d.ts
vendored
@@ -1785,6 +1785,24 @@ declare module "http" {
|
||||
callback?: (res: IncomingMessage) => void,
|
||||
): ClientRequest;
|
||||
|
||||
/**
|
||||
* Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
|
||||
* Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
|
||||
* @param name Header name
|
||||
* @since v14.3.0
|
||||
*/
|
||||
function validateHeaderName(name: string): void;
|
||||
/**
|
||||
* Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
|
||||
* Passing illegal value as value will result in a TypeError being thrown.
|
||||
* - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
|
||||
* - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
|
||||
* @param name Header name
|
||||
* @param value Header value
|
||||
* @since v14.3.0
|
||||
*/
|
||||
function validateHeaderValue(name: string, value: string): void;
|
||||
|
||||
let globalAgent: Agent;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import { watch } from "node:fs";
|
||||
import * as tsd from "tsd";
|
||||
import * as fs from "fs";
|
||||
import { exists } from "fs/promises";
|
||||
|
||||
tsd.expectType<Promise<boolean>>(exists("/etc/passwd"));
|
||||
tsd.expectType<Promise<boolean>>(fs.promises.exists("/etc/passwd"));
|
||||
|
||||
// file path
|
||||
watch(".", (eventType, filename) => {
|
||||
console.log(`event type = ${eventType}`);
|
||||
if (filename) {
|
||||
console.log(`filename = ${filename}`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ export function readMany(this: ReadableStreamDefaultReader): ReadableStreamDefau
|
||||
var length = values.length;
|
||||
|
||||
if (length > 0) {
|
||||
var outValues = $newArrayWithSize<T>(length);
|
||||
var outValues = $newArrayWithSize(length);
|
||||
if ($isReadableByteStreamController(controller)) {
|
||||
{
|
||||
const buf = values[0];
|
||||
@@ -150,7 +150,7 @@ export function readMany(this: ReadableStreamDefaultReader): ReadableStreamDefau
|
||||
|
||||
var pullResult = controller.$pull(controller);
|
||||
if (pullResult && $isPromise(pullResult)) {
|
||||
return pullResult.$then(onPullMany);
|
||||
return pullResult.$then(onPullMany) as any;
|
||||
}
|
||||
|
||||
return onPullMany(pullResult);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
/*
|
||||
* Copyright (C) 2015 Canon Inc. All rights reserved.
|
||||
* Copyright (C) 2015 Igalia.
|
||||
|
||||
@@ -184,7 +184,7 @@ export function createFIFO() {
|
||||
this._capacityMask = (this._capacityMask << 1) | 1;
|
||||
}
|
||||
|
||||
shrinkArray() {
|
||||
_shrinkArray() {
|
||||
this._list.length >>>= 1;
|
||||
this._capacityMask >>>= 1;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
/*
|
||||
* Copyright (C) 2020 Apple Inc. All rights reserved.
|
||||
*
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
/*
|
||||
* Copyright (C) 2020 Apple Inc. All rights reserved.
|
||||
*
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
/*
|
||||
* Copyright (C) 2020 Apple Inc. All rights reserved.
|
||||
*
|
||||
|
||||
@@ -610,16 +610,17 @@ export function setUpWritableStreamDefaultControllerFromUnderlyingSink(
|
||||
highWaterMark,
|
||||
sizeAlgorithm,
|
||||
) {
|
||||
// @ts-ignore
|
||||
const controller = new $WritableStreamDefaultController();
|
||||
|
||||
let startAlgorithm = () => {};
|
||||
let writeAlgorithm = () => {
|
||||
let startAlgorithm: (...args: any[]) => any = () => {};
|
||||
let writeAlgorithm: (...args: any[]) => any = () => {
|
||||
return Promise.$resolve();
|
||||
};
|
||||
let closeAlgorithm = () => {
|
||||
let closeAlgorithm: (...args: any[]) => any = () => {
|
||||
return Promise.$resolve();
|
||||
};
|
||||
let abortAlgorithm = () => {
|
||||
let abortAlgorithm: (...args: any[]) => any = () => {
|
||||
return Promise.$resolve();
|
||||
};
|
||||
|
||||
|
||||
6
src/js/builtins/builtins.d.ts
vendored
6
src/js/builtins/builtins.d.ts
vendored
@@ -57,6 +57,9 @@ declare function $getPromiseInternalField<K extends PromiseFieldType, V>(
|
||||
promise: Promise<V>,
|
||||
key: K,
|
||||
): PromiseFieldToValue<K, V>;
|
||||
declare function $fulfillPromise(...args: any[]): TODO;
|
||||
declare function $evaluateCommonJSModule(...args: any[]): TODO;
|
||||
declare function $loadCJS2ESM(...args: any[]): TODO;
|
||||
declare function $getGeneratorInternalField(): TODO;
|
||||
declare function $getAsyncGeneratorInternalField(): TODO;
|
||||
declare function $getAbstractModuleRecordInternalField(): TODO;
|
||||
@@ -229,7 +232,7 @@ declare function $createFIFO(): TODO;
|
||||
declare function $createNativeReadableStream(): TODO;
|
||||
declare function $createReadableStream(): TODO;
|
||||
declare function $createUninitializedArrayBuffer(size: number): ArrayBuffer;
|
||||
declare function $createWritableStreamFromInternal(): TODO;
|
||||
declare function $createWritableStreamFromInternal(...args: any[]): TODO;
|
||||
declare function $cwd(): TODO;
|
||||
declare function $data(): TODO;
|
||||
declare function $dataView(): TODO;
|
||||
@@ -330,6 +333,7 @@ declare function $read(): TODO;
|
||||
declare function $readIntoRequests(): TODO;
|
||||
declare function $readRequests(): TODO;
|
||||
declare function $readable(): TODO;
|
||||
declare function $readableByteStreamControllerGetDesiredSize(...args: any): TODO;
|
||||
declare function $readableStreamController(): TODO;
|
||||
declare function $readableStreamToArray(): TODO;
|
||||
declare function $reader(): TODO;
|
||||
|
||||
@@ -239,7 +239,7 @@ ffiWrappers[FFIType.function] = function functionType(val) {
|
||||
};
|
||||
|
||||
function FFIBuilder(params, returnType, functionToCall, name) {
|
||||
const hasReturnType = typeof FFIType[returnType] === "number" && FFIType[returnType] !== FFIType.void;
|
||||
const hasReturnType = typeof FFIType[returnType] === "number" && FFIType[returnType as string] !== FFIType.void;
|
||||
var paramNames = new Array(params.length);
|
||||
var args = new Array(params.length);
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
@@ -255,7 +255,7 @@ function FFIBuilder(params, returnType, functionToCall, name) {
|
||||
|
||||
var code = `functionToCall(${args.join(", ")})`;
|
||||
if (hasReturnType) {
|
||||
if (FFIType[returnType] === FFIType.cstring) {
|
||||
if (FFIType[returnType as string] === FFIType.cstring) {
|
||||
code = `return (${cstringReturnType.toString()})(${code})`;
|
||||
} else {
|
||||
code = `return ${code}`;
|
||||
@@ -328,7 +328,7 @@ export function dlopen(path, options) {
|
||||
|
||||
for (let key in result.symbols) {
|
||||
var symbol = result.symbols[key];
|
||||
if (options[key]?.args?.length || FFIType[options[key]?.returns] === FFIType.cstring) {
|
||||
if (options[key]?.args?.length || FFIType[options[key]?.returns as string] === FFIType.cstring) {
|
||||
result.symbols[key] = FFIBuilder(
|
||||
options[key].args ?? [],
|
||||
options[key].returns ?? FFIType.void,
|
||||
@@ -354,7 +354,7 @@ export function linkSymbols(options) {
|
||||
|
||||
for (let key in result.symbols) {
|
||||
var symbol = result.symbols[key];
|
||||
if (options[key]?.args?.length || FFIType[options[key]?.returns] === FFIType.cstring) {
|
||||
if (options[key]?.args?.length || FFIType[options[key]?.returns as string] === FFIType.cstring) {
|
||||
result.symbols[key] = FFIBuilder(options[key].args ?? [], options[key].returns ?? FFIType.void, symbol, key);
|
||||
} else {
|
||||
// consistentcy
|
||||
|
||||
@@ -13,10 +13,12 @@ function ERR_INVALID_ARG_TYPE(name, type, value) {
|
||||
|
||||
function createTracing(opts) {
|
||||
if (typeof opts !== "object" || opts == null) {
|
||||
// @ts-ignore
|
||||
throw new ERR_INVALID_ARG_TYPE("options", "Object", opts);
|
||||
}
|
||||
|
||||
// TODO: validate categories
|
||||
// @ts-ignore
|
||||
return new Tracing(opts);
|
||||
}
|
||||
|
||||
|
||||
3
src/js/private.d.ts
vendored
3
src/js/private.d.ts
vendored
@@ -7,9 +7,8 @@
|
||||
declare function $bundleError(error: string);
|
||||
|
||||
type BunFSWatchOptions = { encoding?: BufferEncoding; persistent?: boolean; recursive?: boolean; signal?: AbortSignal };
|
||||
|
||||
type BunWatchEventType = "rename" | "change" | "error" | "close";
|
||||
type BunWatchListener<T> = (event: WatchEventType, filename: T | Error | undefined) => void;
|
||||
type BunWatchListener<T> = (event: WatchEventType, filename: T | undefined) => void;
|
||||
|
||||
interface BunFSWatcher {
|
||||
/**
|
||||
|
||||
BIN
test/bun.lockb
BIN
test/bun.lockb
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
import fs from "fs";
|
||||
import fs, { FSWatcher } from "node:fs";
|
||||
import path from "path";
|
||||
import { tempDirWithFiles, bunRun, bunRunAsScript } from "harness";
|
||||
import { pathToFileURL } from "bun";
|
||||
@@ -7,7 +7,7 @@ import { describe, expect, test } from "bun:test";
|
||||
// Because macOS (and possibly other operating systems) can return a watcher
|
||||
// before it is actually watching, we need to repeat the operation to avoid
|
||||
// a race condition.
|
||||
function repeat(fn) {
|
||||
function repeat(fn: any) {
|
||||
const interval = setInterval(fn, 20);
|
||||
return interval;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ describe("fs.watch", () => {
|
||||
// https://github.com/joyent/node/issues/2293 - non-persistent watcher should not block the event loop
|
||||
bunRun(path.join(import.meta.dir, "fixtures", "persistent.js"));
|
||||
done();
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
@@ -39,7 +39,7 @@ describe("fs.watch", () => {
|
||||
try {
|
||||
bunRun(path.join(import.meta.dir, "fixtures", "close.js"));
|
||||
done();
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
@@ -48,7 +48,7 @@ describe("fs.watch", () => {
|
||||
try {
|
||||
bunRun(path.join(import.meta.dir, "fixtures", "unref.js"));
|
||||
done();
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
@@ -57,7 +57,7 @@ describe("fs.watch", () => {
|
||||
try {
|
||||
bunRunAsScript(testDir, path.join(import.meta.dir, "fixtures", "relative.js"));
|
||||
done();
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
@@ -68,7 +68,7 @@ describe("fs.watch", () => {
|
||||
try {
|
||||
fs.mkdirSync(root);
|
||||
} catch {}
|
||||
let err = undefined;
|
||||
let err: Error | undefined = undefined;
|
||||
const watcher = fs.watch(root, { signal: AbortSignal.timeout(3000) });
|
||||
watcher.on("change", (event, filename) => {
|
||||
count++;
|
||||
@@ -78,7 +78,7 @@ describe("fs.watch", () => {
|
||||
if (count >= 2) {
|
||||
watcher.close();
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
err = e;
|
||||
watcher.close();
|
||||
}
|
||||
@@ -106,9 +106,9 @@ describe("fs.watch", () => {
|
||||
const subfolder = path.join(root, "subfolder");
|
||||
fs.mkdirSync(subfolder);
|
||||
const watcher = fs.watch(root, { recursive: true, signal: AbortSignal.timeout(3000) });
|
||||
let err = undefined;
|
||||
let err: Error | undefined = undefined;
|
||||
watcher.on("change", (event, filename) => {
|
||||
const basename = path.basename(filename);
|
||||
const basename = path.basename(filename as string);
|
||||
|
||||
if (basename === "subfolder") return;
|
||||
count++;
|
||||
@@ -118,7 +118,7 @@ describe("fs.watch", () => {
|
||||
if (count >= 2) {
|
||||
watcher.close();
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
err = e;
|
||||
watcher.close();
|
||||
}
|
||||
@@ -141,12 +141,12 @@ describe("fs.watch", () => {
|
||||
"deleted.txt": "hello",
|
||||
});
|
||||
const filepath = path.join(testsubdir, "deleted.txt");
|
||||
let err = undefined;
|
||||
let err: Error | undefined = undefined;
|
||||
const watcher = fs.watch(testsubdir, function (event, filename) {
|
||||
try {
|
||||
expect(event).toBe("rename");
|
||||
expect(filename).toBe("deleted.txt");
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
err = e;
|
||||
} finally {
|
||||
clearInterval(interval);
|
||||
@@ -169,12 +169,12 @@ describe("fs.watch", () => {
|
||||
const filepath = path.join(testDir, "watch.txt");
|
||||
|
||||
const watcher = fs.watch(filepath);
|
||||
let err = undefined;
|
||||
let err: Error | undefined = undefined;
|
||||
watcher.on("change", function (event, filename) {
|
||||
try {
|
||||
expect(event).toBe("change");
|
||||
expect(filename).toBe("watch.txt");
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
err = e;
|
||||
} finally {
|
||||
clearInterval(interval);
|
||||
@@ -195,7 +195,7 @@ describe("fs.watch", () => {
|
||||
try {
|
||||
fs.watch(path.join(testDir, "404.txt"));
|
||||
done(new Error("should not reach here"));
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
expect(err).toBeInstanceOf(Error);
|
||||
expect(err.code).toBe("ENOENT");
|
||||
expect(err.syscall).toBe("watch");
|
||||
@@ -203,13 +203,13 @@ describe("fs.watch", () => {
|
||||
}
|
||||
});
|
||||
|
||||
const encodings = ["utf8", "buffer", "hex", "ascii", "base64", "utf16le", "ucs2", "latin1", "binary"];
|
||||
const encodings = ["utf8", "buffer", "hex", "ascii", "base64", "utf16le", "ucs2", "latin1", "binary"] as const;
|
||||
|
||||
test(`should work with encodings ${encodings.join(", ")}`, async () => {
|
||||
const watchers = [];
|
||||
const watchers: FSWatcher[] = [];
|
||||
const filepath = path.join(testDir, encodingFileName);
|
||||
|
||||
const promises = [];
|
||||
const promises: Promise<any>[] = [];
|
||||
encodings.forEach(name => {
|
||||
const encoded_filename =
|
||||
name !== "buffer" ? Buffer.from(encodingFileName, "utf8").toString(name) : Buffer.from(encodingFileName);
|
||||
@@ -225,11 +225,11 @@ describe("fs.watch", () => {
|
||||
expect(filename).toBe(encoded_filename);
|
||||
} else {
|
||||
expect(filename).toBeInstanceOf(Buffer);
|
||||
expect(filename.toString("utf8")).toBe(encodingFileName);
|
||||
expect((filename as any as Buffer)!.toString("utf8")).toBe(encodingFileName);
|
||||
}
|
||||
|
||||
resolve();
|
||||
} catch (e) {
|
||||
resolve(undefined);
|
||||
} catch (e: any) {
|
||||
reject(e);
|
||||
}
|
||||
}),
|
||||
@@ -254,12 +254,12 @@ describe("fs.watch", () => {
|
||||
const filepath = path.join(testDir, "url.txt");
|
||||
try {
|
||||
const watcher = fs.watch(pathToFileURL(filepath));
|
||||
let err = undefined;
|
||||
let err: Error | undefined = undefined;
|
||||
watcher.on("change", function (event, filename) {
|
||||
try {
|
||||
expect(event).toBe("change");
|
||||
expect(filename).toBe("url.txt");
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
err = e;
|
||||
} finally {
|
||||
clearInterval(interval);
|
||||
@@ -274,7 +274,7 @@ describe("fs.watch", () => {
|
||||
const interval = repeat(() => {
|
||||
fs.writeFileSync(filepath, "world");
|
||||
});
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
@@ -288,12 +288,12 @@ describe("fs.watch", () => {
|
||||
try {
|
||||
watcher.close();
|
||||
done();
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
done("Should not error when calling close from error event");
|
||||
}
|
||||
});
|
||||
ac.abort();
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
@@ -308,13 +308,13 @@ describe("fs.watch", () => {
|
||||
try {
|
||||
watcher.close();
|
||||
done();
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
done("Should not error when calling close from close event");
|
||||
}
|
||||
});
|
||||
|
||||
ac.abort();
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
@@ -325,7 +325,7 @@ describe("fs.watch", () => {
|
||||
const ac = new AbortController();
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const watcher = fs.watch(filepath, { signal: ac.signal });
|
||||
watcher.once("error", err => (err.message === "The operation was aborted." ? resolve() : reject(err)));
|
||||
watcher.once("error", err => (err.message === "The operation was aborted." ? resolve(undefined) : reject(err)));
|
||||
watcher.once("close", () => reject());
|
||||
});
|
||||
await Bun.sleep(10);
|
||||
@@ -339,7 +339,7 @@ describe("fs.watch", () => {
|
||||
const signal = AbortSignal.abort();
|
||||
await new Promise((resolve, reject) => {
|
||||
const watcher = fs.watch(filepath, { signal });
|
||||
watcher.once("error", err => (err.message === "The operation was aborted." ? resolve() : reject(err)));
|
||||
watcher.once("error", err => (err.message === "The operation was aborted." ? resolve(undefined) : reject(err)));
|
||||
watcher.once("close", () => reject());
|
||||
});
|
||||
});
|
||||
@@ -353,13 +353,13 @@ describe("fs.watch", () => {
|
||||
});
|
||||
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
let timeout = null;
|
||||
let timeout: any = null;
|
||||
const watcher = fs.watch(filepath, event => {
|
||||
clearTimeout(timeout);
|
||||
clearInterval(interval);
|
||||
try {
|
||||
resolve(event);
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
reject(e);
|
||||
} finally {
|
||||
watcher.close();
|
||||
@@ -383,7 +383,7 @@ describe("fs.promises.watch", () => {
|
||||
fs.mkdirSync(root);
|
||||
} catch {}
|
||||
let success = false;
|
||||
let err = undefined;
|
||||
let err: Error | undefined = undefined;
|
||||
try {
|
||||
const ac = new AbortController();
|
||||
const watcher = fs.promises.watch(root, { signal: ac.signal });
|
||||
@@ -405,13 +405,13 @@ describe("fs.promises.watch", () => {
|
||||
clearInterval(interval);
|
||||
ac.abort();
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
err = e;
|
||||
clearInterval(interval);
|
||||
ac.abort();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
if (!success) {
|
||||
throw err || e;
|
||||
}
|
||||
@@ -427,7 +427,7 @@ describe("fs.promises.watch", () => {
|
||||
const subfolder = path.join(root, "subfolder");
|
||||
fs.mkdirSync(subfolder);
|
||||
let success = false;
|
||||
let err = undefined;
|
||||
let err: Error | undefined = undefined;
|
||||
|
||||
try {
|
||||
const ac = new AbortController();
|
||||
@@ -439,7 +439,7 @@ describe("fs.promises.watch", () => {
|
||||
fs.rmdirSync(path.join(subfolder, "new-folder.txt"));
|
||||
});
|
||||
for await (const event of watcher) {
|
||||
const basename = path.basename(event.filename);
|
||||
const basename = path.basename(event.filename!);
|
||||
if (basename === "subfolder") continue;
|
||||
|
||||
count++;
|
||||
@@ -452,13 +452,13 @@ describe("fs.promises.watch", () => {
|
||||
clearInterval(interval);
|
||||
ac.abort();
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
err = e;
|
||||
clearInterval(interval);
|
||||
ac.abort();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
if (!success) {
|
||||
throw err || e;
|
||||
}
|
||||
@@ -474,7 +474,7 @@ describe("fs.promises.watch", () => {
|
||||
const promise = (async () => {
|
||||
try {
|
||||
for await (const _ of watcher);
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
expect(e.message).toBe("The operation was aborted.");
|
||||
}
|
||||
})();
|
||||
@@ -491,7 +491,7 @@ describe("fs.promises.watch", () => {
|
||||
await (async () => {
|
||||
try {
|
||||
for await (const _ of watcher);
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
expect(e.message).toBe("The operation was aborted.");
|
||||
}
|
||||
})();
|
||||
@@ -511,7 +511,7 @@ describe("fs.promises.watch", () => {
|
||||
for await (const event of watcher) {
|
||||
return event.eventType;
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
expect("unreacheable").toBe(false);
|
||||
} finally {
|
||||
clearInterval(interval);
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
import type { Server } from "socket.io";
|
||||
import request from "supertest";
|
||||
|
||||
|
||||
@@ -301,17 +301,18 @@ describe("FormData", () => {
|
||||
expect(await (body.get("foo") as Blob).text()).toBe("baz");
|
||||
server.stop(true);
|
||||
});
|
||||
|
||||
type FetchReqArgs = [request: Request, init?: RequestInit];
|
||||
type FetchURLArgs = [url: string | URL | Request, init?: FetchRequestInit];
|
||||
for (let useRequestConstructor of [true, false]) {
|
||||
describe(useRequestConstructor ? "Request constructor" : "fetch()", () => {
|
||||
function send(args: Parameters<typeof fetch>) {
|
||||
function send(args: FetchReqArgs | FetchURLArgs) {
|
||||
if (useRequestConstructor) {
|
||||
return fetch(new Request(...args));
|
||||
return fetch(new Request(...(args as FetchReqArgs)));
|
||||
} else {
|
||||
return fetch(...args);
|
||||
return fetch(...(args as FetchURLArgs));
|
||||
}
|
||||
}
|
||||
for (let headers of [{}, undefined, { headers: { X: "Y" } }]) {
|
||||
for (let headers of [{} as {}, undefined, { headers: { X: "Y" } }]) {
|
||||
describe("headers: " + Bun.inspect(headers).replaceAll(/([\n ])/gim, ""), () => {
|
||||
it("send on HTTP server with FormData & Blob (roundtrip)", async () => {
|
||||
let contentType = "";
|
||||
@@ -330,11 +331,10 @@ describe("FormData", () => {
|
||||
form.append("bar", "baz");
|
||||
|
||||
// @ts-ignore
|
||||
const reqBody = [
|
||||
const reqBody: FetchURLArgs = [
|
||||
`http://${server.hostname}:${server.port}`,
|
||||
{
|
||||
body: form,
|
||||
|
||||
headers,
|
||||
method: "POST",
|
||||
},
|
||||
@@ -364,7 +364,6 @@ describe("FormData", () => {
|
||||
form.append("foo", file);
|
||||
form.append("bar", "baz");
|
||||
|
||||
// @ts-ignore
|
||||
const reqBody = [
|
||||
`http://${server.hostname}:${server.port}`,
|
||||
{
|
||||
@@ -374,7 +373,7 @@ describe("FormData", () => {
|
||||
method: "POST",
|
||||
},
|
||||
];
|
||||
const res = await send(reqBody);
|
||||
const res = await send(reqBody as FetchURLArgs);
|
||||
const body = await res.formData();
|
||||
expect(await (body.get("foo") as Blob).text()).toBe(text);
|
||||
expect(contentType).toContain("multipart/form-data");
|
||||
@@ -410,7 +409,7 @@ describe("FormData", () => {
|
||||
method: "POST",
|
||||
},
|
||||
];
|
||||
const res = await send(reqBody);
|
||||
const res = await send(reqBody as FetchURLArgs);
|
||||
const body = await res.formData();
|
||||
expect(contentType).toContain("multipart/form-data");
|
||||
expect(body.get("foo")).toBe("boop");
|
||||
|
||||
@@ -7,15 +7,20 @@ describe("URLSearchParams", () => {
|
||||
params.append("foo", "bar");
|
||||
params.append("foo", "boop");
|
||||
params.append("bar", "baz");
|
||||
// @ts-ignore
|
||||
expect(params.length).toBe(3);
|
||||
params.delete("foo");
|
||||
// @ts-ignore
|
||||
expect(params.length).toBe(1);
|
||||
params.append("foo", "bar");
|
||||
// @ts-ignore
|
||||
expect(params.length).toBe(2);
|
||||
params.delete("foo");
|
||||
params.delete("foo");
|
||||
// @ts-ignore
|
||||
expect(params.length).toBe(1);
|
||||
params.delete("bar");
|
||||
// @ts-ignore
|
||||
expect(params.length).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"@swc/core": "1.3.38",
|
||||
"@types/react": "18.0.28",
|
||||
"@types/react-dom": "18.0.11",
|
||||
"@types/supertest": "2.0.12",
|
||||
"bktree-fast": "0.0.7",
|
||||
"body-parser": "1.20.2",
|
||||
"dedent": "0.7.0",
|
||||
@@ -17,6 +18,9 @@
|
||||
"jest-extended": "4.0.0",
|
||||
"lodash": "4.17.21",
|
||||
"nodemailer": "6.9.3",
|
||||
"pg": "8.11.1",
|
||||
"pg-connection-string": "2.6.1",
|
||||
"postgres": "3.3.5",
|
||||
"prisma": "4.15.0",
|
||||
"socket.io": "4.7.1",
|
||||
"socket.io-client": "4.7.1",
|
||||
@@ -26,10 +30,7 @@
|
||||
"undici": "5.20.0",
|
||||
"vitest": "0.32.2",
|
||||
"webpack": "5.88.0",
|
||||
"webpack-cli": "4.7.2",
|
||||
"pg": "8.11.1",
|
||||
"postgres": "3.3.5",
|
||||
"pg-connection-string": "2.6.1"
|
||||
"webpack-cli": "4.7.2"
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
{
|
||||
"include": [
|
||||
".",
|
||||
"../packages/bun-types/index.d.ts"
|
||||
],
|
||||
"include": [".", "../packages/bun-types/index.d.ts"],
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"lib": [
|
||||
"ESNext"
|
||||
],
|
||||
"lib": ["ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
@@ -23,25 +18,14 @@
|
||||
"resolveJsonModule": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"harness": [
|
||||
"harness.ts"
|
||||
],
|
||||
"mkfifo": [
|
||||
"mkfifo.ts"
|
||||
],
|
||||
"node-harness": [
|
||||
"js/node/harness.ts"
|
||||
],
|
||||
"deno:harness": [
|
||||
"js/deno/harness.ts"
|
||||
],
|
||||
"foo/bar": [
|
||||
"js/bun/resolve/baz.js"
|
||||
],
|
||||
"@faasjs/*": [
|
||||
"js/bun/resolve/*.js"
|
||||
]
|
||||
"harness": ["harness.ts"],
|
||||
"mkfifo": ["mkfifo.ts"],
|
||||
"node-harness": ["js/node/harness.ts"],
|
||||
"deno:harness": ["js/deno/harness.ts"],
|
||||
"foo/bar": ["js/bun/resolve/baz.js"],
|
||||
"@faasjs/*": ["js/bun/resolve/*.js"]
|
||||
}
|
||||
},
|
||||
|
||||
"exclude": ["bundler/fixtures", "snapshots", "js/deno"]
|
||||
}
|
||||
|
||||
@@ -6,12 +6,10 @@
|
||||
// "skipLibCheck": true,
|
||||
"allowJs": true
|
||||
},
|
||||
"include": [
|
||||
".",
|
||||
"packages/bun-types/index.d.ts"
|
||||
],
|
||||
"include": [".", "packages/bun-types/index.d.ts"],
|
||||
"exclude": [
|
||||
"src/test",
|
||||
// "src/js/builtins",
|
||||
"packages",
|
||||
"bench",
|
||||
"examples/*/*",
|
||||
@@ -21,5 +19,6 @@
|
||||
"src/bun.js/WebKit",
|
||||
"src/api/demo",
|
||||
"node_modules"
|
||||
]
|
||||
],
|
||||
"files": ["src/js/builtins/builtins.d.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user