@mpxjs/webpack-plugin 2.10.22 → 2.10.24-beta.1

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.
Files changed (34) hide show
  1. package/lib/index.js +4 -1
  2. package/lib/loader.js +2 -0
  3. package/lib/react/index.js +3 -1
  4. package/lib/react/processTemplate.js +3 -1
  5. package/lib/resolver/AddEnvPlugin.js +1 -1
  6. package/lib/resolver/AddModePlugin.js +1 -1
  7. package/lib/resolver/ExtendComponentsPlugin.js +91 -0
  8. package/lib/runtime/components/extends/section-list.mpx +14 -0
  9. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +3 -1
  10. package/lib/runtime/components/react/dist/mpx-section-list.d.ts +56 -0
  11. package/lib/runtime/components/react/dist/mpx-section-list.jsx +484 -0
  12. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +12 -12
  13. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
  14. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +12 -12
  15. package/lib/runtime/components/react/dist/mpx-text.jsx +15 -15
  16. package/lib/runtime/components/react/dist/mpx-view.jsx +15 -15
  17. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +2 -1
  18. package/lib/runtime/components/react/dist/utils.d.ts +1 -0
  19. package/lib/runtime/components/react/dist/utils.jsx +4 -1
  20. package/lib/runtime/components/react/mpx-canvas/index.tsx +4 -2
  21. package/lib/runtime/components/react/mpx-canvas/utils.tsx +3 -1
  22. package/lib/runtime/components/react/mpx-section-list.tsx +734 -0
  23. package/lib/runtime/components/react/mpx-simple-text.tsx +12 -12
  24. package/lib/runtime/components/react/mpx-simple-view.tsx +12 -12
  25. package/lib/runtime/components/react/mpx-text.tsx +15 -15
  26. package/lib/runtime/components/react/mpx-view.tsx +15 -15
  27. package/lib/runtime/components/react/mpx-web-view.tsx +4 -3
  28. package/lib/runtime/components/react/utils.tsx +5 -1
  29. package/lib/template-compiler/compiler.js +5 -1
  30. package/lib/utils/source-location.js +9 -13
  31. package/lib/web/index.js +3 -1
  32. package/lib/web/processTemplate.js +3 -1
  33. package/package.json +4 -3
  34. package/LICENSE +0 -433
package/lib/index.js CHANGED
@@ -30,6 +30,7 @@ const AddEnvPlugin = require('./resolver/AddEnvPlugin')
30
30
  const PackageEntryPlugin = require('./resolver/PackageEntryPlugin')
31
31
  const DynamicRuntimePlugin = require('./resolver/DynamicRuntimePlugin')
32
32
  const FixDescriptionInfoPlugin = require('./resolver/FixDescriptionInfoPlugin')
33
+ const ExtendComponentsPlugin = require('./resolver/ExtendComponentsPlugin')
33
34
  // const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequireDependency')
34
35
  // const HarmonyImportSideEffectDependency = require('webpack/lib/dependencies/HarmonyImportSideEffectDependency')
35
36
  // const RequireHeaderDependency = require('webpack/lib/dependencies/RequireHeaderDependency')
