Fix logger was not initialized before use

Issue: #IAEDRI

Signed-off-by: wuhailong <wuhailong22@huawei.com>
Change-Id: Iedefdcfdf822550e609767b4b4303fc0be5ef41b
This commit is contained in:
wuhailong 2024-07-20 17:15:30 +08:00
parent b98e8a7558
commit 59891a84b7
16 changed files with 32 additions and 29 deletions

View File

@ -629,7 +629,7 @@ function containFormError(message: string): boolean {
let fileToIgnoreDiagnostics: Set<string> | undefined = undefined;
function collectFileToThrowDiagnostics(file: string, fileToThrowDiagnostics: Set<string>) {
function collectFileToThrowDiagnostics(file: string, fileToThrowDiagnostics: Set<string>): void {
const normalizedFilePath: string = path.resolve(file);
const unixFilePath: string = toUnixPath(file);
if (fileToThrowDiagnostics.has(unixFilePath)) {
@ -690,7 +690,7 @@ export function collectFileToIgnoreDiagnostics(rootFileNames: string[]): void {
fileToThrowDiagnostics.forEach(file => {
fileToIgnoreDiagnostics.delete(file);
})
});
}
export function printDiagnostic(diagnostic: ts.Diagnostic): void {
@ -1413,7 +1413,7 @@ function isEtsDeclFileInSdk(diagnostics: ts.Diagnostic): boolean {
if (diagnostics.file?.fileName === undefined) {
return false;
}
return isInSDK(diagnostics.file.fileName) && diagnostics.file.fileName.endsWith(".ets");
return isInSDK(diagnostics.file.fileName) && diagnostics.file.fileName.endsWith('.ets');
}
function isInOhModuleFile(diagnostics: ts.Diagnostic): boolean {

View File

@ -352,7 +352,7 @@ export class BundleMode extends CommonMode {
const cacheFilePath: string = this.filterIntermediateJsBundle[i].cacheFilePath;
const cacheAbcFilePath: string = changeFileExtension(cacheFilePath, EXTNAME_ABC);
if (!fs.existsSync(cacheFilePath) || !fs.existsSync(cacheAbcFilePath)) {
this.throwArkTsCompilerError(`ArkTS:INTERNAL ERROR: During hash JSON file generation, ` +
this.throwArkTsCompilerError('ArkTS:INTERNAL ERROR: During hash JSON file generation, ' +
`${cacheFilePath} or ${cacheAbcFilePath} is not found.`);
}
const hashCacheFileContentData: string = toHashData(cacheFilePath);
@ -370,7 +370,7 @@ export class BundleMode extends CommonMode {
const cacheAbcFilePath: string = changeFileExtension(value.cacheFilePath, EXTNAME_ABC);
if (!fs.existsSync(cacheAbcFilePath)) {
this.throwArkTsCompilerError(`ArkTS:INTERNAL ERROR: ${cacheAbcFilePath} not found during incremental build. ` +
`Please try to rebuild the project`);
'Please try to rebuild the project');
}
const parent: string = path.join(abcFilePath, '..');
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {

View File

@ -55,8 +55,8 @@ export abstract class CommonMode {
constructor(rollupObject: Object) {
this.projectConfig = Object.assign(rollupObject.share.arkProjectConfig, rollupObject.share.projectConfig);
this.arkConfig = initArkConfig(this.projectConfig);
this.cmdArgs = this.initCmdEnv();
this.logger = rollupObject.share.getLogger(GEN_ABC_PLUGIN_NAME);
this.cmdArgs = this.initCmdEnv();
this.throwArkTsCompilerError = rollupObject.share.throwArkTsCompilerError;
this.hashJsonFilePath = this.genHashJsonFilePath();
this.genAbcScriptPath = path.resolve(__dirname, GEN_ABC_SCRIPT);
@ -94,7 +94,7 @@ export abstract class CommonMode {
args.push('--debug-info');
}
} else {
this.throwArkTsCompilerError(`ArkTS:INTERNAL ERROR: Invalid compilation mode.`);
this.throwArkTsCompilerError('ArkTS:INTERNAL ERROR: Invalid compilation mode.');
}
return args;

View File

@ -39,7 +39,7 @@ export class ModuleBuildMode extends ModuleMode {
this.invokeTs2AbcWorkersToGenProto(splittedModules);
this.processTs2abcWorkersToGenAbc();
} else {
this.throwArkTsCompilerError(`ArkTS:INTERNAL ERROR: Invalid compilation mode.`);
this.throwArkTsCompilerError('ArkTS:INTERNAL ERROR: Invalid compilation mode.');
}
}
}

View File

@ -59,7 +59,7 @@ export class ModuleColdreloadMode extends ModuleMode {
}
}
addColdReloadArgs() {
addColdReloadArgs(): void {
if (isFirstBuild) {
this.cmdArgs.push('--dump-symbol-table');
this.cmdArgs.push(`"${this.symbolMapFilePath}"`);

View File

@ -736,7 +736,7 @@ export class ModuleMode extends CommonMode {
private genFileCachePath(filePath: string, projectRootPath: string, cachePath: string, metaInfo: Object): string {
const sufStr: string = toUnixPath(filePath).startsWith(toUnixPath(projectRootPath)) ?
toUnixPath(filePath).replace(toUnixPath(projectRootPath) + '/', '') :
toUnixPath(filePath).replace(toUnixPath(metaInfo.belongProjectPath) + '/', '')
toUnixPath(filePath).replace(toUnixPath(metaInfo.belongProjectPath) + '/', '');
const output: string = path.join(cachePath, sufStr);
return output;
}

View File

@ -285,7 +285,7 @@ export class ModuleSourceFile {
}
}
static newSourceFile(moduleId: string, source: string | ts.SourceFile, metaInfo: Object) {
static newSourceFile(moduleId: string, source: string | ts.SourceFile, metaInfo: Object): void {
ModuleSourceFile.sourceFiles.push(new ModuleSourceFile(moduleId, source, metaInfo));
}
@ -369,9 +369,11 @@ export class ModuleSourceFile {
private async writeSourceFile(parentEvent: Object): Promise<void> {
if (this.isSourceNode && !isJsSourceFile(this.moduleId)) {
await writeFileSyncByNode(<ts.SourceFile> this.source, ModuleSourceFile.projectConfig, this.metaInfo, this.moduleId, parentEvent, ModuleSourceFile.logger);
await writeFileSyncByNode(<ts.SourceFile> this.source, ModuleSourceFile.projectConfig, this.metaInfo,
this.moduleId, parentEvent, ModuleSourceFile.logger);
} else {
await writeFileContentToTempDir(this.moduleId, <string> this.source, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, parentEvent, this.metaInfo);
await writeFileContentToTempDir(this.moduleId, <string> this.source, ModuleSourceFile.projectConfig,
ModuleSourceFile.logger, parentEvent, this.metaInfo);
}
}
@ -407,11 +409,11 @@ export class ModuleSourceFile {
}
if (filePath) {
const targetModuleInfo: Object = rollupObject.getModuleInfo(filePath);
let res: string = "";
let res: string = '';
if (useNormalizedOHMUrl) {
res = ModuleSourceFile.spliceNormalizedOhmurl(targetModuleInfo, filePath, importerFile);
} else {
const moduleName: string = targetModuleInfo['meta']['moduleName'];
const moduleName: string = targetModuleInfo.meta.moduleName;
const ohmUrl: string =
getOhmUrlByFilepath(filePath, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, moduleName, importerFile);
res = ohmUrl.startsWith(PACKAGES) ? `@package:${ohmUrl}` : `@bundle:${ohmUrl}`;
@ -432,8 +434,8 @@ export class ModuleSourceFile {
private static spliceNormalizedOhmurl(moduleInfo: Object, filePath: string, importerFile?: string): string {
const pkgParams = {
pkgName: moduleInfo['meta']['pkgName'],
pkgPath: moduleInfo['meta']['pkgPath'],
pkgName: moduleInfo.meta.pkgName,
pkgPath: moduleInfo.meta.pkgPath,
isRecordName: false
};
const ohmUrl: string =

View File

@ -77,7 +77,7 @@ function preserveSourceMap(sourceFilePath: string, sourcemap: Object, projectCon
}
const eventAddSourceMapInfo = createAndStartEvent(parentEvent, 'preserve source map for ts/ets files');
const relativeSourceFilePath = sourceFilePath.startsWith(projectConfig.projectRootPath)?
const relativeSourceFilePath = sourceFilePath.startsWith(projectConfig.projectRootPath) ?
toUnixPath(sourceFilePath.replace(projectConfig.projectRootPath + path.sep, '')) :
toUnixPath(sourceFilePath.replace(metaInfo.belongProjectPath + path.sep, ''));
sourcemap.sources = [relativeSourceFilePath];

View File

@ -101,7 +101,7 @@ function removeCacheFile(cacheFilePath: string, ext: string): void {
}
export function shouldETSOrTSFileTransformToJS(filePath: string, projectConfig: Object): boolean {
const projectRootPath: string = getProjectRootPath(filePath, projectConfig, projectConfig?.rootPathSet)
const projectRootPath: string = getProjectRootPath(filePath, projectConfig, projectConfig?.rootPathSet);
const sufStr: string = toUnixPath(filePath).replace(toUnixPath(projectRootPath), '');
let cacheFilePath: string = path.join(projectConfig.cachePath, sufStr);

View File

@ -1088,7 +1088,7 @@ function handleHotReloadChangedFiles() {
let changedFileListJson: string = fs.readFileSync(projectConfig.changedFileList).toString();
let changedFileList: Array<string> = JSON.parse(changedFileListJson).modifiedFiles;
if (typeof(changedFileList) === "undefined" || changedFileList.length === 0) {
if (typeof(changedFileList) === 'undefined' || changedFileList.length === 0) {
return;
}

View File

@ -92,7 +92,7 @@ export function generateAot(arkDir: string, appAbc: string,
const appAot: string = path.join(projectConfig.anBuildOutPut, projectConfig.moduleName);
if (!validateFilePathLengths([aotCompiler, appAbc, appAot], logger)) {
faultHandler(`ArkTS:ERROR GenerateAot failed. Invalid file path.`);
faultHandler('ArkTS:ERROR GenerateAot failed. Invalid file path.');
}
if (!fs.existsSync(appAbc)) {
faultHandler(`ArkTS:ERROR GenerateAot failed. AppAbc not found in "${appAbc}"`);
@ -105,7 +105,7 @@ export function generateAot(arkDir: string, appAbc: string,
} else if (projectConfig.anBuildMode === AOT_PARTIAL) {
const profile: string = projectConfig.apPath;
if (!validateFilePathLength(profile, logger)) {
faultHandler(`ArkTS:ERROR GenerateAot failed. Invalid profile file path.`);
faultHandler('ArkTS:ERROR GenerateAot failed. Invalid profile file path.');
}
if (!fs.existsSync(profile)) {
faultHandler(`ArkTS:ERROR GenerateAot failed. Partial mode lost profile in "${profile}"`);

View File

@ -59,8 +59,8 @@ function js2abcByWorkers(jsonInput: string, cmd: string, workerFileName: string)
logger.debug('worker data is: ', JSON.stringify(process.env));
logger.debug('gen_abc isWorker is: ', cluster.isWorker);
if (cluster.isWorker && process.env.inputs !== undefined && process.env.cmd !== undefined
&& process.env.workerFileName !== undefined && process.env.cachePath !== undefined) {
if (cluster.isWorker && process.env.inputs !== undefined && process.env.cmd !== undefined &&
process.env.workerFileName !== undefined && process.env.cachePath !== undefined) {
logger.debug('==>worker #', cluster.worker.id, 'started!');
js2abcByWorkers(process.env.inputs, process.env.cmd, process.env.workerFileName);
process.exit(SUCCESS);

View File

@ -37,7 +37,7 @@ if (arkEnvParams.workerNumber !== undefined &&
arkEnvParams.splittedData !== undefined &&
arkEnvParams.cmdPrefix !== undefined) {
let workerNumber: number = parseInt(arkEnvParams.workerNumber);
let splittedData: any = JSON.parse(arkEnvParams.splittedData);
let splittedData: Object = JSON.parse(arkEnvParams.splittedData);
let cmdPrefix: string = arkEnvParams.cmdPrefix;
const clusterNewApiVersion: number = 16;

View File

@ -71,8 +71,8 @@ export function processKitImport(id: string, metaInfo: Object,
kitTransformLog.errors.push({
type: LogType.ERROR,
message: `Kit '${moduleRequest}' has no corresponding config file in ArkTS SDK. `+
`Please make sure the Kit apis are consistent with SDK ` +
`and there's no local modification on Kit apis.`,
'Please make sure the Kit apis are consistent with SDK ' +
"and there's no local modification on Kit apis.",
pos: node.getStart()
});
}

View File

@ -41,7 +41,8 @@ import { getRelativeSourcePath } from './fast_build/ark_compiler/common/ob_confi
export const SRC_MAIN: string = 'src/main';
export async function writeFileSyncByNode(node: ts.SourceFile, projectConfig: Object, metaInfo: Object, moduleId?: string , parentEvent?: Object, logger?: Object): Promise<void> {
export async function writeFileSyncByNode(node: ts.SourceFile, projectConfig: Object, metaInfo: Object, moduleId?: string,
parentEvent?: Object, logger?: Object): Promise<void> {
const eventWriteFileSyncByNode = createAndStartEvent(parentEvent, 'write file sync by node');
const eventGenContentAndSourceMapInfo = createAndStartEvent(eventWriteFileSyncByNode, 'generate content and source map information');
const mixedInfo: { content: string, sourceMapJson: ts.RawSourceMap } = genContentAndSourceMapInfo(node, moduleId, projectConfig, metaInfo);

View File

@ -420,7 +420,7 @@ export interface GeneratedFileInHar {
export const harFilesRecord: Map<string, GeneratedFileInHar> = new Map();
export function generateSourceFilesInHar(sourcePath: string, sourceContent: string, suffix: string,
projectConfig: Object, rootPathSet?: Object) {
projectConfig: Object, rootPathSet?: Object): void {
const projectRootPath: string = getProjectRootPath(sourcePath, projectConfig, rootPathSet) ;
// compileShared: compile shared har of project
let jsFilePath: string = genTemporaryPath(sourcePath,