rushstack
rushstack copied to clipboard
[api-extractor] Add support for new TS declaration format when using module resolution 'bundler' or 'nodenext'
Summary
Add support for new TS declaration format when using module resolution 'bundler' or 'nodenext'
fixes https://github.com/microsoft/rushstack/issues/4899
Details
TS 5.x started to support new moduleResolution bundler and nodenext (or node16) which changes the behaviour of TS declaration files for arbitrary extensions like .json and .css.
By default, this import will raise an error to let you know that TypeScript doesn’t understand this file type and your runtime might not support importing it. But if you’ve configured your runtime or bundler to handle it, you can suppress the error with the new --allowArbitraryExtensions compiler option.
Note that historically, a similar effect has often been achievable by adding a declaration file named app.css.d.ts instead of app.d.css.ts - however, this just worked through Node’s require resolution rules for CommonJS. Strictly speaking, the former is interpreted as a declaration file for a JavaScript file named app.css.js. Because relative files imports need to include extensions in Node’s ESM support, TypeScript would error on our example in an ESM file under --moduleResolution node16 or nodenext
By enabling the TS allowArbitraryExtensions setting, declaration files can be imported with the new module resolutions but are required to follow the {file basename}.d.{extension}.ts pattern.
This PR updates the regex in ExtractorConfig which detect if a file is a declaration file to be inclusive of the new pattern.
How it was tested
unit test
Impacted documentation
N/A