Skip to content

Commit 9d315f2

Browse files
authored
fix(outdated): support updating dependencies in external import maps (#27339)
Fixes #27331. The support for it was already in `outdated`, but forgot to wire up the updating part Needs #27337
1 parent 3946956 commit 9d315f2

File tree

9 files changed

+137
-26
lines changed

9 files changed

+137
-26
lines changed

cli/tools/registry/pm/deps.rs

+35-26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use std::borrow::Cow;
44
use std::collections::HashMap;
5+
use std::path::PathBuf;
56
use std::sync::atomic::AtomicBool;
67
use std::sync::Arc;
78

@@ -11,6 +12,7 @@ use deno_config::deno_json::ConfigFileRc;
1112
use deno_config::workspace::Workspace;
1213
use deno_config::workspace::WorkspaceDirectory;
1314
use deno_core::anyhow::bail;
15+
use deno_core::anyhow::Context;
1416
use deno_core::error::AnyError;
1517
use deno_core::futures::future::try_join;
1618
use deno_core::futures::stream::FuturesOrdered;
@@ -43,10 +45,10 @@ use crate::npm::NpmFetchResolver;
4345

4446
use super::ConfigUpdater;
4547

46-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
48+
#[derive(Clone, Debug, PartialEq, Eq)]
4749
pub enum ImportMapKind {
4850
Inline,
49-
Outline,
51+
Outline(PathBuf),
5052
}
5153

5254
#[derive(Clone)]
@@ -62,9 +64,12 @@ impl DepLocation {
6264

6365
pub fn file_path(&self) -> Cow<std::path::Path> {
6466
match self {
65-
DepLocation::DenoJson(arc, _, _) => {
66-
Cow::Owned(arc.specifier.to_file_path().unwrap())
67-
}
67+
DepLocation::DenoJson(arc, _, kind) => match kind {
68+
ImportMapKind::Inline => {
69+
Cow::Owned(arc.specifier.to_file_path().unwrap())
70+
}
71+
ImportMapKind::Outline(path) => Cow::Borrowed(path.as_path()),
72+
},
6873
DepLocation::PackageJson(arc, _) => Cow::Borrowed(arc.path.as_ref()),
6974
}
7075
}
@@ -238,22 +243,30 @@ fn to_import_map_value_from_imports(
238243
fn deno_json_import_map(
239244
deno_json: &ConfigFile,
240245
) -> Result<Option<(ImportMapWithDiagnostics, ImportMapKind)>, AnyError> {
241-
let (value, kind) =
242-
if deno_json.json.imports.is_some() || deno_json.json.scopes.is_some() {
243-
(
244-
to_import_map_value_from_imports(deno_json),
245-
ImportMapKind::Inline,
246-
)
247-
} else {
248-
match deno_json.to_import_map_path()? {
249-
Some(path) => {
250-
let text = std::fs::read_to_string(&path)?;
251-
let value = serde_json::from_str(&text)?;
252-
(value, ImportMapKind::Outline)
253-
}
254-
None => return Ok(None),
246+
let (value, kind) = if deno_json.json.imports.is_some()
247+
|| deno_json.json.scopes.is_some()
248+
{
249+
(
250+
to_import_map_value_from_imports(deno_json),
251+
ImportMapKind::Inline,
252+
)
253+
} else {
254+
match deno_json.to_import_map_path()? {
255+
Some(path) => {
256+
let err_context = || {
257+
format!(
258+
"loading import map at '{}' (from \"importMap\" field in '{}')",
259+
path.display(),
260+
deno_json.specifier
261+
)
262+
};
263+
let text = std::fs::read_to_string(&path).with_context(err_context)?;
264+
let value = serde_json::from_str(&text).with_context(err_context)?;
265+
(value, ImportMapKind::Outline(path))
255266
}
256-
};
267+
None => return Ok(None),
268+
}
269+
};
257270

258271
import_map::parse_from_value(deno_json.specifier.clone(), value)
259272
.map_err(Into::into)
@@ -303,7 +316,7 @@ fn add_deps_from_deno_json(
303316
location: DepLocation::DenoJson(
304317
deno_json.clone(),
305318
key_path,
306-
import_map_kind,
319+
import_map_kind.clone(),
307320
),
308321
kind,
309322
req,
@@ -747,11 +760,7 @@ impl DepManager {
747760
let dep = &mut self.deps[dep_id.0];
748761
dep.req.version_req = version_req.clone();
749762
match &dep.location {
750-
DepLocation::DenoJson(arc, key_path, import_map_kind) => {
751-
if matches!(import_map_kind, ImportMapKind::Outline) {
752-
// not supported
753-
continue;
754-
}
763+
DepLocation::DenoJson(arc, key_path, _) => {
755764
let updater =
756765
get_or_create_updater(&mut config_updaters, &dep.location)?;
757766

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"tempDir": true,
3+
"steps": [
4+
{
5+
"args": "i",
6+
"output": "[WILDCARD]"
7+
},
8+
{
9+
"args": "outdated",
10+
"output": "outdated.out"
11+
},
12+
{
13+
"args": "outdated --update --latest",
14+
"output": "update.out"
15+
},
16+
{
17+
"args": [
18+
"eval",
19+
"console.log(Deno.readTextFileSync('import_map.json').trim())"
20+
],
21+
"output": "import_map.json.out"
22+
}
23+
]
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"importMap": "import_map.json"
3+
}

tests/specs/update/external_import_map/deno.lock

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"imports": {
3+
"@denotest/add": "jsr:@denotest/add@^0.2.0",
4+
"@denotest/subtract": "jsr:@denotest/subtract@^0.2.0",
5+
"@denotest/breaking-change-between-versions": "npm:@denotest/[email protected]",
6+
"@denotest/has-patch-versions": "npm:@denotest/has-patch-versions@^0.1.0"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"imports": {
3+
"@denotest/add": "jsr:@denotest/add@^1.0.0",
4+
"@denotest/subtract": "jsr:@denotest/subtract@^1.0.0",
5+
"@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@^2.0.0",
6+
"@denotest/has-patch-versions": "npm:@denotest/has-patch-versions@^0.2.0"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { add } from "@denotest/add";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
┌────────────────────────────────────────────────┬─────────┬────────┬────────┐
2+
│ Package │ Current │ Update │ Latest │
3+
├────────────────────────────────────────────────┼─────────┼────────┼────────┤
4+
│ jsr:@denotest/subtract │ 0.2.0 │ 0.2.0 │ 1.0.0 │
5+
├────────────────────────────────────────────────┼─────────┼────────┼────────┤
6+
│ jsr:@denotest/add │ 0.2.0 │ 0.2.1 │ 1.0.0 │
7+
├────────────────────────────────────────────────┼─────────┼────────┼────────┤
8+
│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.1 │ 0.2.0 │
9+
├────────────────────────────────────────────────┼─────────┼────────┼────────┤
10+
│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │
11+
└────────────────────────────────────────────────┴─────────┴────────┴────────┘
12+
13+
Run deno outdated --update --latest to update to the latest available versions,
14+
or deno outdated --help for more information.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[UNORDERED_START]
2+
Download http://127.0.0.1:4250/@denotest/subtract/1.0.0/mod.ts
3+
Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts
4+
Download http://localhost:4260/@denotest/has-patch-versions/0.2.0.tgz
5+
Download http://localhost:4260/@denotest/breaking-change-between-versions/2.0.0.tgz
6+
[UNORDERED_END]
7+
Updated 4 dependencies:
8+
- jsr:@denotest/add 0.2.0 -> 1.0.0
9+
- jsr:@denotest/subtract 0.2.0 -> 1.0.0
10+
- npm:@denotest/breaking-change-between-versions 1.0.0 -> 2.0.0
11+
- npm:@denotest/has-patch-versions 0.1.0 -> 0.2.0

0 commit comments

Comments
 (0)