Skip to content

Commit d39ef02

Browse files
Sebastian WendorfSebastian Wendorf
authored andcommitted
Improved logging
1 parent d292d46 commit d39ef02

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

typescript/src/core/post-processors/exports.post-processor.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { LCEDependency } from "../concepts/dependency.concept";
88
import { NodeUtils } from "../utils/node.utils";
99
import * as fs from "fs";
1010
import { LCEProject, LCEProjectInfo } from "../project";
11+
import {debug} from "../utils/log.utils";
1112

1213
export class ExportsPostProcessor extends PostProcessor {
1314
postProcess(projects: LCEProject[]): void {
@@ -97,10 +98,9 @@ export class ExportsPostProcessor extends PostProcessor {
9798
this.addDependency(concepts, modulePathAbsolute, originalExport.globalDeclFqn);
9899
}
99100
} else {
100-
console.error(
101-
`Error: could not find exported declaration "${exp.identifier}" in "${exp.importSource}": Ignoring export...`,
101+
debug(
102+
`Error: could not find exported declaration "${exp.identifier}" in "${exp.importSource}": Ignoring export...\n\toccurred at ${exp.sourceFilePathAbsolute}}`,
102103
);
103-
console.error(`\toccurred at ${exp.sourceFilePathAbsolute}}`);
104104
}
105105
}
106106
} else {
@@ -113,8 +113,7 @@ export class ExportsPostProcessor extends PostProcessor {
113113
try {
114114
resolvedModulePath = NodeUtils.resolveImportPath(exp.importSource, projectInfo, exp.sourceFilePathAbsolute);
115115
} catch (e) {
116-
console.error(`Error: Could not resolve module: ${exp.importSource}`);
117-
console.error(`\toccurred at ${exp.sourceFilePathAbsolute}}`);
116+
debug(`Error: Could not resolve module: ${exp.importSource}\n\toccurred at ${exp.sourceFilePathAbsolute}}`);
118117
}
119118

120119
if (resolvedModulePath) {
@@ -173,16 +172,15 @@ export class ExportsPostProcessor extends PostProcessor {
173172
);
174173
this.addDependency(concepts, modulePathAbsolute, eDecl.fqn.globalFqn);
175174
} else {
176-
console.error(
175+
debug(
177176
`Error: external declaration with identifier "${exp.identifier}" in module "${exp.importSource}" could not be found: Ignoring export...`,
178177
);
179178
}
180179
}
181180
} else {
182-
console.error(
183-
`Error: external module "${exp.importSource}" for re-export of "${exp.identifier}" could not be found. Ignoring export...`,
181+
debug(
182+
`Error: external module "${exp.importSource}" for re-export of "${exp.identifier}" could not be found. Ignoring export...\n\toccurred at ${exp.sourceFilePathAbsolute}`,
184183
);
185-
console.error(`\toccurred at ${exp.sourceFilePathAbsolute}}`);
186184
}
187185
}
188186
} else {

typescript/src/core/processors/import-declaration.processor.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Processor } from "../processor";
88
import { DependencyResolutionProcessor } from "./dependency-resolution.processor";
99
import { NodeUtils } from "../utils/node.utils";
1010
import path from "path";
11+
import {debug} from "../utils/log.utils";
1112

