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

wip(uts): compiler

上级 72ea400d
...@@ -8,7 +8,7 @@ packages/uni-mp-compiler/dist ...@@ -8,7 +8,7 @@ packages/uni-mp-compiler/dist
packages/uni-nvue-styler/dist packages/uni-nvue-styler/dist
packages/vite-plugin-uni/dist packages/vite-plugin-uni/dist
packages/uts/dist packages/uts/dist
packages/uni-uts/dist packages/uni-uts-v1/dist
.DS_Store .DS_Store
......
...@@ -47,7 +47,7 @@ export function uniUtsV1Plugin(): Plugin { ...@@ -47,7 +47,7 @@ export function uniUtsV1Plugin(): Plugin {
resolvePackage, resolvePackage,
resolvePlatformIndex, resolvePlatformIndex,
resolveRootIndex, resolveRootIndex,
} = resolveUTSCompiler().v1 } = resolveUTSCompiler()
const pkg = resolvePackage(module) const pkg = resolvePackage(module)
if (!pkg) { if (!pkg) {
......
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
}, },
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da", "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
"devDependencies": { "devDependencies": {
"@dcloudio/uni-uts": "3.0.0-alpha-3060720221018002", "@dcloudio/uni-uts-v1": "3.0.0-alpha-3060720221018002",
"@types/babel__core": "^7.1.19", "@types/babel__core": "^7.1.19",
"@types/debug": "^4.1.7", "@types/debug": "^4.1.7",
"@types/estree": "^0.0.51", "@types/estree": "^0.0.51",
...@@ -79,4 +79,4 @@ ...@@ -79,4 +79,4 @@
"postcss": "^8.4.16", "postcss": "^8.4.16",
"vue": "3.2.41" "vue": "3.2.41"
} }
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ import path from 'path' ...@@ -4,7 +4,7 @@ import path from 'path'
import debug from 'debug' import debug from 'debug'
import resolve from 'resolve' import resolve from 'resolve'
import { once } from '@dcloudio/uni-shared' import { once } from '@dcloudio/uni-shared'
import * as UTSCompiler from '@dcloudio/uni-uts' import * as UTSCompiler from '@dcloudio/uni-uts-v1'
import { normalizePath } from './utils' import { normalizePath } from './utils'
import { isInHBuilderX } from './hbx/env' import { isInHBuilderX } from './hbx/env'
...@@ -207,7 +207,7 @@ export function resolveUTSCompiler(): typeof UTSCompiler { ...@@ -207,7 +207,7 @@ export function resolveUTSCompiler(): typeof UTSCompiler {
'uniapp-uts' 'uniapp-uts'
)) ))
} }
return require(require.resolve('@dcloudio/uni-uts', { return require(require.resolve('@dcloudio/uni-uts-v1', {
paths: [process.env.UNI_CLI_CONTEXT], paths: [process.env.UNI_CLI_CONTEXT],
})) }))
} }
{ {
"name": "@dcloudio/uni-uts", "name": "@dcloudio/uni-uts-v1",
"version": "3.0.0-alpha-3060720221018002", "version": "3.0.0-alpha-3060720221018002",
"description": "uni-uts", "description": "uni-uts-v1",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"files": [ "files": [
...@@ -10,24 +10,23 @@ ...@@ -10,24 +10,23 @@
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git", "url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uni-uts" "directory": "packages/uni-uts-v1"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3060720221018002",
"@dcloudio/uni-shared": "3.0.0-alpha-3060720221018002",
"@dcloudio/uts": "3.0.0-alpha-3060720221018002", "@dcloudio/uts": "3.0.0-alpha-3060720221018002",
"@vue/shared": "3.2.41", "@vue/shared": "3.2.41",
"adm-zip": "^0.5.9", "adm-zip": "^0.5.9",
"execa": "^5.1.1", "execa": "^5.1.1",
"fast-glob": "^3.2.11", "fast-glob": "^3.2.11",
"fs-extra": "^10.0.0" "fs-extra": "^10.0.0",
"jsonc-parser": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/adm-zip": "^0.5.0", "@types/adm-zip": "^0.5.0",
"@types/fs-extra": "^9.0.13" "@types/fs-extra": "^9.0.13"
} }
} }
\ No newline at end of file
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { isInHBuilderX } from '@dcloudio/uni-cli-shared'
import { import {
BindingIdentifier, BindingIdentifier,
...@@ -14,9 +13,9 @@ import { ...@@ -14,9 +13,9 @@ import {
Param, Param,
TsTypeAnnotation, TsTypeAnnotation,
VariableDeclaration, VariableDeclaration,
} from '../../types/types' } from '../types/types'
import { createResolveTypeReferenceName } from './utils' import { createResolveTypeReferenceName } from './utils'
import { isInHBuilderX } from './shared'
interface GenProxyCodeOptions { interface GenProxyCodeOptions {
is_uni_modules: boolean is_uni_modules: boolean
name: string name: string
......
...@@ -3,14 +3,15 @@ import fs from 'fs-extra' ...@@ -3,14 +3,15 @@ import fs from 'fs-extra'
import path from 'path' import path from 'path'
import AdmZip from 'adm-zip' import AdmZip from 'adm-zip'
import { sync } from 'fast-glob' import { sync } from 'fast-glob'
import { isArray } from '@vue/shared'
import { import {
installHBuilderXPlugin, installHBuilderXPlugin,
isInHBuilderX, isInHBuilderX,
normalizePath, normalizePath,
parseJson,
resolveSourceMapPath, resolveSourceMapPath,
runByHBuilderX, runByHBuilderX,
} from '@dcloudio/uni-cli-shared' } from './shared'
import { import {
genUTSPlatformResource, genUTSPlatformResource,
getUtsCompiler, getUtsCompiler,
...@@ -20,7 +21,7 @@ import { ...@@ -20,7 +21,7 @@ import {
resolveUTSPlatformFile, resolveUTSPlatformFile,
resolveUTSSourceMapPath, resolveUTSSourceMapPath,
} from './utils' } from './utils'
import { Module } from '../../types/types' import { Module } from '../types/types'
export function createKotlinResolveTypeReferenceName( export function createKotlinResolveTypeReferenceName(
_namespace: string, _namespace: string,
...@@ -71,7 +72,11 @@ export async function runKotlinDev(filename: string) { ...@@ -71,7 +72,11 @@ export async function runKotlinDev(filename: string) {
if (!compilerServer) { if (!compilerServer) {
return return
} }
const { getDefaultJar, getKotlincHome, compile } = compilerServer const { getDefaultJar, getKotlincHome, compile, checkDependencies } =
compilerServer
if (checkDependencies) {
await checkDeps(filename, checkDependencies)
}
// time = Date.now() // time = Date.now()
const jarFile = resolveJarPath(kotlinFile) const jarFile = resolveJarPath(kotlinFile)
const options = { const options = {
...@@ -103,6 +108,41 @@ export async function runKotlinDev(filename: string) { ...@@ -103,6 +108,41 @@ export async function runKotlinDev(filename: string) {
} }
} }
function checkDeps(
filename: string,
checkDependencies: (
configJsonFile: string
) => Promise<{ code: number; msg: string; data: string[] }>
) {
const configJsonFile = resolveConfigJsonFile(filename)
if (configJsonFile && hasDeps(configJsonFile)) {
return checkDependencies(configJsonFile).then(({ code, msg, data }) => {
if (code > 0) {
throw msg
}
return data
})
}
return Promise.resolve([])
}
function hasDeps(configJsonFile: string) {
const deps = parseJson(configJsonFile).dependencies || []
if (isArray(deps) && deps.length) {
return true
}
return false
}
function resolveConfigJsonFile(filename: string) {
const configJsonFile = path.resolve(
resolveAndroidDir(filename),
'config.json'
)
if (fs.existsSync(configJsonFile)) {
return configJsonFile
}
}
function resolveSourceMapFile(outputDir: string, kotlinFile: string) { function resolveSourceMapFile(outputDir: string, kotlinFile: string) {
return ( return (
path.resolve(resolveSourceMapPath(), path.relative(outputDir, kotlinFile)) + path.resolve(resolveSourceMapPath(), path.relative(outputDir, kotlinFile)) +
...@@ -221,16 +261,19 @@ function resolveClassPath(jars: string[]) { ...@@ -221,16 +261,19 @@ function resolveClassPath(jars: string[]) {
return jars.join(os.platform() === 'win32' ? ';' : ':') return jars.join(os.platform() === 'win32' ? ';' : ':')
} }
const getCompilerServer = (): interface CompilerServer {
| { getKotlincHome(): string
getKotlincHome(): string getDefaultJar(): string[]
getDefaultJar(): string[] compile(
compile( options: { kotlinc: string[]; d8: string[] },
options: { kotlinc: string[]; d8: string[] }, projectPath: string
projectPath: string ): Promise<boolean>
): Promise<boolean> checkDependencies?: (
} configJsonPath: string
| false => { ) => Promise<{ code: number; msg: string; data: string[] }>
}
function getCompilerServer(): CompilerServer | undefined {
const compilerServerPath = path.resolve( const compilerServerPath = path.resolve(
process.env.UNI_HBUILDERX_PLUGINS, process.env.UNI_HBUILDERX_PLUGINS,
'uniapp-runextension/out/main.js' 'uniapp-runextension/out/main.js'
...@@ -245,6 +288,4 @@ const getCompilerServer = (): ...@@ -245,6 +288,4 @@ const getCompilerServer = ():
console.error(compilerServerPath + ' is not found') console.error(compilerServerPath + ' is not found')
} }
} }
return false
} }
import os from 'os'
import path from 'path'
import { parse } from 'jsonc-parser'
export function parseJson(jsonStr: string) {
return parse(jsonStr)
}
export function once<T extends (...args: any[]) => any>(
fn: T,
ctx: unknown = null
): T {
let res: any
return ((...args: any[]) => {
if (fn) {
res = fn.apply(ctx, args)
fn = null as any
}
return res
}) as T
}
export const runByHBuilderX = once(() => {
return !!process.env.UNI_HBUILDERX_PLUGINS && !!process.env.RUN_BY_HBUILDERX
})
export const isInHBuilderX = once(() => {
try {
// eslint-disable-next-line no-restricted-globals
const { name } = require(path.resolve(
process.cwd(),
'../about/package.json'
))
if (name === 'about') {
process.env.UNI_HBUILDERX_PLUGINS = path.resolve(process.cwd(), '..')
return true
}
} catch (e) {
// console.error(e)
}
return false
})
export function resolveSourceMapPath(
outputDir?: string,
platform?: UniApp.PLATFORM
) {
return path.resolve(
outputDir || process.env.UNI_OUTPUT_DIR,
'../.sourcemap/' +
(platform || process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM)
)
}
export const isWindows = os.platform() === 'win32'
export function normalizePath(id: string): string {
return isWindows ? id.replace(/\\/g, '/') : id
}
function supportAutoInstallPlugin() {
return !!process.env.HX_Version
}
export function installHBuilderXPlugin(plugin: string) {
if (!supportAutoInstallPlugin()) {
return
}
return console.error(
`%HXRunUniAPPPluginName%${plugin}%HXRunUniAPPPluginName%`
)
}
import { isInHBuilderX } from '@dcloudio/uni-cli-shared'
import { capitalize } from '@vue/shared' import { capitalize } from '@vue/shared'
import { import {
genUTSPlatformResource, genUTSPlatformResource,
...@@ -7,6 +6,7 @@ import { ...@@ -7,6 +6,7 @@ import {
resolvePackage, resolvePackage,
resolveUTSSourceMapPath, resolveUTSSourceMapPath,
} from './utils' } from './utils'
import { isInHBuilderX } from './shared'
function parseSwiftPackage(filename: string) { function parseSwiftPackage(filename: string) {
const res = resolvePackage(filename) const res = resolvePackage(filename)
......
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import type { parse, bundle, UtsTarget } from '@dcloudio/uts' import type { parse, bundle, UtsTarget } from '@dcloudio/uts'
import { normalizePath, resolveSourceMapPath } from '@dcloudio/uni-cli-shared'
import { camelize, capitalize } from '@vue/shared' import { camelize, capitalize } from '@vue/shared'
import { Module, ModuleItem } from '../../types/types' import { Module, ModuleItem } from '../types/types'
import { normalizePath, resolveSourceMapPath } from './shared'
export function resolveUTSSourceMapPath(_filename: string) { export function resolveUTSSourceMapPath(_filename: string) {
return resolveSourceMapPath() return resolveSourceMapPath()
......
...@@ -304,7 +304,7 @@ importers: ...@@ -304,7 +304,7 @@ importers:
'@babel/types': ^7.17.0 '@babel/types': ^7.17.0
'@dcloudio/uni-i18n': 3.0.0-alpha-3060720221018002 '@dcloudio/uni-i18n': 3.0.0-alpha-3060720221018002
'@dcloudio/uni-shared': 3.0.0-alpha-3060720221018002 '@dcloudio/uni-shared': 3.0.0-alpha-3060720221018002
'@dcloudio/uni-uts': 3.0.0-alpha-3060720221018002 '@dcloudio/uni-uts-v1': 3.0.0-alpha-3060720221018002
'@intlify/core-base': 9.1.9 '@intlify/core-base': 9.1.9
'@intlify/shared': 9.1.9 '@intlify/shared': 9.1.9
'@intlify/vue-devtools': 9.1.9 '@intlify/vue-devtools': 9.1.9
...@@ -394,7 +394,7 @@ importers: ...@@ -394,7 +394,7 @@ importers:
tapable: 2.2.1 tapable: 2.2.1
xregexp: 3.1.0 xregexp: 3.1.0
devDependencies: devDependencies:
'@dcloudio/uni-uts': link:../uni-uts '@dcloudio/uni-uts-v1': link:../uni-uts-v1
'@types/babel__core': 7.1.19 '@types/babel__core': 7.1.19
'@types/debug': 4.1.7 '@types/debug': 4.1.7
'@types/estree': 0.0.51 '@types/estree': 0.0.51
...@@ -799,10 +799,8 @@ importers: ...@@ -799,10 +799,8 @@ importers:
devDependencies: devDependencies:
'@types/debug': 4.1.7 '@types/debug': 4.1.7
packages/uni-uts: packages/uni-uts-v1:
specifiers: specifiers:
'@dcloudio/uni-cli-shared': 3.0.0-alpha-3060720221018002
'@dcloudio/uni-shared': 3.0.0-alpha-3060720221018002
'@dcloudio/uts': 3.0.0-alpha-3060720221018002 '@dcloudio/uts': 3.0.0-alpha-3060720221018002
'@types/adm-zip': ^0.5.0 '@types/adm-zip': ^0.5.0
'@types/fs-extra': ^9.0.13 '@types/fs-extra': ^9.0.13
...@@ -811,15 +809,15 @@ importers: ...@@ -811,15 +809,15 @@ importers:
execa: ^5.1.1 execa: ^5.1.1
fast-glob: ^3.2.11 fast-glob: ^3.2.11
fs-extra: ^10.0.0 fs-extra: ^10.0.0
jsonc-parser: ^3.0.0
dependencies: dependencies:
'@dcloudio/uni-cli-shared': link:../uni-cli-shared
'@dcloudio/uni-shared': link:../uni-shared
'@dcloudio/uts': link:../uts '@dcloudio/uts': link:../uts
'@vue/shared': 3.2.41 '@vue/shared': 3.2.41
adm-zip: 0.5.9 adm-zip: 0.5.9
execa: 5.1.1 execa: 5.1.1
fast-glob: 3.2.12 fast-glob: 3.2.12
fs-extra: 10.1.0 fs-extra: 10.1.0
jsonc-parser: 3.2.0
devDependencies: devDependencies:
'@types/adm-zip': 0.5.0 '@types/adm-zip': 0.5.0
'@types/fs-extra': 9.0.13 '@types/fs-extra': 9.0.13
......
...@@ -32,7 +32,7 @@ const priority = { ...@@ -32,7 +32,7 @@ const priority = {
'uni-cloud': 10, 'uni-cloud': 10,
'uni-automator': 10, 'uni-automator': 10,
uts: 10, uts: 10,
'uni-uts': 9, 'uni-uts-v1': 9,
'uni-stacktracey': 8, 'uni-stacktracey': 8,
'size-check': 0, 'size-check': 0,
} }
...@@ -51,7 +51,7 @@ const targets = (exports.targets = fs.readdirSync('packages').filter((f) => { ...@@ -51,7 +51,7 @@ const targets = (exports.targets = fs.readdirSync('packages').filter((f) => {
) || ) ||
fs.existsSync(path.resolve(__dirname, `../packages/${f}/tsconfig.json`)) fs.existsSync(path.resolve(__dirname, `../packages/${f}/tsconfig.json`))
) )
} catch (e) {} } catch (e) { }
return false return false
})).sort((a, b) => priority[b] - priority[a]) })).sort((a, b) => priority[b] - priority[a])
exports.fuzzyMatchTarget = (partialTargets, includeAllMatching) => { exports.fuzzyMatchTarget = (partialTargets, includeAllMatching) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册