mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 20:38:55 +00:00
fix(add): create deno.json when running deno add jsr:<pkg>
(#26275)
Fixes https://github.com/denoland/deno/issues/26119. Originally I wanted to put them in package.json if there's no deno.json, but on second thought it makes more sense to just create a deno.json
This commit is contained in:
parent
533a9b1086
commit
797405fc61
@ -400,14 +400,17 @@ impl std::fmt::Display for AddCommandName {
|
||||
|
||||
fn load_configs(
|
||||
flags: &Arc<Flags>,
|
||||
has_jsr_specifiers: impl FnOnce() -> bool,
|
||||
) -> Result<(CliFactory, Option<NpmConfig>, Option<DenoConfig>), AnyError> {
|
||||
let cli_factory = CliFactory::from_flags(flags.clone());
|
||||
let options = cli_factory.cli_options()?;
|
||||
let npm_config = NpmConfig::from_options(options)?;
|
||||
let (cli_factory, deno_config) = match DenoConfig::from_options(options)? {
|
||||
Some(config) => (cli_factory, Some(config)),
|
||||
None if npm_config.is_some() => (cli_factory, None),
|
||||
None => {
|
||||
None if npm_config.is_some() && !has_jsr_specifiers() => {
|
||||
(cli_factory, None)
|
||||
}
|
||||
_ => {
|
||||
let factory = create_deno_json(flags, options)?;
|
||||
let options = factory.cli_options()?.clone();
|
||||
(
|
||||
@ -427,7 +430,9 @@ pub async fn add(
|
||||
add_flags: AddFlags,
|
||||
cmd_name: AddCommandName,
|
||||
) -> Result<(), AnyError> {
|
||||
let (cli_factory, npm_config, deno_config) = load_configs(&flags)?;
|
||||
let (cli_factory, npm_config, deno_config) = load_configs(&flags, || {
|
||||
add_flags.packages.iter().any(|s| s.starts_with("jsr:"))
|
||||
})?;
|
||||
let mut npm_config = ConfigUpdater::maybe_new(npm_config).await?;
|
||||
let mut deno_config = ConfigUpdater::maybe_new(deno_config).await?;
|
||||
|
||||
@ -764,7 +769,7 @@ pub async fn remove(
|
||||
flags: Arc<Flags>,
|
||||
remove_flags: RemoveFlags,
|
||||
) -> Result<(), AnyError> {
|
||||
let (_, npm_config, deno_config) = load_configs(&flags)?;
|
||||
let (_, npm_config, deno_config) = load_configs(&flags, || false)?;
|
||||
|
||||
let mut configs = [
|
||||
ConfigUpdater::maybe_new(npm_config).await?,
|
||||
|
16
tests/specs/add/jsr_prefers_deno_json/__test__.jsonc
Normal file
16
tests/specs/add/jsr_prefers_deno_json/__test__.jsonc
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"tempDir": true,
|
||||
"steps": [
|
||||
{
|
||||
"args": "add jsr:@denotest/add",
|
||||
"output": "add.out"
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
"eval",
|
||||
"console.log(Deno.readTextFileSync('./deno.json').trim())"
|
||||
],
|
||||
"output": "deno.json.out"
|
||||
}
|
||||
]
|
||||
}
|
3
tests/specs/add/jsr_prefers_deno_json/add.out
Normal file
3
tests/specs/add/jsr_prefers_deno_json/add.out
Normal file
@ -0,0 +1,3 @@
|
||||
Created deno.json configuration file.
|
||||
Add jsr:@denotest/add@1.0.0
|
||||
Download [WILDCARD]
|
5
tests/specs/add/jsr_prefers_deno_json/deno.json.out
Normal file
5
tests/specs/add/jsr_prefers_deno_json/deno.json.out
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"imports": {
|
||||
"@denotest/add": "jsr:@denotest/add@^1.0.0"
|
||||
}
|
||||
}
|
1
tests/specs/add/jsr_prefers_deno_json/package.json
Normal file
1
tests/specs/add/jsr_prefers_deno_json/package.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
Loading…
Reference in New Issue
Block a user