Skip to content

Commit 72879e0

Browse files
Move to ESM, update dependencies (#683)
1 parent 6867fb9 commit 72879e0

Some content is hidden

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

42 files changed

+1362
-1173
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 14
14-
- 12
15-
- 10
13+
- 19
14+
- 18
15+
- 16
1616
steps:
17-
- uses: actions/checkout@v2
18-
with:
19-
submodules: true
20-
- uses: actions/setup-node@v2
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-node@v3
2119
with:
2220
node-version: ${{ matrix.node-version }}
2321
- run: git config --global user.name "Github Actions"

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

integration-test

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

package.json

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
"license": "MIT",
66
"repository": "sindresorhus/np",
77
"funding": "https://github.com/sindresorhus/np?sponsor=1",
8+
"type": "module",
89
"bin": "source/cli.js",
910
"engines": {
10-
"node": ">=10",
11-
"npm": ">=6.8.0",
11+
"node": ">=16.6.0",
12+
"npm": ">=7.19.0",
1213
"git": ">=2.11.0",
1314
"yarn": ">=1.7.0"
1415
},
1516
"scripts": {
16-
"test": "xo && FORCE_HYPERLINK=1 ava"
17+
"test": "xo && ava && ava test/integration.js --no-worker-threads"
1718
},
1819
"files": [
1920
"source"
@@ -30,63 +31,60 @@
3031
"commit"
3132
],
3233
"dependencies": {
33-
"@samverschueren/stream-to-observable": "^0.3.1",
34-
"any-observable": "^0.5.1",
35-
"async-exit-hook": "^2.0.1",
36-
"chalk": "^4.1.0",
37-
"cosmiconfig": "^7.0.0",
38-
"del": "^6.0.0",
39-
"escape-goat": "^3.0.0",
40-
"escape-string-regexp": "^4.0.0",
41-
"execa": "^5.0.0",
34+
"chalk": "^5.2.0",
35+
"cosmiconfig": "^8.1.3",
36+
"del": "^7.0.0",
37+
"escape-goat": "^4.0.0",
38+
"escape-string-regexp": "^5.0.0",
39+
"execa": "^7.1.1",
40+
"exit-hook": "^3.2.0",
4241
"github-url-from-git": "^1.5.0",
43-
"has-yarn": "^2.1.0",
44-
"hosted-git-info": "^3.0.7",
45-
"ignore-walk": "^3.0.3",
46-
"import-local": "^3.0.2",
47-
"inquirer": "^7.3.3",
48-
"is-installed-globally": "^0.3.2",
49-
"is-interactive": "^1.0.0",
50-
"is-scoped": "^2.1.0",
51-
"issue-regex": "^3.1.0",
42+
"has-yarn": "^3.0.0",
43+
"hosted-git-info": "^6.1.1",
44+
"ignore-walk": "^6.0.2",
45+
"import-local": "^3.1.0",
46+
"inquirer": "^9.1.5",
47+
"is-installed-globally": "^0.4.0",
48+
"is-interactive": "^2.0.0",
49+
"is-scoped": "^3.0.0",
50+
"issue-regex": "^4.1.0",
5251
"listr": "^0.14.3",
5352
"listr-input": "^0.2.1",
54-
"log-symbols": "^4.0.0",
55-
"meow": "^8.1.0",
56-
"minimatch": "^3.0.4",
57-
"new-github-release-url": "^1.0.0",
58-
"npm-name": "^6.0.1",
59-
"onetime": "^5.1.2",
60-
"open": "^7.3.0",
61-
"ow": "^0.21.0",
62-
"p-memoize": "^4.0.1",
63-
"p-timeout": "^4.1.0",
64-
"pkg-dir": "^5.0.0",
65-
"read-pkg-up": "^7.0.1",
66-
"rxjs": "^6.6.3",
67-
"semver": "^7.3.4",
68-
"split": "^1.0.1",
69-
"symbol-observable": "^3.0.0",
70-
"terminal-link": "^2.1.1",
71-
"update-notifier": "^5.0.1"
53+
"log-symbols": "^5.1.0",
54+
"meow": "^11.0.0",
55+
"minimatch": "^8.0.2",
56+
"new-github-release-url": "^2.0.0",
57+
"npm-name": "^7.1.0",
58+
"onetime": "^6.0.0",
59+
"open": "^9.1.0",
60+
"ow": "^1.1.1",
61+
"p-memoize": "^7.1.1",
62+
"p-timeout": "^6.1.1",
63+
"pkg-dir": "^7.0.0",
64+
"read-pkg-up": "^9.1.0",
65+
"rxjs": "^7.8.0",
66+
"semver": "^7.3.8",
67+
"symbol-observable": "^4.0.0",
68+
"terminal-link": "^3.0.0",
69+
"update-notifier": "^6.0.2"
7270
},
7371
"devDependencies": {
74-
"ava": "^2.3.0",
75-
"execa_test_double": "^4.0.1",
76-
"mockery": "^2.1.0",
77-
"proxyquire": "^2.1.3",
78-
"sinon": "^9.2.2",
79-
"xo": "^0.36.1"
72+
"ava": "^5.2.0",
73+
"common-tags": "^1.8.2",
74+
"esmock": "^2.2.0",
75+
"fs-extra": "^11.1.1",
76+
"sinon": "^15.0.3",
77+
"xo": "^0.53.1"
8078
},
8179
"ava": {
80+
"environmentVariables": {
81+
"FORCE_HYPERLINK": "1"
82+
},
8283
"files": [
83-
"!test/fixtures",
84-
"!integration-test"
85-
]
86-
},
87-
"xo": {
88-
"ignores": [
89-
"integration-test"
84+
"!test/integration.js"
85+
],
86+
"nodeArguments": [
87+
"--loader=esmock"
9088
]
9189
}
9290
}

