diff --git a/cli/tools/registry/pm/deps.rs b/cli/tools/registry/pm/deps.rs index d82e9954cd..e4c38276f7 100644 --- a/cli/tools/registry/pm/deps.rs +++ b/cli/tools/registry/pm/deps.rs @@ -2,6 +2,7 @@ use std::borrow::Cow; use std::collections::HashMap; +use std::path::PathBuf; use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -11,6 +12,7 @@ use deno_config::deno_json::ConfigFileRc; use deno_config::workspace::Workspace; use deno_config::workspace::WorkspaceDirectory; use deno_core::anyhow::bail; +use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::future::try_join; use deno_core::futures::stream::FuturesOrdered; @@ -43,10 +45,10 @@ use crate::npm::NpmFetchResolver; use super::ConfigUpdater; -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum ImportMapKind { Inline, - Outline, + Outline(PathBuf), } #[derive(Clone)] @@ -62,9 +64,12 @@ impl DepLocation { pub fn file_path(&self) -> Cow { match self { - DepLocation::DenoJson(arc, _, _) => { - Cow::Owned(arc.specifier.to_file_path().unwrap()) - } + DepLocation::DenoJson(arc, _, kind) => match kind { + ImportMapKind::Inline => { + Cow::Owned(arc.specifier.to_file_path().unwrap()) + } + ImportMapKind::Outline(path) => Cow::Borrowed(path.as_path()), + }, DepLocation::PackageJson(arc, _) => Cow::Borrowed(arc.path.as_ref()), } } @@ -238,22 +243,30 @@ fn to_import_map_value_from_imports( fn deno_json_import_map( deno_json: &ConfigFile, ) -> Result, AnyError> { - let (value, kind) = - if deno_json.json.imports.is_some() || deno_json.json.scopes.is_some() { - ( - to_import_map_value_from_imports(deno_json), - ImportMapKind::Inline, - ) - } else { - match deno_json.to_import_map_path()? { - Some(path) => { - let text = std::fs::read_to_string(&path)?; - let value = serde_json::from_str(&text)?; - (value, ImportMapKind::Outline) - } - None => return Ok(None), + let (value, kind) = if deno_json.json.imports.is_some() + || deno_json.json.scopes.is_some() + { + ( + to_import_map_value_from_imports(deno_json), + ImportMapKind::Inline, + ) + } else { + match deno_json.to_import_map_path()? { + Some(path) => { + let err_context = || { + format!( + "loading import map at '{}' (from \"importMap\" field in '{}')", + path.display(), + deno_json.specifier + ) + }; + let text = std::fs::read_to_string(&path).with_context(err_context)?; + let value = serde_json::from_str(&text).with_context(err_context)?; + (value, ImportMapKind::Outline(path)) } - }; + None => return Ok(None), + } + }; import_map::parse_from_value(deno_json.specifier.clone(), value) .map_err(Into::into) @@ -303,7 +316,7 @@ fn add_deps_from_deno_json( location: DepLocation::DenoJson( deno_json.clone(), key_path, - import_map_kind, + import_map_kind.clone(), ), kind, req, @@ -747,11 +760,7 @@ impl DepManager { let dep = &mut self.deps[dep_id.0]; dep.req.version_req = version_req.clone(); match &dep.location { - DepLocation::DenoJson(arc, key_path, import_map_kind) => { - if matches!(import_map_kind, ImportMapKind::Outline) { - // not supported - continue; - } + DepLocation::DenoJson(arc, key_path, _) => { let updater = get_or_create_updater(&mut config_updaters, &dep.location)?; diff --git a/tests/specs/update/external_import_map/__test__.jsonc b/tests/specs/update/external_import_map/__test__.jsonc new file mode 100644 index 0000000000..66dc55cc57 --- /dev/null +++ b/tests/specs/update/external_import_map/__test__.jsonc @@ -0,0 +1,24 @@ +{ + "tempDir": true, + "steps": [ + { + "args": "i", + "output": "[WILDCARD]" + }, + { + "args": "outdated", + "output": "outdated.out" + }, + { + "args": "outdated --update --latest", + "output": "update.out" + }, + { + "args": [ + "eval", + "console.log(Deno.readTextFileSync('import_map.json').trim())" + ], + "output": "import_map.json.out" + } + ] +} diff --git a/tests/specs/update/external_import_map/deno.json b/tests/specs/update/external_import_map/deno.json new file mode 100644 index 0000000000..ee44ba9472 --- /dev/null +++ b/tests/specs/update/external_import_map/deno.json @@ -0,0 +1,3 @@ +{ + "importMap": "import_map.json" +} diff --git a/tests/specs/update/external_import_map/deno.lock b/tests/specs/update/external_import_map/deno.lock new file mode 100644 index 0000000000..940f2527d8 --- /dev/null +++ b/tests/specs/update/external_import_map/deno.lock @@ -0,0 +1,33 @@ +{ + "version": "4", + "specifiers": { + "jsr:@denotest/add@0.2": "0.2.0", + "jsr:@denotest/subtract@0.2": "0.2.0", + "npm:@denotest/breaking-change-between-versions@1.0.0": "1.0.0", + "npm:@denotest/has-patch-versions@0.1": "0.1.0" + }, + "jsr": { + "@denotest/add@0.2.0": { + "integrity": "a9076d30ecb42b2fc6dd95e7055fbf4e6358b53f550741bd7f60089d19f68848" + }, + "@denotest/subtract@0.2.0": { + "integrity": "c9650fc559ab2430effc0c7fb1540e3aa89888fbdd926335ccfdeac57eb3a64d" + } + }, + "npm": { + "@denotest/breaking-change-between-versions@1.0.0": { + "integrity": "sha512-bzMGYx+DxxPlI74n/VsDAN7Db1BY7Sz2XqxXruMo9dEznsBZu7Ez3i8YQ8n0leTxAiiMk1RCG4zQHPG1aj3xRw==" + }, + "@denotest/has-patch-versions@0.1.0": { + "integrity": "sha512-H/MBo0jKDdMsX4AAGEGQbZj70nfNe3oUNZXbohYHhqf9EfpLnXp/7FC29ZdfV4+p6VjEcOGdCtXc6rilE6iYpg==" + } + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/add@0.2", + "jsr:@denotest/subtract@0.2", + "npm:@denotest/breaking-change-between-versions@1.0.0", + "npm:@denotest/has-patch-versions@0.1" + ] + } +} diff --git a/tests/specs/update/external_import_map/import_map.json b/tests/specs/update/external_import_map/import_map.json new file mode 100644 index 0000000000..9cc5c77e24 --- /dev/null +++ b/tests/specs/update/external_import_map/import_map.json @@ -0,0 +1,8 @@ +{ + "imports": { + "@denotest/add": "jsr:@denotest/add@^0.2.0", + "@denotest/subtract": "jsr:@denotest/subtract@^0.2.0", + "@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@1.0.0", + "@denotest/has-patch-versions": "npm:@denotest/has-patch-versions@^0.1.0" + } +} diff --git a/tests/specs/update/external_import_map/import_map.json.out b/tests/specs/update/external_import_map/import_map.json.out new file mode 100644 index 0000000000..b4e24decbc --- /dev/null +++ b/tests/specs/update/external_import_map/import_map.json.out @@ -0,0 +1,8 @@ +{ + "imports": { + "@denotest/add": "jsr:@denotest/add@^1.0.0", + "@denotest/subtract": "jsr:@denotest/subtract@^1.0.0", + "@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@^2.0.0", + "@denotest/has-patch-versions": "npm:@denotest/has-patch-versions@^0.2.0" + } +} diff --git a/tests/specs/update/external_import_map/main.ts b/tests/specs/update/external_import_map/main.ts new file mode 100644 index 0000000000..b008bb0d41 --- /dev/null +++ b/tests/specs/update/external_import_map/main.ts @@ -0,0 +1 @@ +import { add } from "@denotest/add"; diff --git a/tests/specs/update/external_import_map/outdated.out b/tests/specs/update/external_import_map/outdated.out new file mode 100644 index 0000000000..8752b132bf --- /dev/null +++ b/tests/specs/update/external_import_map/outdated.out @@ -0,0 +1,14 @@ +┌────────────────────────────────────────────────┬─────────┬────────┬────────┐ +│ Package │ Current │ Update │ Latest │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/subtract │ 0.2.0 │ 0.2.0 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/add │ 0.2.0 │ 0.2.1 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.1 │ 0.2.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │ +└────────────────────────────────────────────────┴─────────┴────────┴────────┘ + +Run deno outdated --update --latest to update to the latest available versions, +or deno outdated --help for more information. diff --git a/tests/specs/update/external_import_map/update.out b/tests/specs/update/external_import_map/update.out new file mode 100644 index 0000000000..d075cff296 --- /dev/null +++ b/tests/specs/update/external_import_map/update.out @@ -0,0 +1,11 @@ +[UNORDERED_START] +Download http://127.0.0.1:4250/@denotest/subtract/1.0.0/mod.ts +Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts +Download http://localhost:4260/@denotest/has-patch-versions/0.2.0.tgz +Download http://localhost:4260/@denotest/breaking-change-between-versions/2.0.0.tgz +[UNORDERED_END] +Updated 4 dependencies: + - jsr:@denotest/add 0.2.0 -> 1.0.0 + - jsr:@denotest/subtract 0.2.0 -> 1.0.0 + - npm:@denotest/breaking-change-between-versions 1.0.0 -> 2.0.0 + - npm:@denotest/has-patch-versions 0.1.0 -> 0.2.0