-
Notifications
You must be signed in to change notification settings - Fork 502
add node:fs and node:fs/promises stub methods #3796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+6,421
−60
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright (c) 2017-2022 Cloudflare, Inc. | ||
| // Licensed under the Apache 2.0 license found in the LICENSE file or at: | ||
| // https://opensource.org/licenses/Apache-2.0 | ||
|
|
||
| import * as promises from 'node-internal:internal_fs_promises'; | ||
| import * as constants from 'node-internal:internal_fs_constants'; | ||
| import * as syncMethods from 'node-internal:internal_fs_sync'; | ||
| import * as callbackMethods from 'node-internal:internal_fs_callback'; | ||
| import { WriteStream, ReadStream } from 'node-internal:internal_fs_streams'; | ||
| import { Dirent, Dir } from 'node-internal:internal_fs'; | ||
|
|
||
| export * from 'node-internal:internal_fs_callback'; | ||
| export * from 'node-internal:internal_fs_sync'; | ||
| export { constants, promises, Dirent, Dir, WriteStream, ReadStream }; | ||
|
|
||
| export default { | ||
| constants, | ||
| promises, | ||
| Dirent, | ||
| Dir, | ||
| WriteStream, | ||
| ReadStream, | ||
| ...syncMethods, | ||
| ...callbackMethods, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Copyright (c) 2017-2022 Cloudflare, Inc. | ||
| // Licensed under the Apache 2.0 license found in the LICENSE file or at: | ||
| // https://opensource.org/licenses/Apache-2.0 | ||
|
|
||
| import * as fs from 'node-internal:internal_fs_promises'; | ||
| import * as constants from 'node-internal:internal_fs_constants'; | ||
|
|
||
| export * from 'node-internal:internal_fs_promises'; | ||
| export { constants }; | ||
|
|
||
| export default { | ||
| constants, | ||
| ...fs, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| export interface StatOptions { | ||
| followSymlinks?: boolean; | ||
| } | ||
|
|
||
| export interface Stat { | ||
| type: 'file' | 'directory' | 'symlink'; | ||
| size: number; | ||
| lastModified: bigint; | ||
| created: bigint; | ||
| writable: boolean; | ||
| device: boolean; | ||
| } | ||
|
|
||
| export function stat(pathOrFd: number | URL, options: StatOptions): Stat | null; | ||
| export function setLastModified( | ||
| pathOrFd: number | URL, | ||
| mtime: Date, | ||
| options: StatOptions | ||
| ): void; | ||
|
|
||
| export function truncate(pathOrFd: number | URL, length: number): void; | ||
|
|
||
| export function readLink( | ||
| path: URL, | ||
| options: { failIfNotSymlink: boolean } | ||
| ): string; | ||
|
|
||
| export function link(from: URL, to: URL, options: { symbolic: boolean }): void; | ||
|
|
||
| export function unlink(path: URL): void; | ||
|
|
||
| export function open( | ||
| path: URL, | ||
| options: { | ||
| read: boolean; | ||
| write: boolean; | ||
| append: boolean; | ||
| exclusive: boolean; | ||
| followSymlinks: boolean; | ||
| } | ||
| ): number; | ||
|
|
||
| export function close(fd: number): void; | ||
|
|
||
| export function write( | ||
| fd: number, | ||
| buffers: ArrayBufferView[], | ||
| options: { | ||
| position: number | bigint | null; | ||
| } | ||
| ): number; | ||
|
|
||
| export function read( | ||
| fd: number, | ||
| buffers: ArrayBufferView[], | ||
| options: { | ||
| position: number | bigint | null; | ||
| } | ||
| ): number; | ||
|
|
||
| export function readAll(pathOrFd: number | URL): Uint8Array; | ||
|
|
||
| export function writeAll( | ||
| pathOrFd: number | URL, | ||
| data: ArrayBufferView, | ||
| options: { append: boolean; exclusive: boolean } | ||
| ): number; | ||
|
|
||
| export function renameOrCopy( | ||
| from: URL, | ||
| to: URL, | ||
| options: { copy: boolean } | ||
| ): void; | ||
|
|
||
| export function mkdir( | ||
| path: URL, | ||
| options: { recursive: boolean; tmp: boolean } | ||
| ): string | undefined; | ||
|
|
||
| export function rm( | ||
| path: URL, | ||
| options: { recursive: boolean; force: boolean; dironly: boolean } | ||
| ): void; | ||
|
|
||
| export interface DirEntryHandle { | ||
| name: string; | ||
| parentPath: string; | ||
| type: number; | ||
| } | ||
|
|
||
| export function readdir( | ||
| path: URL, | ||
| options: { recursive: boolean } | ||
| ): DirEntryHandle[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { | ||
| UV_DIRENT_DIR, | ||
| UV_DIRENT_FILE, | ||
| UV_DIRENT_BLOCK, | ||
| UV_DIRENT_CHAR, | ||
| UV_DIRENT_LINK, | ||
| UV_DIRENT_FIFO, | ||
| UV_DIRENT_SOCKET, | ||
| } from 'node-internal:internal_fs_constants'; | ||
| import { getOptions } from 'node-internal:internal_fs_utils'; | ||
| import { validateFunction, validateUint32 } from 'node-internal:validators'; | ||
| import { ERR_MISSING_ARGS } from 'node-internal:internal_errors'; | ||
|
|
||
| const kType = Symbol('type'); | ||
|
|
||
| export class Dirent { | ||
| public name: string; | ||
| public parentPath: string; | ||
| private [kType]: number; | ||
|
|
||
| public constructor(name: string, type: number, path: string) { | ||
| this.name = name; | ||
| this.parentPath = path; | ||
| this[kType] = type; | ||
| } | ||
|
|
||
| public isDirectory(): boolean { | ||
| return this[kType] === UV_DIRENT_DIR; | ||
| } | ||
|
|
||
| public isFile(): boolean { | ||
| return this[kType] === UV_DIRENT_FILE; | ||
| } | ||
|
|
||
| public isBlockDevice(): boolean { | ||
| return this[kType] === UV_DIRENT_BLOCK; | ||
| } | ||
|
|
||
| public isCharacterDevice(): boolean { | ||
| return this[kType] === UV_DIRENT_CHAR; | ||
| } | ||
|
|
||
| public isSymbolicLink(): boolean { | ||
| return this[kType] === UV_DIRENT_LINK; | ||
| } | ||
|
|
||
| public isFIFO(): boolean { | ||
| return this[kType] === UV_DIRENT_FIFO; | ||
| } | ||
|
|
||
| public isSocket(): boolean { | ||
| return this[kType] === UV_DIRENT_SOCKET; | ||
| } | ||
| } | ||
|
|
||
| export class Dir { | ||
| // @ts-expect-error TS6133 Value is not read. | ||
| #handle: unknown; // eslint-disable-line no-unused-private-class-members | ||
| #path: string; | ||
| #options: Record<string, unknown>; | ||
|
|
||
| public constructor( | ||
| handle: unknown, | ||
| path: string, | ||
| options: Record<string, unknown> | ||
| ) { | ||
| if (handle == null) { | ||
| throw new ERR_MISSING_ARGS('handle'); | ||
| } | ||
| this.#handle = handle; | ||
| this.#path = path; | ||
| this.#options = { | ||
| bufferSize: 32, | ||
| ...getOptions(options, { | ||
| encoding: 'utf8', | ||
| }), | ||
| }; | ||
|
|
||
| validateUint32(this.#options.bufferSize, 'options.bufferSize', true); | ||
| } | ||
|
|
||
| public get path(): string { | ||
| return this.#path; | ||
| } | ||
|
|
||
| public read(callback: unknown): void { | ||
| validateFunction(callback, 'callback'); | ||
| throw new Error('Not implemented'); | ||
| } | ||
|
|
||
| public processReadResult(): void { | ||
| throw new Error('Not implemented'); | ||
| } | ||
|
|
||
| public readSyncRecursive(): void { | ||
| throw new Error('Not implemented'); | ||
| } | ||
|
|
||
| public readSync(): void { | ||
| throw new Error('Not implemented'); | ||
| } | ||
|
|
||
| public close(): void { | ||
| throw new Error('Not implemented'); | ||
| } | ||
|
|
||
| public closeSync(): void { | ||
| throw new Error('Not implemented'); | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/require-await,require-yield | ||
| public async *entries(): AsyncGenerator<unknown, unknown, unknown> { | ||
| throw new Error('Not implemented'); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.