WIP: bootstrap and partial real Solana watcher implementation

This commit is contained in:
2026-08-16 09:17:45 +00:00
commit dc23412c3f
7232 changed files with 1687637 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
'use strict'
const { test } = require('node:test')
const assert = require('node:assert')
const { join } = require('path')
const { MessageChannel } = require('worker_threads')
const { once } = require('events')
const ThreadStream = require('..')
const isYarnPnp = process.versions.pnp !== undefined
test('yarn module resolution', { skip: !isYarnPnp }, (t, done) => {
const modulePath = require.resolve('pino-elasticsearch')
assert.match(modulePath, /.*\.zip.*/)
const stream = new ThreadStream({
filename: modulePath,
workerData: { node: null },
sync: true
})
assert.deepStrictEqual(stream.writableErrored, null)
stream.on('error', (err) => {
assert.deepStrictEqual(stream.writableErrored, err)
})
assert.ok(stream.write('hello world\n'))
assert.ok(stream.writable)
stream.end()
done()
})
test('yarn module resolution for directories with special characters', { skip: !isYarnPnp }, async t => {
const { port1, port2 } = new MessageChannel()
const stream = new ThreadStream({
filename: join(__dirname, 'dir with spaces', 'test-package.zip', 'worker.js'),
workerData: { port: port1 },
workerOpts: {
transferList: [port1]
},
sync: false
})
t.after(() => {
stream.end()
})
assert.ok(stream.write('hello world\n'))
assert.ok(stream.write('something else\n'))
const [strings] = await once(port2, 'message')
assert.strictEqual(strings, 'hello world\nsomething else\n')
})
test('yarn module resolution for typescript commonjs modules', { skip: !isYarnPnp }, async t => {
const { port1, port2 } = new MessageChannel()
const stream = new ThreadStream({
filename: join(__dirname, 'ts-commonjs-default-export.zip', 'worker.js'),
workerData: { port: port1 },
workerOpts: {
transferList: [port1]
},
sync: false
})
t.after(() => {
stream.end()
})
assert.ok(stream.write('hello world\n'))
assert.ok(stream.write('something else\n'))
const [strings] = await once(port2, 'message')
assert.strictEqual(strings, 'hello world\nsomething else\n')
})

View File

@@ -0,0 +1,22 @@
/**
* @fileoverview Code path related utilities.
*/
"use strict";
/**
* Checks all segments in a set and returns true if any are reachable.
* @param {Set<CodePathSegment>} segments The segments to check.
* @returns {boolean} `true` if any segment is reachable; `false` otherwise.
*/
function isAnySegmentReachable(segments) {
for (const segment of segments) {
if (segment.reachable) {
return true;
}
}
return false;
}
module.exports = { isAnySegmentReachable };

View File

@@ -0,0 +1,25 @@
"use strict";
var _define_property = require("./_define_property.cjs");
function _object_spread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(
Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
})
);
}
ownKeys.forEach(function(key) {
_define_property._(target, key, source[key]);
});
}
return target;
}
exports._ = _object_spread;

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env node
console.error(
'`pino` cli has been removed. Use `pino-pretty` cli instead.\n' +
'\nSee: https://github.com/pinojs/pino-pretty'
)
process.exit(1)

View File

@@ -0,0 +1,149 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const util = __importStar(require("../core/util.cjs"));
const error = () => {
const Sizable = {
string: { unit: "znakova", verb: "imati" },
file: { unit: "bajtova", verb: "imati" },
array: { unit: "stavki", verb: "imati" },
set: { unit: "stavki", verb: "imati" },
};
function getSizing(origin) {
return Sizable[origin] ?? null;
}
const FormatDictionary = {
regex: "unos",
email: "email adresa",
url: "URL",
emoji: "emoji",
uuid: "UUID",
uuidv4: "UUIDv4",
uuidv6: "UUIDv6",
nanoid: "nanoid",
guid: "GUID",
cuid: "cuid",
cuid2: "cuid2",
ulid: "ULID",
xid: "XID",
ksuid: "KSUID",
datetime: "ISO datum i vrijeme",
date: "ISO datum",
time: "ISO vrijeme",
duration: "ISO trajanje",
ipv4: "IPv4 adresa",
ipv6: "IPv6 adresa",
cidrv4: "IPv4 raspon",
cidrv6: "IPv6 raspon",
base64: "base64 kodirani tekst",
base64url: "base64url kodirani tekst",
json_string: "JSON tekst",
e164: "E.164 broj",
jwt: "JWT",
template_literal: "unos",
};
const TypeDictionary = {
nan: "NaN",
string: "tekst",
number: "broj",
boolean: "boolean",
array: "niz",
object: "objekt",
set: "skup",
file: "datoteka",
date: "datum",
bigint: "bigint",
symbol: "simbol",
undefined: "undefined",
null: "null",
function: "funkcija",
map: "mapa",
};
return (issue) => {
switch (issue.code) {
case "invalid_type": {
const expected = TypeDictionary[issue.expected] ?? issue.expected;
const receivedType = util.parsedType(issue.input);
const received = TypeDictionary[receivedType] ?? receivedType;
if (/^[A-Z]/.test(issue.expected)) {
return `Neispravan unos: očekuje se instanceof ${issue.expected}, a primljeno je ${received}`;
}
return `Neispravan unos: očekuje se ${expected}, a primljeno je ${received}`;
}
case "invalid_value":
if (issue.values.length === 1)
return `Neispravna vrijednost: očekivano ${util.stringifyPrimitive(issue.values[0])}`;
return `Neispravna opcija: očekivano jedno od ${util.joinValues(issue.values, "|")}`;
case "too_big": {
const adj = issue.inclusive ? "<=" : "<";
const sizing = getSizing(issue.origin);
const origin = TypeDictionary[issue.origin] ?? issue.origin;
if (sizing)
return `Preveliko: očekivano da ${origin ?? "vrijednost"} ima ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elemenata"}`;
return `Preveliko: očekivano da ${origin ?? "vrijednost"} bude ${adj}${issue.maximum.toString()}`;
}
case "too_small": {
const adj = issue.inclusive ? ">=" : ">";
const sizing = getSizing(issue.origin);
const origin = TypeDictionary[issue.origin] ?? issue.origin;
if (sizing) {
return `Premalo: očekivano da ${origin} ima ${adj}${issue.minimum.toString()} ${sizing.unit}`;
}
return `Premalo: očekivano da ${origin} bude ${adj}${issue.minimum.toString()}`;
}
case "invalid_format": {
const _issue = issue;
if (_issue.format === "starts_with")
return `Neispravan tekst: mora započinjati s "${_issue.prefix}"`;
if (_issue.format === "ends_with")
return `Neispravan tekst: mora završavati s "${_issue.suffix}"`;
if (_issue.format === "includes")
return `Neispravan tekst: mora sadržavati "${_issue.includes}"`;
if (_issue.format === "regex")
return `Neispravan tekst: mora odgovarati uzorku ${_issue.pattern}`;
return `Neispravna ${FormatDictionary[_issue.format] ?? issue.format}`;
}
case "not_multiple_of":
return `Neispravan broj: mora biti višekratnik od ${issue.divisor}`;
case "unrecognized_keys":
return `Neprepoznat${issue.keys.length > 1 ? "i ključevi" : " ključ"}: ${util.joinValues(issue.keys, ", ")}`;
case "invalid_key":
return `Neispravan ključ u ${TypeDictionary[issue.origin] ?? issue.origin}`;
case "invalid_union":
return "Neispravan unos";
case "invalid_element":
return `Neispravna vrijednost u ${TypeDictionary[issue.origin] ?? issue.origin}`;
default:
return `Neispravan unos`;
}
};
};
function default_1() {
return {
localeError: error(),
};
}
module.exports = exports.default;

View File

