-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(commonjs): validate node-resolve peer version (#1038)
- Loading branch information
1 parent
0b9a0e8
commit 0dc11e6
Showing
5 changed files
with
66 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
export default function validateRollupVersion(rollupVersion, peerDependencyVersion) { | ||
const [major, minor] = rollupVersion.split('.').map(Number); | ||
const versionRegexp = /\^(\d+\.\d+)\.\d+/g; | ||
export default function validateVersion(actualVersion, peerDependencyVersion, name) { | ||
const versionRegexp = /\^(\d+\.\d+\.\d+)/g; | ||
let minMajor = Infinity; | ||
let minMinor = Infinity; | ||
let minPatch = Infinity; | ||
let foundVersion; | ||
// eslint-disable-next-line no-cond-assign | ||
while ((foundVersion = versionRegexp.exec(peerDependencyVersion))) { | ||
const [foundMajor, foundMinor] = foundVersion[1].split('.').map(Number); | ||
const [foundMajor, foundMinor, foundPatch] = foundVersion[1].split('.').map(Number); | ||
if (foundMajor < minMajor) { | ||
minMajor = foundMajor; | ||
minMinor = foundMinor; | ||
minPatch = foundPatch; | ||
} | ||
} | ||
if (major < minMajor || (major === minMajor && minor < minMinor)) { | ||
if (!actualVersion) { | ||
throw new Error( | ||
`Insufficient Rollup version: "@rollup/plugin-commonjs" requires at least rollup@${minMajor}.${minMinor} but found rollup@${rollupVersion}.` | ||
`Insufficient ${name} version: "@rollup/plugin-commonjs" requires at least ${name}@${minMajor}.${minMinor}.${minPatch}.` | ||
); | ||
} | ||
const [major, minor, patch] = actualVersion.split('.').map(Number); | ||
if ( | ||
major < minMajor || | ||
(major === minMajor && (minor < minMinor || (minor === minMinor && patch < minPatch))) | ||
) { | ||
throw new Error( | ||
`Insufficient ${name} version: "@rollup/plugin-commonjs" requires at least ${name}@${minMajor}.${minMinor}.${minPatch} but found ${name}@${actualVersion}.` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.