Skip to content

feat: add support for package-lock.json files#305

Merged
sdn4z merged 1 commit into
elementsinteractive:mainfrom
sdn4z:npm-source
Sep 8, 2025
Merged

feat: add support for package-lock.json files#305
sdn4z merged 1 commit into
elementsinteractive:mainfrom
sdn4z:npm-source

Conversation

@sdn4z
Copy link
Copy Markdown
Collaborator

@sdn4z sdn4z commented Sep 8, 2025

closes #96
This PR introduces the support for package-lock.json files, making twyn able to check not only against Python dependencies, but also javascript.

In order to do so, a new PackageReference was introduced, so that the trusted packages can be downloaded, together with a package-lock.json file parser, supporting v1, v2 and v3.

Some refactoring took place in this PR, and DependencyManagers were introduced. These are in charge of linking programming languages with the ir corresponding lock files as well as with their PackageReference related classes.

I've manually tested it with v1, v2 and v3 package-json.lock files, and it works! for v1 and v2, at least for the lockfiles that I've used, it returns way more results than it does for Python lockfiles and for v3. This is probably because v1 and v2 files are old and have old dependencies that are not used anymore. Something to keep in mind.

In the ConfigHandler class, pypi_reference was renamed to source, making it breaking change.

BREAKING CHANGE

if dependency_parser().file_exists()
]
self._raise_for_selected_parsers(parsers)
self.dependency_file = parsers[0]().file_path
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to save it now, as we rely on the detected lock file to infer which manager to use when the file was auto detected
https://github.com/elementsinteractive/twyn/pull/305/files#diff-814dedefc2eb7e589119510f15db759d203e36192b41cbb5751ffad17253fcaaR136

@sdn4z sdn4z marked this pull request as ready for review September 8, 2025 11:05
@sdn4z sdn4z requested a review from scastlara as a code owner September 8, 2025 11:05
Comment thread src/twyn/cli.py Outdated
Comment thread src/twyn/main.py Outdated
Comment thread src/twyn/main.py Outdated
Comment thread src/twyn/similarity/algorithm.py Outdated
Comment thread src/twyn/base/constants.py Outdated
DEFAULT_USE_CACHE = True


PackageManagers: TypeAlias = Literal["pypi", "npm"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmm not package manager, it's a repository or a source. We can look maybe at other systems how they call it? Like renovate and dependabot? and then call them the same way.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, I rushed too much and thought of npm's package manager.

I've renamed it to PackageEcosystem

@github-actions github-actions Bot added feature and removed feature labels Sep 8, 2025
@sdn4z sdn4z force-pushed the npm-source branch 2 times, most recently from c01237e to 6701b80 Compare September 8, 2025 12:20
@github-actions github-actions Bot added feature and removed feature labels Sep 8, 2025
@sdn4z sdn4z enabled auto-merge (squash) September 8, 2025 15:19
@github-actions github-actions Bot added feature and removed feature labels Sep 8, 2025
@sdn4z sdn4z merged commit 5fba95c into elementsinteractive:main Sep 8, 2025
12 checks passed
@sdn4z sdn4z deleted the npm-source branch September 10, 2025 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for npm projects

2 participants