Skip to content

Commit

Permalink
fix(perf): lazy load hosted git info on normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Apr 10, 2024
1 parent d4814d4 commit dcf42fc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ const fs = require('fs/promises')
const { glob } = require('glob')
const path = require('path')
const log = require('proc-log')
const hostedGitInfo = require('hosted-git-info')

/**
* @type {import('hosted-git-info')}
*/
let _hostedGitInfo
function lazyHostedGitInfo () {
if (!_hostedGitInfo) {
_hostedGitInfo = require('hosted-git-info')
}
return _hostedGitInfo
}

// used to be npm-normalize-package-bin
function normalizePackageBin (pkg, changes) {
Expand Down Expand Up @@ -445,7 +455,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
}
}
if (data.repository.url) {
const hosted = hostedGitInfo.fromUrl(data.repository.url)
const hosted = lazyHostedGitInfo().fromUrl(data.repository.url)
let r
if (hosted) {
if (hosted.getDefaultRepresentation() === 'shortcut') {
Expand Down Expand Up @@ -505,7 +515,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
changes?.push(`Removed invalid "${deps}.${d}"`)
delete data[deps][d]
}
const hosted = hostedGitInfo.fromUrl(data[deps][d])?.toString()
const hosted = lazyHostedGitInfo().fromUrl(data[deps][d])?.toString()
if (hosted && hosted !== data[deps][d]) {
changes?.push(`Normalized git reference to "${deps}.${d}"`)
data[deps][d] = hosted.toString()
Expand Down

0 comments on commit dcf42fc

Please sign in to comment.