1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

feat(jsr): support importing from jsr via HTTPS specifiers (except for type checking) (#23513)

Closes https://github.com/jsr-io/jsr/issues/322
This commit is contained in:
David Sherret 2024-04-24 17:43:34 -04:00 committed by GitHub
parent 5a7414e163
commit f3284529f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 661 additions and 594 deletions

View file

@ -57,7 +57,7 @@
"ext/websocket/autobahn/reports"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.90.3.wasm",
"https://plugins.dprint.dev/typescript-0.90.4.wasm",
"https://plugins.dprint.dev/json-0.19.2.wasm",
"https://plugins.dprint.dev/markdown-0.16.4.wasm",
"https://plugins.dprint.dev/toml-0.6.1.wasm",

1136
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -43,7 +43,7 @@ license = "MIT"
repository = "https://github.com/denoland/deno"
[workspace.dependencies]
deno_ast = { version = "=0.37.1", features = ["transpiling"] }
deno_ast = { version = "=0.38.0", features = ["transpiling"] }
deno_core = { version = "0.278.0" }
deno_bench_util = { version = "0.141.0", path = "./bench_util" }

View file

@ -66,17 +66,17 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposa
deno_cache_dir = { workspace = true }
deno_config = "=0.16.1"
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_doc = { version = "=0.128.0", features = ["html"] }
deno_emit = "=0.40.0"
deno_graph = { version = "=0.73.1", features = ["tokio_executor"] }
deno_lint = { version = "=0.58.3", features = ["docs"] }
deno_doc = { version = "=0.128.1", features = ["html"] }
deno_emit = "=0.40.1"
deno_graph = { version = "=0.74.0", features = ["tokio_executor"] }
deno_lint = { version = "=0.58.4", features = ["docs"] }
deno_lockfile.workspace = true
deno_npm = "=0.17.0"
deno_npm = "=0.18.0"
deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_semver = "=0.5.4"
deno_task_shell = "=0.16.0"
deno_terminal.workspace = true
eszip = "=0.68.0"
eszip = "=0.68.2"
napi_sym.workspace = true
async-trait.workspace = true
@ -98,7 +98,7 @@ dotenvy = "0.15.7"
dprint-plugin-json = "=0.19.2"
dprint-plugin-jupyter = "=0.1.3"
dprint-plugin-markdown = "=0.16.4"
dprint-plugin-typescript = "=0.90.3"
dprint-plugin-typescript = "=0.90.4"
env_logger = "=0.10.0"
fancy-regex = "=0.10.0"
faster-hex.workspace = true

View file

@ -611,7 +611,7 @@ impl ModuleGraphBuilder {
graph.build_fast_check_type_graph(
deno_graph::BuildFastCheckTypeGraphOptions {
jsr_url_provider: Some(&CliJsrUrlProvider),
jsr_url_provider: &CliJsrUrlProvider,
fast_check_cache: fast_check_cache.as_ref().map(|c| c as _),
fast_check_dts: false,
module_parser: Some(&parser),
@ -969,7 +969,7 @@ pub fn format_range_with_colors(range: &deno_graph::Range) -> String {
}
#[derive(Debug, Default, Clone, Copy)]
struct CliJsrUrlProvider;
pub struct CliJsrUrlProvider;
impl deno_graph::source::JsrUrlProvider for CliJsrUrlProvider {
fn url(&self) -> &'static ModuleSpecifier {

View file

@ -304,6 +304,7 @@ fn partial_jsr_package_version_info_from_slice(
.as_object_mut()
.and_then(|o| o.remove("exports"))
.unwrap_or_default(),
module_graph: None,
module_graph_1: None,
module_graph_2: None,
})
}

View file

@ -1010,6 +1010,9 @@ impl DenoDiagnostic {
} else {
match err {
ResolutionError::InvalidDowngrade { .. } => "invalid-downgrade",
ResolutionError::InvalidJsrHttpsTypesImport { .. } => {
"invalid-jsr-https-types-import"
}
ResolutionError::InvalidLocalImport { .. } => {
"invalid-local-import"
}

View file

@ -12,6 +12,7 @@ use super::tsc::AssetDocument;
use crate::args::package_json;
use crate::cache::HttpCache;
use crate::graph_util::CliJsrUrlProvider;
use crate::jsr::JsrCacheResolver;
use crate::lsp::logging::lsp_warn;
use crate::npm::CliNpmResolver;
@ -409,13 +410,22 @@ impl Document {
.map(|(s, d)| {
(
s.clone(),
d.with_new_resolver(s, Some(graph_resolver), Some(npm_resolver)),
d.with_new_resolver(
s,
&CliJsrUrlProvider,
Some(graph_resolver),
Some(npm_resolver),
),
)
})
.collect(),
);
maybe_types_dependency = self.maybe_types_dependency.as_ref().map(|d| {
Arc::new(d.with_new_resolver(Some(graph_resolver), Some(npm_resolver)))
Arc::new(d.with_new_resolver(
&CliJsrUrlProvider,
Some(graph_resolver),
Some(npm_resolver),
))
});
maybe_parsed_source = self.maybe_parsed_source();
maybe_test_module_fut = self
@ -1409,6 +1419,7 @@ impl Documents {
let graph_import = GraphImport::new(
&referrer,
imports,
&CliJsrUrlProvider,
Some(graph_resolver),
Some(npm_resolver),
);
@ -1745,6 +1756,7 @@ fn analyze_module(
// use a null file system because there's no need to bother resolving
// dynamic imports like import(`./dir/${something}`) in the LSP
file_system: &deno_graph::source::NullFileSystem,
jsr_url_provider: &CliJsrUrlProvider,
maybe_resolver: Some(resolver.as_graph_resolver()),
maybe_npm_resolver: Some(resolver.as_graph_npm_resolver()),
},

View file

@ -0,0 +1,13 @@
{
"steps": [{
"args": "run main.ts",
"output": "main.out"
}, {
"args": "check main.ts",
"output": "main.check.out",
"exitCode": 1
}, {
"args": "info main.ts",
"output": "main.info.out"
}]
}

View file

@ -0,0 +1,3 @@
error: Failed resolving types. Importing JSR packages via HTTPS specifiers for type checking is not supported for performance reasons. If you would like types, import via a `jsr:` specifier instead or else use a non-statically analyzable dynamic import.
Importing: http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts
at file:///[WILDLINE]/import_jsr_via_https/main.ts:1:21

View file

@ -0,0 +1,10 @@
local: [WILDLINE]
emit: [WILDLINE]
type: TypeScript
dependencies: [WILDLINE]
size: [WILDLINE]
file:///[WILDLINE]/main.ts ([WILDLINE])
├── http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts ([WILDLINE])
└── Importing JSR packages via HTTPS specifiers for type checking is not supported for performance reasons. If you would like types, import via a `jsr:` specifier instead or else use a non-statically analyzable dynamic import.
Importing: http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts (resolve error)

View file

@ -0,0 +1,3 @@
Download http://127.0.0.1:4250/@denotest/add/1.0.0_meta.json
Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts
3

View file

@ -0,0 +1,3 @@
import { add } from "http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts";
console.log(add(1, 2));

View file

@ -0,0 +1,4 @@
{
"args": "run -A main.ts",
"output": "main.out"
}

View file

@ -0,0 +1,5 @@
Download http://127.0.0.1:4250/@denotest/worker/meta.json
Download http://127.0.0.1:4250/@denotest/worker/0.1.0_meta.json
Download http://127.0.0.1:4250/@denotest/worker/0.1.0/mod.ts
Download http://127.0.0.1:4250/@denotest/worker/0.1.0/worker.ts
3

View file

@ -0,0 +1,5 @@
import { addAsync } from "jsr:@denotest/worker";
addAsync(1, 2).then((result) => {
console.log(result);
});

View file

@ -0,0 +1,13 @@
export function addAsync(a: number, b: number): Promise<number> {
const worker = new Worker(import.meta.resolve("./worker.ts"), {
type: "module",
});
return new Promise((resolve) => {
worker.addEventListener("message", (event) => {
resolve(event.data);
});
worker.postMessage({ a, b });
});
}

View file

@ -0,0 +1,4 @@
self.onmessage = (evt) => {
self.postMessage(evt.data.a + evt.data.b);
self.close();
};

View file

@ -0,0 +1,5 @@
{
"exports": {
".": "./mod.ts"
}
}

View file

@ -0,0 +1,5 @@
{
"versions": {
"0.1.0": {}
}
}

View file

@ -9,7 +9,7 @@ const cmd = new Deno.Command("deno", {
"run",
"-A",
"--no-config",
"npm:dprint@0.45.0",
"npm:dprint@0.45.1",
subcommand,
"--config=" + configFile,
],