Open ericmorand opened 6 months ago
Actually, it seems to come from @rollup/pluginutils
itself:
There, the createFilter
method behaves differently depending on the type of the pattern: if it is a regular expression, it is used as-is; if it is a string, a regular expression is created from it and the current working directory, hence preventing plugins to handle files located outside of the working directory.
Is this a deliberate move or a bug? If it is a deliberate move, what is the rational?
For information, it forces plugin developers to transform the passed options to regular expressions to make sure that their plugin works in every situation, for example my own TypeScript plugin:
options.include = options.include || /\.(cts|mts|ts|tsx)$/;
if (typeof options.include === "string") {
options.include = [options.include];
}
if (Array.isArray(options.include)) {
options.include = options.include.map((include) => {
if (typeof include === "string") {
return new RegExp(include);
}
return include;
});
}
This is a follow-up to #1650.
Rollup Plugin Name: @rollup/plugin-typescript Rollup Plugin Version: 11.1.5 Rollup Version: 4.9.0 Operating System (or Browser): Ubuntu Node Version: 16.20 Link to reproduction: https://github.com/ericmorand/rollup-plugin-typescript-issue
Expected Behavior
Passing a regular expression or a string representation of the regular expression should gives the same result.
Said differently, passing
/\.ts$/
or'./ts$'
should gives the same result.Actual Behavior
After investigating on #1650, I discovered that the Typescript plugin behaves differently depending on whether the
include
option is a string or a regular expression:include
option is a regular expression, the regular expression is used as-is to test the module id received by the plugin in order to decide if the plugin must or must not handle itinclude
option is a string, the test function is constructed by thecreateFilter
method based on the passedinclude
value and the current working directoryHence:
/\.ts$/
would match every file that ends with.ts
'.ts$'
would only match files that ends with.ts
and are located in the current working directoryWhich is unexpected as both are strictly identical from the point of view of picomatch.
I think that either the bug should be fixed, or the documentation of the plugin should clearly express the difference of behaviour instead of just saying: