Skip to content

Commit

Permalink
fix(perf): only import necessary functions from semver (#88)
Browse files Browse the repository at this point in the history
Just saving a couple of ms by only importing what is needed.
  • Loading branch information
H4ad committed Apr 6, 2024
1 parent 6ebb3c9 commit 71f09d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/normalize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const semver = require('semver')
const valid = require('semver/functions/valid')
const clean = require('semver/functions/clean')
const fs = require('fs/promises')
const { glob } = require('glob')
const legacyFixer = require('normalize-package-data/lib/fixer.js')
Expand Down Expand Up @@ -130,10 +131,10 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
if (!data.version) {
data.version = ''
} else {
if (!semver.valid(data.version, loose)) {
if (!valid(data.version, loose)) {
throw new Error(`Invalid version: "${data.version}"`)
}
const version = semver.clean(data.version, loose)
const version = clean(data.version, loose)
if (version !== data.version) {
changes?.push(`"version" was cleaned and set to "${version}"`)
data.version = version
Expand Down

0 comments on commit 71f09d6

Please sign in to comment.