@@ -0,0 +1,200 @@
declare module 'util' {
interface InspectOptions extends NodeJS.InspectOptions { }
function format(format?: any, ...param: any[]): string;
function formatWithOptions(inspectOptions: InspectOptions, format?: any, ...param: any[]): string;
/** @deprecated since v0.11.3 - use a third party module instead. */
function log(string: string): void;
function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
function inspect(object: any, options: InspectOptions): string;
namespace inspect {
const custom: unique symbol;
let colors: {
[color: string]: [number, number] | undefined
};
let styles: {
[style: string]: string | undefined
};
let defaultOptions: InspectOptions;
/**
* Allows changing inspect settings from the repl.
*/
let replDefaults: InspectOptions;
}
/** @deprecated since v4.0.0 - use `Array.isArray()` instead. */
function isArray(object: any): object is any[];
/** @deprecated since v4.0.0 - use `util.types.isRegExp()` instead. */
function isRegExp(object: any): object is RegExp;
/** @deprecated since v4.0.0 - use `util.types.isDate()` instead. */
function isDate(object: any): object is Date;
/** @deprecated since v4.0.0 - use `util.types.isNativeError()` instead. */
function isError(object: any): object is Error;
function inherits(constructor: any, superConstructor: any): void;
function debuglog(key: string): (msg: string, ...param: any[]) => void;
/** @deprecated since v4.0.0 - use `typeof value === 'boolean'` instead. */
function isBoolean(object: any): object is boolean;
/** @deprecated since v4.0.0 - use `Buffer.isBuffer()` instead. */
function isBuffer(object: any): object is Buffer;
/** @deprecated since v4.0.0 - use `typeof value === 'function'` instead. */
function isFunction(object: any): boolean;
/** @deprecated since v4.0.0 - use `value === null` instead. */
function isNull(object: any): object is null;
/** @deprecated since v4.0.0 - use `value === null || value === undefined` instead. */
function isNullOrUndefined(object: any): object is null | undefined;
/** @deprecated since v4.0.0 - use `typeof value === 'number'` instead. */
function isNumber(object: any): object is number;
/** @deprecated since v4.0.0 - use `value !== null && typeof value === 'object'` instead. */
function isObject(object: any): boolean;
/** @deprecated since v4.0.0 - use `(typeof value !== 'object' && typeof value !== 'function') || value === null` instead. */
function isPrimitive(object: any): boolean;
/** @deprecated since v4.0.0 - use `typeof value === 'string'` instead. */
function isString(object: any): object is string;
/** @deprecated since v4.0.0 - use `typeof value === 'symbol'` instead. */
function isSymbol(object: any): object is symbol;
/** @deprecated since v4.0.0 - use `value === undefined` instead. */
function isUndefined(object: any): object is undefined;
function deprecate<T extends Function>(fn: T, message: string, code?: string): T;
function isDeepStrictEqual(val1: any, val2: any): boolean;
interface CustomPromisify<TCustom extends Function> extends Function {
__promisify__: TCustom;
}
function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
function callbackify<TResult>(fn: () => Promise<TResult>): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
function callbackify<T1>(fn: (arg1: T1) => Promise<void>): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
function callbackify<T1, TResult>(fn: (arg1: T1) => Promise<TResult>): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
function callbackify<T1, T2>(fn: (arg1: T1, arg2: T2) => Promise<void>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
function callbackify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2) => Promise<TResult>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
function callbackify<T1, T2, T3>(fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<void>): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException) => void) => void;
function callbackify<T1, T2, T3, TResult>(
fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
function callbackify<T1, T2, T3, T4>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException) => void) => void;
function callbackify<T1, T2, T3, T4, TResult>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
function callbackify<T1, T2, T3, T4, T5>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException) => void) => void;
function callbackify<T1, T2, T3, T4, T5, TResult>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>,
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
function callbackify<T1, T2, T3, T4, T5, T6>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>,
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException) => void) => void;
function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
function promisify<TResult>(fn: (callback: (err: any, result: TResult) => void) => void): () => Promise<TResult>;
function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
function promisify<T1, T2, T3, TResult>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void):
(arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
function promisify<T1, T2, T3>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2, arg3: T3) => Promise<void>;
function promisify<T1, T2, T3, T4, TResult>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void,
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
function promisify<T1, T2, T3, T4>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void):
(arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
function promisify<T1, T2, T3, T4, T5, TResult>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void,
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
function promisify<T1, T2, T3, T4, T5>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void,
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
function promisify(fn: Function): Function;
namespace promisify {
const custom: unique symbol;
}
namespace types {
function isAnyArrayBuffer(object: any): object is ArrayBufferLike;
function isArgumentsObject(object: any): object is IArguments;
function isArrayBuffer(object: any): object is ArrayBuffer;
function isArrayBufferView(object: any): object is NodeJS.ArrayBufferView;
function isAsyncFunction(object: any): boolean;
function isBigInt64Array(value: any): value is BigInt64Array;
function isBigUint64Array(value: any): value is BigUint64Array;
function isBooleanObject(object: any): object is Boolean;
function isBoxedPrimitive(object: any): object is String | Number | BigInt | Boolean | Symbol;
function isDataView(object: any): object is DataView;
function isDate(object: any): object is Date;
function isExternal(object: any): boolean;
function isFloat32Array(object: any): object is Float32Array;
function isFloat64Array(object: any): object is Float64Array;
function isGeneratorFunction(object: any): object is GeneratorFunction;
function isGeneratorObject(object: any): object is Generator;
function isInt8Array(object: any): object is Int8Array;
function isInt16Array(object: any): object is Int16Array;
function isInt32Array(object: any): object is Int32Array;
function isMap<T>(
object: T | {},
): object is T extends ReadonlyMap<any, any>
? unknown extends T
? never
: ReadonlyMap<any, any>
: Map<any, any>;
function isMapIterator(object: any): boolean;
function isModuleNamespaceObject(value: any): boolean;
function isNativeError(object: any): object is Error;
function isNumberObject(object: any): object is Number;
function isPromise(object: any): object is Promise<any>;
function isProxy(object: any): boolean;
function isRegExp(object: any): object is RegExp;
function isSet<T>(
object: T | {},
): object is T extends ReadonlySet<any>
? unknown extends T
? never
: ReadonlySet<any>
: Set<any>;
function isSetIterator(object: any): boolean;
function isSharedArrayBuffer(object: any): object is SharedArrayBuffer;
function isStringObject(object: any): object is String;
function isSymbolObject(object: any): object is Symbol;
function isTypedArray(object: any): object is NodeJS.TypedArray;
function isUint8Array(object: any): object is Uint8Array;
function isUint8ClampedArray(object: any): object is Uint8ClampedArray;
function isUint16Array(object: any): object is Uint16Array;
function isUint32Array(object: any): object is Uint32Array;
function isWeakMap(object: any): object is WeakMap<any, any>;
function isWeakSet(object: any): object is WeakSet<any>;
/** @deprecated Removed in v14.0.0 */
function isWebAssemblyCompiledModule(object: any): boolean;
}
class TextDecoder {
readonly encoding: string;
readonly fatal: boolean;
readonly ignoreBOM: boolean;
constructor(
encoding?: string,
options?: { fatal?: boolean | undefined; ignoreBOM?: boolean | undefined }
);
decode(
input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
options?: { stream?: boolean | undefined }
): string;
}
interface EncodeIntoResult {
/**
* The read Unicode code units of input.
*/
read: number;
/**
* The written UTF-8 bytes of output.
*/
written: number;
}
class TextEncoder {
readonly encoding: string;
encode(input?: string): Uint8Array;
encodeInto(input: string, output: Uint8Array): EncodeIntoResult;
}
}

View File

