Skip to content

Commit 2abbefc

Browse files
code-asherkylecarbs
authored andcommitted
Update Node fills due to updated types package
1 parent d94d12a commit 2abbefc

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

packages/node-browser/src/child_process.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function fork(modulePath: string): cp.ChildProcess {
161161
}));
162162
}
163163

164-
function spawn(_command: string, _args?: ReadonlyArray<string>, _options?: cp.SpawnOptions): cp.ChildProcess {
164+
function spawn(_command: string, _args?: ReadonlyArray<string> | cp.SpawnOptions, _options?: cp.SpawnOptions): cp.ChildProcess {
165165
throw new Error("not implemented");
166166
}
167167
// tslint:enable only-arrow-functions

packages/node-browser/src/fs.ts

+15-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ReaddirQueue extends Queue<ReaddirCallback> {
3030
const stdio = await promisify(exec)(`bash -c '${keys.map((key) => `cd ${escapePath(key)} && ls -1a; echo;`).join(" ")}'`);
3131
stdio.stdout.trim().split("\n\n").forEach((split, index) => {
3232
const path = keys[index];
33-
const cbs = items.get(path);
33+
const cbs = items.get(path)!;
3434
if (split.indexOf("does not exist") !== -1) {
3535
cbs.forEach((cb) => {
3636
cb({
@@ -262,7 +262,7 @@ function appendFile(
262262
// @ts-ignore not sure how to make this work.
263263
return callback(new Error("not open"), undefined as any); // tslint:disable-line no-any
264264
}
265-
path = openFiles.get(path).path;
265+
path = openFiles.get(path)!.path;
266266
}
267267

268268
const process = exec(`${data ? "cat >>" : "touch"} ${escapePath(path.toString())}`, (error) => {
@@ -310,7 +310,7 @@ function fstat(fd: number, callback: (err: NodeJS.ErrnoException, stats: fs.Stat
310310
if (!openFiles.has(fd)) {
311311
return callback(new Error("not open"), null as any); // tslint:disable-line no-any
312312
}
313-
stat(openFiles.get(fd).path, callback);
313+
stat(openFiles.get(fd)!.path, callback);
314314
}
315315

316316
function futimes(
@@ -323,7 +323,7 @@ function futimes(
323323
return callback(new Error("not opened"));
324324
}
325325

326-
const openFile = openFiles.get(fd);
326+
const openFile = openFiles.get(fd)!;
327327
const command = [
328328
{ flag: "a", time: atime },
329329
{ flag: "m", time: mtime },
@@ -344,7 +344,7 @@ function lstat(path: fs.PathLike, callback: (err: NodeJS.ErrnoException, stats:
344344
}
345345

346346
function mkdir(
347-
path: fs.PathLike, mode: number | string | undefined | null | ((err: NodeJS.ErrnoException) => void),
347+
path: fs.PathLike, mode: number | string | fs.MakeDirectoryOptions | undefined | null | ((err: NodeJS.ErrnoException) => void),
348348
callback?: (err: NodeJS.ErrnoException) => void,
349349
): void {
350350
execAndCallback(
@@ -391,7 +391,7 @@ function open(
391391
});
392392
}
393393

394-
function read<TBuffer extends Buffer | Uint8Array>(
394+
function read<TBuffer extends fs.BinaryData>(
395395
fd: number,
396396
buffer: TBuffer,
397397
offset: number,
@@ -409,7 +409,7 @@ function read<TBuffer extends Buffer | Uint8Array>(
409409
}
410410

411411
const hasPosition = typeof position === "number";
412-
const openFile = openFiles.get(fd);
412+
const openFile = openFiles.get(fd)!;
413413

414414
if (!hasPosition) {
415415
position = openFile.position || 0;
@@ -427,6 +427,7 @@ function read<TBuffer extends Buffer | Uint8Array>(
427427

428428
const output = data.slice(position!, position! + length);
429429
if (output.length !== 0) {
430+
// TODO: seems to be no more set with v10, but need to decide if we'll be running v10.
430431
buffer.set(output, offset);
431432
}
432433

@@ -459,7 +460,7 @@ function readFile(
459460
// @ts-ignore not sure how to make this work.
460461
return callback(new Error("not open"), undefined as any); // tslint:disable-line no-any
461462
}
462-
path = openFiles.get(path).path;
463+
path = openFiles.get(path)!.path;
463464
}
464465

465466
readFileQueue.add(path.toString(), (error, result) => {
@@ -473,8 +474,8 @@ function readFile(
473474

474475
function readdir(
475476
path: fs.PathLike,
476-
options: { encoding?: string | null } | string | undefined | null | ((err: NodeJS.ErrnoException, files: string[]) => void),
477-
callback?: ((err: NodeJS.ErrnoException, files: string[]) => void) | ((err: NodeJS.ErrnoException, files: Buffer[]) => void) | ((err: NodeJS.ErrnoException, files: Array<string | Buffer>) => void),
477+
options: { encoding?: string | null, withFileTypes?: boolean } | string | undefined | null | ((err: NodeJS.ErrnoException, files: string[]) => void),
478+
callback?: ((err: NodeJS.ErrnoException, files: string[]) => void) | ((err: NodeJS.ErrnoException, files: Buffer[]) => void) | ((err: NodeJS.ErrnoException, files: fs.Dirent[]) => void)
478479
): void {
479480
if (typeof options === "function") {
480481
callback = options;
@@ -596,7 +597,7 @@ function writeFile(
596597
// @ts-ignore not sure how to make this work.
597598
return callback(new Error("not open"), undefined as any); // tslint:disable-line no-any
598599
}
599-
path = openFiles.get(path).path;
600+
path = openFiles.get(path)!.path;
600601
}
601602

602603
const process = exec(`${data ? "cat >" : "touch"} ${escapePath(path.toString())}`, (error) => {
@@ -627,13 +628,16 @@ rmdir.__promisify__ = undefined as any;
627628
stat.__promisify__ = undefined as any;
628629
unlink.__promisify__ = undefined as any;
629630
writeFile.__promisify__ = undefined as any;
631+
realpath.native = undefined as any;
630632
// tslint:enable no-any
631633

632634
const exp: typeof fs = {
633635
constants: fs.constants,
634636
Stats: fs.Stats,
635637
ReadStream: fs.ReadStream,
636638
WriteStream: fs.WriteStream,
639+
Dirent: fs.Dirent,
640+
promises: fs.promises,
637641

638642
access: throwUnimplementedError,
639643
accessSync: throwSyncError,

packages/node-browser/src/util.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ throwUnimplementedError.link = undefined as any;
1010
export const throwSyncError = (): any => {
1111
throw new Error("sync is not supported");
1212
};
13+
// realpath & realpathSync.
14+
throwSyncError.native = undefined as any;
1315
// tslint:enable no-any
1416

1517
/**

0 commit comments

Comments
 (0)