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

wip(uts): compiler

上级 ba3e761c
import type { Plugin } from 'vite'
import path from 'path'
import {
isInHBuilderX,
normalizePath,
parseVueRequest,
requireResolve,
......@@ -53,7 +54,7 @@ export function uniUtsV1Plugin(): Plugin {
// 懒加载 uts 编译器
// eslint-disable-next-line no-restricted-globals
const { parse } = require('@dcloudio/uts')
const ast = await parse(code)
const ast = await parse(code, { noColor: isInHBuilderX() })
code = `
import { initUtsProxyClass, initUtsProxyFunction } from '@dcloudio/uni-app'
const pkg = '${pkg}'
......
......@@ -4,7 +4,11 @@ import path from 'path'
import AdmZip from 'adm-zip'
import { sync } from 'fast-glob'
import type { parse, bundle, UtsTarget } from '@dcloudio/uts'
import { installHBuilderXPlugin, normalizePath } from '@dcloudio/uni-cli-shared'
import {
installHBuilderXPlugin,
isInHBuilderX,
normalizePath,
} from '@dcloudio/uni-cli-shared'
import { camelize } from '@vue/shared'
export function getUtsCompiler(): {
......@@ -42,6 +46,7 @@ export async function compile(filename: string) {
'io.dcloud.uts.*',
],
logFilename: true,
noColor: isInHBuilderX(),
},
})
console.log('uts compile time: ' + (Date.now() - time) + 'ms')
......
......@@ -41,11 +41,13 @@ function resolveOptions(options: UtsOptions) {
output.outDir = normalizePath(output.outDir)
output.sourceMap = normalizePath(output.sourceMap)
output.logFilename = !!output.logFilename
output.noColor = !!output.noColor
return options
}
export function parse(source: string, options: UtsParseOptions = {}) {
options.noColor = !!options.noColor
return bindings
.parse(source, toBuffer(options))
.then((res: string) => JSON.parse(res))
......
......@@ -12,6 +12,7 @@ export interface UtsParserConfig {
export type UtsParseOptions = UtsParserConfig & {
filename?: string
comments?: boolean
noColor?: boolean
}
export type UtsInputOptions = UtsParseOptions & {
......@@ -27,6 +28,7 @@ export type UtsOutputOptions = {
inlineSourcesContent?: boolean
extname: string
logFilename?: boolean
noColor?: boolean
}
export interface UtsOptions {
input: UtsInputOptions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册