Skip to content

Commit

Permalink
Merge pull request #2 from SandZn/depx_fixing
Browse files Browse the repository at this point in the history
fix: reinstall dependencies with npm install, and refine the way to count dependencies
  • Loading branch information
emarteca authored Apr 8, 2022
2 parents 308ddf3 + 4b6a8ee commit 5dae875
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/test_JS_repo_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ def run_installation( pkg_json, crawler):
error, output, retcode = run_command( installation_command, crawler.INSTALL_TIMEOUT)
return( (manager, retcode, installation_command, installation_debug))

def get_deps():
deps = []
for d in os.listdir("node_modules"):
# if a folder's name starts with '.', ignore it.
if d[0] == '.':
continue
# if a folder's name starts with '@', count subfolders in it.
if d[0] == '@':
subFolder = os.path.join("node_modules/", d)
for f in os.listdir(subFolder):
deps.append(d + '/' + f)

else:
deps.append(d)

return deps

# note: no timeout option for get_dependencies, so "None" is passed as a default timeout argument to run_command
def get_dependencies( pkg_json, manager, include_dev_deps):
if pkg_json.get("devDependencies", None) and not include_dev_deps:
Expand All @@ -52,15 +69,15 @@ def get_dependencies( pkg_json, manager, include_dev_deps):
pkg_json["devDependencies"] = {}
with open("package.json", 'w') as f:
json.dump( pkg_json, f)
run_command( manager + (" install" if manager == "npm run " else ""))
run_command( "npm install" if manager == "npm run " else manager)
pkg_json["devDependencies"] = dev_deps
# get the list of deps, excluding hidden directories
deps = [] if not os.path.isdir("node_modules") else [d for d in os.listdir("node_modules") if not d[0] == "."]
deps = [] if not os.path.isdir("node_modules") else get_deps()
# then, reset the deps (if required)
if pkg_json.get("devDependencies", None) and not include_dev_deps:
run_command( "rm -r node_modules")
run_command( "mv TEMP_package.json_TEMP package.json")
run_command( manager + (" install" if manager == "npm run " else ""))
run_command( "npm install" if manager == "npm run " else manager)
return( deps)


Expand Down

0 comments on commit 5dae875

Please sign in to comment.