Skip to content

Commit

Permalink
wip: uni_modules编译模式
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed May 11, 2024
1 parent e284390 commit b029435
Show file tree
Hide file tree
Showing 9 changed files with 8,325 additions and 135 deletions.
Expand Up @@ -15,6 +15,9 @@ exports[`uni_modules playground uni-app-x build:app-android 1`] = `
"components": [
"text",
"image"
],
"modules": [
"uni-getSystemInfo"
]
}
}
Expand All @@ -34,6 +37,9 @@ exports[`uni_modules playground uni-app-x build:app-android 2`] = `
"components": [
"text",
"video"
],
"modules": [
"uni-video"
]
}
}
Expand Down Expand Up @@ -674,7 +680,11 @@ exports[`uni_modules playground uni-app-x dev:app-android 1`] = `
"uni.getSystemInfo",
"uniCloud.importObject"
],
"components": []
"components": [],
"modules": [
"uni-getSystemInfo",
"uni-cloud-client"
]
}
}
}"
Expand All @@ -692,7 +702,10 @@ exports[`uni_modules playground uni-app-x dev:app-android 2`] = `
"apis": [
"uniCloud.importObject"
],
"components": []
"components": [],
"modules": [
"uni-cloud-client"
]
}
}
}"
Expand Down
230 changes: 115 additions & 115 deletions packages/uni-app/dist/uni-app.d.ts
@@ -1,115 +1,115 @@
/// <reference types="@dcloudio/types" />

import { capitalize } from '@vue/shared';
import type { ComponentInternalInstance } from 'vue';
import { extend } from '@vue/shared';
import { hasOwn } from '@vue/shared';
import { isPlainObject } from '@vue/shared';
import { ref } from 'vue';
import { shallowRef } from 'vue';
import type { Slots } from 'vue';

export { capitalize }

export { extend }

export declare function formatAppLog(type: 'log' | 'info' | 'debug' | 'warn' | 'error', filename: string, ...args: unknown[]): void;

export declare function formatH5Log(type: keyof Console, filename: string, ...args: unknown[]): void;

/**
* uni 对象是跨实例的,而此处列的 API 均是需要跟当前实例关联的,比如 requireNativePlugin 获取 dom 时,依赖当前 weex 实例
*/
/// <reference types="@dcloudio/types" />
export declare function getCurrentSubNVue(): UniApp.SubNVue;

export declare function getSsrGlobalData(): any;

export { hasOwn }

export { isPlainObject }

declare interface NavigationBarSearchInputFocusChanged {
focus: boolean;
}

export declare const onAddToFavorites: (hook: (options: Page.AddToFavoritesOption) => Page.CustomFavoritesContent, target?: ComponentInternalInstance | null) => void;

export declare const onBackPress: (hook: (options: Page.BackPressOption) => any, target?: ComponentInternalInstance | null) => void;

export declare const onError: (hook: (error: string) => void, target?: ComponentInternalInstance | null) => void;

export declare const onExit: (hook: () => void, target?: ComponentInternalInstance | null) => void;

export declare const onHide: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onInit: (hook: (query?: AnyObject | undefined) => void, target?: ComponentInternalInstance | null) => void;

export declare const onLaunch: (hook: (options?: App.LaunchShowOption | undefined) => void, target?: ComponentInternalInstance | null) => void;

