Skip to content

Commit 083299a

Browse files
committed
fix bug with nested node_modules directories
1 parent 417d0f7 commit 083299a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

oh_node.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'''
1212

1313
from pathlib import Path
14+
import sys
1415
import argparse
1516
import logging
1617
import time
@@ -26,7 +27,7 @@ def main():
2627

2728
# total number of files, extenion count and total size (in bytes)
2829
logging.debug('Counting files...')
29-
files, types, size = count_files(args.root_dir)
30+
files, types, size = count_files(find_node_modules(args.root_dir))
3031

3132
# Calculate and format data
3233
total_files = len(files)
@@ -55,6 +56,19 @@ def main():
5556
print('Total lines of code'.ljust(20, '.') + f'{str(total_lines)}'.rjust(30, '.'))
5657

5758

59+
def find_node_modules(root_dir):
60+
'''Checks for the presence of a node_modules directory and returns the full
61+
path to that location based on the input root_dir'''
62+
63+
root_dir_abs = os.path.abspath(root_dir)
64+
65+
if 'node_modules' not in os.listdir(root_dir_abs):
66+
print(f'node_modules not found in {root_dir_abs}')
67+
sys.exit(1)
68+
69+
return os.path.join(root_dir_abs, 'node_modules')
70+
71+
5872
def top_extensions(types, top=5):
5973
'''Counts, sorts and returns the 5 highest items in the types dictionary'''
6074

@@ -118,8 +132,8 @@ def count_files(root_dir):
118132
for current, dirs, files in os.walk(root_dir):
119133

120134
# ignore files not within a node_modules directory
121-
if 'node_modules' not in current:
122-
continue
135+
# if 'node_modules' not in current:
136+
# continue
123137

124138
for file in files:
125139
try:

0 commit comments

Comments
 (0)