Skip to content

Commit 71f09d6

Browse files
authored
fix(perf): only import necessary functions from semver (#88)
Just saving a couple of ms by only importing what is needed.
1 parent 6ebb3c9 commit 71f09d6

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

lib/normalize.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const semver = require('semver')
1+
const valid = require('semver/functions/valid')
2+
const clean = require('semver/functions/clean')
23
const fs = require('fs/promises')
34
const { glob } = require('glob')
45
const legacyFixer = require('normalize-package-data/lib/fixer.js')
@@ -130,10 +131,10 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
130131
if (!data.version) {
131132
data.version = ''
132133
} else {
133-
if (!semver.valid(data.version, loose)) {
134+
if (!valid(data.version, loose)) {
134135
throw new Error(`Invalid version: "${data.version}"`)
135136
}
136-
const version = semver.clean(data.version, loose)
137+
const version = clean(data.version, loose)
137138
if (version !== data.version) {
138139
changes?.push(`"version" was cleaned and set to "${version}"`)
139140
data.version = version

0 commit comments

Comments
 (0)