Skip to content

Commit

Permalink
fix: issue 102. dependencies broken when import in file has no other …
Browse files Browse the repository at this point in the history
…UML classes

chore: imported logging of axios calls
  • Loading branch information
naddison36 committed Sep 22, 2022
1 parent 34f7267 commit b075c6f
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 14 deletions.
20 changes: 17 additions & 3 deletions lib/converterAST2Classes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/converterClass2Dot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/parserEtherscan.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/sol2uml.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/umlClass.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export declare enum ClassStereotype {
Contract = 4,
Struct = 5,
Enum = 6,
Constant = 7
Constant = 7,
Import = 8
}
export declare enum OperatorStereotype {
None = 0,
Expand Down
1 change: 1 addition & 0 deletions lib/umlClass.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 50 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sol2uml",
"version": "2.2.0",
"version": "2.2.1",
"description": "Solidity contract visualisation tool.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand All @@ -22,6 +22,7 @@
"@aduh95/viz.js": "^3.7.0",
"@solidity-parser/parser": "^0.14.3",
"axios": "^0.27.2",
"axios-debug-log": "^0.8.4",
"commander": "^9.4.0",
"convert-svg-to-png": "^0.6.4",
"debug": "^4.3.4",
Expand Down
19 changes: 16 additions & 3 deletions src/ts/converterAST2Classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,22 @@ export function convertAST2UmlClasses(
throw new Error(`AST node not of type SourceUnit`)
}

umlClasses.forEach((umlClass) => {
umlClass.imports = imports
})
if (umlClasses.length > 0) {
umlClasses.forEach((umlClass) => {
umlClass.imports = imports
})
} else {
const importUmlClass = new UmlClass({
name: 'Import',
stereotype: ClassStereotype.Import,
absolutePath: filesystem
? path.resolve(relativePath) // resolve the absolute path
: relativePath, // from Etherscan so don't resolve
relativePath,
})
importUmlClass.imports = imports
umlClasses = [importUmlClass]
}

return umlClasses
}
Expand Down
1 change: 1 addition & 0 deletions src/ts/converterClass2Dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const convertClass2Dot = (
): string => {
// do not include library, interface, abstracts, struct or enum classes if hidden
if (
umlClass.stereotype === ClassStereotype.Import ||
(options.hideLibraries &&
umlClass.stereotype === ClassStereotype.Library) ||
(options.hideInterfaces &&
Expand Down
2 changes: 2 additions & 0 deletions src/ts/parserEtherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { convertAST2UmlClasses } from './converterAST2Classes'
import { UmlClass } from './umlClass'
import { topologicalSortClasses } from './filterClasses'

require('axios-debug-log')
const debug = require('debug')('sol2uml')

export const networks = <const>[
Expand Down Expand Up @@ -150,6 +151,7 @@ export class EtherscanParser {
(f) => !dependentFilenames.includes(f.filename)
)
const nonDependentFilenames = nonDependentFiles.map((f) => f.filename)
debug(`Failed to find dependencies to files: ${nonDependentFilenames}`)

let solidityCode = ''
// output non dependent code before the dependent files just in case sol2uml missed some dependencies
Expand Down
2 changes: 1 addition & 1 deletion src/ts/sol2uml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ In order for the merged code to compile, the following is done:
})

program.on('option:verbose', () => {
debugControl.enable('sol2uml')
debugControl.enable('sol2uml,axios')
debug('verbose on')
})

Expand Down
1 change: 1 addition & 0 deletions src/ts/umlClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum ClassStereotype {
Struct,
Enum,
Constant,
Import,
}

export enum OperatorStereotype {
Expand Down

0 comments on commit b075c6f

Please sign in to comment.