Skip to content

Commit 996ec07

Browse files
riosjeRafaelGSS
authored andcommitted
fix: CJS Module Lexer version parser issue
Signed-off-by: Jefferson <[email protected]> fix: CJS Module Lexer version parser issue
1 parent e5535e0 commit 996ec07

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

dep_checker/dependencies.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ def get_cpe(self, repo_path: Path) -> Optional[str]:
130130
npm_name="corepack",
131131
),
132132
"CJS Module Lexer": Dependency(
133-
version_parser=lambda repo_path: vp.get_cjs_lexer_version_old(repo_path) \
134-
if "v20" in str(repo_path) else vp.get_cjs_lexer_version(repo_path),
133+
version_parser=lambda repo_path: (
134+
vp.get_cjs_lexer_version(repo_path)
135+
if int(vp.get_node_version(repo_path).split(".")[0]) > 20
136+
else vp.get_cjs_lexer_version_old(repo_path)
137+
),
135138
cpe=None,
136139
keyword="cjs-module-lexer",
137140
npm_name="cjs-module-lexer",

dep_checker/versions_parser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,17 @@ def get_ada_version(repo_path: Path) -> str:
242242
if matches is None:
243243
raise RuntimeError("Error extracting version number for ada")
244244
return matches.groupdict()["version"]
245+
246+
def get_node_version(repo_path: Path) -> str:
247+
"""
248+
Parses src/node_version.h and returns the Node.js version as a string (e.g., '20.19.4').
249+
"""
250+
version_file = repo_path / "src/node_version.h"
251+
with open(version_file, "r") as f:
252+
content = f.read()
253+
major = re.search(r"#define NODE_MAJOR_VERSION (\d+)", content)
254+
minor = re.search(r"#define NODE_MINOR_VERSION (\d+)", content)
255+
patch = re.search(r"#define NODE_PATCH_VERSION (\d+)", content)
256+
if not (major and minor and patch):
257+
raise RuntimeError(f"Error extracting Node.js version from {version_file}")
258+
return f"{major.group(1)}.{minor.group(1)}.{patch.group(1)}"

0 commit comments

Comments
 (0)