提交 9aaf1bd2 编写于 作者: fxy060608's avatar fxy060608

wip: uni_modules编译模式

上级 a4ab2875
......@@ -3,7 +3,7 @@ import path from 'path'
import fs from 'fs-extra'
import { sync } from 'fast-glob'
import type { UTSTargetLanguage } from './uts'
import { normalizePath } from './utils'
import { normalizePath, requireUniHelpers } from './utils'
import { genUTSComponentPublicInstanceIdent } from './easycom'
import { M } from './messages'
......@@ -720,14 +720,15 @@ export async function checkEncryptUniModules(
)
if (zipFile) {
const downloadFile = path.resolve(cacheDir, 'uni_modules.download.zip')
const { C, D, R, U } = require(path.join(
process.env.UNI_HBUILDERX_PLUGINS,
'uni_helpers'
))
const { C, D, R, U } = requireUniHelpers()
try {
const isLogin = await C()
const tips =
process.env.UNI_UTS_PLATFORM !== 'app-android'
? '(此过程耗时较长)'
: ''
console.log(
`正在云编译插件${isLogin ? '' : '(请先登录)'}${modules.join(
`正在云编译插件${isLogin ? '' : '(请先登录)'}${tips}${modules.join(
','
)}...`
)
......@@ -769,10 +770,7 @@ export async function checkEncryptUniModules(
} else {
// android 平台需要在这里初始化
if (params.platform === 'app-android') {
const { R } = require(path.join(
process.env.UNI_HBUILDERX_PLUGINS,
'uni_helpers'
))
const { R } = requireUniHelpers()
R({
dir: process.env.UNI_INPUT_DIR,
cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR,
......
......@@ -211,3 +211,11 @@ export function enableSourceMap() {
process.env.UNI_COMPILE_TARGET !== 'uni_modules'
)
}
export function requireUniHelpers() {
require(path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'uni_helpers/lib/bytenode'
))
return require(path.join(process.env.UNI_HBUILDERX_PLUGINS, 'uni_helpers'))
}
......@@ -11,11 +11,12 @@ import {
resolveDexFile,
resolveJarPath,
} from './kotlin'
import { getCompilerServer } from './utils'
import { getCompilerServer, requireUniHelpers } from './utils'
import { restoreDex } from './manifest'
import { sync } from 'fast-glob'
import { resolveDexCacheFile } from './manifest/dex'
import type { CompileResult } from './index'
import { hbuilderFormatter } from './stacktrace/kotlin'
export function isEncrypt(pluginDir: string) {
return fs.existsSync(path.resolve(pluginDir, 'encrypt'))
......@@ -195,10 +196,7 @@ async function compileEncryptByUniHelpers(pluginDir: string) {
}
// development
if (process.env.UNI_HBUILDERX_PLUGINS) {
const { DUM } = require(path.join(
process.env.UNI_HBUILDERX_PLUGINS,
'uni_helpers'
))
const { DUM } = requireUniHelpers()
const ktFiles: Record<string, string> = sync('**/*.kt', {
absolute: false,
......@@ -242,7 +240,21 @@ async function compileEncryptByUniHelpers(pluginDir: string) {
jarFile,
'',
depJars,
createStderrListener(outputDir, resolveSourceMapPath(), waiting)
createStderrListener(outputDir, resolveSourceMapPath(), waiting, (m) => {
if (m.file) {
const file = normalizePath(m.file)
if (file.startsWith(outputPluginDir)) {
// 过滤部分插件的非错误信息
if (m.type !== 'error') {
return ''
} else {
// 移除完整路径
m.file = pluginDir
}
}
}
return hbuilderFormatter(m)
})
)
// 等待 stderrListener 执行完毕
if (waiting.done) {
......
......@@ -363,7 +363,12 @@ export async function runKotlinDev(
jarFile,
resolveSourceMapFile(outputDir, kotlinFile),
extraJars.concat(depJars),
createStderrListener(outputDir, resolveSourceMapPath(), waiting)
createStderrListener(
outputDir,
resolveSourceMapPath(),
waiting,
hbuilderFormatter
)
)
// 等待 stderrListener 执行完毕
......@@ -829,7 +834,8 @@ function createPluginGlob(plugins?: string[]) {
export function createStderrListener(
inputDir: string,
sourceMapDir: string,
waiting: { done: Promise<void> | undefined }
waiting: { done: Promise<void> | undefined },
format: (msg: MessageSourceLocation) => string
) {
return async function stderrListener(data: any) {
waiting.done = new Promise(async (resolve) => {
......@@ -855,7 +861,7 @@ export function createStderrListener(
inputDir,
sourceMapDir,
replaceTabsWithSpace: true,
format: hbuilderFormatter,
format,
})
if (msg) {
// 异步输出,保证插件编译失败的日志在他之前输出,不能使用process.nextTick
......
......@@ -788,3 +788,11 @@ function formatExtApiProviderName(service: string, name: string) {
camelize(name)
)}Provider`
}
export function requireUniHelpers() {
require(path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'uni_helpers/lib/bytenode'
))
return require(path.join(process.env.UNI_HBUILDERX_PLUGINS, 'uni_helpers'))
}
......@@ -33,7 +33,10 @@ import {
resolveUniAppXSourceMapPath,
shouldAutoImportUniCloud,
} from '../utils'
import type { KotlinManifestCache } from '../stacktrace/kotlin'
import {
type KotlinManifestCache,
hbuilderFormatter,
} from '../stacktrace/kotlin'
import { isWindows } from '../shared'
const DEFAULT_IMPORTS = [
......@@ -353,7 +356,8 @@ async function runKotlinDev(
const cacheDir = process.env.HX_DEPENDENCIES_DIR || ''
const kotlinClassOutDir = kotlinClassDir(kotlinRootOutDir)
const waiting = { done: undefined }
const options = {
const compileOptions = {
version: 'v2',
pageCount,
kotlinc: resolveKotlincArgs(
......@@ -377,12 +381,13 @@ async function runKotlinDev(
stderrListener: createStderrListener(
kotlinSrcOutDir,
resolveUniAppXSourceMapPath(kotlinRootOutDir),
waiting
waiting,
hbuilderFormatter
),
}
result.kotlinc = true
// console.log('DEX编译参数:', options)
const { code, msg, data } = await compileDex(options, inputDir)
// console.log('DEX编译参数:', compileOptions)
const { code, msg, data } = await compileDex(compileOptions, inputDir)
// 等待 stderrListener 执行完毕
if (waiting.done) {
await waiting.done
......
import path from 'path'
// import debug from 'debug'
import { extend, isString } from '@vue/shared'
import type { Plugin, ResolvedConfig } from 'vite'
import type { FilterPattern } from '@rollup/pluginutils'
import { COMMON_EXCLUDE } from '@dcloudio/uni-cli-shared'
import { COMMON_EXCLUDE, requireUniHelpers } from '@dcloudio/uni-cli-shared'
import type { VitePluginUniResolvedOptions } from '../..'
import { uniPrePlugin } from './pre'
......@@ -71,14 +70,7 @@ export function initPlugins(
process.env.UNI_COMPILE_TARGET !== 'uni_modules'
) {
try {
require(path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'uni_helpers/lib/bytenode'
))
const { V } = require(path.join(
process.env.UNI_HBUILDERX_PLUGINS,
'uni_helpers'
))
const { V } = requireUniHelpers()
addPlugin(
plugins,
V({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册