mirror of
https://github.com/denoland/deno.git
synced 2025-01-18 11:53:59 -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:
parent
3946956b8c
commit
9d315f27ed
9 changed files with 137 additions and 26 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ use deno_config::deno_json::ConfigFileRc;
|
||||||
use deno_config::workspace::Workspace;
|
use deno_config::workspace::Workspace;
|
||||||
use deno_config::workspace::WorkspaceDirectory;
|
use deno_config::workspace::WorkspaceDirectory;
|
||||||
use deno_core::anyhow::bail;
|
use deno_core::anyhow::bail;
|
||||||
|
use deno_core::anyhow::Context;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::futures::future::try_join;
|
use deno_core::futures::future::try_join;
|
||||||
use deno_core::futures::stream::FuturesOrdered;
|
use deno_core::futures::stream::FuturesOrdered;
|
||||||
|
@ -43,10 +45,10 @@ use crate::npm::NpmFetchResolver;
|
||||||
|
|
||||||
use super::ConfigUpdater;
|
use super::ConfigUpdater;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum ImportMapKind {
|
pub enum ImportMapKind {
|
||||||
Inline,
|
Inline,
|
||||||
Outline,
|
Outline(PathBuf),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -62,9 +64,12 @@ impl DepLocation {
|
||||||
|
|
||||||
pub fn file_path(&self) -> Cow<std::path::Path> {
|
pub fn file_path(&self) -> Cow<std::path::Path> {
|
||||||
match self {
|
match self {
|
||||||
DepLocation::DenoJson(arc, _, _) => {
|
DepLocation::DenoJson(arc, _, kind) => match kind {
|
||||||
Cow::Owned(arc.specifier.to_file_path().unwrap())
|
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()),
|
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(
|
fn deno_json_import_map(
|
||||||
deno_json: &ConfigFile,
|
deno_json: &ConfigFile,
|
||||||
) -> Result<Option<(ImportMapWithDiagnostics, ImportMapKind)>, AnyError> {
|
) -> Result<Option<(ImportMapWithDiagnostics, ImportMapKind)>, AnyError> {
|
||||||
let (value, kind) =
|
let (value, kind) = if deno_json.json.imports.is_some()
|
||||||
if deno_json.json.imports.is_some() || deno_json.json.scopes.is_some() {
|
|| deno_json.json.scopes.is_some()
|
||||||
(
|
{
|
||||||
to_import_map_value_from_imports(deno_json),
|
(
|
||||||
ImportMapKind::Inline,
|
to_import_map_value_from_imports(deno_json),
|
||||||
)
|
ImportMapKind::Inline,
|
||||||
} else {
|
)
|
||||||
match deno_json.to_import_map_path()? {
|
} else {
|
||||||
Some(path) => {
|
match deno_json.to_import_map_path()? {
|
||||||
let text = std::fs::read_to_string(&path)?;
|
Some(path) => {
|
||||||
let value = serde_json::from_str(&text)?;
|
let err_context = || {
|
||||||
(value, ImportMapKind::Outline)
|
format!(
|
||||||
}
|
"loading import map at '{}' (from \"importMap\" field in '{}')",
|
||||||
None => return Ok(None),
|
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)
|
import_map::parse_from_value(deno_json.specifier.clone(), value)
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
|
@ -303,7 +316,7 @@ fn add_deps_from_deno_json(
|
||||||
location: DepLocation::DenoJson(
|
location: DepLocation::DenoJson(
|
||||||
deno_json.clone(),
|
deno_json.clone(),
|
||||||
key_path,
|
key_path,
|
||||||
import_map_kind,
|
import_map_kind.clone(),
|
||||||
),
|
),
|
||||||
kind,
|
kind,
|
||||||
req,
|
req,
|
||||||
|
@ -747,11 +760,7 @@ impl DepManager {
|
||||||
let dep = &mut self.deps[dep_id.0];
|
let dep = &mut self.deps[dep_id.0];
|
||||||
dep.req.version_req = version_req.clone();
|
dep.req.version_req = version_req.clone();
|
||||||
match &dep.location {
|
match &dep.location {
|
||||||
DepLocation::DenoJson(arc, key_path, import_map_kind) => {
|
DepLocation::DenoJson(arc, key_path, _) => {
|
||||||
if matches!(import_map_kind, ImportMapKind::Outline) {
|
|
||||||
// not supported
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let updater =
|
let updater =
|
||||||
get_or_create_updater(&mut config_updaters, &dep.location)?;
|
get_or_create_updater(&mut config_updaters, &dep.location)?;
|
||||||
|
|
||||||
|
|
24
tests/specs/update/external_import_map/__test__.jsonc
Normal file
24
tests/specs/update/external_import_map/__test__.jsonc
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
3
tests/specs/update/external_import_map/deno.json
Normal file
3
tests/specs/update/external_import_map/deno.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"importMap": "import_map.json"
|
||||||
|
}
|
33
tests/specs/update/external_import_map/deno.lock
generated
Normal file
33
tests/specs/update/external_import_map/deno.lock
generated
Normal 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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
8
tests/specs/update/external_import_map/import_map.json
Normal file
8
tests/specs/update/external_import_map/import_map.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
1
tests/specs/update/external_import_map/main.ts
Normal file
1
tests/specs/update/external_import_map/main.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
import { add } from "@denotest/add";
|
14
tests/specs/update/external_import_map/outdated.out
Normal file
14
tests/specs/update/external_import_map/outdated.out
Normal 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.
|
11
tests/specs/update/external_import_map/update.out
Normal file
11
tests/specs/update/external_import_map/update.out
Normal 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
|
Loading…
Add table
Reference in a new issue