Allow excluding fields from inferred package.json input in @nx/js/typescript (and other inferred-input plugins) #35951
ryan-mcginty-alation
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
The
@nx/js/typescriptplugin unconditionally adds{projectRoot}/package.jsonas a raw file input to every inferredtypechecktask. In a workspace usingnx releasewithprojectsRelationship: "fixed", every release commit bumps theversionfield of every publishedpackage.json, busting thetypecheckcache for every affected project even though theversionfield has zero effect on the typecheck output.It would be great if the plugin accepted an option to use field-based hashing (
{json: ..., excludeFields: [...]}) for the package.json input it emits, so that volatile-but-irrelevant fields likeversioncould be excluded.Why this matters
Nx already supports field-based hashing on
namedInputsand explicitinputsarrays. We use this in our owndefaultnamed input today:This works perfectly for
lint(["default", "{workspaceRoot}/eslint.config.mjs"]) andtesttargets that referencedefault/production. Release version-bumps no longer invalidate caches for those targets, while non-version edits (dependencies,peerDependencies,main,exports, etc.) still do — which preserves correctness for@nx/dependency-checksand other rules.But for
typecheck, the plugin-inferred input list bypasses ournamedInputsentirely. The relevant code is in@nx/js/src/plugins/typescript/plugin.js(paraphrasing the current shape):The pushed string is a bare
"{projectRoot}/package.json", soversionis hashed. TheTscPluginOptionsinterface exposescompiler,typecheck.targetName,typecheck.configName,build,verboseOutput— no inputs override.Why a workspace-level workaround is brittle
targetDefaults.typecheck.inputsis documented to replace plugin-inferred inputs, not merge. To avoid hashing version, a workspace would have to fully replicate the plugin's inferred input set (~28–46 entries depending on whether the project has Storybook etc.) and hand-maintain it across nx version bumps. That works once but freezes a one-size-fits-all input list for every project, losing per-project tailoring (the plugin generates the list from each project's owntsconfig.lib.jsoninclude/excludepatterns).Proposed API
Extend
TscPluginOptions.typecheckwith an optional field hashing config that the plugin would apply when emitting the package.json input:Usage:
{ "plugins": [ { "plugin": "@nx/js/typescript", "options": { "typecheck": { "targetName": "typecheck", "packageJsonInput": { "excludeFields": ["version"] } } } } ] }The plugin would then emit
{json: "{projectRoot}/package.json", excludeFields: ["version"]}instead of the raw string, leaving the rest of the inferred input set untouched.The same shape would be useful on other inferred-input plugins (e.g.
@nx/eslint/plugin,@nx/vite/plugin,@nx/playwright/plugin) that may includepackage.jsonin their inferred input lists.Alternatives considered
targetDefaults.typecheck.inputs— full replacement, brittle to plugin upgrades and per-project shape divergence. Rejected.nx release(git: { commit: true, tag: true }writes the bumped version to source).pathsmappings intsconfig.base.json— doesn't change which files the plugin hashes; the plugin emitspackage.jsonas an input regardless of TS resolution strategy.Use case context
We use
nx releasewith fixed-version projects relationship. Releases happen 1–2× per day. Every release commit bumps theversionfield of every release-managedpackage.json. With the workspace-level fix above,lintandtestcaches survive this cleanly.typecheckis the only remaining target busting on pure-version flips, and we can't fix it without owning a per-workspace fork of the plugin's inferred input list.Beta Was this translation helpful? Give feedback.
All reactions