@@ -0,0 +1,34 @@
This library is available under the terms of the modified BSD license. No external contributions
are allowed under licenses which are fundamentally incompatible with the BSD license that this library is distributed under.
The text of the BSD license is reproduced below.
-------------------------------------------------------------------------------
The "New" BSD License:
**********************
Copyright (c) 2005-2024, Eugene Lazutkin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Eugene Lazutkin nor the names of other contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,186 @@
'use strict'
const test = require('node:test')
const assert = require('node:assert')
const os = require('node:os')
const { promises: { readFile }, createWriteStream } = require('node:fs')
const { join } = require('node:path')
const { fork } = require('node:child_process')
const writer = require('flush-write-stream')
const {
once,
getPathToNull,
file,
watchFileCreated
} = require('./helper')
const { promisify } = require('node:util')
const tspl = require('@matteo.collina/tspl')
const sleep = promisify(setTimeout)
test('asynchronous logging', async (t) => {
const now = Date.now
const hostname = os.hostname
const proc = process
global.process = {
__proto__: process,
pid: 123456
}
Date.now = () => 1459875739796
os.hostname = () => 'abcdefghijklmnopqr'
delete require.cache[require.resolve('../')]
const pino = require('../')
let expected = ''
let actual = ''
const normal = pino(writer((s, enc, cb) => {
expected += s
cb()
}))
const dest = createWriteStream(getPathToNull())
dest.write = (s) => {
actual += s
}
const asyncLogger = pino(dest)
let i = 44
while (i--) {
normal.info('h')
asyncLogger.info('h')
}
const expected2 = expected.split('\n')[0]
let actual2 = ''
const child = fork(join(__dirname, '/fixtures/syncfalse.js'), { silent: true })
child.stdout.pipe(writer((s, enc, cb) => {
actual2 += s
cb()
}))
await once(child, 'close')
// Wait for the last write to be flushed
await sleep(100)
assert.equal(actual, expected)
assert.equal(actual2.trim(), expected2)
t.after(() => {
os.hostname = hostname
Date.now = now
global.process = proc
})
})
test('sync false with child', async (t) => {
const now = Date.now
const hostname = os.hostname
const proc = process
global.process = {
__proto__: process,
pid: 123456
}
Date.now = function () {
return 1459875739796
}
os.hostname = function () {
return 'abcdefghijklmnopqr'
}
delete require.cache[require.resolve('../')]
const pino = require('../')
let expected = ''
let actual = ''
const normal = pino(writer((s, enc, cb) => {
expected += s
cb()
})).child({ hello: 'world' })
const dest = createWriteStream(getPathToNull())
dest.write = function (s) {
actual += s
}
const asyncLogger = pino(dest).child({ hello: 'world' })
let i = 500
while (i--) {
normal.info('h')
asyncLogger.info('h')
}
asyncLogger.flush()
const expected2 = expected.split('\n')[0]
let actual2 = ''
const child = fork(join(__dirname, '/fixtures/syncfalse-child.js'), { silent: true })
child.stdout.pipe(writer((s, enc, cb) => {
actual2 += s
cb()
}))
await once(child, 'close')
assert.equal(actual, expected)
assert.equal(actual2.trim(), expected2)
t.after(() => {
os.hostname = hostname
Date.now = now
global.process = proc
})
})
test('flush does nothing with sync true (default)', async () => {
const instance = require('..')()
assert.equal(instance.flush(), undefined)
})
test('should still call flush callback even when does nothing with sync true (default)', async (t) => {
const plan = tspl(t, { plan: 3 })
const instance = require('..')()
instance.flush((...args) => {
plan.ok('flush called')
plan.deepEqual(args, [])
// next tick to make flush not called more than once
process.nextTick(() => {
plan.ok('flush next tick called')
})
})
await plan
})
test('should call the flush callback when flushed the data for async logger', async () => {
const outputPath = file()
async function getOutputLogLines () {
return (await readFile(outputPath)).toString().trim().split('\n').map(JSON.parse)
}
const pino = require('../')
const instance = pino({}, pino.destination({
dest: outputPath,
// to make sure it does not flush on its own
minLength: 4096
}))
const flushPromise = promisify(instance.flush).bind(instance)
instance.info('hello')
await flushPromise()
await watchFileCreated(outputPath)
const [firstFlushData] = await getOutputLogLines()
assert.equal(firstFlushData.msg, 'hello')
// should not flush this as no data accumulated that's bigger than min length
instance.info('world')
// Making sure data is not flushed yet
const afterLogData = await getOutputLogLines()
assert.equal(afterLogData.length, 1)
await flushPromise()
// Making sure data is not flushed yet
const afterSecondFlush = (await getOutputLogLines())[1]
assert.equal(afterSecondFlush.msg, 'world')
})

View File

