diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 24c37a8..01bfccb 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -220,7 +220,7 @@ export class ResultStates { if (lastModuleCollection && lastModuleCollection !== 'NULL') { lastModuleCollection.split(',').forEach(item => { moduleCollection.add(item); - }) + }); } } const moduleContent: string = diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 7a13c0a..f976be3 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -111,7 +111,7 @@ export function createLanguageService(rootFileNames: string[]): ts.LanguageServi } function getOhmUrlFile(moduleName: string): {modulePath: string, suffix: string} { - let modulePath = resolveSourceFile(moduleName); + const modulePath: string = resolveSourceFile(moduleName); let suffix: string = path.extname(modulePath); if (suffix === 'ts' && modulePath.endsWith('.d.ts')) { suffix = '.d.ts'; diff --git a/compiler/src/resolve_ohm_url.ts b/compiler/src/resolve_ohm_url.ts index dbf0845..0bc8c0b 100644 --- a/compiler/src/resolve_ohm_url.ts +++ b/compiler/src/resolve_ohm_url.ts @@ -13,71 +13,73 @@ export class OHMResolverPlugin { private target: any; constructor(source = 'resolve', target = 'resolve') { - this.source = source; - this.target = target; + this.source = source; + this.target = target; } apply(resolver) { - const target = resolver.ensureHook(this.target); - resolver.getHook(this.source).tapAsync("OHMResolverPlugin", (request, resolveContext, callback) => { - if (isOhmUrl(request.request)) { - var resolvedSourceFile: string = resolveSourceFile(request.request); - var obj = Object.assign({}, request, { - request: resolvedSourceFile - }); - return resolver.doResolve(target, obj, null, resolveContext, callback); - } - callback(); - }); + const target = resolver.ensureHook(this.target); + resolver.getHook(this.source).tapAsync('OHMResolverPlugin', (request, resolveContext, callback) => { + if (isOhmUrl(request.request)) { + const resolvedSourceFile: string = resolveSourceFile(request.request); + const obj = Object.assign({}, request, { + request: resolvedSourceFile + }); + return resolver.doResolve(target, obj, null, resolveContext, callback); + } + callback(); + }); } } export function isOhmUrl(moduleRequest: string): boolean { - return /^@(\S+):/.test(moduleRequest) ? true : false; + return !!/^@(\S+):/.test(moduleRequest); } function addExtension(file: string, srcPath: string): string { - if (path.extname(file) !== '') { - return file; - } + if (path.extname(file) !== '') { + return file; + } - let extension: string = '.d.ts'; - if (fs.existsSync(file + '.ets') && fs.statSync(file + '.ets').isFile()) { - extension = '.ets'; + let extension: string = '.d.ts'; + if (fs.existsSync(file + '.ets') && fs.statSync(file + '.ets').isFile()) { + extension = '.ets'; + } + if (fs.existsSync(file + '.ts') && fs.statSync(file + '.ts').isFile()) { + if (extension !== '.d.ts') { + logger.error(red, `ETS:ERROR Failed to compile with files with same name ${srcPath} in the same directory`, reset); } - if (fs.existsSync(file + '.ts') && fs.statSync(file + '.ts').isFile()) { - if (extension != '.d.ts') { - logger.error(red, `ETS:ERROR Failed to compile with files with same name ${srcPath} in the same directory`, reset); - } - extension = '.ts'; + extension = '.ts'; + } + if (fs.existsSync(file + '.js') && fs.statSync(file + '.js').isFile()) { + if (extension !== '.d.ts') { + logger.error(red, `ETS:ERROR Failed to compile with files with same name ${srcPath} in the same directory`, reset); } - if (fs.existsSync(file + '.js') && fs.statSync(file + '.js').isFile()) { - if (extension != '.d.ts') { - logger.error(red, `ETS:ERROR Failed to compile with files with same name ${srcPath} in the same directory`, reset); - } - extension = '.js'; - } - return file + extension; + extension = '.js'; + } + return file + extension; } export function resolveSourceFile(ohmUrl: string): string { - const result = ohmUrl.match(REG_OHM_URL); - let moduleName = result[2]; - let srcKind = result[3]; + const result = ohmUrl.match(REG_OHM_URL); + const moduleName = result[2]; + const srcKind = result[3]; - let file = path.join(projectConfig.projectPath, '../../../../../', moduleName, 'src/main', srcKind, result[4]); + let file = ''; - if (projectConfig.aceBuildJson) { - const buildJson = JSON.parse(fs.readFileSync(projectConfig.aceBuildJson).toString()); - const modulePath = buildJson.modulePathMap[moduleName]; - file = path.join(modulePath, 'src/main', srcKind, result[4]); - } + if (projectConfig.aceBuildJson) { + const buildJson = JSON.parse(fs.readFileSync(projectConfig.aceBuildJson).toString()); + const modulePath = buildJson.modulePathMap[moduleName]; + file = path.join(modulePath, 'src/main', srcKind, result[4]); + } else { + logger.error(red, `ETS:ERROR Failed to resolve OhmUrl because of aceBuildJson not existing `, reset); + } - file = addExtension(file, result[4]); + file = addExtension(file, result[4]); - if (!fs.existsSync(file) || !fs.statSync(file).isFile()) { - logger.error(red, `ETS:ERROR Failed to resolve existed file by this ohm url ${ohmUrl} `, reset); - } + if (!fs.existsSync(file) || !fs.statSync(file).isFile()) { + logger.error(red, `ETS:ERROR Failed to resolve existed file by this ohm url ${ohmUrl} `, reset); + } - return file; -} \ No newline at end of file + return file; +} diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index a3fcb3e..94b5239 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -58,7 +58,7 @@ import { EXTEND_ATTRIBUTE, GLOBAL_STYLE_FUNCTION, STYLES_ATTRIBUTE, - CUSTOM_BUILDER_METHOD, + CUSTOM_BUILDER_METHOD } from './component_map'; import { LogType, @@ -839,7 +839,7 @@ function getPackageInfo(configFile: string): Array { } const data = JSON.parse(fs.readFileSync(configFile).toString()); const bundleName = data.app.bundleName; - const moduleName = projectConfig.aceModuleJsonPath ? data.module.name : data.module.distro.moduleName; + const moduleName = data.module.name; packageCollection.set(configFile, [bundleName, moduleName]); return [bundleName, moduleName]; } @@ -867,47 +867,82 @@ function replaceLibSo(importValue: string, libSoKey: string, sourcePath: string return `var ${importValue} = globalThis.requireNapi("${libSoKey}", true);`; } -function replaceOhmUrl(isSystemModule: boolean, item: string, importValue: string, moduleRequest: string, sourcePath: string = null) { - const result = moduleRequest.match(/^@(\S+):(\S+)$/) - let urlType: string = result[1]; - let url: string = result[2]; - switch(urlType) { - case 'bundle': { - let urlResult = url.match(/^(\S+)\/(\S+)\/(\S+)\/(\S+)$/); - if (urlResult) { - let moduleKind = urlResult[3]; - if (moduleKind === 'lib') { - item = replaceLibSo(importValue, moduleRequest, sourcePath); - } +function replaceOhmStartsWithBundle(url: string, item: string, importValue: string, moduleRequest: string, sourcePath: string) { + const urlResult = url.match(/^(\S+)\/(\S+)\/(\S+)\/(\S+)$/); + if (urlResult) { + const moduleKind = urlResult[3]; + if (moduleKind === 'lib') { + item = replaceLibSo(importValue, moduleRequest, sourcePath); + } + } + return item; +} + +function replaceOhmStartsWithModule(url: string, item: string, importValue: string, moduleRequest: string, sourcePath: string) { + const urlResult = url.match(/^(\S+)\/(\S+)\/(\S+)$/); + if (urlResult && projectConfig.aceModuleJsonPath) { + const moduleName = urlResult[1]; + const moduleKind = urlResult[2]; + const modulePath = urlResult[3]; + const bundleName = getPackageInfo(projectConfig.aceModuleJsonPath)[0]; + moduleRequest = `@bundle:${bundleName}/${moduleName}/${moduleKind}/${modulePath}`; + item = moduleKind === 'lib' ? replaceLibSo(importValue, moduleRequest, sourcePath) : + item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); + } + return item; +} + +function replaceOhmStartsWithOhos(url: string, item: string, importValue:string, moduleRequest: string, isSystemModule: boolean) { + url = url.replace('/', '.'); + const urlResult = url.match(/^system\.(\S+)/); + moduleRequest = urlResult ? `@${url}` : `@ohos.${url}`; + if (!isSystemModule) { + item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); + } else { + const moduleType = urlResult ? 'system' : 'ohos'; + const systemKey = urlResult ? url.substring(7) : url; + item = replaceSystemApi(item, importValue, moduleType, systemKey); + } + return item; +} + +function replaceOhmStartsWithLocal(url: string, item: string, importValue: string, moduleRequest: string, sourcePath: string) { + const result = sourcePath.match(/(\S+)(\/|\\)src(\/|\\)main(\/|\\)(ets|js)(\/|\\)(\S+)/); + if (result && projectConfig.aceModuleJsonPath) { + const packageInfo = getPackageInfo(projectConfig.aceModuleJsonPath); + const urlResult = url.match(/^\/(ets|js|lib|node_modules)\/(\S+)$/); + if (urlResult) { + const moduleKind = urlResult[1]; + const modulePath = urlResult[2]; + if (moduleKind === 'lib') { + item = replaceLibSo(importValue, modulePath, sourcePath); + } else if (moduleKind === 'node_modules') { + moduleRequest = `${modulePath}`; + item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); + } else { + moduleRequest = `@bundle:${packageInfo[0]}/${packageInfo[1]}/${moduleKind}/${modulePath}`; + item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); } + } + } + return item; +} + +function replaceOhmUrl(isSystemModule: boolean, item: string, importValue: string, moduleRequest: string, sourcePath: string = null) { + const result = moduleRequest.match(/^@(\S+):(\S+)$/); + const urlType: string = result[1]; + const url: string = result[2]; + switch (urlType) { + case 'bundle': { + item = replaceOhmStartsWithBundle(url, item, importValue, moduleRequest, sourcePath); break; } case 'module': { - let urlResult = url.match(/^(\S+)\/(\S+)\/(\S+)$/); - if (urlResult) { - let moduleName = urlResult[1]; - let moduleKind = urlResult[2]; - let modulePath = urlResult[3]; - const configJsonFile: string = projectConfig.aceModuleJsonPath ? projectConfig.aceModuleJsonPath : - path.join(projectConfig.projectPath, '../../../../../', moduleName, 'src/main/config.json'); - let bundleName = getPackageInfo(configJsonFile)[0]; - moduleRequest = `@bundle:${bundleName}/${moduleName}/${moduleKind}/${modulePath}`; - item = moduleKind === 'lib' ? replaceLibSo(importValue, moduleRequest, sourcePath) : - item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); - } + item = replaceOhmStartsWithModule(url, item, importValue, moduleRequest, sourcePath); break; } case 'ohos': { - url = url.replace('/', '.'); - let urlResult = url.match(/^system\.(\S+)/); - moduleRequest = urlResult ? `@${url}` : `@ohos.${url}`; - if (!isSystemModule) { - item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); - } else { - let moduleType = urlResult ? 'system' : 'ohos'; - let systemKey = urlResult ? url.substring(7) : url; - item = replaceSystemApi(item, importValue, moduleType, systemKey); - } + item = replaceOhmStartsWithOhos(url, item, importValue, moduleRequest, isSystemModule); break; } case 'lib': { @@ -915,44 +950,24 @@ function replaceOhmUrl(isSystemModule: boolean, item: string, importValue: strin break; } case 'local': { - let result = sourcePath.match(/(\S+)(\/|\\)src(\/|\\)main(\/|\\)(ets|js)(\/|\\)(\S+)/); - if (result) { - const configJsonFile: string = projectConfig.aceModuleJsonPath ? projectConfig.aceModuleJsonPath : - path.join(result[1], 'src/main/config.json'); - let packageInfo = getPackageInfo(configJsonFile); - let urlResult = url.match(/^\/(ets|js|lib|node_modules)\/(\S+)$/); - if (urlResult) { - let moduleKind = urlResult[1]; - let modulePath = urlResult[2]; - if (moduleKind === 'lib') { - item = replaceLibSo(importValue, modulePath, sourcePath); - } else if (moduleKind === 'node_modules') { - moduleRequest = `${modulePath}`; - item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); - } else { - moduleRequest = `@bundle:${packageInfo[0]}/${packageInfo[1]}/${moduleKind}/${modulePath}`; - item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); - } - } - } + item = replaceOhmStartsWithLocal(url, item, importValue, moduleRequest, sourcePath); break; } default: - console.error("Incorrect OpenHarmony module kind: ", urlType); + console.error('Incorrect OpenHarmony module kind: ', urlType); } return item; } function replaceRelativePath(item:string, moduleRequest: string, sourcePath: string) { - if (sourcePath) { - let filePath = path.resolve(path.dirname(sourcePath), moduleRequest); - let result = filePath.match(/(\S+)(\/|\\)src(\/|\\)main(\/|\\)(ets|js)(\/|\\)(\S+)/); - if (result) { - const configJsonFile: string = projectConfig.aceModuleJsonPath ? projectConfig.aceModuleJsonPath : - path.join(result[1], 'src/main/config.json'); - let packageInfo = getPackageInfo(configJsonFile); - let bundleName = packageInfo[0]; - let moduleName = packageInfo[1]; + // Do not replace relativePath to ohmUrl when building bundle + if (sourcePath && projectConfig.compileMode === 'esmodule') { + const filePath = path.resolve(path.dirname(sourcePath), moduleRequest); + const result = filePath.match(/(\S+)(\/|\\)src(\/|\\)main(\/|\\)(ets|js)(\/|\\)(\S+)/); + if (result && projectConfig.aceModuleJsonPath) { + const packageInfo = getPackageInfo(projectConfig.aceModuleJsonPath); + const bundleName = packageInfo[0]; + const moduleName = packageInfo[1]; moduleRequest = `@bundle:${bundleName}/${moduleName}/${result[5]}/${toUnixPath(result[7])}`; item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); } @@ -966,13 +981,13 @@ export function processSystemApi(content: string, isProcessAllowList: boolean = /(import|export)\s+(.+)\s+from\s+['"](\S+)['"]|import\s+(.+)\s*=\s*require\(\s*['"](\S+)['"]\s*\)/g; const processedContent: string = content.replace(REG_IMPORT_DECL, (item, item1, item2, item3, item4, item5) => { - let importValue: string = isProcessAllowList ? item1 : item2 || item4; + const importValue: string = isProcessAllowList ? item1 : item2 || item4; if (isProcessAllowList) { return replaceSystemApi(item, importValue, item2, item3); } - let moduleRequest: string = item3 || item5; + const moduleRequest: string = item3 || item5; if (isOhmUrl(moduleRequest)) { // ohmURL return replaceOhmUrl(isSystemModule, item, importValue, moduleRequest, sourcePath); } else if (/^@(system|ohos)\./.test(moduleRequest)) { // ohos/system.api @@ -980,15 +995,15 @@ export function processSystemApi(content: string, isProcessAllowList: boolean = if (!isSystemModule) { return item; } - let result = moduleRequest.match(/^@(system|ohos)\.(\S+)$/); - let moduleType: string = result[1]; - let apiName: string = result[2]; + const result = moduleRequest.match(/^@(system|ohos)\.(\S+)$/); + const moduleType: string = result[1]; + const apiName: string = result[2]; return replaceSystemApi(item, importValue, moduleType, apiName); } else if (/^(\.|\.\.)\//.test(moduleRequest)) { // relativePath return replaceRelativePath(item, moduleRequest, sourcePath); } else if (/^lib(\S+)\.so$/.test(moduleRequest)) { // libxxx.so - let result = moduleRequest.match(/^lib(\S+)\.so$/); - let libSoKey = result[1]; + const result = moduleRequest.match(/^lib(\S+)\.so$/); + const libSoKey = result[1]; return replaceLibSo(importValue, libSoKey, sourcePath); } // node_modules diff --git a/compiler/tsconfig.cjs.json b/compiler/tsconfig.cjs.json new file mode 100644 index 0000000..09ad1cd --- /dev/null +++ b/compiler/tsconfig.cjs.json @@ -0,0 +1,571 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "ets": { + "render": { + "method": ["build", "pageTransition"], + "decorator": "Builder" + }, + "components": [ + "AbilityComponent", + "AlphabetIndexer", + "Animator", + "Badge", + "Blank", + "Button", + "Calendar", + "Camera", + "Canvas", + "Checkbox", + "CheckboxGroup", + "Circle", + "ColorPicker", + "ColorPickerDialog", + "Column", + "ColumnSplit", + "Counter", + "DataPanel", + "DatePicker", + "Divider", + "Ellipse", + "Flex", + "FormComponent", + "Gauge", + "GeometryView", + "Grid", + "GridItem", + "GridContainer", + "Hyperlink", + "Image", + "ImageAnimator", + "Line", + "List", + "ListItem", + "LoadingProgress", + "Marquee", + "Menu", + "Navigation", + "Navigator", + "Option", + "PageTransitionEnter", + "PageTransitionExit", + "Panel", + "Path", + "PatternLock", + "Piece", + "PluginComponent", + "Polygon", + "Polyline", + "Progress", + "QRCode", + "Radio", + "Rating", + "Rect", + "Refresh", + "RelativeContainer", + "RemoteWindow", + "Row", + "RowSplit", + "RichText", + "Scroll", + "ScrollBar", + "Search", + "Section", + "Select", + "Shape", + "Sheet", + "SideBarContainer", + "Slider", + "Span", + "Stack", + "Stepper", + "StepperItem", + "Swiper", + "TabContent", + "Tabs", + "Text", + "TextPicker", + "TextClock", + "TextArea", + "TextInput", + "TextTimer", + "TimePicker", + "Toggle", + "Video", + "Web", + "XComponent" + ], + "extend": { + "decorator": "Extend", + "components": [ + { + "name": "AbilityComponent", + "type": "AbilityComponentAttribute", + "instance": "AbilityComponentInstance" + }, + { + "name": "AlphabetIndexer", + "type": "AlphabetIndexerAttribute", + "instance": "AlphabetIndexerInstance" + }, + { + "name": "Animator", + "type": "AnimatorAttribute", + "instance": "AnimatorInstance" + }, + { + "name": "Badge", + "type": "BadgeAttribute", + "instance": "BadgeInstance" + }, + { + "name": "Blank", + "type": "BlankAttribute", + "instance": "BlankInstance" + }, + { + "name": "Button", + "type": "ButtonAttribute", + "instance": "ButtonInstance" + }, + { + "name": "Calendar", + "type": "CalendarAttribute", + "instance": "CalendarInstance" + }, + { + "name": "Camera", + "type": "CameraAttribute", + "instance": "CameraInstance" + }, + { + "name": "Canvas", + "type": "CanvasAttribute", + "instance": "CanvasInstance" + }, + { + "name": "Checkbox", + "type": "CheckboxAttribute", + "instance": "CheckboxInstance" + }, + { + "name": "CheckboxGroup", + "type": "CheckboxGroupAttribute", + "instance": "CheckboxGroupInstance" + }, + { + "name": "Circle", + "type": "CircleAttribute", + "instance": "CircleInstance" + }, + { + "name": "ColorPicker", + "type": "ColorPickerAttribute", + "instance": "ColorPickerInstance" + }, + { + "name": "ColorPickerDialog", + "type": "ColorPickerDialogAttribute", + "instance": "ColorPickerDialogInstance" + }, + { + "name": "Column", + "type": "ColumnAttribute", + "instance": "ColumnInstance" + }, + { + "name": "ColumnSplit", + "type": "ColumnSplitAttribute", + "instance": "ColumnSplitInstance" + }, + { + "name": "Counter", + "type": "CounterAttribute", + "instance": "CounterInstance" + }, + { + "name": "DataPanel", + "type": "DataPanelAttribute", + "instance": "DataPanelInstance" + }, + { + "name": "DatePicker", + "type": "DatePickerAttribute", + "instance": "DatePickerInstance" + }, + { + "name": "Divider", + "type": "DividerAttribute", + "instance": "DividerInstance" + }, + { + "name": "Ellipse", + "type": "EllipseAttribute", + "instance": "EllipseInstance" + }, + { + "name": "Flex", + "type": "FlexAttribute", + "instance": "FlexInstance" + }, + { + "name": "FormComponent", + "type": "FormComponentAttribute", + "instance": "FormComponentInstance" + }, + { + "name": "Gauge", + "type": "GaugeAttribute", + "instance": "GaugeInstance" + }, + { + "name": "GeometryView", + "type": "GeometryViewAttribute", + "instance": "GeometryViewInstance" + }, + { + "name": "Grid", + "type": "GridAttribute", + "instance": "GridInstance" + }, + { + "name": "GridItem", + "type": "GridItemAttribute", + "instance": "GridItemInstance" + }, + { + "name": "GridContainer", + "type": "GridContainerAttribute", + "instance": "GridContainerInstance" + }, + { + "name": "Hyperlink", + "type": "HyperlinkAttribute", + "instance": "HyperlinkInstance" + }, + { + "name": "Image", + "type": "ImageAttribute", + "instance": "ImageInstance" + }, + { + "name": "ImageAnimator", + "type": "ImageAnimatorAttribute", + "instance": "ImageAnimatorInstance" + }, + { + "name": "Line", + "type": "LineAttribute", + "instance": "LineInstance" + }, + { + "name": "List", + "type": "ListAttribute", + "instance": "ListInstance" + }, + { + "name": "ListItem", + "type": "ListItemAttribute", + "instance": "ListItemInstance" + }, + { + "name": "LoadingProgress", + "type": "LoadingProgressAttribute", + "instance": "LoadingProgressInstance" + }, + { + "name": "Marquee", + "type": "MarqueeAttribute", + "instance": "MarqueeInstance" + }, + { + "name": "Menu", + "type": "MenuAttribute", + "instance": "MenuInstance" + }, + { + "name": "Navigation", + "type": "NavigationAttribute", + "instance": "NavigationInstance" + }, + { + "name": "Navigator", + "type": "NavigatorAttribute", + "instance": "NavigatorInstance" + }, + { + "name": "Option", + "type": "OptionAttribute", + "instance": "OptionInstance" + }, + { + "name": "PageTransitionEnter", + "type": "PageTransitionEnterAttribute", + "instance": "PageTransitionEnterInstance" + }, + { + "name": "PageTransitionExit", + "type": "PageTransitionExitAttribute", + "instance": "PageTransitionExitInstance" + }, + { + "name": "Panel", + "type": "PanelAttribute", + "instance": "PanelInstance" + }, + { + "name": "Path", + "type": "PathAttribute", + "instance": "PathInstance" + }, + { + "name": "PatternLock", + "type": "PatternLockAttribute", + "instance": "PatternLockInstance" + }, + { + "name": "Piece", + "type": "PieceAttribute", + "instance": "PieceInstance" + }, + { + "name": "PluginComponent", + "type": "PluginComponentAttribute", + "instance": "PluginComponentInstance" + }, + { + "name": "Polygon", + "type": "PolygonAttribute", + "instance": "PolygonInstance" + }, + { + "name": "Polyline", + "type": "PolylineAttribute", + "instance": "PolylineInstance" + }, + { + "name": "Progress", + "type": "ProgressAttribute", + "instance": "ProgressInstance" + }, + { + "name": "QRCode", + "type": "QRCodeAttribute", + "instance": "QRCodeInstance" + }, + { + "name": "Radio", + "type": "RadioAttribute", + "instance": "RadioInstance" + }, + { + "name": "Rating", + "type": "RatingAttribute", + "instance": "RatingInstance" + }, + { + "name": "Rect", + "type": "RectAttribute", + "instance": "RectInstance" + }, + { + "name": "RelativeContainer", + "type": "RelativeContainerAttribute", + "instance": "RelativeContainerInstance" + }, + { + "name": "Refresh", + "type": "RefreshAttribute", + "instance": "RefreshInstance" + }, + { + "name": "RemoteWindow", + "type": "RemoteWindowAttribute", + "instance": "RemoteWindowInstance" + }, + { + "name": "Row", + "type": "RowAttribute", + "instance": "RowInstance" + }, + { + "name": "RowSplit", + "type": "RowSplitAttribute", + "instance": "RowSplitInstance" + }, + { + "name": "RichText", + "type": "RichTextAttribute", + "instance": "RichTextInstance" + }, + { + "name": "Scroll", + "type": "ScrollAttribute", + "instance": "ScrollInstance" + }, + { + "name": "ScrollBar", + "type": "ScrollBarAttribute", + "instance": "ScrollBarInstance" + }, + { + "name": "Search", + "type": "SearchAttribute", + "instance": "SearchInstance" + }, + { + "name": "Section", + "type": "SectionAttribute", + "instance": "SectionInstance" + }, + { + "name": "Select", + "type": "SelectAttribute", + "instance": "SelectInstance" + }, + { + "name": "Shape", + "type": "ShapeAttribute", + "instance": "ShapeInstance" + }, + { + "name": "Sheet", + "type": "SheetAttribute", + "instance": "SheetInstance" + }, + { + "name": "SideBarContainer", + "type": "SideBarContainerAttribute", + "instance": "SideBarContainerInstance" + }, + { + "name": "Slider", + "type": "SliderAttribute", + "instance": "SliderInstance" + }, + { + "name": "Span", + "type": "SpanAttribute", + "instance": "SpanInstance" + }, + { + "name": "Stack", + "type": "StackAttribute", + "instance": "StackInstance" + }, + { + "name": "Stepper", + "type": "StepperAttribute", + "instance": "StepperInstance" + }, + { + "name": "StepperItem", + "type": "StepperItemAttribute", + "instance": "StepperItemInstance" + }, + { + "name": "Swiper", + "type": "SwiperAttribute", + "instance": "SwiperInstance" + }, + { + "name": "TabContent", + "type": "TabContentAttribute", + "instance": "TabContentInstance" + }, + { + "name": "Tabs", + "type": "TabsAttribute", + "instance": "TabsInstance" + }, + { + "name": "Text", + "type": "TextAttribute", + "instance": "TextInstance" + }, + { + "name": "TextPicker", + "type": "TextPickerAttribute", + "instance": "TextPickerInstance" + }, + { + "name": "TextClock", + "type": "TextClockAttribute", + "instance": "TextClockInstance" + }, + { + "name": "TextArea", + "type": "TextAreaAttribute", + "instance": "TextAreaInstance" + }, + { + "name": "TextInput", + "type": "TextInputAttribute", + "instance": "TextInputInstance" + }, + { + "name": "TextTimer", + "type": "TextTimerAttribute", + "instance": "TextTimerInstance" + }, + { + "name": "TimePicker", + "type": "TimePickerAttribute", + "instance": "TimePickerInstance" + }, + { + "name": "Toggle", + "type": "ToggleAttribute", + "instance": "ToggleInstance" + }, + { + "name": "Video", + "type": "VideoAttribute", + "instance": "VideoInstance" + }, + { + "name": "Web", + "type": "WebAttribute", + "instance": "WebInstance" + }, + { + "name": "XComponent", + "type": "XComponentAttribute", + "instance": "XComponentInstance" + }, + ] + }, + "styles": { + "decorator": "Styles", + "component": { + "name": "Common", + "type": "T", + "instance": "CommonInstance" + }, + "property": "stateStyles" + }, + }, + "allowJs": true, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "importsNotUsedAsValues": "preserve", + "noImplicitAny": false, + "noUnusedLocals": false, + "noUnusedParameters": false, + "experimentalDecorators": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "module": "commonjs", + "target": "es2017", + "types": [], + "typeRoots": [], + "lib": [ + "es2020" + ] + }, + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index ad3881a..144c862 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -287,10 +287,26 @@ function setOptimizationConfig(config, workerFile) { } } +function setTsConfigFile() { + let tsconfigTemplate = + path.resolve(__dirname, projectConfig.compileMode === 'esmodule' ? 'tsconfig.esm.json' : 'tsconfig.cjs.json'); + if (fs.existsSync(tsconfigTemplate) && fs.statSync(tsconfigTemplate).isFile()) { + let currentTsconfigFile = path.resolve(__dirname, 'tsconfig.json'); + let tsconfigTemplateNew = + currentTsconfigFile.replace(/.json$/, projectConfig.compileMode === 'esmodule' ? '.cjs.json' : '.esm.json'); + fs.renameSync(currentTsconfigFile, tsconfigTemplateNew); + + let tsconfigFileNew = + tsconfigTemplate.replace(projectConfig.compileMode === 'esmodule' ? /.esm.json$/ : /.cjs.json$/, '.json'); + fs.renameSync(tsconfigTemplate, tsconfigFileNew); + } +} + module.exports = (env, argv) => { const config = {}; setProjectConfig(env); loadEntryObj(projectConfig); + setTsConfigFile(); initConfig(config); const workerFile = readWorkerFile(); setOptimizationConfig(config, workerFile);