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

wip(uts): compiler

上级 6bc41845
...@@ -62,6 +62,7 @@ function transformSwiper(node) { ...@@ -62,6 +62,7 @@ function transformSwiper(node) {
} }
} }
const customElements = ['aweme-data'];
const projectConfigFilename = 'project.config.json'; const projectConfigFilename = 'project.config.json';
const nodeTransforms = [ const nodeTransforms = [
uniCliShared.transformRef, uniCliShared.transformRef,
...@@ -119,7 +120,7 @@ const options = { ...@@ -119,7 +120,7 @@ const options = {
config: ['project.tt.json'], config: ['project.tt.json'],
source, source,
}, },
template: Object.assign(Object.assign({}, miniProgram), { filter: { template: Object.assign(Object.assign({}, miniProgram), { customElements, filter: {
extname: '.sjs', extname: '.sjs',
lang: 'sjs', lang: 'sjs',
generate(filter, filename) { generate(filter, filename) {
......
...@@ -62,9 +62,7 @@ function transformSwiper(node) { ...@@ -62,9 +62,7 @@ function transformSwiper(node) {
} }
} }
const customElements = [ const customElements = ['aweme-data'];
'aweme-data'
];
const projectConfigFilename = 'project.config.json'; const projectConfigFilename = 'project.config.json';
const nodeTransforms = [ const nodeTransforms = [
uniCliShared.transformRef, uniCliShared.transformRef,
......
...@@ -2,6 +2,7 @@ import { resolve } from 'path' ...@@ -2,6 +2,7 @@ import { resolve } from 'path'
import { FORMATS, genProxyCode } from '../src/code' import { FORMATS, genProxyCode } from '../src/code'
import { ERR_MSG_PLACEHOLDER } from '../src/utils' import { ERR_MSG_PLACEHOLDER } from '../src/utils'
const inputDir = resolve(__dirname, 'examples/uts')
const pluginDir = resolve(__dirname, 'examples/uts/utssdk/test-uts') const pluginDir = resolve(__dirname, 'examples/uts/utssdk/test-uts')
describe('code', () => { describe('code', () => {
...@@ -17,6 +18,7 @@ describe('code', () => { ...@@ -17,6 +18,7 @@ describe('code', () => {
namespace: 'uts.sdk.testUTS', namespace: 'uts.sdk.testUTS',
extname: '.uts', extname: '.uts',
androidComponents: { TestUTS: '' }, androidComponents: { TestUTS: '' },
inputDir,
}) })
).replace(ERR_MSG_PLACEHOLDER, '') ).replace(ERR_MSG_PLACEHOLDER, '')
).toMatchSnapshot() ).toMatchSnapshot()
...@@ -33,6 +35,7 @@ describe('code', () => { ...@@ -33,6 +35,7 @@ describe('code', () => {
format: FORMATS.CJS, format: FORMATS.CJS,
pluginRelativeDir: 'utssdk/test-uts', pluginRelativeDir: 'utssdk/test-uts',
androidComponents: { TestUTS: '' }, androidComponents: { TestUTS: '' },
inputDir,
}) })
).replace(ERR_MSG_PLACEHOLDER, '') ).replace(ERR_MSG_PLACEHOLDER, '')
).toMatchSnapshot() ).toMatchSnapshot()
......
...@@ -51,6 +51,7 @@ interface GenProxyCodeOptions { ...@@ -51,6 +51,7 @@ interface GenProxyCodeOptions {
androidComponents?: Record<string, string> androidComponents?: Record<string, string>
iosComponents?: Record<string, string> iosComponents?: Record<string, string>
format?: FORMATS format?: FORMATS
inputDir?: string
pluginRelativeDir?: string pluginRelativeDir?: string
moduleName?: string moduleName?: string
moduleType?: string moduleType?: string
...@@ -63,11 +64,10 @@ export async function genProxyCode( ...@@ -63,11 +64,10 @@ export async function genProxyCode(
options: GenProxyCodeOptions options: GenProxyCodeOptions
) { ) {
const { name, is_uni_modules, format, moduleName, moduleType } = options const { name, is_uni_modules, format, moduleName, moduleType } = options
options.inputDir = options.inputDir || process.env.UNI_INPUT_DIR
if (!options.meta) { if (!options.meta) {
options.meta = { exports: {}, types: {} } options.meta = { exports: {}, types: {} }
} }
options.types = await parseInterfaceTypes(module, options) options.types = await parseInterfaceTypes(module, options)
options.meta!.types = parseMetaTypes(options.types) options.meta!.types = parseMetaTypes(options.types)
return ` return `
...@@ -294,11 +294,11 @@ async function parseInterfaceTypes( ...@@ -294,11 +294,11 @@ async function parseInterfaceTypes(
let ast: Module | null = null let ast: Module | null = null
try { try {
ast = await parse(fs.readFileSync(interfaceFilename, 'utf8'), { ast = await parse(fs.readFileSync(interfaceFilename, 'utf8'), {
filename: relative(interfaceFilename, process.env.UNI_INPUT_DIR), filename: relative(interfaceFilename, options.inputDir!),
noColor: !isColorSupported(), noColor: !isColorSupported(),
}) })
} catch (e) { } catch (e) {
console.error(parseUTSSyntaxError(e, process.env.UNI_INPUT_DIR)) console.error(parseUTSSyntaxError(e, options.inputDir!))
} }
const classTypes: string[] = [] const classTypes: string[] = []
const fnTypes: Record<string, Param[]> = {} const fnTypes: Record<string, Param[]> = {}
...@@ -455,7 +455,8 @@ async function parseFile( ...@@ -455,7 +455,8 @@ async function parseFile(
fs.readFileSync(filename, 'utf8'), fs.readFileSync(filename, 'utf8'),
options.namespace, options.namespace,
options.types!, options.types!,
filename filename,
options.inputDir!
) )
} }
return [] return []
...@@ -465,14 +466,15 @@ async function parseCode( ...@@ -465,14 +466,15 @@ async function parseCode(
code: string, code: string,
namespace: string, namespace: string,
types: Types, types: Types,
filename: string filename: string,
inputDir: string
): Promise<ProxyDecl[]> { ): Promise<ProxyDecl[]> {
// 懒加载 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')
try { try {
const ast = await parse(code, { const ast = await parse(code, {
filename: relative(filename, process.env.UNI_INPUT_DIR), filename: relative(filename, inputDir),
noColor: !isColorSupported(), noColor: !isColorSupported(),
}) })
return parseAst( return parseAst(
...@@ -481,7 +483,7 @@ async function parseCode( ...@@ -481,7 +483,7 @@ async function parseCode(
types types
) )
} catch (e: any) { } catch (e: any) {
console.error(parseUTSSyntaxError(e, process.env.UNI_INPUT_DIR)) console.error(parseUTSSyntaxError(e, inputDir))
} }
return [] return []
} }
......
...@@ -140,6 +140,7 @@ export async function compile( ...@@ -140,6 +140,7 @@ export async function compile(
require(join(pluginDir, 'package.json')).displayName || pkg.id, require(join(pluginDir, 'package.json')).displayName || pkg.id,
moduleType: process.env.UNI_UTS_MODULE_TYPE || '', moduleType: process.env.UNI_UTS_MODULE_TYPE || '',
meta, meta,
inputDir,
}, },
pkg pkg
) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册