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

feat: load JSR URLs using checksum found in package's manifest #380

Merged
merged 11 commits into from
Feb 15, 2024
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ parking_lot = "0.12.0"
regex = "1.10.2"
serde = { version = "1.0.130", features = ["derive", "rc"] }
serde_json = { version = "1.0.67", features = ["preserve_order"] }
sha2 = "^0.10.0"
dsherret marked this conversation as resolved.
Show resolved Hide resolved
thiserror = "1.0.24"
url = { version = "2.2.2", features = ["serde"] }

Expand Down
15 changes: 12 additions & 3 deletions js/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface CreateGraphOptions {
specifier: string,
isDynamic: boolean,
cacheSetting: CacheSetting,
checksum: string | undefined,
): Promise<LoadResponse | undefined>;
/** The type of graph to build. `"all"` includes all dependencies of the
* roots. `"typesOnly"` skips any code only dependencies that do not impact
Expand Down Expand Up @@ -143,10 +144,18 @@ export async function createGraph(
rootSpecifiers,
async (
specifier: string,
isDynamic: boolean,
cacheSetting: CacheSetting,
options: {
isDynamic: boolean;
cacheSetting: CacheSetting;
checksum: string | undefined;
},
) => {
const result = await load(specifier, isDynamic, cacheSetting);
const result = await load(
specifier,
options.isDynamic,
options.cacheSetting,
options.checksum,
);
if (result?.kind === "module") {
if (typeof result.content === "string") {
result.content = encoder.encode(result.content);
Expand Down
22 changes: 16 additions & 6 deletions lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::collections::HashMap;
use deno_graph::resolve_import;
use deno_graph::source::load_data_url;
use deno_graph::source::CacheInfo;
use deno_graph::source::CacheSetting;
use deno_graph::source::LoadFuture;
use deno_graph::source::LoadOptions;
use deno_graph::source::Loader;
use deno_graph::source::NullFileSystem;
use deno_graph::source::ResolutionMode;
Expand Down Expand Up @@ -65,18 +65,28 @@ impl Loader for JsLoader {
fn load(
&mut self,
specifier: &ModuleSpecifier,
is_dynamic: bool,
cache_setting: CacheSetting,
options: LoadOptions,
) -> LoadFuture {
#[derive(Serialize)]
struct JsLoadOptions {
is_dynamic: bool,
cache_setting: &'static str,
maybe_checksum: Option<String>,
}

if specifier.scheme() == "data" {
Box::pin(future::ready(load_data_url(specifier)))
} else {
let specifier = specifier.clone();
let context = JsValue::null();
let arg1 = JsValue::from(specifier.to_string());
let arg2 = JsValue::from(is_dynamic);
let arg3 = JsValue::from(cache_setting.as_js_str());
let result = self.load.call3(&context, &arg1, &arg2, &arg3);
let arg2 = serde_wasm_bindgen::to_value(&JsLoadOptions {
is_dynamic: options.is_dynamic,
cache_setting: options.cache_setting.as_js_str(),
maybe_checksum: options.maybe_checksum.map(|c| c.into_string()),
})
.unwrap();
let result = self.load.call2(&context, &arg1, &arg2);
let f = async move {
let response = match result {
Ok(result) => {
Expand Down
Loading
Loading