summaryrefslogtreecommitdiff
path: root/ext/node/ops/require.rs
AgeCommit message (Collapse)Author
2024-11-15refactor: use boxed_error in some places (#26887)David Sherret
2024-11-14refactor(resolver): move more resolution code into deno_resolver (#26873)David Sherret
Follow-up to cjs refactor. This moves most of the resolution code into the deno_resolver crate. Still pending is the npm resolution code.
2024-11-13feat(node): stabilize detecting if CJS via `"type": "commonjs"` in a ↵David Sherret
package.json (#26439) This will respect `"type": "commonjs"` in a package.json to determine if `.js`/`.jsx`/`.ts`/.tsx` files are CJS or ESM. If the file is found to be ESM it will be loaded as ESM though.
2024-11-01fix: improved support for cjs and cts modules (#26558)David Sherret
* cts support * better cjs/cts type checking * deno compile cjs/cts support * More efficient detect cjs (going towards stabilization) * Determination of whether .js, .ts, .jsx, or .tsx is cjs or esm is only done after loading * Support `import x = require(...);` Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-10-31fix(ext/node): resolve exports even if parent module filename isn't present ↵Nathan Whitaker
(#26553) Fixes https://github.com/denoland/deno/issues/26505 I'm not exactly sure how this case comes about (I tried to write tests for it but couldn't manage to reproduce it), but what happens is the parent filename ends up null, and we bail out of resolving the specifier in package exports. I've checked, and in node the parent filename is also null (so that's not a bug on our part), but node continues to resolve even in that case. So this PR should match node's behavior more closely than we currently do.
2024-10-30fix: remove permission check in op_require_node_module_paths (#26645)David Sherret
2024-10-24refactor(ext/node): use concrete error types (#26419)Leo Kettmeir
2024-10-14perf: use fast calls for microtask ops (#26236)Divy Srivastava
Updates deno_core to 0.312.0
2024-10-04refactor: improve node permission checks (#26028)David Sherret
Does less work when requesting permissions with `-A`
2024-09-28refactor: use deno_path_util (#25918)David Sherret
2024-09-10feat: require(esm) (#25501)snek
implement require(esm) using `op_import_sync` from deno_core. possible future changes: - cts and mts - replace Deno.core.evalContext to optimize esm syntax detection Fixes: https://github.com/denoland/deno/issues/25487
2024-09-10fix(inspector): Fix panic when re-entering runtime ops (#25537)Divy Srivastava
Mark `op_require_break_on_next_statement` as reentrant and properly release borrow on the `OpState`. This fixes `BorrowMut` assertions when running with inspector + op metrics. Fixes https://github.com/denoland/deno/issues/25515
2024-08-26perf(ext/node): reduce some allocations in require (#25197)David Sherret
2024-07-25refactor: decouple node resolution from deno_core (#24724)David Sherret
2024-07-09refactor: use concrete error types for node resolution (#24470)David Sherret
This will help clean up some of the code in the CLI because we'll be able to tell how the resolution failed (not part of this PR).
2024-06-26refactor: move PackageJson to deno_config (#24348)David Sherret
2024-06-08fix(check): attempt to resolve types from pkg before `@types` pkg (#24152)David Sherret
I've been meaning to fix this for ages, but I finally ran into it here: https://github.com/dsherret/ts-ast-viewer/actions/runs/9432038675/job/25981325408 We need to resolve the `@types` package as a fallback instead of eagerly resolving it.
2024-06-08fix(ext/node): lossy UTF-8 read node_modules files (#24140)Luca Casonato
Previously various reads of files in `node_modules` would error on invalid UTF-8. These were cases involving: - reading package.json from Rust - reading package.json from JS - reading CommonJS files from JS - reading CommonJS files from Rust (for ESM translation) - reading ESM files from Rust
2024-06-06refactor: remove `PermissionsContainer` in deno_runtime (#24119)David Sherret
Also removes permissions being passed in for node resolution. It was completely useless because we only checked it for reading package.json files, but Deno reading package.json files for resolution is perfectly fine. My guess is this is also a perf improvement because Deno is doing less work.
2024-04-19feat(runtime): Allow embedders to perform additional access checks on file ↵Matt Mastracci
open (#23208) Embedders may have special requirements around file opening, so we add a new `check_open` permission check that is called as part of the file open process.
2024-04-01perf(node): put pkg json into an `Rc` (#23156)David Sherret
Was doing a bit of debugging on why some stuff is not working in a personal project and ran a quick debug profile and saw it cloning the pkg json a lot. We should put this in an Rc.
2024-03-28fix(node): remove unwrap in op_require_node_module_paths (#23114)David Sherret
Part of #22671
2024-03-20fix(ext/node): worker_threads ESM handling (#22841)mash-graz
Fixes #22840 Fixes #22964
2024-03-09fix(node): require of pkg json imports was broken (#22821)David Sherret
2024-01-01chore: update copyright to 2024 (#21753)David Sherret
2023-12-14fix(node): support resolving a package.json import to a builtin node module ↵David Sherret
(#21576) Closes https://github.com/denoland/deno/issues/21501
2023-11-07fix(node): inspect ancestor directories when resolving cjs re-exports during ↵David Sherret
analysis (#21104) If a CJS re-export can't be resolved, it will check the ancestor directories, which is more similar to what `require` does at runtime.
2023-11-04fix(node): use closest package.json to resolve package.json imports (#21075)David Sherret
2023-10-04refactor(node): combine node resolution code for resolving a package subpath ↵David Sherret
from external code (#20791) We had two methods that did the same functionality.
2023-09-07chore(ext/node): port some ops to op2 (#20400)Matt Mastracci
2023-08-17fix(npm): do not panic providing file url to require.resolve paths (#20182)David Sherret
Closes #19922
2023-08-08chore: rename some helpers on the Fs trait (#20097)Luca Casonato
Rename some of the helper methods on the Fs trait to be suffixed with `_sync` / `_async`, in preparation of the introduction of more async methods for some helpers. Also adds a `read_text_file_async` helper to complement the renamed `read_text_file_sync` helper.
2023-07-17fix(node): improve require esm error messages (#19853)David Sherret
Part of #19842. Closes #19583 Closes #16913
2023-06-26chore: fix typos (#19572)Martin Fischer
2023-05-23fix(node): duplicate node_module suffixes (#19222)Marvin Hagemeister
Noticed that we're checking more module paths than necessary. In particular the module path array contains a couple of entries with a duplicated `node_modules/node_modules` suffix. ```js [ // ... more entries before here, where some also contain duplicate suffixes "/Users/marvinhagemeister/dev/preact-render-to-string/node_modules/.deno/node_modules", "/Users/marvinhagemeister/dev/preact-render-to-string/node_modules/node_modules", // <-- duplicate suffix "/Users/marvinhagemeister/dev/preact-render-to-string/node_modules", "/Users/marvinhagemeister/dev/node_modules", "/Users/marvinhagemeister/node_modules", "/Users/node_modules", "/node_modules", "/node_modules" // <-- duplicate entry ] ``` This was caused by a misunderstanding in how Rust's [`Path::ends_with()`](https://doc.rust-lang.org/std/path/struct.Path.html#method.ends_with) works. It's designed to match on whole path segments and the suffix `/node_modules` is not that, except for the root entry. This meant that our check for if the path already ended with `node_module` always returned `false`. Removing the leading slash fixes that. While we're at it, we can remove the last condition where we explicitly added the root `/node_modules` entry since the while loop prior to that takes care of it already.
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-05-02fix(npm): canonicalize filename before returning (#18948)Bartek Iwańczuk
This commit changes how paths for npm packages are handled, by canonicalizing them when resolving. This is done so that instead of returning "node_modules/<package_name>@<version>/node_modules/<dep>/index.js" (which is a symlink) we "node_modules/<dep>@<dep_version>/index.js. Fixes https://github.com/denoland/deno/issues/18924 Fixes https://github.com/bluwy/create-vite-extra/issues/31 --------- Co-authored-by: David Sherret <dsherret@gmail.com>
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.