@@ -416,11 +417,13 @@ class MpxWebpackPlugin {
416
417
  const addEnvPlugin = new AddEnvPlugin('before-file', this.options.env, this.options.fileConditionRules, 'file')
417
418
  const packageEntryPlugin = new PackageEntryPlugin('before-file', this.options.miniNpmPackages, this.options.normalNpmPackages, 'file')
418
419
  const dynamicPlugin = new DynamicPlugin('result', this.options.dynamicComponentRules)
420
+ const extendComponentsPlugin = new ExtendComponentsPlugin('before-file', this.options.mode, 'file', compiler)
419
421
 
420
422
  if (Array.isArray(compiler.options.resolve.plugins)) {
423
+ compiler.options.resolve.plugins.push(extendComponentsPlugin)
421
424
  compiler.options.resolve.plugins.push(addModePlugin)
422
425
  } else {
423
- compiler.options.resolve.plugins = [addModePlugin]
426
+ compiler.options.resolve.plugins = [extendComponentsPlugin, addModePlugin]
424
427
  }
425
428
  if (this.options.env) {
426
429
  compiler.options.resolve.plugins.push(addEnvPlugin)
package/lib/loader.js CHANGED
@@ -154,6 +154,7 @@ module.exports = function (content) {
154
154
  usingComponentsInfo,
155
155
  originalUsingComponents,
156
156
  componentGenerics,
157
+ componentPlaceholder,
157
158
  autoScope,
158
159
  callback
159
160
  })
@@ -177,6 +178,7 @@ module.exports = function (content) {
177
178
  usingComponentsInfo,
178
179
  originalUsingComponents,
179
180
  componentGenerics,
181
+ componentPlaceholder,
180
182
  autoScope,
181
183
  callback
182
184
  })
@@ -23,6 +23,7 @@ module.exports = function ({
23
23
  usingComponentsInfo,
24
24
  originalUsingComponents,
25
25
  componentGenerics,
26
+ componentPlaceholder,
26
27
  autoScope,
27
28
  callback
28
29
  }) {
@@ -55,7 +56,8 @@ module.exports = function ({
55
56
  ctorType,
56
57
  usingComponentsInfo,
57
58
  originalUsingComponents,
58
- componentGenerics
59
+ componentGenerics,
60
+ componentPlaceholder
59
61
  }, callback)
60
62
  },
