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

Issue: using workspace: to implement nohoist in a package.json while using pnpm throws an error #919

Closed
danroberts opened this issue Mar 12, 2024 · 4 comments · Fixed by #920
Labels
bug something is not working as expected

Comments

@danroberts
Copy link

If you are using pnpm to do workspace manage, you don't define your workspaces in package.json - workspaces property, instead, separately in a pnpm-workspaces.yaml file.

One of our packages had a leftover workspaces nohoist property from when we used to use yarn, like this:

 "workspaces": {
    "nohoist": [
      "vite",
      "rollup"
    ]
  },

but doesn't specify any workspaces.

When analyzed with `pnpm depcruise packages/package-name -T json -c > results.json

it throws an error:

  ERROR: Extracting dependencies ran afoul of...

 pWorkspace.endsWith is not a function
... in packages/...

Removing the nohoist makes it work as expected.

Expected Behavior

If the workspaces property of the package.json is an object with only a nohoist property, ignore it.

Current Behavior

  ERROR: Extracting dependencies ran afoul of...

 pWorkspace.endsWith is not a function
... in packages/...

Possible Solution

If the workspaces property of the package.json is an object with only a nohoist property, ignore it in

Steps to Reproduce (for bugs)

Context

Your Environment

  • Version used:
  • Node version:
  • Operating System and version:
  • Link to your project:
@sverweij
Copy link
Owner

Hi @danroberts thanks for raising this (clear & well documented) bug report.

I've created a fix (see linked PR) and published dependency-cruiser@16.2.4-beta-1 (with the beta tag) to npmjs that contains it.

Let me know whether or not that fixes the issue on your side as well!

@sverweij sverweij added the bug something is not working as expected label Mar 12, 2024
@danroberts
Copy link
Author

Hi @sverweij! Thanks for the quick response. It does solve my problem, however, it is possible that your fix might regress the following example which is valid for yarn:

  "workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/pkgA/**"
    ]
  },

I'm not really sure how the cruiser would handle that but it's possible it might miss the workspaces defined in the packages property.

@sverweij
Copy link
Owner

Hi @danroberts thanks for checking! That yarn (1) shape of workspaces indeed won't work. It didn't in the previous version either b.t.w., so that'll be a good addition.

It won't (and didn't) lead to missing workspace dependencies (determining that happens elsewhere), only thing that'll happen is that these specific workspace aliases will not get classified as such.

Anyway - PR updated, & published as dependency-cruiser@16.2.4-beta-2 (since a few minutes).

sverweij added a commit that referenced this issue Mar 16, 2024
… 'workspaces' type alias field (#920)

## Description

- ignores 'workspaces' field when it isn't an array _and_ it doesn't
contain a yarn1 workspaces.packages field
- also classifies dependencies resolving via yarn1 workspaces.packages
fields as _aliased_, _aliased-workspace_

## Motivation and Context

fixes #919 

## How Has This Been Tested?

- [x] green ci
- [x] additional automated non-regression test

Note: a version with this fix has been published as
`dependency-cruiser@16.2.4-beta-1` - once the PR is merged it'll be part
of dependency-cruiser@16.2.4.

## Types of changes

- [x] Bug fix (non-breaking change which fixes an issue)
@sverweij
Copy link
Owner

FYI @danroberts - I've just released dependency-cruiser@16.2.4 that contains the fix for this issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is not working as expected
Projects
None yet
2 participants