Skip to content

Conversation

@amyssnippet
Copy link
Contributor

Fixes #30803

Description

This PR introduces the --save-exact flag (and its alias --exact) to the deno add. rn, deno defaults to prepending a caret (^) to installed versions (e.g., ^1.0.0). This flag allows users to opt-out of this behavior and save the exact version string (e.g., 1.0.0) to deno.json or package.json, aligning with the behavior found in npm, pnpm, and yarn.

Changes

  • Updated AddFlags in cli/args/flags.rs to include save_exact.
  • Updated cli/tools/pm/mod.rs to pass this flag to the version selection logic.
  • Implemented logic to return an empty prefix string "" instead of ^ when the flag is present.

@amyssnippet
Copy link
Contributor Author

@dsherret @bartlomieju , rn i only did this for deno add, if you proceed, i will continue towards deno install

amol@Amols-MacBook-Air deno %cd deno_test_add 
amol@Amols-MacBook-Air deno_test_add %deno init
✅ Project initialized

Run these commands to get started

  # Run the program
  deno run main.ts

  # Run the program and watch for file changes
  deno task dev

  # Run the tests
  deno test
amol@Amols-MacBook-Air deno_test_add %cat deno.json
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1"
  }
}
amol@Amols-MacBook-Air deno_test_add %deno add jsr:@std/http --save-exact
error: unexpected argument '--save-exact' found

  tip: a similar argument exists: '--unstable-net'

Usage: deno add <packages>...

amol@Amols-MacBook-Air deno_test_add %deno add jsr:@std/http             
Add jsr:@std/[email protected]
amol@Amols-MacBook-Air deno_test_add %cat deno.json 
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1",
    "@std/http": "jsr:@std/http@^1.0.23"
  }
}
amol@Amols-MacBook-Air deno_test_add %deno remove jsr:@std/http             
Removed @std/http
amol@Amols-MacBook-Air deno_test_add %cat deno.json             
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1"
  }
}
amol@Amols-MacBook-Air deno_test_add %./target/debug/deno add jsr:@std/http --save-exact
zsh: no such file or directory: ./target/debug/deno
amol@Amols-MacBook-Air deno_test_add %../target/debug/deno add jsr:@std/http --save-exact
Add jsr:@std/[email protected]
amol@Amols-MacBook-Air deno_test_add %cat deno.json                                      
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1",
    "@std/http": "jsr:@std/[email protected]"
  }
}
amol@Amols-MacBook-Air deno_test_add %../target/debug/deno remove jsr:@std/http 
Removed @std/http
amol@Amols-MacBook-Air deno_test_add %cat deno.json                            
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1"
  }
}
amol@Amols-MacBook-Air deno_test_add %../target/debug/deno add jsr:@std/http 
Add jsr:@std/[email protected]
amol@Amols-MacBook-Air deno_test_add %cat deno.json                         
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1",
    "@std/http": "jsr:@std/http@^1.0.23"
  }
}
amol@Amols-MacBook-Air deno_test_add %../target/debug/deno remove jsr:@std/http
Removed @std/http
amol@Amols-MacBook-Air deno_test_add %../target/debug/deno add jsr:@std/http --exact
Add jsr:@std/[email protected]
amol@Amols-MacBook-Air deno_test_add %cat deno.json                                 
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1",
    "@std/http": "jsr:@std/[email protected]"
  }
}

…act version instead of carret

Signed-off-by: Amol Yadav <[email protected]>
Signed-off-by: Amol Yadav <[email protected]>
Signed-off-by: Amol Yadav <[email protected]>
@amyssnippet
Copy link
Contributor Author

amyssnippet commented Jan 29, 2026

I've resolved the CI failures. I added the --save-exact and --exact as alias argument definition to the deno install command as well, ensuring consistency and preventing the panic in the integration tests.

All checks are passing now. Ready for review? Thanks!

amol@Amols-MacBook-Air deno_test_add %cat deno.json                                       
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1"
  }
}
amol@Amols-MacBook-Air deno_test_add %../target/debug/deno install jsr:@std/http --save-exact
Add jsr:@std/[email protected]
amol@Amols-MacBook-Air deno_test_add %cat deno.json        
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1",
    "@std/http": "jsr:@std/[email protected]"
  }
}
amol@Amols-MacBook-Air deno_test_add %../target/debug/deno install jsr:@zod/zod --exact
Add jsr:@zod/[email protected]
Installed 1 package in 2162ms
Reused 12 packages from cache
++++++++++++
Downloaded 1 package from JSR
+
Downloaded 0 packages from npm

Dependencies:
+ jsr:@zod/zod 4.3.6

amol@Amols-MacBook-Air deno_test_add %cat deno.json                                    
{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1",
    "@std/http": "jsr:@std/[email protected]",
    "@zod/zod": "jsr:@zod/[email protected]"
  }
}
amol@Amols-MacBook-Air deno_test_add %

@amyssnippet
Copy link
Contributor Author

amyssnippet commented Jan 29, 2026

@dsherret i guess it is a great DX feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce --save-exact or --exact to install an exact version

1 participant