devbonzai 1.6.9 → 1.7.1
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/cli.js +71 -14
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -382,6 +382,11 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
382
382
|
return { functions: [], classes: [] };
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
+
// Skip .d.ts files, minified files, and node_modules
|
|
386
|
+
if (filePath.endsWith('.d.ts') || filePath.endsWith('.min.js') || filePath.includes('node_modules')) {
|
|
387
|
+
return { functions: [], classes: [] };
|
|
388
|
+
}
|
|
389
|
+
|
|
385
390
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
386
391
|
const functions = [];
|
|
387
392
|
const classes = [];
|
|
@@ -413,12 +418,20 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
413
418
|
return content.substring(node.start, node.end);
|
|
414
419
|
};
|
|
415
420
|
|
|
421
|
+
// Track visited nodes to avoid duplicates
|
|
422
|
+
const visitedNodes = new Set();
|
|
423
|
+
|
|
416
424
|
// Traverse AST
|
|
417
|
-
function traverse(node) {
|
|
425
|
+
function traverse(node, parentType = null) {
|
|
418
426
|
if (!node) return;
|
|
419
427
|
|
|
428
|
+
// Skip if already visited (avoid processing same node twice)
|
|
429
|
+
if (visitedNodes.has(node)) return;
|
|
430
|
+
visitedNodes.add(node);
|
|
431
|
+
|
|
420
432
|
// Function declarations: function myFunc() {}
|
|
421
|
-
if (
|
|
433
|
+
// Skip if inside ExportNamedDeclaration (will be handled below)
|
|
434
|
+
if (node.type === 'FunctionDeclaration' && node.id && parentType !== 'ExportNamedDeclaration') {
|
|
422
435
|
functions.push({
|
|
423
436
|
name: node.id.name,
|
|
424
437
|
content: getCode(node),
|
|
@@ -432,7 +445,6 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
432
445
|
node.init &&
|
|
433
446
|
(node.init.type === 'ArrowFunctionExpression' || node.init.type === 'FunctionExpression') &&
|
|
434
447
|
node.id && node.id.type === 'Identifier') {
|
|
435
|
-
const funcNode = node.init;
|
|
436
448
|
const funcContent = getCode(node);
|
|
437
449
|
functions.push({
|
|
438
450
|
name: node.id.name,
|
|
@@ -443,7 +455,8 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
443
455
|
}
|
|
444
456
|
|
|
445
457
|
// Class declarations: class User { ... }
|
|
446
|
-
if (
|
|
458
|
+
// Skip if inside ExportNamedDeclaration (will be handled below)
|
|
459
|
+
if (node.type === 'ClassDeclaration' && node.id && parentType !== 'ExportNamedDeclaration') {
|
|
447
460
|
const className = node.id.name;
|
|
448
461
|
const methods = [];
|
|
449
462
|
|
|
@@ -486,6 +499,8 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
486
499
|
endLine: node.declaration.loc ? node.declaration.loc.end.line : 0,
|
|
487
500
|
isExported: true
|
|
488
501
|
});
|
|
502
|
+
// Mark as visited to avoid duplicate processing
|
|
503
|
+
visitedNodes.add(node.declaration);
|
|
489
504
|
} else if (node.declaration.type === 'ClassDeclaration' && node.declaration.id) {
|
|
490
505
|
const className = node.declaration.id.name;
|
|
491
506
|
const methods = [];
|
|
@@ -517,6 +532,8 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
517
532
|
endLine: node.declaration.loc ? node.declaration.loc.end.line : 0,
|
|
518
533
|
isExported: true
|
|
519
534
|
});
|
|
535
|
+
// Mark as visited to avoid duplicate processing
|
|
536
|
+
visitedNodes.add(node.declaration);
|
|
520
537
|
}
|
|
521
538
|
}
|
|
522
539
|
|
|
@@ -525,16 +542,27 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
525
542
|
if (key === 'parent' || key === 'leadingComments' || key === 'trailingComments') continue;
|
|
526
543
|
const child = node[key];
|
|
527
544
|
if (Array.isArray(child)) {
|
|
528
|
-
child.forEach(traverse);
|
|
545
|
+
child.forEach(c => traverse(c, node.type));
|
|
529
546
|
} else if (child && typeof child === 'object' && child.type) {
|
|
530
|
-
traverse(child);
|
|
547
|
+
traverse(child, node.type);
|
|
531
548
|
}
|
|
532
549
|
}
|
|
533
550
|
}
|
|
534
551
|
|
|
535
552
|
traverse(ast);
|
|
536
553
|
} catch (parseError) {
|
|
537
|
-
|
|
554
|
+
// Silently skip parsing errors - these are expected for some files
|
|
555
|
+
// Only log if it's not in node_modules or a known problematic file type
|
|
556
|
+
if (!filePath.includes('node_modules') && !filePath.endsWith('.d.ts') && !filePath.endsWith('.min.js')) {
|
|
557
|
+
// Suppress warnings for common parsing issues
|
|
558
|
+
const errorMsg = parseError.message || '';
|
|
559
|
+
if (!errorMsg.includes('outside of function') &&
|
|
560
|
+
!errorMsg.includes('Missing initializer') &&
|
|
561
|
+
!errorMsg.includes('Export') &&
|
|
562
|
+
!errorMsg.includes('Unexpected token')) {
|
|
563
|
+
// Only log unexpected errors
|
|
564
|
+
}
|
|
565
|
+
}
|
|
538
566
|
return { functions: [], classes: [] };
|
|
539
567
|
}
|
|
540
568
|
|
|
@@ -594,11 +622,20 @@ function extractVueFunctions(filePath) {
|
|
|
594
622
|
return scriptContent.substring(node.start, node.end);
|
|
595
623
|
};
|
|
596
624
|
|
|
625
|
+
// Track visited nodes to avoid duplicates
|
|
626
|
+
const visitedNodes = new Set();
|
|
627
|
+
|
|
597
628
|
// Traverse AST (same logic as JavaScript parser)
|
|
598
|
-
function traverse(node) {
|
|
629
|
+
function traverse(node, parentType = null) {
|
|
599
630
|
if (!node) return;
|
|
600
631
|
|
|
601
|
-
if (
|
|
632
|
+
// Skip if already visited (avoid processing same node twice)
|
|
633
|
+
if (visitedNodes.has(node)) return;
|
|
634
|
+
visitedNodes.add(node);
|
|
635
|
+
|
|
636
|
+
// Function declarations: function myFunc() {}
|
|
637
|
+
// Skip if inside ExportNamedDeclaration (will be handled below)
|
|
638
|
+
if (node.type === 'FunctionDeclaration' && node.id && parentType !== 'ExportNamedDeclaration') {
|
|
602
639
|
functions.push({
|
|
603
640
|
name: node.id.name,
|
|
604
641
|
content: getCode(node),
|
|
@@ -607,6 +644,7 @@ function extractVueFunctions(filePath) {
|
|
|
607
644
|
});
|
|
608
645
|
}
|
|
609
646
|
|
|
647
|
+
// Arrow functions: const myFunc = () => {}
|
|
610
648
|
if (node.type === 'VariableDeclarator' &&
|
|
611
649
|
node.init &&
|
|
612
650
|
(node.init.type === 'ArrowFunctionExpression' || node.init.type === 'FunctionExpression') &&
|
|
@@ -620,7 +658,9 @@ function extractVueFunctions(filePath) {
|
|
|
620
658
|
});
|
|
621
659
|
}
|
|
622
660
|
|
|
623
|
-
|
|
661
|
+
// Class declarations: class User { ... }
|
|
662
|
+
// Skip if inside ExportNamedDeclaration (will be handled below)
|
|
663
|
+
if (node.type === 'ClassDeclaration' && node.id && parentType !== 'ExportNamedDeclaration') {
|
|
624
664
|
const className = node.id.name;
|
|
625
665
|
const methods = [];
|
|
626
666
|
|
|
@@ -652,6 +692,7 @@ function extractVueFunctions(filePath) {
|
|
|
652
692
|
});
|
|
653
693
|
}
|
|
654
694
|
|
|
695
|
+
// Export declarations: export function, export default
|
|
655
696
|
if (node.type === 'ExportNamedDeclaration' && node.declaration) {
|
|
656
697
|
if (node.declaration.type === 'FunctionDeclaration' && node.declaration.id) {
|
|
657
698
|
functions.push({
|
|
@@ -661,6 +702,8 @@ function extractVueFunctions(filePath) {
|
|
|
661
702
|
endLine: node.declaration.loc ? node.declaration.loc.end.line : 0,
|
|
662
703
|
isExported: true
|
|
663
704
|
});
|
|
705
|
+
// Mark as visited to avoid duplicate processing
|
|
706
|
+
visitedNodes.add(node.declaration);
|
|
664
707
|
} else if (node.declaration.type === 'ClassDeclaration' && node.declaration.id) {
|
|
665
708
|
const className = node.declaration.id.name;
|
|
666
709
|
const methods = [];
|
|
@@ -692,23 +735,26 @@ function extractVueFunctions(filePath) {
|
|
|
692
735
|
endLine: node.declaration.loc ? node.declaration.loc.end.line : 0,
|
|
693
736
|
isExported: true
|
|
694
737
|
});
|
|
738
|
+
// Mark as visited to avoid duplicate processing
|
|
739
|
+
visitedNodes.add(node.declaration);
|
|
695
740
|
}
|
|
696
741
|
}
|
|
697
742
|
|
|
743
|
+
// Recursively traverse children
|
|
698
744
|
for (const key in node) {
|
|
699
745
|
if (key === 'parent' || key === 'leadingComments' || key === 'trailingComments') continue;
|
|
700
746
|
const child = node[key];
|
|
701
747
|
if (Array.isArray(child)) {
|
|
702
|
-
child.forEach(traverse);
|
|
748
|
+
child.forEach(c => traverse(c, node.type));
|
|
703
749
|
} else if (child && typeof child === 'object' && child.type) {
|
|
704
|
-
traverse(child);
|
|
750
|
+
traverse(child, node.type);
|
|
705
751
|
}
|
|
706
752
|
}
|
|
707
753
|
}
|
|
708
754
|
|
|
709
755
|
traverse(ast);
|
|
710
756
|
} catch (parseError) {
|
|
711
|
-
|
|
757
|
+
// Silently skip parsing errors for Vue files
|
|
712
758
|
return { functions: [], classes: [] };
|
|
713
759
|
}
|
|
714
760
|
|
|
@@ -739,11 +785,20 @@ function listAllFiles(dir, base = '', ignorePatterns = null) {
|
|
|
739
785
|
|
|
740
786
|
const stat = fs.statSync(fullPath);
|
|
741
787
|
if (stat && stat.isDirectory()) {
|
|
788
|
+
// Skip node_modules directories explicitly
|
|
789
|
+
if (file === 'node_modules' || relativePath.includes('node_modules/')) {
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
742
792
|
// Add the directory itself to results
|
|
743
793
|
results.push(relativePath + '/');
|
|
744
794
|
// Recursively list files inside the directory
|
|
745
795
|
results = results.concat(listAllFiles(fullPath, relativePath, ignorePatterns));
|
|
746
796
|
} else {
|
|
797
|
+
// Skip files in node_modules explicitly
|
|
798
|
+
if (relativePath.includes('node_modules/') || fullPath.includes('node_modules')) {
|
|
799
|
+
continue;
|
|
800
|
+
}
|
|
801
|
+
|
|
747
802
|
results.push(relativePath);
|
|
748
803
|
|
|
749
804
|
// Helper function to add functions, classes, and methods as virtual files
|
|
@@ -778,7 +833,9 @@ function listAllFiles(dir, base = '', ignorePatterns = null) {
|
|
|
778
833
|
}
|
|
779
834
|
|
|
780
835
|
// Handle JavaScript/TypeScript files
|
|
781
|
-
|
|
836
|
+
// Skip .d.ts files (TypeScript declaration files) and .min.js files (minified)
|
|
837
|
+
if ((file.endsWith('.js') || file.endsWith('.jsx') || file.endsWith('.ts') || file.endsWith('.tsx')) &&
|
|
838
|
+
!file.endsWith('.d.ts') && !file.endsWith('.min.js')) {
|
|
782
839
|
const parseResult = extractJavaScriptFunctions(fullPath);
|
|
783
840
|
addVirtualFiles(parseResult, relativePath);
|
|
784
841
|
}
|