Skip to content

yarn add --cwd invalid-dir should warn/fail #5206

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

Open
thatmarvin opened this issue Jan 10, 2018 · 5 comments · May be fixed by #7372
Open

yarn add --cwd invalid-dir should warn/fail #5206

thatmarvin opened this issue Jan 10, 2018 · 5 comments · May be fixed by #7372

Comments

@thatmarvin
Copy link

Do you want to request a feature or report a bug?

Bug

What is the current behavior?
yarn add --cwd invalid-dir bluebird installs bluebird to the root:

yarn add v1.3.2
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
└─ [email protected]
✨  Done in 0.30s.

If the current behavior is a bug, please provide the steps to reproduce.

Just yarn add --cwd invalid-dir bluebird (and invalid-dir not exist, of course)

What is the expected behavior?
Throw an error, or at least show a warning.

For reference, on npm 5.6.0, npm --prefix invalid-dir bluebird creates invalid-dir and installs it there (which I also think is unexpected behavior), but at least it throws a warning:

$ npm i --prefix invalid-dir bluebird
npm WARN saveError ENOENT: no such file or directory, open '/Users/marvin/devel/yarn-add-cwd-demo/invalid-dir/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/marvin/devel/yarn-add-cwd-demo/invalid-dir/package.json'
npm WARN invalid-dir No description
npm WARN invalid-dir No repository field.
npm WARN invalid-dir No README data
npm WARN invalid-dir No license field.

+ [email protected]
added 1 package in 0.734s

Please mention your node.js, yarn and operating system version.
node v8.9.4, yarn 1.3.4, macOS High Sierra 10.13.2

@maciej-ka
Copy link
Contributor

Hi, I'm on it.

maciej-ka added a commit to maciej-ka/yarn that referenced this issue Jan 15, 2018
maciej-ka added a commit to maciej-ka/yarn that referenced this issue Jan 15, 2018
agoldis added a commit to agoldis/yarn that referenced this issue 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)
  ...
@witalewski
Copy link

Is this issue solved? If not, I'd like to tackle this

@arcanis
Copy link
Member

arcanis commented Nov 5, 2018

It should have been fixed in #5222 (1.5+). Still having this issue?

@witalewski
Copy link

witalewski commented Nov 5, 2018

I'm still having it with yarn 1.13 if the path passed to --cwd doesn't begin with '/':

yarn on  master [!?] is 📦 v1.13.0-0 via ⬢ v8.11.4 took 2s
➜ node $PWD/lib/cli/index.js add --cwd /nonexistent bluebird
yarn add v1.13.0-0
error Directory "/nonexistent" doesn't exist
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

yarn on  master [!?] is 📦 v1.13.0-0 via ⬢ v8.11.4
➜ node $PWD/lib/cli/index.js add --cwd nonexistent bluebird
yarn add v1.13.0-0
[1/5] 🔍  Validating package.json...
[2/5] 🔍  Resolving packages...
[3/5] 🚚  Fetching packages...
[4/5] 🔗  Linking dependencies...
warning " > [email protected]" has incorrect peer dependency "eslint-plugin-babel@^4.1.1".
warning "eslint-config-fb-strict > [email protected]" has incorrect peer dependency "eslint-plugin-babel@^4.1.1".
[5/5] 📃  Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
✨  Done in 10.65s.

@mollyIV
Copy link

mollyIV commented Jul 3, 2019

👋 I was testing the fix for yarn v1.16.0.

Directory path starting with / 👍

$ yarn add --cwd /invalid-dir bluebird
yarn add v1.16.0
error Directory "/invalid-dir" doesn't exist
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Directory path not starting with / (I can imagine that might be a case of relative path or the path on Windows) 🐛

$ yarn add --cwd invalid-dir bluebird
yarn add v1.16.0
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...

success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
✨  Done in 0.39s.

If you do not mind, I would like to work on this and create a PR with the fix 🙏🙇

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

Successfully merging a pull request may close this issue.

6 participants