mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-14 04:43:14 +00:00
feat: 支持 esModule#preferClassProperty 配置项
This commit is contained in:
parent
a37a647ef6
commit
574e348c1e
@ -24,22 +24,31 @@ interface IModuleInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ProjectBuilderInitOptions {
|
export interface ProjectBuilderInitOptions {
|
||||||
|
|
||||||
/** 项目模板 */
|
/** 项目模板 */
|
||||||
template: IProjectTemplate;
|
template: IProjectTemplate;
|
||||||
|
|
||||||
/** 项目插件 */
|
/** 项目插件 */
|
||||||
plugins: IProjectPlugins;
|
plugins: IProjectPlugins;
|
||||||
|
|
||||||
/** 模块后置处理器 */
|
/** 模块后置处理器 */
|
||||||
postProcessors: PostProcessor[];
|
postProcessors: PostProcessor[];
|
||||||
|
|
||||||
/** Schema 解析器 */
|
/** Schema 解析器 */
|
||||||
schemaParser?: ISchemaParser;
|
schemaParser?: ISchemaParser;
|
||||||
|
|
||||||
/** 项目级别的前置处理器 */
|
/** 项目级别的前置处理器 */
|
||||||
projectPreProcessors?: ProjectPreProcessor[];
|
projectPreProcessors?: ProjectPreProcessor[];
|
||||||
|
|
||||||
/** 项目级别的后置处理器 */
|
/** 项目级别的后置处理器 */
|
||||||
projectPostProcessors?: ProjectPostProcessor[];
|
projectPostProcessors?: ProjectPostProcessor[];
|
||||||
|
|
||||||
/** 是否处于严格模式 */
|
/** 是否处于严格模式 */
|
||||||
inStrictMode?: boolean;
|
inStrictMode?: boolean;
|
||||||
|
|
||||||
/** 一些额外的上下文数据 */
|
/** 一些额外的上下文数据 */
|
||||||
extraContextData?: Record<string, unknown>;
|
extraContextData?: Record<string, unknown>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook which is used to customize original options, we can reorder/add/remove plugins/processors
|
* Hook which is used to customize original options, we can reorder/add/remove plugins/processors
|
||||||
* of the existing solution.
|
* of the existing solution.
|
||||||
@ -264,6 +273,16 @@ export class ProjectBuilder implements IProjectBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 更多 slots 的处理??是不是可以考虑把 template 中所有的 slots 都处理下?
|
// TODO: 更多 slots 的处理??是不是可以考虑把 template 中所有的 slots 都处理下?
|
||||||
|
// const whitelistSlotNames = [
|
||||||
|
// 'router',
|
||||||
|
// 'entry',
|
||||||
|
// 'appConfig',
|
||||||
|
// 'buildConfig',
|
||||||
|
// 'router',
|
||||||
|
// ];
|
||||||
|
// Object.keys(this.template.slots).forEach((slotName: string) => {
|
||||||
|
|
||||||
|
// });
|
||||||
|
|
||||||
// Post Process
|
// Post Process
|
||||||
const isSingleComponent = parseResult?.project?.projectRemark?.isSingleComponent;
|
const isSingleComponent = parseResult?.project?.projectRemark?.isSingleComponent;
|
||||||
|
|||||||
@ -443,6 +443,7 @@ function buildPackageImport(
|
|||||||
export interface PluginConfig {
|
export interface PluginConfig {
|
||||||
fileType?: string; // 导出的文件类型
|
fileType?: string; // 导出的文件类型
|
||||||
useAliasName?: boolean; // 是否使用 componentName 重命名组件 identifier
|
useAliasName?: boolean; // 是否使用 componentName 重命名组件 identifier
|
||||||
|
filter?: (deps: IDependency[]) => IDependency[]; // 支持过滤能力
|
||||||
}
|
}
|
||||||
|
|
||||||
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?: PluginConfig) => {
|
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?: PluginConfig) => {
|
||||||
@ -460,7 +461,8 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?: Plu
|
|||||||
const ir = next.ir as IWithDependency;
|
const ir = next.ir as IWithDependency;
|
||||||
|
|
||||||
if (ir && ir.deps && ir.deps.length > 0) {
|
if (ir && ir.deps && ir.deps.length > 0) {
|
||||||
const packs = groupDepsByPack(ir.deps);
|
const deps = cfg.filter ? cfg.filter(ir.deps) : ir.deps;
|
||||||
|
const packs = groupDepsByPack(deps);
|
||||||
|
|
||||||
Object.keys(packs).forEach((pkg) => {
|
Object.keys(packs).forEach((pkg) => {
|
||||||
const chunks = buildPackageImport(pkg, packs[pkg], cfg.fileType, cfg.useAliasName);
|
const chunks = buildPackageImport(pkg, packs[pkg], cfg.fileType, cfg.useAliasName);
|
||||||
|
|||||||
@ -16,6 +16,9 @@ import {
|
|||||||
|
|
||||||
export interface PluginConfig {
|
export interface PluginConfig {
|
||||||
fileType: string;
|
fileType: string;
|
||||||
|
|
||||||
|
/** prefer using class property to define utils */
|
||||||
|
preferClassProperty?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
|
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
|
||||||
@ -57,13 +60,25 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
|||||||
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
|
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
|
||||||
});
|
});
|
||||||
|
|
||||||
next.chunks.push({
|
if (cfg.preferClassProperty) {
|
||||||
type: ChunkType.STRING,
|
// mode: class property
|
||||||
fileType: cfg.fileType,
|
next.chunks.push({
|
||||||
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
|
type: ChunkType.STRING,
|
||||||
content: 'this.utils = utils;',
|
fileType: cfg.fileType,
|
||||||
linkAfter: [CLASS_DEFINE_CHUNK_NAME.ConstructorStart],
|
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
|
||||||
});
|
content: 'utils = utils;',
|
||||||
|
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsVar]],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// mode: assign in constructor
|
||||||
|
next.chunks.push({
|
||||||
|
type: ChunkType.STRING,
|
||||||
|
fileType: cfg.fileType,
|
||||||
|
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
|
||||||
|
content: 'this.utils = utils;',
|
||||||
|
linkAfter: [CLASS_DEFINE_CHUNK_NAME.ConstructorStart],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (useRef) {
|
if (useRef) {
|
||||||
next.chunks.push({
|
next.chunks.push({
|
||||||
|
|||||||
@ -22,6 +22,8 @@ const factory: PostProcessorFactory<ProcessorConfig> = (config?: ProcessorConfig
|
|||||||
let parser: prettier.BuiltInParserName | any;
|
let parser: prettier.BuiltInParserName | any;
|
||||||
if (fileType === 'js' || fileType === 'jsx') {
|
if (fileType === 'js' || fileType === 'jsx') {
|
||||||
parser = 'babel';
|
parser = 'babel';
|
||||||
|
} else if (fileType === 'json') {
|
||||||
|
parser = 'json-stringify';
|
||||||
} else if (PARSERS.indexOf(fileType) >= 0) {
|
} else if (PARSERS.indexOf(fileType) >= 0) {
|
||||||
parser = fileType;
|
parser = fileType;
|
||||||
} else if (cfg.customFileTypeParser[fileType]) {
|
} else if (cfg.customFileTypeParser[fileType]) {
|
||||||
|
|||||||
@ -22,8 +22,10 @@ export enum FileType {
|
|||||||
LESS = 'less',
|
LESS = 'less',
|
||||||
HTML = 'html',
|
HTML = 'html',
|
||||||
JS = 'js',
|
JS = 'js',
|
||||||
|
MJS = 'mjs',
|
||||||
JSX = 'jsx',
|
JSX = 'jsx',
|
||||||
TS = 'ts',
|
TS = 'ts',
|
||||||
|
MTS = 'mts',
|
||||||
TSX = 'tsx',
|
TSX = 'tsx',
|
||||||
JSON = 'json',
|
JSON = 'json',
|
||||||
MD = 'md',
|
MD = 'md',
|
||||||
@ -168,6 +170,7 @@ export interface IProjectBuilderOptions {
|
|||||||
* - expr: 求值的表达式
|
* - expr: 求值的表达式
|
||||||
*/
|
*/
|
||||||
evalErrorsHandler?: string;
|
evalErrorsHandler?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook which is used to customize original options, we can reorder/add/remove plugins/processors
|
* Hook which is used to customize original options, we can reorder/add/remove plugins/processors
|
||||||
* of the existing solution.
|
* of the existing solution.
|
||||||
|
|||||||
@ -42,6 +42,7 @@ export interface IRouterInfo extends IWithDependency {
|
|||||||
* project's remarks
|
* project's remarks
|
||||||
*/
|
*/
|
||||||
export interface ProjectRemark {
|
export interface ProjectRemark {
|
||||||
|
|
||||||
/** if current project only contain one container which type is `Component` */
|
/** if current project only contain one container which type is `Component` */
|
||||||
isSingleComponent?: boolean;
|
isSingleComponent?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user