Repository navigation
feat: add "preferPackageJson" deno.json setting - #35392
Conversation
Adds a "preferPackageJson": true field to deno.json that always manages dependencies via package.json, equivalent to passing --package-json to deno add/install/remove. A package.json is created if one doesn't exist. Also emits a warning when "imports"/"scopes" are present in deno.json while "preferPackageJson" is enabled.
The "preferPackageJson" imports warning fired whenever deno.json had any "imports"/"scopes", but path-alias imports (e.g. "#utils" -> "./utils.ts") can't be moved to package.json, so warning about them is misleading. Narrow the trigger to entries that are actual npm:/jsr: dependency specifiers. Add a unit test covering the warning's presence (imports + scopes deps) and absence (path aliases, setting off), and a spec test that `deno remove` honors preferPackageJson by removing from package.json.
| @@ -0,0 +1,2 @@ | |||
| Created package.json configuration file. | |||
There was a problem hiding this comment.
I would prefer we don't print this message
A workspace member setting "preferPackageJson" was silently ignored (the setting is read from the root deno.json only), and yet the member could still receive the lingering-imports warning. Emit a RootOnlyOption diagnostic for members that set it, and only emit the PreferPackageJsonWithImports warning for the root config where the setting actually takes effect.
|
Reviewed β solid and well-tested. A few notes: Confirmed correct:
One design point on the new Minor: the diff adds a third spec ( |
Summary
Builds on the
--package-jsonflag (added in Deno 2.8) by introducing a persistent"preferPackageJson": truesetting indeno.json. When enabled, dependency management commands always targetpackage.json:deno add/deno install <pkg>/deno removewrite topackage.jsoninstead ofdeno.jsonpackage.jsonis created automatically if one doesn't exist--package-jsonto those commands on every invocationIt also prints a warning when
imports/scopesare still present indeno.jsonwhilepreferPackageJsonis enabled, nudging users to move those dependencies topackage.json.Implementation
preferPackageJsonadded to theConfigFileJsonschema and the JSON schema (config-file.v1.json) for editor autocompletion.Workspace::prefer_package_json()reads the setting from the rootdeno.json.cli/tools/pm/mod.rsfolds the setting into the existingforce_package_jsonpath that already powers--package-json, soadd/install/removeall honor it.link/unlinkexplicitly opt out, since the"links"field lives indeno.json.WorkspaceDiagnosticKind::PreferPackageJsonWithImports).Tests
tests/specs/add/prefer_package_jsonβ routes deps intopackage.json; creates it when missing.tests/specs/add/prefer_package_json_imports_warningβ warning fires whenimportsis present.Existing
package_json_flag,link,remove, anddeno_configtests pass.