babel-plugin-istanbul
babel-plugin-istanbul copied to clipboard
shouldSkip cache breaks plugin in some cases
Hi,
I've noticed a bug in how makeShouldSkip
caches the exclusion test function. The current behavior is to only build the function once, and then reuse it for all subsequent invocations. However, the built function makes use of the passed-in options (inclusion and exclusion patterns). The problem is that these options might be (and in our case, are) different for various files.
Babel uses the .babelrc
closest to the file being transpiled, so two packages containing different inclusion patterns in their .babelrc
can cause issues, because the location of the first file being transpiled determines the inclusion patterns the plugin uses for all other files. A quick console.log before the function is created shows this when we run it (using replaced paths):
incoming options are { include: [ 'test/**/*.{js,jsx}' ], exclude: [] } for file: /path/to/package/a/test/b.js
incoming options are { include: [ 'src/**/*.{js,jsx}' ], exclude: [] } for file: /path/to/package/x/src/y.js
Package a
's .babelrc
contains the plugin option "include": ["test/**/*.{js,jsx}"]
and packagex
's .babelrc
contains the plugin option "include": ["src/**/*.{js,jsx}"]
. Because the second inclusion pattern is ignored, /path/to/package/x/src/y.js
isn't instrumented.
What made this one particular hard to figure out is that depending on other settings/plugins files aren't always instrumented in the same order. Some runs would apply test/**
to all files, some would apply src/**
to all files … :)
It seems to me that the plugin should either:
- Don't cache the whole function, only cache things that are truly static (nyc config), or
- Cache the function, but cache multiple versions of it (one for each set of options encountered)