Skip to content

Support monorepo and workaround local dependencies #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

gladykov
Copy link

If you are OK with those changes, I can update documentation and tests.

While trying to use it, I encountered few issues:

1. Some packages define dependencies as paths to files

Ex. "tablesorter": "file:./src/js-vendor/tablesorter" 🤦

a) Such package does not have metadata (name, license). So sorting by name was failing. Added check, to sort only if all packages have names.
b) Lack of metadata was also causing impossible to ignore such packages. Added ignorePath option to ignore by path

2.Reusing licensee() in monorepo in loop over multiple paths to package.json was not working

a) configuration object was kept in memory , meaning it was processed few times, resulting in errors. Now method creates structuredCopy of original, before processing it.
b) It was impossible to wait for licensee() execution, despite method being sync. Marked as async, and now it will return promise, , which at the end returns callback. This allows more custom processing of a result.

Attaching example of TS using this (renamed to txt because Github):
license.txt

@ljharb
Copy link
Member

ljharb commented May 29, 2025

It should probably just omit anything that's a file dep, no?

@kemitchell
Copy link
Member

I'd support just ignoring, but I have no idea whether or how Arborist handles such deps.

@ljharb
Copy link
Member

ljharb commented May 29, 2025

Arborist handles them fine, but I mean because it's first-party code so the license isn't relevant.

@gladykov
Copy link
Author

Unfortunately we encountered 3rd party package which ships third party packages this way 🤦 So we still had to verify manually if license is OK

@ljharb
Copy link
Member

ljharb commented May 29, 2025

I'm confused, the third-party package contains a file: dep, that's also contained in the package?

and that tablesorter thing has a package.json?

@gladykov
Copy link
Author

Say hello to @atlassian/aui package:
image

where src is hardcoded file:src , and there are internal symlinks between node_modules and src folder

@ljharb
Copy link
Member

ljharb commented May 29, 2025

wow, that is horrific - vendoring code anywhere has been a bad practice for a long time, and doing it in a package is, as this shows, very problematic with tooling, especially security tooling.

In this case, though, the vendored deps don't even seem to have a package.json, so there's no license information to be found - it's useless for this tool (in-code comments aren't statically discoverable). So I still think just unilaterally skipping file deps is the right move.

I also note that I can't even find a live version of that package with tablesorter in it (it may exist, i only checked the latest and earliest in each major, v5-v9). What version are you using?

@gladykov
Copy link
Author

We do not use tablesorter. This is dependency coming from the package. Looks like some of those symlinks are even dead

@ljharb
Copy link
Member

ljharb commented May 30, 2025

Right, but that's what i mean - the package doesn't actually have tablesorter in it.

@gladykov
Copy link
Author

Yep. Anyway, about PR, should I move forward with docs and tests updates? Any remarks?

@ljharb
Copy link
Member

ljharb commented May 31, 2025

I think a bug fix to not crash with cases like this is great and uncontroversial. I’m not as convinced about a new option.

@kemitchell
Copy link
Member

A test inducing a crash would be welcome. Preferably one that writes out a package.json causing the issue, rather than pulling in unrelated packages from npm.

@gladykov
Copy link
Author

gladykov commented Jun 2, 2025

Added unit test, which proves things will not explode if bad package is added. What I discovered in the process, is that symlink leading to non existing file is causing the issue.

Can you also add filtering by path? It is good for exactly such case.

@gladykov
Copy link
Author

gladykov commented Jun 9, 2025

Fixed unit test (test was failing because of structuredCopy is not seen by JavaScript Standard Style), and one more corner case we found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants