depgraph-core 1.0.1-beta → 1.0.2

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.
Files changed (2) hide show
  1. package/depgraph.js +108 -4
  2. package/package.json +5 -1
package/depgraph.js CHANGED
@@ -68,12 +68,12 @@ var require_constants = __commonJS({
68
68
  exports2.MAX_FILE_SIZE = 3e5;
69
69
  exports2.MAX_BFS_DEPTH = 10;
70
70
  exports2.COMPLEXITY_THRESHOLDS = {
71
+ /** Complexity score is "low" if there are 3 or fewer branch points. */
71
72
  low: 3,
72
- // 0-3 branches → low complexity
73
+ /** Complexity score is "medium" if there are between 4 and 8 branch points. */
73
74
  medium: 8,
74
- // 4-8 branches → medium complexity
75
+ /** Complexity score is "high" if there are 9 or more branch points. */
75
76
  high: Infinity
76
- // 9+ → high complexity
77
77
  };
78
78
  }
79
79
  });
@@ -228,6 +228,109 @@ var require_javascript = __commonJS({
228
228
  }
229
229
  });
230
230
 
231
+ // dist/languages/python.js
232
+ var require_python = __commonJS({
233
+ "dist/languages/python.js"(exports2) {
234
+ "use strict";
235
+ Object.defineProperty(exports2, "__esModule", { value: true });
236
+ var registry_1 = require_registry();
237
+ var constants_1 = require_constants();
238
+ function estimateComplexity(code, name) {
239
+ const lines = code.split("\n");
240
+ const defLine = lines.findIndex((l) => l.match(new RegExp(`def\\s+${name}\\s*\\(`)));
241
+ if (defLine === -1)
242
+ return "low";
243
+ const bodyLines = [];
244
+ for (let i = defLine + 1; i < lines.length; i++) {
245
+ const line = lines[i];
246
+ if (line.trim() === "")
247
+ continue;
248
+ if (!line.match(/^\s+/))
249
+ break;
250
+ bodyLines.push(line);
251
+ }
252
+ const body = bodyLines.join("\n");
253
+ const branches = (body.match(/\b(if|elif|else|for|while|except|and|or)\b/g) || []).length;
254
+ if (branches <= constants_1.COMPLEXITY_THRESHOLDS.low)
255
+ return "low";
256
+ if (branches <= constants_1.COMPLEXITY_THRESHOLDS.medium)
257
+ return "medium";
258
+ return "high";
259
+ }
260
+ function extractEntities(code, filePath) {
261
+ const entities = [];
262
+ const patterns = [
263
+ // regular functions
264
+ {
265
+ regex: /^(?:async\s+)?def\s+(\w+)\s*\(/gm,
266
+ type: "function"
267
+ },
268
+ // classes
269
+ {
270
+ regex: /^class\s+(\w+)(?:\s*\([^)]*\))?\s*:/gm,
271
+ type: "class"
272
+ }
273
+ ];
274
+ for (const { regex, type } of patterns) {
275
+ regex.lastIndex = 0;
276
+ let match;
277
+ while ((match = regex.exec(code)) !== null) {
278
+ const name = match[1];
279
+ if (type === "function" && name.startsWith("__") && name.endsWith("__"))
280
+ continue;
281
+ if (entities.some((e) => e.name === name))
282
+ continue;
283
+ const upToMatch = code.slice(0, match.index);
284
+ const line = upToMatch.split("\n").length;
285
+ entities.push({
286
+ name,
287
+ type,
288
+ line,
289
+ complexity: type === "function" ? estimateComplexity(code, name) : "low"
290
+ });
291
+ }
292
+ }
293
+ return entities;
294
+ }
295
+ function extractImports(code) {
296
+ const imports = [];
297
+ const fromPattern = /^from\s+([\w.]+)\s+import\s+(.+)$/gm;
298
+ let match;
299
+ while ((match = fromPattern.exec(code)) !== null) {
300
+ const source = match[1];
301
+ const names = match[2].split(",").map((n) => n.trim()).filter((n) => n.length > 0);
302
+ const isLocal = source.startsWith(".");
303
+ imports.push({ source, names, isLocal });
304
+ }
305
+ const importPattern = /^import\s+([\w.]+)/gm;
306
+ while ((match = importPattern.exec(code)) !== null) {
307
+ const source = match[1];
308
+ imports.push({
309
+ source,
310
+ names: [source],
311
+ isLocal: false
312
+ // bare imports are always external
313
+ });
314
+ }
315
+ return imports;
316
+ }
317
+ function extractExports(code) {
318
+ const allMatch = code.match(/__all__\s*=\s*\[([^\]]+)\]/);
319
+ if (!allMatch)
320
+ return [];
321
+ return allMatch[1].split(",").map((n) => n.trim().replace(/['"]/g, "")).filter((n) => n.length > 0);
322
+ }
323
+ var PythonParser = {
324
+ lang: "py",
325
+ extensions: [".py"],
326
+ extractEntities,
327
+ extractImports,
328
+ extractExports
329
+ };
330
+ (0, registry_1.registerParser)(PythonParser);
331
+ }
332
+ });
333
+
231
334
  // dist/stages/collector.js
232
335
  var require_collector = __commonJS({
233
336
  "dist/stages/collector.js"(exports2) {
@@ -715,6 +818,7 @@ var __importDefault = exports && exports.__importDefault || function(mod) {
715
818
  };
716
819
  Object.defineProperty(exports, "__esModule", { value: true });
717
820
  require_javascript();
821
+ require_python();
718
822
  var fs_1 = __importDefault(require("fs"));
719
823
  var collector_1 = require_collector();
720
824
  var parser_1 = require_parser();
@@ -742,7 +846,7 @@ function getFlag(flag) {
742
846
  }
743
847
  function printHelp() {
744
848
  console.log(`
745
- ${bold("DepGraph Compiler")} ${dim("v1.0.0")}
849
+ ${bold("DepGraph Compiler")} ${dim("v1.0.2")}
746
850
  ${dim("Dependency mapping \xB7 Impact simulation \xB7 Developer intelligence")}
747
851
 
748
852
  ${bold("USAGE")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "depgraph-core",
3
- "version": "1.0.1-beta",
3
+ "version": "1.0.2",
4
4
  "description": "Dependency mapping and impact simulation for JS/TS projects",
5
5
  "main": "depgraph.js",
6
6
  "bin": {
@@ -21,6 +21,10 @@
21
21
  "typescript"
22
22
  ],
23
23
  "author": "Arafat Mannan",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/arafat2020/depgraph.git"
27
+ },
24
28
  "license": "MIT",
25
29
  "devDependencies": {
26
30
  "@types/node": "^26.1.1",