Add package support to typescript/javascript dependency inference
This adds better dependency inference to typescript/javascript.
- Adds support for imports relative to tsconfig root
a. i.e.
utils/stringUtils->frontend/src/utils/stringUtils.ts - Adds support for namespaced package imports
a.
@apollo/client->:package#__apollo/client - Adds support for importing
.tsxfrom.tsfiles a. This is a weird one, I had to add this to support my usecase but I'm not sure the "right" way to handle js/jsx/ts/tsx cross-imports.
I'm not how much of the javascript "spec" I covered
Sample file
# example.ts
import 'axios'
import '@apollo/client'
import 'utils/stringUtils'
import 'utils/tableUtils'
import '../utils/urlUtils'
Produces
PANTS_SOURCE=../../OSS/pants pants --no-pantsd dependecies example.ts
frontend/src/utils/stringUtils.ts:../../typescript
frontend/src/utils/tableUtils.tsx:../../tsx
frontend/src/utils/urlUtils.ts:../../typescript
frontend:package#__apollo/client
frontend:package#axios
You need to provide the tsconfig or full repro to be able to validate your example.
"Adds support for imports relative to tsconfig root", this is not a default of the ts resolution spec, but might be for your tooling. If it is, I'm going to encourage you set your tsconfig to match what the tooling is implicitly doing, instead of merging "1a" of this change.
You generally need to supply "paths" entries in the tsconfig that maps to the "any" match (*) to get behaviour like that, from what I understand. See https://www.typescriptlang.org/tsconfig/#paths and https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths
If tests prove "2a" I think that would be a good bug fix.
3a should adhere to https://www.typescriptlang.org/docs/handbook/modules/reference.html#file-extension-substitution.
I just want to reiterate that the parser is a javascript parser, not a typescript parser. It is not up to the task of parsing any typescript specifics, so please tread lightly.
@jasondamour thanks for this contribution! Do you think you will be able to revise with the review comments?
Just a headsup that I think this is superseded by https://github.com/pantsbuild/pants/pull/22364 (and prior changes).