-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1339 from didi/feat-check-version-match
Feat check version match
- Loading branch information
Showing
5 changed files
with
29 additions
and
19 deletions.
There are no files selected for viewing
32 changes: 18 additions & 14 deletions
32
packages/webpack-plugin/lib/utils/check-core-version-match.js
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,18 +1,22 @@ | ||
// @mpxjs/webpack-plugin 2.7.x -> @mpxjs/core 2.7.x | ||
// @mpxjs/webpack-plugin 2.8.x -> @mpxjs/core 2.8.x | ||
const coreVersion = require('@mpxjs/core/package.json').version | ||
const packageName = require('../../package.json').name | ||
const packageVersion = require('../../package.json').version | ||
const utilsVersion = require('@mpxjs/utils/package.json').version | ||
const corePath = require.resolve('@mpxjs/core') | ||
const utilsPath = require.resolve('@mpxjs/utils') | ||
const semverLt = require('semver/functions/lt') | ||
|
||
if (packageVersion.slice(0, 3) !== coreVersion.slice(0, 3)) { | ||
const corePath = require.resolve('@mpxjs/core') | ||
const packagePath = require.resolve('../../package.json') | ||
throw new Error( | ||
`@mpxjs/core packages version mismatch: | ||
-@mpxjs/core@${coreVersion}(${corePath}) | ||
-${packageName}@${packageVersion}(${packagePath}) | ||
This may cause things to work incorrectly, Make sure to use the same minor version for both. | ||
For example: @mpxjs/[email protected] with @mpxjs/[email protected] | ||
const leastCoreVersion = '2.8.59' | ||
const leastUtilsVersion = '2.8.59' | ||
|
||
function compare (version, leastVersion, npmName, npmPath) { | ||
if (semverLt(version, leastVersion)) { | ||
throw new Error( | ||
`${npmName} packages version mismatch: | ||
-${npmName}@${version}(${npmPath}) | ||
This may cause things to work incorrectly, Make sure the usage version is greater than ${leastVersion}. | ||
` | ||
) | ||
) | ||
} | ||
} | ||
|
||
compare(coreVersion, leastCoreVersion, '@mpxjs/core', corePath) | ||
compare(utilsVersion, leastUtilsVersion, '@mpxjs/utils', utilsPath) |
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
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