Yarn: Support for specifying package.json path?

Created on 21 Jan 2017  路  9Comments  路  Source: yarnpkg/yarn

I'm sorry if this has been asked before, but I can't find it in the issue list.

How can I specify the path to a (local) package.json? When deploying apps with eg. ansible, the way yarn works right now forces messing about with cwd, not ideal.

npm supports the -C flag to npm install which sets the current working directory; not ideal either but better than nothing.

yarn 0.19.1

Most helpful comment

Can you provide more details about why and how you need this

Given this directory structure:

  \- package.json  # <- using workspaces package1 and package2
  \- package1
       \- package.json
  \- package2
       \- package.json

I was attempting a workaround for https://github.com/yarnpkg/yarn/issues/6715. I was hoping I could force the installer to only install the dependencies defined in package1/package.json into package1/node_modules with something like this:

# Pseudo code that I wish I could do:
cd package1
yarn install --modules-folder node_modules --package-file package.json

So I could test packages in isolation. Currently, only everything defined in myproject/package.json is installed. If I delete myproject/package.json then I can run yarn install and it does what I wish it would do even if I had not deleted that file ;)

I just wanted to mention my use-case, it will eventually be solved when that other issue with the --focus flag is solved.

Thank you for your hard work!

All 9 comments

+1

@jleclanche Were you able to figure this out? I am stuck on the same issue.

Nope. using cwd overrides.

Hey @jleclanche, I think my issues were because $(yarn bin) was not in the path when invoking scripts in package.json. I fixed this by doing the following:

client/package.json

"scripts": {
"postinstall": "echo \"Postinstall running - client/package.json\"",

config/deploy/feature.rb (this should be production.rb if you are trying to deploy it to production environment)

set :yarn_flags, '--production'

package.json

"scripts": {
"postinstall": "cd client && npm install && echo \"Postinstall running\"",

Let me know if this helps.

Can you provide more details about why and how you need this and about your environment so we can assess?

@BYK this is needed for example if we want to avoid using cwd directives when deploying using eg. ansible, or anything else that is cwd-agnostic.

@jleclanche what's wrong with using cwd, though? Because I'm pretty sure even if we introduce this feature, I'm guessing we'd do the switching internally.

@BYK In my case I want to run unit tests with multiple dependency versions

Can you provide more details about why and how you need this

Given this directory structure:

  \- package.json  # <- using workspaces package1 and package2
  \- package1
       \- package.json
  \- package2
       \- package.json

I was attempting a workaround for https://github.com/yarnpkg/yarn/issues/6715. I was hoping I could force the installer to only install the dependencies defined in package1/package.json into package1/node_modules with something like this:

# Pseudo code that I wish I could do:
cd package1
yarn install --modules-folder node_modules --package-file package.json

So I could test packages in isolation. Currently, only everything defined in myproject/package.json is installed. If I delete myproject/package.json then I can run yarn install and it does what I wish it would do even if I had not deleted that file ;)

I just wanted to mention my use-case, it will eventually be solved when that other issue with the --focus flag is solved.

Thank you for your hard work!

Was this page helpful?
0 / 5 - 0 ratings