np
np copied to clipboard
contents flag does not get respected in latest version
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
- Create an empty project via npm init (project A)
- Create an empty project via npm init (project B)
- Install np as dependency in project B
- Create an npm run script in project B which runs
np --contents=./../../ --preview"
(Script X) - Create an npm run script in project A (Script Y) which runs script X
- 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
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.
@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.
Thanks for the feedback.
So there will be no feature to mimick the npm publish ./../../
behaviour?
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.
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 I am also experiencing this case, I'm almost certain it's an oversight on my end. Did you manage to find a solution?