Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsr): https import of jsr dep that has a dependency #466

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2945,6 +2945,12 @@ struct PendingInfo {
redirects: BTreeMap<ModuleSpecifier, ModuleSpecifier>,
result: Result<Option<PendingInfoResponse>, Arc<anyhow::Error>>,
maybe_version_info: Option<JsrPackageVersionInfoExt>,
loaded_package_via_https_url: Option<LoadedJsrPackageViaHttpsUrl>,
}

struct LoadedJsrPackageViaHttpsUrl {
nv: PackageNv,
manifest_checksum: String,
}

type PendingInfoFuture<'a> = LocalBoxFuture<'a, PendingInfo>;
Expand Down Expand Up @@ -3186,7 +3192,15 @@ impl<'a, 'graph> Builder<'a, 'graph> {
result,
redirects,
maybe_version_info,
loaded_package_via_https_url,
}) => {
if let Some(pkg) = loaded_package_via_https_url {
self
.graph
.packages
.ensure_package(pkg.nv, pkg.manifest_checksum);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the bug. Basically it needs to record that we imported this package.


for (from, to) in redirects {
self.add_redirect(from, to);
}
Expand Down Expand Up @@ -3803,6 +3817,7 @@ impl<'a, 'graph> Builder<'a, 'graph> {
})),
redirects: BTreeMap::new(),
maybe_version_info: Some(version_info),
loaded_package_via_https_url: None,
},
response => PendingInfo {
specifier,
Expand Down Expand Up @@ -3832,6 +3847,7 @@ impl<'a, 'graph> Builder<'a, 'graph> {
Err(err) => Err(Arc::new(err)),
},
maybe_version_info: Some(version_info),
loaded_package_via_https_url: None,
},
}
}
Expand Down Expand Up @@ -4135,21 +4151,27 @@ impl<'a, 'graph> Builder<'a, 'graph> {
load_specifier: ModuleSpecifier,
mut maybe_checksum: Option<LoaderChecksum>,
maybe_version_info: &mut Option<JsrPackageVersionInfoExt>,
loaded_package_via_https_url: &mut Option<LoadedJsrPackageViaHttpsUrl>,
redirects: &mut BTreeMap<ModuleSpecifier, ModuleSpecifier>,
maybe_version_load_fut: Option<(PackageNv, PendingResult<PendingJsrPackageVersionInfoLoadItem>)>,
is_dynamic: bool,
loader: &dyn Loader,
jsr_url_provider: &dyn JsrUrlProvider,
) -> Result<Option<PendingInfoResponse>, Arc<anyhow::Error>> {
if let Some((package_nv, fut)) = maybe_version_load_fut {
let inner = fut.await?;
let info = JsrPackageVersionInfoExt {
base_url: jsr_url_provider.package_url(&package_nv),
inner: fut.await?.info,
inner: inner.info,
};
if let Some(sub_path) = info.get_subpath(&load_specifier) {
maybe_checksum = Some(LoaderChecksum::new(info.get_checksum(sub_path)?.to_string()));
}
maybe_version_info.replace(info);
loaded_package_via_https_url.replace(LoadedJsrPackageViaHttpsUrl {
nv: package_nv,
manifest_checksum: inner.checksum,
});
}
let mut load_specifier = load_specifier;
for _ in 0..=loader.max_redirects() {
Expand Down Expand Up @@ -4190,11 +4212,13 @@ impl<'a, 'graph> Builder<'a, 'graph> {
content,
specifier,
maybe_headers,
} => {return Ok(Some(PendingInfoResponse::Module {
content_or_module_info: ContentOrModuleInfo::Content(content),
specifier,
maybe_headers,
}))},
} => {
return Ok(Some(PendingInfoResponse::Module {
content_or_module_info: ContentOrModuleInfo::Content(content),
specifier,
maybe_headers,
}))
},
},
Ok(None) => return Ok(None),
Err(err) => return Err(Arc::new(err)),
Expand All @@ -4205,10 +4229,12 @@ impl<'a, 'graph> Builder<'a, 'graph> {
}

let mut redirects = BTreeMap::new();
let mut loaded_package_via_https_url = None;
let result = try_load_with_redirects(
load_specifier,
maybe_checksum,
&mut maybe_version_info,
&mut loaded_package_via_https_url,
&mut redirects,
maybe_version_load_fut,
is_dynamic,
Expand All @@ -4222,6 +4248,7 @@ impl<'a, 'graph> Builder<'a, 'graph> {
redirects,
result,
maybe_version_info,
loaded_package_via_https_url,
}
}
.boxed_local();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}
}
}

# https://jsr.io/@scope/a/1.0.0/mod.ts
export class Test {}

Expand Down
126 changes: 126 additions & 0 deletions tests/specs/graph/jsr/import_via_https_with_deps.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# https://jsr.io/@scope/a/meta.json
{"versions": { "1.0.0": {} } }

# https://jsr.io/@scope/a/1.0.0_meta.json
{
"exports": {
".": "./mod.ts"
}
}

# https://jsr.io/@scope/a/1.0.0/mod.ts
import { Test as Other } from "jsr:@scope/b";
export class Test {}

# https://jsr.io/@scope/b/meta.json
{"versions": { "1.0.0": {} } }

# https://jsr.io/@scope/b/1.0.0_meta.json
{
"exports": {
".": "./mod.ts"
}
}

# https://jsr.io/@scope/b/1.0.0/mod.ts
export class Test {}

# mod.ts
import { Test } from "https://jsr.io/@scope/a/1.0.0/mod.ts";
console.log(Test);

# output
{
"roots": [
"file:///mod.ts"
],
"modules": [
{
"kind": "esm",
"dependencies": [
{
"specifier": "https://jsr.io/@scope/a/1.0.0/mod.ts",
"code": {
"specifier": "https://jsr.io/@scope/a/1.0.0/mod.ts",
"span": {
"start": {
"line": 0,
"character": 21
},
"end": {
"line": 0,
"character": 59
}
}
},
"type": {
"error": "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.\n Importing: https://jsr.io/@scope/a/1.0.0/mod.ts",
"span": {
"start": {
"line": 0,
"character": 21
},
"end": {
"line": 0,
"character": 59
}
}
}
}
],
"size": 80,
"mediaType": "TypeScript",
"specifier": "file:///mod.ts"
},
{
"kind": "esm",
"dependencies": [
{
"specifier": "jsr:@scope/b",
"code": {
"specifier": "jsr:@scope/b",
"span": {
"start": {
"line": 0,
"character": 30
},
"end": {
"line": 0,
"character": 44
}
}
}
}
],
"size": 67,
"mediaType": "TypeScript",
"specifier": "https://jsr.io/@scope/a/1.0.0/mod.ts"
},
{
"kind": "esm",
"size": 21,
"mediaType": "TypeScript",
"specifier": "https://jsr.io/@scope/b/1.0.0/mod.ts"
}
],
"redirects": {
"jsr:@scope/b": "https://jsr.io/@scope/b/1.0.0/mod.ts"
},
"packages": {
"@scope/b": "@scope/b@1.0.0"
}
}

jsr deps: {
"@scope/a@1.0.0": [
"jsr:@scope/b",
],
}

Fast check https://jsr.io/@scope/b/1.0.0/mod.ts:
{}
export class Test {
}
--- DTS ---
export declare class Test {
}