Skip to content

Commit 4a5a090

Browse files
unkillbobjamestalmage
authored andcommitted
skip publishing if package is flagged as private (sindresorhus#64)
* Don't attempt to npm publish if package flagged as private * Missing semicolon * Change to using load-json-file * Use read-pkg-up to read package.json * Fix lint error * Document private packages in readme * Use readPkgUp.sync
1 parent 4954429 commit 4a5a090

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

index.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
'use strict';
2-
const fs = require('fs');
32
const semver = require('semver');
43
const execa = require('execa');
54
const del = require('del');
6-
const pify = require('pify');
75
const Listr = require('listr');
86
const split = require('split');
97
require('any-observable/register/rxjs-all');
108
const Observable = require('any-observable');
119
const streamToObservable = require('stream-to-observable');
10+
const readPkgUp = require('read-pkg-up');
1211

13-
const fsP = pify(fs);
1412
const VERSIONS = ['major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', 'prerelease'];
1513

1614
const exec = (cmd, args) => {
@@ -116,7 +114,13 @@ module.exports = (input, opts) => {
116114
},
117115
{
118116
title: 'Publishing package',
119-
task: () => exec('npm', ['publish'].concat(opts.tag ? ['--tag', opts.tag] : []))
117+
task: () => {
118+
if (readPkgUp.sync().pkg.private) {
119+
return 'Private package: publishing skipped.';
120+
}
121+
122+
return exec('npm', ['publish'].concat(opts.tag ? ['--tag', opts.tag] : []));
123+
}
120124
},
121125
{
122126
title: 'Pushing tags',
@@ -125,6 +129,6 @@ module.exports = (input, opts) => {
125129
]);
126130

127131
return tasks.run()
128-
.then(() => fsP.readFile('package.json', 'utf8'))
129-
.then(JSON.parse);
132+
.then(() => readPkgUp())
133+
.then(result => result.pkg);
130134
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"execa": "^0.4.0",
3838
"listr": "^0.4.3",
3939
"meow": "^3.7.0",
40-
"pify": "^2.3.0",
40+
"read-pkg-up": "^1.0.1",
4141
"rxjs": "^5.0.0-beta.9",
4242
"semver": "^5.1.0",
4343
"split": "^1.0.0",

private-packages.png

16.9 KB
Loading

readme.md

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ Set the [`sign-git-tag`](https://docs.npmjs.com/misc/config#sign-git-tag) npm co
7272
$ npm config set sign-git-tag true
7373
```
7474

75+
### Private packages
76+
77+
You can use np for modules that aren't publicly published to npm (perhaps installed from a private git repo).
78+
79+
Set `"private": true` in your `package.json` and the publish step will be skipped. All other steps
80+
including versioning and pushing tags will still be completed.
81+
82+
<img src="private-packages.png" width="306">
7583

7684
## License
7785

0 commit comments

Comments
 (0)