@@ -0,0 +1,375 @@
import { _ as BindingTsconfigCompilerOptions, v as BindingTsconfigRawOptions } from "./shared/binding-CVtkJvyl.mjs";
import { a as MinifyOptions, c as minifySync, d as parse, f as parseSync, i as transformSync, l as ParseResult, n as TransformResult, o as MinifyResult, p as TsconfigCache, r as transform, s as minify, t as TransformOptions, u as ParserOptions } from "./shared/transform-WmU_cI8e.mjs";
import * as ESTree from "@oxc-project/types";
import { Program } from "@oxc-project/types";
//#region ../../node_modules/.pnpm/oxc-parser@0.144.0/node_modules/oxc-parser/src-js/generated/visit/visitor.d.ts
interface VisitorObject$1 {
DebuggerStatement?: (node: ESTree.DebuggerStatement) => void;
"DebuggerStatement:exit"?: (node: ESTree.DebuggerStatement) => void;
EmptyStatement?: (node: ESTree.EmptyStatement) => void;
"EmptyStatement:exit"?: (node: ESTree.EmptyStatement) => void;
Literal?: (node: ESTree.BooleanLiteral | ESTree.NullLiteral | ESTree.NumericLiteral | ESTree.StringLiteral | ESTree.BigIntLiteral | ESTree.RegExpLiteral) => void;
"Literal:exit"?: (node: ESTree.BooleanLiteral | ESTree.NullLiteral | ESTree.NumericLiteral | ESTree.StringLiteral | ESTree.BigIntLiteral | ESTree.RegExpLiteral) => void;
PrivateIdentifier?: (node: ESTree.PrivateIdentifier) => void;
"PrivateIdentifier:exit"?: (node: ESTree.PrivateIdentifier) => void;
Super?: (node: ESTree.Super) => void;
"Super:exit"?: (node: ESTree.Super) => void;
TemplateElement?: (node: ESTree.TemplateElement) => void;
"TemplateElement:exit"?: (node: ESTree.TemplateElement) => void;
ThisExpression?: (node: ESTree.ThisExpression) => void;
"ThisExpression:exit"?: (node: ESTree.ThisExpression) => void;
JSXClosingFragment?: (node: ESTree.JSXClosingFragment) => void;
"JSXClosingFragment:exit"?: (node: ESTree.JSXClosingFragment) => void;
JSXEmptyExpression?: (node: ESTree.JSXEmptyExpression) => void;
"JSXEmptyExpression:exit"?: (node: ESTree.JSXEmptyExpression) => void;
JSXIdentifier?: (node: ESTree.JSXIdentifier) => void;
"JSXIdentifier:exit"?: (node: ESTree.JSXIdentifier) => void;
JSXOpeningFragment?: (node: ESTree.JSXOpeningFragment) => void;
"JSXOpeningFragment:exit"?: (node: ESTree.JSXOpeningFragment) => void;
JSXText?: (node: ESTree.JSXText) => void;
"JSXText:exit"?: (node: ESTree.JSXText) => void;
TSAnyKeyword?: (node: ESTree.TSAnyKeyword) => void;
"TSAnyKeyword:exit"?: (node: ESTree.TSAnyKeyword) => void;
TSBigIntKeyword?: (node: ESTree.TSBigIntKeyword) => void;
"TSBigIntKeyword:exit"?: (node: ESTree.TSBigIntKeyword) => void;
TSBooleanKeyword?: (node: ESTree.TSBooleanKeyword) => void;
"TSBooleanKeyword:exit"?: (node: ESTree.TSBooleanKeyword) => void;
TSIntrinsicKeyword?: (node: ESTree.TSIntrinsicKeyword) => void;
"TSIntrinsicKeyword:exit"?: (node: ESTree.TSIntrinsicKeyword) => void;
TSJSDocUnknownType?: (node: ESTree.JSDocUnknownType) => void;
"TSJSDocUnknownType:exit"?: (node: ESTree.JSDocUnknownType) => void;
TSNeverKeyword?: (node: ESTree.TSNeverKeyword) => void;
"TSNeverKeyword:exit"?: (node: ESTree.TSNeverKeyword) => void;
TSNullKeyword?: (node: ESTree.TSNullKeyword) => void;
"TSNullKeyword:exit"?: (node: ESTree.TSNullKeyword) => void;
TSNumberKeyword?: (node: ESTree.TSNumberKeyword) => void;
"TSNumberKeyword:exit"?: (node: ESTree.TSNumberKeyword) => void;
TSObjectKeyword?: (node: ESTree.TSObjectKeyword) => void;
"TSObjectKeyword:exit"?: (node: ESTree.TSObjectKeyword) => void;
TSStringKeyword?: (node: ESTree.TSStringKeyword) => void;
"TSStringKeyword:exit"?: (node: ESTree.TSStringKeyword) => void;
TSSymbolKeyword?: (node: ESTree.TSSymbolKeyword) => void;
"TSSymbolKeyword:exit"?: (node: ESTree.TSSymbolKeyword) => void;
TSThisType?: (node: ESTree.TSThisType) => void;
"TSThisType:exit"?: (node: ESTree.TSThisType) => void;
TSUndefinedKeyword?: (node: ESTree.TSUndefinedKeyword) => void;
"TSUndefinedKeyword:exit"?: (node: ESTree.TSUndefinedKeyword) => void;
TSUnknownKeyword?: (node: ESTree.TSUnknownKeyword) => void;
"TSUnknownKeyword:exit"?: (node: ESTree.TSUnknownKeyword) => void;
TSVoidKeyword?: (node: ESTree.TSVoidKeyword) => void;
"TSVoidKeyword:exit"?: (node: ESTree.TSVoidKeyword) => void;
AccessorProperty?: (node: ESTree.AccessorProperty) => void;
"AccessorProperty:exit"?: (node: ESTree.AccessorProperty) => void;
ArrayExpression?: (node: ESTree.ArrayExpression) => void;
"ArrayExpression:exit"?: (node: ESTree.ArrayExpression) => void;
ArrayPattern?: (node: ESTree.ArrayPattern) => void;
"ArrayPattern:exit"?: (node: ESTree.ArrayPattern) => void;
ArrowFunctionExpression?: (node: ESTree.ArrowFunctionExpression) => void;
"ArrowFunctionExpression:exit"?: (node: ESTree.ArrowFunctionExpression) => void;
AssignmentExpression?: (node: ESTree.AssignmentExpression) => void;
"AssignmentExpression:exit"?: (node: ESTree.AssignmentExpression) => void;
AssignmentPattern?: (node: ESTree.AssignmentPattern) => void;
"AssignmentPattern:exit"?: (node: ESTree.AssignmentPattern) => void;
AwaitExpression?: (node: ESTree.AwaitExpression) => void;
"AwaitExpression:exit"?: (node: ESTree.AwaitExpression) => void;
BinaryExpression?: (node: ESTree.BinaryExpression) => void;
"BinaryExpression:exit"?: (node: ESTree.BinaryExpression) => void;
BlockStatement?: (node: ESTree.BlockStatement) => void;
"BlockStatement:exit"?: (node: ESTree.BlockStatement) => void;
BreakStatement?: (node: ESTree.BreakStatement) => void;
"BreakStatement:exit"?: (node: ESTree.BreakStatement) => void;
CallExpression?: (node: ESTree.CallExpression) => void;
"CallExpression:exit"?: (node: ESTree.CallExpression) => void;
CatchClause?: (node: ESTree.CatchClause) => void;
"CatchClause:exit"?: (node: ESTree.CatchClause) => void;
ChainExpression?: (node: ESTree.ChainExpression) => void;
"ChainExpression:exit"?: (node: ESTree.ChainExpression) => void;
ClassBody?: (node: ESTree.ClassBody) => void;
"ClassBody:exit"?: (node: ESTree.ClassBody) => void;
ClassDeclaration?: (node: ESTree.Class) => void;
"ClassDeclaration:exit"?: (node: ESTree.Class) => void;
ClassExpression?: (node: ESTree.Class) => void;
"ClassExpression:exit"?: (node: ESTree.Class) => void;
ConditionalExpression?: (node: ESTree.ConditionalExpression) => void;
"ConditionalExpression:exit"?: (node: ESTree.ConditionalExpression) => void;
ContinueStatement?: (node: ESTree.ContinueStatement) => void;
"ContinueStatement:exit"?: (node: ESTree.ContinueStatement) => void;
Decorator?: (node: ESTree.Decorator) => void;
"Decorator:exit"?: (node: ESTree.Decorator) => void;
DoWhileStatement?: (node: ESTree.DoWhileStatement) => void;
"DoWhileStatement:exit"?: (node: ESTree.DoWhileStatement) => void;
ExportAllDeclaration?: (node: ESTree.ExportAllDeclaration) => void;
"ExportAllDeclaration:exit"?: (node: ESTree.ExportAllDeclaration) => void;
ExportDefaultDeclaration?: (node: ESTree.ExportDefaultDeclaration) => void;
"ExportDefaultDeclaration:exit"?: (node: ESTree.ExportDefaultDeclaration) => void;
ExportNamedDeclaration?: (node: ESTree.ExportNamedDeclaration) => void;
"ExportNamedDeclaration:exit"?: (node: ESTree.ExportNamedDeclaration) => void;
ExportSpecifier?: (node: ESTree.ExportSpecifier) => void;
"ExportSpecifier:exit"?: (node: ESTree.ExportSpecifier) => void;
ExpressionStatement?: (node: ESTree.ExpressionStatement) => void;
"ExpressionStatement:exit"?: (node: ESTree.ExpressionStatement) => void;
ForInStatement?: (node: ESTree.ForInStatement) => void;
"ForInStatement:exit"?: (node: ESTree.ForInStatement) => void;
ForOfStatement?: (node: ESTree.ForOfStatement) => void;
"ForOfStatement:exit"?: (node: ESTree.ForOfStatement) => void;
ForStatement?: (node: ESTree.ForStatement) => void;
"ForStatement:exit"?: (node: ESTree.ForStatement) => void;
FunctionDeclaration?: (node: ESTree.Function) => void;
"FunctionDeclaration:exit"?: (node: ESTree.Function) => void;
FunctionExpression?: (node: ESTree.Function) => void;
"FunctionExpression:exit"?: (node: ESTree.Function) => void;
Identifier?: (node: ESTree.IdentifierName | ESTree.IdentifierReference | ESTree.BindingIdentifier | ESTree.LabelIdentifier | ESTree.TSThisParameter | ESTree.TSIndexSignatureName) => void;
"Identifier:exit"?: (node: ESTree.IdentifierName | ESTree.IdentifierReference | ESTree.BindingIdentifier | ESTree.LabelIdentifier | ESTree.TSThisParameter | ESTree.TSIndexSignatureName) => void;
IfStatement?: (node: ESTree.IfStatement) => void;
"IfStatement:exit"?: (node: ESTree.IfStatement) => void;
ImportAttribute?: (node: ESTree.ImportAttribute) => void;
"ImportAttribute:exit"?: (node: ESTree.ImportAttribute) => void;
ImportDeclaration?: (node: ESTree.ImportDeclaration) => void;
"ImportDeclaration:exit"?: (node: ESTree.ImportDeclaration) => void;
ImportDefaultSpecifier?: (node: ESTree.ImportDefaultSpecifier) => void;
"ImportDefaultSpecifier:exit"?: (node: ESTree.ImportDefaultSpecifier) => void;
ImportExpression?: (node: ESTree.ImportExpression) => void;
"ImportExpression:exit"?: (node: ESTree.ImportExpression) => void;
ImportNamespaceSpecifier?: (node: ESTree.ImportNamespaceSpecifier) => void;
"ImportNamespaceSpecifier:exit"?: (node: ESTree.ImportNamespaceSpecifier) => void;
ImportSpecifier?: (node: ESTree.ImportSpecifier) => void;
"ImportSpecifier:exit"?: (node: ESTree.ImportSpecifier) => void;
LabeledStatement?: (node: ESTree.LabeledStatement) => void;
"LabeledStatement:exit"?: (node: ESTree.LabeledStatement) => void;
LogicalExpression?: (node: ESTree.LogicalExpression) => void;
"LogicalExpression:exit"?: (node: ESTree.LogicalExpression) => void;
MemberExpression?: (node: ESTree.MemberExpression) => void;
"MemberExpression:exit"?: (node: ESTree.MemberExpression) => void;
MetaProperty?: (node: ESTree.MetaProperty) => void;
"MetaProperty:exit"?: (node: ESTree.MetaProperty) => void;
MethodDefinition?: (node: ESTree.MethodDefinition) => void;
"MethodDefinition:exit"?: (node: ESTree.MethodDefinition) => void;
NewExpression?: (node: ESTree.NewExpression) => void;
"NewExpression:exit"?: (node: ESTree.NewExpression) => void;
ObjectExpression?: (node: ESTree.ObjectExpression) => void;
"ObjectExpression:exit"?: (node: ESTree.ObjectExpression) => void;
ObjectPattern?: (node: ESTree.ObjectPattern) => void;
"ObjectPattern:exit"?: (node: ESTree.ObjectPattern) => void;
ParenthesizedExpression?: (node: ESTree.ParenthesizedExpression) => void;
"ParenthesizedExpression:exit"?: (node: ESTree.ParenthesizedExpression) => void;
Program?: (node: ESTree.Program) => void;
"Program:exit"?: (node: ESTree.Program) => void;
Property?: (node: ESTree.ObjectProperty | ESTree.AssignmentTargetProperty | ESTree.AssignmentTargetPropertyProperty | ESTree.BindingProperty) => void;
"Property:exit"?: (node: ESTree.ObjectProperty | ESTree.AssignmentTargetProperty | ESTree.AssignmentTargetPropertyProperty | ESTree.BindingProperty) => void;
PropertyDefinition?: (node: ESTree.PropertyDefinition) => void;
"PropertyDefinition:exit"?: (node: ESTree.PropertyDefinition) => void;
RestElement?: (node: ESTree.AssignmentTargetRest | ESTree.BindingRestElement | ESTree.FormalParameterRest) => void;
"RestElement:exit"?: (node: ESTree.AssignmentTargetRest | ESTree.BindingRestElement | ESTree.FormalParameterRest) => void;
ReturnStatement?: (node: ESTree.ReturnStatement) => void;
"ReturnStatement:exit"?: (node: ESTree.ReturnStatement) => void;
SequenceExpression?: (node: ESTree.SequenceExpression) => void;
"SequenceExpression:exit"?: (node: ESTree.SequenceExpression) => void;
SpreadElement?: (node: ESTree.SpreadElement) => void;
"SpreadElement:exit"?: (node: ESTree.SpreadElement) => void;
StaticBlock?: (node: ESTree.StaticBlock) => void;
"StaticBlock:exit"?: (node: ESTree.StaticBlock) => void;
SwitchCase?: (node: ESTree.SwitchCase) => void;
"SwitchCase:exit"?: (node: ESTree.SwitchCase) => void;
SwitchStatement?: (node: ESTree.SwitchStatement) => void;
"SwitchStatement:exit"?: (node: ESTree.SwitchStatement) => void;
TaggedTemplateExpression?: (node: ESTree.TaggedTemplateExpression) => void;
"TaggedTemplateExpression:exit"?: (node: ESTree.TaggedTemplateExpression) => void;
TemplateLiteral?: (node: ESTree.TemplateLiteral) => void;
"TemplateLiteral:exit"?: (node: ESTree.TemplateLiteral) => void;
ThrowStatement?: (node: ESTree.ThrowStatement) => void;
"ThrowStatement:exit"?: (node: ESTree.ThrowStatement) => void;
TryStatement?: (node: ESTree.TryStatement) => void;
"TryStatement:exit"?: (node: ESTree.TryStatement) => void;
UnaryExpression?: (node: ESTree.UnaryExpression) => void;
"UnaryExpression:exit"?: (node: ESTree.UnaryExpression) => void;
UpdateExpression?: (node: ESTree.UpdateExpression) => void;
"UpdateExpression:exit"?: (node: ESTree.UpdateExpression) => void;
V8IntrinsicExpression?: (node: ESTree.V8IntrinsicExpression) => void;
"V8IntrinsicExpression:exit"?: (node: ESTree.V8IntrinsicExpression) => void;
VariableDeclaration?: (node: ESTree.VariableDeclaration) => void;
"VariableDeclaration:exit"?: (node: ESTree.VariableDeclaration) => void;
VariableDeclarator?: (node: ESTree.VariableDeclarator) => void;
"VariableDeclarator:exit"?: (node: ESTree.VariableDeclarator) => void;
WhileStatement?: (node: ESTree.WhileStatement) => void;
"WhileStatement:exit"?: (node: ESTree.WhileStatement) => void;
WithStatement?: (node: ESTree.WithStatement) => void;
"WithStatement:exit"?: (node: ESTree.WithStatement) => void;
YieldExpression?: (node: ESTree.YieldExpression) => void;
"YieldExpression:exit"?: (node: ESTree.YieldExpression) => void;
JSXAttribute?: (node: ESTree.JSXAttribute) => void;
"JSXAttribute:exit"?: (node: ESTree.JSXAttribute) => void;
JSXClosingElement?: (node: ESTree.JSXClosingElement) => void;
"JSXClosingElement:exit"?: (node: ESTree.JSXClosingElement) => void;
JSXElement?: (node: ESTree.JSXElement) => void;
"JSXElement:exit"?: (node: ESTree.JSXElement) => void;
JSXExpressionContainer?: (node: ESTree.JSXExpressionContainer) => void;
"JSXExpressionContainer:exit"?: (node: ESTree.JSXExpressionContainer) => void;
JSXFragment?: (node: ESTree.JSXFragment) => void;
"JSXFragment:exit"?: (node: ESTree.JSXFragment) => void;
JSXMemberExpression?: (node: ESTree.JSXMemberExpression) => void;
"JSXMemberExpression:exit"?: (node: ESTree.JSXMemberExpression) => void;
JSXNamespacedName?: (node: ESTree.JSXNamespacedName) => void;
"JSXNamespacedName:exit"?: (node: ESTree.JSXNamespacedName) => void;
JSXOpeningElement?: (node: ESTree.JSXOpeningElement) => void;
"JSXOpeningElement:exit"?: (node: ESTree.JSXOpeningElement) => void;
JSXSpreadAttribute?: (node: ESTree.JSXSpreadAttribute) => void;
"JSXSpreadAttribute:exit"?: (node: ESTree.JSXSpreadAttribute) => void;
JSXSpreadChild?: (node: ESTree.JSXSpreadChild) => void;
"JSXSpreadChild:exit"?: (node: ESTree.JSXSpreadChild) => void;
TSAbstractAccessorProperty?: (node: ESTree.AccessorProperty) => void;
"TSAbstractAccessorProperty:exit"?: (node: ESTree.AccessorProperty) => void;
TSAbstractMethodDefinition?: (node: ESTree.MethodDefinition) => void;
"TSAbstractMethodDefinition:exit"?: (node: ESTree.MethodDefinition) => void;
TSAbstractPropertyDefinition?: (node: ESTree.PropertyDefinition) => void;
"TSAbstractPropertyDefinition:exit"?: (node: ESTree.PropertyDefinition) => void;
TSArrayType?: (node: ESTree.TSArrayType) => void;
"TSArrayType:exit"?: (node: ESTree.TSArrayType) => void;
TSAsExpression?: (node: ESTree.TSAsExpression) => void;
"TSAsExpression:exit"?: (node: ESTree.TSAsExpression) => void;
TSCallSignatureDeclaration?: (node: ESTree.TSCallSignatureDeclaration) => void;
"TSCallSignatureDeclaration:exit"?: (node: ESTree.TSCallSignatureDeclaration) => void;
TSClassImplements?: (node: ESTree.TSClassImplements) => void;
"TSClassImplements:exit"?: (node: ESTree.TSClassImplements) => void;
TSConditionalType?: (node: ESTree.TSConditionalType) => void;
"TSConditionalType:exit"?: (node: ESTree.TSConditionalType) => void;
TSConstructSignatureDeclaration?: (node: ESTree.TSConstructSignatureDeclaration) => void;
"TSConstructSignatureDeclaration:exit"?: (node: ESTree.TSConstructSignatureDeclaration) => void;
TSConstructorType?: (node: ESTree.TSConstructorType) => void;
"TSConstructorType:exit"?: (node: ESTree.TSConstructorType) => void;
TSDeclareFunction?: (node: ESTree.Function) => void;
"TSDeclareFunction:exit"?: (node: ESTree.Function) => void;
TSEmptyBodyFunctionExpression?: (node: ESTree.Function) => void;
"TSEmptyBodyFunctionExpression:exit"?: (node: ESTree.Function) => void;
TSEnumBody?: (node: ESTree.TSEnumBody) => void;
"TSEnumBody:exit"?: (node: ESTree.TSEnumBody) => void;
TSEnumDeclaration?: (node: ESTree.TSEnumDeclaration) => void;
"TSEnumDeclaration:exit"?: (node: ESTree.TSEnumDeclaration) => void;
TSEnumMember?: (node: ESTree.TSEnumMember) => void;
"TSEnumMember:exit"?: (node: ESTree.TSEnumMember) => void;
TSExportAssignment?: (node: ESTree.TSExportAssignment) => void;
"TSExportAssignment:exit"?: (node: ESTree.TSExportAssignment) => void;
TSExternalModuleReference?: (node: ESTree.TSExternalModuleReference) => void;
"TSExternalModuleReference:exit"?: (node: ESTree.TSExternalModuleReference) => void;
TSFunctionType?: (node: ESTree.TSFunctionType) => void;
"TSFunctionType:exit"?: (node: ESTree.TSFunctionType) => void;
TSImportEqualsDeclaration?: (node: ESTree.TSImportEqualsDeclaration) => void;
"TSImportEqualsDeclaration:exit"?: (node: ESTree.TSImportEqualsDeclaration) => void;
TSImportType?: (node: ESTree.TSImportType) => void;
"TSImportType:exit"?: (node: ESTree.TSImportType) => void;
TSIndexSignature?: (node: ESTree.TSIndexSignature) => void;
"TSIndexSignature:exit"?: (node: ESTree.TSIndexSignature) => void;
TSIndexedAccessType?: (node: ESTree.TSIndexedAccessType) => void;
"TSIndexedAccessType:exit"?: (node: ESTree.TSIndexedAccessType) => void;
TSInferType?: (node: ESTree.TSInferType) => void;
"TSInferType:exit"?: (node: ESTree.TSInferType) => void;
TSInstantiationExpression?: (node: ESTree.TSInstantiationExpression) => void;
"TSInstantiationExpression:exit"?: (node: ESTree.TSInstantiationExpression) => void;
TSInterfaceBody?: (node: ESTree.TSInterfaceBody) => void;
"TSInterfaceBody:exit"?: (node: ESTree.TSInterfaceBody) => void;
TSInterfaceDeclaration?: (node: ESTree.TSInterfaceDeclaration) => void;
"TSInterfaceDeclaration:exit"?: (node: ESTree.TSInterfaceDeclaration) => void;
TSInterfaceHeritage?: (node: ESTree.TSInterfaceHeritage) => void;
"TSInterfaceHeritage:exit"?: (node: ESTree.TSInterfaceHeritage) => void;
TSIntersectionType?: (node: ESTree.TSIntersectionType) => void;
"TSIntersectionType:exit"?: (node: ESTree.TSIntersectionType) => void;
TSJSDocNonNullableType?: (node: ESTree.JSDocNonNullableType) => void;
"TSJSDocNonNullableType:exit"?: (node: ESTree.JSDocNonNullableType) => void;
TSJSDocNullableType?: (node: ESTree.JSDocNullableType) => void;
"TSJSDocNullableType:exit"?: (node: ESTree.JSDocNullableType) => void;
TSLiteralType?: (node: ESTree.TSLiteralType) => void;
"TSLiteralType:exit"?: (node: ESTree.TSLiteralType) => void;
TSMappedType?: (node: ESTree.TSMappedType) => void;
"TSMappedType:exit"?: (node: ESTree.TSMappedType) => void;
TSMethodSignature?: (node: ESTree.TSMethodSignature) => void;
"TSMethodSignature:exit"?: (node: ESTree.TSMethodSignature) => void;
TSModuleBlock?: (node: ESTree.TSModuleBlock) => void;
"TSModuleBlock:exit"?: (node: ESTree.TSModuleBlock) => void;
TSModuleDeclaration?: (node: ESTree.TSModuleDeclaration | ESTree.TSGlobalDeclaration) => void;
"TSModuleDeclaration:exit"?: (node: ESTree.TSModuleDeclaration | ESTree.TSGlobalDeclaration) => void;
TSNamedTupleMember?: (node: ESTree.TSNamedTupleMember) => void;
"TSNamedTupleMember:exit"?: (node: ESTree.TSNamedTupleMember) => void;
TSNamespaceExportDeclaration?: (node: ESTree.TSNamespaceExportDeclaration) => void;
"TSNamespaceExportDeclaration:exit"?: (node: ESTree.TSNamespaceExportDeclaration) => void;
TSNonNullExpression?: (node: ESTree.TSNonNullExpression) => void;
"TSNonNullExpression:exit"?: (node: ESTree.TSNonNullExpression) => void;
TSOptionalType?: (node: ESTree.TSOptionalType) => void;
"TSOptionalType:exit"?: (node: ESTree.TSOptionalType) => void;
TSParameterProperty?: (node: ESTree.TSParameterProperty) => void;
"TSParameterProperty:exit"?: (node: ESTree.TSParameterProperty) => void;
TSParenthesizedType?: (node: ESTree.TSParenthesizedType) => void;
"TSParenthesizedType:exit"?: (node: ESTree.TSParenthesizedType) => void;
TSPropertySignature?: (node: ESTree.TSPropertySignature) => void;
"TSPropertySignature:exit"?: (node: ESTree.TSPropertySignature) => void;
TSQualifiedName?: (node: ESTree.TSQualifiedName) => void;
"TSQualifiedName:exit"?: (node: ESTree.TSQualifiedName) => void;
TSRestType?: (node: ESTree.TSRestType) => void;
"TSRestType:exit"?: (node: ESTree.TSRestType) => void;
TSSatisfiesExpression?: (node: ESTree.TSSatisfiesExpression) => void;
"TSSatisfiesExpression:exit"?: (node: ESTree.TSSatisfiesExpression) => void;
TSTemplateLiteralType?: (node: ESTree.TSTemplateLiteralType) => void;
"TSTemplateLiteralType:exit"?: (node: ESTree.TSTemplateLiteralType) => void;
TSTupleType?: (node: ESTree.TSTupleType) => void;
"TSTupleType:exit"?: (node: ESTree.TSTupleType) => void;
TSTypeAliasDeclaration?: (node: ESTree.TSTypeAliasDeclaration) => void;
"TSTypeAliasDeclaration:exit"?: (node: ESTree.TSTypeAliasDeclaration) => void;
TSTypeAnnotation?: (node: ESTree.TSTypeAnnotation) => void;
"TSTypeAnnotation:exit"?: (node: ESTree.TSTypeAnnotation) => void;
TSTypeAssertion?: (node: ESTree.TSTypeAssertion) => void;
"TSTypeAssertion:exit"?: (node: ESTree.TSTypeAssertion) => void;
TSTypeLiteral?: (node: ESTree.TSTypeLiteral) => void;
"TSTypeLiteral:exit"?: (node: ESTree.TSTypeLiteral) => void;
TSTypeOperator?: (node: ESTree.TSTypeOperator) => void;
"TSTypeOperator:exit"?: (node: ESTree.TSTypeOperator) => void;
TSTypeParameter?: (node: ESTree.TSTypeParameter) => void;
"TSTypeParameter:exit"?: (node: ESTree.TSTypeParameter) => void;
TSTypeParameterDeclaration?: (node: ESTree.TSTypeParameterDeclaration) => void;
"TSTypeParameterDeclaration:exit"?: (node: ESTree.TSTypeParameterDeclaration) => void;
TSTypeParameterInstantiation?: (node: ESTree.TSTypeParameterInstantiation) => void;
"TSTypeParameterInstantiation:exit"?: (node: ESTree.TSTypeParameterInstantiation) => void;
TSTypePredicate?: (node: ESTree.TSTypePredicate) => void;
"TSTypePredicate:exit"?: (node: ESTree.TSTypePredicate) => void;
TSTypeQuery?: (node: ESTree.TSTypeQuery) => void;
"TSTypeQuery:exit"?: (node: ESTree.TSTypeQuery) => void;
TSTypeReference?: (node: ESTree.TSTypeReference) => void;
"TSTypeReference:exit"?: (node: ESTree.TSTypeReference) => void;
TSUnionType?: (node: ESTree.TSUnionType) => void;
"TSUnionType:exit"?: (node: ESTree.TSUnionType) => void;
}
//#endregion
//#region src/utils/visitor.d.ts
/**
* Visitor object for traversing AST.
*
* @category Utilities
*/
type VisitorObject = VisitorObject$1;
/**
* Visitor class for traversing AST.
*
* @example
* ```ts
* import { Visitor } from 'rolldown/utils';
* import { parseSync } from 'rolldown/utils';
*
* const result = parseSync(...);
* const visitor = new Visitor({
* VariableDeclaration(path) {
* // Do something with the variable declaration
* },
* "VariableDeclaration:exit"(path) {
* // Do something after visiting the variable declaration
* }
* });
* visitor.visit(result.program);
* ```
*
* @category Utilities
* @experimental
*/
declare class Visitor {
#private;
constructor(visitor: VisitorObject);
visit(program: Program): void;
}
//#endregion
export { type ESTree, type MinifyOptions, type MinifyResult, type ParseResult, type ParserOptions, type TransformOptions, type TransformResult, TsconfigCache, type BindingTsconfigCompilerOptions as TsconfigCompilerOptions, type BindingTsconfigRawOptions as TsconfigRawOptions, Visitor, type VisitorObject, minify, minifySync, parse, parseSync, transform, transformSync };