readme.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
---
2424

25-
<img src="screenshot.gif" width="688">
25+
<img src="media/screenshot.gif" width="688">
2626

2727
## Why
2828

@@ -54,8 +54,8 @@
5454

5555
## Prerequisite
5656

57-
- Node.js 10 or later
58-
- npm 6.8.0 or later
57+
- Node.js 16 or later
58+
- npm 7.19.0 or later
5959
- Git 2.11 or later
6060

6161
## Install
@@ -104,11 +104,11 @@ $ np --help
104104

105105
Run `np` without arguments to launch the interactive UI that guides you through publishing a new version.
106106

107-
<img src="screenshot-ui.png" width="1290">
107+
<img src="media/screenshot-ui.png" width="1290">
108108

109109
## Config
110110

111-
`np` can be configured both locally and globally. When using the global `np` binary, you can configure any of the CLI flags in either a `.np-config.js`, `.np-config.cjs` or `.np-config.json` file in the home directory. When using the local `np` binary, for example, in a `npm run` script, you can configure `np` by setting the flags in either a top-level `np` field in `package.json` or in a `.np-config.js`, `.np-config.cjs` or `.np-config.json` file in the project directory. If it exists, the local installation will always take precedence. This ensures any local config matches the version of `np` it was designed for.
111+
`np` can be configured both globally and locally. When using the global `np` binary, you can configure any of the CLI flags in either a `.np-config.js` (as CJS), `.np-config.cjs`, `.np-config.mjs`, or `.np-config.json` file in the home directory. When using the local `np` binary, for example, in a `npm run` script, you can configure `np` by setting the flags in either a top-level `np` field in `package.json` or in one of the aforementioned file types in the project directory. If it exists, the local installation will always take precedence. This ensures any local config matches the version of `np` it was designed for.
112112

113113
Currently, these are the flags you can configure:
114114

