From 57b736941cdd494b16eda2787299077056176122 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Sun, 17 Dec 2023 21:57:23 +0500 Subject: [PATCH 1/2] lazily get git path --- lib/which.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/which.js b/lib/which.js index dc2a1ad..064a3d8 100644 --- a/lib/which.js +++ b/lib/which.js @@ -1,13 +1,15 @@ -const which = require('which') - let gitPath -try { - gitPath = which.sync('git') -} catch { - // ignore errors -} - module.exports = (opts = {}) => { + if (!gitPath) { + try { + // inline lazy require to avoid unnecessary perf cost when requiring @npmcli/git + const which = require('which') + gitPath = which.sync('git') + } catch { + // ignore errors + } + } + if (opts.git) { return opts.git } From 3ed420d53ecba756f08153799a9bcb54b6d9a44d Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 18 Dec 2023 22:42:25 +0500 Subject: [PATCH 2/2] make suggested changes --- lib/spawn.js | 2 +- lib/which.js | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) 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) { diff --git a/lib/which.js b/lib/which.js index 064a3d8..dc2a1ad 100644 --- a/lib/which.js +++ b/lib/which.js @@ -1,15 +1,13 @@ +const which = require('which') + let gitPath -module.exports = (opts = {}) => { - if (!gitPath) { - try { - // inline lazy require to avoid unnecessary perf cost when requiring @npmcli/git - const which = require('which') - gitPath = which.sync('git') - } catch { - // ignore errors - } - } +try { + gitPath = which.sync('git') +} catch { + // ignore errors +} +module.exports = (opts = {}) => { if (opts.git) { return opts.git }