Skip to content

Commit fda5722

Browse files
authored
fix(perf): lazy load un-common dependencies for npm run (#87)
I know we avoid lazy loading but I think this case is worthy: Before: ```bash $ hyperfine --warmup 3 "node ./bin/npm-cli.js run empty" Benchmark 1: node ./bin/npm-cli.js run empty Time (mean ± σ): 197.3 ms ± 3.5 ms [User: 183.1 ms, System: 51.9 ms] Range (min … max): 193.2 ms … 207.5 ms 15 runs ``` After: ```bash $ hyperfine --warmup 3 "node ./bin/npm-cli.js run empty" Benchmark 1: node ./bin/npm-cli.js run empty Time (mean ± σ): 184.6 ms ± 2.3 ms [User: 170.1 ms, System: 51.1 ms] Range (min … max): 181.6 ms … 190.5 ms 16 runs ```
1 parent 71f09d6 commit fda5722

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/normalize.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ const valid = require('semver/functions/valid')
22
const clean = require('semver/functions/clean')
33
const fs = require('fs/promises')
44
const { glob } = require('glob')
5-
const legacyFixer = require('normalize-package-data/lib/fixer.js')
6-
const legacyMakeWarning = require('normalize-package-data/lib/make_warning.js')
75
const path = require('path')
86
const log = require('proc-log')
9-
const git = require('@npmcli/git')
107
const hostedGitInfo = require('hosted-git-info')
118

129
// used to be npm-normalize-package-bin
@@ -334,6 +331,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
334331

335332
// populate "gitHead" attribute
336333
if (steps.includes('gitHead') && !data.gitHead) {
334+
const git = require('@npmcli/git')
337335
const gitRoot = await git.find({ cwd: pkg.path, root })
338336
let head
339337
if (gitRoot) {
@@ -519,6 +517,8 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
519517
}
520518

521519
if (steps.includes('normalizeData')) {
520+
const legacyFixer = require('normalize-package-data/lib/fixer.js')
521+
const legacyMakeWarning = require('normalize-package-data/lib/make_warning.js')
522522
legacyFixer.warn = function () {
523523
changes?.push(legacyMakeWarning.apply(null, arguments))
524524
}

0 commit comments

Comments
 (0)