Skip to content

Conversation

jungomi
Copy link
Contributor

@jungomi jungomi commented Jan 24, 2018

Summary

upgrade-interactive was updating the package.json in the current directory (where Yarn was run) instead of where the upgrades were made. The most notable occurrence of this was global upgrade-interactive, but it also happened by using the --cwd option.

When the location was not a workspace, it resolved to the current directory instead of using the previously configured one. Additionally, config.cwd was changed without being cleaned up, so it contained the last processed workspace, which affected anything that used it afterwards (e.g. symlinking binaries).

Fixes #4728
Fixes #4952
Fixes #4922

Test plan

Install any package globally, then upgrade it interactively without being in the global directory. (or with --cwd). The binary of the package that is being upgraded was symlinked again, but all other symlinks were removed.

Before

# Outdated version of `serve`, `prettier` for an extra binary
$ ~/some-dir ➜  yarn global add prettier [email protected]
yarn global v1.4.1
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "[email protected]" with binaries:
      - prettier
success Installed "[email protected]" with binaries:
      - serve
Done in 1.65s.

# Prettier binary is available
$ ~/some-dir ➜  prettier --version
1.10.2

$ ~/some-dir ➜  cat package.json
cat: package.json: No such file or directory

$ ~/some-dir ➜  cat $(yarn global dir)/package.json
{
  "dependencies": {
    "prettier": "^1.10.2",
    "serve": "6.0.0"
  }
}

# Upgrade `serve` to the latest version
$ ~/some-dir ➜  yarn global upgrade-interactive --latest
yarn global v1.4.1
info Color legend :
 "<red>"    : Major Update backward-incompatible updates
 "<yellow>" : Minor Update backward-compatible features
 "<green>"  : Patch Update backward-compatible bug fixes
? Choose which packages to update.
? Choose which packages to update. [email protected]
info Installing "dependencies"...
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 35 new dependencies.
├─ @zeit/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
Done in 3.69s.

# Prettier binary no longer exists
$ ~/some-dir ➜  prettier --version
-bash: prettier: command not found

# Suddenly, there is a package.json in the current directory
$ ~/some-dir ➜  cat package.json
{
  "dependencies": {
    "serve": "6.4.9"
  }
}

# Global package.json did not update
$ ~/some-dir ➜  cat $(yarn global dir)/package.json
warning package.json: No license field
{
  "dependencies": {
    "prettier": "^1.10.2",
    "serve": "6.0.0"
  }
}

After

# Outdated version of `serve`, `prettier` for an extra binary
$ ~/some-dir ➜  yarn global add prettier [email protected]
yarn global v1.4.1
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "[email protected]" with binaries:
      - prettier
success Installed "[email protected]" with binaries:
      - serve
Done in 1.92s.

# Prettier binary is available
$ ~/some-dir ➜  prettier --version
1.10.2

$ ~/some-dir ➜  cat package.json
cat: package.json: No such file or directory

$ ~/some-dir ➜  cat $(yarn global dir)/package.json
{
  "dependencies": {
    "prettier": "^1.10.2",
    "serve": "6.0.0"
  }
}

# Upgrade `serve` to the latest version
$ ~/some-dir ➜  yarn global upgrade-interactive --latest
yarn global v1.4.1
info Color legend :
 "<red>"    : Major Update backward-incompatible updates
 "<yellow>" : Minor Update backward-compatible features
 "<green>"  : Patch Update backward-compatible bug fixes
? Choose which packages to update.
? Choose which packages to update. [email protected]
info Installing "dependencies"...
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 34 new dependencies.
├─ @zeit/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
Done in 3.00s.

# Prettier is still available
$ ~/some-dir ➜  prettier --version
1.10.2

$ ~/some-dir ➜  cat package.json
cat: package.json: No such file or directory

# Global package.json was correctly updated
$ ~/some-dir ➜  cat $(yarn global dir)/package.json
{
  "dependencies": {
    "prettier": "^1.10.2",
    "serve": "6.4.9"
  }
}

Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

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

Cool, thanks for fixing my issue #4728 🎉

@arcanis arcanis merged commit 6dbc9d7 into yarnpkg:master Jan 29, 2018
@arcanis
Copy link
Member

arcanis commented Jan 29, 2018

Thanks!

@jungomi jungomi deleted the fix-upgrade-interactive-cwd branch January 29, 2018 18:02
agoldis added a commit to agoldis/yarn that referenced this pull request Feb 2, 2018
…readdir_files

* upstream/master: (34 commits)
  feat(upgrade, add): Separately log added/upgraded dependencies (yarnpkg#5227)
  feat(publish): Publish command uses publishConfig.access in package.json (yarnpkg#5290)
  fix(CLI): Use process exit instead of exitCode for node < 4 (yarnpkg#5291)
  feat(cli): error on missing workspace directory (yarnpkg#5206) (yarnpkg#5222)
  feat: better error when package is not found (yarnpkg#5213)
  Allow scoped package as alias source (yarnpkg#5229)
  fix(cli): Use correct directory for upgrade-interactive (yarnpkg#5272)
  nohoist baseline implementation (yarnpkg#4979)
  1.4.1
  1.4.0
  Show current version, when new version is not supplied on "yarn publish" (yarnpkg#4947)
  fix(install): use node-gyp from homebrew npm (yarnpkg#4994)
  Fix transient symlinks overriding direct ones v2 (yarnpkg#5016)
  fix(auth): Fixes authentication conditions and logic with registries (yarnpkg#5216)
  chore(package): move devDeps to appropriate place (yarnpkg#5166)
  fix(resolution) Eliminate "missing peerDep" warning when dep exists at root level. (yarnpkg#5088)
  fix(cli): improve guessing of package names that contain a dot (yarnpkg#5102) (yarnpkg#5135)
  feat(cli): include notice with license when generating disclaimer (yarnpkg#5072) (yarnpkg#5111)
  feat(cli): group by license in licenses list (yarnpkg#5074) (yarnpkg#5110)
  feat(cli): improve error message when file resolver can't find file (yarnpkg#5134) (yarnpkg#5145)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants