Don't attempt to npm publish if package flagged as private in package.json #64

Merged
merged 7 commits into from Jul 22, 2016

Projects

None yet

4 participants

@unkillbob
Contributor
unkillbob commented Jul 19, 2016 edited

Fixes #65

private

We have a bunch of packages that are installed out of private git repos and attempting to use np fails at the second last step as npm publish exits with an error when the package.json specifies private: true.

This pull request makes the change to simply skip the publish step if the package is flagged as private. I wasn't sure whether you'd want this mentioned in the readme or not - let me know if I should update it.

np is really awesome and exactly what we needed, I hope we can get this small change in to adapt it for our use case!

@SamVerschueren
Collaborator

np is all about publishing a module. Shouldn't this just be a prerequisite check and exit early? Just wondering.

@SamVerschueren SamVerschueren commented on an outdated diff Jul 19, 2016
@@ -116,7 +121,12 @@ module.exports = (input, opts) => {
},
{
title: 'Publishing package',
- task: () => exec('npm', ['publish'].concat(opts.tag ? ['--tag', opts.tag] : []))
+ task: () => getPackageJson()
@SamVerschueren
SamVerschueren Jul 19, 2016 Collaborator

Use the load-json-file package here

@unkillbob
Contributor

np is all about publishing a module. Shouldn't this just be a prerequisite check and exit early?

We still "publish" these modules (we install them from the tag produced by npm version) so need all the other aspects of np (clean, npm install, version bump, push tags, etc).

@jamestalmage
Collaborator

I think this makes sense.

However, you should use read-pkg-up instead.

Also, it should very clearly state that the publish step was skipped, and why.

private package: publishing skipped

Is it possible to publish private packages on npm if they are namespaced and you have a paid account? If so we may need to add extra logic for that.

@unkillbob
Contributor

Is it possible to publish private packages on npm if they are namespaced and you have a paid account?

Reading the docs (https://docs.npmjs.com/files/package.json#private) it doesn't look like it. The purpose of private:true is to prevent accidental publishing. If you simply want to change where your package is published to you configure the publishConfig instead.

@jamestalmage
Collaborator

Yeah, this makes sense then. If private:true, then npm publish will always fail. Relying on git tagging just makes sense then.

As stated - use read-pkg-up, and provide a good message when private mode is encountered. Otherwise 👍

@unkillbob
Contributor

provide a good message when private mode is encountered

Not really sure how to accomplish this with Listr - are you able to point me in the right direction?

I tried resolving the 'publish' task's promise to the message, I tried exec'ing an echo with the message and I tried a console.log - all happen so fast you don't even see it.

@jamestalmage jamestalmage referenced this pull request in SamVerschueren/listr Jul 19, 2016
Closed

Skippable Tasks #15

@unkillbob
Contributor

@jamestalmage yes that's exactly what I need, thanks for raising those issues! In the meantime I've addressed all your other feedback - hopefully this can go ahead without the official skip warning?

@sindresorhus sindresorhus commented on an outdated diff Jul 20, 2016
@@ -116,7 +114,14 @@ module.exports = (input, opts) => {
},
{
title: 'Publishing package',
- task: () => exec('npm', ['publish'].concat(opts.tag ? ['--tag', opts.tag] : []))
+ task: () => readPkgUp()
@sindresorhus
sindresorhus Jul 20, 2016 Owner

I would use readPkgUp.sync() here. No real benefit of using async fs here as these tasks are done serially.

@sindresorhus
Owner

hopefully this can go ahead without the official skip warning?

Sure, just open an issue with the remaining work so we don't forget.

@sindresorhus
Owner

Looks great. Could you add a note to the readme about the behavior? This might be useful for other people to, but I don't think they would realize it's possible without some kind of indication.

@unkillbob
Contributor

Skipping tasks is hopefully not too far away (SamVerschueren/listr#17), happy to hold out for that - this isn't super urgent for us.

@jamestalmage jamestalmage merged commit 4a5a090 into sindresorhus:master Jul 22, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jamestalmage
Collaborator

Skipping tasks is hopefully not too far away (SamVerschueren/listr#17), happy to hold out for that

We can follow up once that lands.

Great work. Thanks!

@sindresorhus
Owner

Excellent work on this @unkillbob :) Cheers.

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