Skip to content

Commit

Permalink
fix: semver imports (#985)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
ehmicky and kodiakhq[bot] committed Feb 8, 2022
1 parent 33dbff2 commit c7159d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/runtimes/node/bundlers/zisi/nested.ts
@@ -1,4 +1,4 @@
import { valid as validVersion, validRange, satisfies, gte as greaterThanEqual, ltr as lessThanRange } from 'semver'
import semver from 'semver'

import { PackageJson } from '../../utils/package_json'

Expand Down Expand Up @@ -82,7 +82,8 @@ const isOptionalModule = function (
const MIN_NEXT_VERSION = '10.0.4'

const satisfiesRange = (range: string): boolean =>
Boolean(validRange(range)) && (satisfies(MIN_NEXT_VERSION, range) || lessThanRange(MIN_NEXT_VERSION, range))
Boolean(semver.validRange(range)) &&
(semver.satisfies(MIN_NEXT_VERSION, range) || semver.ltr(MIN_NEXT_VERSION, range))

// 'critters' is used only in Next.js >= 10.0.4 when enabling an experimental option and has to be installed manually
// we ignore it if it's missing
Expand All @@ -101,8 +102,8 @@ const isExternalCrittersModule = function (

// can the declared Next.js version resolve to >=10.0.4 ?
// test exact versions
if (validVersion(nextVersion)) {
return greaterThanEqual(nextVersion, MIN_NEXT_VERSION)
if (semver.valid(nextVersion)) {
return semver.gte(nextVersion, MIN_NEXT_VERSION)
}

return satisfiesRange(nextVersion)
Expand Down
4 changes: 2 additions & 2 deletions src/runtimes/node/bundlers/zisi/resolve.ts
Expand Up @@ -3,7 +3,7 @@ import { version as nodeVersion } from 'process'
import findUp from 'find-up'
import pathExists from 'path-exists'
import resolveLib from 'resolve'
import { lt as ltVersion } from 'semver'
import semver from 'semver'

const BACKSLASH_REGEXP = /\\/g

Expand All @@ -25,7 +25,7 @@ const resolvePackage = async function (moduleName: string, baseDirs: string[]):
try {
return await resolvePathPreserveSymlinks(`${moduleName}/package.json`, baseDirs)
} catch (error) {
if (ltVersion(nodeVersion, REQUEST_RESOLVE_MIN_VERSION)) {
if (semver.lt(nodeVersion, REQUEST_RESOLVE_MIN_VERSION)) {
throw error
}

Expand Down

1 comment on commit c7159d7

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 7.5s

largeDepsNft: 34.4s

largeDepsZisi: 1m 0.8s

Please sign in to comment.