From 193cb17d5220492009dc40a833a6619984136525 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Tue, 19 Nov 2019 04:52:58 -0500 Subject: [PATCH] chore: Lazy load modules that are rarely/never needed in test processes. --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7b7959a96..e45617981 100755 --- a/index.js +++ b/index.js @@ -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') @@ -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. @@ -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,