rollup / plugins

🍣 The one-stop shop for official Rollup plugins
MIT License
3.57k stars 568 forks source link

[TypeScript] Include "js", "mjs", "cjs" and "json" in default `includes` #1663

Open kraenhansen opened 5 months ago

kraenhansen commented 5 months ago

Expected Behavior

Between v10.0.1 and v11.0.0 of the @rollup/plugin-typescript package, what I suspect is the merge of https://github.com/rollup/plugins/issues/1267 regressed a feature that I was relying on.

When resolving files through the paths of a tsconfig.json, I expect .js, .cjs, .mjs and .json files to resolve, just as if they're referenced directly using relative paths in a TypeScript source file.

Actual Behavior

When resolving files through the paths of a tsconfig.json the files are externalised from the bundle.

Additional Information

The issue can be worked around by providing a value for the includes option, which includes the extensions of all the expected files: '{,**/}*.(cts|mts|ts|tsx|js|cjs|mjs|json)'. This issue might simply be a case of a misalignment in my expectations of the default and the actual default. If there's no immediate drawback, I'd suggest expanding this default value for includes to include any file extension importable from TypeScript. Alternatively, the default could be determined based on the value of the allowJs resolveJsonModule options from the loaded tsconfig.json.

As a side-note: Adding to the confusion, is that the plugin uses "includes" as the name for this option, which can easily be confused with a way to supply and alternative / overriding value for the TypeScript includes option read from the tsconfig.json. This is most likely why I originally didn't think to configure it.

foretoo commented 5 months ago

it took me 2 days to find a reason why paths in .js files are not trasformed, i even wrote my own transformer to handle it, lol.