export declare const onLoad: (hook: (query?: AnyObject | undefined) => void, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarButtonTap: (hook: (options: Page.NavigationBarButtonTapOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarSearchInputChanged: (hook: (event: Page.NavigationBarSearchInputEvent) => void, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarSearchInputClicked: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarSearchInputConfirmed: (hook: (event: Page.NavigationBarSearchInputEvent) => void, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarSearchInputFocusChanged: (hook: onNavigationBarSearchInputFocusChangedHook, target?: ComponentInternalInstance | null) => void;

declare type onNavigationBarSearchInputFocusChangedHook = (options: NavigationBarSearchInputFocusChanged) => void;

export declare const onPageHide: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onPageNotFound: (hook: (options: App.PageNotFoundOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onPageScroll: (hook: (options: Page.PageScrollOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onPageShow: (hook: ((options?: App.LaunchShowOption | undefined) => void) | (() => void), target?: ComponentInternalInstance | null) => void;

export declare const onPullDownRefresh: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onReachBottom: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onReady: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onResize: (hook: (options: Page.ResizeOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onSaveExitState: (hook: onSaveExitStateHook, target?: ComponentInternalInstance | null) => void;

declare type onSaveExitStateHook = () => SaveExitState;

export declare const onShareAppMessage: (hook: (options: Page.ShareAppMessageOption) => Page.CustomShareContent | Promise<Omit<Page.CustomShareContent, "promise">>, target?: ComponentInternalInstance | null) => void;

export declare const onShareTimeline: (hook: () => Page.ShareTimelineContent, target?: ComponentInternalInstance | null) => void;

export declare const onShow: (hook: ((options?: App.LaunchShowOption | undefined) => void) | (() => void), target?: ComponentInternalInstance | null) => void;

export declare const onTabItemTap: (hook: (options: Page.TabItemTapOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onThemeChange: (hook: (options: UniApp.OnThemeChangeCallbackResult) => void, target?: ComponentInternalInstance | null) => void;

export declare const onUnhandledRejection: (hook: (options: UniApp.OnUnhandledRejectionCallbackResult) => void, target?: ComponentInternalInstance | null) => void;

export declare const onUnload: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare function renderComponentSlot(slots: Slots, name: string, props?: any | null): any | null;

export declare function requireNativePlugin(name: string): any;

export declare function resolveEasycom(component: unknown, easycom: unknown): unknown;

declare interface SaveExitState {
data: any;
expireTimeStamp: number;
}

export declare const shallowSsrRef: SSRRef;

declare type SSRRef = (value: unknown, key?: string, shallow?: boolean) => ReturnType<typeof ref> | ReturnType<typeof shallowRef>;

export declare const ssrRef: SSRRef;

export { }
/// <reference types="@dcloudio/types" />

import { capitalize } from '@vue/shared';
import type { ComponentInternalInstance } from 'vue';
import { extend } from '@vue/shared';
import { hasOwn } from '@vue/shared';
import { isPlainObject } from '@vue/shared';
import { ref } from 'vue';
import { shallowRef } from 'vue';
import type { Slots } from 'vue';

export { capitalize }

export { extend }

export declare function formatAppLog(type: 'log' | 'info' | 'debug' | 'warn' | 'error', filename: string, ...args: unknown[]): void;

export declare function formatH5Log(type: keyof Console, filename: string, ...args: unknown[]): void;

/**
* uni 对象是跨实例的,而此处列的 API 均是需要跟当前实例关联的,比如 requireNativePlugin 获取 dom 时,依赖当前 weex 实例
*/
/// <reference types="@dcloudio/types" />
export declare function getCurrentSubNVue(): UniApp.SubNVue;

export declare function getSsrGlobalData(): any;

export { hasOwn }

export { isPlainObject }

declare interface NavigationBarSearchInputFocusChanged {
focus: boolean;
}

export declare const onAddToFavorites: (hook: (options: Page.AddToFavoritesOption) => Page.CustomFavoritesContent, target?: ComponentInternalInstance | null) => void;

export declare const onBackPress: (hook: (options: Page.BackPressOption) => any, target?: ComponentInternalInstance | null) => void;

export declare const onError: (hook: (error: string) => void, target?: ComponentInternalInstance | null) => void;

export declare const onExit: (hook: () => void, target?: ComponentInternalInstance | null) => void;

export declare const onHide: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onInit: (hook: (query?: AnyObject | undefined) => void, target?: ComponentInternalInstance | null) => void;

export declare const onLaunch: (hook: (options?: App.LaunchShowOption | undefined) => void, target?: ComponentInternalInstance | null) => void;

export declare const onLoad: (hook: (query?: AnyObject | undefined) => void, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarButtonTap: (hook: (options: Page.NavigationBarButtonTapOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarSearchInputChanged: (hook: (event: Page.NavigationBarSearchInputEvent) => void, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarSearchInputClicked: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarSearchInputConfirmed: (hook: (event: Page.NavigationBarSearchInputEvent) => void, target?: ComponentInternalInstance | null) => void;

export declare const onNavigationBarSearchInputFocusChanged: (hook: onNavigationBarSearchInputFocusChangedHook, target?: ComponentInternalInstance | null) => void;

declare type onNavigationBarSearchInputFocusChangedHook = (options: NavigationBarSearchInputFocusChanged) => void;

export declare const onPageHide: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onPageNotFound: (hook: (options: App.PageNotFoundOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onPageScroll: (hook: (options: Page.PageScrollOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onPageShow: (hook: ((options?: App.LaunchShowOption | undefined) => void) | (() => void), target?: ComponentInternalInstance | null) => void;

export declare const onPullDownRefresh: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onReachBottom: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onReady: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare const onResize: (hook: (options: Page.ResizeOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onSaveExitState: (hook: onSaveExitStateHook, target?: ComponentInternalInstance | null) => void;

declare type onSaveExitStateHook = () => SaveExitState;

export declare const onShareAppMessage: (hook: (options: Page.ShareAppMessageOption) => Page.CustomShareContent | Promise<Omit<Page.CustomShareContent, "promise">>, target?: ComponentInternalInstance | null) => void;

export declare const onShareTimeline: (hook: () => Page.ShareTimelineContent, target?: ComponentInternalInstance | null) => void;

export declare const onShow: (hook: ((options?: App.LaunchShowOption | undefined) => void) | (() => void), target?: ComponentInternalInstance | null) => void;

export declare const onTabItemTap: (hook: (options: Page.TabItemTapOption) => void, target?: ComponentInternalInstance | null) => void;

export declare const onThemeChange: (hook: (options: UniApp.OnThemeChangeCallbackResult) => void, target?: ComponentInternalInstance | null) => void;

export declare const onUnhandledRejection: (hook: (options: UniApp.OnUnhandledRejectionCallbackResult) => void, target?: ComponentInternalInstance | null) => void;

export declare const onUnload: (hook: () => any, target?: ComponentInternalInstance | null) => void;

export declare function renderComponentSlot(slots: Slots, name: string, props?: any | null): any | null;

export declare function requireNativePlugin(name: string): any;

export declare function resolveEasycom(component: unknown, easycom: unknown): unknown;

declare interface SaveExitState {
data: any;
expireTimeStamp: number;
}

export declare const shallowSsrRef: SSRRef;

declare type SSRRef = (value: unknown, key?: string, shallow?: boolean) => ReturnType<typeof ref> | ReturnType<typeof shallowRef>;

export declare const ssrRef: SSRRef;

export { }
11 changes: 9 additions & 2 deletions packages/uni-cli-shared/src/uni_modules.ts
Expand Up @@ -624,13 +624,20 @@ function findLastIndex<T>(

let encryptUniModules: ReturnType<typeof findEncryptUniModules> = {}

export function resolveEncryptUniModule(id: string) {
export function resolveEncryptUniModule(
id: string,
platform: typeof process.env.UNI_UTS_PLATFORM,
isX: boolean = true
) {
const parts = id.split('/')
const index = findLastIndex(parts, (part) => part === 'uni_modules')
if (index !== -1) {
const uniModuleId = parts[index + 1]
if (uniModuleId in encryptUniModules) {
return `@/uni_modules/${uniModuleId}?uni_helpers`
// 原生平台走旧的uts-proxy
return `@/uni_modules/${uniModuleId}?${
isX && platform === 'app-android' ? 'uts-proxy' : 'uni_helpers'
}`
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions packages/uni-cli-shared/src/vite/cloud.ts
Expand Up @@ -118,6 +118,13 @@ export function uniEncryptUniModulesPlugin(): Plugin {
uni_modules: [],
})
if (result) {
const apis = result.inject_apis
const components = getUniModulesExtApiComponents(uniModule)
const modules = resolveUTSCompiler().parseInjectModules(
apis,
{},
components
)
fs.writeFileSync(
path.resolve(
process.env.UNI_OUTPUT_DIR,
Expand All @@ -127,8 +134,9 @@ export function uniEncryptUniModulesPlugin(): Plugin {
),
genUniModulesPackageJson(uniModule, tempOutputDir, {
env: initCheckEnv(),
apis: result.inject_apis,
components: getUniModulesExtApiComponents(uniModule),
apis,
components,
modules,
})
)
}
Expand Down
34 changes: 22 additions & 12 deletions packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
Expand Up @@ -114,28 +114,38 @@ export function uniUTSUniModulesPlugin(
}
}

const isX = process.env.UNI_APP_X === 'true'

return {
name: 'uni:uts-uni_modules',
apply: 'build',
enforce: 'pre',
async configResolved() {
const manifest = parseManifestJsonOnce(inputDir)
await checkEncryptUniModules(inputDir, {
mode:
process.env.NODE_ENV !== 'development' ? 'production' : 'development',
compilerVersion: process.env.UNI_COMPILER_VERSION,
appid: manifest.appid,
appname: manifest.name,
platform: process.env.UNI_UTS_PLATFORM,
'uni-app-x': process.env.UNI_APP_X === 'true',
})
if (isX) {
const manifest = parseManifestJsonOnce(inputDir)
await checkEncryptUniModules(inputDir, {
mode:
process.env.NODE_ENV !== 'development'
? 'production'
: 'development',
compilerVersion: process.env.UNI_COMPILER_VERSION,
appid: manifest.appid,
appname: manifest.name,
platform: process.env.UNI_UTS_PLATFORM,
'uni-app-x': isX,
})
}
},
resolveId(id, importer) {
if (isUTSProxy(id) || isUniHelpers(id)) {
return id
}
if (process.env.UNI_COMPILE_TARGET !== 'uni_modules') {
const resolvedId = resolveEncryptUniModule(id)
if (isX && process.env.UNI_COMPILE_TARGET !== 'uni_modules') {
const resolvedId = resolveEncryptUniModule(
id,
process.env.UNI_UTS_PLATFORM,
process.env.UNI_APP_X === 'true'
)
if (resolvedId) {
return resolvedId
}
Expand Down

0 comments on commit b029435

Please sign in to comment.