Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Lazy load modules that are rarely/never needed in test processes. #1232

Merged
merged 1 commit into from Nov 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions index.js
Expand Up @@ -12,13 +12,10 @@ const Hash = require('./lib/hash')
const libCoverage = require('istanbul-lib-coverage')
const libHook = require('istanbul-lib-hook')
const { ProcessInfo, ProcessDB } = require('istanbul-lib-processinfo')
const libReport = require('istanbul-lib-report')
const mkdirp = require('make-dir')
const Module = require('module')
const onExit = require('signal-exit')
const path = require('path')
const reports = require('istanbul-reports')
const resolveFrom = require('resolve-from')
const rimraf = promisify(require('rimraf'))
const SourceMaps = require('./lib/source-maps')
const testExclude = require('test-exclude')
Expand Down Expand Up @@ -127,10 +124,11 @@ class NYC {
}

_loadAdditionalModules () {
if (!this.config.useSpawnWrap) {
if (!this.config.useSpawnWrap || this.require.length === 0) {
return
}

const resolveFrom = require('resolve-from')
this.require.forEach(requireModule => {
// Attempt to require the module relative to the directory being instrumented.
// Then try other locations, e.g. the nyc node_modules folder.
Expand Down Expand Up @@ -430,6 +428,9 @@ class NYC {
}

async report () {
const libReport = require('istanbul-lib-report')
const reports = require('istanbul-reports')

const context = libReport.createContext({
dir: this.reportDirectory(),
watermarks: this.config.watermarks,
Expand Down