summaryrefslogtreecommitdiff
path: root/ext/node/lib.rs
AgeCommit message (Collapse)Author
2023-08-21refactor: upgrade deno_ast 0.28 and deno_semver 0.4 (#20193)David Sherret
2023-08-16feat(ext/node): eagerly bootstrap node (#20153)Matt Mastracci
To fix bugs around detection of when node emulation is required, we will just eagerly initialize it. The improvements we make to reduce the impact of the startup time: - [x] Process stdin/stdout/stderr are lazily created - [x] node.js global proxy no longer allocates on each access check - [x] Process checks for `beforeExit` listeners before doing expensive shutdown work - [x] Process should avoid adding global event handlers until listeners are added Benchmarking this PR (`89de7e1ff`) vs main (`41cad2179`) ``` 12:36 $ third_party/prebuilt/mac/hyperfine --warmup 100 -S none './deno-41cad2179 run ./empty.js' './deno-89de7e1ff run ./empty.js' Benchmark 1: ./deno-41cad2179 run ./empty.js Time (mean ± σ): 24.3 ms ± 1.6 ms [User: 16.2 ms, System: 6.0 ms] Range (min … max): 21.1 ms … 29.1 ms 115 runs Benchmark 2: ./deno-89de7e1ff run ./empty.js Time (mean ± σ): 24.0 ms ± 1.4 ms [User: 16.3 ms, System: 5.6 ms] Range (min … max): 21.3 ms … 28.6 ms 126 runs ``` Fixes https://github.com/denoland/deno/issues/20142 Fixes https://github.com/denoland/deno/issues/15826 Fixes https://github.com/denoland/deno/issues/20028
2023-08-06build: allow disabling snapshots for dev (#20048)Nayeem Rahman
Closes #19399 (running without snapshots at all was suggested as an alternative solution). Adds a `__runtime_js_sources` pseudo-private feature to load extension JS sources at runtime for faster development, instead of building and loading snapshots or embedding sources in the binary. Will only work in a development environment obviously. Try running `cargo test --features __runtime_js_sources integration::node_unit_tests::os_test`. Then break some behaviour in `ext/node/polyfills/os.ts` e.g. make `function cpus() {}` return an empty array, and run it again. Fix and then run again. No more build time in between.
2023-08-04fix(node): repl._builtinLibs (#20046)Bartek Iwańczuk
Ref https://github.com/denoland/deno/issues/19733
2023-08-02feat(node): add polyfill for node:test module (#20002)Bartek Iwańczuk
This commit provides basic polyfill for "node:test" module. Currently only top-level "test" function is polyfilled, all remaining functions from that module throw not implemented errors.
2023-07-31feat(node/os): implement getPriority, setPriority & userInfo (#19370)Leo Kettmeir
Takes #4202 over Closes #17850 --------- Co-authored-by: ecyrbe <ecyrbe@gmail.com>
2023-07-31refactor: update core extension api usage (#19952)Nayeem Rahman
2023-07-19feat(ext/node): properly segregate node globals (#19307)Luca Casonato
Code run within Deno-mode and Node-mode should have access to a slightly different set of globals. Previously this was done through a compile time code-transform for Node-mode, but this is not ideal and has many edge cases, for example Node's globalThis having a different identity than Deno's globalThis. This commit makes the `globalThis` of the entire runtime a semi-proxy. This proxy returns a different set of globals depending on the caller's mode. This is not a full proxy, because it is shadowed by "real" properties on globalThis. This is done to avoid the overhead of a full proxy for all globalThis operations. The globals between Deno-mode and Node-mode are now properly segregated. This means that code running in Deno-mode will not have access to Node's globals, and vice versa. Deleting a managed global in Deno-mode will NOT delete the corresponding global in Node-mode, and vice versa. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Aapo Alasuutari <aapo.alasuutari@gmail.com>
2023-07-17fix(node): improve require esm error messages (#19853)David Sherret
Part of #19842. Closes #19583 Closes #16913
2023-07-06perf(node/async_hooks): optimize AsyncLocalStorage (#19729)Bartek Iwańczuk
This makes the implementation of "AsyncLocalStorage" from "node:async_hooks" 3.5x faster than before for noop benchmark (measuring baseline overhead). It's still 3.5x slower than not using `AsyncLocalStorage` and 1.64x slower than using noop promise hooks.
2023-07-05perf(ext/node): optimize net streams (#19678)Divy Srivastava
~4.5x improvement in `npm:ws` echo benchmark: ``` $ ./load_test 10 0.0.0.0 8080 0 0 Using message size of 20 bytes Running benchmark now... Msg/sec: 101083.750000 Msg/sec: 103606.000000 ^C $ ./load_test 10 0.0.0.0 8080 0 0 Using message size of 20 bytes Running benchmark now... Msg/sec: 24906.750000 Msg/sec: 28478.000000 ^C ```
2023-07-02refactor: rename built-in node modules from ext:deno_node/ to node: (#19680)Bartek Iwańczuk
Closes https://github.com/denoland/deno/issues/19510
2023-06-27test(ext/node): port crypto_test.ts from deno_std (#19561)Felipe Baltor
2023-06-24fix(ext/node): support brotli APIs (#19223)Divy Srivastava
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-06-22refactor(npm): remove needless resolve_nv_ref_from_pkg_req_ref on ↵David Sherret
NpmResolver (#19582)
2023-06-02feat(node_compat): Added base implementation of FileHandle (#19294)nasa
<!-- 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-05-28refactor(core): remove ext: modules from the module map (#19040)Nayeem Rahman
Rather than disallowing `ext:` resolution, clear the module map after initializing extensions so extension modules are anonymized. This operation is explicitly called in `deno_runtime`. Re-inject `node:` specifiers into the module map after doing this. Fixes #17717.
2023-05-27refactor(node/http): don't use readablestream for writing to request (#19282)Leo Kettmeir
Refactors the internal usage of a readablestream to write to the resource directly --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-05-17fix(ext/node): make nodeGlobalThis configurable (#19163)Luca Casonato
2023-05-17refactor(node): reimplement http client (#19122)Leo Kettmeir
This commit reimplements most of "node:http" client APIs using "ext/fetch". There is some duplicated code and two removed Node compat tests that will be fixed in follow up PRs. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-05-15feat(node/crypto): Diffie Hellman Support (#18943)Levente Kurusa
Support crypto.DiffieHellman class in ext/node/crypto
2023-05-08refactor(ext/fs): `deno_fs::FileSystem` - conditional `Send + Sync` (#18993)David Sherret
This allows for having a conditional `Send + Sync` on the file system trait for Deploy.
2023-05-05refactor(ext/node): combine `deno_node::Fs` with `deno_fs::FileSystem` (#18991)David Sherret
2023-05-04refactor(ext/node): remove NodeEnv trait (#18986)Luca Casonato
2023-04-27feat(node/crypto): Elliptic Curve Diffie-Hellman (ECDH) support (#18832)Levente Kurusa
- ECDH class - crypto.createECDH() - Supported curves: - secp256k1 - prime256v1 / secp256r1 - secp384r1 - secp224r1 Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-04-27fix(ext/node): prime generation (#18861)Divy Srivastava
Towards https://github.com/denoland/deno/issues/18455 `safe`, `add` and `rem` options are not implemented because there is no rust crate that provides this functionality (except rust-openssl maybe) and its just not clear if this API is used widely.
2023-04-27refactor(cli): extract out ProcState from CliMainWorker (#18867)David Sherret
2023-04-26refactor(ext/node): use a snapshottable global name for Node's globalThis ↵David Sherret
(#18860)
2023-04-24refactor(ext/node): enforce interior mutable for `NodePermissions` to remove ↵David Sherret
clones (#18831) We can make `NodePermissions` rely on interior mutability (which the `PermissionsContainer` is already doing) in order to not have to clone everything all the time. This also reduces the chance of an accidental `borrow` while `borrrow_mut`.
2023-04-24refactor(ext/node): allow injecting `NodeFs` from CLI (#18829)David Sherret
This allows providing a `NodeFs` as part of the `WorkerOptions`.
2023-04-24refactor(ext/node): reorganize ops (#18799)Bartek Iwańczuk
Move all op related code of "ext/node" to "ext/node/ops" module. These files were unnecessarily scattered around the extension.
2023-04-21refactor(node): move most of cli/node to ext/node (#18797)David Sherret
This is just a straight refactor and I didn't do any cleanup in ext/node. After this PR we can start to clean it up and make things private that don't need to be public anymore.
2023-04-21refactor: move some CJS and ESM code analysis to ext/node (#18789)David Sherret
2023-04-20refactor(ext/node): remove polyfills/_core.ts (#18766)Yoshiya Hinosawa
2023-04-19fix(ext/node): implement asymmetric keygen (#18651)Divy Srivastava
Towards #18455 This commit implements the keypair generation for asymmetric keys for the `generateKeyPair` API. See how key material is managed in this implementation: https://www.notion.so/denolandinc/node-crypto-design-99fc33f568d24e47a5e4b36002c5325d?pvs=4 Private and public key encoding depend on `KeyObject#export` which is not implemented. I've also skipped ED448 and X448 since we need a crate for that in WebCrypto too.
2023-04-18refactor(node/crypto): scrypt polyfill to rust (#18746)Levente Kurusa
2023-04-18fix(ext/node): implement crypto.createVerify (#18703)Yoshiya Hinosawa
2023-04-18fix(path): Remove non node symbols (#18630)Ryan Clements
- preserve referential invariants (e.g. path.posix === posix) - remove glob and separator exports - save removal of fromFileUrl and toFileUrl for a different PR as that refactor is more involved - addresses #18177
2023-04-12refactor(node/crypto): port polyfill to Rust for randomInt, randomFill, ↵Levente Kurusa
randomFillSync (#18658) Pretty much as per the title, I'd welcome some feedback especially around the array/buffer handling in the two randomFill functions.
2023-04-07fix(ext/node): add X509Certificate (#18625)Divy Srivastava
Towards #18455
2023-04-06fix(ext/node): implement hkdf-expand (#18612)Divy Srivastava
Towards https://github.com/denoland/deno/issues/18455
2023-04-06refactor(ext/node): `NodeFs` - add back altered metadata method (#18613)David Sherret
From https://github.com/denoland/deno/pull/18604/files#r1159992299 We should still have a `metadata` method because it's one system call instead of two on most platforms.
2023-04-06fix(ext/node): add symmetric keygen (#18609)Divy Srivastava
Towards #18455
2023-04-06refactor(ext/node): add more methods to 'NodeFs' trait (#18604)Bartek Iwańczuk
Added more methods to `ext/node/clippy.toml` that are not allowed to be used in the crate. Prerequisite for https://github.com/denoland/deno/pull/18544
2023-04-06fix(ext/node): json encode binary command name (#18596)Geert-Jan Zwiers
Fixes https://github.com/denoland/deno/issues/18588
2023-04-04refactor(core): Improve ergonomics of managing ASCII strings (#18498)Matt Mastracci
This is a follow-on to the earlier work in reducing string copies, mainly focused on ensuring that ASCII strings are easy to provide to the JS runtime. While we are replacing a 16-byte reference in a number of places with a 24-byte structure (measured via `std::mem::size_of`), the reduction in copies wins out over the additional size of the arguments passed into functions. Benchmarking shows approximately the same if not slightly less wallclock time/instructions retired, but I believe this continues to open up further refactoring opportunities.
2023-03-30refactor(ext/node): add NodeEnv::Fs associated type (#18484)Bartek Iwańczuk
This commit adds associated type to "NodeEnv" trait, called "Fs". The "Fs" type has a trait bound on "NodeFs", which specifies APIs required for all ops and resolution APIs to function. A "RealFs" implementation of "NodeFs" is exported from the "deno_node" crate, that provides a default implementation for the trait. All code in "deno_node" extension was changed to use the "NodeFs" trait to handle file system operations, instead of relying on APIs from the standard library.
2023-03-28refactor(ext/node): change extension type parameter (#18483)Bartek Iwańczuk
This commit changes the type parameter for "deno_node" extension, from `P: NodePermission` to `Env: NodeEnv`. `NodeEnv` is a new trait that has associated type `P: NodePermission`. This is a stepping stone to support swappable file system for the extension, that will be added as a second associated type to the `NodeEnv` trait.
2023-03-28fix(ext/node): implement crypto.Sign (RSA/PEM/SHA{224,256,384,512}) (#18471)Yoshiya Hinosawa
2023-03-28feat(ext/node): add `crypto.checkPrime` API (#18465)Divy Srivastava
Towards #18455 This commit implements `checkPrimeSync` and `checkPrime` in node:crypto using the Miller-Rabin primality test (fun fact: it actually is a test for composite numbers) It first compares the candidate against many known small primes and if not, proceeds to run the Miller-Rabin primality test. http://nickle.org/examples/miller-rabin.5c used as reference implementation.