Skip to content

Commit a6951cc

Browse files
committed
Lazy-load dependencies in CLI entrypoint
1 parent 3ec0617 commit a6951cc

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

lib/cli.js

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
21
import fs from 'node:fs';
32
import path from 'node:path';
43
import process from 'node:process';
54

65
import arrify from 'arrify';
7-
import ciParallelVars from 'ci-parallel-vars';
86
import figures from 'figures';
97
import yargs from 'yargs';
108
import {hideBin} from 'yargs/helpers'; // eslint-disable-line n/file-extension-in-import
@@ -14,16 +12,12 @@ import {chalk} from './chalk.js';
1412
import validateEnvironmentVariables from './environment-variables.js';
1513
import normalizeExtensions from './extensions.js';
1614
import {normalizeGlobs, normalizePattern} from './globs.js';
17-
import {controlFlow} from './ipc-flow-control.cjs';
1815
import isCi from './is-ci.js';
1916
import {splitPatternAndLineNumbers} from './line-numbers.js';
2017
import {loadConfig} from './load-config.js';
2118
import normalizeModuleTypes from './module-types.js';
2219
import normalizeNodeArguments from './node-arguments.js';
2320
import pkg from './pkg.cjs';
24-
import providerManager from './provider-manager.js';
25-
import DefaultReporter from './reporters/default.js';
26-
import TapReporter from './reporters/tap.js';
2721

2822
function exit(message) {
2923
console.error(`\n ${chalk.red(figures.cross)} ${message}`);
@@ -348,6 +342,7 @@ export default async function loadCli() { // eslint-disable-line complexity
348342

349343
const providers = [];
350344
if (Object.hasOwn(conf, 'typescript')) {
345+
const {default: providerManager} = await import('./provider-manager.js');
351346
try {
352347
const {identifier: protocol, level, main} = await providerManager.typescript(projectDir, {fullConfig: conf});
353348
providers.push({
@@ -397,9 +392,12 @@ export default async function loadCli() { // eslint-disable-line complexity
397392
}
398393

399394
let parallelRuns = null;
400-
if (isCi && ciParallelVars && combined.utilizeParallelBuilds !== false) {
401-
const {index: currentIndex, total: totalRuns} = ciParallelVars;
402-
parallelRuns = {currentIndex, totalRuns};
395+
if (isCi && combined.utilizeParallelBuilds !== false) {
396+
const {default: ciParallelVars} = await import('ci-parallel-vars');
397+
if (ciParallelVars) {
398+
const {index: currentIndex, total: totalRuns} = ciParallelVars;
399+
parallelRuns = {currentIndex, totalRuns};
400+
}
403401
}
404402

405403
const match = combined.match === '' ? [] : arrify(combined.match);
@@ -441,29 +439,39 @@ export default async function loadCli() { // eslint-disable-line complexity
441439
workerArgv: argv['--'],
442440
});
443441

444-
const reporter = combined.tap && !argv.watch && debug === null ? new TapReporter({
445-
extensions: globs.extensions,
446-
projectDir,
447-
reportStream: process.stdout,
448-
stdStream: process.stderr,
449-
}) : new DefaultReporter({
450-
extensions: globs.extensions,
451-
projectDir,
452-
reportStream: process.stdout,
453-
stdStream: process.stderr,
454-
watching: argv.watch,
455-
});
456-
457-
api.on('run', plan => {
458-
reporter.startRun(plan);
442+
let reporter;
443+
if (combined.tap && !argv.watch && debug === null) {
444+
const {default: TapReporter} = await import('./reporters/tap.js');
445+
reporter = new TapReporter({
446+
extensions: globs.extensions,
447+
projectDir,
448+
reportStream: process.stdout,
449+
stdStream: process.stderr,
450+
});
451+
} else {
452+
const {default: Reporter} = await import('./reporters/default.js');
453+
reporter = new Reporter({
454+
extensions: globs.extensions,
455+
projectDir,
456+
reportStream: process.stdout,
457+
stdStream: process.stderr,
458+
watching: argv.watch,
459+
});
460+
}
459461

460-
if (process.env.TEST_AVA) {
461-
const bufferedSend = controlFlow(process);
462+
if (process.env.TEST_AVA) {
463+
const {controlFlow} = await import('./ipc-flow-control.cjs');
464+
const bufferedSend = controlFlow(process);
462465

466+
api.on('run', plan => {
463467
plan.status.on('stateChange', evt => {
464468
bufferedSend(evt);
465469
});
466-
}
470+
});
471+
}
472+
473+
api.on('run', plan => {
474+
reporter.startRun(plan);
467475

468476
plan.status.on('stateChange', evt => {
469477
if (evt.type === 'interrupt') {

0 commit comments

Comments
 (0)