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

wip(uts): compiler

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