diff --git a/packages/webpack-plugin/lib/utils/check-core-version-match.js b/packages/webpack-plugin/lib/utils/check-core-version-match.js index 5264f199af..0bdc7befad 100644 --- a/packages/webpack-plugin/lib/utils/check-core-version-match.js +++ b/packages/webpack-plugin/lib/utils/check-core-version-match.js @@ -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/core@2.7.x with @mpxjs/webpack-plugin@2.7.x +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) diff --git a/packages/webpack-plugin/package.json b/packages/webpack-plugin/package.json index c3f888f33d..241a21701f 100644 --- a/packages/webpack-plugin/package.json +++ b/packages/webpack-plugin/package.json @@ -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" diff --git a/test/e2e/miniprogram-project/package.json b/test/e2e/miniprogram-project/package.json index 0174647c43..2bb89f67b6 100644 --- a/test/e2e/miniprogram-project/package.json +++ b/test/e2e/miniprogram-project/package.json @@ -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", diff --git a/test/e2e/miniprogram-wxss-loader/package.json b/test/e2e/miniprogram-wxss-loader/package.json index fc4fc35208..3f63814b8f 100644 --- a/test/e2e/miniprogram-wxss-loader/package.json +++ b/test/e2e/miniprogram-wxss-loader/package.json @@ -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" }, diff --git a/test/e2e/plugin-project/package.json b/test/e2e/plugin-project/package.json index 8cc8d40b81..a4d6f7f912 100644 --- a/test/e2e/plugin-project/package.json +++ b/test/e2e/plugin-project/package.json @@ -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" },