summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/01_require.js
AgeCommit message (Collapse)Author
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-13fix(ext/node): process.getBuiltinModule (#26833)Divy Srivastava
Closes https://github.com/denoland/deno/issues/26832
2024-11-04fix(ext/node): add `findSourceMap` to the default export of `node:module` ↵Nathan Whitaker
(#26720) Next.js 15.0.2 tries to use this and errors out
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-09-19fix: cjs resolution cases (#25739)snek
Fixes cjs modules being loaded as esm.
2024-09-17fix(ext/node): stub `inspector/promises` (#25635)Divy Srivastava
Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-09-15fix(ext/node): add stubs for `node:trace_events` (#25628)Divy Srivastava
2024-09-13fix(ext/node): attach console stream properties (#25617)snek
`kBindStreamsLazy` should be called with `process` during init, but it never was.
2024-09-12feat(ext/node): expose ES modules for _ modules (#25588)Bartek Iwańczuk
Exposes following modules: - `"node:_http_agent"` - `"node:_http_common"` - `"node:_http_outgoing"` - `"node:_http_server"` - `"node:_stream_duplex"` - `"node:_stream_passthrough"` - `"node:_stream_readable"` - `"node:_stream_transform"` - `"node:_stream_writable"` - `"node:_tls_common"` - `"node:_tls_wrap"`
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-04feat(cli): give access to `process` global everywhere (#25291)Luca Casonato
2024-08-28refactor(ext): throw new error instead of throw error (#25272)Ian Bull
To ensure consistency across the codebase, this commit refactors the code in the `ext` folder to use `throw new Error`` instead of `throw` for throwing errors. Fixes https://github.com/denoland/deno/issues/25270
2024-08-28refactor: don't virtualize the `console` global for node mode (#25263)Luca Casonato
Turns out we only virtualized it so one could have a `Console` property, and the other one not. We can just make this `console.Console` available everywhere.
2024-08-28fix(ext/node): throw when loading `cpu-features` module (#25257)Divy Srivastava
It crashes because of NAN usage, we want to trigger the fallback case in ssh2 by throwing an error. Fixes https://github.com/denoland/deno/issues/25236
2024-08-22fix(ext/node): register `node:wasi` built-in (#25134)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/23531
2024-08-14fix: `node:inspector` not being registered (#25007)Marvin Hagemeister
For some reason we didn't register the `node:inspector` module, which lead to a panic when trying to import it. This PR registers it. Related: https://github.com/denoland/deno/issues/25004
2024-08-09fix: stub `node:module.register()` (#24965)Marvin Hagemeister
This is commonly used to register loading non standard file types. But some libs also register TS loaders which Deno supports natively, like the npm `payload` package. This PR unblocks those. Fixes https://github.com/denoland/deno/issues/24902
2024-07-31feat: upgrade V8 to 12.8 (#24693)snek
- upgrade to v8 12.8 - optimizes DataView bigint methods - fixes global interceptors - includes CPED methods for ALS - fix global resolution - makes global resolution consistent using host_defined_options. originally a separate patch but due to the global interceptor bug it needs to be included in this pr for all tests to pass.
2024-07-28fix: actually add missing `node:readline/promises` module (#24772)David Sherret
Closes #24768
2024-07-11fix: unblock fsevents native module (#24542)snek
node-api is fully supported now. Signed-off-by: snek <snek@deno.com>
2024-06-26refactor: move PackageJson to deno_config (#24348)David Sherret
2024-06-25feat: add module.parent (#24333)snek
This field is deprecated but still used by the ecosystem, so let's just support it.
2024-06-10fix: Rewrite Node-API (#24101)snek
Phase 1 node-api rewrite
2024-05-20fix(node): stub findSourceMap for `ava` (#23899)Marvin Hagemeister
This stubs `findSourceMap` in `node:module` by always returning `undefined` as if it never found a source map. This unblocks the `ava` test runner. Fixes https://github.com/denoland/deno/issues/18666
2024-04-30fix(node): require.resolve - fallback to global cache when bare specifier ↵David Sherret
from paths not found (#23618) Part of #22607 (probably closes it, but I haven't done thorough testing) Makes it so that `require.resolve` with `paths` specified will fallback to using the global cache when the paths can't be found when using a global cache (not when using a node_modules folder)
2024-04-05fix(ext/node): Add "module" to builtinsModule (#23242)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/22731
2024-03-13fix(node): resolve types via package.json for directory import (#22878)David Sherret
Does a package resolve when resolving types for a directory (copying the behaviour that typescript does).
2024-03-08fix(ext/node): Implement `isBuiltin` in `node:module` (#22817)Nathan Whitaker
Fixes #22502 Implements the [`isBuiltin`](https://nodejs.org/api/module.html#moduleisbuiltinmodulename) function in `node:module`. I had to update the version of `@types/node` in the test registry in order to get the test I added to typecheck.
2024-01-29refactor: Use virtul ops module (#22175)Bartek Iwańczuk
Follow up to #22157. This leaves us with 4 usages of `ensureFastOps()` in `deno` itself. There's also about 150 usages of `Deno.core.ops.<op_name>` left as well.
2024-01-29refactor: migrate 'ext/node' extension to virtual ops module (#22157)Bartek Iwańczuk
Follow up to https://github.com/denoland/deno/pull/22135
2024-01-10refactor: use `core.ensureFastOps()` (#21888)Kenta Moriuchi
2024-01-01chore: update copyright to 2024 (#21753)David Sherret
2023-12-07refactor: pull 'core', 'internals', 'primordials' from ES module (#21462)Bartek Iwańczuk
This commit refactors how we access "core", "internals" and "primordials" objects coming from `deno_core`, in our internal JavaScript code. Instead of capturing them from "globalThis.__bootstrap" namespace, we import them from recently added "ext:core/mod.js" file.
2023-08-15fix(require): use canonicalized path for loading content (#20133)Bartek Iwańczuk
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-31perf: faster node globals access in cjs (#19997)Luca Casonato
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-07-24fix(node_compat): Wrap require resolve exports in try catch block (#19592)Vedant Pandey
Potentially closes #19499
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 error message requiring non-npm es module (#19856)David Sherret
Closes #19842 Closes #16913
2023-07-17fix(node): improve require esm error messages (#19853)David Sherret
Part of #19842. Closes #19583 Closes #16913
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-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-17fix(node): export diagnostics_channel module (#19167)Bartek Iwańczuk
Closes https://github.com/denoland/deno/issues/19166
2023-05-16fix(npm): add performance.markResourceTiming sham (#19123)Bartek Iwańczuk
This commit shams "performance.markResourceTiming" API by using a noop function. It is done to provide compatibility with "npm:undici" package. We should look into actually implementing this API properly, but I wanted to unblock support for "undici" and "astro" for now. Ref https://github.com/denoland/deno/issues/19065
2023-05-11feat(node): add `Module.runMain()` (#19080)Marvin Hagemeister
This PR adds the missing `Module.runMain()` function which is required for tools like `ts-node`. Fixes #19033
2023-05-02refactor(core): Use `ObjectHasOwn` instead of ↵Kenta Moriuchi
`ObjectPrototypeHasOwnProperty` (#18952) ES2022 `Object.hasOwn` can be used in snapshot, so I migrate to use it.
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>