1213
export class ImportDeclarationProcessor extends Processor {
1314
public executionCondition: ExecutionCondition = new ExecutionCondition([AST_NODE_TYPES.ImportDeclaration], () => true);
@@ -26,16 +27,20 @@ export class ImportDeclarationProcessor extends Processor {
2627
for (const specifier of node.specifiers) {
2728
let target = new FQN("");
2829
let isModule = false;
29-
if (specifier.type === AST_NODE_TYPES.ImportSpecifier) {
30-
const importSourceFqn = this.importSourceToFqn(importSource, globalContext);
31-
const importedName = specifier.imported.type === AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.raw;
32-
target = new FQN(importSourceFqn.globalFqn + "." + importedName, importSourceFqn.localFqn + "." + importedName);
33-
} else if (specifier.type === AST_NODE_TYPES.ImportDefaultSpecifier) {
34-
const importSourceFqn = this.importSourceToFqn(importSource, globalContext);
35-
target = new FQN(importSourceFqn.globalFqn + ".default", importSourceFqn.localFqn + ".default");
36-
} else if (specifier.type === AST_NODE_TYPES.ImportNamespaceSpecifier) {
37-
target = new FQN(path.resolve(globalContext.projectInfo.rootPath, importSource), importSource);
38-
isModule = true;
30+
try {
31+
if (specifier.type === AST_NODE_TYPES.ImportSpecifier) {
32+
const importSourceFqn = this.importSourceToFqn(importSource, globalContext);
33+
const importedName = specifier.imported.type === AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.raw;
34+
target = new FQN(importSourceFqn.globalFqn + "." + importedName, importSourceFqn.localFqn + "." + importedName);
35+
} else if (specifier.type === AST_NODE_TYPES.ImportDefaultSpecifier) {
36+
const importSourceFqn = this.importSourceToFqn(importSource, globalContext);
37+
target = new FQN(importSourceFqn.globalFqn + ".default", importSourceFqn.localFqn + ".default");
38+
} else if (specifier.type === AST_NODE_TYPES.ImportNamespaceSpecifier) {
39+
target = new FQN(path.resolve(globalContext.projectInfo.rootPath, importSource), importSource);
40+
isModule = true;
41+
}
42+
} catch (e) {
43+
debug(`Error while resolving import: ${e}`)
3944
}
4045

4146
if (!isModule && ModulePathUtils.getPathType(ModulePathUtils.extractFQNPath(target.globalFqn)) === "node") {
@@ -63,7 +68,7 @@ export class ImportDeclarationProcessor extends Processor {
6368
);
6469
}
6570
} catch (e) {
66-
console.log("\n" + `Error: Could not resolve import path for: ${ModulePathUtils.extractFQNPath(target.globalFqn)}`);
71+
debug(`Error: Could not resolve import path for: ${ModulePathUtils.extractFQNPath(target.globalFqn)}`);
6772
}
6873
}
6974

typescript/src/core/processors/type.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { DependencyResolutionProcessor } from "./dependency-resolution.processor
5454
import { NodeUtils } from "../utils/node.utils";
5555
import path from "path";
5656
import { FileUtils } from "../utils/file.utils";
57+
import {debug} from "../utils/log.utils";
5758

5859
let MAX_TYPE_RESOLUTION_DEPTH = 10;
5960

@@ -474,8 +475,7 @@ function parseType(
474475
return result;
475476
}
476477
} catch (e) {
477-
console.error("Error occurred during type resolution:");
478-
console.error(e);
478+
debug(`Error occurred during type resolution:\n${e}`);
479479
return new LCETypeNotIdentified(tc.typeToString(type));
480480
}
481481
}

typescript/src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#! /usr/bin/env node
22

3+
import pkg from '../package.json';
34
import { program } from "commander";
45
import { processProjectsAndOutputResult } from "./core/extractor";
56
import packageInfo from "../package.json";
@@ -31,6 +32,8 @@ setDebugLogging(!!options.debug);
3132

3233
const projectRootPath: string = program.processedArgs[0];
3334

35+
console.log(`Running jQAssistant TypeScript Language Concept Extractor ${pkg.version}`)
36+
3437
// initialize extensions
3538
if(extensions.includes("react")) {
3639
initializeReactExtractor();

typescript/src/react/processors/jsx-dependency.processor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { LCEVariableDeclaration } from "../../core/concepts/variable-declaration
1010
import { LCEFunctionDeclaration } from "../../core/concepts/function-declaration.concept";
1111
import { VariableDeclarationProcessor } from "../../core/processors/variable-declaration.processor";
1212
import { ReactContextKeys } from "../context.keys";
13+
import {debug} from "../../core/utils/log.utils";
1314

1415
export class JSXDependencyContextProcessor extends Processor {
1516
public static readonly JSX_DEPENDENCY_METADATA: "jsx-dependencies";
@@ -74,8 +75,7 @@ export class JSXDependencyProcessor extends Processor {
7475
let currentExpression = node.name.object;
7576
while (currentExpression.type === AST_NODE_TYPES.JSXMemberExpression) {
7677
if (depth > 20) {
77-
console.log("ERROR: Could not resolve JSX member expression:");
78-
console.log(name);
78+
debug(`ERROR: Could not resolve JSX member expression: ${name}`);
7979
return new Map();
8080
}
8181
name = currentExpression.property.name + "." + name;

0 commit comments

Comments
 (0)