View File

@@ -0,0 +1,72 @@
/**
* This package brings together every error message across all Solana JavaScript modules.
*
* # Reading error messages
*
* ## In development mode
*
* When your bundler sets the constant `__DEV__` to `true`, every error message will be included in
* the bundle. As such, you will be able to read them in plain language wherever they appear.
*
* > [!WARNING]
* > The size of your JavaScript bundle will increase significantly with the inclusion of every
* > error message in development mode. Be sure to build your bundle with `__DEV__` set to `false`
* > when you go to production.
*
* ## In production mode
*
* When your bundler sets the constant `__DEV__` to `false`, error messages will be stripped from
* the bundle to save space. Only the error code will appear when an error is encountered. Follow
* the instructions in the error message to convert the error code back to the human-readable error
* message.
*
* For instance, to recover the error text for the error with code `123`:
*
* ```package-install
* npx @solana/errors decode -- 123
* ```
*
* > [!IMPORTANT]
* > The string representation of a {@link SolanaError} should not be shown to users. Developers
* > should use {@link isSolanaError} to distinguish the type of a thrown error, then show a custom,
* > localized error message appropriate for their application's audience. Custom error messages
* > should use the error's {@link SolanaError#context | `context`} if it would help the reader
* > understand what happened and/or what to do next.
*
* # Adding a new error
*
* 1. Add a new exported error code constant to `src/codes.ts`.
* 2. Add that new constant to the {@link SolanaErrorCode} union in `src/codes.ts`.
* 3. If you would like the new error to encapsulate context about the error itself (eg. the public
* keys for which a transaction is missing signatures) define the shape of that context in
* `src/context.ts`.
* 4. Add the error's message to `src/messages.ts`. Any context values that you defined above will
* be interpolated into the message wherever you write `$key`, where `key` is the index of a
* value in the context (eg. ``'Missing a signature for account `$address`'``).
* 5. Publish a new version of `@solana/errors`.
* 6. Bump the version of `@solana/errors` in the package from which the error is thrown.
*
* # Removing an error message
*
* - Don't remove errors.
* - Don't change the meaning of an error message.
* - Don't change or reorder error codes.
* - Don't change or remove members of an error's context.
*
* When an older client throws an error, we want to make sure that they can always decode the error.
* If you make any of the changes above, old clients will, by definition, not have received your
* changes. This could make the errors that they throw impossible to decode going forward.
*
* # Catching errors
*
* See {@link isSolanaError} for an example of how to handle a caught {@link SolanaError}.
*
* @packageDocumentation
*/
export * from './codes';
export * from './error';
export * from './json-rpc-error';
export * from './instruction-error';
export * from './stack-trace';
export * from './transaction-error';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
export { _ as default } from "../esm/_interop_require_default.js";

