1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05: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:
Nathan Whitaker 2024-10-15 09:38:42 -07:00 committed by GitHub
parent 533a9b1086
commit 797405fc61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 4 deletions

View file

@ -400,14 +400,17 @@ impl std::fmt::Display for AddCommandName {
fn load_configs( fn load_configs(
flags: &Arc<Flags>, flags: &Arc<Flags>,
has_jsr_specifiers: impl FnOnce() -> bool,
) -> Result<(CliFactory, Option<NpmConfig>, Option<DenoConfig>), AnyError> { ) -> Result<(CliFactory, Option<NpmConfig>, Option<DenoConfig>), AnyError> {
let cli_factory = CliFactory::from_flags(flags.clone()); let cli_factory = CliFactory::from_flags(flags.clone());
let options = cli_factory.cli_options()?; let options = cli_factory.cli_options()?;
let npm_config = NpmConfig::from_options(options)?; let npm_config = NpmConfig::from_options(options)?;
let (cli_factory, deno_config) = match DenoConfig::from_options(options)? { let (cli_factory, deno_config) = match DenoConfig::from_options(options)? {
Some(config) => (cli_factory, Some(config)), Some(config) => (cli_factory, Some(config)),
None if npm_config.is_some() => (cli_factory, None), None if npm_config.is_some() && !has_jsr_specifiers() => {
None => { (cli_factory, None)
}
_ => {
let factory = create_deno_json(flags, options)?; let factory = create_deno_json(flags, options)?;
let options = factory.cli_options()?.clone(); let options = factory.cli_options()?.clone();
( (
@ -427,7 +430,9 @@ pub async fn add(
add_flags: AddFlags, add_flags: AddFlags,
cmd_name: AddCommandName, cmd_name: AddCommandName,
) -> Result<(), AnyError> { ) -> 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 npm_config = ConfigUpdater::maybe_new(npm_config).await?;
let mut deno_config = ConfigUpdater::maybe_new(deno_config).await?; let mut deno_config = ConfigUpdater::maybe_new(deno_config).await?;
@ -764,7 +769,7 @@ pub async fn remove(
flags: Arc<Flags>, flags: Arc<Flags>,
remove_flags: RemoveFlags, remove_flags: RemoveFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let (_, npm_config, deno_config) = load_configs(&flags)?; let (_, npm_config, deno_config) = load_configs(&flags, || false)?;
let mut configs = [ let mut configs = [
ConfigUpdater::maybe_new(npm_config).await?, ConfigUpdater::maybe_new(npm_config).await?,

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

View file

@ -0,0 +1,3 @@
Created deno.json configuration file.
Add jsr:@denotest/add@1.0.0
Download [WILDCARD]

View file

@ -0,0 +1,5 @@
{
"imports": {
"@denotest/add": "jsr:@denotest/add@^1.0.0"
}
}

View file

@ -0,0 +1 @@
{}