Commit graph

159 commits

Author SHA1 Message Date
David Sherret 9026f20b2d
fix(unstable/byonm): improve error messages (#20987)
This improves the error messages when a specifier can't be resolved from
a deno module into an npm package.
2023-10-26 21:22:15 -04:00
Luca Casonato 08b99f3909
chore: update base64 crate (#20877) 2023-10-26 18:39:04 +02:00
David Sherret be97170a19
feat(unstable): ability to npm install then deno run main.ts (#20967)
This PR adds a new unstable "bring your own node_modules" (BYONM)
functionality currently behind a `--unstable-byonm` flag (`"unstable":
["byonm"]` in a deno.json).

This enables users to run a separate install command (ex. `npm install`,
`pnpm install`) then run `deno run main.ts` and Deno will respect the
layout of the node_modules directory as setup by the separate install
command. It also works with npm/yarn/pnpm workspaces.

For this PR, the behaviour is opted into by specifying
`--unstable-byonm`/`"unstable": ["byonm"]`, but in the future we may
make this the default behaviour as outlined in
https://github.com/denoland/deno/issues/18967#issuecomment-1761248941

This is an extremely rough initial implementation. Errors are
terrible in this and the LSP requires frequent restarts. Improvements
will be done in follow up PRs.
2023-10-25 14:39:00 -04:00
David Sherret 8c1677ecbc
refactor(npm): break up NpmModuleLoader and move more methods into the managed CliNpmResolver (#20777)
Part of https://github.com/denoland/deno/issues/18967
2023-10-03 19:05:06 -04:00
David Sherret 148694eb35
refactor(npm): make NpmCache, CliNpmRegistryApi, and NpmResolution internal to npm::managed (#20764) 2023-10-02 17:53:55 -04:00
David Sherret 8d24be1a59
refactor(npm): create cli::npm::managed module (#20740)
Creates the `cli::npm::managed` module and starts moving more
functionality into it.
2023-09-30 12:06:38 -04:00
David Sherret 5edd102f3f
refactor(cli): make CliNpmResolver a trait (#20732)
This makes `CliNpmResolver` a trait. The terminology used is:

- **managed** - Deno manages the node_modules folder and does an
auto-install (ex. `ManagedCliNpmResolver`)
- **byonm** - "Bring your own node_modules" (ex. `ByonmCliNpmResolver`,
which is in this PR, but unimplemented at the moment)

Part of #18967
2023-09-29 09:26:25 -04:00
David Sherret d43e48c4e9
refactor(ext/node): remove dependency on deno_npm and deno_semver (#20718)
This is required from BYONM (bring your own node_modules).

Part of #18967
2023-09-28 22:43:45 +02:00
David Sherret dcb00bb9b8
chore: slight cleanup in npm resolvers (#20692) 2023-09-26 16:42:39 -04:00
David Sherret 3de9af4d0b
fix(npm): properly handle legacy shasum of package (#20557)
Closes #20554
2023-09-18 16:40:41 -04:00
David Sherret e66d3c2c2e
refactor: remove DENO_UNSTABLE_NPM_SYNC_DOWNLOAD and custom sync functionality (#20504)
https://github.com/denoland/deno/pull/20488 enables us to remove this
functionality. This is better because our test suite is now not testing
a separate code path.
2023-09-14 17:51:28 +00:00
David Sherret 12a75e3b43
refactor: move deno_core::TaskQueue to cli::util::sync (#20481)
TaskQueue is being removed from `deno_core` and replaced with an unsync
version in deno_unsyc.

https://github.com/denoland/deno_core/pull/193

This is a change in preparation for that. The remaining
`deno_core::TaskQueue` usage in this repo should be replaced with
`deno_core::unsync::TaskQueue` once upgraded.
2023-09-13 21:53:07 +00:00
David Sherret c521c5fe77
feat: lockfile v3 (#20424)
Details: https://github.com/denoland/deno_lockfile/pull/8
2023-09-08 14:34:57 -04:00
林炳权 2080669943
chore: update to Rust 1.72 (#20258)
<!--
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.
-->

As the title.

---------

Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-08-26 22:04:12 -06:00
Matt Mastracci b1ce2e4167
fix(ext/web): add stream tests to detect v8slice split bug (#20253)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-08-23 17:03:05 -06:00
David Sherret 5834d282d4
refactor: upgrade deno_ast 0.28 and deno_semver 0.4 (#20193) 2023-08-21 09:53:52 +00:00
Matt Mastracci 4380a09a05
feat(ext/node): eagerly bootstrap node (#20153)
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-16 04:36:36 +09:00
Luca Casonato 03e963f578
chore: rename some helpers on the Fs trait (#20097)
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-08-08 16:28:18 -04:00
Yusuke Tanaka f2e30a6f79
refactor(cli): move snapshot_from_lockfile function to deno_npm (#20024)
This commit moves `snapshot_from_lockfile` function to [deno_npm
crate](https://github.com/denoland/deno_npm). This allows this function
to be called outside Deno CLI (in particular, Deno Deploy).
2023-08-08 10:07:29 -07:00
David Sherret 1cefa831fd
feat(unstable): optional deno_modules directory (#19977)
Closes #15633
2023-08-02 00:49:09 +00:00
David Sherret cf16df00d9
fix(check): should bust check cache when json module or npm resolution changes (#19941)
A small part of #19928.
2023-07-26 17:23:07 -04:00
David Sherret 7a9f7f3419
fix(node): improve require esm error messages (#19853)
Part of #19842.

Closes #19583
Closes #16913
2023-07-17 14:00:44 -04:00
David Sherret b83dac3b14
fix(npm): improve error message importing non-existent file in a node_modules npm package (#19835) 2023-07-14 17:47:15 +00:00
David Sherret 629d09b149
perf: add setup cache for node_modules folder (#19787)
Part of #19774. This makes it twice as fast on my machine.

Stores a file at `node_modules/.deno/setup-cache.bin`, which contains
information about how the node_modules folder is currently setup.
Obviously there is a risk that this information will get out of date
with the current folder structure.
2023-07-10 13:42:47 -04:00
David Sherret a3986b641c
fix: bump default @types/node version range to 18.16.19 (#19706) 2023-07-04 15:27:04 +00:00
David Sherret cfbc9b471f
feat(lsp): basic support of auto-imports for npm specifiers (#19675)
Closes #19625
Closes https://github.com/denoland/vscode_deno/issues/857
2023-07-02 01:07:57 +00:00
David Sherret dd508c9c89
fix(npm): support siblings that are peer dependencies of each other (#19657)
https://github.com/denoland/deno_npm/pull/20
2023-06-30 08:49:49 -04:00
Martin Fischer 801b9ec62d
chore: fix typos (#19572) 2023-06-26 09:10:27 -04:00
David Sherret 1301a03b51
refactor(npm): remove needless resolve_nv_ref_from_pkg_req_ref on NpmResolver (#19582) 2023-06-22 11:50:48 +02:00
Bartek Iwańczuk 0733943fe7
fix(cli): avoid crash on import of invalid module names (#19523)
Fixes https://github.com/denoland/deno/issues/17748
Closes #17770

Co-authored-by: Anton Bershanskiy
<bershanskiy@users.noreply.github.com>
Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
2023-06-15 18:36:33 +00:00
David Sherret 5348778666
fix(npm): warn when tarball contains hardlink or symlink (#19474)
This is to help us get some visibility into whether we need to support
this.
2023-06-13 09:48:13 -04:00
Gustrb 2b2eebd583
perf(node): cache realpath_sync calls in read permission check (#19379) 2023-06-09 14:41:18 -04:00
David Sherret 55f0150854
refactor(compile): store the npm snapshot in the eszip (#19343) 2023-06-08 11:48:29 -04:00
David Sherret 91ca9904b5
refactor: upgrade to deno_npm 0.6 (#19244) 2023-05-24 16:23:10 -04:00
David Sherret ba6f573b4e
fix(npm): create node_modules/.deno/node_modules folder (#19242)
This is what pnpm does and we were missing it. It makes modules work
which have a dependency on something, but don't say they have that
dependency, but that dep is still in the tree somewhere.
2023-05-24 15:04:21 -04:00
David Sherret bb37dfb5b7
feat(lsp): support lockfile and node_modules directory (#19203)
This adds support for the lockfile and node_modules directory to the
lsp.

In the case of the node_modules directory, it is only enabled when
explicitly opted into via `"nodeModulesDir": true` in the configuration
file. This is to reduce the language server automatically modifying the
node_modules directory when the user doesn't want it to.

Closes #16510
Closes #16373
2023-05-22 21:28:36 -04:00
David Sherret 7b4c483aa1
fix(npm): store npm binary command resolution in lockfile (#19219)
Part of #19038

Closes #19034 (eliminates the time spent re-resolving)
2023-05-22 16:55:04 -04:00
David Sherret cc406c8360
feat(vendor): support for npm specifiers (#19186)
We never properly added support for this. This fixes vendoring when it
has npm or node specifiers. Vendoring occurs by adding a
`"nodeModulesDir": true` property to deno.json then it uses a local
node_modules directory. This can be opted out by setting
`"nodeModulesDir": false` or running with `--node-modules-dir=false`.

Closes #18090
Closes #17210
Closes #17619
Closes #16778
2023-05-19 22:39:27 +00:00
David Sherret 41f618a1df
fix(npm): improved optional dependency support (#19135)
Note: If the package information has already been cached, then this
requires running with `--reload` or for the registry information to be
fetched some other way (ex. the cache busting).

Closes #15544

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-05-17 17:38:50 -04:00
Matt Mastracci 9845361153
refactor(core): bake single-thread assumptions into spawn/spawn_blocking (#19056)
Partially supersedes #19016.

This migrates `spawn` and `spawn_blocking` to `deno_core`, and removes
the requirement for `spawn` tasks to be `Send` given our single-threaded
executor.

While we don't need to technically do anything w/`spawn_blocking`, this
allows us to have a single `JoinHandle` type that works for both cases,
and allows us to more easily experiment with alternative
`spawn_blocking` implementations that do not require tokio (ie: rayon).

Async ops (+~35%):

Before: 

```
time 1310 ms rate 763358
time 1267 ms rate 789265
time 1259 ms rate 794281
time 1266 ms rate 789889
```

After:

```
time 956 ms rate 1046025
time 954 ms rate 1048218
time 924 ms rate 1082251
time 920 ms rate 1086956
```

HTTP serve (+~4.4%):

Before:

```
Running 10s test @ http://localhost:4500
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    68.78us   19.77us   1.43ms   86.84%
    Req/Sec    68.78k     5.00k   73.84k    91.58%
  1381833 requests in 10.10s, 167.36MB read
Requests/sec: 136823.29
Transfer/sec:     16.57MB
```

After:

```
Running 10s test @ http://localhost:4500
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    63.12us   17.43us   1.11ms   85.13%
    Req/Sec    71.82k     3.71k   77.02k    79.21%
  1443195 requests in 10.10s, 174.79MB read
Requests/sec: 142921.99
Transfer/sec:     17.31MB
```

Suggested-By: alice@ryhl.io
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-05-14 15:40:01 -06:00
David Sherret 68c0fcb157
refactor(lsp): make RequestMethod private (#19114) 2023-05-12 19:07:40 -04:00
David Sherret 28aa489de9
feat(compile): unstable npm and node specifier support (#19005)
This is the initial support for npm and node specifiers in `deno
compile`. The npm packages are included in the binary and read from it via
a virtual file system. This also supports the `--node-modules-dir` flag,
dependencies specified in a package.json, and npm binary commands (ex.
`deno compile --unstable npm:cowsay`)

Closes #16632
2023-05-10 20:06:59 -04:00
David Sherret a6c47ee740
refactor(ext/node): combine deno_node::Fs with deno_fs::FileSystem (#18991) 2023-05-05 16:44:24 +00:00
Bartek Iwańczuk 2f651b2d64
fix(npm): canonicalize filename before returning (#18948)
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-05-02 02:35:33 +02:00
David Sherret 913176313b
perf: lazily create RootCertStore (#18938) 2023-05-01 16:42:05 -04:00
David Sherret 55a9977c62
refactor(compile): remove usage of ProcState and CliOptions (#18855) 2023-04-26 13:07:15 -04:00
David Sherret 5b4a9b48ae
refactor(ext/node): enforce interior mutable for NodePermissions to remove 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-24 21:07:48 -04:00
David Sherret aa286fdecb
refactor(ext/node): allow injecting NodeFs from CLI (#18829)
This allows providing a `NodeFs` as part of the `WorkerOptions`.
2023-04-24 19:44:35 -04:00
David Sherret 0e97fa4d5f
fix(npm): only include top level packages in top level node_modules directory (#18824)
We were indeterministically including packages in the top level
`node_modules/` folder when using a local node_modules directory. This
change aligns with pnpm and only includes top level packages in this
folder. This should be faster for initializing the folder, but may
expose issues in packages that reference other packages not defined in
their dependencies. That said, the behaviour previously was previously
broken.

This has exposed a bug in the require implementation where it doesn't
find a package (which is the main underlying issue here). There is a
failing test already for this in the test suite after this change.

Closes #18822

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-04-24 17:08:11 -04:00
David Sherret a615eb3b56
refactor(node): move most of cli/node to ext/node (#18797)
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-21 21:02:46 -04:00