1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-18 03:44:05 -05:00

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
This commit is contained in:
Nathan Whitaker 2024-12-13 12:25:05 -08:00 committed by GitHub
parent 3946956b8c
commit 9d315f27ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 137 additions and 26 deletions

View file

@ -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<std::path::Path> {
match self {
DepLocation::DenoJson(arc, _, _) => {
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,8 +243,9 @@ fn to_import_map_value_from_imports(
fn deno_json_import_map(
deno_json: &ConfigFile,
) -> Result<Option<(ImportMapWithDiagnostics, ImportMapKind)>, AnyError> {
let (value, kind) =
if deno_json.json.imports.is_some() || deno_json.json.scopes.is_some() {
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,
@ -247,9 +253,16 @@ fn deno_json_import_map(
} 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)
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),
}
@ -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)?;

View file

@ -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"
}
]
}

View file

@ -0,0 +1,3 @@
{
"importMap": "import_map.json"
}

View file

@ -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"
]
}
}

View file

@ -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"
}
}

View file

@ -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"
}
}

View file

@ -0,0 +1 @@
import { add } from "@denotest/add";

View file

@ -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.

View file

@ -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