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

peer dependencies incorrectly resolved after updating interactively in monorepo scheme #8002

Open
2 of 4 tasks
dwiyatci opened this issue Apr 23, 2024 · 2 comments
Open
2 of 4 tasks

Comments

@dwiyatci
Copy link

Verify latest release

  • I verified that the issue exists in the latest pnpm release

pnpm version

9.0.5

Which area(s) of pnpm are affected? (leave empty if unsure)

Dependencies resolver, Lockfile

Link to the code that reproduces this issue or a replay of the bug

https://github.com/dwiyatci/fiddle/tree/pnpm9-issue-peerdeps

Reproduction steps

  • clone the repo above (branch: pnpm9-issue-peerdeps)
  • pnpm i
  • pnpm upgr, and then upgrade to jquery@3.7.1 in package1
  • evaluate the lock file and/or pnpm whyeslint9

Describe the Bug

ESLint v9 (which allegedly is a peer dep of @eslint-community/eslint-utils@4.4.0) is wrongly installed and being resolved as dev dependencies of a package (react-scripts) that's incompatible with it.

Expected Behavior

ESLint v8 (8.57.0) that's specified in the root should be resolved instead.

Which Node.js version are you using?

18.18.2

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

If your OS is a Linux based, which one it is? (Include the version if relevant)

No response

@dwiyatci dwiyatci changed the title peer dependencies wrongly resolved after updating interactively in monorepo scheme peer dependencies incorrectly resolved after updating interactively in monorepo scheme Apr 23, 2024
@luisMolina95
Copy link

I am having a similar issue:

In the dependency I export an interface like this:

export interface IName{
   /**
   * Any Comment
   */
    anyKey: string;
}

But on the node_modules/.pnpm/dependency folder it gets resolved like this:

export interface IName{
    anyKey: string | undefined;
}

@dwiyatci
Copy link
Author

dwiyatci commented May 1, 2024

Since I'm a bit pessimistic that this issue will be picked up anytime soon, I (with GPT assist) created a bash script to upgrade non-breaking (non-major) dependencies to the latest across all workspaces in my monorepo project, which is my use case in using pnpm up --recursive --latest --interactive (before it's broken 😭).

The script assumes you've got jq installed, and capitalize the output of pnpm outdated -r --format json.

upgrade_nonbreaking_deps.sh

#!/bin/bash

# Set your monorepo root package name here
MONOREPO_ROOT_PKG_NAME="myproject-monorepo"

# Parse JSON data and prepare package upgrades without a major version update
prepare_package_update() {
  local package=$1
  local package_data=$2

  # Get the current and latest version
  local current_version=$(echo "$package_data" | jq -r '.current')
  local latest_version=$(echo "$package_data" | jq -r '.latest')

  # Return if the current and latest version are the same
  if [ "$current_version" == "$latest_version" ]; then
    return
  fi

  # Compare major version. Do not upgrade if the major version is different
  local current_major_version=${current_version%%.*}
  local latest_major_version=${latest_version%%.*}
  if [ "$current_major_version" != "$latest_major_version" ]; then
    return
  fi

  # Update the local storage file for every dependent package
  local deps=$(echo "$package_data" | jq -r '.dependentPackages[].name')
  for dep in $deps; do
    local sanitized_dep=$(echo "$dep" | sed "s~/~_~g")
    echo "$package@$latest_version" >> "$sanitized_dep.updates"
  done
}

# Save the output of the outdated package command
echo "pnpm outdated -r --format json"
data=$(pnpm outdated -r --format json)
echo $data | jq .

# Loop through the JSON object
for package in $(echo "$data" | jq -r 'keys[]'); do
  package_data=$(echo "$data" | jq -r --arg package "$package" '.[$package]')
  prepare_package_update "$package" "$package_data"
done

# Iterate over each storage file, execute the pnpm update command, and then remove the file
for file in *.updates; do
  packages=$(cat "$file")
  dep=${file%.updates}
  dep=$(echo "$dep" | sed "s~_~/~g")
  update_cmd="pnpm up --filter \"$dep\" $packages"
  if [ "$dep" == $MONOREPO_ROOT_PKG_NAME ]; then
    update_cmd="$update_cmd -w"
  fi

  # Execute the upgrading command
  echo $update_cmd
  eval $update_cmd
  rm "$file"
done

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

No branches or pull requests

2 participants