Skip to content
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

Zod schema fails if there are "workspace:*" dependencies #3

Open
wtlgo opened this issue Mar 22, 2024 · 2 comments
Open

Zod schema fails if there are "workspace:*" dependencies #3

wtlgo opened this issue Mar 22, 2024 · 2 comments

Comments

@wtlgo
Copy link

wtlgo commented Mar 22, 2024

With pnpm monorepo, if there's a "package": "workspace:*" dependency in the package.json, pnpm licenses list does not generate the version field for such dependency for some reason (even though it is specified in dependencies package.json). Because of this the tool simply does not work in such an environment.

@wtlgo
Copy link
Author

wtlgo commented Mar 23, 2024

I was able to work around it by patch

diff --git a/dist/chunk-L3HHIU3I.mjs b/dist/chunk-L3HHIU3I.mjs
index c048b0eabda2092497bc3522a3a24f1786d14d1e..21e5ca45993a5a23af8f71135658fe33567fdff3 100644
--- a/dist/chunk-L3HHIU3I.mjs
+++ b/dist/chunk-L3HHIU3I.mjs
@@ -21,7 +21,7 @@ var pnpmDependencyFlattenedSchema = z.object({
   description: z.string().optional()
 });
 var pnpmDependencySchema = z.union([pnpmDependencyGroupedSchema, pnpmDependencyFlattenedSchema]);
-var pnpmInputSchema = z.record(z.string(), z.array(pnpmDependencySchema));
+var pnpmInputSchema = z.record(z.string(), z.array(z.unknown()).transform(arr => arr?.filter(item => pnpmDependencySchema.safeParse(item).success)));
 var flattenDependencies = (deps) => deps.flatMap(({ name, license, author, homepage, description, ...rest }) => {
   if ("version" in rest) {
     return [{ name, license, author, homepage, description, ...rest }];

But there probably should be a better way...

@JaninaWibkerQC
Copy link
Collaborator

Sorry for only responding now, I didn't have notifications turned on for the repo 😅

pnpm licenses list has quite a few bugs/inconsistencies oftentimes, I cannot reproduce the issue because for me the monorepo dependencies are excluded completely from the output.

I am not sure if I am missing some flag or similar but pnpm only lists non-workspace dependencies for me

I tested v7, v8 and v9 of pnpm but they all behaved the same

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

No branches or pull requests

2 participants