From c3988721734281bb793d85db3dcbe8cacae59961 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 19 Dec 2023 06:02:22 +0500 Subject: [PATCH] fix: lazy load of which module (#176) Currently `@npmcli/git` is eagerly getting and caching the `git` path in a user's system which can have a significant performance cost when requiring `@npmcli/git`. This PR avoids this cost by lazily getting & caching `git` path on first use. --- lib/spawn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spawn.js b/lib/spawn.js index 7098d7b..5e96eb5 100644 --- a/lib/spawn.js +++ b/lib/spawn.js @@ -2,10 +2,10 @@ const spawn = require('@npmcli/promise-spawn') const promiseRetry = require('promise-retry') const log = require('proc-log') const makeError = require('./make-error.js') -const whichGit = require('./which.js') const makeOpts = require('./opts.js') module.exports = (gitArgs, opts = {}) => { + const whichGit = require('./which.js') const gitPath = whichGit(opts) if (gitPath instanceof Error) {