Skip to content

Commit 1cb22e0

Browse files
Internal improvements, add more tests (#689)
1 parent 885cc94 commit 1cb22e0

File tree

93 files changed

+3446
-1056
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3446
-1056
lines changed

package.json

+28-18
Original file line numberDiff line numberDiff line change
@@ -31,60 +31,70 @@
3131
"commit"
3232
],
3333
"dependencies": {
34-
"chalk": "^5.2.0",
34+
"chalk": "^5.3.0",
35+
"chalk-template": "^1.1.0",
3536
"cosmiconfig": "^8.1.3",
36-
"del": "^7.0.0",
37+
"del": "^7.1.0",
3738
"escape-goat": "^4.0.0",
3839
"escape-string-regexp": "^5.0.0",
39-
"execa": "^7.1.1",
40-
"exit-hook": "^3.2.0",
40+
"execa": "^8.0.1",
41+
"exit-hook": "^4.0.0",
4142
"github-url-from-git": "^1.5.0",
4243
"has-yarn": "^3.0.0",
43-
"hosted-git-info": "^6.1.1",
44+
"hosted-git-info": "^7.0.0",
4445
"ignore-walk": "^6.0.3",
4546
"import-local": "^3.1.0",
46-
"inquirer": "^9.2.6",
47+
"inquirer": "^9.2.10",
4748
"is-installed-globally": "^0.4.0",
4849
"is-interactive": "^2.0.0",
4950
"is-scoped": "^3.0.0",
5051
"issue-regex": "^4.1.0",
5152
"listr": "^0.14.3",
5253
"listr-input": "^0.2.1",
5354
"log-symbols": "^5.1.0",
54-
"meow": "^12.0.1",
55+
"meow": "^12.1.1",
5556
"new-github-release-url": "^2.0.0",
5657
"npm-name": "^7.1.0",
5758
"onetime": "^6.0.0",
5859
"open": "^9.1.0",
5960
"ow": "^1.1.1",
6061
"p-memoize": "^7.1.1",
61-
"p-timeout": "^6.1.1",
62+
"p-timeout": "^6.1.2",
6263
"path-exists": "^5.0.0",
6364
"pkg-dir": "^7.0.0",
64-
"read-pkg-up": "^9.1.0",
65+
"read-pkg": "^8.1.0",
66+
"read-pkg-up": "^10.1.0",
6567
"rxjs": "^7.8.1",
66-
"semver": "^7.5.1",
68+
"semver": "^7.5.4",
6769
"symbol-observable": "^4.0.0",
6870
"terminal-link": "^3.0.0",
6971
"update-notifier": "^6.0.2"
7072
},
7173
"devDependencies": {
72-
"ava": "^5.3.0",
74+
"@sindresorhus/is": "^6.0.0",
75+
"@types/semver": "^7.5.1",
76+
"ava": "^5.3.1",
7377
"common-tags": "^1.8.2",
74-
"esmock": "^2.2.3",
78+
"esmock": "^2.3.8",
7579
"fs-extra": "^11.1.1",
76-
"move-file": "^3.1.0",
77-
"sinon": "^15.1.0",
78-
"tempy": "^3.0.0",
79-
"write-pkg": "^5.1.0",
80-
"xo": "^0.54.2"
80+
"map-obj": "^5.0.2",
81+
"sinon": "^15.2.0",
82+
"strip-ansi": "^7.1.0",
83+
"tempy": "^3.1.0",
84+
"write-pkg": "^6.0.0",
85+
"xo": "^0.56.0"
8186
},
8287
"ava": {
88+
"files": [
89+
"!test/fixtures",
90+
"!test/_helpers"
91+
],
8392
"environmentVariables": {
8493
"FORCE_HYPERLINK": "1"
8594
},
8695
"nodeArguments": [
87-
"--loader=esmock"
96+
"--loader=esmock",
97+
"--no-warnings=ExperimentalWarning"
8898
]
8999
}
90100
}

readme.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ $ np --help
7373
$ np <version>
7474
7575
Version can be:
76-
patch | minor | major | prepatch | preminor | premajor | prerelease | 1.2.3
76+
major | minor | patch | premajor | preminor | prepatch | prerelease | 1.2.3
7777
7878
Options
7979
--any-branch Allow publishing from any branch
@@ -87,7 +87,7 @@ $ np --help
8787
--no-yarn Don't use Yarn
8888
--contents Subdirectory to publish
8989
--no-release-draft Skips opening a GitHub release draft
90-
--release-draft-only Only opens a GitHub release draft
90+
--release-draft-only Only opens a GitHub release draft for the latest published version
9191
--test-script Name of npm run script to run tests before publishing (default: test)
9292
--no-2fa Don't enable 2FA on new packages (not recommended)
9393
--message Version bump commit message. `%s` will be replaced with version. (default: '%s' with npm and 'v%s' with yarn)
@@ -113,7 +113,7 @@ Run `np` without arguments to launch the interactive UI that guides you through
113113
Currently, these are the flags you can configure:
114114