View File

@@ -0,0 +1,236 @@
export interface CSPair { // eslint-disable-line @typescript-eslint/naming-convention
/**
The ANSI terminal control sequence for starting this style.
*/
readonly open: string;
/**
The ANSI terminal control sequence for ending this style.
*/
readonly close: string;
}
export interface ColorBase {
/**
The ANSI terminal control sequence for ending this color.
*/
readonly close: string;
ansi(code: number): string;
ansi256(code: number): string;
ansi16m(red: number, green: number, blue: number): string;
}
export interface Modifier {
/**
Resets the current color chain.
*/
readonly reset: CSPair;
/**
Make text bold.
*/
readonly bold: CSPair;
/**
Emitting only a small amount of light.
*/
readonly dim: CSPair;
/**
Make text italic. (Not widely supported)
*/
readonly italic: CSPair;
/**
Make text underline. (Not widely supported)
*/
readonly underline: CSPair;
/**
Make text overline.
Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.
*/
readonly overline: CSPair;
/**
Inverse background and foreground colors.
*/
readonly inverse: CSPair;
/**
Prints the text, but makes it invisible.
*/
readonly hidden: CSPair;
/**
Puts a horizontal line through the center of the text. (Not widely supported)
*/
readonly strikethrough: CSPair;
}
export interface ForegroundColor {
readonly black: CSPair;
readonly red: CSPair;
readonly green: CSPair;
readonly yellow: CSPair;
readonly blue: CSPair;
readonly cyan: CSPair;
readonly magenta: CSPair;
readonly white: CSPair;
/**
Alias for `blackBright`.
*/
readonly gray: CSPair;
/**
Alias for `blackBright`.
*/
readonly grey: CSPair;
readonly blackBright: CSPair;
readonly redBright: CSPair;
readonly greenBright: CSPair;
readonly yellowBright: CSPair;
readonly blueBright: CSPair;
readonly cyanBright: CSPair;
readonly magentaBright: CSPair;
readonly whiteBright: CSPair;
}
export interface BackgroundColor {
readonly bgBlack: CSPair;
readonly bgRed: CSPair;
readonly bgGreen: CSPair;
readonly bgYellow: CSPair;
readonly bgBlue: CSPair;
readonly bgCyan: CSPair;
readonly bgMagenta: CSPair;
readonly bgWhite: CSPair;
/**
Alias for `bgBlackBright`.
*/
readonly bgGray: CSPair;
/**
Alias for `bgBlackBright`.
*/
readonly bgGrey: CSPair;
readonly bgBlackBright: CSPair;
readonly bgRedBright: CSPair;
readonly bgGreenBright: CSPair;
readonly bgYellowBright: CSPair;
readonly bgBlueBright: CSPair;
readonly bgCyanBright: CSPair;
readonly bgMagentaBright: CSPair;
readonly bgWhiteBright: CSPair;
}
export interface ConvertColor {
/**
Convert from the RGB color space to the ANSI 256 color space.
@param red - (`0...255`)
@param green - (`0...255`)
@param blue - (`0...255`)
*/
rgbToAnsi256(red: number, green: number, blue: number): number;
/**
Convert from the RGB HEX color space to the RGB color space.
@param hex - A hexadecimal string containing RGB data.
*/
hexToRgb(hex: string): [red: number, green: number, blue: number];
/**
Convert from the RGB HEX color space to the ANSI 256 color space.
@param hex - A hexadecimal string containing RGB data.
*/
hexToAnsi256(hex: string): number;
/**
Convert from the ANSI 256 color space to the ANSI 16 color space.
@param code - A number representing the ANSI 256 color.
*/
ansi256ToAnsi(code: number): number;
/**
Convert from the RGB color space to the ANSI 16 color space.
@param red - (`0...255`)
@param green - (`0...255`)
@param blue - (`0...255`)
*/
rgbToAnsi(red: number, green: number, blue: number): number;
/**
Convert from the RGB HEX color space to the ANSI 16 color space.
@param hex - A hexadecimal string containing RGB data.
*/
hexToAnsi(hex: string): number;
}
/**
Basic modifier names.
*/
export type ModifierName = keyof Modifier;
/**
Basic foreground color names.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
export type ForegroundColorName = keyof ForegroundColor;
/**
Basic background color names.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
export type BackgroundColorName = keyof BackgroundColor;
/**
Basic color names. The combination of foreground and background color names.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
export type ColorName = ForegroundColorName | BackgroundColorName;
/**
Basic modifier names.
*/
export const modifierNames: readonly ModifierName[];
/**
Basic foreground color names.
*/
export const foregroundColorNames: readonly ForegroundColorName[];
/**
Basic background color names.
*/
export const backgroundColorNames: readonly BackgroundColorName[];
/*
Basic color names. The combination of foreground and background color names.
*/
export const colorNames: readonly ColorName[];
declare const ansiStyles: {
readonly modifier: Modifier;
readonly color: ColorBase & ForegroundColor;
readonly bgColor: ColorBase & BackgroundColor;
readonly codes: ReadonlyMap<number, number>;
} & ForegroundColor & BackgroundColor & Modifier & ConvertColor;
export default ansiStyles;

