Skip to content

Commit

Permalink
Merge pull request #1339 from didi/feat-check-version-match
Browse files Browse the repository at this point in the history
Feat check version match
  • Loading branch information
hiyuki authored Dec 4, 2023
2 parents eef66a6 + 8049573 commit ef40678
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
32 changes: 18 additions & 14 deletions packages/webpack-plugin/lib/utils/check-core-version-match.js
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)
3 changes: 2 additions & 1 deletion packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"postcss-selector-parser": "^6.0.8",
"postcss-value-parser": "^4.0.2",
"source-list-map": "^2.0.0",
"video.js": "^8.6.0"
"video.js": "^8.6.0",
"semver": "^7.5.4"
},
"peerDependencies": {
"webpack": "^5.75.0"
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/miniprogram-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"license": "ISC",
"dependencies": {
"@mpxjs/api-proxy": "^2.7.1",
"@mpxjs/core": "^2.9.1",
"@mpxjs/utils": "^2.9.1",
"semver": "^7.5.4",
"vue": "^2.6.10",
"vue-i18n": "^8.15.3",
"@mpxjs/core": "^2.7.2"
"vue-i18n": "^8.15.3"
},
"browserslist": [
"ios >= 9",
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/miniprogram-wxss-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"license": "ISC",
"dependencies": {
"@mpxjs/api-proxy": "^2.7.1",
"@mpxjs/core": "^2.7.2",
"@mpxjs/core": "^2.9.1",
"@mpxjs/utils": "^2.9.1",
"semver": "^7.5.4",
"vue": "^2.6.10",
"vue-i18n": "^8.15.3"
},
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/plugin-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
"license": "ISC",
"dependencies": {
"@mpxjs/api-proxy": "^2.7.1",
"@mpxjs/core": "^2.7.2",
"@mpxjs/core": "^2.9.1",
"@mpxjs/store": "^2.8.15",
"semver": "^7.5.4",
"vue": "^2.6.10",
"vue-i18n": "^8.15.3"
},
Expand Down

0 comments on commit ef40678

Please sign in to comment.