felixge / felixge/node-sandboxed-module

nyc builtin source transformer

Offen
#63 4 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
343
Forks
41
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.