diff --git a/compiler/main.js b/compiler/main.js index 6732940ce315c360dacf4ef0598988fb6e00266b..35c1b6db44f72b7d3843e2cab3f22852848e7ca1 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -48,8 +48,8 @@ configure({ }); const logger = getLogger('ETS'); -const staticPreviewPage = process.env.aceStaticPreview; -const aceCompileMode = process.env.aceCompileMode || 'page'; +let staticPreviewPage = process.env.aceStaticPreview; +let aceCompileMode = process.env.aceCompileMode || 'page'; const abilityConfig = { abilityType: process.env.abilityType || 'page', abilityEntryFile: null, @@ -115,6 +115,7 @@ function initProjectConfig(projectConfig) { function loadEntryObj(projectConfig) { let manifest = {}; + initMain(); initProjectConfig(projectConfig); loadBuildJson(); if (process.env.aceManifestPath && aceCompileMode === 'page') { @@ -886,11 +887,65 @@ const partialUpdateConfig = { partialUpdateMode: false, builderCheck: true, executeArkTSLinter: true, - standardArkTSLinter: true, + standardArkTSLinter: false, optimizeComponent: true, arkTSVersion: undefined, }; +function resetMain() { + staticPreviewPage = undefined; + aceCompileMode = 'page'; + resetAbilityConfig(); + resetProjectConfig(); + resources.app = {}; + abilityPagesFullPath.length = 0; + aceBuildJson = {}; + resetGlobalProgram(); + partialUpdateConfig.builderCheck = true; +} + +function resetAbilityConfig() { + abilityConfig.abilityType = 'page'; + abilityConfig.abilityEntryFile = null; + abilityConfig.projectAbilityPath = []; + abilityConfig.testRunnerFile = []; +} + +function resetProjectConfig() { + projectConfig.entryObj = {}; + projectConfig.cardObj = {}; + projectConfig.compileHar = false; + projectConfig.compileShared = false; + projectConfig.packageDir = 'node_modules'; + projectConfig.packageJson = 'package.json'; + projectConfig.packageManagerType = 'npm'; + projectConfig.cardEntryObj = {}; + projectConfig.compilerTypes = []; + projectConfig.optLazyForEach = false; + const props = ['projectPath', 'buildPath', 'aceModuleBuild', 'manifestFilePath', 'aceProfilePath', + 'aceModuleJsonPath', 'aceSuperVisualPath', 'hashProjectPath', 'aceBuildJson', 'cachePath', + 'aceSoPath', 'localPropertiesPath', 'projectProfilePath', 'isPreview', 'compileMode', 'runtimeOS', + 'sdkInfo', 'checkEntry', 'obfuscateHarType', 'isCrossplatform', 'enableDebugLine', 'bundleType' + ]; + for (let key in projectConfig) { + if (props.includes(key)) { + projectConfig[key] = undefined; + } + } +} + +function resetGlobalProgram() { + globalProgram.builderProgram = null; + globalProgram.program = null; + globalProgram.checker = null; +} + +function initMain() { + staticPreviewPage = process.env.aceStaticPreview; + aceCompileMode = process.env.aceCompileMode || 'page'; + abilityConfig.abilityType = process.env.abilityType || 'page'; +} + exports.globalProgram = globalProgram; exports.projectConfig = projectConfig; exports.loadEntryObj = loadEntryObj; @@ -914,3 +969,4 @@ exports.extendSdkConfigs = extendSdkConfigs; exports.sdkConfigs = sdkConfigs; exports.sdkConfigPrefix = sdkConfigPrefix; exports.ohosSystemModulePaths = ohosSystemModulePaths; +exports.resetMain = resetMain; diff --git a/compiler/src/ark_utils.ts b/compiler/src/ark_utils.ts index 028e969c901dfc293f043d11d2547a321845dc70..2755726a342a2ceb321bd85052c00f902ec161d3 100644 --- a/compiler/src/ark_utils.ts +++ b/compiler/src/ark_utils.ts @@ -18,7 +18,7 @@ import fs from 'fs'; import type sourceMap from 'source-map'; import { minify, MinifyOutput } from 'terser'; -import { ArkObfuscator, getMapFromJson } from "arkguard" +import { getMapFromJson } from "arkguard" import { OH_MODULES } from './fast_build/ark_compiler/common/ark_define'; import { @@ -58,7 +58,7 @@ import { projectConfig, sdkConfigPrefix } from '../main'; -import { mangleFilePath, MergedConfig } from './fast_build/ark_compiler/common/ob_config_resolver'; +import { mangleFilePath } from './fast_build/ark_compiler/common/ob_config_resolver'; import { getRealModulePath, type ResolveModuleInfo } from './ets_checker'; const red: string = '\u001b[31m'; @@ -365,7 +365,7 @@ export async function writeObfuscatedSourceCode(content: string, filePath: strin let genFileInHar: GeneratedFileInHar = harFilesRecord.get(sourcePath); if (!genFileInHar) { - genFileInHar = {sourcePath: sourcePath}; + genFileInHar = {sourcePath: sourcePath}; } if (!genFileInHar.sourceCachePath) { genFileInHar.sourceCachePath = toUnixPath(filePath); @@ -375,7 +375,6 @@ export async function writeObfuscatedSourceCode(content: string, filePath: strin fs.writeFileSync(filePath, content); } - export async function writeArkguardObfuscatedSourceCode(content: string, filePath: string, logger: any, projectConfig: any, relativeSourceFilePath: string = '', rollupNewSourceMaps: Object = {}, originalFilePath: string): Promise { const arkObfuscator = projectConfig.arkObfuscator; @@ -687,6 +686,12 @@ function checkBundleVersion(bundleVersion: string): boolean { return false; } +export function cleanUpUtilsObjects(): void { + newSourceMaps = {}; + identifierCaches = {}; + packageCollection.clear(); +} + const CONSTANT_STEP_0: number = 0; const CONSTANT_STEP_1: number = 1; const CONSTANT_STEP_2: number = 2; diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 580efac9efaa0c094d11536659ca832a310205c8..9ba688b7f302e71c5ac7856de7b86b2c6d51abe5 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -499,3 +499,6 @@ function handleFinishModules(modules, callback) { } } +export function resetCompileInfo() { + props.length = 0; +} diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index b3b5ef5a1640e56a4da36d58491daa773d0a4a8a..07a6ced0ad7f53bb259ee131eb5b750b747a90dd 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -151,3 +151,9 @@ export const CUSTOM_BUILDER_CONSTRUCTORS: Set = new Set(['MenuItem', 'Me } }); })(); + +export function resetComponentMap() { + ID_ATTRS.clear(); + EXTEND_ATTRIBUTE.clear(); + STYLES_ATTRIBUTE.clear(); +} diff --git a/compiler/src/do_arkTS_linter.ts b/compiler/src/do_arkTS_linter.ts index f2009efa9ae67dba84fc55a51a5470cad1564040..578c0bcdcd2b44dab204583123762c46599cc480 100644 --- a/compiler/src/do_arkTS_linter.ts +++ b/compiler/src/do_arkTS_linter.ts @@ -16,29 +16,18 @@ import fs from 'fs'; import path from 'path'; import * as ts from 'typescript'; -import { - projectConfig, - partialUpdateConfig -} from '../main'; -import { toUnixPath } from './utils'; +import { projectConfig } from '../main'; +import { toUnixPath, getRollupCacheManagerKey } from './utils'; import { resolveModuleNames, resolveTypeReferenceDirectives, - cache -} from './ets_checker' -import {Worker} from 'worker_threads'; -import { logger } from './compile_info'; -const fse = require('fs-extra'); + fileHashScriptVersion, +} from './ets_checker'; +import { ARKTS_LINTER_BUILD_INFO_SUFFIX } from './pre_define'; const arkTSDir: string = 'ArkTS'; const arkTSLinterOutputFileName: string = 'ArkTSLinter_output.json'; const spaceNumBeforeJsonLine = 2; -const sleepInterval = 100; -const filteredDiagnosticCode = -2; -let worker: Worker | undefined = undefined; -let tsDiagnostics: ArkTSDiagnostic[] | undefined = undefined; -let strictArkTSDiagnostics: Map | undefined = undefined; -let processArkTSLinterDiagnostic = (): void => {}; interface OutputInfo { categoryInfo: string | undefined; @@ -59,33 +48,29 @@ export enum ArkTSVersion { ArkTS_1_1, } -export type ProcessDiagnosticsFunc = (diagnostics: ts.Diagnostic, isArkTSDiagnostic: boolean) => void; - -export function getArkTSDiagnostics(arkTSVersion: ArkTSVersion, builderProgram: ts.BuilderProgram, - buildInfoWriteFile?: ts.WriteFileCallback): ts.Diagnostic[] { - const compilerHost: ts.CompilerHost = ts.createIncrementalCompilerHost(builderProgram.getProgram().getCompilerOptions()); - compilerHost.resolveModuleNames = resolveModuleNames; - compilerHost.getCurrentDirectory = (): string => process.cwd(); - compilerHost.getDefaultLibFileName = (options): string => ts.getDefaultLibFilePath(options); - compilerHost.resolveTypeReferenceDirectives = resolveTypeReferenceDirectives; - if (arkTSVersion === ArkTSVersion.ArkTS_1_0) { - return ts.ArkTSLinter_1_0.runArkTSLinter(builderProgram, compilerHost, /*srcFile*/ undefined, buildInfoWriteFile); - } else { - return ts.ArkTSLinter_1_1.runArkTSLinter(builderProgram, compilerHost, /*srcFile*/ undefined, buildInfoWriteFile); - } +export interface ArkTSProgram { + builderProgram: ts.BuilderProgram, + wasStrict: boolean } -export function doArkTSLinter(arkTSVersion: ArkTSVersion, builderProgram: ts.BuilderProgram, - arkTSMode: ArkTSLinterMode, printDiagnostic: ProcessDiagnosticsFunc, - shouldWriteFile: boolean = true, buildInfoWriteFile?: ts.WriteFileCallback): ts.Diagnostic[] { +export type ProcessDiagnosticsFunc = (diagnostics: ts.Diagnostic) => void; + +export function doArkTSLinter(arkTSVersion: ArkTSVersion, arkTSMode: ArkTSLinterMode, + builderProgram: ArkTSProgram, reverseStrictProgram: ArkTSProgram, + printDiagnostic: ProcessDiagnosticsFunc, shouldWriteFile: boolean = true, + buildInfoWriteFile?: ts.WriteFileCallback): ts.Diagnostic[] { if (arkTSMode === ArkTSLinterMode.NOT_USE) { return []; } - let diagnostics: ts.Diagnostic[] = getArkTSDiagnostics(arkTSVersion, builderProgram, buildInfoWriteFile); + let diagnostics: ts.Diagnostic[] = []; - if (printDiagnostic === undefined) { - return diagnostics; + if (arkTSVersion === ArkTSVersion.ArkTS_1_0) { + diagnostics = ts.ArkTSLinter_1_0.runArkTSLinter(builderProgram, reverseStrictProgram, + /*srcFile*/ undefined, buildInfoWriteFile); + } else { + diagnostics = ts.ArkTSLinter_1_1.runArkTSLinter(builderProgram, reverseStrictProgram, + /*srcFile*/ undefined, buildInfoWriteFile); } removeOutputFile(); @@ -104,7 +89,7 @@ export function doArkTSLinter(arkTSVersion: ArkTSVersion, builderProgram: ts.Bui function processArkTSLinterReportAsError(diagnostics: ts.Diagnostic[], printDiagnostic: ProcessDiagnosticsFunc): void { diagnostics.forEach((diagnostic: ts.Diagnostic) => { - printDiagnostic(diagnostic, true); + printDiagnostic(diagnostic); }); printArkTSLinterFAQ(diagnostics, printDiagnostic); } @@ -116,7 +101,7 @@ function processArkTSLinterReportAsWarning(diagnostics: ts.Diagnostic[], printDi diagnostics.forEach((diagnostic: ts.Diagnostic) => { const originalCategory = diagnostic.category; diagnostic.category = ts.DiagnosticCategory.Warning; - printDiagnostic(diagnostic, true); + printDiagnostic(diagnostic); diagnostic.category = originalCategory; }); printArkTSLinterFAQ(diagnostics, printDiagnostic); @@ -133,8 +118,8 @@ function processArkTSLinterReportAsWarning(diagnostics: ts.Diagnostic[], printDi reportsUnnecessary: undefined, reportsDeprecated: undefined }; + printDiagnostic(arkTSDiagnostic); - printDiagnostic(arkTSDiagnostic, false); printArkTSLinterFAQ(diagnostics, printDiagnostic); } @@ -150,27 +135,15 @@ function writeOutputFile(diagnostics: ts.Diagnostic[]): string | undefined { filePath = toUnixPath((path.join(filePath, arkTSLinterOutputFileName))); const outputInfo: OutputInfo[] = []; diagnostics.forEach((diagnostic: ts.Diagnostic) => { - if (diagnostic.file) { - const { line, character }: ts.LineAndCharacter = - diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!); - outputInfo.push({ - categoryInfo: diagnostic.category === ts.DiagnosticCategory.Error ? 'Error' : 'Warning', - fileName: diagnostic.file?.fileName, - line: line + 1, - character: character + 1, - messageText: diagnostic.messageText - }); - } else { - const arkTSdiagnostic = diagnostic as ArkTSDiagnostic; - outputInfo.push({ - categoryInfo: arkTSdiagnostic.category === ts.DiagnosticCategory.Error ? 'Error' : 'Warning', - fileName: arkTSdiagnostic.fileName, - line: arkTSdiagnostic.line + 1, - character: arkTSdiagnostic.character + 1, - messageText: arkTSdiagnostic.messageText - }); - - } + const { line, character }: ts.LineAndCharacter = + diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!); + outputInfo.push({ + categoryInfo: diagnostic.category === ts.DiagnosticCategory.Error ? 'Error' : 'Warning', + fileName: diagnostic.file?.fileName, + line: line + 1, + character: character + 1, + messageText: diagnostic.messageText + }); }); let output: string | undefined = filePath; try { @@ -212,182 +185,85 @@ function printArkTSLinterFAQ(diagnostics: ts.Diagnostic[], printDiagnostic: Proc reportsUnnecessary: undefined, reportsDeprecated: undefined }; - printDiagnostic(arkTSFAQDiagnostic, false); + printDiagnostic(arkTSFAQDiagnostic); } -export interface ArkTSDiagnostic extends ts.Diagnostic { - fileName: string | undefined; - line: number; - character: number; -} +function setCompilerOptions(originProgram: ts.Program, wasStrict: boolean): ts.CompilerOptions { + const compilerOptions: ts.CompilerOptions = { ...originProgram.getCompilerOptions() }; + const inversedOptions = getStrictOptions(wasStrict); -let arkTSLinterFinished: boolean = true; -let arkTSLinterDiagnosticProcessed: boolean = true; -let didArkTSLinter: boolean = false; -let arkTSDiagnostics: ArkTSDiagnostic[] = []; -let cacheFilePath: string | null = null; - -export function resetDidArkTSLinter(): void { - didArkTSLinter = false; -} + Object.assign(compilerOptions, inversedOptions); + compilerOptions.allowJs = true; + compilerOptions.checkJs = true; + compilerOptions.tsBuildInfoFile = path.resolve(projectConfig.cachePath, '..', ARKTS_LINTER_BUILD_INFO_SUFFIX); -export function doArkTSLinterParallel(arkTSVersion: ArkTSVersion, arkTSMode: ArkTSLinterMode, printDiagnostic: ProcessDiagnosticsFunc, - rootFileNames: string[], resolveModulePaths: string[], cacheFile: string, shouldWriteFile: boolean = true): void { - if (arkTSMode === ArkTSLinterMode.NOT_USE) { - arkTSLinterFinished = true; - arkTSLinterDiagnosticProcessed = true; - return; - } - arkTSLinterFinished = false; - arkTSLinterDiagnosticProcessed = false; - - didArkTSLinter = true; - - let processArkTSLinterDiagnostic = (): void => { - let diagnostics: ArkTSDiagnostic[] = filterStaticDiagnostics(); - removeOutputFile(); - if (diagnostics.length === 0) { - arkTSLinterDiagnosticProcessed = true; - return; - } - if (arkTSMode === ArkTSLinterMode.COMPATIBLE_MODE) { - processArkTSLinterReportAsWarning(diagnostics, printDiagnostic, shouldWriteFile); - } else { - processArkTSLinterReportAsError(diagnostics, printDiagnostic); - } - arkTSDiagnostics = diagnostics; - cacheFilePath = cacheFile; - arkTSLinterDiagnosticProcessed = true; - }; - - const workerData = { - workerData: { - arkTSVersion: arkTSVersion, - projectConfig: JSON.parse(JSON.stringify(projectConfig)), - partialUpdateConfig: partialUpdateConfig, - processEnv: JSON.parse(JSON.stringify(process.env)), - rootFileNames: rootFileNames, - resolveModulePaths: resolveModulePaths - }, - env: process.env - }; - worker = new Worker(path.resolve(__dirname, './do_arkTS_linter_parallel.js'), workerData); - worker.on('message', (strictDiagnostics: Map) => { - strictArkTSDiagnostics = strictDiagnostics; - if (tsDiagnostics !== undefined) { - processArkTSLinterDiagnostic(); - cleanProcessArkTSLinterDiagnostic(); - } - }); + return compilerOptions; } -function cleanProcessArkTSLinterDiagnostic(): void { - processArkTSLinterDiagnostic = (): void => {}; -} - -export function updateFileCache(): void { - if (!didArkTSLinter) { - return; - } - if (cacheFilePath === null) { - return; - } - if (process.env.watchMode !== 'true' && !projectConfig.xtsMode) { - arkTSDiagnostics.forEach((diagnostic: ArkTSDiagnostic) => { - const fileName = diagnostic.file ? diagnostic.file.fileName : diagnostic.fileName; - if (cache[path.resolve(fileName)]) { - cache[path.resolve(fileName)].error = true; +export function getReverseStrictBuilderProgram(rollupShareObject: any, originProgram: ts.Program, + wasStrict: boolean): ts.BuilderProgram { + let cacheManagerKey: string = getRollupCacheManagerKey(projectConfig); + let cacheServiceKey: string = 'linter_service'; + let service: ts.LanguageService | undefined = + rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).getCache(cacheServiceKey); + if (!service) { + // create language service for linter + const compilerOptions: ts.CompilerOptions = setCompilerOptions(originProgram, wasStrict); + const servicesHost: ts.LanguageServiceHost = { + getScriptFileNames: () => [...originProgram.getRootFileNames()], + getScriptVersion: fileHashScriptVersion, + getScriptSnapshot: fileName => { + if (!fs.existsSync(fileName)) { + return undefined; + } + return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString()); + }, + getCurrentDirectory: () => process.cwd(), + getCompilationSettings: () => compilerOptions, + getDefaultLibFileName: options => ts.getDefaultLibFilePath(options), + fileExists: ts.sys.fileExists, + readFile: ts.sys.readFile, + readDirectory: ts.sys.readDirectory, + resolveModuleNames: resolveModuleNames, + resolveTypeReferenceDirectives: resolveTypeReferenceDirectives, + directoryExists: ts.sys.directoryExists, + getDirectories: ts.sys.getDirectories, + getFileCheckedModuleInfo:(containFilePath: string)=>{ + return { + fileNeedCheck: true, + checkPayload: undefined, + currentFileName: containFilePath, + }; } - }); - fse.ensureDirSync(projectConfig.cachePath); - fs.writeFileSync(cacheFilePath, JSON.stringify({ - 'runtimeOS': projectConfig.runtimeOS, - 'sdkInfo': projectConfig.sdkInfo, - 'fileList': cache - }, null, spaceNumBeforeJsonLine)); - } - arkTSDiagnostics = undefined; -} + }; -export async function waitArkTSLinterFinished(): Promise { - if (worker === undefined) { - return; - } - if ((!arkTSLinterDiagnosticProcessed) && tsDiagnostics && strictArkTSDiagnostics) { - processArkTSLinterDiagnostic(); - cleanProcessArkTSLinterDiagnostic(); - } - let sleep = async (time): Promise => { - return new Promise(r => setTimeout(r, time)); - }; - while (!(arkTSLinterDiagnosticProcessed)) { - await sleep(sleepInterval); + service = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); } - worker.terminate(); - worker = undefined; -} -export function sendtsDiagnostic(allDiagnostics: ts.Diagnostic[]):void { - tsDiagnostics = processDiagnosticsToArkTSDiagnosticInfo(allDiagnostics.filter(diag=>diag.file.scriptKind === ts.ScriptKind.ETS)); - if (strictArkTSDiagnostics !== undefined) { - processArkTSLinterDiagnostic(); - cleanProcessArkTSLinterDiagnostic(); - } + service.updateRootFiles([...originProgram.getRootFileNames()]); + rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).setCache(cacheServiceKey, service); + + return service.getBuilderProgram(); } -export function processDiagnosticsToArkTSDiagnosticInfo(diagnostics: ts.Diagnostic[]): ArkTSDiagnostic[] { - let diagnosticsInfo: ArkTSDiagnostic[] = []; - for (const diagnostic of diagnostics) { - const { line, character }: ts.LineAndCharacter = - diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!); - diagnosticsInfo.push( - { - fileName: diagnostic.file?.fileName, - line: line, - character: character, - category: diagnostic.category, - code: diagnostic.code, - file: undefined, - start: diagnostic.start, - length: diagnostic.length, - messageText: diagnostic.messageText, - } - ); +function getStrictOptions(strict = true) { + return { + strictNullChecks: strict, + strictFunctionTypes: strict, + strictPropertyInitialization: strict, + noImplicitReturns: strict, }; - return diagnosticsInfo; } -function filterStaticDiagnostics(): ArkTSDiagnostic[] { - tsDiagnostics.forEach(diag => { - if (!diag.fileName) { - return; - } - strictArkTSDiagnostics.get(diag.fileName)?.strictDiagnostics.forEach( - strictDiag => { - if (strictDiag.code === diag.code && strictDiag.start === diag.start && strictDiag.length === diag.length) { - strictDiag.code = filteredDiagnosticCode; - return; - } - } - ); +/** + * Returns true if options were initially strict + */ +export function inverseStrictOptions(compilerOptions: ts.CompilerOptions): boolean { + const strictOptions = getStrictOptions(); + let wasStrict = false; + Object.keys(strictOptions).forEach(x => { + wasStrict = wasStrict || !!compilerOptions[x]; }); - - let resultDiagnostics: ArkTSDiagnostic[] = []; - strictArkTSDiagnostics.forEach( - (value) => { - value.strictDiagnostics.forEach( - diagnostic => { - if (diagnostic.code === filteredDiagnosticCode) { - return; - } - resultDiagnostics.push(diagnostic); - } - ); - value.arkTSDiagnostics.forEach(diagnostic => { resultDiagnostics.push(diagnostic); }); - } - ); - - tsDiagnostics = undefined; - strictArkTSDiagnostics = undefined; - return resultDiagnostics; + // wasStrict evaluates true if any of the strict options was set + return wasStrict; } diff --git a/compiler/src/do_arkTS_linter_parallel.ts b/compiler/src/do_arkTS_linter_parallel.ts deleted file mode 100644 index c3ce5dec1e41bb2cf270f697c06883d28edc8f06..0000000000000000000000000000000000000000 --- a/compiler/src/do_arkTS_linter_parallel.ts +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as ts from 'typescript'; -import path from 'path'; -import { - projectConfig, - partialUpdateConfig -} from '../main'; -import { - compilerOptions, - resolveModuleNames, - resolveTypeReferenceDirectives, - setCompilerOptions, - readDeaclareFiles, - buildInfoWriteFile -} from './ets_checker'; -import type { ArkTSDiagnostic } from './do_arkTS_linter'; -import { - ArkTSVersion, - processDiagnosticsToArkTSDiagnosticInfo -} from './do_arkTS_linter'; -import { parentPort, workerData } from 'worker_threads'; - -const STRICT_TS_BUILD_INFO_SUFFIX = 'inversedArkTsLinter.tsbuildinfo'; - -function init(): void { - Object.assign(partialUpdateConfig, workerData.partialUpdateConfig); - Object.assign(projectConfig, workerData.projectConfig); - Object.assign(process.env, workerData.processEnv); -} - -function createStrictProgram(): ts.BuilderProgram | undefined { - setCompilerOptions(workerData.resolveModulePaths); - Object.assign(compilerOptions, { - 'noImplicitReturns': true, - 'strictFunctionTypes': true, - 'strictNullChecks': true, - 'strictPropertyInitialization': true, - 'allowJs': true, - 'checkJs': true - }); - const compilerHost: ts.CompilerHost = ts.createIncrementalCompilerHost(compilerOptions); - compilerHost.resolveModuleNames = resolveModuleNames; - compilerHost.getCurrentDirectory = (): string => process.cwd(); - compilerHost.getDefaultLibFileName = (options): string => ts.getDefaultLibFilePath(options); - compilerHost.resolveTypeReferenceDirectives = resolveTypeReferenceDirectives; - const createProgramOptions = { - rootNames: [...workerData.rootFileNames, ...readDeaclareFiles()], - host: compilerHost, - options: compilerOptions, - }; - createProgramOptions.options.tsBuildInfoFile = compilerOptions.tsBuildInfoFile && - path.resolve(projectConfig.cachePath, '..', STRICT_TS_BUILD_INFO_SUFFIX); - const program = ts.createIncrementalProgram(createProgramOptions); - return program; -} - -function doArkTSLinterParallel(): void { - init(); - const strictBuilderProgram = createStrictProgram()!; - let strictDiagnostics: ts.ESMap; - if (workerData.arkTSVersion === ArkTSVersion.ArkTS_1_0) { - strictDiagnostics = ts.ArkTSLinter_1_0.getDiagnosticsFromStrictProgram(strictBuilderProgram, buildInfoWriteFile); - } else { - strictDiagnostics = ts.ArkTSLinter_1_1.getDiagnosticsFromStrictProgram(strictBuilderProgram, buildInfoWriteFile); - } - - let diagnostics = new Map(); - strictDiagnostics.forEach( - (value, key) => { - diagnostics.set(key, { - strictDiagnostics : processDiagnosticsToArkTSDiagnosticInfo(value.strictDiagnostics), - arkTSDiagnostics: processDiagnosticsToArkTSDiagnosticInfo(value.arkTSDiagnostics), - }); - } - ); - parentPort.postMessage(diagnostics); -} - -doArkTSLinterParallel(); \ No newline at end of file diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 1785668c53cff50ba777bd128f33cf7b79c7286b..78b02877458566ea076ee7db46d539b8ead64a14 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -16,8 +16,8 @@ import fs from 'fs'; import path from 'path'; import * as ts from 'typescript'; -const fse = require('fs-extra'); import * as crypto from 'crypto'; +const fse = require('fs-extra'); import { projectConfig, @@ -73,10 +73,7 @@ import { INNER_COMPONENT_NAMES, JS_BIND_COMPONENTS } from './component_map'; -import { - props, - logger -} from './compile_info'; +import { logger } from './compile_info'; import { hasDecorator, isString, @@ -87,21 +84,23 @@ import { stopTimeStatisticsLocation, resolveModuleNamesTime, CompilationTimeStatistics, - storedFileInfo + storedFileInfo, + getRollupCacheManagerKey } from './utils'; import { isExtendFunction, isOriginalExtend } from './process_ui_syntax'; import { visualTransform } from './process_visual'; import { tsWatchEmitter } from './fast_build/ets_ui/rollup-plugin-ets-checker'; import { doArkTSLinter, - doArkTSLinterParallel, ArkTSLinterMode, - ArkTSDiagnostic, - sendtsDiagnostic, - ArkTSVersion + ArkTSProgram, + ArkTSVersion, + getReverseStrictBuilderProgram, + inverseStrictOptions } from './do_arkTS_linter'; export const SOURCE_FILES: Map = new Map(); +export var props: string[] = []; function collectSourceFilesMap(program: ts.Program): void { program.getSourceFiles().forEach((sourceFile: ts.SourceFile) => { @@ -120,7 +119,7 @@ export function readDeaclareFiles(): string[] { return declarationsFileNames; } -export const buildInfoWriteFile: ts.WriteFileCallback = (fileName: string, data: string) => { +const buildInfoWriteFile: ts.WriteFileCallback = (fileName: string, data: string) => { if (fileName.endsWith(TS_BUILD_INFO_SUFFIX)) { let fd: number = fs.openSync(fileName, 'w'); fs.writeSync(fd, data, undefined, 'utf8'); @@ -130,7 +129,7 @@ export const buildInfoWriteFile: ts.WriteFileCallback = (fileName: string, data: export const compilerOptions: ts.CompilerOptions = ts.readConfigFile( path.resolve(__dirname, '../tsconfig.json'), ts.sys.readFile).config.compilerOptions; -export function setCompilerOptions(resolveModulePaths: string[]): void { +function setCompilerOptions(resolveModulePaths: string[]) { const allPath: Array = [ '*' ]; @@ -256,7 +255,7 @@ interface extendInfo { compName: string } -export const files: ts.MapLike<{ version: number }> = {}; +export let files: ts.MapLike<{ version: number }> = {}; function createHash(str: string): string { const hash = crypto.createHash('sha256'); @@ -264,7 +263,7 @@ function createHash(str: string): string { return hash.digest('hex'); } -const fileHashScriptVersion: (fileName: string) => string = (fileName: string) => { +export const fileHashScriptVersion: (fileName: string) => string = (fileName: string) => { return createHash(fs.readFileSync(fileName).toString()); } @@ -276,7 +275,7 @@ const watchModeScriptVersion: (fileName: string) => string = (fileName: string) } export function createLanguageService(rootFileNames: string[], resolveModulePaths: string[], - compilationTime: CompilationTimeStatistics = null): ts.LanguageService { + compilationTime: CompilationTimeStatistics = null, rollupShareObject?: any): ts.LanguageService { setCompilerOptions(resolveModulePaths); rootFileNames.forEach((fileName: string) => { files[fileName] = {version: 0}; @@ -318,9 +317,35 @@ export function createLanguageService(rootFileNames: string[], resolveModulePath checkPayload: undefined, currentFileName: containFilePath, }; + }, + getProps: () => { + return props; + }, + clearProps: () => { + dollarCollection.clear(); + decoratorParamsCollection.clear(); + extendCollection.clear(); + props = [] } }; - return ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); + + if (process.env.watchMode === 'true') { + return ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); + } + + let cacheManagerKey: string = getRollupCacheManagerKey(projectConfig); + let cacheServiceKey: string = 'service'; + let service: ts.LanguageService | undefined = + rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).getCache(cacheServiceKey); + if (!service) { + service = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); + } + + let updateRootFileNames = [...rootFileNames, ...readDeaclareFiles()]; + service.updateRootFiles(updateRootFileNames); + + rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).setCache(cacheServiceKey, service); + return service; } interface CacheFileName { @@ -358,7 +383,7 @@ export const checkerResult: CheckerResult = {count: 0}; export const warnCheckerResult: WarnCheckerResult = {count: 0}; export let languageService: ts.LanguageService = null; export function serviceChecker(rootFileNames: string[], newLogger: any = null, resolveModulePaths: string[] = null, parentEvent?: any, - compilationTime: CompilationTimeStatistics = null): void { + compilationTime: CompilationTimeStatistics = null, rollupShareObject?: any): void { fastBuildLogger = newLogger; let cacheFile: string = null; if (projectConfig.xtsMode || process.env.watchMode === 'true') { @@ -367,7 +392,6 @@ export function serviceChecker(rootFileNames: string[], newLogger: any = null, r hotReloadSupportFiles.add(fileName); }); } - runArkTSLinterParallel(rootFileNames, resolveModulePaths, cacheFile); languageService = createLanguageService(rootFileNames, resolveModulePaths, compilationTime); } else { cacheFile = path.resolve(projectConfig.cachePath, '../.ts_checker_cache'); @@ -379,17 +403,16 @@ export function serviceChecker(rootFileNames: string[], newLogger: any = null, r } else { cache = {}; } - const filterFiles: string[] = filterInput(rootFileNames); - runArkTSLinterParallel(filterFiles, resolveModulePaths, cacheFile); - languageService = createLanguageService(filterFiles, resolveModulePaths, compilationTime); + languageService = createLanguageService(rootFileNames, resolveModulePaths, compilationTime, rollupShareObject); } startTimeStatisticsLocation(compilationTime ? compilationTime.createProgramTime : undefined); - globalProgram.builderProgram = languageService.getBuilderProgram(); globalProgram.program = globalProgram.builderProgram.getProgram(); - + props = languageService.getProps(); stopTimeStatisticsLocation(compilationTime ? compilationTime.createProgramTime : undefined); - collectSourceFilesMap(globalProgram.program); + startTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); + runArkTSLinter(parentEvent, rollupShareObject); + stopTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); if (process.env.watchMode !== 'true') { processBuildHap(cacheFile, rootFileNames, compilationTime); } @@ -400,7 +423,6 @@ function processBuildHap(cacheFile: string, rootFileNames: string[], compilation const allDiagnostics: ts.Diagnostic[] = globalProgram.builderProgram .getSyntacticDiagnostics() .concat(globalProgram.builderProgram.getSemanticDiagnostics()); - sendtsDiagnostic(allDiagnostics); stopTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); globalProgram.builderProgram.emitBuildInfo(buildInfoWriteFile); @@ -465,14 +487,14 @@ function containFormError(message: string): boolean { return false; } -export function printDiagnostic(diagnostic: ts.Diagnostic, isArkTSDiagnostic: boolean = false): void { +export function printDiagnostic(diagnostic: ts.Diagnostic): void { const message: string = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); if (validateError(message)) { if (process.env.watchMode !== 'true' && !projectConfig.xtsMode) { updateErrorFileCache(diagnostic); } - if (containFormError(message) && diagnostic.file && !isCardFile(diagnostic.file.fileName)) { + if (containFormError(message) && !isCardFile(diagnostic.file.fileName)) { return; } @@ -489,12 +511,7 @@ export function printDiagnostic(diagnostic: ts.Diagnostic, isArkTSDiagnostic: bo diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!); logMessage = `ArkTS:${logPrefix} File: ${diagnostic.file.fileName}:${line + 1}:${character + 1}\n ${message}\n`; } else { - if (!isArkTSDiagnostic) { - logMessage = `ArkTS:${logPrefix}: ${message}`; - } else { - const arkTSDiagnostic = diagnostic as ArkTSDiagnostic; - logMessage = `ArkTS:${logPrefix} File: ${arkTSDiagnostic.fileName}:${arkTSDiagnostic.line + 1}:${arkTSDiagnostic.character + 1}\n ${message}\n`; - } + logMessage = `ArkTS:${logPrefix}: ${message}`; } if (diagnostic.category === ts.DiagnosticCategory.Error) { @@ -1090,10 +1107,26 @@ export function incrementWatchFile(watchModifiedFiles: string[], }); } -function runArkTSLinter(parentEvent?: any): void { +function runArkTSLinter(parentEvent?: any, rollupShareObject?: any): void { const eventRunArkTsLinter = createAndStartEvent(parentEvent, 'run Arkts linter'); - const arkTSLinterDiagnostics = doArkTSLinter(getArkTSVersion(), globalProgram.builderProgram, getArkTSLinterMode(), - printArkTSLinterDiagnostic, !projectConfig.xtsMode, buildInfoWriteFile); + + let wasStrict: boolean = inverseStrictOptions(globalProgram.program.getCompilerOptions()); + let originProgram: ArkTSProgram = { + builderProgram: globalProgram.builderProgram, + wasStrict: wasStrict + }; + let reverseStrictProgram: ArkTSProgram = { + builderProgram: getReverseStrictBuilderProgram(rollupShareObject, globalProgram.program, wasStrict), + wasStrict: !wasStrict + }; + const arkTSLinterDiagnostics = doArkTSLinter(getArkTSVersion(), + getArkTSLinterMode(), + originProgram, + reverseStrictProgram, + printArkTSLinterDiagnostic, + !projectConfig.xtsMode, + buildInfoWriteFile); + if (process.env.watchMode !== 'true' && !projectConfig.xtsMode) { arkTSLinterDiagnostics.forEach((diagnostic: ts.Diagnostic) => { updateErrorFileCache(diagnostic); @@ -1102,36 +1135,24 @@ function runArkTSLinter(parentEvent?: any): void { stopEvent(eventRunArkTsLinter); } -function runArkTSLinterParallel(rootFileNames: string[], resolveModulePaths: string[], cacheFile: string): void { - doArkTSLinterParallel( - getArkTSVersion(), - getArkTSLinterMode(), - printArkTSLinterDiagnostic, - rootFileNames, - resolveModulePaths, - cacheFile, - !projectConfig.xtsMode - ); -} - -function printArkTSLinterDiagnostic(diagnostic: ts.Diagnostic, isArkTSDiagnostic: boolean): void { +function printArkTSLinterDiagnostic(diagnostic: ts.Diagnostic): void { if (diagnostic.category === ts.DiagnosticCategory.Error && (isInOhModuleFile(diagnostic) || isInSDK(diagnostic))) { const originalCategory = diagnostic.category; diagnostic.category = ts.DiagnosticCategory.Warning; - printDiagnostic(diagnostic, isArkTSDiagnostic); + printDiagnostic(diagnostic); diagnostic.category = originalCategory; return; } - printDiagnostic(diagnostic, isArkTSDiagnostic); + printDiagnostic(diagnostic); } function isInOhModuleFile(diagnostics: ts.Diagnostic): boolean { - const fileName = diagnostics.file ? diagnostics.file.fileName : (diagnostics as ArkTSDiagnostic).fileName; - return ((fileName.indexOf('/oh_modules/') !== -1) || fileName.indexOf('\\oh_modules\\') !== -1); + return (diagnostics.file !== undefined) && + ((diagnostics.file.fileName.indexOf('/oh_modules/') !== -1) || diagnostics.file.fileName.indexOf('\\oh_modules\\') !== -1); } function isInSDK(diagnostics: ts.Diagnostic): boolean { - const fileName = diagnostics.file ? diagnostics.file.fileName : (diagnostics as ArkTSDiagnostic).fileName; + const fileName = diagnostics.file?.fileName; if (projectConfig.etsLoaderPath === undefined || fileName === undefined) { return false; } @@ -1214,6 +1235,7 @@ export function etsStandaloneChecker(entryObj, logger, projectConfig): void { const filterFiles: string[] = filterInput(rootFileNames); languageService = createLanguageService(filterFiles, resolveModulePaths); globalProgram.builderProgram = languageService.getBuilderProgram(); + globalProgram.program = globalProgram.builderProgram.getProgram(); runArkTSLinter(); const allDiagnostics: ts.Diagnostic[] = globalProgram.builderProgram .getSyntacticDiagnostics() @@ -1223,4 +1245,17 @@ export function etsStandaloneChecker(entryObj, logger, projectConfig): void { allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { printDiagnostic(diagnostic); }); -} \ No newline at end of file +} + +export function resetEtsCheck() { + files = {}; + cache = {}; + languageService = null; + allResolvedModules.clear(); + checkerResult.count = 0; + warnCheckerResult.count = 0; + resolvedModulesCache.clear(); + dollarCollection.clear(); + decoratorParamsCollection.clear(); + extendCollection.clear(); +} diff --git a/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts b/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts index 042fb282e8dda9eedeec29596b82e4cad1c8136b..4b1831361191caaa7029356427091b3f4bada4a8 100644 --- a/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts +++ b/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts @@ -626,6 +626,11 @@ export function writeObfuscationNameCache(projectConfig:any, obfuscationCacheDir if (printNameCache && printNameCache.length > 0) { fs.writeFileSync(printNameCache, writeContent); } + renamePropertyModule.globalMangledTable?.clear(); + renamePropertyModule.historyMangledTable?.clear(); + renameFileNameModule.globalFileNameMangledTable?.clear(); + renameFileNameModule.globalFileNameMangledTable?.clear(); + ApiExtractor.mPropertySet?.clear(); } export function generateConsumerObConfigFile(obfuscationOptions: any, logger: any) { diff --git a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts index a44dd88110fba71adfb94db7aebe9526e7f61a6d..58c4c1b5c4d88a76bd6c0b71111675d268e66636 100644 --- a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts +++ b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts @@ -23,13 +23,8 @@ import { import { TS2ABC, ESMODULE, - AOT_FULL, - AOT_PARTIAL, - AOT_TYPE, - AOT_PROFILE_SUFFIX, NODE_MODULES, OH_MODULES, - FAIL, OBFUSCATION_TOOL } from './ark_define'; import { isAotMode, isDebug } from '../utils'; @@ -59,20 +54,29 @@ type ArkConfig = { isDebug: boolean; }; -let arkConfig: ArkConfig = {}; export function initArkConfig(projectConfig: any) { let arkRootPath: string = path.join(__dirname, '..', '..', '..', '..', 'bin', 'ark'); if (projectConfig.arkFrontendDir) { arkRootPath = projectConfig.arkFrontendDir; } + let arkConfig: ArkConfig = { + arkRootPath: '', + ts2abcPath: '', + js2abcPath: '', + mergeAbcPath: '', + es2abcPath: '', + aotCompilerPath: '', + nodePath: '', + isDebug: false + }; arkConfig.nodePath = 'node'; if (projectConfig.nodeJs) { arkConfig.nodePath = projectConfig.nodePath; } - processPlatformInfo(arkRootPath); - processCompatibleVersion(projectConfig, arkRootPath); arkConfig.isDebug = isDebug(projectConfig); arkConfig.arkRootPath = arkRootPath; + processPlatformInfo(arkConfig); + processCompatibleVersion(projectConfig, arkConfig); return arkConfig; } @@ -155,7 +159,7 @@ function initObfuscationConfig(projectConfig: any, arkProjectConfig: any, logger } let projectAndLibs: {projectAndLibsReservedProperties: string[]; libExportNames: string[]}; if (mergedObConfig.options.enablePropertyObfuscation || mergedObConfig.options.enableExportObfuscation) { - projectAndLibs = readProjectProperties([projectConfig.modulePath], + projectAndLibs = readProjectProperties([projectConfig.modulePath], { mNameObfuscation: {mReservedProperties: [], mKeepStringProperty: !mergedObConfig.options.enableStringPropertyObfuscation}, mExportObfuscation: mergedObConfig.options.enableExportObfuscation @@ -282,8 +286,8 @@ function initArkGuardConfig(obfuscationCacheDir: string | undefined, logger: any return arkObfuscator; } -function processPlatformInfo(arkRootPath: string): void { - const arkPlatformPath: string = getArkBuildDir(arkRootPath); +function processPlatformInfo(arkConfig: ArkConfig): void { + const arkPlatformPath: string = getArkBuildDir(arkConfig.arkRootPath); if (isWindows()) { arkConfig.es2abcPath = path.join(arkPlatformPath, 'bin', 'es2abc.exe'); arkConfig.ts2abcPath = path.join(arkPlatformPath, 'src', 'index.js'); @@ -302,8 +306,8 @@ function processPlatformInfo(arkRootPath: string): void { } } -function processCompatibleVersion(projectConfig: any, arkRootPath: string) { - const platformPath: string = getArkBuildDir(arkRootPath); +function processCompatibleVersion(projectConfig: object, arkConfig: ArkConfig): void { + const platformPath: string = getArkBuildDir(arkConfig.arkRootPath); if (projectConfig.minPlatformVersion && projectConfig.minPlatformVersion.toString() === '8') { // use ts2abc to compile apps with 'CompatibleSdkVersion' set to 8 arkConfig.ts2abcPath = path.join(platformPath, 'legacy_api8', 'src', 'index.js'); diff --git a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts index f6cb44abd63c2f55d709b5dc6f790f0b9065f313..bcbcd0c70eecdf80433c7555f0d88b036e100ab9 100644 --- a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts +++ b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts @@ -14,6 +14,7 @@ */ import { ESMODULE } from './common/ark_define'; +import type { ModuleMode } from './module/module_mode'; import { ModuleBuildMode } from './module/module_build_mode'; import { ModuleHotfixMode } from './module/module_hotfix_mode'; import { ModuleHotreloadMode } from './module/module_hotreload_mode'; @@ -25,6 +26,8 @@ import { stopEvent } from '../../utils'; +let moduleMode: ModuleMode = null; + export async function generateModuleAbc(error) { const hookEventFactory = getHookEventFactory(this.share, 'genAbc', 'buildEnd'); if (error) { @@ -47,15 +50,27 @@ function generateAbc(rollupObject: any, parentEvent: any) { if (rollupObject.share.projectConfig.watchMode !== 'true') { const moduleBuildMode: ModuleBuildMode = new ModuleBuildMode(rollupObject); moduleBuildMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = moduleBuildMode; } else if (rollupObject.share.arkProjectConfig.hotReload) { const moduleHotreloadMode: ModuleHotreloadMode = new ModuleHotreloadMode(rollupObject); moduleHotreloadMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = moduleHotreloadMode; } else if (rollupObject.share.arkProjectConfig.hotFix) { const moduleHotfixMode: ModuleHotfixMode = new ModuleHotfixMode(rollupObject); moduleHotfixMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = moduleHotfixMode; } else { const modulePreviewMode: ModulePreviewMode = new ModulePreviewMode(rollupObject); modulePreviewMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = modulePreviewMode; } stopEvent(eventGenerateAbc); } + +export function cleanModuleMode() { + if (moduleMode) { + moduleMode.triggerAsync = null; + moduleMode.triggerEndSignal = null; + moduleMode = null; + } +} \ No newline at end of file diff --git a/compiler/src/fast_build/ark_compiler/module/module_hotreload_mode.ts b/compiler/src/fast_build/ark_compiler/module/module_hotreload_mode.ts index 05cb3f5312449a8f677654b765e917e6709c7d95..e2a914a8830dc48dde29707c4629f2487da853be 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_hotreload_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_hotreload_mode.ts @@ -35,7 +35,6 @@ import { } from '../../../utils'; let isFirstBuild: boolean = true; -let hotReloadSourceMap: Object = {}; export class ModuleHotreloadMode extends ModuleMode { symbolMapFilePath: string; @@ -110,7 +109,6 @@ export class ModuleHotreloadMode extends ModuleMode { mkdirsSync(this.projectConfig.patchAbcPath); } - this.updateSourceMapFromFileList(changedFileList, parentEvent); const outputABCPath: string = path.join(this.projectConfig.patchAbcPath, MODULES_ABC); validateFilePathLength(outputABCPath, this.logger); @@ -122,6 +120,7 @@ export class ModuleHotreloadMode extends ModuleMode { const eventUpdateSourceMapFromFileList = createAndStartEvent(parentEvent, 'update source map from file list'); const relativeProjectPath: string = this.projectConfig.projectPath.slice( this.projectConfig.projectRootPath.length + path.sep.length); + let hotReloadSourceMap: Object = {}; for (const file of fileList) { const sourceMapPath: string = toUnixPath(path.join(relativeProjectPath, file)); validateFilePathLength(sourceMapPath, this.logger); diff --git a/compiler/src/fast_build/ark_compiler/module/module_mode.ts b/compiler/src/fast_build/ark_compiler/module/module_mode.ts index c3d5a42f0240d26c750a696c98622ece899b974b..a8a064251527bc090262480b4e4944b233ab3042 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -766,4 +766,4 @@ export class ModuleMode extends CommonMode { delete sourceMap[key]; }); } -} +} \ No newline at end of file diff --git a/compiler/src/fast_build/ark_compiler/process_mock.ts b/compiler/src/fast_build/ark_compiler/process_mock.ts index d8c48a0eb11e97d13d28eb2b0886a9c154a6f52b..7e170dec70d35b946e343940365c7b2519f95a62 100644 --- a/compiler/src/fast_build/ark_compiler/process_mock.ts +++ b/compiler/src/fast_build/ark_compiler/process_mock.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import ts, { NodeArray } from 'typescript'; +import ts from 'typescript'; import { projectConfig } from '../../../main'; import { DECORATOR_SUFFIX } from '../../pre_define'; diff --git a/compiler/src/fast_build/ark_compiler/rollup-plugin-gen-abc.ts b/compiler/src/fast_build/ark_compiler/rollup-plugin-gen-abc.ts index 6667863a6c55b74e1c383fe5e49dfe30e2c1d448..c4d2f5cba90158835c21c58ff56fae9803625c52 100644 --- a/compiler/src/fast_build/ark_compiler/rollup-plugin-gen-abc.ts +++ b/compiler/src/fast_build/ark_compiler/rollup-plugin-gen-abc.ts @@ -20,6 +20,7 @@ import { transformForModule } from './transform'; import { checkArkCompilerCacheInfo, shouldInvalidCache } from './cache'; import { checkIfJsImportingArkts } from './check_import_module'; import { compilerOptions } from '../../ets_checker'; +import { cleanUpObjects } from './utils'; export function genAbc() { return { @@ -40,6 +41,7 @@ export function genAbc() { } }, buildEnd: generateModuleAbc, - generateBundle: generateBundleAbc + generateBundle: generateBundleAbc, + cleanUp: cleanUpObjects }; } diff --git a/compiler/src/fast_build/ark_compiler/transform.ts b/compiler/src/fast_build/ark_compiler/transform.ts index 5e69b119d10033e3322b4849f893cb5af137cf73..d266236d6c2dd13e941250c7af80c879137eb606 100644 --- a/compiler/src/fast_build/ark_compiler/transform.ts +++ b/compiler/src/fast_build/ark_compiler/transform.ts @@ -94,3 +94,7 @@ function transformJsByBabelPlugin(code: string, parentEvent: any): any { stopEvent(eventTransformByBabel); return transformed; } + +export function cleanSourceMapObject(): void { + newSourceMaps = {}; +} \ No newline at end of file diff --git a/compiler/src/fast_build/ark_compiler/utils.ts b/compiler/src/fast_build/ark_compiler/utils.ts index 6155d93de97ea3f3a41ae081b1b18f70e78599ab..1aac35ee7f07aab2e8ea0edefd131a426409e581 100644 --- a/compiler/src/fast_build/ark_compiler/utils.ts +++ b/compiler/src/fast_build/ark_compiler/utils.ts @@ -37,17 +37,19 @@ import { validateFilePathLength, toUnixPath, createAndStartEvent, - stopEvent, - harFilesRecord + stopEvent } from '../../utils'; -import type { GeneratedFileInHar } from '../../utils'; import { tryMangleFileNameAndWriteFile, - writeObfuscatedSourceCode + writeObfuscatedSourceCode, + cleanUpUtilsObjects } from '../../ark_utils'; import { AOT_FULL, AOT_PARTIAL, AOT_TYPE } from '../../pre_define'; import { newSourceMaps } from './transform'; import { hasTsNoCheckOrTsIgnoreFiles, compilingEtsOrTsFiles } from '../../process_kit_import'; +import { cleanSourceMapObject } from './transform'; +import { cleanUpKitImportObjects } from '../../process_kit_import'; +import { cleanModuleMode } from './generate_module_abc'; export function needAotCompiler(projectConfig: any): boolean { return projectConfig.compileMode === ESMODULE && (projectConfig.anBuildMode === AOT_FULL || @@ -232,6 +234,14 @@ export async function updateSourceMap(originMap: sourceMap.RawSourceMap, newMap: updatedGenerator['_mappings']['_array'] = newMappingList; return JSON.parse(updatedGenerator.toString()); } + +export function cleanUpObjects(): void { + cleanSourceMapObject(); + cleanUpUtilsObjects(); + cleanUpKitImportObjects(); + cleanModuleMode(); +} + export const utUtils = { writeFileContent } \ No newline at end of file diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts index ed63ec870b25c5c729fb9b8fe9812c8c0c0e26e3..e062f8b88831611ce93b0418649b50edbfd62905 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts @@ -37,12 +37,6 @@ import { CompilationTimeStatistics, getHookEventFactory } from '../../utils'; -import { - waitArkTSLinterFinished, - updateFileCache, - resetDidArkTSLinter, - sendtsDiagnostic -} from '../../do_arkTS_linter'; export let tsWatchEmitter: EventEmitter | undefined = undefined; export let tsWatchEndPromise: Promise; @@ -54,8 +48,14 @@ export function etsChecker() { buildStart() { const hookEventFactory = getHookEventFactory(this.share, 'etsChecker', 'buildStart'); const compilationTime: CompilationTimeStatistics = new CompilationTimeStatistics(this.share, 'etsChecker', 'buildStart'); - resetDidArkTSLinter(); - setTsWatch(); + if (process.env.watchMode === 'true' && process.env.triggerTsWatch === 'true') { + tsWatchEmitter = new EventEmitter(); + tsWatchEndPromise = new Promise(resolve => { + tsWatchEmitter.on(TS_WATCH_END_MSG, () => { + resolve(); + }); + }); + } Object.assign(projectConfig, this.share.projectConfig); Object.assign(this.share.projectConfig, { compileHar: projectConfig.compileHar, @@ -76,48 +76,28 @@ export function etsChecker() { } const eventServiceChecker = createAndStartEvent(hookEventFactory, 'check Ets code syntax'); if (process.env.watchMode === 'true') { - !executedOnce && serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, compilationTime); + !executedOnce && serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, + compilationTime); executedOnce = true; - getAllDiagnostics(compilationTime); + startTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); + globalProgram.program = languageService.getProgram(); + const allDiagnostics: ts.Diagnostic[] = globalProgram.program + .getSyntacticDiagnostics() + .concat(globalProgram.program.getSemanticDiagnostics()) + .concat(globalProgram.program.getDeclarationDiagnostics()); + stopTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); + allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { + printDiagnostic(diagnostic); + }); fastBuildLogger.debug(TS_WATCH_END_MSG); tsWatchEmitter.emit(TS_WATCH_END_MSG); } else { - serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, compilationTime); + serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, + compilationTime, this.share); } stopEvent(eventServiceChecker); setChecker(); - }, - beforeBuildEnd: { - order: 'pre', - async handler(): Promise { - await waitArkTSLinterFinished(); - updateFileCache(); - } } }; } -function setTsWatch(): void { - if (process.env.watchMode === 'true' && process.env.triggerTsWatch === 'true') { - tsWatchEmitter = new EventEmitter(); - tsWatchEndPromise = new Promise(resolve => { - tsWatchEmitter.on(TS_WATCH_END_MSG, () => { - resolve(); - }); - }); - } -} - -function getAllDiagnostics(compilationTime: CompilationTimeStatistics): void { - startTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); - globalProgram.program = languageService.getProgram(); - const allDiagnostics: ts.Diagnostic[] = globalProgram.program - .getSyntacticDiagnostics() - .concat(globalProgram.program.getSemanticDiagnostics()) - .concat(globalProgram.program.getDeclarationDiagnostics()); - stopTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); - allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { - printDiagnostic(diagnostic); - }); - sendtsDiagnostic(allDiagnostics); -} \ No newline at end of file diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts index ae20ed29efd0d2e9b8235a7aa944e872b81936c1..5d196c01e1e85ff11161d93713bb5a6a2e11819b 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts @@ -40,7 +40,8 @@ import { CompilationTimeStatistics, getHookEventFactory, genLoaderOutPathOfHar, - harFilesRecord + harFilesRecord, + resetUtils } from '../../utils'; import { preprocessExtend, @@ -49,39 +50,46 @@ import { propertyCollection, linkCollection, resetComponentCollection, - componentCollection + componentCollection, + resetValidateUiSyntax } from '../../validate_ui_syntax'; import { processUISyntax, resetLog, - transformLog + transformLog, + resetProcessUiSyntax } from '../../process_ui_syntax'; import { projectConfig, abilityPagesFullPath, - globalProgram + globalProgram, + resetMain } from '../../../main'; import { appComponentCollection, compilerOptions as etsCheckerCompilerOptions, resolveModuleNames, - resolveTypeReferenceDirectives + resolveTypeReferenceDirectives, + resetEtsCheck } from '../../ets_checker'; import { CUSTOM_BUILDER_METHOD, GLOBAL_CUSTOM_BUILDER_METHOD, - INNER_CUSTOM_BUILDER_METHOD + INNER_CUSTOM_BUILDER_METHOD, + resetComponentMap } from '../../component_map'; import { kitTransformLog, processKitImport } from '../../process_kit_import'; +import { resetCompileInfo } from '../../compile_info'; +import { resetProcessComponentMember } from '../../process_component_member'; const filter:any = createFilter(/(?> = new Map(); export function apiTransform() { const useOSFiles: Set = new Set(); - let hiresStatus: boolean = true; return { name: 'apiTransform', load(id: string) { allFiles.add(path.join(id)); }, transform(code: string, id: string) { - const magicString = new MagicString(code); if (filter(id)) { if (projectConfig.compileMode === "esmodule") { code = processSystemApiAndLibso(code, id, useOSFiles); - hiresStatus = false; + return { + code: code + }; } else { code = processSystemApi(code, id); code = processLibso(code, id, useOSFiles); - hiresStatus = true; + return { + code: code, + map: new MagicString(code).generateMap({ hires: true }) + }; } } - return { - code: code, - map: magicString.generateMap({ hires: hiresStatus }) - }; }, beforeBuildEnd() { this.share.allComponents = getAllComponentsOrModules(allFiles, 'component_collection.json'); @@ -79,6 +78,11 @@ export function apiTransform() { const allModules: Map> = getAllComponentsOrModules(allFiles, 'module_collection.json'); writeCollectionFile(projectConfig.cachePath, appImportModuleCollection, allModules, 'module_collection.json'); } + }, + cleanUp() { + allFiles.clear(); + appImportModuleCollection.clear(); + useOSFiles.clear(); } }; } diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 542e8f0d99070b07e8437a5a09542a17b1833d2e..39c04bd4960750c8f5a2c1facf7f6a6e25fe65a8 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -577,3 +577,4 @@ export const IS_INITIAL_ITEM = 'isInitialItem'; export const MY_IDS = 'myIds'; export const TS_BUILD_INFO_SUFFIX = '.tsbuildinfo'; +export const ARKTS_LINTER_BUILD_INFO_SUFFIX = 'inversedArkTsLinter.tsbuildinfo'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 2ef4eccddbfcd47e2382f934227f8a6848b89097..262161b55fb1825fa9a6d837e97ff46d0e0bf8d0 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -175,7 +175,7 @@ import { validatorCard, builderTypeParameter } from './process_ui_syntax'; -import { props } from './compile_info'; +import { props } from './ets_checker'; import { regularCollection } from './validate_ui_syntax'; const checkComponents: Set = new Set([ @@ -2962,14 +2962,14 @@ function isEtsComponent(node: ts.ExpressionStatement): boolean { } function isSomeName(forEachParameters: ts.NodeArray, name: string): boolean { - return Array.isArray(forEachParameters) && + return Array.isArray(forEachParameters) && forEachParameters.some((item)=>{ return ts.isIdentifier(item.name) ? item.name.escapedText.toString() === name : false; }); } function isParamFunction(node: ts.ExpressionStatement): boolean { - return node.expression && ts.isCallExpression(node.expression) && + return node.expression && ts.isCallExpression(node.expression) && node.expression.expression && ts.isIdentifier(node.expression.expression); } @@ -3194,3 +3194,4 @@ function checkNonspecificParents(node: ts.ExpressionStatement, name: string, sav } } } + diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 72b65f3afa94e4f244775736d9f1a6cc858a7c73..b883a3183d77e22986cca939875e03d97f885846 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -1269,3 +1269,7 @@ function isObserved(type: ts.Type): boolean { }); } } + +export function resetProcessComponentMember() { + decoratorParamSet.clear(); +} diff --git a/compiler/src/process_kit_import.ts b/compiler/src/process_kit_import.ts index e038c173d30992ff102850275a9180a863174334..9c7a5d2edc968102e38fab697f18215ec2aa142c 100644 --- a/compiler/src/process_kit_import.ts +++ b/compiler/src/process_kit_import.ts @@ -43,7 +43,7 @@ const KIT_PREFIX = '@kit.'; /* * This API is the TSC Transformer for transforming `KitImport` into `OhosImport` -* e.g. +* e.g. * ``` * import { ability, ErrorCode } from '@kit.AbilityKit' * ---> @@ -126,7 +126,7 @@ class SpecificerInfo { private importName: string; private symbol: KitSymbol; private renamed: boolean; - + private originElement: TSspecifier | undefined; constructor(localName: string, importName: string, symbol: KitSymbol, originElement: TSspecifier | undefined) { @@ -304,7 +304,7 @@ class KitInfo { getOhosImportNodes(): TSModuleDeclaration[] { return this.ohosImportNodes; } - + newSpecificerInfo(localName: string, importName: string, originElement: TSspecifier | undefined): void { const symbol: KitSymbol | undefined = this.symbols[importName]; if (symbol) { @@ -503,4 +503,8 @@ function getKitDefs(kitModuleRequest: string) { function trimSourceSuffix(source: string): string { return source.replace(/\.d.[e]?ts$/, ''); +} + +export function cleanUpKitImportObjects(): void { + kitTransformLog.cleanUp(); } \ No newline at end of file diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 8a6d1731047fc159d6026388730e8ab6e77a81de..9a25c70d94e7049c6afee4baee5bde641d8e79d1 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -134,7 +134,7 @@ import { createCustomComponentNewExpression, createViewCreate } from './process_ import { assignComponentParams } from './process_custom_component'; import { processDecorator } from './fast_build/ark_compiler/process_decorator'; -export const transformLog: FileLog = new FileLog(); +export let transformLog: FileLog = new FileLog(); export let contextGlobal: ts.TransformationContext; export let resourceFileName: string = ''; export const builderTypeParameter: {params: string[]} = {params: []}; @@ -1749,3 +1749,8 @@ export function validatorCard(log: any[], type: number, pos: number, log.push(logInfo); } } + +export function resetProcessUiSyntax() { + transformLog= new FileLog(); + contextGlobal = undefined; +} diff --git a/compiler/src/utils.ts b/compiler/src/utils.ts index 683344570ed2aa3b93839fc5c40636807ed086f9..6de8cd90cec8e61b78dd1ad9a89d0e4725e155eb 100644 --- a/compiler/src/utils.ts +++ b/compiler/src/utils.ts @@ -28,8 +28,6 @@ import { createHash } from 'crypto'; import { AUXILIARY, EXTNAME_ETS, - EXTNAME_CJS, - EXTNAME_MJS, EXTNAME_JS, MAIN, FAIL, @@ -69,7 +67,7 @@ export interface LogInfo { export const repeatLog: Map = new Map(); export class FileLog { - private _sourceFile: ts.SourceFile; + private _sourceFile: ts.SourceFile | undefined; private _errors: LogInfo[] = []; public get sourceFile() { @@ -87,6 +85,11 @@ export class FileLog { public set errors(newValue: LogInfo[]) { this._errors = newValue; } + + public cleanUp(): void { + this._sourceFile = undefined; + this._errors = []; + } } export function emitLogInfo(loader: any, infos: LogInfo[], fastBuild: boolean = false, @@ -174,7 +177,7 @@ class ComponentInfo { } } -export const componentInfo: ComponentInfo = new ComponentInfo(); +export let componentInfo: ComponentInfo = new ComponentInfo(); export function hasDecorator(node: ts.MethodDeclaration | ts.FunctionDeclaration | ts.StructDeclaration | ts.ClassDeclaration, decortorName: string, @@ -862,7 +865,7 @@ class ProcessFileInfo { } } -export const storedFileInfo: ProcessFileInfo = new ProcessFileInfo(); +export let storedFileInfo: ProcessFileInfo = new ProcessFileInfo(); export interface fileInfo extends tsFileInfo { hasEntry: boolean; // Has @Entry decorator or not @@ -956,6 +959,12 @@ export function isString(text: unknown): text is string { return typeof text === 'string'; } +export function getRollupCacheManagerKey(projectConfig: object): string { + let keyInfo: string[] = [projectConfig.compileSdkVersion, projectConfig.compatibleSdkVersion, projectConfig.runtimeOS, + projectConfig.etsLoaderPath, projectConfig.entryModuleName, projectConfig.widgetCompile]; + return keyInfo.join('#'); +} + export function getHookEventFactory(share: any, pluginName: string, hookName: string): any { if (typeof share.getHookEventFactory === 'function') { return share.getHookEventFactory(pluginName, hookName); @@ -1056,3 +1065,9 @@ interface CompileEvent { stopAsyncEvent(state?: CompileEventState, TIME?: number): void; createSubEvent(name: string): CompileEvent; } + +export function resetUtils() { + componentInfo = new ComponentInfo(); + harFilesRecord.clear(); + storedFileInfo = new ProcessFileInfo(); +} diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 81e4c24eee30b0979938b557b8016212e3f10c12..2a733c855c00401e0aab2395c53888dde79ed93a 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -1423,3 +1423,23 @@ export function getLocalStorageCollection(componentName: string, collection: Set } } } + +export function resetValidateUiSyntax(): void { + observedClassCollection.clear(); + enumCollection.clear(); + classMethodCollection.clear(); + dollarCollection.clear(); + stateCollection.clear(); + regularCollection.clear(); + storagePropCollection.clear(); + storageLinkCollection.clear(); + provideCollection.clear(); + consumeCollection.clear(); + builderParamObjectCollection.clear(); + localStorageLinkCollection.clear(); + localStoragePropCollection.clear(); + isStaticViewCollection.clear(); + useOSFiles.clear(); + sourcemapNamesCollection.clear(); + originalImportNamesMap.clear(); +} diff --git a/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts b/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts index c23df93098d2edf3bf74d9d540426642716a2537..f7594f095fdde681328d10968c332bac40863d74 100644 --- a/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts +++ b/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts @@ -279,12 +279,12 @@ mocha.describe('test process_ark_config file api', function () { mocha.it('4-1: test processCompatibleVersion under build debug', function () { this.rollup.build(); const arkConfig = initArkConfig(this.rollup.share.projectConfig); - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig,); expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; this.rollup.share.projectConfig.minPlatformVersion = 8; - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; }); @@ -292,12 +292,12 @@ mocha.describe('test process_ark_config file api', function () { mocha.it('4-2: test processCompatibleVersion under build release', function () { this.rollup.build(RELEASE); const arkConfig = initArkConfig(this.rollup.share.projectConfig); - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; this.rollup.share.projectConfig.minPlatformVersion = 8; - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; }); @@ -305,12 +305,12 @@ mocha.describe('test process_ark_config file api', function () { mocha.it('4-3: test processCompatibleVersion under preview debug', function () { this.rollup.preview(); const arkConfig = initArkConfig(this.rollup.share.projectConfig); - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; this.rollup.share.projectConfig.minPlatformVersion = 8; - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; }); @@ -318,12 +318,12 @@ mocha.describe('test process_ark_config file api', function () { mocha.it('4-4: test processCompatibleVersion under hot reload debug', function () { this.rollup.hotReload(); const arkConfig = initArkConfig(this.rollup.share.projectConfig); - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; this.rollup.share.projectConfig.minPlatformVersion = 8; - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; });