@weapp-vite/web 1.3.36 → 1.4.0
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/README.md +144 -5
- package/dist/_virtual/_rolldown/runtime.mjs +19 -1
- package/dist/compiler/wxml/attributes.mjs +1 -1
- package/dist/compiler/wxml/attributes.mjs.map +1 -1
- package/dist/compiler/wxml/compile.mjs +6 -3
- package/dist/compiler/wxml/compile.mjs.map +1 -1
- package/dist/compiler/wxml/interpolation.mjs +1 -2
- package/dist/compiler/wxml/interpolation.mjs.map +1 -1
- package/dist/compiler/wxml/navigation.mjs +5 -7
- package/dist/compiler/wxml/navigation.mjs.map +1 -1
- package/dist/compiler/wxml/parser.mjs +5 -5
- package/dist/compiler/wxml/parser.mjs.map +1 -1
- package/dist/compiler/wxml/renderer.mjs +13 -12
- package/dist/compiler/wxml/renderer.mjs.map +1 -1
- package/dist/compiler/wxml/specialNodes.mjs +6 -1
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -1
- package/dist/compiler/wxml/types.d.mts +12 -0
- package/dist/compiler/wxs.mjs +5 -5
- package/dist/compiler/wxs.mjs.map +1 -1
- package/dist/css/wxss.d.mts +1 -0
- package/dist/css/wxss.mjs +110 -9
- package/dist/css/wxss.mjs.map +1 -1
- package/dist/index.d.mts +29 -6
- package/dist/index.mjs +197 -4
- package/dist/index.mjs.map +1 -0
- package/dist/plugin/assets.d.mts +7 -0
- package/dist/plugin/assets.mjs +122 -0
- package/dist/plugin/assets.mjs.map +1 -0
- package/dist/plugin/constants.mjs +10 -1
- package/dist/plugin/constants.mjs.map +1 -1
- package/dist/plugin/dependencyScan.mjs +41 -0
- package/dist/plugin/dependencyScan.mjs.map +1 -0
- package/dist/plugin/entry.mjs +56 -7
- package/dist/plugin/entry.mjs.map +1 -1
- package/dist/plugin/files.mjs +1 -1
- package/dist/plugin/files.mjs.map +1 -1
- package/dist/plugin/index.d.mts +37 -3
- package/dist/plugin/index.mjs +245 -74
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/layout.mjs +24 -0
- package/dist/plugin/layout.mjs.map +1 -0
- package/dist/plugin/path.mjs +4 -1
- package/dist/plugin/path.mjs.map +1 -1
- package/dist/plugin/register.mjs +48 -36
- package/dist/plugin/register.mjs.map +1 -1
- package/dist/plugin/scan.mjs +206 -94
- package/dist/plugin/scan.mjs.map +1 -1
- package/dist/plugin/scanSfc.mjs +65 -0
- package/dist/plugin/scanSfc.mjs.map +1 -0
- package/dist/plugin/state.mjs +3 -2
- package/dist/plugin/state.mjs.map +1 -1
- package/dist/plugin/styleModule.mjs +52 -0
- package/dist/plugin/styleModule.mjs.map +1 -0
- package/dist/plugin/types.d.mts +46 -1
- package/dist/plugin/vueSfc.mjs +149 -0
- package/dist/plugin/vueSfc.mjs.map +1 -0
- package/dist/runtime/appShell/container.mjs +25 -0
- package/dist/runtime/appShell/container.mjs.map +1 -0
- package/dist/runtime/appShell/tabBar/index.mjs +192 -0
- package/dist/runtime/appShell/tabBar/index.mjs.map +1 -0
- package/dist/runtime/appShell/tabBar/style.mjs +127 -0
- package/dist/runtime/appShell/tabBar/style.mjs.map +1 -0
- package/dist/runtime/button/helpers.mjs +1 -58
- package/dist/runtime/button/helpers.mjs.map +1 -1
- package/dist/runtime/button/index.d.mts +4 -5
- package/dist/runtime/button/index.mjs +6 -28
- package/dist/runtime/button/index.mjs.map +1 -1
- package/dist/runtime/button/style.mjs +53 -28
- package/dist/runtime/button/style.mjs.map +1 -1
- package/dist/runtime/component/behavior.mjs +26 -2
- package/dist/runtime/component/behavior.mjs.map +1 -1
- package/dist/runtime/component/element.mjs +107 -31
- package/dist/runtime/component/element.mjs.map +1 -1
- package/dist/runtime/component/observers.mjs +36 -0
- package/dist/runtime/component/observers.mjs.map +1 -0
- package/dist/runtime/component/publicInstance.mjs +48 -0
- package/dist/runtime/component/publicInstance.mjs.map +1 -0
- package/dist/runtime/component/relations.mjs +35 -0
- package/dist/runtime/component/relations.mjs.map +1 -0
- package/dist/runtime/component/slots.mjs +24 -0
- package/dist/runtime/component/slots.mjs.map +1 -0
- package/dist/runtime/component/state.mjs +13 -3
- package/dist/runtime/component/state.mjs.map +1 -1
- package/dist/runtime/component/types.d.mts +29 -4
- package/dist/runtime/component/virtualHost.mjs +83 -0
- package/dist/runtime/component/virtualHost.mjs.map +1 -0
- package/dist/runtime/host/index.d.mts +13 -0
- package/dist/runtime/host/index.mjs +47 -0
- package/dist/runtime/host/index.mjs.map +1 -0
- package/dist/runtime/host/types.d.mts +28 -0
- package/dist/runtime/hostGlobals.d.mts +9 -0
- package/dist/runtime/hostGlobals.mjs +39 -0
- package/dist/runtime/hostGlobals.mjs.map +1 -0
- package/dist/runtime/index.d.mts +21 -3
- package/dist/runtime/index.mjs +26 -4
- package/dist/runtime/index.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/dom.mjs +3 -3
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/expression.mjs +9 -9
- package/dist/runtime/legacyTemplate/expression.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/index.mjs +6 -6
- package/dist/runtime/legacyTemplate/index.mjs.map +1 -1
- package/dist/runtime/nativeComponents/canvas/index.mjs +53 -0
- package/dist/runtime/nativeComponents/canvas/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/checkbox.mjs +137 -0
- package/dist/runtime/nativeComponents/checkbox.mjs.map +1 -0
- package/dist/runtime/nativeComponents/cover/index.mjs +23 -0
- package/dist/runtime/nativeComponents/cover/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/form.d.mts +7 -0
- package/dist/runtime/nativeComponents/form.mjs +50 -0
- package/dist/runtime/nativeComponents/form.mjs.map +1 -0
- package/dist/runtime/nativeComponents/formControl.mjs +61 -0
- package/dist/runtime/nativeComponents/formControl.mjs.map +1 -0
- package/dist/runtime/nativeComponents/helpers.mjs +25 -0
- package/dist/runtime/nativeComponents/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/icon/helpers.mjs +42 -0
- package/dist/runtime/nativeComponents/icon/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/icon/index.mjs +45 -0
- package/dist/runtime/nativeComponents/icon/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/icon/style.mjs +176 -0
- package/dist/runtime/nativeComponents/icon/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/image.d.mts +8 -0
- package/dist/runtime/nativeComponents/image.mjs +121 -0
- package/dist/runtime/nativeComponents/image.mjs.map +1 -0
- package/dist/runtime/nativeComponents/index.d.mts +11 -0
- package/dist/runtime/nativeComponents/index.mjs +83 -0
- package/dist/runtime/nativeComponents/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/input.d.mts +8 -0
- package/dist/runtime/nativeComponents/input.mjs +131 -0
- package/dist/runtime/nativeComponents/input.mjs.map +1 -0
- package/dist/runtime/nativeComponents/label.mjs +36 -0
- package/dist/runtime/nativeComponents/label.mjs.map +1 -0
- package/dist/runtime/nativeComponents/mediaRegistry.mjs +47 -0
- package/dist/runtime/nativeComponents/mediaRegistry.mjs.map +1 -0
- package/dist/runtime/nativeComponents/movable/helpers.mjs +23 -0
- package/dist/runtime/nativeComponents/movable/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/movable/index.mjs +117 -0
- package/dist/runtime/nativeComponents/movable/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/navigator.mjs +200 -0
- package/dist/runtime/nativeComponents/navigator.mjs.map +1 -0
- package/dist/runtime/nativeComponents/picker/editors.mjs +74 -0
- package/dist/runtime/nativeComponents/picker/editors.mjs.map +1 -0
- package/dist/runtime/nativeComponents/picker/helpers.mjs +57 -0
- package/dist/runtime/nativeComponents/picker/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/picker/index.mjs +210 -0
- package/dist/runtime/nativeComponents/picker/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/picker/style.mjs +71 -0
- package/dist/runtime/nativeComponents/picker/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/pickerView/column.mjs +134 -0
- package/dist/runtime/nativeComponents/pickerView/column.mjs.map +1 -0
- package/dist/runtime/nativeComponents/pickerView/helpers.mjs +17 -0
- package/dist/runtime/nativeComponents/pickerView/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/pickerView/index.mjs +128 -0
- package/dist/runtime/nativeComponents/pickerView/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/pickerView/style.mjs +58 -0
- package/dist/runtime/nativeComponents/pickerView/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/primitives.mjs +16 -0
- package/dist/runtime/nativeComponents/primitives.mjs.map +1 -0
- package/dist/runtime/nativeComponents/progress/helpers.mjs +29 -0
- package/dist/runtime/nativeComponents/progress/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/progress/index.mjs +130 -0
- package/dist/runtime/nativeComponents/progress/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/progress/style.mjs +40 -0
- package/dist/runtime/nativeComponents/progress/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/radio.mjs +147 -0
- package/dist/runtime/nativeComponents/radio.mjs.map +1 -0
- package/dist/runtime/nativeComponents/richText/helpers.mjs +230 -0
- package/dist/runtime/nativeComponents/richText/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/richText/index.mjs +74 -0
- package/dist/runtime/nativeComponents/richText/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/scrollView.d.mts +15 -0
- package/dist/runtime/nativeComponents/scrollView.mjs +79 -0
- package/dist/runtime/nativeComponents/scrollView.mjs.map +1 -0
- package/dist/runtime/nativeComponents/slider/helpers.mjs +28 -0
- package/dist/runtime/nativeComponents/slider/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/slider/index.mjs +120 -0
- package/dist/runtime/nativeComponents/slider/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/slider/style.mjs +60 -0
- package/dist/runtime/nativeComponents/slider/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/style.mjs +41 -0
- package/dist/runtime/nativeComponents/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/swiper/helpers.mjs +52 -0
- package/dist/runtime/nativeComponents/swiper/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/swiper/index.mjs +235 -0
- package/dist/runtime/nativeComponents/swiper/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/swiper/item.mjs +14 -0
- package/dist/runtime/nativeComponents/swiper/item.mjs.map +1 -0
- package/dist/runtime/nativeComponents/swiper/style.mjs +20 -0
- package/dist/runtime/nativeComponents/swiper/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/switch.d.mts +7 -0
- package/dist/runtime/nativeComponents/switch.mjs +132 -0
- package/dist/runtime/nativeComponents/switch.mjs.map +1 -0
- package/dist/runtime/nativeComponents/textarea.d.mts +9 -0
- package/dist/runtime/nativeComponents/textarea.mjs +144 -0
- package/dist/runtime/nativeComponents/textarea.mjs.map +1 -0
- package/dist/runtime/nativeComponents/video/helpers.d.mts +12 -0
- package/dist/runtime/nativeComponents/video/helpers.mjs +21 -0
- package/dist/runtime/nativeComponents/video/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/video/index.mjs +124 -0
- package/dist/runtime/nativeComponents/video/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/video/style.mjs +14 -0
- package/dist/runtime/nativeComponents/video/style.mjs.map +1 -0
- package/dist/runtime/navigationBar/index.mjs +1 -3
- package/dist/runtime/navigationBar/index.mjs.map +1 -1
- package/dist/runtime/pageLayout.d.mts +9 -0
- package/dist/runtime/pageLayout.mjs +16 -0
- package/dist/runtime/pageLayout.mjs.map +1 -0
- package/dist/runtime/polyfill/animation.mjs +120 -0
- package/dist/runtime/polyfill/animation.mjs.map +1 -0
- package/dist/runtime/polyfill/appState.mjs +1 -1
- package/dist/runtime/polyfill/appState.mjs.map +1 -1
- package/dist/runtime/polyfill/async.d.mts +7 -0
- package/dist/runtime/polyfill/async.mjs.map +1 -1
- package/dist/runtime/polyfill/canvasContext.mjs +41 -0
- package/dist/runtime/polyfill/canvasContext.mjs.map +1 -1
- package/dist/runtime/polyfill/device.mjs +1 -1
- package/dist/runtime/polyfill/device.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +8 -2
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -1
- package/dist/runtime/polyfill/eventBus.mjs +56 -0
- package/dist/runtime/polyfill/eventBus.mjs.map +1 -0
- package/dist/runtime/polyfill/fileSystemManager.mjs +5 -2
- package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -1
- package/dist/runtime/polyfill/files.mjs +10 -10
- package/dist/runtime/polyfill/files.mjs.map +1 -1
- package/dist/runtime/polyfill/font.mjs +32 -0
- package/dist/runtime/polyfill/font.mjs.map +1 -0
- package/dist/runtime/polyfill/index.d.mts +2 -2
- package/dist/runtime/polyfill/index.mjs +49 -45
- package/dist/runtime/polyfill/index.mjs.map +1 -1
- package/dist/runtime/polyfill/interaction.mjs +7 -6
- package/dist/runtime/polyfill/interaction.mjs.map +1 -1
- package/dist/runtime/polyfill/interactionApi.mjs +3 -2
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -1
- package/dist/runtime/polyfill/intersectionObserver.mjs +106 -0
- package/dist/runtime/polyfill/intersectionObserver.mjs.map +1 -0
- package/dist/runtime/polyfill/locale.mjs +14 -0
- package/dist/runtime/polyfill/locale.mjs.map +1 -0
- package/dist/runtime/polyfill/locationApi.mjs +7 -4
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaActions.mjs +2 -2
- package/dist/runtime/polyfill/mediaActions.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/file.mjs +1 -1
- package/dist/runtime/polyfill/mediaApi/info.mjs +6 -4
- package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -1
- package/dist/runtime/polyfill/menuApi.mjs +38 -4
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
- package/dist/runtime/polyfill/navigationBarRuntime.mjs +6 -1
- package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/network/request.mjs +2 -2
- package/dist/runtime/polyfill/network/request.mjs.map +1 -1
- package/dist/runtime/polyfill/platformApi.mjs +1 -1
- package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs +88 -0
- package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/dom.mjs +44 -15
- package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/history.d.mts +30 -0
- package/dist/runtime/polyfill/routeRuntime/history.mjs +148 -0
- package/dist/runtime/polyfill/routeRuntime/history.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +39 -8
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +11 -1
- package/dist/runtime/polyfill/routeRuntime/options.mjs +0 -1
- package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/result.mjs +12 -0
- package/dist/runtime/polyfill/routeRuntime/result.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/scroll.mjs +39 -0
- package/dist/runtime/polyfill/routeRuntime/scroll.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/stack.mjs +122 -0
- package/dist/runtime/polyfill/routeRuntime/stack.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime.d.mts +26 -17
- package/dist/runtime/polyfill/routeRuntime.mjs +121 -96
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeDataApi.mjs +8 -3
- package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeOps.mjs +10 -6
- package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -1
- package/dist/runtime/polyfill/selectorQuery.mjs +70 -14
- package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -1
- package/dist/runtime/polyfill/storage.mjs +5 -2
- package/dist/runtime/polyfill/storage.mjs.map +1 -1
- package/dist/runtime/polyfill/system.mjs +30 -3
- package/dist/runtime/polyfill/system.mjs.map +1 -1
- package/dist/runtime/polyfill/types/locationRuntime.d.mts +1 -4
- package/dist/runtime/polyfill/types/platformRuntime.d.mts +9 -0
- package/dist/runtime/polyfill/types/systemAuth.d.mts +20 -9
- package/dist/runtime/polyfill/types/tabBarRuntime.d.mts +25 -0
- package/dist/runtime/polyfill/ui.mjs +2 -6
- package/dist/runtime/polyfill/ui.mjs.map +1 -1
- package/dist/runtime/polyfill/uiMediaApi.d.mts +11 -10
- package/dist/runtime/polyfill/uiMediaApi.mjs +26 -2
- package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -1
- package/dist/runtime/polyfill/videoContext.mjs +4 -0
- package/dist/runtime/polyfill/videoContext.mjs.map +1 -1
- package/dist/runtime/polyfill/vkSession.mjs +4 -14
- package/dist/runtime/polyfill/vkSession.mjs.map +1 -1
- package/dist/runtime/polyfill.d.mts +2 -2
- package/dist/runtime/renderContext.mjs +1 -1
- package/dist/runtime/renderContext.mjs.map +1 -1
- package/dist/runtime/rpx.mjs +17 -8
- package/dist/runtime/rpx.mjs.map +1 -1
- package/dist/runtime/seo/index.d.mts +31 -0
- package/dist/runtime/seo/index.mjs +94 -0
- package/dist/runtime/seo/index.mjs.map +1 -0
- package/dist/runtime/viewport/index.d.mts +12 -0
- package/dist/runtime/viewport/index.mjs +44 -0
- package/dist/runtime/viewport/index.mjs.map +1 -0
- package/dist/runtime/viewport/style.mjs +62 -0
- package/dist/runtime/viewport/style.mjs.map +1 -0
- package/dist/runtime/viewport/types.d.mts +14 -0
- package/dist/runtime/wevu.d.mts +20 -0
- package/dist/runtime/wevu.mjs +73 -0
- package/dist/runtime/wevu.mjs.map +1 -0
- package/dist/shared/nativeComponents.mjs +401 -0
- package/dist/shared/nativeComponents.mjs.map +1 -0
- package/dist/shared/tabBar.d.mts +19 -0
- package/dist/shared/tabBar.mjs +37 -0
- package/dist/shared/tabBar.mjs.map +1 -0
- package/dist/shared/wxml.mjs +3 -20
- package/dist/shared/wxml.mjs.map +1 -1
- package/package.json +13 -5
package/dist/plugin/register.mjs
CHANGED
|
@@ -1,44 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { STYLE_QUERY, TEMPLATE_QUERY } from "./constants.mjs";
|
|
2
|
+
import { appendQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from "./path.mjs";
|
|
2
3
|
import { parse } from "@babel/parser";
|
|
3
4
|
import _babelTraverse from "@babel/traverse";
|
|
4
5
|
import * as t from "@babel/types";
|
|
5
6
|
import MagicString from "magic-string";
|
|
6
7
|
|
|
7
8
|
//#region src/plugin/register.ts
|
|
8
|
-
|
|
9
|
-
const mod = _babelTraverse;
|
|
9
|
+
function resolveBabelTraverse(mod) {
|
|
10
10
|
if (typeof mod === "function") return mod;
|
|
11
11
|
if (mod?.default && typeof mod.default === "function") return mod.default;
|
|
12
12
|
if (mod?.traverse && typeof mod.traverse === "function") return mod.traverse;
|
|
13
|
-
|
|
14
|
-
if (typeof traverseCandidate !== "function") throw new TypeError("[@weapp-vite/web] Failed to resolve @babel/traverse export.");
|
|
15
|
-
const traverse = traverseCandidate;
|
|
16
|
-
function mapRegisterIdentifier(kind) {
|
|
17
|
-
if (kind === "page") return "Page";
|
|
18
|
-
if (kind === "component") return "Component";
|
|
19
|
-
if (kind === "app") return "App";
|
|
20
|
-
return "";
|
|
13
|
+
throw new TypeError("[@weapp-vite/web] Failed to resolve @babel/traverse export.");
|
|
21
14
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (kind === "
|
|
25
|
-
if (kind === "
|
|
15
|
+
const traverse = resolveBabelTraverse(_babelTraverse);
|
|
16
|
+
function getRegisterName(kind, callee) {
|
|
17
|
+
if (kind === "page" && (callee === "Page" || callee === "Component")) return "registerPage";
|
|
18
|
+
if (kind === "component" && callee === "Component") return "registerComponent";
|
|
19
|
+
if (kind === "app" && callee === "App") return "registerApp";
|
|
26
20
|
}
|
|
27
|
-
function
|
|
28
|
-
const node = path.node;
|
|
29
|
-
const callee = node.callee;
|
|
30
|
-
if (!t.isIdentifier(callee)) return;
|
|
31
|
-
const insertPosition = node.end - 1;
|
|
21
|
+
function createRegisterMetaCode(meta, templateIdent, styleIdent, includeKind = false) {
|
|
32
22
|
const metaParts = [`id: ${JSON.stringify(meta.id)}`];
|
|
23
|
+
if (includeKind) metaParts.push(`kind: ${JSON.stringify(meta.kind)}`);
|
|
33
24
|
if (templateIdent) metaParts.push(`template: ${templateIdent}`);
|
|
34
25
|
if (styleIdent) metaParts.push(`style: ${styleIdent}`);
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
if (meta.navigationBar) metaParts.push(`navigationBar: ${JSON.stringify(meta.navigationBar)}`);
|
|
27
|
+
return `{ ${metaParts.join(", ")} }`;
|
|
28
|
+
}
|
|
29
|
+
function overwriteCall(path, meta, registerName, templateIdent, styleIdent, s, includeKind = false) {
|
|
30
|
+
const node = path.node;
|
|
31
|
+
const identifier = node.callee;
|
|
32
|
+
const insertPosition = node.end - 1;
|
|
33
|
+
const metaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, includeKind);
|
|
34
|
+
s.overwrite(identifier.start, identifier.end, registerName);
|
|
37
35
|
s.appendLeft(insertPosition, `, ${metaCode}`);
|
|
38
36
|
}
|
|
39
|
-
function transformScriptModule({ code, cleanId, meta, enableHmr }) {
|
|
40
|
-
const registerName = getRegisterName(meta.kind);
|
|
41
|
-
if (!registerName) return null;
|
|
37
|
+
function transformScriptModule({ code, cleanId, meta, enableHmr, runtimeModuleId, hmrAcceptCode }) {
|
|
42
38
|
let ast;
|
|
43
39
|
try {
|
|
44
40
|
ast = parse(code, {
|
|
@@ -51,27 +47,43 @@ function transformScriptModule({ code, cleanId, meta, enableHmr }) {
|
|
|
51
47
|
return null;
|
|
52
48
|
}
|
|
53
49
|
const s = new MagicString(code);
|
|
54
|
-
|
|
50
|
+
const wevuDefineComponentNames = /* @__PURE__ */ new Set();
|
|
51
|
+
for (const statement of ast.program.body) {
|
|
52
|
+
if (!t.isImportDeclaration(statement) || statement.source.value !== "wevu") continue;
|
|
53
|
+
for (const specifier of statement.specifiers) if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, { name: "defineComponent" })) wevuDefineComponentNames.add(specifier.local.name);
|
|
54
|
+
}
|
|
55
55
|
const imports = [];
|
|
56
|
-
const runtimePolyfillId = toViteFsImport(resolveRuntimePolyfillPath());
|
|
56
|
+
const runtimePolyfillId = runtimeModuleId ?? toViteFsImport(resolveRuntimePolyfillPath());
|
|
57
57
|
const templateIdent = meta.templatePath ? "__weapp_template__" : void 0;
|
|
58
58
|
const styleIdent = meta.stylePath ? "__weapp_style__" : void 0;
|
|
59
|
-
if (meta.templatePath && templateIdent) imports.push(`import ${templateIdent} from '${toRelativeImport(cleanId, meta.templatePath)}'`);
|
|
60
|
-
if (meta.stylePath && styleIdent)
|
|
59
|
+
if (meta.templatePath && templateIdent) imports.push(`import ${templateIdent} from '${appendQuery(toRelativeImport(cleanId, meta.templatePath), TEMPLATE_QUERY)}'`);
|
|
60
|
+
if (meta.stylePath && styleIdent) {
|
|
61
|
+
const styleQuery = meta.stylePath.endsWith(".wxss") ? STYLE_QUERY : "inline";
|
|
62
|
+
imports.push(`import ${styleIdent} from '${appendQuery(toRelativeImport(cleanId, meta.stylePath), styleQuery)}'`);
|
|
63
|
+
}
|
|
61
64
|
const registerImports = /* @__PURE__ */ new Set();
|
|
62
65
|
traverse(ast, { CallExpression(path) {
|
|
63
66
|
if (!t.isIdentifier(path.node.callee)) return;
|
|
64
|
-
|
|
67
|
+
const name = path.node.callee.name;
|
|
68
|
+
if (wevuDefineComponentNames.has(name) && meta.kind !== "app") {
|
|
69
|
+
registerImports.add("registerWebWevuComponent");
|
|
70
|
+
overwriteCall(path, meta, "registerWebWevuComponent", templateIdent, styleIdent, s, true);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const registerName = getRegisterName(meta.kind, name);
|
|
74
|
+
if (registerName) {
|
|
65
75
|
registerImports.add(registerName);
|
|
66
76
|
overwriteCall(path, meta, registerName, templateIdent, styleIdent, s);
|
|
67
|
-
transformed = true;
|
|
68
77
|
}
|
|
69
78
|
} });
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
79
|
+
registerImports.add("installWebModuleRegistration");
|
|
80
|
+
imports.unshift(`import { ${Array.from(registerImports).join(", ")} } from '${runtimePolyfillId}'`);
|
|
81
|
+
const moduleMetaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, true);
|
|
82
|
+
const restoreIdent = "__weapp_web_restore_registration__";
|
|
83
|
+
const prefix = `${imports.join("\n")}\nconst ${restoreIdent} = installWebModuleRegistration(${moduleMetaCode})\n`;
|
|
73
84
|
s.prepend(prefix);
|
|
74
|
-
|
|
85
|
+
s.append(`\n${restoreIdent}()\n`);
|
|
86
|
+
if (enableHmr && hmrAcceptCode) s.append(`\n${hmrAcceptCode}\n`);
|
|
75
87
|
return {
|
|
76
88
|
code: s.toString(),
|
|
77
89
|
map: s.generateMap({ hires: true })
|
|
@@ -79,5 +91,5 @@ function transformScriptModule({ code, cleanId, meta, enableHmr }) {
|
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
//#endregion
|
|
82
|
-
export { transformScriptModule };
|
|
94
|
+
export { resolveBabelTraverse, transformScriptModule };
|
|
83
95
|
//# sourceMappingURL=register.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.mjs","names":[],"sources":["../../src/plugin/register.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { SourceMap } from 'magic-string'\n\nimport type { ModuleMeta } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport MagicString from 'magic-string'\nimport {
|
|
1
|
+
{"version":3,"file":"register.mjs","names":[],"sources":["../../src/plugin/register.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { SourceMap } from 'magic-string'\n\nimport type { ModuleMeta } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport MagicString from 'magic-string'\nimport { STYLE_QUERY, TEMPLATE_QUERY } from './constants'\nimport { appendQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from './path'\n\ntype TraverseFunction = typeof _babelTraverse extends (...args: any[]) => any\n ? typeof _babelTraverse\n : typeof _babelTraverse extends { default: infer D }\n ? D\n : typeof _babelTraverse\n\nexport function resolveBabelTraverse(mod: any): TraverseFunction {\n if (typeof mod === 'function') {\n return mod\n }\n if (mod?.default && typeof mod.default === 'function') {\n return mod.default\n }\n if (mod?.traverse && typeof mod.traverse === 'function') {\n return mod.traverse\n }\n throw new TypeError('[@weapp-vite/web] Failed to resolve @babel/traverse export.')\n}\n\nconst traverse = resolveBabelTraverse(_babelTraverse)\n\nfunction getRegisterName(kind: ModuleMeta['kind'], callee: string) {\n if (kind === 'page' && (callee === 'Page' || callee === 'Component')) {\n return 'registerPage'\n }\n if (kind === 'component' && callee === 'Component') {\n return 'registerComponent'\n }\n if (kind === 'app' && callee === 'App') {\n return 'registerApp'\n }\n return undefined\n}\n\nfunction createRegisterMetaCode(\n meta: ModuleMeta,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n includeKind = false,\n) {\n const metaParts: string[] = [`id: ${JSON.stringify(meta.id)}`]\n if (includeKind) {\n metaParts.push(`kind: ${JSON.stringify(meta.kind)}`)\n }\n if (templateIdent) {\n metaParts.push(`template: ${templateIdent}`)\n }\n if (styleIdent) {\n metaParts.push(`style: ${styleIdent}`)\n }\n if (meta.navigationBar) {\n metaParts.push(`navigationBar: ${JSON.stringify(meta.navigationBar)}`)\n }\n return `{ ${metaParts.join(', ')} }`\n}\n\nfunction overwriteCall(\n path: NodePath<CallExpression>,\n meta: ModuleMeta,\n registerName: string,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n s: MagicString,\n includeKind = false,\n) {\n const node = path.node\n const callee = node.callee\n const identifier = callee as t.Identifier\n const end = node.end!\n const insertPosition = end - 1\n const metaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, includeKind)\n s.overwrite(identifier.start!, identifier.end!, registerName)\n s.appendLeft(insertPosition, `, ${metaCode}`)\n}\n\ninterface TransformScriptModuleOptions {\n code: string\n cleanId: string\n meta: ModuleMeta\n enableHmr: boolean\n runtimeModuleId?: string\n hmrAcceptCode?: string\n}\n\nexport function transformScriptModule({\n code,\n cleanId,\n meta,\n enableHmr,\n runtimeModuleId,\n hmrAcceptCode,\n}: TransformScriptModuleOptions): null | { code: string, map: SourceMap } {\n let ast: ReturnType<typeof parse> | undefined\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n ranges: true,\n })\n }\n catch {\n return null\n }\n\n const s = new MagicString(code)\n const wevuDefineComponentNames = new Set<string>()\n for (const statement of ast.program.body) {\n if (!t.isImportDeclaration(statement) || statement.source.value !== 'wevu') {\n continue\n }\n for (const specifier of statement.specifiers) {\n if (t.isImportSpecifier(specifier)\n && t.isIdentifier(specifier.imported, { name: 'defineComponent' })) {\n wevuDefineComponentNames.add(specifier.local.name)\n }\n }\n }\n\n const imports: string[] = []\n const runtimePolyfillId = runtimeModuleId ?? toViteFsImport(resolveRuntimePolyfillPath())\n const templateIdent = meta.templatePath ? '__weapp_template__' : undefined\n const styleIdent = meta.stylePath ? '__weapp_style__' : undefined\n\n if (meta.templatePath && templateIdent) {\n imports.push(`import ${templateIdent} from '${appendQuery(toRelativeImport(cleanId, meta.templatePath), TEMPLATE_QUERY)}'`)\n }\n\n if (meta.stylePath && styleIdent) {\n const styleQuery = meta.stylePath.endsWith('.wxss') ? STYLE_QUERY : 'inline'\n imports.push(`import ${styleIdent} from '${appendQuery(toRelativeImport(cleanId, meta.stylePath), styleQuery)}'`)\n }\n\n const registerImports = new Set<string>()\n\n traverse(ast, {\n CallExpression(path: NodePath<CallExpression>) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n const name = path.node.callee.name\n if (wevuDefineComponentNames.has(name) && meta.kind !== 'app') {\n registerImports.add('registerWebWevuComponent')\n overwriteCall(path, meta, 'registerWebWevuComponent', templateIdent, styleIdent, s, true)\n return\n }\n const registerName = getRegisterName(meta.kind, name)\n if (registerName) {\n registerImports.add(registerName)\n overwriteCall(path, meta, registerName, templateIdent, styleIdent, s)\n }\n },\n })\n\n registerImports.add('installWebModuleRegistration')\n imports.unshift(`import { ${Array.from(registerImports).join(', ')} } from '${runtimePolyfillId}'`)\n\n const moduleMetaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, true)\n const restoreIdent = '__weapp_web_restore_registration__'\n const prefix = `${imports.join('\\n')}\\nconst ${restoreIdent} = installWebModuleRegistration(${moduleMetaCode})\\n`\n s.prepend(prefix)\n\n s.append(`\\n${restoreIdent}()\\n`)\n\n if (enableHmr && hmrAcceptCode) {\n s.append(`\\n${hmrAcceptCode}\\n`)\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({\n hires: true,\n }),\n }\n}\n"],"mappings":"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"}
|
package/dist/plugin/scan.mjs
CHANGED
|
@@ -1,77 +1,135 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SCRIPT_EXTS } from "./constants.mjs";
|
|
2
|
+
import { isInsideDir, normalizePath, toPosixId } from "./path.mjs";
|
|
2
3
|
import { slugify } from "../shared/slugify.mjs";
|
|
4
|
+
import { normalizeWebTabBarConfig } from "../shared/tabBar.mjs";
|
|
3
5
|
import { isRecord, readJsonFile, resolveJsonPath, resolveScriptFile, resolveStyleFile, resolveTemplateFile } from "./files.mjs";
|
|
4
6
|
import { mergeNavigationConfig, pickNavigationConfig } from "./navigation.mjs";
|
|
5
7
|
import { collectComponentTagsFromConfig, collectComponentTagsFromJson, mergeComponentTags } from "./scanConfig.mjs";
|
|
8
|
+
import { compileScannedSfc, discoverWebPageIds } from "./scanSfc.mjs";
|
|
9
|
+
import { readdir } from "node:fs/promises";
|
|
6
10
|
import process from "node:process";
|
|
7
11
|
import { dirname, extname, join, posix, relative, resolve } from "pathe";
|
|
8
12
|
|
|
9
13
|
//#region src/plugin/scan.ts
|
|
10
|
-
|
|
14
|
+
function getStableWebComponentId(script, srcRoot) {
|
|
15
|
+
const normalized = script.replace(/\\/g, "/");
|
|
16
|
+
const nodeModulesIndex = normalized.lastIndexOf("/node_modules/");
|
|
17
|
+
const extension = extname(script);
|
|
18
|
+
if (nodeModulesIndex >= 0) return `__external__/${normalized.slice(nodeModulesIndex + 14).slice(0, -extension.length)}`;
|
|
19
|
+
return toPosixId(relative(srcRoot, script).slice(0, -extension.length));
|
|
20
|
+
}
|
|
21
|
+
function resolveComponentBase(raw, importerDir, srcRoot) {
|
|
22
|
+
if (!raw) return;
|
|
23
|
+
if (raw.startsWith(".")) return resolve(importerDir, raw);
|
|
24
|
+
if (raw.startsWith("/")) return resolve(srcRoot, raw.slice(1));
|
|
25
|
+
}
|
|
26
|
+
async function scanProject({ srcRoot, warn, state, resolveId, resolveAutoImportTag, resolveAppConfig, uniApp }) {
|
|
11
27
|
state.moduleMeta.clear();
|
|
12
28
|
state.pageNavigationMap.clear();
|
|
13
29
|
state.templateComponentMap.clear();
|
|
14
30
|
state.templatePathSet.clear();
|
|
15
31
|
state.componentTagMap.clear();
|
|
16
|
-
state.
|
|
32
|
+
state.sfcResults.clear();
|
|
17
33
|
let appNavigationDefaults = {};
|
|
18
34
|
let appComponentTags = {};
|
|
35
|
+
let appTabBar;
|
|
19
36
|
const pages = /* @__PURE__ */ new Map();
|
|
20
37
|
const components = /* @__PURE__ */ new Map();
|
|
38
|
+
const layouts = /* @__PURE__ */ new Map();
|
|
39
|
+
async function walk(current, files) {
|
|
40
|
+
const entries = await readdir(current, { withFileTypes: true });
|
|
41
|
+
for (const entry of entries) {
|
|
42
|
+
const pathname = join(current, entry.name);
|
|
43
|
+
if (entry.isDirectory()) await walk(pathname, files);
|
|
44
|
+
else files.push(pathname);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
21
47
|
const reportWarning = (message) => {
|
|
22
48
|
if (warn) {
|
|
23
49
|
warn(message);
|
|
24
50
|
return;
|
|
25
51
|
}
|
|
26
|
-
|
|
52
|
+
process.emitWarning(message);
|
|
27
53
|
};
|
|
28
54
|
const appScript = await resolveScriptFile(join(srcRoot, "app"));
|
|
29
|
-
if (appScript)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
if (appScript) {
|
|
56
|
+
const appMeta = {
|
|
57
|
+
kind: "app",
|
|
58
|
+
id: "app",
|
|
59
|
+
scriptPath: appScript,
|
|
60
|
+
stylePath: await resolveStyleFile(appScript),
|
|
61
|
+
sourceType: appScript.endsWith(".vue") ? "vue-sfc" : "native"
|
|
62
|
+
};
|
|
63
|
+
state.moduleMeta.set(normalizePath(appScript), appMeta);
|
|
64
|
+
}
|
|
35
65
|
const resolveComponentScript = async (raw, importerDir) => {
|
|
36
66
|
const base = resolveComponentBase(raw, importerDir, srcRoot);
|
|
37
|
-
if (
|
|
38
|
-
|
|
67
|
+
if (base) {
|
|
68
|
+
const resolved = await resolveScriptFile(base);
|
|
69
|
+
return resolved ? normalizePath(resolved) : void 0;
|
|
70
|
+
}
|
|
71
|
+
const importer = join(importerDir, "__weapp_web_using_components__.ts");
|
|
72
|
+
const resolved = await resolveId?.(raw, importer);
|
|
73
|
+
const script = resolved ? await resolveScriptFile(resolved) : void 0;
|
|
74
|
+
return script ? normalizePath(script) : void 0;
|
|
39
75
|
};
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
if (cached) return cached;
|
|
43
|
-
const componentIdPosix = toPosixId(relative(srcRoot, script).replace(new RegExp(`${extname(script)}$`), ""));
|
|
44
|
-
state.componentIdMap.set(script, componentIdPosix);
|
|
45
|
-
return componentIdPosix;
|
|
76
|
+
const getStableComponentId = (script) => {
|
|
77
|
+
return getStableWebComponentId(script, srcRoot);
|
|
46
78
|
};
|
|
47
79
|
const getComponentTag = (script) => {
|
|
48
80
|
const cached = state.componentTagMap.get(script);
|
|
49
81
|
if (cached) return cached;
|
|
50
|
-
const tag = slugify(
|
|
82
|
+
const tag = slugify(getStableComponentId(script), "wv-component");
|
|
51
83
|
state.componentTagMap.set(script, tag);
|
|
52
84
|
return tag;
|
|
53
85
|
};
|
|
54
86
|
const collectComponent = async (componentId, importerDir) => {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
87
|
+
const script = await resolveComponentScript(componentId, importerDir);
|
|
88
|
+
if (!script) return;
|
|
89
|
+
const existing = components.get(script);
|
|
90
|
+
if (existing) {
|
|
91
|
+
existing.importId ??= resolveComponentBase(componentId, importerDir, srcRoot) ? void 0 : componentId;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const componentIdPosix = getStableComponentId(script);
|
|
95
|
+
const importId = resolveComponentBase(componentId, importerDir, srcRoot) ? isInsideDir(script, srcRoot) ? void 0 : componentIdPosix : componentId;
|
|
59
96
|
const template = await resolveTemplateFile(script);
|
|
60
97
|
const style = await resolveStyleFile(script);
|
|
61
98
|
if (template) state.templatePathSet.add(normalizePath(template));
|
|
62
|
-
|
|
99
|
+
const componentMeta = {
|
|
63
100
|
kind: "component",
|
|
64
101
|
id: componentIdPosix,
|
|
65
102
|
scriptPath: script,
|
|
66
103
|
templatePath: template,
|
|
67
|
-
stylePath: style
|
|
68
|
-
|
|
104
|
+
stylePath: style,
|
|
105
|
+
sourceType: script.endsWith(".vue") ? "vue-sfc" : "native"
|
|
106
|
+
};
|
|
107
|
+
state.moduleMeta.set(normalizePath(script), componentMeta);
|
|
69
108
|
components.set(script, {
|
|
70
109
|
script,
|
|
71
|
-
id: componentIdPosix
|
|
110
|
+
id: componentIdPosix,
|
|
111
|
+
importId
|
|
72
112
|
});
|
|
73
|
-
const
|
|
74
|
-
|
|
113
|
+
const componentJsonBasePath = `${script.replace(new RegExp(`${extname(script)}$`), "")}.json`;
|
|
114
|
+
const sfcConfig = script.endsWith(".vue") ? (await compileScannedSfc({
|
|
115
|
+
filename: script,
|
|
116
|
+
meta: componentMeta,
|
|
117
|
+
srcRoot,
|
|
118
|
+
state,
|
|
119
|
+
resolveId,
|
|
120
|
+
resolveAutoImportTag,
|
|
121
|
+
uniApp
|
|
122
|
+
})).config : void 0;
|
|
123
|
+
const componentTags = sfcConfig ? await collectComponentTagsFromConfig({
|
|
124
|
+
json: sfcConfig,
|
|
125
|
+
importerDir: dirname(script),
|
|
126
|
+
jsonPath: script,
|
|
127
|
+
warn: reportWarning,
|
|
128
|
+
resolveComponentScript,
|
|
129
|
+
getComponentTag,
|
|
130
|
+
collectComponent
|
|
131
|
+
}) : await collectComponentTagsFromJson({
|
|
132
|
+
jsonBasePath: componentJsonBasePath,
|
|
75
133
|
importerDir: dirname(script),
|
|
76
134
|
warn: reportWarning,
|
|
77
135
|
collectFromConfig: (json, nextImporterDir, jsonPath, nextWarn) => collectComponentTagsFromConfig({
|
|
@@ -84,6 +142,7 @@ async function scanProject({ srcRoot, warn, state }) {
|
|
|
84
142
|
collectComponent
|
|
85
143
|
})
|
|
86
144
|
});
|
|
145
|
+
componentMeta.componentTags = mergeComponentTags(appComponentTags, componentTags);
|
|
87
146
|
if (!template) return;
|
|
88
147
|
const mergedTags = mergeComponentTags(appComponentTags, componentTags);
|
|
89
148
|
if (Object.keys(mergedTags).length > 0) {
|
|
@@ -92,41 +151,6 @@ async function scanProject({ srcRoot, warn, state }) {
|
|
|
92
151
|
}
|
|
93
152
|
state.templateComponentMap.delete(normalizePath(template));
|
|
94
153
|
};
|
|
95
|
-
const appJsonPath = await resolveJsonPath(join(srcRoot, "app.json"));
|
|
96
|
-
if (appJsonPath) {
|
|
97
|
-
const appJson = await readJsonFile(appJsonPath);
|
|
98
|
-
if (appJson) appComponentTags = await collectComponentTagsFromConfig({
|
|
99
|
-
json: appJson,
|
|
100
|
-
importerDir: srcRoot,
|
|
101
|
-
jsonPath: appJsonPath,
|
|
102
|
-
warn: reportWarning,
|
|
103
|
-
resolveComponentScript,
|
|
104
|
-
getComponentTag,
|
|
105
|
-
collectComponent,
|
|
106
|
-
onResolved: (tags) => {
|
|
107
|
-
appComponentTags = tags;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
if (appJson?.pages && Array.isArray(appJson.pages)) {
|
|
111
|
-
for (const page of appJson.pages) if (typeof page === "string") await collectPage(page);
|
|
112
|
-
}
|
|
113
|
-
if (appJson?.subPackages && Array.isArray(appJson.subPackages)) for (const pkg of appJson.subPackages) {
|
|
114
|
-
if (!pkg || typeof pkg !== "object" || !Array.isArray(pkg.pages)) continue;
|
|
115
|
-
const root = typeof pkg.root === "string" ? pkg.root : "";
|
|
116
|
-
for (const page of pkg.pages) {
|
|
117
|
-
if (typeof page !== "string") continue;
|
|
118
|
-
await collectPage(posix.join(root, page));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
appNavigationDefaults = pickNavigationConfig(isRecord(appJson?.window) ? appJson.window : void 0);
|
|
122
|
-
}
|
|
123
|
-
state.appNavigationDefaults = appNavigationDefaults;
|
|
124
|
-
state.appComponentTags = appComponentTags;
|
|
125
|
-
state.scanResult = {
|
|
126
|
-
app: appScript,
|
|
127
|
-
pages: Array.from(pages.values()),
|
|
128
|
-
components: Array.from(components.values())
|
|
129
|
-
};
|
|
130
154
|
async function collectPage(pageId) {
|
|
131
155
|
const base = join(srcRoot, pageId);
|
|
132
156
|
const script = await resolveScriptFile(base);
|
|
@@ -134,62 +158,150 @@ async function scanProject({ srcRoot, warn, state }) {
|
|
|
134
158
|
const template = await resolveTemplateFile(base);
|
|
135
159
|
if (template) state.templatePathSet.add(normalizePath(template));
|
|
136
160
|
const style = await resolveStyleFile(base);
|
|
137
|
-
const
|
|
138
|
-
const pageJsonPath = await resolveJsonPath(pageJsonBasePath);
|
|
161
|
+
const pageJsonPath = await resolveJsonPath(join(srcRoot, `${pageId}.json`));
|
|
139
162
|
const pageJson = pageJsonPath ? await readJsonFile(pageJsonPath) : void 0;
|
|
140
|
-
|
|
163
|
+
const pageMeta = {
|
|
141
164
|
kind: "page",
|
|
142
165
|
id: toPosixId(pageId),
|
|
143
166
|
scriptPath: script,
|
|
144
167
|
templatePath: template,
|
|
145
|
-
stylePath: style
|
|
146
|
-
|
|
168
|
+
stylePath: style,
|
|
169
|
+
sourceType: script.endsWith(".vue") ? "vue-sfc" : "native"
|
|
170
|
+
};
|
|
171
|
+
const sfcConfig = script.endsWith(".vue") ? (await compileScannedSfc({
|
|
172
|
+
filename: script,
|
|
173
|
+
meta: pageMeta,
|
|
174
|
+
srcRoot,
|
|
175
|
+
state,
|
|
176
|
+
resolveId,
|
|
177
|
+
resolveAutoImportTag,
|
|
178
|
+
uniApp
|
|
179
|
+
})).config : void 0;
|
|
180
|
+
const resolvedNavigationConfig = mergeNavigationConfig(appNavigationDefaults, sfcConfig ? pickNavigationConfig(sfcConfig) : pageJson ? pickNavigationConfig(pageJson) : {});
|
|
181
|
+
pageMeta.navigationBar = Object.keys(resolvedNavigationConfig).length > 0 ? resolvedNavigationConfig : void 0;
|
|
182
|
+
state.moduleMeta.set(normalizePath(script), pageMeta);
|
|
147
183
|
pages.set(script, {
|
|
148
184
|
script,
|
|
149
185
|
id: toPosixId(pageId)
|
|
150
186
|
});
|
|
151
|
-
const pageComponentTags =
|
|
152
|
-
json:
|
|
187
|
+
const pageComponentTags = sfcConfig ? await collectComponentTagsFromConfig({
|
|
188
|
+
json: sfcConfig,
|
|
153
189
|
importerDir: dirname(script),
|
|
154
|
-
jsonPath:
|
|
190
|
+
jsonPath: script,
|
|
155
191
|
warn: reportWarning,
|
|
156
192
|
resolveComponentScript,
|
|
157
193
|
getComponentTag,
|
|
158
194
|
collectComponent
|
|
159
|
-
}) : await
|
|
160
|
-
|
|
195
|
+
}) : pageJson && pageJsonPath ? await collectComponentTagsFromConfig({
|
|
196
|
+
json: pageJson,
|
|
161
197
|
importerDir: dirname(script),
|
|
198
|
+
jsonPath: pageJsonPath,
|
|
162
199
|
warn: reportWarning,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
warn: nextWarn,
|
|
168
|
-
resolveComponentScript,
|
|
169
|
-
getComponentTag,
|
|
170
|
-
collectComponent
|
|
171
|
-
})
|
|
172
|
-
});
|
|
200
|
+
resolveComponentScript,
|
|
201
|
+
getComponentTag,
|
|
202
|
+
collectComponent
|
|
203
|
+
}) : {};
|
|
173
204
|
if (template) {
|
|
174
205
|
const mergedTags = mergeComponentTags(appComponentTags, pageComponentTags);
|
|
175
206
|
if (Object.keys(mergedTags).length > 0) state.templateComponentMap.set(normalizePath(template), mergedTags);
|
|
176
207
|
else state.templateComponentMap.delete(normalizePath(template));
|
|
177
208
|
}
|
|
209
|
+
pageMeta.componentTags = mergeComponentTags(appComponentTags, pageComponentTags);
|
|
178
210
|
if (!template) return;
|
|
179
|
-
|
|
180
|
-
|
|
211
|
+
state.pageNavigationMap.set(normalizePath(template), resolvedNavigationConfig);
|
|
212
|
+
}
|
|
213
|
+
async function collectLayouts() {
|
|
214
|
+
const layoutsRoot = join(srcRoot, "layouts");
|
|
215
|
+
const files = [];
|
|
216
|
+
try {
|
|
217
|
+
await walk(layoutsRoot, files);
|
|
218
|
+
} catch {
|
|
181
219
|
return;
|
|
182
220
|
}
|
|
183
|
-
|
|
221
|
+
for (const filename of files.sort()) {
|
|
222
|
+
const script = SCRIPT_EXTS.includes(extname(filename)) ? filename : void 0;
|
|
223
|
+
if (!script) continue;
|
|
224
|
+
const segments = relative(layoutsRoot, script).replace(/\\/g, "/").split("/");
|
|
225
|
+
segments.pop();
|
|
226
|
+
if (segments[segments.length - 1] === "index") segments.pop();
|
|
227
|
+
const name = segments.join("/");
|
|
228
|
+
if (!name) continue;
|
|
229
|
+
const id = `layouts/${name}`;
|
|
230
|
+
const template = await resolveTemplateFile(script);
|
|
231
|
+
const style = await resolveStyleFile(script);
|
|
232
|
+
const tag = slugify(id, "wv-component");
|
|
233
|
+
state.moduleMeta.set(normalizePath(script), {
|
|
234
|
+
kind: "component",
|
|
235
|
+
id,
|
|
236
|
+
scriptPath: script,
|
|
237
|
+
templatePath: template,
|
|
238
|
+
stylePath: style,
|
|
239
|
+
sourceType: "native"
|
|
240
|
+
});
|
|
241
|
+
layouts.set(script, {
|
|
242
|
+
script,
|
|
243
|
+
id,
|
|
244
|
+
name,
|
|
245
|
+
tag,
|
|
246
|
+
template,
|
|
247
|
+
style
|
|
248
|
+
});
|
|
249
|
+
if (template) state.templatePathSet.add(normalizePath(template));
|
|
250
|
+
}
|
|
184
251
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
252
|
+
const appJsonPath = await resolveJsonPath(join(srcRoot, "app.json"));
|
|
253
|
+
let appJson = appJsonPath ? await (resolveAppConfig ? resolveAppConfig(appJsonPath) : readJsonFile(appJsonPath)) : void 0;
|
|
254
|
+
if (appScript?.endsWith(".vue")) appJson = {
|
|
255
|
+
...(await compileScannedSfc({
|
|
256
|
+
filename: appScript,
|
|
257
|
+
meta: state.moduleMeta.get(normalizePath(appScript)),
|
|
258
|
+
srcRoot,
|
|
259
|
+
state,
|
|
260
|
+
resolveId,
|
|
261
|
+
resolveAutoImportTag,
|
|
262
|
+
uniApp
|
|
263
|
+
})).config ?? {},
|
|
264
|
+
...appJson ?? {}
|
|
265
|
+
};
|
|
266
|
+
if (appJson) {
|
|
267
|
+
appComponentTags = await collectComponentTagsFromConfig({
|
|
268
|
+
json: appJson,
|
|
269
|
+
importerDir: srcRoot,
|
|
270
|
+
jsonPath: appJsonPath ?? appScript,
|
|
271
|
+
warn: reportWarning,
|
|
272
|
+
resolveComponentScript,
|
|
273
|
+
getComponentTag,
|
|
274
|
+
collectComponent,
|
|
275
|
+
onResolved: (tags) => {
|
|
276
|
+
appComponentTags = tags;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
appNavigationDefaults = pickNavigationConfig(isRecord(appJson?.window) ? appJson.window : void 0);
|
|
280
|
+
const configuredPages = Array.isArray(appJson.pages) ? appJson.pages.filter((page) => typeof page === "string") : [];
|
|
281
|
+
for (const page of configuredPages.length > 0 ? configuredPages : await discoverWebPageIds(srcRoot)) await collectPage(page);
|
|
282
|
+
const subPackages = Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : [];
|
|
283
|
+
if (subPackages.length > 0) for (const pkg of subPackages) {
|
|
284
|
+
if (!pkg || typeof pkg !== "object" || !Array.isArray(pkg.pages)) continue;
|
|
285
|
+
const root = typeof pkg.root === "string" ? pkg.root : "";
|
|
286
|
+
for (const page of pkg.pages) {
|
|
287
|
+
if (typeof page !== "string") continue;
|
|
288
|
+
await collectPage(posix.join(root, page));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
appTabBar = normalizeWebTabBarConfig(appJson?.tabBar);
|
|
292
|
+
} else for (const page of await discoverWebPageIds(srcRoot)) await collectPage(page);
|
|
293
|
+
await collectLayouts();
|
|
294
|
+
state.appNavigationDefaults = appNavigationDefaults;
|
|
295
|
+
state.appComponentTags = appComponentTags;
|
|
296
|
+
state.scanResult = {
|
|
297
|
+
app: appScript,
|
|
298
|
+
pages: Array.from(pages.values()),
|
|
299
|
+
components: Array.from(components.values()),
|
|
300
|
+
layouts: Array.from(layouts.values()),
|
|
301
|
+
tabBar: appTabBar
|
|
302
|
+
};
|
|
191
303
|
}
|
|
192
304
|
|
|
193
305
|
//#endregion
|
|
194
|
-
export { scanProject };
|
|
306
|
+
export { getStableWebComponentId, scanProject };
|
|
195
307
|
//# sourceMappingURL=scan.mjs.map
|