View File

@@ -0,0 +1,13 @@
import crypto from 'crypto';
function md5(bytes) {
if (Array.isArray(bytes)) {
bytes = Buffer.from(bytes);
} else if (typeof bytes === 'string') {
bytes = Buffer.from(bytes, 'utf8');
}
return crypto.createHash('md5').update(bytes).digest();
}
export default md5;

View File

@@ -0,0 +1,84 @@
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
/**
* Represents an encoder for numbers and bigints.
*
* This type allows encoding values that are either `number` or `bigint`.
* Depending on the specific implementation, the encoded output may have a fixed or variable size.
*
* @see {@link FixedSizeNumberEncoder}
*/
export type NumberEncoder = Encoder<bigint | number>;
/**
* Represents a fixed-size encoder for numbers and bigints.
*
* This encoder serializes values using an exact number of bytes, defined by `TSize`.
*
* @typeParam TSize - The number of bytes used for encoding.
*
* @see {@link NumberEncoder}
*/
export type FixedSizeNumberEncoder<TSize extends number = number> = FixedSizeEncoder<bigint | number, TSize>;
/**
* Represents a decoder for numbers and bigints.
*
* This type supports decoding values as either `number` or `bigint`, depending on the implementation.
*
* @see {@link FixedSizeNumberDecoder}
*/
export type NumberDecoder = Decoder<bigint> | Decoder<number>;
/**
* Represents a fixed-size decoder for numbers and bigints.
*
* This decoder reads a fixed number of bytes (`TSize`) and converts them into a `number` or `bigint`.
*
* @typeParam TSize - The number of bytes expected for decoding.
*
* @see {@link NumberDecoder}
*/
export type FixedSizeNumberDecoder<TSize extends number = number> = FixedSizeDecoder<bigint, TSize> | FixedSizeDecoder<number, TSize>;
/**
* Represents a codec for encoding and decoding numbers and bigints.
*
* - The encoded value can be either a `number` or a `bigint`.
* - The decoded value will always be either a `number` or `bigint`, depending on the implementation.
*
* @see {@link FixedSizeNumberCodec}
*/
export type NumberCodec = Codec<bigint | number, bigint> | Codec<bigint | number, number>;
/**
* Represents a fixed-size codec for encoding and decoding numbers and bigints.
*
* This codec uses a specific number of bytes (`TSize`) for serialization.
* The encoded value can be either a `number` or `bigint`, but the decoded value will always be a `number` or `bigint`,
* depending on the implementation.
*
* @typeParam TSize - The number of bytes used for encoding and decoding.
*
* @see {@link NumberCodec}
*/
export type FixedSizeNumberCodec<TSize extends number = number> = FixedSizeCodec<bigint | number, bigint, TSize> | FixedSizeCodec<bigint | number, number, TSize>;
/**
* Configuration options for number codecs that use more than one byte.
*
* This configuration applies to all number codecs except `u8` and `i8`,
* allowing the user to specify the endianness of serialization.
*/
export type NumberCodecConfig = {
/**
* Specifies whether numbers should be encoded in little-endian or big-endian format.
*
* @defaultValue `Endian.Little`
*/
endian?: Endian;
};
/**
* Defines the byte order used for number serialization.
*
* - `Little`: The least significant byte is stored first.
* - `Big`: The most significant byte is stored first.
*/
export declare enum Endian {
Little = 0,
Big = 1
}
//# sourceMappingURL=common.d.ts.map

