Skip to content

Commit 9c2b5e2

Browse files
leosvelperezFrozenPandaz
authored andcommitted
fix(js): preserve tsconfig fields in typescript plugin cache (#34908)
## Current Behavior After certain cache state transitions (e.g., tsconfig parsing cache warm but targets cache cold), the `@nx/js/typescript` plugin falls back to the `production` named input instead of deriving precise inputs from tsconfig `include`/`exclude` paths. This results in broader cache invalidation than necessary, and in projects with `allowJs` or `resolveJsonModule`, the wrong file extensions are tracked as inputs. Output inference is also affected when `emitDeclarationOnly` or `declarationMap` are set. Running `nx reset` restores correct behavior, but the issue recurs. ## Expected Behavior Inferred inputs and outputs are consistent regardless of cache state — always matching what the tsconfig actually specifies. The root cause was the tsconfig parsing cache serialization (`toAbsolutePaths`/`toRelativePaths`) dropping fields the plugin relies on: `raw.include`, `raw.exclude`, `raw.files`, and `options.allowJs`, `options.resolveJsonModule`, `options.emitDeclarationOnly`, `options.declarationMap`. These are now preserved, and `TSCONFIG_CACHE_VERSION` is bumped to invalidate stale caches.
1 parent 1c7076d commit 9c2b5e2

1 file changed

Lines changed: 39 additions & 7 deletions

File tree

packages/js/src/plugins/typescript/plugin.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ interface ConfigContext {
114114
let ts: typeof import('typescript');
115115
const pmc = getPackageManagerCommand();
116116

117-
const TSCONFIG_CACHE_VERSION = 1;
117+
const TSCONFIG_CACHE_VERSION = 2;
118118
const TS_CONFIG_CACHE_PATH = join(
119119
workspaceDataDirectory,
120120
'tsconfig-files.hash'
@@ -1646,12 +1646,28 @@ function toAbsolutePaths(
16461646
for (const [key, { data, extendedFilesHash, hash }] of Object.entries(
16471647
cache
16481648
)) {
1649+
const raw: Record<string, unknown> = {
1650+
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
1651+
};
1652+
if (data.raw?.include) {
1653+
raw.include = data.raw.include;
1654+
}
1655+
if (data.raw?.exclude) {
1656+
raw.exclude = data.raw.exclude;
1657+
}
1658+
if (data.raw?.files) {
1659+
raw.files = data.raw.files;
1660+
}
16491661
updatedCache[key] = {
16501662
data: {
1651-
options: { noEmit: data.options.noEmit },
1652-
raw: {
1653-
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
1663+
options: {
1664+
noEmit: data.options.noEmit,
1665+
allowJs: data.options.allowJs,
1666+
resolveJsonModule: data.options.resolveJsonModule,
1667+
emitDeclarationOnly: data.options.emitDeclarationOnly,
1668+
declarationMap: data.options.declarationMap,
16541669
},
1670+
raw,
16551671
extendedConfigFiles: data.extendedConfigFiles,
16561672
},
16571673
extendedFilesHash,
@@ -1704,12 +1720,28 @@ function toRelativePaths(
17041720
for (const [key, { data, extendedFilesHash, hash }] of Object.entries(
17051721
cache
17061722
)) {
1723+
const raw: Record<string, unknown> = {
1724+
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
1725+
};
1726+
if (data.raw?.include) {
1727+
raw.include = data.raw.include;
1728+
}
1729+
if (data.raw?.exclude) {
1730+
raw.exclude = data.raw.exclude;
1731+
}
1732+
if (data.raw?.files) {
1733+
raw.files = data.raw.files;
1734+
}
17071735
updatedCache[key] = {
17081736
data: {
1709-
options: { noEmit: data.options.noEmit },
1710-
raw: {
1711-
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
1737+
options: {
1738+
noEmit: data.options.noEmit,
1739+
allowJs: data.options.allowJs,
1740+
resolveJsonModule: data.options.resolveJsonModule,
1741+
emitDeclarationOnly: data.options.emitDeclarationOnly,
1742+
declarationMap: data.options.declarationMap,
17121743
},
1744+
raw,
17131745
extendedConfigFiles: data.extendedConfigFiles,
17141746
},
17151747
extendedFilesHash,

0 commit comments

Comments
 (0)