11import { execa } from 'execa' ;
22import { deleteAsync } from 'del' ;
33import 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' ;
511import hostedGitInfo from 'hosted-git-info' ;
612import onetime from 'onetime' ;
713import { asyncExitHook } from 'exit-hook' ;
814import logSymbols from 'log-symbols' ;
915import prerequisiteTasks from './prerequisite-tasks.js' ;
1016import gitTasks from './git-tasks.js' ;
1117import { getPackagePublishArguments } from './npm/publish.js' ;
12- import enable2fa , { getEnable2faArgs } from './npm/enable-2fa.js' ;
18+ import enable2fa , { getEnable2faArguments } from './npm/enable-2fa.js' ;
1319import handleNpmError from './npm/handle-npm-error.js' ;
1420import releaseTaskHelper from './release-task-helper.js' ;
1521import { findLockfile , getPackageManagerConfig , printCommand } from './package-manager/index.js' ;
@@ -18,20 +24,20 @@ import * as git from './git-util.js';
1824import * 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
258264export default np ;
0 commit comments