@mpxjs/webpack-plugin 2.10.15 → 2.10.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dependencies/DynamicEntryDependency.js +1 -1
- package/lib/dependencies/ImportDependency.js +102 -0
- package/lib/{retry-runtime-module.js → dependencies/RetryRuntimeModule.js} +1 -1
- package/lib/index.js +11 -10
- package/lib/platform/template/wx/component-config/slider.js +12 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/resolver/AddEnvPlugin.js +13 -0
- package/lib/resolver/AddModePlugin.js +18 -0
- package/lib/runtime/components/react/dist/mpx-progress.jsx +26 -22
- package/lib/runtime/components/react/dist/mpx-slider.jsx +321 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +7 -10
- package/lib/runtime/components/react/mpx-progress.tsx +26 -24
- package/lib/runtime/components/react/mpx-slider.tsx +444 -0
- package/lib/runtime/components/react/mpx-view.tsx +7 -10
- package/lib/runtime/components/web/mpx-input.vue +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +7 -1
- package/lib/runtime/components/web/mpx-video.vue +12 -1
- package/lib/runtime/optionProcessor.js +3 -1
- package/lib/runtime/optionProcessorReact.js +4 -2
- package/lib/template-compiler/compiler.js +10 -6
- package/lib/utils/chain-assign.js +47 -0
- package/lib/utils/check-core-version-match.js +75 -15
- package/lib/wxs/pre-loader.js +5 -5
- package/package.json +5 -4
- package/lib/dependencies/ImportDependencyTemplate.js +0 -50
|
@@ -1,22 +1,82 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const corePath = require.resolve('@mpxjs/core')
|
|
4
|
-
const utilsPath = require.resolve('@mpxjs/utils')
|
|
5
|
-
const semverLt = require('semver/functions/lt')
|
|
1
|
+
const semverSatisfies = require('semver/functions/satisfies')
|
|
2
|
+
const semverCoerce = require('semver/functions/coerce')
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
const
|
|
4
|
+
// 定义包之间的依赖关系和最低版本要求
|
|
5
|
+
const PACKAGE_DEPENDENCIES = {
|
|
6
|
+
'@mpxjs/webpack-plugin': {
|
|
7
|
+
'@mpxjs/core': '^2.10.15 || ^2.10.15-beta.1',
|
|
8
|
+
'@mpxjs/utils': '^2.10.13 || ^2.10.13-beta.1',
|
|
9
|
+
'@mpxjs/api-proxy': '^2.10.15 || ^2.10.15-beta.1'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getPackageVersion (packageName) {
|
|
14
|
+
try {
|
|
15
|
+
return require(`${packageName}/package.json`).version
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.warn(`无法获取 ${packageName} 的版本信息: ${e.message}`)
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function checkVersionSatisfies (version, requiredVersion) {
|
|
23
|
+
try {
|
|
24
|
+
const normalizedVersion = semverCoerce(version).version
|
|
25
|
+
return semverSatisfies(normalizedVersion, requiredVersion)
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.warn(`版本检查失败: ${e.message}`)
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function checkPackageDependencies (packageName) {
|
|
33
|
+
const dependencies = PACKAGE_DEPENDENCIES[packageName]
|
|
34
|
+
if (!dependencies) return []
|
|
35
|
+
|
|
36
|
+
const results = []
|
|
37
|
+
|
|
38
|
+
for (const depName in dependencies) {
|
|
39
|
+
const requiredVersion = dependencies[depName]
|
|
40
|
+
const actualVersion = getPackageVersion(depName)
|
|
41
|
+
|
|
42
|
+
if (!actualVersion) {
|
|
43
|
+
results.push({
|
|
44
|
+
dependency: depName,
|
|
45
|
+
required: requiredVersion,
|
|
46
|
+
actual: null,
|
|
47
|
+
compatible: false,
|
|
48
|
+
error: `无法获取 ${depName} 的版本信息`
|
|
49
|
+
})
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const isCompatible = checkVersionSatisfies(actualVersion, requiredVersion)
|
|
54
|
+
results.push({
|
|
55
|
+
dependency: depName,
|
|
56
|
+
required: requiredVersion,
|
|
57
|
+
actual: actualVersion,
|
|
58
|
+
compatible: isCompatible
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return results
|
|
63
|
+
}
|
|
9
64
|
|
|
10
|
-
function
|
|
11
|
-
|
|
65
|
+
function checkVersionCompatibility () {
|
|
66
|
+
const pluginResults = checkPackageDependencies('@mpxjs/webpack-plugin')
|
|
67
|
+
const incompatibleResults = pluginResults.filter(result => !result.compatible)
|
|
68
|
+
if (incompatibleResults.length > 0) {
|
|
69
|
+
const errorMessages = incompatibleResults.map(result => {
|
|
70
|
+
if (!result.actual) {
|
|
71
|
+
return ` - ${result.error || `${result.dependency} 未安装`}`
|
|
72
|
+
}
|
|
73
|
+
return ` - ${result.dependency}@${result.actual} 不满足所需版本 ${result.required}`
|
|
74
|
+
})
|
|
12
75
|
throw new Error(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
This may cause things to work incorrectly, Make sure the usage version is greater than ${leastVersion}.
|
|
16
|
-
`
|
|
76
|
+
`检测到 @mpxjs 包版本不兼容问题:\n${errorMessages.join('\n')}\n\n` +
|
|
77
|
+
'这可能导致编译或运行异常。请确保所有 @mpxjs 相关包的版本兼容,建议使用相同版本。'
|
|
17
78
|
)
|
|
18
79
|
}
|
|
19
80
|
}
|
|
20
81
|
|
|
21
|
-
|
|
22
|
-
compare(utilsVersion, leastUtilsVersion, '@mpxjs/utils', utilsPath)
|
|
82
|
+
module.exports = checkVersionCompatibility
|
package/lib/wxs/pre-loader.js
CHANGED
|
@@ -4,6 +4,7 @@ const t = require('@babel/types')
|
|
|
4
4
|
const generate = require('@babel/generator').default
|
|
5
5
|
const parseRequest = require('../utils/parse-request')
|
|
6
6
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
7
|
+
const chainAssign = require('../utils/chain-assign')
|
|
7
8
|
const parseQuery = require('loader-utils').parseQuery
|
|
8
9
|
|
|
9
10
|
module.exports = function (content) {
|
|
@@ -30,8 +31,7 @@ module.exports = function (content) {
|
|
|
30
31
|
' __mpx_args__[i] = arguments[i];\n' +
|
|
31
32
|
'}'
|
|
32
33
|
).program.body
|
|
33
|
-
|
|
34
|
-
Object.assign(visitor, {
|
|
34
|
+
chainAssign(visitor, {
|
|
35
35
|
Identifier (path) {
|
|
36
36
|
if (path.node.name === 'arguments') {
|
|
37
37
|
path.node.name = '__mpx_args__'
|
|
@@ -66,7 +66,7 @@ module.exports = function (content) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (mode !== 'wx') {
|
|
69
|
-
|
|
69
|
+
chainAssign(visitor, {
|
|
70
70
|
CallExpression (path) {
|
|
71
71
|
const callee = path.node.callee
|
|
72
72
|
if (t.isIdentifier(callee) && callee.name === 'getRegExp') {
|
|
@@ -81,7 +81,7 @@ module.exports = function (content) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
if (mode === 'dd') {
|
|
84
|
-
|
|
84
|
+
chainAssign(visitor, {
|
|
85
85
|
MemberExpression (path) {
|
|
86
86
|
const property = path.node.property
|
|
87
87
|
if (
|
|
@@ -96,7 +96,7 @@ module.exports = function (content) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
if (!module.wxs) {
|
|
99
|
-
|
|
99
|
+
chainAssign(visitor, {
|
|
100
100
|
MemberExpression (path) {
|
|
101
101
|
const property = path.node.property
|
|
102
102
|
if (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.16",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"@babel/traverse": "^7.16.0",
|
|
22
22
|
"@babel/types": "^7.16.0",
|
|
23
23
|
"@better-scroll/core": "^2.5.1",
|
|
24
|
+
"@better-scroll/mouse-wheel": "^2.5.1",
|
|
24
25
|
"@better-scroll/movable": "^2.5.1",
|
|
25
26
|
"@better-scroll/observe-dom": "^2.5.1",
|
|
26
27
|
"@better-scroll/pull-down": "^2.5.1",
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
"@better-scroll/wheel": "^2.5.1",
|
|
29
30
|
"@better-scroll/zoom": "^2.5.1",
|
|
30
31
|
"@mpxjs/template-engine": "^2.8.7",
|
|
31
|
-
"@mpxjs/utils": "^2.10.
|
|
32
|
+
"@mpxjs/utils": "^2.10.16",
|
|
32
33
|
"acorn": "^8.11.3",
|
|
33
34
|
"acorn-walk": "^7.2.0",
|
|
34
35
|
"async": "^2.6.0",
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
},
|
|
84
85
|
"devDependencies": {
|
|
85
86
|
"@d11/react-native-fast-image": "^8.6.12",
|
|
86
|
-
"@mpxjs/api-proxy": "^2.10.
|
|
87
|
+
"@mpxjs/api-proxy": "^2.10.16",
|
|
87
88
|
"@types/babel-traverse": "^6.25.4",
|
|
88
89
|
"@types/babel-types": "^7.0.4",
|
|
89
90
|
"@types/react": "^18.2.79",
|
|
@@ -100,5 +101,5 @@
|
|
|
100
101
|
"engines": {
|
|
101
102
|
"node": ">=14.14.0"
|
|
102
103
|
},
|
|
103
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "be4129320e298edf935ea35f9ca3d375f75ac51c"
|
|
104
105
|
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const ModuleDependency = require('webpack/lib/dependencies/ModuleDependency')
|
|
2
|
-
const { RetryRuntimeGlobal } = require('../retry-runtime-module')
|
|
3
|
-
const parseRequest = require('../utils/parse-request')
|
|
4
|
-
|
|
5
|
-
class ImportDependencyTemplate extends (
|
|
6
|
-
ModuleDependency.Template
|
|
7
|
-
) {
|
|
8
|
-
/**
|
|
9
|
-
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
10
|
-
* @param {ReplaceSource} source the current replace source which can be modified
|
|
11
|
-
* @param {DependencyTemplateContext} templateContext the context object
|
|
12
|
-
* @returns {void}
|
|
13
|
-
*/
|
|
14
|
-
apply (
|
|
15
|
-
dependency,
|
|
16
|
-
source,
|
|
17
|
-
{ runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
|
|
18
|
-
) {
|
|
19
|
-
const dep = /** @type {ImportDependency} */ (dependency)
|
|
20
|
-
const block = /** @type {AsyncDependenciesBlock} */ (
|
|
21
|
-
moduleGraph.getParentBlock(dep)
|
|
22
|
-
)
|
|
23
|
-
let content = runtimeTemplate.moduleNamespacePromise({
|
|
24
|
-
chunkGraph,
|
|
25
|
-
block: block,
|
|
26
|
-
module: /** @type {Module} */ (moduleGraph.getModule(dep)),
|
|
27
|
-
request: dep.request,
|
|
28
|
-
strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
|
|
29
|
-
message: 'import()',
|
|
30
|
-
runtimeRequirements
|
|
31
|
-
})
|
|
32
|
-
// replace fakeType by 9 to fix require.async to commonjs2 module like 'module.exports = function(){...}'
|
|
33
|
-
content = content.replace(/(__webpack_require__\.t\.bind\(.+,\s*)(\d+)(\s*\))/, (_, p1, p2, p3) => {
|
|
34
|
-
return p1 + '9' + p3
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const { queryObj } = parseRequest(dep.request)
|
|
38
|
-
const retryRequireAsync = queryObj.retryRequireAsync && JSON.parse(queryObj.retryRequireAsync)
|
|
39
|
-
|
|
40
|
-
// require.async 的场景且配置了重试次数才注入 RetryRuntimeModule
|
|
41
|
-
if (queryObj.isRequireAsync && retryRequireAsync && retryRequireAsync.times > 0) {
|
|
42
|
-
runtimeRequirements.add(RetryRuntimeGlobal)
|
|
43
|
-
content = `${RetryRuntimeGlobal}(function() { return ${content} }, ${retryRequireAsync.times}, ${retryRequireAsync.interval})`
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
source.replace(dep.range[0], dep.range[1] - 1, content)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = ImportDependencyTemplate
|