Skip to content

Commit

Permalink
Update JavaScript side.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Aug 30, 2023
1 parent 4abddfc commit 372a194
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 85 deletions.
4 changes: 4 additions & 0 deletions js/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export type {
TypesDependency,
} from "./types.d.ts";

// note: keep this in line with deno_cache
export type CacheSetting = "only" | "use" | "reload";

export interface CreateGraphOptions {
/**
* A callback that is called with the URL string of the resource to be loaded
Expand All @@ -55,6 +58,7 @@ export interface CreateGraphOptions {
load?(
specifier: string,
isDynamic: boolean,
cacheSetting: CacheSetting
): 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
9 changes: 5 additions & 4 deletions lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ impl Loader for JsLoader {
let arg1 = JsValue::from(specifier.to_string());
let arg2 = JsValue::from(is_dynamic);
let arg3 = JsValue::from(match cache_setting {
LoaderCacheSetting::Prefer => 0,
LoaderCacheSetting::Reload => 1,
LoaderCacheSetting::Only => 3,
// note: keep these values aligned with deno_cache
LoaderCacheSetting::Only => "only",
LoaderCacheSetting::Prefer => "prefer",
LoaderCacheSetting::Reload => "reload",
});
let result = self.load.call2(&context, &arg1, &arg2);
let result = self.load.call3(&context, &arg1, &arg2, &arg3);
let f = async move {
let response = match result {
Ok(result) => {
Expand Down
16 changes: 8 additions & 8 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@ pub type LoadFuture = LocalBoxFuture<'static, LoadResult>;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum LoaderCacheSetting {
/// The implementation should prefer using the cache.
Prefer,
/// Loads a specifier where the implementation should not load
/// from an internal cache. This is only ever done when loading
/// `deno:` specifier module information and the version constraint
/// cannot be resolved.
Reload,
/// Attempts to load a specifier from the cache.
///
/// This is used to see whether the specifier is in the cache for `deno:` specifiers.
/// * If it is, then it will use the source provided to get the module information.
/// * If not, then it will use the manifest information to do resolution and
/// issue a separate request to the `load` method in order to get the source.
Only,
/// The implementation should prefer using the cache.
Prefer,
/// Loads a specifier where the implementation should not load
/// from an internal cache. This is only ever done when loading
/// `deno:` specifier module information and the version constraint
/// cannot be resolved.
Reload,
}

pub static DEFAULT_DENO_REGISTRY_URL: Lazy<Url> =
Lazy::new(|| Url::parse("https://deno-registry-staging.net").unwrap());
Lazy::new(|| Url::parse("https://registry-staging.deno.com").unwrap());

/// A trait which allows asynchronous loading of source files into a module
/// graph in a thread safe way as well as a way to provide additional meta data
Expand Down
14 changes: 7 additions & 7 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async fn test_deno_version_not_found_then_found() {
content: "import 'deno:@scope/[email protected]/mod.ts".into(),
}))
}),
"https://deno-registry-staging.net/@scope/a/meta.json" => {
"https://registry-staging.deno.com/@scope/a/meta.json" => {
Box::pin(async move {
Ok(Some(LoadResponse::Module {
specifier: specifier.clone(),
Expand All @@ -275,7 +275,7 @@ async fn test_deno_version_not_found_then_found() {
}))
})
}
"https://deno-registry-staging.net/@scope/a/1.2.0_meta.json" => {
"https://registry-staging.deno.com/@scope/a/1.2.0_meta.json" => {
Box::pin(async move {
Ok(Some(LoadResponse::Module {
specifier: specifier.clone(),
Expand All @@ -284,7 +284,7 @@ async fn test_deno_version_not_found_then_found() {
}))
})
}
"https://deno-registry-staging.net/@scope/a/1.2.0/mod.ts" => {
"https://registry-staging.deno.com/@scope/a/1.2.0/mod.ts" => {
Box::pin(async move {
Ok(Some(LoadResponse::Module {
specifier: specifier.clone(),
Expand Down Expand Up @@ -313,21 +313,21 @@ async fn test_deno_version_not_found_then_found() {
vec![
("file:///main.ts".to_string(), LoaderCacheSetting::Prefer),
(
"https://deno-registry-staging.net/@scope/a/meta.json".to_string(),
"https://registry-staging.deno.com/@scope/a/meta.json".to_string(),
LoaderCacheSetting::Prefer
),
("file:///main.ts".to_string(), LoaderCacheSetting::Prefer),
(
"https://deno-registry-staging.net/@scope/a/meta.json".to_string(),
"https://registry-staging.deno.com/@scope/a/meta.json".to_string(),
LoaderCacheSetting::Reload
),
(
"https://deno-registry-staging.net/@scope/a/1.2.0_meta.json"
"https://registry-staging.deno.com/@scope/a/1.2.0_meta.json"
.to_string(),
LoaderCacheSetting::Reload
),
(
"https://deno-registry-staging.net/@scope/a/1.2.0/mod.ts".to_string(),
"https://registry-staging.deno.com/@scope/a/1.2.0/mod.ts".to_string(),
LoaderCacheSetting::Prefer
),
]
Expand Down
44 changes: 22 additions & 22 deletions tests/specs/graph/DenoSpecifiers_ModuleGraphInfo.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# https://deno-registry-staging.net/@scope/a/meta.json
# https://registry-staging.deno.com/@scope/a/meta.json
{
"versions": {
"1.0.0": {}
}
}

# https://deno-registry-staging.net/@scope/a/1.0.0_meta.json
# https://registry-staging.deno.com/@scope/a/1.0.0_meta.json
{
"moduleGraph1": {
"/mod.ts": {
Expand All @@ -32,14 +32,14 @@
}
}

# https://deno-registry-staging.net/@scope/b/meta.json
# https://registry-staging.deno.com/@scope/b/meta.json
{
"versions": {
"9.0.0": {}
}
}

# https://deno-registry-staging.net/@scope/b/9.0.0_meta.json
# https://registry-staging.deno.com/@scope/b/9.0.0_meta.json
{
"moduleGraph1": {
"/mod.ts": {
Expand All @@ -57,22 +57,22 @@
import 'deno:@scope/a@^1.0/mod.ts';


# https://deno-registry-staging.net/@scope/a/1.0.0/mod.ts
# https://registry-staging.deno.com/@scope/a/1.0.0/mod.ts
1; // this will be ignored

# https://deno-registry-staging.net/@scope/a/1.0.0/a.ts
# https://registry-staging.deno.com/@scope/a/1.0.0/a.ts
2; // this will be ignored

# https://deno-registry-staging.net/@scope/a/1.0.0/b.ts
# https://registry-staging.deno.com/@scope/a/1.0.0/b.ts
import './c.ts';

# https://deno-registry-staging.net/@scope/a/1.0.0/c.ts
# https://registry-staging.deno.com/@scope/a/1.0.0/c.ts
3;

# https://deno-registry-staging.net/@scope/b/9.0.0/mod.ts
# https://registry-staging.deno.com/@scope/b/9.0.0/mod.ts
4;

# https://deno-registry-staging.net/@scope/b/9.0.0/inner.ts
# https://registry-staging.deno.com/@scope/b/9.0.0/inner.ts
5;

# output
Expand Down Expand Up @@ -111,7 +111,7 @@ import './c.ts';
{
"specifier": "./b.ts",
"code": {
"specifier": "https://deno-registry-staging.net/@scope/a/1.0.0/b.ts",
"specifier": "https://registry-staging.deno.com/@scope/a/1.0.0/b.ts",
"span": {
"start": {
"line": 13,
Expand Down Expand Up @@ -143,15 +143,15 @@ import './c.ts';
],
"size": 27,
"mediaType": "TypeScript",
"specifier": "https://deno-registry-staging.net/@scope/a/1.0.0/a.ts"
"specifier": "https://registry-staging.deno.com/@scope/a/1.0.0/a.ts"
},
{
"kind": "esm",
"dependencies": [
{
"specifier": "./c.ts",
"code": {
"specifier": "https://deno-registry-staging.net/@scope/a/1.0.0/c.ts",
"specifier": "https://registry-staging.deno.com/@scope/a/1.0.0/c.ts",
"span": {
"start": {
"line": 0,
Expand All @@ -167,21 +167,21 @@ import './c.ts';
],
"size": 17,
"mediaType": "TypeScript",
"specifier": "https://deno-registry-staging.net/@scope/a/1.0.0/b.ts"
"specifier": "https://registry-staging.deno.com/@scope/a/1.0.0/b.ts"
},
{
"kind": "esm",
"size": 3,
"mediaType": "TypeScript",
"specifier": "https://deno-registry-staging.net/@scope/a/1.0.0/c.ts"
"specifier": "https://registry-staging.deno.com/@scope/a/1.0.0/c.ts"
},
{
"kind": "esm",
"dependencies": [
{
"specifier": "./a.ts",
"code": {
"specifier": "https://deno-registry-staging.net/@scope/a/1.0.0/a.ts",
"specifier": "https://registry-staging.deno.com/@scope/a/1.0.0/a.ts",
"span": {
"start": {
"line": 5,
Expand All @@ -197,21 +197,21 @@ import './c.ts';
],
"size": 27,
"mediaType": "TypeScript",
"specifier": "https://deno-registry-staging.net/@scope/a/1.0.0/mod.ts"
"specifier": "https://registry-staging.deno.com/@scope/a/1.0.0/mod.ts"
},
{
"kind": "esm",
"size": 3,
"mediaType": "TypeScript",
"specifier": "https://deno-registry-staging.net/@scope/b/9.0.0/inner.ts"
"specifier": "https://registry-staging.deno.com/@scope/b/9.0.0/inner.ts"
},
{
"kind": "esm",
"dependencies": [
{
"specifier": "./inner.ts",
"code": {
"specifier": "https://deno-registry-staging.net/@scope/b/9.0.0/inner.ts",
"specifier": "https://registry-staging.deno.com/@scope/b/9.0.0/inner.ts",
"span": {
"start": {
"line": 5,
Expand All @@ -227,12 +227,12 @@ import './c.ts';
],
"size": 3,
"mediaType": "TypeScript",
"specifier": "https://deno-registry-staging.net/@scope/b/9.0.0/mod.ts"
"specifier": "https://registry-staging.deno.com/@scope/b/9.0.0/mod.ts"
}
],
"redirects": {
"deno:@scope/a@^1.0/mod.ts": "https://deno-registry-staging.net/@scope/a/1.0.0/mod.ts",
"deno:@scope/b/mod.ts": "https://deno-registry-staging.net/@scope/b/9.0.0/mod.ts"
"deno:@scope/a@^1.0/mod.ts": "https://registry-staging.deno.com/@scope/a/1.0.0/mod.ts",
"deno:@scope/b/mod.ts": "https://registry-staging.deno.com/@scope/b/9.0.0/mod.ts"
},
"deno": {
"@scope/a@^1.0": "@scope/[email protected]",
Expand Down
Loading

0 comments on commit 372a194

Please sign in to comment.