1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00
denoland-deno/cli
nasa 25fdc7bf6c
feat(node_compat): Added base implementation of FileHandle (#19294)
<!--
Before submitting a PR, please read https://deno.com/manual/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't
run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench'
label.
-->


## WHY

ref: https://github.com/denoland/deno/issues/19165

Node's fs/promises includes a FileHandle class, but deno does not. The
open function in Node's fs/promises returns a FileHandle, which provides
an IO interface to the file. However, deno's open function returns a
resource id.


### deno 

```js
> const fs = await import("node:fs/promises");
undefined
> const file3 = await fs.open("./README.md");
undefined
> file3
3
> file3.read
undefined
Node:
```

### Node
```js
> const fs = await import("fs/promises");
undefined
>   const file3 = await fs.open("./tests/e2e_unit/testdata/file.txt");
undefined
> file3
FileHandle {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  close: [Function: close],
  [Symbol(kCapture)]: false,
  [Symbol(kHandle)]: FileHandle {},
  [Symbol(kFd)]: 24,
  [Symbol(kRefs)]: 1,
  [Symbol(kClosePromise)]: null
}
> file3.read
[Function: read]
```


To be compatible with Node, deno's open function should also return a
FileHandle.

## WHAT

I have implemented the first step in adding a FileHandle.

- Changed the return value of the open function to a FileHandle object
- Implemented the readFile method in FileHandle
- Add test code


## What to do next
This PR is the first step in adding a FileHandle, and there are things
that should be done next.

- Add functionality equivalent to Node's FileHandle to FileHandle
(currently there is only readFile)

---------

Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-06-02 08:28:05 -06:00
..
args fix(compile): handle when DENO_DIR is readonly (#19257) 2023-05-25 14:27:45 -04:00
bench chore: remove useless benchmark (#19272) 2023-05-26 13:26:21 +00:00
cache fix: do not show cache initialization errors if stderr is piped (#18920) 2023-05-30 13:35:02 -04:00
js fix(ext/web): improve timers resolution for 0ms timeouts (#19212) 2023-05-22 14:09:31 +02:00
lsp refactor(core): remove ext: modules from the module map (#19040) 2023-05-28 12:44:41 -06:00
napi chore: forward v1.34.1 to main (#19312) 2023-05-29 20:26:03 -06:00
npm refactor: upgrade to deno_npm 0.6 (#19244) 2023-05-24 16:23:10 -04:00
ops refactor(node): move most of cli/node to ext/node (#18797) 2023-04-21 21:02:46 -04:00
schemas feat: add support for globs in the config file and CLI arguments for files (#19102) 2023-05-23 03:39:59 +02:00
standalone feat(runtime): add WorkerLogLevel (#19316) 2023-05-30 15:34:50 +00:00
tests feat(node_compat): Added base implementation of FileHandle (#19294) 2023-06-02 08:28:05 -06:00
tools fix(compile): handle when DENO_DIR is readonly (#19257) 2023-05-25 14:27:45 -04:00
tsc refactor(core): remove ext: modules from the module map (#19040) 2023-05-28 12:44:41 -06:00
util refactor(core): bake single-thread assumptions into spawn/spawn_blocking (#19056) 2023-05-14 15:40:01 -06:00
auth_tokens.rs chore: upgrade to Rust 1.67 (#17548) 2023-01-27 10:43:16 -05:00
build.rs chore(core): Split JsRuntimeForSnapshot from JsRuntime (#19308) 2023-05-31 08:19:06 -06:00
Cargo.toml chore: forward v1.34.1 to main (#19312) 2023-05-29 20:26:03 -06:00
deno.ico fix(cli): add icon and metadata to deno.exe on Windows (#6693) 2020-07-15 21:54:38 +02:00
deno_std.rs chore: forward v1.34.1 to main (#19312) 2023-05-29 20:26:03 -06:00
emit.rs refactor: break up ProcState (#18707) 2023-04-14 16:22:33 -04:00
errors.rs feat: TypeScript 5.0.2 (except decorators) (#18294) 2023-03-21 15:46:40 +00:00
factory.rs feat(runtime): add WorkerLogLevel (#19316) 2023-05-30 15:34:50 +00:00
file_fetcher.rs feat(unstable): add more options to Deno.createHttpClient (#17385) 2023-05-21 03:43:54 +02:00
graph_util.rs refactor(core): remove ext: modules from the module map (#19040) 2023-05-28 12:44:41 -06:00
http_util.rs feat(unstable): add more options to Deno.createHttpClient (#17385) 2023-05-21 03:43:54 +02:00
js.rs refactor(core): Improve ergonomics of managing ASCII strings (#18498) 2023-04-04 06:46:31 -06:00
main.rs Revert "perf: use jemalloc as global allocator (#18957)" (#19187) 2023-05-19 09:10:33 -04:00
module_loader.rs refactor(core): don't pass op state to prepare_module_load() (#19332) 2023-05-31 23:35:14 -06:00
node.rs refactor(ext/node): allow injecting NodeFs from CLI (#18829) 2023-04-24 19:44:35 -04:00
README.md docs(cli): do not need gen doc for cli (#17260) 2023-01-04 13:19:58 +01:00
resolver.rs feat: top level package.json install when node_modules dir is explicitly opted into (#19233) 2023-05-23 18:51:48 -04:00
version.rs refactor: make version and user_agent &'static str (#18400) 2023-03-23 23:27:58 +01:00
watcher.rs refactor(cli): remove ProcState - add CliFactory (#18900) 2023-05-01 14:35:23 -04:00
worker.rs feat(runtime): add WorkerLogLevel (#19316) 2023-05-30 15:34:50 +00:00

Deno CLI Crate

crates

This provides the actual deno executable and the user-facing APIs.

The deno crate uses the deno_core to provide the executable.