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

wip(uts): compiler

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