Commit graph

81 commits

Author SHA1 Message Date
Satya Rohith b2628e4a06
fix(ext/node): don't rely on Deno.env to read NODE_DEBUG (#23694)
This patch allows implementors to use ext/node without
the need to implement Deno.env API.

Closes https://github.com/denoland/deno/issues/23687
2024-05-05 16:16:02 +02:00
Matt Mastracci 2f8825a935
feat: Add deno serve subcommand (#23511)
By default, `deno serve` will assign port 8000 (like `Deno.serve`).
Users may choose a different port using `--port`.

`deno serve /tmp/file.ts`

`server.ts`:
```ts
export default {
  fetch(req) {
    return new Response("hello world!\n");
  },
};
```
2024-04-24 19:45:49 +00:00
Nathan Whitaker 8a367d3cc3
fix(cli): Don't panic on invalid emit options (#23463)
Fixes #23456.
2024-04-23 08:50:50 -07:00
Igor Zinkovsky b3d7df5535
perf: v8 code cache (#23081)
This PR enables V8 code cache for ES modules and for `require` scripts
through `op_eval_context`. Code cache artifacts are transparently stored
and fetched using sqlite db and are passed to V8. `--no-code-cache` can
be used to disable.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-04-17 07:19:55 -07:00
David Sherret 43c8c1cc6e
feat(check): allow using side effect imports with unknown module kinds (ex. css modules) (#23392)
This allows people to use imports like:

```ts
import "./app.css";
```

...with `deno check` in systems where there's a bundle step (ex. Vite).
This will still error when using it with `deno run` or if the referenced
file does not exist.

See test cases for behaviour.
2024-04-16 16:46:31 -04:00
Bartek Iwańczuk f358ae6278
fix(inspector): don't panic if port is not free (#22745)
Closes https://github.com/denoland/deno/issues/22113
Closes https://github.com/denoland/deno/issues/23177
Closes https://github.com/denoland/deno/issues/22883
Closes https://github.com/denoland/deno/issues/22377
2024-04-12 01:17:10 +02:00
David Sherret ade0cd5e97
fix: upgrade deno_ast related crates (#23187)
Had to revert back swc due to
https://github.com/swc-project/swc/issues/8840

Fixes:

- https://github.com/denoland/deno_lint/pull/1262
- https://github.com/denoland/deno_doc/pull/538
- https://github.com/denoland/deno_doc/pull/537
- https://github.com/denoland/deno_graph/pull/430
- https://github.com/denoland/deno_graph/pull/425
- https://github.com/denoland/deno_graph/pull/432
2024-04-11 23:00:17 +00:00
David Sherret 049e703331
FUTURE: override byonm with nodeModulesDir setting (#23222)
Makes the `"nodeModulesDir"` setting take precedence over byonm when
using `DENO_FUTURE`.
2024-04-05 10:34:51 -04:00
Bartek Iwańczuk c0b7454175
FUTURE: enable BYONM by default (#23194)
When `DENO_FUTURE=1` env var is present, then BYONM
("bring your own node_modules") is enabled by default.
That means that is there's a `package.json` present, users
are expected to explicitly install dependencies from that file.

Towards https://github.com/denoland/deno/issues/23151
2024-04-03 00:43:03 +02:00
David Sherret ad6b00a2bf
chore: enable clippy unused_async rule (#22834) 2024-03-11 23:48:00 -04:00
David Sherret 594d8397ad
fix(publish): properly display graph validation errors (#22775)
The graph validation errors were displaying cryptically during publish.
This fixes that.
2024-03-07 17:30:30 +01:00
Nayeem Rahman 01bc2f530e
feat(unstable/pm): support npm packages in 'deno add' (#22715) 2024-03-06 13:24:15 +00:00
David Sherret 3eaf174bfc
fix(node): improve cjs tracking (#22673)
We were missing saying that a file is CJS when some Deno code imported
from the node_modules directory at runtime.
2024-03-06 00:23:51 +00:00
David Sherret 942dcbad84
refactor: move deno json functionality to args module (#22710) 2024-03-05 15:45:44 -05:00
Luca Casonato 8d5c231349
feat(publish): support sloppy imports and bare node built-ins (#22588) 2024-02-27 15:13:16 +00:00
David Sherret 6567dc94a9
fix(lsp): import map expansion (#22553) 2024-02-24 00:21:09 -05:00
Satya Rohith 47dee65e4a
fix(ext/node): set correct process.argv0 (#22555) 2024-02-23 17:30:29 +01:00
David Sherret f90889e5ee
perf(jsr): fast check cache and lazy fast check graph (#22485) 2024-02-20 21:29:57 +00:00
David Sherret 828d9b8485
refactor: remove module graph setup from ModuleLoader (#22442)
`ModuleLoader` was doing too much duplicate work.
2024-02-16 22:10:06 +00:00
David Sherret 4f80d83774
feat(unstable): single checksum per JSR package in the lockfile (#22421)
This changes the lockfile to not store JSR specifiers in the "remote"
section. Instead a single JSR integrity is stored per package in the
lockfile, which is a hash of the version's `x.x.x_meta.json` file, which
contains hashes for every file in the package. The hashes in this file
are then compared against when loading.

Additionally, when using `{ "vendor": true }` in a deno.json, the files
can be modified without causing lockfile errors—the checksum is only
checked when copying into the vendor folder and not afterwards
(eventually we should add this behaviour for non-jsr specifiers as
well). As part of this change, the `vendor` folder creation is not
always automatic in the LSP and running an explicit cache command is
necessary. The code required to track checksums in the LSP would have
been too complex for this PR, so that all goes through deno_graph now.
The vendoring is still automatic when running from the CLI.
2024-02-15 14:49:35 -05:00
Divy Srivastava b72f0be27c
chore: add DENO_FUTURE env var (#22318)
Closes https://github.com/denoland/deno/issues/22315

```
~> DENO_FUTURE=1 target/debug/deno

> globalThis.window
undefined
```
2024-02-15 04:50:17 +00:00
Nayeem Rahman 012a9d8aeb
chore: rename DENO_REGISTRY_URL to JSR_URL (#22414) 2024-02-14 18:30:44 +00:00
Divy Srivastava a68eb3fcc3
feat: denort binary for deno compile (#22205)
This introduces the `denort` binary - a slim version of deno without
tooling. The binary is used as the default for `deno compile`.

Improves `deno compile` final size by ~2.5x (141 MB -> 61 MB) on Linux
x86_64.
2024-02-13 21:52:30 +05:30
Bartek Iwańczuk fddbb018c1
chore: temporarily disable deprecation warnings (#22204) 2024-01-31 23:18:14 +01:00
David Sherret 0e1cae32b3
fix(lockfile): only consider package.json beside lockfile in workspace property (#22179)
Closes https://github.com/denoland/deno/issues/22176 (see detail there)
2024-01-30 09:26:30 -05:00
Divy Srivastava ed65bc6abc
refactor(cli): decouple resolvers from module_loader.rs for standalone use (#22147)
It makes it easier to write a standalone bin target for `deno compile`
without pulling a lot of the tooling and tsc loader logic
2024-01-27 09:10:36 -08:00
Bartek Iwańczuk 9e0495baa7
fix: make deprecation warnings less verbose (#22128)
This commit makes deprecation warnings less verbose by default.

Only a single warnings is issued per deprecated API use.

`DENO_VERBOSE_WARNINGS` env var can be provided to enable more detailed
logging for each use of API including a stack trace.

https://github.com/denoland/deno/assets/13602871/9c036c84-0044-4cb6-9c8e-deb641f43712
2024-01-26 16:41:16 +01:00
Bartek Iwańczuk 427b73c3ec
feat: warn when using --unstable, prefer granular flags (#21452)
This commit deprecates "--unstable" flag. 

When "--unstable" flag is encountered a warning like this is printed:
```
The `--unstable` flag is deprecated, use granular `--unstable-*` flags instead.
Learn more at: https://docs.deno.com/runtime/manual/tools/unstable_flags
```
When "--unstable" flag is used and an unstable API is called an
additional warning like this is printed for each API call:
```
The `Deno.dlopen` API was used with `--unstable` flag. The `--unstable` flag is deprecated, use granular `--unstable-ffi` instead. 
Learn more at: https://docs.deno.com/runtime/manual/tools/unstable_flags
```
When no "--unstable-*" flag is provided and an unstable API is called
following
warning is issued before exiting:
```
Unstable API 'Deno.dlopen'. The `--unstable-ffi` flag must be provided.
```

---------

Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
2024-01-23 15:33:07 +01:00
David Sherret 69d5f136ba
feat(lockfile): track JSR and npm dependencies in config file (#22004)
See overview in https://github.com/denoland/deno_lockfile/pull/13
2024-01-22 22:31:12 +01:00
Bartek Iwańczuk d20c9e75d1
refactor: add "UnstableConfig" struct to cli/args/flags.rs (#21993)
This commit adds "UnstableConfig" struct which centralizes
handling of all "--unstable-*" flags.

Closes https://github.com/denoland/deno/issues/21920
2024-01-22 17:37:28 +00:00
Bartek Iwańczuk c62615bfe5
feat: Start warning on each use of a deprecated API (#21939)
This commit introduces deprecation warnings for "Deno.*" APIs.

This is gonna be quite noisy, but should tremendously help with user
code updates to ensure
smooth migration to Deno 2.0. The warning is printed at each unique call
site to help quickly
identify where code needs to be adjusted. There's some stack frame
filtering going on to
remove frames that are not useful to the user and would only cause
confusion.

The warning can be silenced using "--quiet" flag or
"DENO_NO_DEPRECATION_WARNINGS" env var.

"Deno.run()" API is now using this warning. Other deprecated APIs will
start warning
in follow up PRs.

Example:

```js
import { runEcho as runEcho2 } from "http://localhost:4545/run/warn_on_deprecated_api/mod.ts";

const p = Deno.run({
  cmd: [
    Deno.execPath(),
    "eval",
    "console.log('hello world')",
  ],
});
await p.status();
p.close();

async function runEcho() {
  const p = Deno.run({
    cmd: [
      Deno.execPath(),
      "eval",
      "console.log('hello world')",
    ],
  });
  await p.status();
  p.close();
}

await runEcho();
await runEcho();

for (let i = 0; i < 10; i++) {
  await runEcho();
}

await runEcho2();

```

```
$ deno run --allow-read foo.js
Warning
├ Use of deprecated "Deno.run()" API.
│
├ This API will be removed in Deno 2.0. Make sure to upgrade to a stable API before then.
│
├ Suggestion: Use "Deno.Command()" API instead.
│
└ Stack trace:
  └─ at file:///Users/ib/dev/deno/foo.js:3:16

hello world
Warning
├ Use of deprecated "Deno.run()" API.
│
├ This API will be removed in Deno 2.0. Make sure to upgrade to a stable API before then.
│
├ Suggestion: Use "Deno.Command()" API instead.
│
└ Stack trace:
  ├─ at runEcho (file:///Users/ib/dev/deno/foo.js:8:18)
  └─ at file:///Users/ib/dev/deno/foo.js:13:7

hello world
Warning
├ Use of deprecated "Deno.run()" API.
│
├ This API will be removed in Deno 2.0. Make sure to upgrade to a stable API before then.
│
├ Suggestion: Use "Deno.Command()" API instead.
│
└ Stack trace:
  ├─ at runEcho (file:///Users/ib/dev/deno/foo.js:8:18)
  └─ at file:///Users/ib/dev/deno/foo.js:14:7

hello world
Warning
├ Use of deprecated "Deno.run()" API.
│
├ This API will be removed in Deno 2.0. Make sure to upgrade to a stable API before then.
│
├ Suggestion: Use "Deno.Command()" API instead.
│
└ Stack trace:
  ├─ at runEcho (file:///Users/ib/dev/deno/foo.js:8:18)
  └─ at file:///Users/ib/dev/deno/foo.js:17:9

hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
Warning
├ Use of deprecated "Deno.run()" API.
│
├ This API will be removed in Deno 2.0. Make sure to upgrade to a stable API before then.
│
├ Suggestion: Use "Deno.Command()" API instead.
│
├ Suggestion: It appears this API is used by a remote dependency.
│             Try upgrading to the latest version of that dependency.
│
└ Stack trace:
  ├─ at runEcho (http://localhost:4545/run/warn_on_deprecated_api/mod.ts:2:18)
  └─ at file:///Users/ib/dev/deno/foo.js:20:7

hello world

```

Closes #21839
2024-01-18 23:30:49 +00:00
David Sherret 7e72f3af61
chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
Divy Srivastava 5a91a065b8
fix: implement child_process IPC (#21490)
This PR implements the Node child_process IPC functionality in Deno on
Unix systems.

For `fd > 2` a duplex unix pipe is set up between the parent and child
processes. Currently implements data passing via the channel in the JSON
serialization format.
2023-12-13 11:14:16 +01:00
David Sherret 78566753c8
feat: add suggestions to module not found error messages for file urls (#21498) 2023-12-07 15:59:13 -05:00
David Sherret 890780a9e9
feat(unstable): ability to resolve specifiers with no extension, specifiers for a directory, and TS files from JS extensions (#21464)
Adds an `--unstable-sloppy-imports` flag which supports the
following for `file:` specifiers:

* Allows writing `./mod` in a specifier to do extension probing.
- ex. `import { Example } from "./example"` instead of `import { Example
} from "./example.ts"`
* Allows writing `./routes` to do directory extension probing for files
like `./routes/index.ts`
* Allows writing `./mod.js` for *mod.ts* files.

This functionality is **NOT RECOMMENDED** for general use with Deno:

1. It's not as optimal for perf:
https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-2/
1. It makes tooling in the ecosystem more complex in order to have to
understand this.
1. The "Deno way" is to be explicit about what you're doing. It's better
in the long run.
1. It doesn't work if published to the Deno registry because doing stuff
like extension probing with remote specifiers would be incredibly slow.

This is instead only recommended to help with migrating existing
projects to Deno. For example, it's very useful for getting CJS projects
written with import/export declaration working in Deno without modifying
module specifiers and for supporting TS ESM projects written with
`./mod.js` specifiers.

This feature will output warnings to guide the user towards correcting
their specifiers. Additionally, quick fixes are provided in the LSP to
update these specifiers:
2023-12-07 00:03:18 +00:00
David Sherret e372fc73e8
fix(task): handle node_modules/.bin directory with byonm (#21386)
A bit hacky, but it works. Essentially, this will check for all the
scripts in the node_modules/.bin directory then force them to run with
Deno via deno_task_shell.
2023-12-06 16:36:06 -05:00
David Sherret a1d823e27d
feat(compile): support discovering modules for more dynamic arguments (#21381)
This PR causes Deno to include more files in the graph based on how a
template literal looks that's provided to a dynamic import:

```ts
const file = await import(`./dir/${expr}`);
```

In this case, it will search the `dir` directory and descendant
directories for any .js/jsx/etc modules and include them in the graph.

To opt out of this behaviour, move the template literal to a separate
line:

```ts
const specifier = `./dir/${expr}`
const file = await import(specifier);
```
2023-12-01 20:12:10 +00:00
David Sherret 9ac405d587
feat(compile): support "bring your own node_modules" in deno compile (#21377)
Not tested thoroughly. This is a good start.

Closes #21350
2023-11-29 09:32:23 -05:00
Divy Srivastava ab0c637425
perf: move jupyter esm out of main snapshot (#21163)
Towards https://github.com/denoland/deno/issues/21136
2023-11-14 22:06:00 +01:00
Divy Srivastava 9f4a45561f
perf: snapshot runtime ops (#21127)
Closes https://github.com/denoland/deno/issues/21135

~1ms startup time improvement

---------

Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
2023-11-11 17:01:48 +00:00
Matt Mastracci 68607b593f
perf(cli): strace mode for ops (undocumented) (#21131)
Example usage:

```
# Trace every op except op_*tick*
cargo run -- run --unstable -A --strace-ops=-tick '/Users/matt/Documents/github/deno/deno/ext/websocket/autobahn/autobahn_server.js

# Trace any op matching op_*http*
cargo run -- run --unstable -A --strace-ops=http ...
```

Example output:

```
[    11.478] op_ws_get_buffer                        : Dispatched Slow
[    11.478] op_ws_get_buffer                        : Completed Slow
[    11.478] op_ws_send_binary                       : Dispatched Fast
[    11.478] op_ws_send_binary                       : Completed Fast
[    11.478] op_ws_next_event                        : Dispatched Async
[    11.478] op_try_close                            : Dispatched Fast
[    11.478] op_try_close                            : Completed Fast
[    11.478] op_timer_handle                         : Dispatched Fast
[    11.478] op_timer_handle                         : Completed Fast
[    11.478] op_sleep                                : Dispatched Asyn
```
2023-11-10 10:41:24 -07:00
Matt Mastracci 485fade0b6
chore: migrate to new deno_core and metrics (#21057)
- Uses the new OpMetrics system for sync and async calls
- Partial revert of #21048 as we moved Array.fromAsync upstream to
deno_core
2023-11-05 14:27:36 -07:00
David Sherret 58d543a480
fix(repl): jsxImportSource was not working (#21049)
I made some fixes in deno_ast to make this possible and we forgot to
update this.
2023-11-01 23:04:54 +00:00
Bartek Iwańczuk 24c3c96958
feat: granular --unstable-* flags (#20968)
This commit adds granular `--unstable-*` flags:
- "--unstable-broadcast-channel"
- "--unstable-ffi"
- "--unstable-fs"
- "--unstable-http"
- "--unstable-kv"
- "--unstable-net"
- "--unstable-worker-options"
- "--unstable-cron"

These flags are meant to replace a "catch-all" flag - "--unstable", that
gives a binary control whether unstable features are enabled or not. The
downside of this flag that allowing eg. Deno KV API also enables the FFI
API (though the latter is still gated with a permission).

These flags can also be specified in `deno.json` file under `unstable`
key.

Currently, "--unstable" flag works the same way - I will open a follow
up PR that will print a warning when using "--unstable" and suggest to use
concrete "--unstable-*" flag instead. We plan to phase out "--unstable"
completely in Deno 2.
2023-11-01 23:15:08 +01:00
Bartek Iwańczuk 1713df1352
feat: deno run --unstable-hmr (#20876)
This commit adds `--unstable-hmr` flag, that enabled Hot Module Replacement.

This flag works like `--watch` and accepts the same arguments. If
HMR is not possible the process will be restarted instead.

Currently HMR is only supported in `deno run` subcommand.

Upon HMR a `CustomEvent("hmr")` will be dispatched that contains
information which file was changed in its `details` property.

---------

Co-authored-by: Valentin Anger <syrupthinker@gryphno.de>
Co-authored-by: David Sherret <dsherret@gmail.com>
2023-10-31 01:25:58 +01:00
David Sherret 842e29057d
refactor: break out ModuleInfoCache from ParsedSourceCache (#20977)
As title. This will help use the two independently from the other, which
will help in an upcoming deno doc PR where I need to parse the source
files with scope analysis.
2023-10-25 18:13:22 -04: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
Yoshiya Hinosawa fb73eb1e9d
feat(unstable): allow bare specifier for builtin node module (#20728)
closes #20566
2023-10-20 13:02:08 +09:00
Bartek Iwańczuk 8d9fef3b89
refactor: add WatcherCommunicator helper struct (#20927)
This commit introduces "WatcherCommunicator" struct that
is used facilitate bi-directional communication between CLI
file watcher and the watched function.

Prerequisite for https://github.com/denoland/deno/pull/20876
2023-10-19 07:05:00 +02:00
Bartek Iwańczuk c464cd7073
refactor: FeatureChecker integration in ext/ crates (#20797)
Towards https://github.com/denoland/deno/issues/20779.
2023-10-12 15:55:50 +00:00