Skip to content

Commit

Permalink
(TypeScript plugin): Add references path of tsconfig to config (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
taro-28 authored Oct 28, 2024
1 parent 366acdc commit bff0977
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/knip/fixtures/plugins/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"devDependencies": {
"@tsconfig/node16": "*",
"@tsconfig/node20": "*",
"@tsconfig/node22": "*",
"typescript": "*"
}
}
4 changes: 4 additions & 0 deletions packages/knip/fixtures/plugins/typescript/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@tsconfig/node22/tsconfig.json",
"compilerOptions": {}
}
7 changes: 6 additions & 1 deletion packages/knip/fixtures/plugins/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
"tag": "gql"
},
]
}
},
"references": [
{
"path": "./tsconfig.app.json"
},
]
}
9 changes: 7 additions & 2 deletions packages/knip/src/plugins/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ const resolveConfig: ResolveConfig<TsConfigJson> = async (localConfig, options)
? [localConfig.extends].flat().map(specifier => toConfig('typescript', specifier, options.configFilePath))
: [];

if (!(compilerOptions && localConfig)) return extend;
const references =
localConfig.references
?.filter(reference => reference.path.endsWith('.json'))
.map(reference => toConfig('typescript', reference.path, options.configFilePath)) ?? [];

if (!(compilerOptions && localConfig)) return compact([...extend, ...references]);

const jsx = (compilerOptions?.jsxImportSource ? [compilerOptions.jsxImportSource] : []).map(toProductionDependency);

Expand All @@ -35,7 +40,7 @@ const resolveConfig: ResolveConfig<TsConfigJson> = async (localConfig, options)
: [];
const importHelpers = compilerOptions?.importHelpers ? ['tslib'] : [];

return compact([...extend, ...[...types, ...plugins, ...importHelpers].map(toDeferResolve), ...jsx]);
return compact([...extend, ...references, ...[...types, ...plugins, ...importHelpers].map(toDeferResolve), ...jsx]);
};

const args = {
Expand Down

0 comments on commit bff0977

Please sign in to comment.