Skip to content

Commit 28ed746

Browse files
authored
chore: Lazy load modules that are rarely/never needed in test processes. (#1232)
1 parent 7307626 commit 28ed746

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ const Hash = require('./lib/hash')
1212
const libCoverage = require('istanbul-lib-coverage')
1313
const libHook = require('istanbul-lib-hook')
1414
const { ProcessInfo, ProcessDB } = require('istanbul-lib-processinfo')
15-
const libReport = require('istanbul-lib-report')
1615
const mkdirp = require('make-dir')
1716
const Module = require('module')
1817
const onExit = require('signal-exit')
1918
const path = require('path')
20-
const reports = require('istanbul-reports')
21-
const resolveFrom = require('resolve-from')
2219
const rimraf = promisify(require('rimraf'))
2320
const SourceMaps = require('./lib/source-maps')
2421
const testExclude = require('test-exclude')
@@ -127,10 +124,11 @@ class NYC {
127124
}
128125

129126
_loadAdditionalModules () {
130-
if (!this.config.useSpawnWrap) {
127+
if (!this.config.useSpawnWrap || this.require.length === 0) {
131128
return
132129
}
133130

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

432430
async report () {
431+
const libReport = require('istanbul-lib-report')
432+
const reports = require('istanbul-reports')
433+
433434
const context = libReport.createContext({
434435
dir: this.reportDirectory(),
435436
watermarks: this.config.watermarks,

0 commit comments

Comments
 (0)