mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-01 05:30:40 +00:00
1. fix bug of failing to resolve RFC components
2. support transforming function args
3. fix bug of oneOfType
4. fix bug of crash when circular parsing
5. fix bug of union
6. support tuple
7. fix bug of builtin type parsing
8. fix bug of false positive component identification
9. fix bug of entry resolving
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import parseDynamic from './dynamic';
|
|
import parseJS from './js';
|
|
import parseTS from './ts';
|
|
import { install, installPeerDeps, installTypeModules } from '../utils';
|
|
import { IMaterialScanModel } from '../types';
|
|
import { debug } from '../core';
|
|
|
|
const log = debug.extend('parse');
|
|
|
|
export interface IParseArgs extends IMaterialScanModel {
|
|
accesser?: 'online' | 'local';
|
|
npmClient?: string;
|
|
workDir: string;
|
|
moduleDir: string;
|
|
typingsFileAbsolutePath?: string;
|
|
mainFileAbsolutePath: string;
|
|
moduleFileAbsolutePath?: string;
|
|
}
|
|
|
|
export default async (args: IParseArgs) => {
|
|
const {
|
|
typingsFileAbsolutePath,
|
|
mainFileAbsolutePath,
|
|
moduleFileAbsolutePath = mainFileAbsolutePath,
|
|
} = args;
|
|
if (args.accesser === 'local') {
|
|
if (mainFileAbsolutePath.endsWith('ts') || mainFileAbsolutePath.endsWith('tsx')) {
|
|
await install(args);
|
|
return parseTS(mainFileAbsolutePath);
|
|
} else {
|
|
try {
|
|
return parseJS(moduleFileAbsolutePath);
|
|
} catch (e) {
|
|
await install(args);
|
|
const info = parseDynamic(mainFileAbsolutePath);
|
|
if (!info || !info.length) {
|
|
throw Error();
|
|
}
|
|
return info;
|
|
}
|
|
}
|
|
} else if (args.accesser === 'online') {
|
|
// ts
|
|
if (typingsFileAbsolutePath) {
|
|
await installTypeModules(args);
|
|
return parseTS(typingsFileAbsolutePath);
|
|
}
|
|
// js
|
|
try {
|
|
// try dynamic parsing first
|
|
await installPeerDeps(args);
|
|
const info = parseDynamic(mainFileAbsolutePath);
|
|
if (!info || !info.length) {
|
|
throw Error();
|
|
}
|
|
return info;
|
|
} catch (e) {
|
|
log(e);
|
|
// if error, use static js parsing instead
|
|
return parseJS(moduleFileAbsolutePath);
|
|
}
|
|
}
|
|
return parseJS(moduleFileAbsolutePath);
|
|
};
|