np icon indicating copy to clipboard operation
np copied to clipboard

contents flag does not get respected in latest version

Open cambiph opened this issue 4 years ago • 6 comments

Description

When specifying the contents flag like np --contents=./../../ --preview" it seems to be ignored. This may be caused by my setup but I am not sure because using npm publish ./../../ --dry-run does what I expect.

My project has a dependency called vl-ui-util that has a package.json containing an npm run script that calls np. When calling np in the parent project, np will try and publish vl-ui-util instead of the parent project. According to the documentation, this can be fixed using the --contents flag, however, this seems to fail.

Steps to reproduce

  1. Create an empty project via npm init (project A)
  2. Create an empty project via npm init (project B)
  3. Install np as dependency in project B
  4. Create an npm run script in project B which runs np --contents=./../../ --preview" (Script X)
  5. Create an npm run script in project A (Script Y) which runs script X
  6. Call script A

Expected behavior

Np wizard starts and tries to release project A.

Environment

np - 6.3.0 Node.js - 13.12.0 npm - 6.14.5 Git - 2.15.0 OS - OSX Catalina 10.15.5

cambiph avatar Jul 07 '20 13:07 cambiph

On further investigation, it looks like np does publish the right file. However, the root of the project is still the package.json which started the call. You should not think that contents means that np will use the folder specified as root, it only publishes from this folder, much like npm publish does. The rest of the operations will still be working on your current root directory. Look through the comments in #276 and #264 to see the reason why the --contents flag should be used and see whether it makes sense.

dopecodez avatar Jul 13 '20 14:07 dopecodez

@sindresorhus , i suggest we change the readme sligthly to stress this is the use case. I can see where the confusion could arise, I had the same doubt when i first started looking into the issue.

dopecodez avatar Jul 13 '20 14:07 dopecodez

Thanks for the feedback. So there will be no feature to mimick the npm publish ./../../ behaviour?

cambiph avatar Jul 16 '20 10:07 cambiph

np publish contents=./../.. should do exactly the same thing as npm publish ./../../ does. The contents folder will only be taken into consideration while publishing only ie when np internally runs npm publish ./../../, all the other options np performs will be on the package that called np, and not on the contents path.

dopecodez avatar Jul 16 '20 11:07 dopecodez

I'm not sure how to make np work properly with a separate folder. As one of the steps in np is to bump the version, the updated package.json is in the package folder, not in the contents folder, so when it comes time to do the actual publish, the task fails because it is trying to update a version that is already published.

I suppose the alternative is to use publish: false, then delegate the bundling to the contents folder and publish that with npm publish ./contents?

twelve17 avatar Jan 28 '21 00:01 twelve17

@twelve17 I am also experiencing this case, I'm almost certain it's an oversight on my end. Did you manage to find a solution?

STLMikey avatar Feb 26 '21 21:02 STLMikey