1
1
import { execa } from 'execa' ;
2
2
import { deleteAsync } from 'del' ;
3
3
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' ;
5
11
import hostedGitInfo from 'hosted-git-info' ;
6
12
import onetime from 'onetime' ;
7
13
import { asyncExitHook } from 'exit-hook' ;
8
14
import logSymbols from 'log-symbols' ;
9
15
import prerequisiteTasks from './prerequisite-tasks.js' ;
10
16
import gitTasks from './git-tasks.js' ;
11
17
import { getPackagePublishArguments } from './npm/publish.js' ;
12
- import enable2fa , { getEnable2faArgs } from './npm/enable-2fa.js' ;
18
+ import enable2fa , { getEnable2faArguments } from './npm/enable-2fa.js' ;
13
19
import handleNpmError from './npm/handle-npm-error.js' ;
14
20
import releaseTaskHelper from './release-task-helper.js' ;
15
21
import { findLockfile , getPackageManagerConfig , printCommand } from './package-manager/index.js' ;
@@ -18,20 +24,20 @@ import * as git from './git-util.js';
18
24
import * as npm from './npm/util.js' ;
19
25
20
26
/** @type {(cmd: string, args: string[], options?: import('execa').Options) => any } */
21
- const exec = ( cmd , args , options ) => {
27
+ const exec = ( command , arguments_ , options ) => {
22
28
// 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 ) ;
24
30
25
- return merge ( cp . stdout , cp . stderr , cp ) . pipe ( filter ( Boolean ) ) ;
31
+ return merge ( subProcess . stdout , subProcess . stderr , subProcess ) . pipe ( filter ( Boolean ) ) ;
26
32
} ;
27
33
28
34
/**
29
35
@param {string } input
30
36
@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
32
38
*/
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_ ) ;
35
41
36
42
// TODO: Remove sometime far in the future
37
43
if ( options . skipCleanup ) {
@@ -40,13 +46,13 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
40
46
41
47
const runTests = options . tests && ! options . yolo ;
42
48
const runCleanup = options . cleanup && ! options . yolo ;
43
- const lockfile = findLockfile ( rootDir , pkgManager ) ;
49
+ const lockfile = findLockfile ( rootDirectory , packageManager ) ;
44
50
const isOnGitHub = options . repoUrl && hostedGitInfo . fromUrl ( options . repoUrl ) ?. type === 'github' ;
45
51
const testScript = options . testScript || 'test' ;
46
52
47
53
if ( options . releaseDraftOnly ) {
48
- await releaseTaskHelper ( options , pkg , pkgManager ) ;
49
- return pkg ;
54
+ await releaseTaskHelper ( options , package_ , packageManager ) ;
55
+ return package_ ;
50
56
}
51
57
52
58
let publishStatus = 'UNKNOWN' ;
@@ -55,19 +61,19 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
55
61
const rollback = onetime ( async ( ) => {
56
62
console . log ( '\nPublish failed. Rolling back to the previous state…' ) ;
57
63
58
- const tagVersionPrefix = await util . getTagVersionPrefix ( pkgManager ) ;
64
+ const tagVersionPrefix = await util . getTagVersionPrefix ( packageManager ) ;
59
65
60
66
const latestTag = await git . latestTag ( ) ;
61
67
const versionInLatestTag = latestTag . slice ( tagVersionPrefix . length ) ;
62
68
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 ;
66
72
}
67
73
68
74
try {
69
75
// 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 ) {
71
77
await git . deleteTag ( latestTag ) ;
72
78
await git . removeLastCommit ( ) ;
73
79
}
@@ -90,23 +96,23 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
90
96
}
91
97
} , { wait : 2000 } ) ;
92
98
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_ ) ;
94
100
95
101
// To prevent the process from hanging due to watch mode (e.g. when running `vitest`)
96
102
const ciEnvOptions = { env : { CI : 'true' } } ;
97
103
98
104
/** @param {typeof options } _options */
99
105
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_ ) ;
103
109
}
104
110
105
111
const tasks = new Listr ( [
106
112
{
107
113
title : 'Prerequisite check' ,
108
114
enabled : ( ) => options . runPublish ,
109
- task : ( ) => prerequisiteTasks ( input , pkg , options , pkgManager ) ,
115
+ task : ( ) => prerequisiteTasks ( input , package_ , options , packageManager ) ,
110
116
} ,
111
117
{
112
118
title : 'Git' ,
@@ -118,13 +124,13 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
118
124
task : ( ) => deleteAsync ( 'node_modules' ) ,
119
125
} ,
120
126
{
121
- title : `Installing dependencies using ${ pkgManager . id } ` ,
127
+ title : `Installing dependencies using ${ packageManager . id } ` ,
122
128
enabled : ( ) => runCleanup ,
123
129
task : ( ) => new Listr ( [
124
130
{
125
131
title : 'Running install command' ,
126
132
task ( ) {
127
- const installCommand = lockfile ? pkgManager . installCommand : pkgManager . installCommandNoLockfile ;
133
+ const installCommand = lockfile ? packageManager . installCommand : packageManager . installCommandNoLockfile ;
128
134
return exec ( ...installCommand ) ;
129
135
} ,
130
136
} ,
@@ -137,29 +143,29 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
137
143
{
138
144
title : 'Running tests' ,
139
145
enabled : ( ) => runTests ,
140
- task : ( ) => exec ( pkgManager . cli , [ 'run' , testScript ] , ciEnvOptions ) ,
146
+ task : ( ) => exec ( packageManager . cli , [ 'run' , testScript ] , ciEnvOptions ) ,
141
147
} ,
142
148
{
143
149
title : 'Bumping version' ,
144
150
skip ( ) {
145
151
if ( options . preview ) {
146
- const [ cli , args ] = pkgManager . versionCommand ( input ) ;
152
+ const [ cli , arguments_ ] = packageManager . versionCommand ( input ) ;
147
153
148
154
if ( options . message ) {
149
- args . push ( '--message' , options . message . replaceAll ( '%s' , input ) ) ;
155
+ arguments_ . push ( '--message' , options . message . replaceAll ( '%s' , input ) ) ;
150
156
}
151
157
152
- return `[Preview] Command not executed: ${ printCommand ( [ cli , args ] ) } ` ;
158
+ return `[Preview] Command not executed: ${ printCommand ( [ cli , arguments_ ] ) } ` ;
153
159
}
154
160
} ,
155
161
task ( ) {
156
- const [ cli , args ] = pkgManager . versionCommand ( input ) ;
162
+ const [ cli , arguments_ ] = packageManager . versionCommand ( input ) ;
157
163
158
164
if ( options . message ) {
159
- args . push ( '--message' , options . message ) ;
165
+ arguments_ . push ( '--message' , options . message ) ;
160
166
}
161
167
162
- return exec ( cli , args ) ;
168
+ return exec ( cli , arguments_ ) ;
163
169
} ,
164
170
} ,
165
171
...options . runPublish ? [
@@ -199,11 +205,11 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
199
205
title : 'Enabling two-factor authentication' ,
200
206
async skip ( ) {
201
207
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 ( ' ' ) } .` ;
204
210
}
205
211
} ,
206
- task : ( context , task ) => enable2fa ( task , pkg . name , { otp : context . otp } ) ,
212
+ task : ( context , task ) => enable2fa ( task , package_ . name , { otp : context . otp } ) ,
207
213
} ] : [ ] ,
208
214
] : [ ] ,
209
215
{
@@ -234,7 +240,7 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
234
240
}
235
241
} ,
236
242
// TODO: parse version outside of index
237
- task : ( ) => releaseTaskHelper ( options , pkg , pkgManager ) ,
243
+ task : ( ) => releaseTaskHelper ( options , package_ , packageManager ) ,
238
244
} ] : [ ] ,
239
245
] , {
240
246
showSubtasks : false ,
@@ -251,8 +257,8 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
251
257
console . error ( `\n${ logSymbols . error } ${ pushedObjects . reason } ` ) ;
252
258
}
253
259
254
- const { pkg : newPkg } = await util . readPkg ( ) ;
255
- return newPkg ;
260
+ const { package_ : newPackage } = await util . readPackage ( ) ;
261
+ return newPackage ;
256
262
} ;
257
263
258
264
export default np ;
0 commit comments