115115
- `anyBranch` - Allow publishing from any branch (`false` by default).
116-
- `branch` - Name of the release branch (`master` by default).
116+
- `branch` - Name of the release branch (`main` or `master` by default).
117117
- `cleanup` - Cleanup `node_modules` (`true` by default).
118118
- `tests` - Run `npm test` (`true` by default).
119119
- `yolo` - Skip cleanup and testing (`false` by default).
@@ -346,6 +346,8 @@ npm ERR! 403 Forbidden - GET https://registry.yarnpkg.com/-/package/my-awesome-p
346346
"publishConfig": {
347347
"registry": "https://registry.npmjs.org"
348348
}
349+
350+
Note: On `npm` v9+, the command has been changed to `npm access list collaborators my-awesome-package`.
349351
```
350352

351353
## Maintainers

source/cli-implementation.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import config from './config.js';
1010
import * as util from './util.js';
1111
import * as git from './git-util.js';
1212
import * as npm from './npm/util.js';
13-
import Version from './version.js';
13+
import {SEMVER_INCREMENTS} from './version.js';
1414
import ui from './ui.js';
1515
import np from './index.js';
1616

@@ -19,7 +19,7 @@ const cli = meow(`
1919
$ np <version>
2020
2121
Version can be:
22-
${Version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3
22+
${SEMVER_INCREMENTS.join(' | ')} | 1.2.3
2323
2424
Options
2525
--any-branch Allow publishing from any branch
@@ -56,18 +56,22 @@ const cli = meow(`
5656
},
5757
cleanup: {
5858
type: 'boolean',
59+
default: true,
5960
},
6061
tests: {
6162
type: 'boolean',
63+
default: true,
6264
},
6365
yolo: {
6466
type: 'boolean',
6567
},
6668
publish: {
6769
type: 'boolean',
70+
default: true,
6871
},
6972
releaseDraft: {
7073
type: 'boolean',
74+
default: true,
7175
},
7276
releaseDraftOnly: {
7377
type: 'boolean',
@@ -77,6 +81,7 @@ const cli = meow(`
7781
},
7882
yarn: {
7983
type: 'boolean',
84+
default: hasYarn(),
8085
},
8186
contents: {
8287
type: 'string',
@@ -89,6 +94,7 @@ const cli = meow(`
8994
},
9095
'2fa': {
9196
type: 'boolean',
97+
default: true,
9298
},
9399
message: {
94100
type: 'string',
@@ -101,19 +107,8 @@ updateNotifier({pkg: cli.pkg}).notify();
101107
try {
102108
const {pkg, rootDir} = await util.readPkg(cli.flags.contents);
103109

104-
const defaultFlags = {
105-
cleanup: true,
106-
tests: true,
107-
publish: true,
108-
releaseDraft: true,
109-
yarn: hasYarn(),
110-
'2fa': true,
111-
};
112-
113110
const localConfig = await config(rootDir);
114-
115111
const flags = {
116-
...defaultFlags,
117112
...localConfig,
118113
...cli.flags,
119114
};
@@ -125,20 +120,22 @@ try {
125120

126121
const runPublish = !flags.releaseDraftOnly && flags.publish && !pkg.private;
127122

128-
const availability = flags.publish ? await npm.isPackageNameAvailable(pkg) : {
123+
// TODO: does this need to run if `runPublish` is false?
124+
const availability = runPublish ? await npm.isPackageNameAvailable(pkg) : {
129125
isAvailable: false,
130126
isUnknown: false,
131127
};
132128

133-
// Use current (latest) version when 'releaseDraftOnly', otherwise use the first argument.
134-
const version = flags.releaseDraftOnly ? pkg.version : (cli.input.length > 0 ? cli.input[0] : false);
129+
// Use current (latest) version when 'releaseDraftOnly', otherwise try to use the first argument.
130+
const version = flags.releaseDraftOnly ? pkg.version : cli.input.at(0);
131+
132+
const branch = flags.branch ?? await git.defaultBranch();
135133

136-
const branch = flags.branch || await git.defaultBranch();
137134
const options = await ui({
138135
...flags,
136+
runPublish,
139137
availability,
140138
version,
141-
runPublish,
142139
branch,
143140
}, {pkg, rootDir});
144141

source/cli.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#!/usr/bin/env node
2-
import {fileURLToPath} from 'node:url';
32
import {debuglog} from 'node:util';
43
import importLocal from 'import-local';
54
import isInstalledGlobally from 'is-installed-globally';
65

7-
const __filename = fileURLToPath(import.meta.url);
86
const log = debuglog('np');
97

108
// Prefer the local installation
11-
if (!importLocal(__filename)) {
9+
if (!importLocal(import.meta.url)) {
1210
if (isInstalledGlobally) {
1311
log('Using global install of np.');
1412
}

source/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'node:os';
22
import isInstalledGlobally from 'is-installed-globally';
33
import {cosmiconfig} from 'cosmiconfig';
44

5-
// TODO: remove when cosmiconfig/cosmiconfig#283 lands
5+
// TODO: Remove when cosmiconfig/cosmiconfig#283 lands
66
const loadESM = async filepath => {
77
const module = await import(filepath);
88
return module.default ?? module;

0 commit comments

Comments
 (0)