View File

@@ -0,0 +1,9 @@
/**
* Internal webcrypto alias.
* We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
* See utils.ts for details.
* @module
*/
declare const globalThis: Record<string, any> | undefined;
export const crypto: any =
typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;

View File

@@ -0,0 +1 @@
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../../src/schemes/ws.ts"],"names":[],"mappings":"AAOA,kBAAkB,YAAyB;IAC1C,OAAO,OAAO,YAAY,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC;AAC7H,CAAC;AAED,UAAU;AACV,MAAM,OAAO,GAAoB;IAChC,MAAM,EAAG,IAAI;IAEb,UAAU,EAAG,IAAI;IAEjB,KAAK,EAAG,UAAU,UAAwB,EAAE,OAAkB;QAC7D,MAAM,YAAY,GAAG,UAA0B,CAAC;QAEhD,oCAAoC;QACpC,YAAY,CAAC,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;QAE7C,wBAAwB;QACxB,YAAY,CAAC,YAAY,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9G,YAAY,CAAC,IAAI,GAAG,SAAS,CAAC;QAC9B,YAAY,CAAC,KAAK,GAAG,SAAS,CAAC;QAE/B,OAAO,YAAY,CAAC;IACrB,CAAC;IAED,SAAS,EAAG,UAAU,YAAyB,EAAE,OAAkB;QAClE,4BAA4B;QAC5B,IAAI,YAAY,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,YAAY,CAAC,IAAI,KAAK,EAAE,EAAE;YAC1F,YAAY,CAAC,IAAI,GAAG,SAAS,CAAC;SAC9B;QAED,mCAAmC;QACnC,IAAI,OAAO,YAAY,CAAC,MAAM,KAAK,SAAS,EAAE;YAC7C,YAAY,CAAC,MAAM,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC3D,YAAY,CAAC,MAAM,GAAG,SAAS,CAAC;SAChC;QAED,qCAAqC;QACrC,IAAI,YAAY,CAAC,YAAY,EAAE;YAC9B,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC3D,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YAC9D,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;YAC3B,YAAY,CAAC,YAAY,GAAG,SAAS,CAAC;SACtC;QAED,2BAA2B;QAC3B,YAAY,CAAC,QAAQ,GAAG,SAAS,CAAC;QAElC,OAAO,YAAY,CAAC;IACrB,CAAC;CACD,CAAC;AAEF,eAAe,OAAO,CAAC"}

View File

@@ -0,0 +1,124 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@typescript-eslint/utils");
const util_1 = require("../util");
exports.default = (0, util_1.createRule)({
name: 'adjacent-overload-signatures',
meta: {
type: 'suggestion',
docs: {
description: 'Require that function overload signatures be consecutive',
recommended: 'stylistic',
},
messages: {
adjacentSignature: 'All {{name}} signatures should be adjacent.',
},
schema: [],
},
defaultOptions: [],
create(context) {
/**
* Gets the name and attribute of the member being processed.
* @param member the member being processed.
* @returns the name and attribute of the member or null if it's a member not relevant to the rule.
*/
function getMemberMethod(member) {
switch (member.type) {
case utils_1.AST_NODE_TYPES.ExportDefaultDeclaration:
case utils_1.AST_NODE_TYPES.ExportNamedDeclaration: {
// export statements (e.g. export { a };)
// have no declarations, so ignore them
if (!member.declaration) {
return null;
}
return getMemberMethod(member.declaration);
}
case utils_1.AST_NODE_TYPES.TSDeclareFunction:
case utils_1.AST_NODE_TYPES.FunctionDeclaration: {
const name = member.id?.name ?? null;
if (name == null) {
return null;
}
return {
name,
type: util_1.MemberNameType.Normal,
callSignature: false,
};
}
case utils_1.AST_NODE_TYPES.TSMethodSignature:
case utils_1.AST_NODE_TYPES.MethodDefinition:
return {
...(0, util_1.getNameFromMember)(member, context.sourceCode),
callSignature: false,
static: member.static,
};
case utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
return {
name: 'call',
type: util_1.MemberNameType.Normal,
callSignature: true,
};
case utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
return {
name: 'new',
type: util_1.MemberNameType.Normal,
callSignature: false,
};
}
return null;
}
function isSameMethod(method1, method2) {
return (!!method2 &&
method1.name === method2.name &&
method1.static === method2.static &&
method1.callSignature === method2.callSignature &&
method1.type === method2.type);
}
function getMembers(node) {
switch (node.type) {
case utils_1.AST_NODE_TYPES.ClassBody:
case utils_1.AST_NODE_TYPES.Program:
case utils_1.AST_NODE_TYPES.TSModuleBlock:
case utils_1.AST_NODE_TYPES.TSInterfaceBody:
case utils_1.AST_NODE_TYPES.BlockStatement:
return node.body;
case utils_1.AST_NODE_TYPES.TSTypeLiteral:
return node.members;
}
}
function checkBodyForOverloadMethods(node) {
const members = getMembers(node);
let lastMethod = null;
const seenMethods = [];
members.forEach(member => {
const method = getMemberMethod(member);
if (method == null) {
lastMethod = null;
return;
}
const index = seenMethods.findIndex(seenMethod => isSameMethod(method, seenMethod));
if (index > -1 && !isSameMethod(method, lastMethod)) {
context.report({
node: member,
messageId: 'adjacentSignature',
data: {
name: `${method.static ? 'static ' : ''}${method.name}`,
},
});
}
else if (index === -1) {
seenMethods.push(method);
}
lastMethod = method;
});
}
return {
BlockStatement: checkBodyForOverloadMethods,
ClassBody: checkBodyForOverloadMethods,
Program: checkBodyForOverloadMethods,
TSInterfaceBody: checkBodyForOverloadMethods,
TSModuleBlock: checkBodyForOverloadMethods,
TSTypeLiteral: checkBodyForOverloadMethods,
};
},
});

View File

@@ -0,0 +1,66 @@
/**
* @fileoverview Rule to disallow `javascript:` URLs
* @author Ilya Volodin
*/
/* eslint no-script-url: 0 -- Code is checking to report such URLs */
"use strict";
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../types').Rule.RuleModule} */
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Disallow `javascript:` URLs",
recommended: false,
url: "https://eslint.org/docs/latest/rules/no-script-url",
},
schema: [],
messages: {
unexpectedScriptURL: "Script URL is a form of eval.",
},
},
create(context) {
/**
* Check whether a node's static value starts with `javascript:` or not.
* And report an error for unexpected script URL.
* @param {ASTNode} node node to check
* @returns {void}
*/
function check(node) {
const value = astUtils.getStaticStringValue(node);
if (
typeof value === "string" &&
value.toLowerCase().indexOf("javascript:") === 0
) {
context.report({ node, messageId: "unexpectedScriptURL" });
}
}
return {
Literal(node) {
if (node.value && typeof node.value === "string") {
check(node);
}
},
TemplateLiteral(node) {
if (!(
node.parent &&
node.parent.type === "TaggedTemplateExpression"
)) {
check(node);
}
},
};
},
};

View File

@@ -0,0 +1,3 @@
export function root(...p) {
return path.resolve(__dirname, "..", ...p);
}