0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-04 09:57:11 -05:00
Commit graph

628 commits

Author SHA1 Message Date
David Sherret
4ff629bb2a
chore: fix dts file for DefinitelyTyped linting (#28114)
Added this so that we only export exports from `Deno.lint`. Required to
pass DefinitelyTyped's linting.
2025-02-16 13:56:17 -05:00
Marvin Hagemeister
6c368c2469
fix(unstable): align js lint context API with eslint (#28066)
This PR aligns the `RuleContext` of JS plugins with ESLint.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2025-02-13 14:01:57 +00:00
Marvin Hagemeister
e1871e5291
feat(unstable): add js lint plugin source code helpers (#28065)
This PR adds a part of the `SourceCode` API in eslint (see
https://eslint.org/docs/latest/extend/custom-rules#applying-fixes) .
It's used to get the text of the current node, etc.
2025-02-13 13:19:55 +01:00
Nathan Whitaker
bb4ee0cb17
refactor: support hmr feature for lsp files (#28103)
So you can edit (e.g.) 00_typescript.js and not have to recompile during
dev
2025-02-13 11:39:44 +00:00
Nathan Whitaker
33bccf9090
perf(check): use v8 code cache for extension sources in deno check (#28089)
In particular this helps startup of the TSC isolate because
`00_typescript.js` can use the code cache.

Overall, this offsets a fair bit of the hit we took when we removed the
TSC snapshot.

```
❯ hyperfine --warmup 5 -p "rm -rf ~/Library/Caches/deno/check_cache_v2" "./deno-this-pr check main.ts" "./deno-no-snapshot check main.ts" "./deno-with-snapshot check main.ts"
Benchmark 1: ../../deno/target/release-lite/deno check main.ts
  Time (mean ± σ):     145.7 ms ±   3.6 ms    [User: 347.6 ms, System: 36.9 ms]
  Range (min … max):   142.2 ms … 155.9 ms    19 runs

Benchmark 2: ./deno-no-snapshot check main.ts
  Time (mean ± σ):     195.4 ms ±   3.3 ms    [User: 397.7 ms, System: 34.9 ms]
  Range (min … max):   192.1 ms … 206.0 ms    15 runs

Benchmark 3: ./deno-with-snapshot check main.ts
  Time (mean ± σ):     109.0 ms ±   2.2 ms    [User: 155.9 ms, System: 19.3 ms]
  Range (min … max):   106.5 ms … 118.0 ms    26 runs

Summary
  ./deno-with-snapshot check main.ts ran
    1.34 ± 0.04 times faster than ./deno-this-pr check main.ts
    1.79 ± 0.05 times faster than ./deno-no-snapshot check main.ts
```
2025-02-12 17:47:00 +00:00
Bartek Iwańczuk
55c5b07535
perf(lsp): add built-in tracing support for the LSP (#27843)
adds tracing and opentelemetry exporting to the LSP.

enable it in `.vscode/settings.json` (or wherever you configure the
LSP), like

```
{
  "deno.tracing": true
}
```

which will by default export opentelemetry traces to `localhost:4317`
or
```
{
  "deno.tracing": {
    // all fields optional
     "collector": "openTelemetry" (default) | "logging" (output in lsp log window)
     "collectorEndpoint": "http://localhost:4318" (for opentelemetry)
     "enable": true | false,
     "filter": "info" // defaults to "info", but can be any span filter
   }
}
```

---

a full working setup would be 

1: Run jaeger (an opentelemetry collector with a nice UI):
```
docker run --rm -p 16686:16686 -p 4317:4317 jaegertracing/jaeger
```
2. Enable in .vscode/settings.json
```
{
  "deno.tracing": true
}
```
3. Restart LSP (right now it only will start the opentelemetry exporter
on LSP startup)
3. open `http://localhost:16686` in your browser

---------

Co-authored-by: Nathan Whitaker <nathan@deno.com>
2025-02-12 08:40:40 -08:00
Leo Kettmeir
7253820764
refactor: object wrap WebGPU (#27665)
Fixes #25874
Fixes #26760
Fixes #24288
Fixes #24798
Fixes #25627
Fixes #25915
Fixes #26769
2025-02-12 13:45:41 +00:00
Bartek Iwańczuk
d29f9f99dd
fix(lint): Deno.lint.runPlugin throws in deno run (#28063)
This commit changes `Deno.lint.runPlugin` to throw
in non-`deno test` subcommand, instead of returning
`undefined`.
2025-02-12 09:18:55 +00:00
Yoshiya Hinosawa
3ff9ca2533
docs(cli): update description of readFile and readFileSync (#28079) 2025-02-12 17:56:12 +09:00
Bartek Iwańczuk
795ecfdca6
refactor(lsp): make TS host use CLI snapshot (#28062)
This commit changes the TS host implementation
in the LSP to use the same snapshot as the runtime worker
and web worker use.

This is due to upcoming V8 upgrade that might require
that all isolates in the same process use the exact same
snapshot.
2025-02-11 18:33:04 +01:00
Marvin Hagemeister
a2afae46b6
fix(unstable): add missing rule context types (#28014) 2025-02-11 16:35:16 +01:00
Bartek Iwańczuk
23540c2825
refactor: remove tsc snapshot (#28056)
This reverts commit acdc7dcdcf
and relands 174e496847.

Closes https://github.com/denoland/deno/issues/28047
Closes https://github.com/denoland/deno/issues/28044
2025-02-11 15:36:07 +01:00
Marvin Hagemeister
aead459fb2
feat(unstable): support multiple fixes from lint plugins (#28040)
This PR supports returning multiple changes from a lint fix. It works
the same way as eslint, see
https://eslint.org/docs/latest/extend/custom-rules#applying-fixes .

- Return a single fix
- Return an array of fixes
- Return a generator function with fixes
2025-02-11 15:24:28 +01:00
Bartek Iwańczuk
acdc7dcdcf
Revert "refactor: remove tsc snapshot (#27987)" (#28052)
This reverts commit 174e496847.

That commit caused panic on startup like
https://github.com/denoland/deno/issues/28047
or https://github.com/denoland/deno/issues/28044.

Reverting for now, until we figure out what's going wrong.
2025-02-11 11:18:32 +00:00
Nathan Whitaker
174e496847
refactor: remove tsc snapshot (#27987)
Removes the TSC snapshot to unblock the V8 upgrade (which enables shared
RO heap, and is incompatible with multiple snapshots).


this compresses the sources and declaration files as well, which leads
to a roughly 4.2MB reduction in binary size.

this currently adds about 80ms to deno check times, but code cache isn't
wired up for the extension code (namely `00_typescript.js`) yet

```
❯ hyperfine --warmup 5 -p "rm -rf ~/Library/Caches/deno/check_cache_v2" "../../deno/target/release-lite/deno check main.ts" "deno check main.ts"
Benchmark 1: ../../deno/target/release-lite/deno check main.ts
  Time (mean ± σ):     184.2 ms ±   2.2 ms    [User: 378.3 ms, System: 48.2 ms]
  Range (min … max):   181.5 ms … 189.9 ms    15 runs

Benchmark 2: deno check main.ts
  Time (mean ± σ):     107.4 ms ±   1.2 ms    [User: 155.3 ms, System: 23.9 ms]
  Range (min … max):   105.3 ms … 109.6 ms    26 runs

Summary
  deno check main.ts ran
    1.72 ± 0.03 times faster than ../../deno/target/release-lite/deno check main.ts
```

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2025-02-10 16:39:18 +00:00
Marvin Hagemeister
615bf8a4b0
feat(unstable): type lint plugin visitor (#28005)
This PR strongly types the JS plugin visitor.

```ts
export default {
  name: "foo",
  rules: {
    bar: {
      create(ctx) {
        return {
          // Plain ast node visitor
          Identifier(node) {},

          // Exit visitor
          "Identifier:exit"(node) {},

          // Custom selectors, `node` needs to be typed manually
          "FunctionDeclaration > Identifier"(node: Deno.lint.Identifier) {}
        }
      }
    }
  }
}

```

Follow up to https://github.com/denoland/deno/pull/27977
2025-02-07 13:01:33 +01:00
Marvin Hagemeister
89b1969f02
feat(unstable): add lint plugin ast types (#27977)
Add type definition for all TSEstree AST nodes in the JS lint plugin
system
2025-02-06 21:45:45 +01:00
Bartek Iwańczuk
f08ca6414b
feat(lint): add JavaScript plugin support (#27203)
This commit adds an unstable lint plugin API.

Plugins are specified in the `deno.json` file under
`lint.plugins` option like so:

```
{
  "lint": {
    "plugins": [
      "./plugins/my-plugin.ts",
      "jsr:@deno/lint-plugin1",
      "npm:@deno/lint-plugin2"
    ]
  }
}
```

The API is considered unstable and might be subject
to changes in the future.

Plugin API was modelled after ESLint API for the 
most part, but there are no guarantees for compatibility.
The AST format exposed to plugins is closely modelled
after the AST that `typescript-eslint` uses.

Lint plugins use the visitor pattern and can add
diagnostics like so:

```
export default {
  name: "lint-plugin",
  rules: {
    "plugin-rule": {
      create(context) {
        return {
          Identifier(node) {
            if (node.name === "a") {
              context.report({
                node,
                message: "should be b",
                fix(fixer) {
                  return fixer.replaceText(node, "_b");
                },
              });
            }
          },
        };
      },
    },
  },
} satisfies Deno.lint.Plugin;
```

Besides reporting errors (diagnostics) plugins can provide
automatic fixes that use text replacement to apply changes.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
Co-authored-by: David Sherret <dsherret@gmail.com>
2025-02-05 16:59:24 +01:00
David Sherret
8971064546
feat: TypeScript 5.7 (#27857)
Co-authored-by: Kenta Moriuchi <moriken@kimamass.com>
2025-01-31 16:07:42 -05:00
Timothy
8d824182be
docs: Temporal plaintime docs link (#27879) 2025-01-31 12:23:38 -08:00
Nathan Whitaker
b7456fed70
fix(lsp): ignore errors on ambient module imports (#27855)
This makes it so imports of ambient modules (e.g. `$app/environment` in
svelte, any virtual module in vite, or other module provided by a
bundler) don't error in the LSP.

The way this works is that when we request diagnostics from TSC, we also
respond with the list of ambient modules. Then, in the diagnostics code,
we save diagnostics (produced by deno) that may be invalidated as an
ambient module and wait to publish the diagnostics until we've received
the ambient modules from TSC.

The actual ambient modules you get from TSC can contain globs, e.g.
`*.css`. So when we get new ambient modules, we compile them all into a
regex and check erroring imports against that regex. Ambient modules
should change rarely, so in most cases we should be using a pre-compiled
regex, which executes in linear time (wrt the specifier length).

TODO:
- Ideally we should only publish once, right now we publish with the
filtered specifiers and then the TSC ones
- deno check (#27633)
2025-01-30 00:25:32 +00:00
David Sherret
4648fc4570
fix(check): compiler options from workspace members (#27785)
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
2025-01-28 10:49:58 -05:00
David Sherret
679902a108
perf(node_resolver): reduce url to/from path conversions (#27839)
Extracted out of https://github.com/denoland/deno/pull/27838/files

Reduces some allocations by accepting either a pathbuf or url for the
referrer for resolution and returning either a pathbuf or url at the
end, which the caller can then convert into to their preferred state.

This is about 4% faster when still converting the final result to a url
and 6% faster when keeping the result as a path in a benchmark I ran.
2025-01-27 15:23:20 -05:00
Divy Srivastava
8ccc05e503
fix(core): handle dyn imports exceeding call stack size (#27825)
Fixes https://github.com/denoland/deno/issues/27736
2025-01-27 09:10:12 +05:30
Kenta Moriuchi
6880608452
fix(types): Deno.readDirSync's type returns an IteratorObject (#27805) 2025-01-24 11:25:55 -05:00
Bartek Iwańczuk
ad50c0df34
refactor(tsc): remove TS program creation during snapshotting (#27797)
This commit refactors how a snapshot is created for the TypeScript
compiler.

Instead of having 4 ops, only a single op ("op_load") is left. This is
achieved by not creating a "ts.Program" during snapshotting, that during
benchmarking doesn't provide much benefit.

This greatly simplifies build script for the TS snapshot and opens up
way to simplify it even further in follow up PRs.
2025-01-24 13:06:36 +01:00
Bartek Iwańczuk
ab18dac09d
refactor(tsc): split TS compiler into multiple files, use ESM (#27784)
This is a pure refactor, the `99_main_compiler.js` file
was getting out of hand, being over 1500 lines and serving
3 distinct purposes:
- snapshotting
- type-checking
- running LSP

The file was split into:
- 97_ts_host.js
- 98_lsp.js
- 99_main_compiler.js
2025-01-23 01:37:50 +01:00
David Sherret
57dd66ec3d
refactor: move denort to separate crate (#27688)
This slightly degrades the performance of CJS export analysis on
subsequent runs because I changed it to no longer cache in the DENO_DIR
with this PR (denort now properly has no idea about the DENO_DIR). We'll
have to change it to embed this data in the binary and that will also
allow us to get rid of swc in denort (will do that in a follow-up PR).
2025-01-17 20:39:29 +00:00
Nathan Whitaker
464ee9155e
fix(check/lsp): fix bugs with tsc type resolution, allow npm packages to augment ImportMeta (#27690)
Fixes #26224.
Fixes #27042.

There were three bugs here:
- we were only resolving `/// <reference types` directives starting with
`npm:`, which meant we failed to resolve bare specifiers (this broke the
`/// <reference types="vite/client">` directive in most of the vite
templates)
- the `$node_modules` workaround caused us to fail to read files for
tsc. For instance tsc would construct new paths based on specifiers
containing `$node_modules`, and since we hadn't created those we weren't
mapping them back to the original (this broke some type resolution
within `vite/client`)
- our separation of `ImportMeta` across node and deno globals in tsc
meant that npm packages couldn't augment `ImportMeta` (this broke
`vite/client`'s augmentation to add `import.meta.env` and others)


After this, the only remaining issue in the vanilla vite template is our
error on `/vite.svg` (which is an ambient module), and I'll look into
that next.
2025-01-16 19:20:04 +00:00
Phil Hawksworth
8d2f76ae36
docs: JSDocs examples for prompt, confirm, and alert (#27695)
Adds examples
2025-01-16 14:20:45 +00:00
Phil Hawksworth
e54d467812
docs:Adds examples in JSDocs for localStorage and sessionStorage (#27668)
Improves docs for:

- http://docs.deno.com/api/web/~/localStorage
- http://docs.deno.com/api/web/~/sessionStorage
2025-01-16 12:33:08 +00:00
David Sherret
05dc69932d
refactor: create deno_lib crate (#27673)
Shifts just some code down for now. I'll do the rest of the refactor in
the next pr, but didn't want to drop a huge refactor.
2025-01-15 09:35:46 -05:00
David Sherret
0b033140c0
refactor: move CliNpmResolver to deno_resolver::npm::NpmResolver (#27659)
As title. After this PR all npm resolution will be out of the CLI crate.
2025-01-14 10:01:05 -05:00
David Sherret
9dbb99a83c
refactor: create NpmInstaller (#27626)
This separates npm resolution code from npm installation (more work
towards moving resolution code out of the CLI and cleaning up this
code).
2025-01-13 17:35:18 -05:00
Nathan Whitaker
70c822bfe2
fix(lsp/check): don't resolve unknown media types to a .js extension (#27631)
Fixes https://github.com/denoland/deno/issues/25762. Note that some of
the things in that issue are not resolved (vite/client types not working
properly which has other root causes), but the wildcard module
augmentation specifically is fixed by this.

We were telling TSC that files with unknown media types had an extension
of `.js`, so the ambient module declarations weren't applying. Instead,
just don't resolve them, so the ambient declaration applies.
2025-01-11 03:26:01 +00:00
Ryan Dahl
1d64670f9c
docs: added jsdoc for window.close() (#27608) 2025-01-09 15:05:39 -05:00
Leo Kettmeir
ea30e188a8
refactor: update deno_core for error refactor (#26867)
Closes #26171

---------

Co-authored-by: David Sherret <dsherret@gmail.com>
2025-01-08 14:52:32 -08:00
Luca Casonato
f483996658
feat(unstable): no config npm:@opentelemetry/api integration (#27541)
After this PR, one does not need to import `jsr:@deno/otel` anymore.
2025-01-06 17:00:32 +01:00
Luca Casonato
4b35ba6b13
feat(unstable): replace SpanExporter with TracerProvider (#27473) 2025-01-06 14:28:29 +01:00
Kitson Kelly
7cabd02c59
fix(kv): improve backoff error message and inline documentation (#27537)
Ref: #27536
2025-01-04 00:04:14 +01:00
David Sherret
89c92b84fa
fix(check): move module not found errors to typescript diagnostics (#27533)
Instead of hard erroring, we now surface module not found errors as
TypeScript diagnostics (we have yet to show the source code of the
error, but something we can improve over time).
2025-01-03 21:49:56 +00:00
Nayeem Rahman
18b813b93f
fix(check): line-break between diagnostic message chain entries (#27543) 2025-01-03 18:30:41 +00:00
Kenta Moriuchi
8fb073d7b4
chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
David Sherret
ac7b33a340
chore: cargo fmt - turn on group_imports=StdExternalCrate (#26646) 2024-12-31 12:13:39 -05:00
David Sherret
4638caa740
refactor: do not use deno_fs::FileSystem everywhere (#27508)
This changes the cli to mostly use `std::fs` via `sys_traits` instead of
the implemention of `deno_fs::FileSystem`.
2024-12-31 11:29:07 -05:00
Je Xia
7b491a28df
fix(node): Add missing inspector/promises (#27491)
Add missing `inspector/promises` in node builtin module list, that
causes types checking error.
2024-12-31 11:06:21 +01:00
David Sherret
c391ad315e
refactor: use sys_traits (#27480) 2024-12-30 12:38:20 -05:00
snek
65b647909d
feat(unstable): Implement QUIC (#21942)
Implements a QUIC interface, loosely based on the WebTransport API (a
future change could add the WebTransport API, built on top of this one).

[quinn](https://docs.rs/quinn/latest/quinn/) is used for the underlying
QUIC implementation, for a few reasons:
- A cloneable "handle" api which fits quite nicely into deno resources.
- Good collaboration with the rust ecosystem, especially rustls.
- I like it.

<!--
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.
-->
2024-12-20 13:48:48 +01:00
Nayeem Rahman
358bf566c2
fix(lsp): respect "typescript.suggestionActions.enabled" setting (#27373) 2024-12-16 17:25:49 +00:00
Luca Casonato
32e260d55a
fix: support bun specifiers in JSR publish (#24588)
Fixes https://github.com/denoland/deno/issues/26989

---------

Co-authored-by: Nathan Whitaker <nathan@deno.com>
2024-11-28 14:51:24 +01:00