sol2uml 2.1.5 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -77,9 +77,9 @@ Usage: sol2uml class <fileFolderAddress> [options]
77
77
 
78
78
  Generates UML diagrams from Solidity source code.
79
79
 
80
- If no file, folder or address is passes as the first argument, the working folder is used.
80
+ If no file, folder or address is passed as the first argument, the working folder is used.
81
81
  When a folder is used, all *.sol files are found in that folder and all sub folders.
82
- A comma separated list of files and folders can also used. For example
82
+ A comma separated list of files and folders can also be used. For example
83
83
  sol2uml contracts,node_modules/openzeppelin-solidity
84
84
 
85
85
  If an Ethereum address with a 0x prefix is passed, the verified source code from Etherscan will be used. For example
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.convertAST2UmlClasses = void 0;
27
27
  const path = __importStar(require("path"));
28
+ const path_1 = require("path");
28
29
  const umlClass_1 = require("./umlClass");
29
30
  const typeGuards_1 = require("./typeGuards");
30
31
  const debug = require('debug')('sol2uml');
@@ -35,7 +36,6 @@ function convertAST2UmlClasses(node, relativePath, filesystem = false) {
35
36
  if (node.type === 'SourceUnit') {
36
37
  node.children.forEach((childNode) => {
37
38
  if (childNode.type === 'ContractDefinition') {
38
- debug(`Adding contract ${childNode.name}`);
39
39
  let umlClass = new umlClass_1.UmlClass({
40
40
  name: childNode.name,
41
41
  absolutePath: filesystem
@@ -44,6 +44,7 @@ function convertAST2UmlClasses(node, relativePath, filesystem = false) {
44
44
  relativePath,
45
45
  });
46
46
  umlClass = parseContractDefinition(umlClass, childNode);
47
+ debug(`Added contract ${childNode.name}`);
47
48
  umlClasses.push(umlClass);
48
49
  }
49
50
  else if (childNode.type === 'StructDefinition') {
@@ -57,6 +58,7 @@ function convertAST2UmlClasses(node, relativePath, filesystem = false) {
57
58
  relativePath,
58
59
  });
59
60
  umlClass = parseStructDefinition(umlClass, childNode);
61
+ debug(`Added struct ${umlClass.name}`);
60
62
  umlClasses.push(umlClass);
61
63
  }
62
64
  else if (childNode.type === 'EnumDefinition') {
@@ -69,6 +71,7 @@ function convertAST2UmlClasses(node, relativePath, filesystem = false) {
69
71
  : relativePath,
70
72
  relativePath,
71
73
  });
74
+ debug(`Added enum ${umlClass.name}`);
72
75
  umlClass = parseEnumDefinition(umlClass, childNode);
73
76
  umlClasses.push(umlClass);
74
77
  }
@@ -80,7 +83,7 @@ function convertAST2UmlClasses(node, relativePath, filesystem = false) {
80
83
  const importPath = require.resolve(childNode.path, {
81
84
  paths: [codeFolder],
82
85
  });
83
- imports.push({
86
+ const newImport = {
84
87
  absolutePath: importPath,
85
88
  classNames: childNode.symbolAliases
86
89
  ? childNode.symbolAliases.map((alias) => {
@@ -90,7 +93,9 @@ function convertAST2UmlClasses(node, relativePath, filesystem = false) {
90
93
  };
91
94
  })
92
95
  : [],
93
- });
96
+ };
97
+ debug(`Added filesystem import ${newImport.absolutePath} with class names ${newImport.classNames}`);
98
+ imports.push(newImport);
94
99
  }
95
100
  catch (err) {
96
101
  debug(`Failed to resolve import ${childNode.path} from file ${relativePath}`);
@@ -98,10 +103,12 @@ function convertAST2UmlClasses(node, relativePath, filesystem = false) {
98
103
  }
99
104
  else {
100
105
  // this has come from Etherscan
101
- const importPath = childNode.path[0] === '@'
102
- ? childNode.path
103
- : path.join(codeFolder, childNode.path);
104
- imports.push({
106
+ const importPath = childNode.path[0] === '.'
107
+ ? // Use Linux paths, not Windows paths, to resolve Etherscan files
108
+ path_1.posix.join(codeFolder.toString(), childNode.path)
109
+ : childNode.path;
110
+ debug(`codeFolder ${codeFolder} childNode.path ${childNode.path}`);
111
+ const newImport = {
105
112
  absolutePath: importPath,
106
113
  classNames: childNode.symbolAliases
107
114
  ? childNode.symbolAliases.map((alias) => {
@@ -111,9 +118,12 @@ function convertAST2UmlClasses(node, relativePath, filesystem = false) {
111
118
  };
112
119
  })
113
120
  : [],
114
- });
121
+ };
122
+ debug(`Added Etherscan import ${newImport.absolutePath} with class names: ${newImport.classNames}`);
123
+ imports.push(newImport);
115
124
  }
116
125
  }
126
+ // TODO add file level constants
117
127
  });
118
128
  }
119
129
  else {
@@ -41,8 +41,9 @@ const convertClasses2Storages = (contractName, umlClasses, contractFilename) =>
41
41
  return name === contractName;
42
42
  }
43
43
  return (name === contractName &&
44
- (relativePath == contractFilename ||
45
- path_1.default.basename(relativePath) === contractFilename));
44
+ (relativePath == path_1.default.normalize(contractFilename) ||
45
+ path_1.default.basename(relativePath) ===
46
+ path_1.default.normalize(contractFilename)));
46
47
  });
47
48
  if (!umlClass) {
48
49
  const contractFilenameError = contractFilename
@@ -105,6 +105,7 @@ class EtherscanParser {
105
105
  const { files, contractName } = await this.getSourceCode(contractAddress);
106
106
  let umlClasses = [];
107
107
  for (const file of files) {
108
+ debug(`Parsing source file ${file.filename}`);
108
109
  const node = await this.parseSourceCode(file.code);
109
110
  const umlClass = (0, converterAST2Classes_1.convertAST2UmlClasses)(node, file.filename);
110
111
  umlClasses = umlClasses.concat(umlClass);
package/lib/sol2uml.js CHANGED
@@ -46,9 +46,9 @@ program
46
46
 
47
47
  Generates UML diagrams from Solidity source code.
48
48
 
49
- If no file, folder or address is passes as the first argument, the working folder is used.
49
+ If no file, folder or address is passed as the first argument, the working folder is used.
50
50
  When a folder is used, all *.sol files are found in that folder and all sub folders.
51
- A comma separated list of files and folders can also used. For example
51
+ A comma separated list of files and folders can also be used. For example
52
52
  sol2uml contracts,node_modules/openzeppelin-solidity
53
53
 
54
54
  If an Ethereum address with a 0x prefix is passed, the verified source code from Etherscan will be used. For example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sol2uml",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "description": "Solidity contract visualisation tool.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",