提交 192e7a13 编写于 作者: fxy060608's avatar fxy060608

wip(uts): compiler

上级 1c11b5bd
......@@ -52,5 +52,7 @@ declare namespace NodeJS {
UNI_APP_X?: 'true' | 'false'
UNI_APP_X_CACHE_DIR?: string
HX_Version: string
}
}
......@@ -11,10 +11,10 @@
"md5": "d41d8cd98f00b204e9800998ecf8427e"
},
"index.uts": {
"md5": "fb7530a446dae78d4853ff5bf698ed20"
"md5": "719035aae84f58b2028f63d102c49887"
},
"interface.uts": {
"md5": "8a55e93e1d27e88f34d38b8a7c0a3608"
"md5": "4821d45870be9af550787418f7a4c34c"
},
"package.json": {
"md5": "9595031a0d4158abb72060cdf3a200c1"
......
......@@ -11,10 +11,10 @@
"md5": "d41d8cd98f00b204e9800998ecf8427e"
},
"index.uts": {
"md5": "fb7530a446dae78d4853ff5bf698ed20"
"md5": "719035aae84f58b2028f63d102c49887"
},
"interface.uts": {
"md5": "8a55e93e1d27e88f34d38b8a7c0a3608"
"md5": "4821d45870be9af550787418f7a4c34c"
},
"package.json": {
"md5": "9595031a0d4158abb72060cdf3a200c1"
......
......@@ -433,6 +433,7 @@ export async function compile(
}
const options: UTSBundleOptions = {
mode: process.env.NODE_ENV,
hbxVersion: process.env.HX_Version || process.env.UNI_COMPILER_VERSION,
input,
output: {
isX,
......
......@@ -139,24 +139,28 @@ let kotlinManifest = {
manifest: {} as Record<string, string>,
}
export interface KotlinManifestCache {
version: string
env: Record<string, string>
files: Record<string, Record<string, string>>
}
function updateUTSKotlinSourceMapManifestCache(cacheDir: string) {
const manifestFile = path.resolve(cacheDir, 'src/.manifest.json')
const stats = fs.statSync(manifestFile)
if (stats.isFile()) {
if (kotlinManifest.mtimeMs !== stats.mtimeMs) {
const manifest = fs.readJSONSync(manifestFile) as Record<
string,
Record<string, string>
>
const classManifest: Record<string, string> = {}
Object.keys(manifest).forEach((name) => {
const kotlinClass = manifest[name].class
if (kotlinClass) {
classManifest[kotlinClass] = name
}
})
kotlinManifest.mtimeMs = stats.mtimeMs
kotlinManifest.manifest = classManifest
const { files } = fs.readJSONSync(manifestFile) as KotlinManifestCache
if (files) {
const classManifest: Record<string, string> = {}
Object.keys(files).forEach((name) => {
const kotlinClass = files[name].class
if (kotlinClass) {
classManifest[kotlinClass] = name
}
})
kotlinManifest.mtimeMs = stats.mtimeMs
kotlinManifest.manifest = classManifest
}
}
}
}
......
......@@ -235,6 +235,7 @@ export async function compile(
}
const options: UTSBundleOptions = {
mode: process.env.NODE_ENV,
hbxVersion: process.env.HX_Version || process.env.UNI_COMPILER_VERSION,
input,
output: {
isX,
......
......@@ -24,6 +24,7 @@ import {
isUniCloudSupported,
parseExtApiDefaultParameters,
} from '../utils'
import { KotlinManifestCache } from '../stacktrace/kotlin'
const DEFAULT_IMPORTS = [
'kotlinx.coroutines.async',
......@@ -95,6 +96,7 @@ export async function compileApp(entry: string, options: CompileAppOptions) {
const bundleOptions: UTSBundleOptions = {
mode: process.env.NODE_ENV,
hbxVersion: process.env.HX_Version || process.env.UNI_COMPILER_VERSION,
input,
output: {
isX: true,
......@@ -317,9 +319,9 @@ async function runKotlinDev(
// 编译失败,需要调整缓存的 manifest.json
if (result.changed.length) {
const manifest = readKotlinManifestJson(kotlinSrcOutDir)
if (manifest) {
if (manifest && manifest.files) {
result.changed.forEach((file) => {
delete manifest[file]
delete manifest.files[file]
})
writeKotlinManifestJson(kotlinSrcOutDir, manifest)
}
......@@ -345,7 +347,7 @@ function hasKotlinManifestJson(kotlinSrcOutDir: string) {
function readKotlinManifestJson(
kotlinSrcOutDir: string
): Record<string, string> | undefined {
): KotlinManifestCache | undefined {
const file = path.resolve(kotlinSrcOutDir, '.manifest.json')
if (fs.existsSync(file)) {
return JSON.parse(fs.readFileSync(file, 'utf8'))
......@@ -354,7 +356,7 @@ function readKotlinManifestJson(
function writeKotlinManifestJson(
kotlinSrcOutDir: string,
manifest: Record<string, string>
manifest: KotlinManifestCache
) {
fs.writeFileSync(
path.resolve(kotlinSrcOutDir, '.manifest.json'),
......
......@@ -65,6 +65,7 @@ export type UTSOutputOptions = {
}
export interface UTSOptions {
mode?: string
hbxVersion: string
input: UTSInputOptions
output: UTSOutputOptions
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册