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

feat: add dedupeDependencies utility #175

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

Conversation

OrbisK
Copy link

@OrbisK OrbisK commented Dec 28, 2024

fix #166

@pi0 pi0 changed the title feat: add dedupe util feat: add dedupeDependencies utility Dec 28, 2024
src/api.ts Outdated
const resolvedOptions = await resolveOperationOptions(options);
if (["bun", "deno"].includes(resolvedOptions.packageManager?.name ?? "")) {
throw new Error(
`Deduping is currently not supported for \`${resolvedOptions.packageManager?.name ?? "unknown package manager"}\``,
Copy link
Member

Choose a reason for hiding this comment

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

In this case, we can fallback to:

  • Remove known lockfiles
  • Run install

Copy link
Author

Choose a reason for hiding this comment

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

In this case, we can fallback to:

  • Remove known lockfiles
  • Run install

Should I use another utility to remove the lockfile or do it in place?

Copy link
Member

Choose a reason for hiding this comment

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

Inline is fine. We can support { recreateLockFile?: boolean } option also to force this behavior optionaly.

Copy link
Author

Choose a reason for hiding this comment

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

Inline is fine. We can support { recreateLockFile?: boolean } option also to force this behavior optionaly.

I have tried it so that you can also pass a false for deno or bun. This should ensure that you can also prevent recreating. Might be nice for nuxi.

Copy link

codecov bot commented Dec 28, 2024

Codecov Report

Attention: Patch coverage is 28.12500% with 23 lines in your changes missing coverage. Please review.

Project coverage is 62.52%. Comparing base (660392f) to head (fa96ead).
Report is 67 commits behind head on main.

Files with missing lines Patch % Lines
src/cli.ts 0.00% 20 Missing ⚠️
src/api.ts 75.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #175       +/-   ##
===========================================
- Coverage   82.17%   62.52%   -19.65%     
===========================================
  Files           6        5        -1     
  Lines         516      515        -1     
  Branches       71      101       +30     
===========================================
- Hits          424      322      -102     
- Misses         91      190       +99     
- Partials        1        3        +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/api.ts Outdated
const recreateLockfile = options.recreateLockfile ?? !isSupported;
if(!isSupported) {
consola.log(
`Deduping is currently not supported for \`${resolvedOptions.packageManager?.name ?? "unknown package manager"}\`.`,
Copy link
Member

Choose a reason for hiding this comment

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

IMO it might only make users more confused, goal of nypm is transparent compatibility and recreate is already closest behavior + we log about what we do.

Also, it might make implicit issues, if a library passes recreateLockfile: false it will be a no-op function on deno/bun.

I suggest we do fallback without warn by default and in case recreateLockfile: false is passed, throw an error so we cover both max compat (default) and strict (if option explicitly asks to not fallback)

Copy link
Author

@OrbisK OrbisK Dec 28, 2024

Choose a reason for hiding this comment

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

so to summarise:

recreate result
deno or bun undefined recreate lockfile
deno or bun false error
deno or bun true recreate lockfile
any other pm true recreate lockfile
deno or bun undefined dedupe
any other pm false dedupe
  • plus no supported warning

Did I understand that correctly?

Copy link
Member

@pi0 pi0 Dec 28, 2024

Choose a reason for hiding this comment

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

Exactly. Without passing recreate (undefined) also:

recreate result
deno or bun undefined recreate lockfile
any other pm undefined dedupe
deno or bun false error
any other pm false dedupe
deno or bun true recreate lockfile
any other pm true recreate lockfile

Copy link
Author

Choose a reason for hiding this comment

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

I tried to add tests as best as possbile. it was not possible for me to test for deno and bun with recreate false. Because the errors origin is the test.

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.

util to dedup dependencies
2 participants