felixge / felixge/node-sandboxed-module

nyc builtin source transformer

オープン
#63 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
343
フォーク
41
PR マージ指標
30日以内にマージされた PR はありません

説明

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);
}
} : {}
});
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。