Skip to content

Commit 587d6f6

Browse files
committed
Meta tweaks
1 parent 4b3b599 commit 587d6f6

Some content is hidden

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

43 files changed

+393
-375
lines changed

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"repository": "sindresorhus/np",
77
"funding": "https://github.com/sindresorhus/np?sponsor=1",
88
"type": "module",
9-
"bin": "source/cli.js",
9+
"bin": "./source/cli.js",
1010
"engines": {
1111
"node": ">=18",
1212
"npm": ">=9",
@@ -44,7 +44,7 @@
4444
"hosted-git-info": "^7.0.1",
4545
"ignore-walk": "^6.0.3",
4646
"import-local": "^3.1.0",
47-
"inquirer": "^9.2.12",
47+
"inquirer": "^9.2.15",
4848
"is-installed-globally": "^1.0.0",
4949
"is-interactive": "^2.0.0",
5050
"is-scoped": "^3.0.0",
@@ -54,9 +54,9 @@
5454
"log-symbols": "^6.0.0",
5555
"meow": "^13.1.0",
5656
"new-github-release-url": "^2.0.0",
57-
"npm-name": "^7.1.1",
57+
"npm-name": "^8.0.0",
5858
"onetime": "^7.0.0",
59-
"open": "^9.1.0",
59+
"open": "^10.0.4",
6060
"ow": "^1.1.1",
6161
"p-memoize": "^7.1.1",
6262
"p-timeout": "^6.1.2",
@@ -65,24 +65,24 @@
6565
"read-package-up": "^11.0.0",
6666
"read-pkg": "^9.0.1",
6767
"rxjs": "^7.8.1",
68-
"semver": "^7.5.4",
68+
"semver": "^7.6.0",
6969
"symbol-observable": "^4.0.0",
7070
"terminal-link": "^3.0.0",
7171
"update-notifier": "^7.0.0"
7272
},
7373
"devDependencies": {
7474
"@sindresorhus/is": "^6.1.0",
75-
"@types/semver": "^7.5.6",
75+
"@types/semver": "^7.5.8",
7676
"ava": "^5.3.1",
7777
"common-tags": "^1.8.2",
78-
"esmock": "^2.6.0",
78+
"esmock": "^2.6.3",
7979
"fs-extra": "^11.1.1",
8080
"map-obj": "^5.0.2",
8181
"sinon": "^17.0.1",
8282
"strip-ansi": "^7.1.0",
8383
"tempy": "^3.1.0",
84-
"write-package": "^7.0.0",
85-
"xo": "^0.56.0"
84+
"write-package": "^7.0.1",
85+
"xo": "^0.57.0"
8686
},
8787
"ava": {
8888
"files": [

source/cli-implementation.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ updateNotifier({pkg: cli.pkg}).notify();
107107
/** @typedef {Awaited<ReturnType<typeof getOptions>>['options']} Options */
108108

109109
export async function getOptions() {
110-
const {pkg, rootDir} = await util.readPkg(cli.flags.contents);
110+
const {package_, rootDirectory} = await util.readPackage(cli.flags.contents);
111111

112-
const localConfig = await config(rootDir);
112+
const localConfig = await config(rootDirectory);
113113
const flags = {
114114
...localConfig,
115115
...cli.flags,
@@ -121,19 +121,19 @@ export async function getOptions() {
121121
}
122122

123123
if (flags.packageManager) {
124-
pkg.packageManager = flags.packageManager;
124+
package_.packageManager = flags.packageManager;
125125
}
126126

127-
const runPublish = !flags.releaseDraftOnly && flags.publish && !pkg.private;
127+
const runPublish = !flags.releaseDraftOnly && flags.publish && !package_.private;
128128

129129
// TODO: does this need to run if `runPublish` is false?
130-
const availability = runPublish ? await npm.isPackageNameAvailable(pkg) : {
130+
const availability = runPublish ? await npm.isPackageNameAvailable(package_) : {
131131
isAvailable: false,
132132
isUnknown: false,
133133
};
134134

135135
// Use current (latest) version when 'releaseDraftOnly', otherwise try to use the first argument.
136-
const version = flags.releaseDraftOnly ? pkg.version : cli.input.at(0);
136+
const version = flags.releaseDraftOnly ? package_.version : cli.input.at(0);
137137

138138
const branch = flags.branch ?? await git.defaultBranch();
139139

@@ -143,26 +143,26 @@ export async function getOptions() {
143143
availability,
144144
version,
145145
branch,
146-
}, {pkg, rootDir});
146+
}, {package_, rootDirectory});
147147

148-
return {options, rootDir, pkg};
148+
return {options, rootDirectory, package_};
149149
}
150150

151151
try {
152-
const {options, rootDir, pkg} = await getOptions();
152+
const {options, rootDirectory, package_} = await getOptions();
153153

154154
if (!options.confirm) {
155155
gracefulExit();
156156
}
157157

158158
console.log(); // Prints a newline for readability
159-
const newPkg = await np(options.version, options, {pkg, rootDir});
159+
const newPackage = await np(options.version, options, {package_, rootDirectory});
160160

161161
if (options.preview || options.releaseDraftOnly) {
162162
gracefulExit();
163163
}
164164

165-
console.log(`\n ${newPkg.name} ${newPkg.version} published 🎉`);
165+
console.log(`\n ${newPackage.name} ${newPackage.version} published 🎉`);
166166
} catch (error) {
167167
console.error(`\n${logSymbols.error} ${error?.stack ?? error}`);
168168
gracefulExit(1);

source/git-util.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const root = async () => {
1414
return stdout;
1515
};
1616

17-
export const newFilesSinceLastRelease = async rootDir => {
17+
export const newFilesSinceLastRelease = async rootDirectory => {
1818
try {
1919
const {stdout} = await execa('git', ['diff', '--name-only', '--diff-filter=A', await latestTag(), 'HEAD']);
2020
if (stdout.trim().length === 0) {
@@ -26,7 +26,7 @@ export const newFilesSinceLastRelease = async rootDir => {
2626
} catch {
2727
// Get all files under version control
2828
return ignoreWalker({
29-
path: rootDir,
29+
path: rootDirectory,
3030
ignoreFiles: ['.gitignore'],
3131
});
3232
}
@@ -234,8 +234,8 @@ export const commitLogFromRevision = async revision => {
234234
return stdout;
235235
};
236236

237-
const push = async (tagArg = '--follow-tags') => {
238-
await execa('git', ['push', tagArg]);
237+
const push = async (tagArgument = '--follow-tags') => {
238+
await execa('git', ['push', tagArgument]);
239239
};
240240

241241
export const pushGraceful = async remoteIsOnGitHub => {

source/index.js

+42-36
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import {execa} from 'execa';
22
import {deleteAsync} from 'del';
33
import Listr from 'listr';
4-
import {merge, catchError, filter, finalize, from} from 'rxjs';
4+
import {
5+
merge,
6+
catchError,
7+
filter,
8+
finalize,
9+
from,
10+
} from 'rxjs';
511
import hostedGitInfo from 'hosted-git-info';
612
import onetime from 'onetime';
713
import {asyncExitHook} from 'exit-hook';
814
import logSymbols from 'log-symbols';
915
import prerequisiteTasks from './prerequisite-tasks.js';
1016
import gitTasks from './git-tasks.js';
1117
import {getPackagePublishArguments} from './npm/publish.js';
12-
import enable2fa, {getEnable2faArgs} from './npm/enable-2fa.js';
18+
import enable2fa, {getEnable2faArguments} from './npm/enable-2fa.js';
1319
import handleNpmError from './npm/handle-npm-error.js';
1420
import releaseTaskHelper from './release-task-helper.js';
1521
import {findLockfile, getPackageManagerConfig, printCommand} from './package-manager/index.js';
@@ -18,20 +24,20 @@ import * as git from './git-util.js';
1824
import * as npm from './npm/util.js';
1925

2026
/** @type {(cmd: string, args: string[], options?: import('execa').Options) => any} */
21-
const exec = (cmd, args, options) => {
27+
const exec = (command, arguments_, options) => {
2228
// Use `Observable` support if merged https://github.com/sindresorhus/execa/pull/26
23-
const cp = execa(cmd, args, options);
29+
const subProcess = execa(command, arguments_, options);
2430

25-
return merge(cp.stdout, cp.stderr, cp).pipe(filter(Boolean));
31+
return merge(subProcess.stdout, subProcess.stderr, subProcess).pipe(filter(Boolean));
2632
};
2733

2834
/**
2935
@param {string} input
3036
@param {import('./cli-implementation.js').Options} options
31-
@param {{pkg: import('read-pkg').NormalizedPackageJson; rootDir: string}} context
37+
@param {{package_: import('read-pkg').NormalizedPackageJson; rootDirectory: string}} context
3238
*/
33-
const np = async (input = 'patch', options, {pkg, rootDir}) => {
34-
const pkgManager = getPackageManagerConfig(rootDir, pkg);
39+
const np = async (input = 'patch', options, {package_, rootDirectory}) => {
40+
const packageManager = getPackageManagerConfig(rootDirectory, package_);
3541

3642
// TODO: Remove sometime far in the future
3743
if (options.skipCleanup) {
@@ -40,13 +46,13 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
4046

4147
const runTests = options.tests && !options.yolo;
4248
const runCleanup = options.cleanup && !options.yolo;
43-
const lockfile = findLockfile(rootDir, pkgManager);
49+
const lockfile = findLockfile(rootDirectory, packageManager);
4450
const isOnGitHub = options.repoUrl && hostedGitInfo.fromUrl(options.repoUrl)?.type === 'github';
4551
const testScript = options.testScript || 'test';
4652

4753
if (options.releaseDraftOnly) {
48-
await releaseTaskHelper(options, pkg, pkgManager);
49-
return pkg;
54+
await releaseTaskHelper(options, package_, packageManager);
55+
return package_;
5056
}
5157

5258
let publishStatus = 'UNKNOWN';
@@ -55,19 +61,19 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
5561
const rollback = onetime(async () => {
5662
console.log('\nPublish failed. Rolling back to the previous state…');
5763

58-
const tagVersionPrefix = await util.getTagVersionPrefix(pkgManager);
64+
const tagVersionPrefix = await util.getTagVersionPrefix(packageManager);
5965

6066
const latestTag = await git.latestTag();
6167
const versionInLatestTag = latestTag.slice(tagVersionPrefix.length);
6268

63-
async function getPkgVersion() {
64-
const pkg = await util.readPkg(rootDir);
65-
return pkg.version;
69+
async function getPackageVersion() {
70+
const package_ = await util.readPackage(rootDirectory);
71+
return package_.version;
6672
}
6773

6874
try {
6975
// Verify that the package's version has been bumped before deleting the last tag and commit.
70-
if (versionInLatestTag === await getPkgVersion() && versionInLatestTag !== pkg.version) {
76+
if (versionInLatestTag === await getPackageVersion() && versionInLatestTag !== package_.version) {
7177
await git.deleteTag(latestTag);
7278
await git.removeLastCommit();
7379
}
@@ -90,23 +96,23 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
9096
}
9197
}, {wait: 2000});
9298

93-
const shouldEnable2FA = options['2fa'] && options.availability.isAvailable && !options.availability.isUnknown && !pkg.private && !npm.isExternalRegistry(pkg);
99+
const shouldEnable2FA = options['2fa'] && options.availability.isAvailable && !options.availability.isUnknown && !package_.private && !npm.isExternalRegistry(package_);
94100

95101
// To prevent the process from hanging due to watch mode (e.g. when running `vitest`)
96102
const ciEnvOptions = {env: {CI: 'true'}};
97103

98104
/** @param {typeof options} _options */
99105
function getPublishCommand(_options) {
100-
const publishCommand = pkgManager.publishCommand || (args => [pkgManager.cli, args]);
101-
const args = getPackagePublishArguments(_options);
102-
return publishCommand(args);
106+
const publishCommand = packageManager.publishCommand || (arguments_ => [packageManager.cli, arguments_]);
107+
const arguments_ = getPackagePublishArguments(_options);
108+
return publishCommand(arguments_);
103109
}
104110

105111
const tasks = new Listr([
106112
{
107113
title: 'Prerequisite check',
108114
enabled: () => options.runPublish,
109-
task: () => prerequisiteTasks(input, pkg, options, pkgManager),
115+
task: () => prerequisiteTasks(input, package_, options, packageManager),
110116
},
111117
{
112118
title: 'Git',
@@ -118,13 +124,13 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
118124
task: () => deleteAsync('node_modules'),
119125
},
120126
{
121-
title: `Installing dependencies using ${pkgManager.id}`,
127+
title: `Installing dependencies using ${packageManager.id}`,
122128
enabled: () => runCleanup,
123129
task: () => new Listr([
124130
{
125131
title: 'Running install command',
126132
task() {
127-
const installCommand = lockfile ? pkgManager.installCommand : pkgManager.installCommandNoLockfile;
133+
const installCommand = lockfile ? packageManager.installCommand : packageManager.installCommandNoLockfile;
128134
return exec(...installCommand);
129135
},
130136
},
@@ -137,29 +143,29 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
137143
{
138144
title: 'Running tests',
139145
enabled: () => runTests,
140-
task: () => exec(pkgManager.cli, ['run', testScript], ciEnvOptions),
146+
task: () => exec(packageManager.cli, ['run', testScript], ciEnvOptions),
141147
},
142148
{
143149
title: 'Bumping version',
144150
skip() {
145151
if (options.preview) {
146-
const [cli, args] = pkgManager.versionCommand(input);
152+
const [cli, arguments_] = packageManager.versionCommand(input);
147153

148154
if (options.message) {
149-
args.push('--message', options.message.replaceAll('%s', input));
155+
arguments_.push('--message', options.message.replaceAll('%s', input));
150156
}
151157

152-
return `[Preview] Command not executed: ${printCommand([cli, args])}`;
158+
return `[Preview] Command not executed: ${printCommand([cli, arguments_])}`;
153159
}
154160
},
155161
task() {
156-
const [cli, args] = pkgManager.versionCommand(input);
162+
const [cli, arguments_] = packageManager.versionCommand(input);
157163

158164
if (options.message) {
159-
args.push('--message', options.message);
165+
arguments_.push('--message', options.message);
160166
}
161167

162-
return exec(cli, args);
168+
return exec(cli, arguments_);
163169
},
164170
},
165171
...options.runPublish ? [
@@ -199,11 +205,11 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
199205
title: 'Enabling two-factor authentication',
200206
async skip() {
201207
if (options.preview) {
202-
const args = await getEnable2faArgs(pkg.name, options);
203-
return `[Preview] Command not executed: npm ${args.join(' ')}.`;
208+
const arguments_ = await getEnable2faArguments(package_.name, options);
209+
return `[Preview] Command not executed: npm ${arguments_.join(' ')}.`;
204210
}
205211
},
206-
task: (context, task) => enable2fa(task, pkg.name, {otp: context.otp}),
212+
task: (context, task) => enable2fa(task, package_.name, {otp: context.otp}),
207213
}] : [],
208214
] : [],
209215
{
@@ -234,7 +240,7 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
234240
}
235241
},
236242
// TODO: parse version outside of index
237-
task: () => releaseTaskHelper(options, pkg, pkgManager),
243+
task: () => releaseTaskHelper(options, package_, packageManager),
238244
}] : [],
239245
], {
240246
showSubtasks: false,
@@ -251,8 +257,8 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
251257
console.error(`\n${logSymbols.error} ${pushedObjects.reason}`);
252258
}
253259

254-
const {pkg: newPkg} = await util.readPkg();
255-
return newPkg;
260+
const {package_: newPackage} = await util.readPackage();
261+
return newPackage;
256262
};
257263

258264
export default np;

source/npm/enable-2fa.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import Version from '../version.js';
44
import handleNpmError from './handle-npm-error.js';
55
import {version as npmVersionCheck} from './util.js';
66

7-
export const getEnable2faArgs = async (packageName, options) => {
7+
export const getEnable2faArguments = async (packageName, options) => {
88
const npmVersion = await npmVersionCheck();
9-
const args = new Version(npmVersion).satisfies('>=9.0.0')
9+
const arguments_ = new Version(npmVersion).satisfies('>=9.0.0')
1010
? ['access', 'set', 'mfa=publish', packageName]
1111
: ['access', '2fa-required', packageName];
1212

1313
if (options && options.otp) {
14-
args.push('--otp', options.otp);
14+
arguments_.push('--otp', options.otp);
1515
}
1616

17-
return args;
17+
return arguments_;
1818
};
1919

20-
const enable2fa = (packageName, options) => execa('npm', getEnable2faArgs(packageName, options));
20+
const enable2fa = (packageName, options) => execa('npm', getEnable2faArguments(packageName, options));
2121

2222
const tryEnable2fa = (task, packageName, options) => {
2323
from(enable2fa(packageName, options)).pipe(

0 commit comments

Comments
 (0)