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

[BUG] decimal.js false-positive detection in monorepo #246

Open
sylver opened this issue Apr 26, 2024 · 0 comments
Open

[BUG] decimal.js false-positive detection in monorepo #246

sylver opened this issue Apr 26, 2024 · 0 comments
Assignees
Labels
bug (unconfirmed) Could be a bug

Comments

@sylver
Copy link

sylver commented Apr 26, 2024

Describe the bug

When used in the context of a monorepo (typically with pnpm), since all packages dependencies are hoisted to <root>/node_modules, if any of them has decimal.js in its dependencies (even a nested one), the method getDecimalJSInstalled using require.resolve finds it in the root node_modules and returns true as a false positive (since the module is not actually a dependency of the current package).

A typical tree would be :

<root>/
 |- node_modules/  // `pnpm` hoisting all modules here, including `zod-prisma-types` and `decimal.js`
 |- packages/
 |   |- package-a/
 |   |   |- schema.prisma
 |   |   |- node_modules/ // `zod-prisma-types` installed here
 |   |   
 |   |- package-b/
 |   |   |- node_modules/ // `decimal.js` installed only here, not even as a direct dependency of `package-b`
... ...  ...

Package versions (please complete the following information):

  • zod: 3.22.4
  • zod-prisma-types: 3.1.6
  • prisma: 5.11.0

Additional context

export const getDecimalJSInstalled = () => {
try {
require.resolve('decimal.js');
return true;
} catch (_e) {
return false;
}
};

The method getDecimalJSInstalled should use a more contained approach to detect if decimal.js module is a dependency of the current package.

Problem is, given the versatile nature of monorepo dependency hoisting and the several options given to the user to set it up, it can become very tricky to know if a given decimal.js package is actually a direct dependency of the current package or not.

I would probably look directly into the current package.json dependencies since that would be the only reliable source of truth in such context.

I can do a PR but first I could use your thoughts on this @chrishoermann

@sylver sylver added the bug (unconfirmed) Could be a bug label Apr 26, 2024
@sylver sylver changed the title [BUG] decimal.js detection false-positive in monorepo [BUG] decimal.js false-positive detection in monorepo Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (unconfirmed) Could be a bug
Projects
None yet
Development

No branches or pull requests

2 participants