[Feature]: Support for Isolated Declarations in TS 5.5
What problem does this feature solve?
Since SWC already supports Isolated Declarations in TS 5.5, Rslib can provide option to enable it to speed up dts generation.
https://github.com/swc-project/swc/pull/9086
What does the proposed API look like?
- Detect
tsconfig.json#isolatedDeclarationsand enable it by default. - Provide an option to enable / disable it, like
dts. isolated
Currently, swc-loader does not ship emitIsolatedDts but swc-cli do. We need to do some processing in Rspack's built-in swc-loader to emit the result of transform during build process.
And isolated declarations produce the same result with tsc's bundleless dts, we can also support using isolated emit dts for type bundle with api-extractor.
Saw this PR in draft https://github.com/web-infra-dev/rspack/pull/8097#issuecomment-2728805669 and would like to share personal thoughts - I think isolated emission is still meaningful even with tsgo.
We have a workspaces have multiple internal packages with ts project references, and rslib's dts emission and main tsc shares same tsbuildinfo for each time compiler runs - there's possible conflict between since task runs in parallel determined by task runner. I tried to detach rslib's dts declarationdir - but it wasn't easy since rslib requires its dts outpath to declarationdir in tsconfig when project references is enabled, and if we want to avoid that we have to create a separate tsconfig for every package to setup a new project references for rslib only.
isolated dts emission on rslib side may resolves this by avoid sharing / reusing same tsbuildinfo.
Thanks, I fully understand your opinion. Unlike tsc with type checking, supporting isolated declarations can enable fast type generation while avoiding potential issues with tsbuildinfo files.
In early time, we have explored using swc-loader for isolated declaration generation to improve performance, and after the birth of tsgo, we integrated it which achieving our initial expectation in accelerating type generation.
Currently, we still face a pain point in declaration files bundle, which could be another application scenario for isolated declarations. In the future, we may be able to directly bundle declaration files in Rspack based on isolated declarations info in swc-loader, thus fully integrating the emission of dts and js files.
Thanks for sharing! I believe isolated DTS generation still has its use cases. Tsgo will take some time to mature, so we should consider supporting isolated DTS in Rslib before tsgo becomes stable.
We have a workspaces have multiple internal packages with ts project references, and rslib's dts emission and main tsc shares same tsbuildinfo for each time compiler runs - there's possible conflict between since task runs in parallel determined by task runner. I tried to detach rslib's dts declarationdir - but it wasn't easy since rslib requires its dts outpath to declarationdir in tsconfig when project references is enabled, and if we want to avoid that we have to create a separate tsconfig for every package to setup a new project references for rslib only.
isolated dts emission on rslib side may resolves this by avoid sharing / reusing same tsbuildinfo.
Can you provide a reproduction? I'm not sure that the swc dts emit will solve your problem; it's just for performance and bypassing the tsc check is not the real intention.
if we encounter the same problem, rslib cannot force users to switch to swc dts emit either, so I think providing a reproduction or an issue is valuable.
bypassing the tsc check is not the real intention
Not sure if I understand this correctly. I didn't mean to skip tsc or anything - there's a main tsc runs for those purpose. So far my understanding is rslib's tsc run is to emit the type definition, not attempt to own typescript compiler's type check process itself; if rslib emits the type definition with swc without tsc, does it still need to run tsc separately for some reason?
Can you provide a reproduction
It is intermittent on our end even so creating a repro is not trivial. The setup we have is 1. there are internal workspace packages using rslib with transtive dependencies (say A is rslib, import b which is not rslib, b imports c which is rslib) 2. and using build tool supports parallel executions (bazel, moon, etcs) 3. and running main tsc / rslib' tsc occurs in parallel may cause some side effects since both shares tsbuildinfo and emitted dts files.