@@ -156,6 +156,14 @@ module.exports = {
156156
};
157157
```
158158

159+
`.np-config.mjs`
160+
```js
161+
export default {
162+
yarn: false,
163+
contents: 'dist'
164+
};
165+
```
166+
159167
_**Note:** The global config only applies when using the global `np` binary, and is never inherited when using a local binary._
160168

161169
## Tips
@@ -226,7 +234,7 @@ $ yarn config set version-sign-git-tag true
226234

227235
### Private packages
228236

229-
<img src="private-packages.png" width="260" align="right">
237+
<img src="media/private-packages.png" width="260" align="right">
230238

231239
You can use `np` for packages that aren't publicly published to npm (perhaps installed from a private git repo).
232240

source/cli-implementation.js

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#!/usr/bin/env node
2-
'use strict';
32
// eslint-disable-next-line import/no-unassigned-import
4-
require('symbol-observable'); // Important: This needs to be first to prevent weird Observable incompatibilities
5-
const logSymbols = require('log-symbols');
6-
const meow = require('meow');
7-
const updateNotifier = require('update-notifier');
8-
const hasYarn = require('has-yarn');
9-
const config = require('./config');
10-
const git = require('./git-util');
11-
const {isPackageNameAvailable} = require('./npm/util');
12-
const version = require('./version');
13-
const util = require('./util');
14-
const ui = require('./ui');
15-
const np = require('.');
3+
import 'symbol-observable'; // Important: This needs to be first to prevent weird Observable incompatibilities
4+
import logSymbols from 'log-symbols';
5+
import meow from 'meow';
6+
import updateNotifier from 'update-notifier';
7+
import hasYarn from 'has-yarn';
8+
import {gracefulExit} from 'exit-hook';
9+
import config from './config.js';
10+
import * as git from './git-util.js';
11+
import {isPackageNameAvailable} from './npm/util.js';
12+
import Version from './version.js';
13+
import * as util from './util.js';
14+
import ui from './ui.js';
15+
import np from './index.js';
1616

1717
const cli = meow(`
1818
Usage
1919
$ np <version>
2020
2121
Version can be:
22-
${version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3
22+
${Version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3
2323
2424
Options
2525
--any-branch Allow publishing from any branch
@@ -45,76 +45,77 @@ const cli = meow(`
4545
$ np 1.0.2-beta.3 --tag=beta
4646
$ np 1.0.2-beta.3 --tag=beta --contents=dist
4747
`, {
48+
importMeta: import.meta,
4849
booleanDefault: undefined,
4950
flags: {
5051
anyBranch: {
51-
type: 'boolean'
52+
type: 'boolean',
5253
},
5354
branch: {
54-
type: 'string'
55+
type: 'string',
5556
},
5657
cleanup: {
57-
type: 'boolean'
58+
type: 'boolean',
5859
},
5960
tests: {
60-
type: 'boolean'
61+
type: 'boolean',
6162
},
6263
yolo: {
63-
type: 'boolean'
64+
type: 'boolean',
6465
},
6566
publish: {
66-
type: 'boolean'
67+
type: 'boolean',
6768
},
6869
releaseDraft: {
69-
type: 'boolean'
70+
type: 'boolean',
7071
},
7172
releaseDraftOnly: {
72-
type: 'boolean'
73+
type: 'boolean',
7374
},
7475
tag: {
75-
type: 'string'
76+
type: 'string',
7677
},
7778
yarn: {
78-
type: 'boolean'
79+
type: 'boolean',
7980
},
8081
contents: {
81-
type: 'string'
82+
type: 'string',
8283
},
8384
preview: {
84-
type: 'boolean'
85+
type: 'boolean',
8586
},
8687
testScript: {
87-
type: 'string'
88+
type: 'string',
8889
},
8990
'2fa': {
90-
type: 'boolean'
91+
type: 'boolean',
9192
},
9293
message: {
93-
type: 'string'
94-
}
95-
}
94+
type: 'string',
95+
},
96+
},
9697
});
9798

9899
updateNotifier({pkg: cli.pkg}).notify();
99100

100-
(async () => {
101-
const {pkg, pkgPath} = util.readPkg();
101+
try {
102+
const {pkg, pkgPath} = await util.readPkg();
102103

103104
const defaultFlags = {
104105
cleanup: true,
105106
tests: true,
106107
publish: true,
107108
releaseDraft: true,
108109
yarn: hasYarn(),
109-
'2fa': true
110+
'2fa': true,
110111
};
111112

112113
const localConfig = await config();
113114

114115
const flags = {
115116
...defaultFlags,
116117
...localConfig,
117-
...cli.flags
118+
...cli.flags,
118119
};
119120

120121
// Workaround for unintended auto-casing behavior from `meow`.
@@ -126,7 +127,7 @@ updateNotifier({pkg: cli.pkg}).notify();
126127

127128
const availability = flags.publish ? await isPackageNameAvailable(pkg) : {
128129
isAvailable: false,
129-
isUnknown: false
130+
isUnknown: false,
130131
};
131132

132133
// Use current (latest) version when 'releaseDraftOnly', otherwise use the first argument.
@@ -138,22 +139,22 @@ updateNotifier({pkg: cli.pkg}).notify();
138139
availability,
139140
version,
140141
runPublish,
141-
branch
142+
branch,
142143
}, {pkg, pkgPath});
143144

144145
if (!options.confirm) {
145-
process.exit(0);
146+
gracefulExit();
146147
}
147148

148149
console.log(); // Prints a newline for readability
149150
const newPkg = await np(options.version, options);
150151

151152
if (options.preview || options.releaseDraftOnly) {
152-
return;
153+
gracefulExit();
153154
}
154155

155156
console.log(`\n ${newPkg.name} ${newPkg.version} published 🎉`);
156-
})().catch(error => {
157+
} catch (error) {
157158
console.error(`\n${logSymbols.error} ${error.message}`);
158-
process.exit(1);
159-
});
159+
gracefulExit(1);
160+
}

0 commit comments

Comments
 (0)