fake-node 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_fs.d.ts +254 -0
- package/lib/_fs.js +750 -0
- package/lib/_fs.js.map +1 -0
- package/lib/buffer.d.ts +9 -0
- package/lib/buffer.js +12 -0
- package/lib/buffer.js.map +1 -0
- package/lib/fs.d.ts +110 -0
- package/lib/fs.js +223 -0
- package/lib/fs.js.map +1 -0
- package/lib/index.d.ts +34 -13
- package/lib/index.js +113 -37
- package/lib/index.js.map +1 -0
- package/lib/os.js +3 -13
- package/lib/os.js.map +1 -0
- package/lib/path.d.ts +55 -0
- package/lib/path.js +105 -0
- package/lib/path.js.map +1 -0
- package/lib/process.js +2 -9
- package/lib/process.js.map +1 -0
- package/lib/querystring.js +1 -0
- package/lib/querystring.js.map +1 -0
- package/lib/util.d.ts +145 -0
- package/lib/util.js +460 -0
- package/lib/util.js.map +1 -0
- package/package.json +5 -2
- package/src/_fs.ts +852 -0
- package/src/buffer.ts +13 -0
- package/src/fs.ts +168 -455
- package/src/in_fake_node.d.ts +12 -0
- package/src/index.ts +134 -42
- package/src/os.ts +3 -10
- package/src/path.ts +141 -0
- package/src/process.ts +2 -20
- package/src/util.ts +126 -13
package/src/util.ts
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
/// <reference path="./in_fake_node.d.ts" />
|
3
|
+
import {emitWarning} from './process';
|
3
4
|
|
5
|
+
export type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array;
|
4
6
|
|
5
|
-
type
|
6
|
-
type Callback = (error: Error | null, value: any) => void;
|
7
|
+
export type Callback = (error: Error | null, value: unknown) => void;
|
7
8
|
|
8
9
|
function shouldBeCloneable(value: unknown): boolean {
|
9
10
|
return value?.constructor === Object || value === undefined || value === null || typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string' || typeof value === 'bigint' || Array.isArray(value) || value instanceof ArrayBuffer || value instanceof Boolean || value instanceof DataView || value instanceof Date || value instanceof Error || value instanceof Map || value instanceof Number || value instanceof RegExp || value instanceof Set || value instanceof String || value instanceof Object.getPrototypeOf(Uint8Array) || value instanceof AudioData || value instanceof Blob || value instanceof CryptoKey || value instanceof DOMException || value instanceof DOMMatrix || value instanceof DOMMatrixReadOnly || value instanceof DOMPoint || value instanceof DOMPointReadOnly || value instanceof DOMQuad || value instanceof DOMRect || value instanceof DOMRectReadOnly || value instanceof EncodedAudioChunk || value instanceof EncodedVideoChunk || value instanceof File || value instanceof FileList || value instanceof FileSystemDirectoryHandle || value instanceof FileSystemFileHandle || value instanceof FileSystemHandle || value instanceof ImageBitmap || value instanceof ImageData || value instanceof RTCCertificate || value instanceof RTCEncodedAudioFrame || value instanceof RTCEncodedVideoFrame || value instanceof VideoFrame || value instanceof WebTransportError;
|
10
11
|
}
|
11
12
|
|
12
|
-
|
13
13
|
export function callbackify(original: (...args: any[]) => Promise<any>): (...args: [...any[], Callback]) => void {
|
14
14
|
return function(...args: [...any[], Callback]): void {
|
15
15
|
const callback = args[args.length - 1];
|
@@ -19,9 +19,9 @@ export function callbackify(original: (...args: any[]) => Promise<any>): (...arg
|
|
19
19
|
}
|
20
20
|
|
21
21
|
export function debuglog(section: string, callback: (message: string) => void = console.log): ((message: string) => void) & {enabled: boolean} {
|
22
|
-
if (typeof env.NODE_DEBUG === 'string' && env.NODE_DEBUG.includes(section)) {
|
22
|
+
if (typeof __fakeNode_process__.env.NODE_DEBUG === 'string' && __fakeNode_process__.env.NODE_DEBUG.includes(section)) {
|
23
23
|
return Object.assign(function(message: string): void {
|
24
|
-
callback(`${env.NODE_DEBUG.toUpperCase()} ${__fakeNode_process__.pid}: ${message}`);
|
24
|
+
callback(`${__fakeNode_process__.env.NODE_DEBUG.toUpperCase()} ${__fakeNode_process__.pid}: ${message}`);
|
25
25
|
}, {enabled: true});
|
26
26
|
} else {
|
27
27
|
return Object.assign(() => {}, {enabled: true});
|
@@ -132,10 +132,12 @@ export function inherits(constructor: Function, superConstructor: Function) {
|
|
132
132
|
Object.setPrototypeOf(constructor.prototype, superConstructor.prototype);
|
133
133
|
}
|
134
134
|
|
135
|
-
|
135
|
+
interface InspectOptions {
|
136
|
+
|
137
|
+
}
|
136
138
|
|
137
139
|
export function inspect(value: unknown, options: InspectOptions = {}): string {
|
138
|
-
|
140
|
+
throw new TypeError('util.inspect is not supported in fake-node');
|
139
141
|
}
|
140
142
|
|
141
143
|
export function isDeepStrictEqual(val1: unknown, val2: unknown): boolean {
|
@@ -143,7 +145,10 @@ export function isDeepStrictEqual(val1: unknown, val2: unknown): boolean {
|
|
143
145
|
if (!(typeof val2 === 'object' && val2 !== null) && !(typeof val2 === 'function')) {
|
144
146
|
return false;
|
145
147
|
}
|
146
|
-
if ((val1
|
148
|
+
if ((Symbol.toStringTag in val1 && Symbol.toStringTag in val2) && val1[Symbol.toStringTag] !== val2[Symbol.toStringTag]) {
|
149
|
+
return false;
|
150
|
+
}
|
151
|
+
if (Object.getPrototypeOf(val1) !== Object.getPrototypeOf(val2)) {
|
147
152
|
return false;
|
148
153
|
}
|
149
154
|
if (val1 instanceof Map) {
|
@@ -175,12 +180,13 @@ export function isDeepStrictEqual(val1: unknown, val2: unknown): boolean {
|
|
175
180
|
}
|
176
181
|
return true;
|
177
182
|
}
|
178
|
-
const properties =
|
183
|
+
const properties = Reflect.ownKeys(val1);
|
179
184
|
const val2Properties = (Object.getOwnPropertyNames(val2) as (string | symbol)[]).concat(Object.getOwnPropertySymbols(val2));
|
180
185
|
if (!properties.every((prop: string | symbol) => val2Properties.includes(prop))) {
|
181
186
|
return false;
|
182
187
|
}
|
183
188
|
for (const property of properties) {
|
189
|
+
// @ts-ignore
|
184
190
|
if (!isDeepStrictEqual(val1[property], val2[property])) {
|
185
191
|
return false;
|
186
192
|
}
|
@@ -199,6 +205,114 @@ export function isDeepStrictEqual(val1: unknown, val2: unknown): boolean {
|
|
199
205
|
}
|
200
206
|
}
|
201
207
|
|
208
|
+
export class MIMEType {
|
209
|
+
|
210
|
+
constructor() {
|
211
|
+
throw new TypeError('util.MIMEType is not supported in fake-node');
|
212
|
+
}
|
213
|
+
|
214
|
+
}
|
215
|
+
|
216
|
+
export class MIMEParams {
|
217
|
+
|
218
|
+
constructor() {
|
219
|
+
throw new TypeError('util.MIMEParams is not supported in fake-node');
|
220
|
+
}
|
221
|
+
|
222
|
+
}
|
223
|
+
|
224
|
+
interface ParseArgsConfig {
|
225
|
+
args?: string[];
|
226
|
+
options: {
|
227
|
+
[key: string]: {
|
228
|
+
short?: string;
|
229
|
+
} & (({multiple: false} & ({
|
230
|
+
type: 'string';
|
231
|
+
default?: string;
|
232
|
+
} | {
|
233
|
+
type: 'boolean';
|
234
|
+
default?: boolean;
|
235
|
+
})) | ({multiple: true} & ({
|
236
|
+
type: 'string';
|
237
|
+
default?: string[];
|
238
|
+
} | {
|
239
|
+
type: 'boolean';
|
240
|
+
default?: boolean[];
|
241
|
+
}))
|
242
|
+
);
|
243
|
+
};
|
244
|
+
strict?: boolean;
|
245
|
+
allowPositionals?: boolean;
|
246
|
+
allowNegative?: boolean;
|
247
|
+
tokens?: boolean;
|
248
|
+
}
|
249
|
+
|
250
|
+
export function parseArgs(config?: ParseArgsConfig): {values: {[key: string]: string | boolean}, positionals: string[], tokens?: object[]} {
|
251
|
+
throw new TypeError('util.parseArgs is not supported in fake-node');
|
252
|
+
}
|
253
|
+
|
254
|
+
export function parseEnv(content: string): {[key: string]: string} {
|
255
|
+
throw new TypeError('util.parseEnv is not supported in fake-node');
|
256
|
+
}
|
257
|
+
|
258
|
+
export function promisify(original: ((...args: [...any[], Callback]) => void) & {[func: typeof promisify.custom]: (...args: any[]) => Promise<any>}): (...args: any[]) => Promise<any> {
|
259
|
+
if (promisify.custom in original) {
|
260
|
+
return original[promisify.custom];
|
261
|
+
}
|
262
|
+
return function(...args: any[]): Promise<any> {
|
263
|
+
return new Promise((resolve, reject) => {
|
264
|
+
original(args, (error: Error | null, value: unknown) => {
|
265
|
+
if (error instanceof Error) {
|
266
|
+
reject(error);
|
267
|
+
} else {
|
268
|
+
resolve(value);
|
269
|
+
}
|
270
|
+
});
|
271
|
+
});
|
272
|
+
};
|
273
|
+
}
|
274
|
+
promisify.custom = Symbol.for('nodejs.util.promisify.custom');
|
275
|
+
|
276
|
+
export function stripVTControlCharacters(str: string): string {
|
277
|
+
throw new TypeError('util.stripVTControlCharacters is not supported in fake-node');
|
278
|
+
}
|
279
|
+
|
280
|
+
export function styleText(format: string | Array<unknown>, text: string, options?: {validateStream: boolean, stream: unknown}): string {
|
281
|
+
throw new TypeError('util.styleText is not supported in fake-node');
|
282
|
+
}
|
283
|
+
|
284
|
+
const TextDecoder_ = TextDecoder;
|
285
|
+
const TextEncoder_ = TextEncoder;
|
286
|
+
export {
|
287
|
+
TextDecoder_ as TextDecoder,
|
288
|
+
TextEncoder_ as TextEncoder,
|
289
|
+
};
|
290
|
+
|
291
|
+
export function toUSVString(string: string): string {
|
292
|
+
let out = '';
|
293
|
+
for (let i = 0; i < string.length; i++) {
|
294
|
+
const code = string.charCodeAt(i);
|
295
|
+
if (code >= 0xD800 && code < 0xDFFF) {
|
296
|
+
out += '\uFFFD';
|
297
|
+
} else {
|
298
|
+
out += string[i];
|
299
|
+
}
|
300
|
+
}
|
301
|
+
return out;
|
302
|
+
}
|
303
|
+
|
304
|
+
export function transferableAbortController(): AbortController {
|
305
|
+
throw new TypeError('util.transferableAbortController is not supported in fake-node');
|
306
|
+
}
|
307
|
+
|
308
|
+
export function transferableAbortSignal(): AbortSignal {
|
309
|
+
throw new TypeError('util.transferableAbortSignal is not supported in fake-node');
|
310
|
+
}
|
311
|
+
|
312
|
+
export function aborted(signal: AbortSignal, resource: object): Promise<undefined> {
|
313
|
+
throw new TypeError('util.aborted is not supported in fake-node');
|
314
|
+
}
|
315
|
+
|
202
316
|
export const types = {
|
203
317
|
|
204
318
|
isAnyArrayBuffer(value: unknown): value is (ArrayBuffer | SharedArrayBuffer) {
|
@@ -210,15 +324,14 @@ export const types = {
|
|
210
324
|
},
|
211
325
|
|
212
326
|
isArgumentsObject(value: unknown): value is typeof arguments {
|
213
|
-
if (typeof value !== 'object' || value === null || !
|
327
|
+
if (typeof value !== 'object' || value === null || !('length' in value) || !('callee' in value)) {
|
214
328
|
return false;
|
215
329
|
}
|
216
330
|
try {
|
217
|
-
// @ts-ignore
|
218
331
|
value.callee;
|
219
332
|
return false;
|
220
333
|
} catch (error) {
|
221
|
-
if (error.message === "TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them" || error.message === "TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context.") {
|
334
|
+
if (error instanceof Error && (error.message === "TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them" || error.message === "TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context.")) {
|
222
335
|
return types.isProxy(value) !== true;
|
223
336
|
} else {
|
224
337
|
throw error;
|