This PR updates the type definitions for `setTimeout` and `setInterval`
in `lib.deno.shared_globals.d.ts` to accept both a string and a function
as the callback, matching the DOM standard and Deno's runtime behavior.
Previously, the types only allowed a function, but Deno's implementation
(and the web standard) also allow a string, which is evaluated as code.
This change ensures that TypeScript users can use both forms without
type errors, aligning Deno's types with web compatibility.
Fixes#30166
This commit changes `Deno.execPath()` API to no longer require
read permission.
This change is dictated by the fact that in common scenarios, requiring
read permission is less secure than not requiring permissions - if
a user wants to spawn a Deno subprocess using the current executable,
they would do something like:
```
new Deno.Command(Deno.execPath(), { args: ["eval", "1+1"] }).outputSync();
```
To run this program, currently one needs to pass `--allow-read
--allow-run=deno` flags.
It's possible to limit scope of `--allow-read` flag, but it's really
cumbersome to do,
so most users will opt to give a blanket `--allow-read` permission.
Not requiring read permissions allows the above program to be run with
just `--allow-run=deno` flag.
This change is in similar to relaxing of permissions in `Deno.cwd()` API
done in https://github.com/denoland/deno/pull/27192.
Ref
https://github.com/denoland/deno/issues/20061#issuecomment-2942497783
This commit adds support for using
[vsock](https://man7.org/linux/man-pages/man7/vsock.7.html) transport in
fetch API on Linux and macOS.
Similar to #29154, a vsock transport can be specified in the `proxy`
field when calling `Deno.createHttpClient`.
```ts
const client = Deno.createHttpClient({
proxy: {
transport: "vsock",
cid: 2,
port: 80,
},
});
await fetch("http://localhost/ping", { client });
```
Since `rust 1.87.0` reported `undefined symbol:
ring::pbkdf2::PBKDF2_HMAC_SHA1::*` in CI and it was difficult to debug
locally, use `rust 1.86.0` in CI tests for troubleshoot the errors
This commit makes `deno check` ignore `Cannot find module` diagnostic if the
missing module specifier matches one of ambient module pattern. (For
example if there's `declare module "*.svg" { ... }` declaration in one
of d.ts files, importing of `<any>.svg` doesn't cause type error with
this change. This is necessary for passing the type checking of default
vite template.)
---------
Co-authored-by: David Sherret <dsherret@gmail.com>
This commit adds support for using Unix socket proxies in `fetch` API.
This is facilitated by passing an appropriate `Deno.HttpClient` instance
to the `fetch` API:
```
const client = Deno.createHttpClient({
proxy: {
transport: "unix",
path: "/path/to/unix.sock",
},
});
await fetch("http://localhost/ping", { client });
```
Closes https://github.com/denoland/deno/issues/8821
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This change configures V8 isolates to respect memory limits imposed by
cgroups on Linux.
It adds support for detecting both cgroups v1 and v2 memory limits,
enabling Deno to properly adapt to containerized environments with
memory constraints. When cgroups information is unavailable or not
applicable, it falls back to using the system's total memory as before.
Closes#29077
## Test
For testing, I created a ubuntu VM with 1Gi memory. Within this VM, set
up a cgroup with 512Mi memory limit, then ran the following script to
see how much heap size limit the V8 isolate had.
```js
import * as v8 from "node:v8";
console.log(v8.getHeapStatistics());
```
### Ubuntu 20.04
In this version of ubuntu, hybrid mode is enabled by default.
```
$ cat /proc/self/cgroup
12:rdma:/
11:blkio:/user.slice
10:devices:/user.slice
9:cpu,cpuacct:/user.slice
8:pids:/user.slice/user-1000.slice/session-3.scope
7:memory:/user.slice/user-1000.slice/session-3.scope
6:perf_event:/
5:freezer:/
4:net_cls,net_prio:/
3:hugetlb:/
2:cpuset:/
1:name=systemd:/user.slice/user-1000.slice/session-3.scope
0::/user.slice/user-1000.slice/session-3.scope
```
Create a new cgroup with 512Mi memory limit and run the above script in
this cgroup:
```
$ sudo cgcreate -g memory:/mygroup
$ sudo cgset -r memory.limit_in_bytes=$((512 * 1024 * 1024)) mygroup
$ sudo cgexec -g memory:mygroup ./deno run main.mjs
{
total_heap_size: 7745536,
total_heap_size_executable: 0,
total_physical_size: 7090176,
total_available_size: 266348216,
used_heap_size: 6276752,
heap_size_limit: 271581184,
malloced_memory: 303200,
peak_malloced_memory: 140456,
does_zap_garbage: 0,
number_of_native_contexts: 1,
number_of_detached_contexts: 0,
total_global_handles_size: 24576,
used_global_handles_size: 22432,
external_memory: 3232012
}
```
This indicates that the isolate was informed of cgroup-constrained
memory limit (512Mi) and hence got ~270M heap limit.
### Ubuntu 22.04
In this version of ubuntu, cgroup v2 is used.
```
$ cat /proc/self/cgroup
0::/user.slice/user-1000.slice/session-3.scope
```
Run the above script using `systemd-run`:
```
$ sudo systemd-run --property=MemoryMax=512M --pty bash -c '/home/ubuntu/deno run /home/ubuntu/main.mjs'
{
total_heap_size: 7745536,
total_heap_size_executable: 0,
total_physical_size: 7090176,
total_available_size: 266348184,
used_heap_size: 6276784,
heap_size_limit: 271581184,
malloced_memory: 303200,
peak_malloced_memory: 140456,
does_zap_garbage: 0,
number_of_native_contexts: 1,
number_of_detached_contexts: 0,
total_global_handles_size: 24576,
used_global_handles_size: 22432,
external_memory: 3232012
}
```
Again the isolate got ~270M heap limit properly.
Note that it should have had bigger heap limit if the entire system
memory, i.e. 1Gi, had been passed to V8. In fact, if we run the same
script outside the cgroup, it does display larger `heap_size_limit` like
below:
```
$ ./deno run main.mjs
{
total_heap_size: 7745536,
total_heap_size_executable: 0,
total_physical_size: 7090176,
total_available_size: 546580152,
used_heap_size: 6276752,
heap_size_limit: 551813120,
malloced_memory: 303200,
peak_malloced_memory: 140456,
does_zap_garbage: 0,
number_of_native_contexts: 1,
number_of_detached_contexts: 0,
total_global_handles_size: 24576,
used_global_handles_size: 22432,
external_memory: 3232012
}
```
---------
Signed-off-by: Yusuke Tanaka <wing0920@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This PR adds support for comments in the AST for lint plugins.
- The `Program` node has a `comments` field pointing to an array of all
comments.
- `SourceCode.getAllComments()`: Returns all comments (same as
`program.comments`)
- `SourceCode.getCommentsBefore(node)`: Get all comments before this
Node
- `SourceCode.getCommentsAfter(node)`: Get all comments after this Node
- `SourceCode.getCommentsInside(node)`: Get all comments inside this
Node
ESLint docs:
-
https://eslint.org/docs/latest/extend/custom-rules#accessing-the-source-code
- https://eslint.org/docs/latest/extend/custom-rules#accessing-comments
`Deno.env.get` returns undefined when the environment variable is not
present. I initially interpreted this doc string to indicate that it
would return the string literal `"undefined"`, which isn't right.
Could use backticks here as above, but a little confusing in a JS
context where this also indicates a (template) string literal.
This is technically **BREAKING** as it removes a public API, but the
brand is type-only and the chance of anyone actually relying on this
seems very unlikely.
---------
Co-authored-by: David Sherret <dsherret@gmail.com>
Ref #26819
An optional **timeout** parameter has been added to the
**Deno.connect()** interface. This parameter allows specifying a timeout
(in milliseconds) within which the application must establish a
connection. If the timeout is exceeded without successfully connecting,
the operation is automatically aborted with an error. If the parameter
is not provided, the default behavior remains unchanged (no timeout).
Currently, the timeout functionality is implemented only for TCP
connections. Other connection types are not affected by this change.
---------
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
Noticed that the `.parent` type was missing for AST nodes for our JS
lint API. Whenever possible I've only specified the limited
possibilities of parent types, but when it's too complex I defaulted to
just `Node`.