Skip to content

feat(cli): deno add --no-save and --save-optional#36039

Merged
bartlomieju merged 1 commit into
mainfrom
feat/add-no-save-save-optional
Jul 15, 2026
Merged

feat(cli): deno add --no-save and --save-optional#36039
bartlomieju merged 1 commit into
mainfrom
feat/add-no-save-save-optional

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

deno add could not install a package without declaring it, and had no way
to write to optionalDependencies, which meant tools that translate install
commands between package managers (e.g. npm-to-yarn) could not faithfully
express npm install --no-save or npm install -O. This adds both flags to
deno add and deno install <pkg>, matching the npm short forms -O for
--save-optional.

--no-save resolves and installs the package into node_modules and the
lockfile but leaves deno.json / package.json untouched. --save-optional
/ -O writes the package to optionalDependencies. The three placement flags
(--dev, --save-optional, --no-save) are mutually exclusive.

Deno's installer does not currently materialize optionalDependencies from
package.json (the resolved package.json deps only cover dependencies and
devDependencies), so optional and --no-save packages are installed directly
as extra graph roots via a new additional_roots field on
CacheTopLevelDepsOptions. This keeps --save-optional at parity with
--save-dev, which installs on add. Teaching the installer to honor
optionalDependencies on its own is left as a follow-up.

Closes #36037

Adds two `deno add` / `deno install` flags for parity with npm (closes #36037):

- `--no-save` installs the package(s) into `node_modules` and the lockfile
  without writing them to `deno.json` / `package.json`.
- `--save-optional` / `-O` writes the package to `optionalDependencies`.

Deno's installer does not materialize `optionalDependencies` from
`package.json`, so optional packages (and `--no-save` packages) are installed
directly via a new `additional_roots` field on `CacheTopLevelDepsOptions`,
keeping `--save-optional` at parity with `--save-dev`.
@bartlomieju
bartlomieju merged commit 5de9e18 into main Jul 15, 2026
136 checks passed
@bartlomieju
bartlomieju deleted the feat/add-no-save-save-optional branch July 15, 2026 08:50
bartlomieju added a commit that referenced this pull request Jul 15, 2026
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.

Support npm's --no-save and --save-optional flags in deno add

1 participant