61
63
  (callback) => {
@@ -32,7 +32,8 @@ module.exports = function (template, {
32
32
  ctorType,
33
33
  usingComponentsInfo,
34
34
  originalUsingComponents,
35
- componentGenerics
35
+ componentGenerics,
36
+ componentPlaceholder
36
37
  }, callback) {
37
38
  const mpx = loaderContext.getMpx()
38
39
  const {
@@ -103,6 +104,7 @@ module.exports = function (template, {
103
104
  i18n: null,
104
105
  // 与 template-compiler/index 一致:usingComponentsInfo 已合并 globalComponentsInfo,此处白名单避免对仅 app 注册的组件误报「未使用」
105
106
  globalComponents: Object.keys(globalComponents || {}),
107
+ componentPlaceholder,
106
108
  // rn模式下实现抽象组件
107
109
  componentGenerics,
108
110
  hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules),
@@ -19,7 +19,7 @@ module.exports = class AddEnvPlugin {
19
19
  const envPattern = new RegExp(`\\.${env}(\\.|$)`)
20
20
 
21
21
  resolver.getHook(this.source).tapAsync('AddEnvPlugin', (request, resolveContext, callback) => {
22
- if (request.env) {
22
+ if (request.__mpxResolvedExtendComponent || request.env) {
23
23
  return callback()
24
24
  }
25
25
  const obj = {
@@ -21,7 +21,7 @@ module.exports = class AddModePlugin {
21
21
  const defaultModePattern = new RegExp(`\\.${defaultMode}(\\.|$)`)
22
22
 
23
23
  resolver.getHook(this.source).tapAsync('AddModePlugin', (request, resolveContext, callback) => {
24
- if (request.mode || request.env) {
24
+ if (request.__mpxResolvedExtendComponent || request.mode || request.env) {
25
25
  return callback()
26
26
  }
27
27
  const obj = {
@@ -0,0 +1,91 @@
1
+ const path = require('path')
2
+ const toPosix = require('../utils/to-posix')
3
+ const EXTEND_COMPONENT_PATH_REGEXP = /\/lib\/runtime\/components\/extends\//
4
+ const EXTEND_COMPONENT_TARGET_SUB_PATH = 'lib/runtime/components/react/dist/'
5
+ const EXTEND_COMPONENTS = {
6
+ 'section-list': ['ios', 'android', 'harmony']
7
+ }
8
+
9
+ /**
10
+ * 扩展组件路径解析插件
11
+ * 将 @mpxjs/webpack-plugin/lib/runtime/components/extends/[component-name] 格式的路径
12
+ * 解析为对应平台的实际组件路径
13
+ */
14
+ module.exports = class ExtendComponentsPlugin {
15
+ constructor (source, mode, target, compiler) {
16
+ this.source = source
17
+ this.target = target
18
+ this.mode = mode
19
+ this.currentCompilation = null
20
+ compiler.hooks.thisCompilation.tap('ExtendComponentsPlugin', (compilation) => {
21
+ this.currentCompilation = compilation
22
+ })
23
+ }
24
+
25
+ apply (resolver) {
26
+ const target = resolver.ensureHook(this.target)
27
+ const mode = this.mode
28
+
29
+ const pushError = (err) => {
30
+ if (this.currentCompilation) {
31
+ this.currentCompilation.errors.push(err)
32
+ }
33
+ }
34
+
35
+ resolver.getHook(this.source).tapAsync('ExtendComponentsPlugin', (request, resolveContext, callback) => {
36
+ if (request.__mpxResolvedExtendComponent) return callback()
37
+
38
+ const componentName = getComponentName(request)
39
+ if (!componentName) {
40
+ return callback()
41
+ }
42
+
43
+ // 检查组件是否在配置中
44
+ const supportedModes = EXTEND_COMPONENTS[componentName]
45
+ if (!supportedModes) {
46
+ pushError(new Error(`Extended component "${componentName}" was not found. Available extended components: ${Object.keys(EXTEND_COMPONENTS).join(', ')}`))
47
+ return callback()
48
+ }
49
+
50
+ // 获取当前模式下的组件路径
51
+ if (!supportedModes.includes(mode)) {
52
+ pushError(new Error(`Extended component "${componentName}" cannot be used on the ${mode} platform. Supported platforms include: ${supportedModes.join(', ')}`))
53
+ return callback()
54
+ }
55
+ const targetSubPath = `${EXTEND_COMPONENT_TARGET_SUB_PATH}mpx-${componentName}.jsx`
56
+ const targetRelativePath = `./${targetSubPath}`
57
+ const targetPath = path.join(request.descriptionFileRoot, targetSubPath)
58
+
59
+ const redirectRequest = Object.assign({}, request, {
60
+ path: targetPath,
61
+ relativePath: targetRelativePath,
62
+ __mpxResolvedExtendComponent: true
63
+ })
64
+
65
+ resolver.doResolve(
66
+ target,
67
+ redirectRequest,
68
+ `resolve extend component: ${componentName} to ${targetPath}`,
69
+ resolveContext,
70
+ (err, result) => {
71
+ if (err) {
72
+ pushError(err)
73
+ return callback()
74
+ }
75
+ if (!result) {
76
+ pushError(new Error(`Extended component "${componentName}" resolved to "${targetPath}", but the target file was not found.`))
77
+ return callback()
78
+ }
79
+ callback(null, result)
80
+ }
81
+ )
82
+ })
83
+ }
84
+ }
85
+
86
+ function getComponentName (request) {
87
+ if (!request.path) return
88
+ const requestPath = toPosix(request.path)
89
+ if (!EXTEND_COMPONENT_PATH_REGEXP.test(requestPath)) return
90
+ return path.basename(requestPath, path.extname(requestPath))
91
+ }
@@ -0,0 +1,14 @@
1
+ <!--
2
+ Placeholder for @mpxjs/webpack-plugin/lib/runtime/components/extends/section-list.
3
+ ExtendComponentsPlugin should always redirect requests away from this file at
4
+ build time. Reaching this module means the plugin failed to redirect — most
5
+ likely because section-list is not supported on the current platform, or
6
+ ExtendComponentsPlugin is not registered on the resolver.
7
+ -->
8
+ <template></template>
9
+
10
+ <script>
11
+ import { error } from '@mpxjs/utils'
12
+ error('section-list extend placeholder reached at runtime, ExtendComponentsPlugin redirect failed. See build log for the original error.')
13
+ export default {}
14
+ </script>
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { WebView } from 'react-native-webview';
3
3
  import Bus from './Bus';
4
+ type WebViewInstance = WebView<{}>;
4
5
  export declare const WEBVIEW_TARGET = "@@WEBVIEW_TARGET";
5
6
  export declare const constructors: Record<string, any>;
6
7
  export declare const ID: () => string;
@@ -30,7 +31,7 @@ export interface WebviewMessage {
30
31
  };
31
32
  }
32
33
  export interface CanvasInstance {
33
- webview: WebView | null;
34
+ webview: WebViewInstance | null;
34
35
  bus: Bus | null;
35
36
  context2D: CanvasRenderingContext2D;
36
37
  getContext: (contextType: string) => CanvasRenderingContext2D | null;
@@ -50,3 +51,4 @@ export declare const useWebviewBinding: ({ targetName, properties, methods }: {
50
51
  properties?: Record<string, any> | undefined;
51
52
  methods?: string[] | undefined;
52
53
  }) => import("react").MutableRefObject<{}>;
54
+ export {};
@@ -0,0 +1,56 @@
1
+ /// <reference types="react" />
2
+ import { GestureHandler } from './utils';
3
+ interface ListItem {
4
+ isSectionHeader?: boolean;
5
+ isSectionFooter?: boolean;
6
+ [key: string]: any;
7
+ }
8
+ interface ItemHeightType {
9
+ value?: number;
10
+ getter?: (item: any, index: number) => number;
11
+ }
12
+ interface MpxSectionListProps {
13
+ enhanced?: boolean;
14
+ bounces?: boolean;
15
+ height?: number | string;
16
+ width?: number | string;
17
+ generichash?: string;
18
+ style?: Record<string, any>;
19
+ 'scroll-event-throttle'?: number;
20
+ 'list-data'?: ListItem[];
21
+ 'item-height'?: ItemHeightType;
22
+ 'section-header-height'?: ItemHeightType;
23
+ 'section-footer-height'?: ItemHeightType;
24
+ 'list-header-data'?: any;
25
+ 'list-header-height'?: number;
26
+ 'use-list-header'?: boolean;
27
+ 'list-footer-data'?: any;
28
+ 'use-list-footer'?: boolean;
29
+ 'genericrecycle-item'?: string;
30
+ 'genericsection-header'?: string;
31
+ 'genericsection-footer'?: string;
32
+ 'genericlist-header'?: string;
33
+ 'genericlist-footer'?: string;
34
+ 'enable-var'?: boolean;
35
+ 'external-var-context'?: any;
36
+ 'parent-font-size'?: number;
37
+ 'parent-width'?: number;
38
+ 'parent-height'?: number;
39
+ 'enable-sticky'?: boolean;
40
+ 'enable-back-to-top'?: boolean;
41
+ 'end-reached-threshold'?: number;
42
+ 'refresher-enabled'?: boolean;
43
+ 'show-scrollbar'?: boolean;
44
+ 'refresher-triggered'?: boolean;
45
+ 'enable-item-exposure'?: boolean;
46
+ 'item-exposure-threshold'?: number;
47
+ 'wait-for'?: Array<GestureHandler>;
48
+ 'simultaneous-handlers'?: Array<GestureHandler>;
49
+ bindrefresherrefresh?: (event: any) => void;
50
+ bindscrolltolower?: (event: any) => void;
51
+ bindscroll?: (event: any) => void;
52
+ binditemexposure?: (event: any) => void;
53
+ [key: string]: any;
54
+ }
55
+ declare const _SectionList: import("react").ForwardRefExoticComponent<Omit<MpxSectionListProps, "ref"> & import("react").RefAttributes<any>>;
56
+ export default _SectionList;