MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / check_javascript_script

Function check_javascript_script

Scripts/Other Tools/Termux Repair Wizard.py:1088–1132  ·  view source on GitHub ↗
(path, language, text, root, auto_install, report, processed_manifests)

Source from the content-addressed store, hash-verified

1086
1087
1088def check_javascript_script(path, language, text, root, auto_install, report, processed_manifests):
1089 if language == "javascript" and have("node"):
1090 code, _, err = run(["node", "--check", path], capture=True)
1091 if code != 0:
1092 report.line("syntax_failures", f"{path}: Node syntax check failed: {err.strip()[-800:]}")
1093
1094 manifest = find_project_file(path, ["package.json"], root)
1095 project_dir = manifest.parent if manifest else path.parent
1096 if manifest and manifest not in processed_manifests:
1097 processed_manifests.add(manifest)
1098 if auto_install:
1099 code, _, err = run(["npm", "install", "--no-audit", "--no-fund"], capture=True, cwd=project_dir)
1100 if code == 0:
1101 report.line("installed", f"Installed npm dependencies from {manifest}")
1102 else:
1103 report.line("failures", f"npm install failed in {project_dir}: {err.strip()[-600:]}")
1104
1105 node_modules = project_dir / "node_modules"
1106 for module in sorted(parse_javascript_modules(text)):
1107 module_path = node_modules / module
1108 if module_path.exists():
1109 continue
1110 if auto_install:
1111 save_args = ["--save"] if manifest else ["--no-save", "--no-package-lock"]
1112 code, _, err = run(["npm", "install", module, *save_args, "--no-audit", "--no-fund"], capture=True, cwd=project_dir)
1113 if code == 0:
1114 report.line("installed", f"Installed npm module '{module}' for {path}")
1115 else:
1116 report.line("failures", f"npm module '{module}' failed for {path}: {err.strip()[-600:]}")
1117 else:
1118 report.line("warnings", f"{path}: npm module may be missing: {module}")
1119
1120 if language == "typescript" and auto_install:
1121 local_tsc = project_dir / "node_modules" / ".bin" / "tsc"
1122 if not local_tsc.exists():
1123 type_args = ["--save-dev"] if manifest else ["--no-save", "--no-package-lock"]
1124 code, _, err = run(["npm", "install", "typescript", *type_args, "--no-audit", "--no-fund"], capture=True, cwd=project_dir)
1125 if code == 0:
1126 report.line("installed", f"Installed local TypeScript compiler in {project_dir}")
1127 else:
1128 report.line("failures", f"Could not install TypeScript in {project_dir}: {err.strip()[-600:]}")
1129 if local_tsc.exists():
1130 code, _, err = run([local_tsc, "--noEmit", "--skipLibCheck", path], capture=True, cwd=project_dir)
1131 if code != 0:
1132 report.line("syntax_failures", f"{path}: TypeScript check failed: {err.strip()[-800:]}")
1133
1134
1135def parse_ruby_requires(text):

Callers 1

script_keeperFunction · 0.70

Calls 6

haveFunction · 0.70
runFunction · 0.70
find_project_fileFunction · 0.70
parse_javascript_modulesFunction · 0.70
lineMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected