You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
paths - additional directories, relative to baseUrl, that should also be searched.
rootDirs - virtual directories that relative paths can be resolved from
There's also the legacy module resolution mode that TS supports. Not sure if that's something we should also support, but I guess someone might still use it. 🤷
Implementation
These resolution features should be supported in Parcel for imports declared in .ts or .tsx files. This can be done via a new resolver plugin, included in the default config: @parcel/resolver-typescript. This resolver should look at the sourcePath property of the dependency, and if it has a .ts or .tsx extension, it should resolve using the TS compiler API's resolveModuleName method. It should use a custom ModuleResolutionHost that ensures the Parcel file system is used instead of the Node one. This can be created using the @parcel/ts-utils package, which already includes an FSHost package implementing much of the required interface.
If a module is not resolved, or the source file is not a .ts or .tsx file, then the resolver should return null. This will then fall back to the default Parcel resolver, which will handle Parcel specific features like aliases.
Open questions
We'll need to determine whether we can properly track all of the files that the TS resolver reads so we can invalidate the Parcel cache properly. This is a work in progress for the default resolver as well.
It's unclear how the TS resolver should interact with Parcel features like aliases and named pipelines (e.g. url:./foo.jpg to import an image as a url). Theoretically we could fall back to the default resolver if TS doesn't find anything, but what if you alias react to preact but reactis found by the TS resolver?
TypeScript supports some additional features in its resolver on top of the Node resolution algorithm. These are configured in
tsconfig.json.baseUrl- a root directory from which to resolve non-relative paths, in addition tonode_modules. See also: [TypeScript]baseUrlinside tsconfig.json not supporting. #202.paths- additional directories, relative tobaseUrl, that should also be searched.rootDirs- virtual directories that relative paths can be resolved fromThere's also the legacy module resolution mode that TS supports. Not sure if that's something we should also support, but I guess someone might still use it. 🤷
Implementation
These resolution features should be supported in Parcel for imports declared in
.tsor.tsxfiles. This can be done via a new resolver plugin, included in the default config:@parcel/resolver-typescript. This resolver should look at thesourcePathproperty of the dependency, and if it has a.tsor.tsxextension, it should resolve using the TS compiler API'sresolveModuleNamemethod. It should use a customModuleResolutionHostthat ensures the Parcel file system is used instead of the Node one. This can be created using the@parcel/ts-utilspackage, which already includes anFSHostpackage implementing much of the required interface.If a module is not resolved, or the source file is not a
.tsor.tsxfile, then the resolver should returnnull. This will then fall back to the default Parcel resolver, which will handle Parcel specific features like aliases.Open questions
url:./foo.jpgto import an image as a url). Theoretically we could fall back to the default resolver if TS doesn't find anything, but what if you aliasreacttopreactbutreactis found by the TS resolver?