felixge / felixge/node-sandboxed-module
nyc builtin source transformer
- Dominant language
- JavaScript
- Stars
- 343
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
Related to https://github.com/felixge/node-sandboxed-module/issues/25.
It'd be nice if the istanbul transformer also supported nyc, which in turn supports subprocesses. I got this working with the following voodoo, but I wasn't sure whether this was the supported mechanism per https://github.com/istanbuljs/nyc. Thoughts? Is this in scope?
```js
function maybeCoverage() {
return Object.keys(require.cache).some((path) => /node_modules\/nyc/.test(path));
}
SandboxedModule.require('.../index.js', {
// Voodoo magic to support nyc.
sourceTransformers: maybeCoverage() ? {
nyc(source) {
const Instrumenter = require('nyc/lib/instrumenters/istanbul'),
instrumenter = Instrumenter(process.cwd(), {}),
instrumentMethod = instrumenter.instrumentSync.bind(instrumenter);
return instrumentMethod(source, this.filename);
}
} : {}
});
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.