From a6951cc3abba60728c55d88e1283743fb34d7e27 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Sat, 1 Jul 2023 20:48:58 +0200 Subject: [PATCH] Lazy-load dependencies in CLI entrypoint --- lib/cli.js | 62 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 1261a54de..30bb11939 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,10 +1,8 @@ - import fs from 'node:fs'; import path from 'node:path'; import process from 'node:process'; import arrify from 'arrify'; -import ciParallelVars from 'ci-parallel-vars'; import figures from 'figures'; import yargs from 'yargs'; import {hideBin} from 'yargs/helpers'; // eslint-disable-line n/file-extension-in-import @@ -14,16 +12,12 @@ import {chalk} from './chalk.js'; import validateEnvironmentVariables from './environment-variables.js'; import normalizeExtensions from './extensions.js'; import {normalizeGlobs, normalizePattern} from './globs.js'; -import {controlFlow} from './ipc-flow-control.cjs'; import isCi from './is-ci.js'; import {splitPatternAndLineNumbers} from './line-numbers.js'; import {loadConfig} from './load-config.js'; import normalizeModuleTypes from './module-types.js'; import normalizeNodeArguments from './node-arguments.js'; import pkg from './pkg.cjs'; -import providerManager from './provider-manager.js'; -import DefaultReporter from './reporters/default.js'; -import TapReporter from './reporters/tap.js'; function exit(message) { console.error(`\n ${chalk.red(figures.cross)} ${message}`); @@ -348,6 +342,7 @@ export default async function loadCli() { // eslint-disable-line complexity const providers = []; if (Object.hasOwn(conf, 'typescript')) { + const {default: providerManager} = await import('./provider-manager.js'); try { const {identifier: protocol, level, main} = await providerManager.typescript(projectDir, {fullConfig: conf}); providers.push({ @@ -397,9 +392,12 @@ export default async function loadCli() { // eslint-disable-line complexity } let parallelRuns = null; - if (isCi && ciParallelVars && combined.utilizeParallelBuilds !== false) { - const {index: currentIndex, total: totalRuns} = ciParallelVars; - parallelRuns = {currentIndex, totalRuns}; + if (isCi && combined.utilizeParallelBuilds !== false) { + const {default: ciParallelVars} = await import('ci-parallel-vars'); + if (ciParallelVars) { + const {index: currentIndex, total: totalRuns} = ciParallelVars; + parallelRuns = {currentIndex, totalRuns}; + } } const match = combined.match === '' ? [] : arrify(combined.match); @@ -441,29 +439,39 @@ export default async function loadCli() { // eslint-disable-line complexity workerArgv: argv['--'], }); - const reporter = combined.tap && !argv.watch && debug === null ? new TapReporter({ - extensions: globs.extensions, - projectDir, - reportStream: process.stdout, - stdStream: process.stderr, - }) : new DefaultReporter({ - extensions: globs.extensions, - projectDir, - reportStream: process.stdout, - stdStream: process.stderr, - watching: argv.watch, - }); - - api.on('run', plan => { - reporter.startRun(plan); + let reporter; + if (combined.tap && !argv.watch && debug === null) { + const {default: TapReporter} = await import('./reporters/tap.js'); + reporter = new TapReporter({ + extensions: globs.extensions, + projectDir, + reportStream: process.stdout, + stdStream: process.stderr, + }); + } else { + const {default: Reporter} = await import('./reporters/default.js'); + reporter = new Reporter({ + extensions: globs.extensions, + projectDir, + reportStream: process.stdout, + stdStream: process.stderr, + watching: argv.watch, + }); + } - if (process.env.TEST_AVA) { - const bufferedSend = controlFlow(process); + if (process.env.TEST_AVA) { + const {controlFlow} = await import('./ipc-flow-control.cjs'); + const bufferedSend = controlFlow(process); + api.on('run', plan => { plan.status.on('stateChange', evt => { bufferedSend(evt); }); - } + }); + } + + api.on('run', plan => { + reporter.startRun(plan); plan.status.on('stateChange', evt => { if (evt.type === 'interrupt') {