Skip to content

Commit 28a9696

Browse files
committed
fix(perf): lazy load hosted git info on normalize
1 parent d4814d4 commit 28a9696

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/normalize.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ const fs = require('fs/promises')
44
const { glob } = require('glob')
55
const path = require('path')
66
const log = require('proc-log')
7-
const hostedGitInfo = require('hosted-git-info')
7+
8+
/**
9+
* @type {import('hosted-git-info')}
10+
*/
11+
let _hostedGitInfo
12+
function lazyHostedGitInfo() {
13+
if (!_hostedGitInfo) {
14+
_hostedGitInfo = require('hosted-git-info')
15+
}
16+
return _hostedGitInfo
17+
}
818

919
// used to be npm-normalize-package-bin
1020
function normalizePackageBin (pkg, changes) {
@@ -445,7 +455,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
445455
}
446456
}
447457
if (data.repository.url) {
448-
const hosted = hostedGitInfo.fromUrl(data.repository.url)
458+
const hosted = lazyHostedGitInfo().fromUrl(data.repository.url)
449459
let r
450460
if (hosted) {
451461
if (hosted.getDefaultRepresentation() === 'shortcut') {
@@ -505,7 +515,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
505515
changes?.push(`Removed invalid "${deps}.${d}"`)
506516
delete data[deps][d]
507517
}
508-
const hosted = hostedGitInfo.fromUrl(data[deps][d])?.toString()
518+
const hosted = lazyHostedGitInfo().fromUrl(data[deps][d])?.toString()
509519
if (hosted && hosted !== data[deps][d]) {
510520
changes?.push(`Normalized git reference to "${deps}.${d}"`)
511521
data[deps][d] = hosted.toString()

0 commit comments

Comments
 (0)