@@ -20,6 +20,14 @@ const WINDOWS = process.platform === 'win32'
2020const GLOBAL_BIN = WINDOWS ? '' : 'bin'
2121const GLOBAL_NODE_MODULES = join ( WINDOWS ? '' : 'lib' , 'node_modules' )
2222
23+ const getOpts = ( ...a ) => {
24+ const [ opts , args ] = a . reduce ( ( acc , arg ) => {
25+ acc [ typeof arg === 'object' ? 0 : 1 ] . push ( arg )
26+ return acc
27+ } , [ [ ] , [ ] ] )
28+ return [ Object . assign ( { } , ...opts ) , args ]
29+ }
30+
2331const normalizePath = path => path . replace ( / [ A - Z ] : / , '' ) . replace ( / \\ / g, '/' )
2432
2533const testdirHelper = ( obj ) => {
@@ -169,14 +177,10 @@ module.exports = async (t, { testdir = {}, debug, registry: _registry = {} } = {
169177 return stdout
170178 }
171179
172- const baseNpm = async ( baseOpts , ...args ) => {
173- const hasMoreOpts = args [ args . length - 1 ] && typeof args [ args . length - 1 ] === 'object'
174- const { cwd, cmd, argv = [ ] , proxy = true , ...opts } = {
175- ...baseOpts ,
176- ...hasMoreOpts ? args . pop ( ) : { } ,
177- }
180+ const baseNpm = async ( ...a ) => {
181+ const [ { cwd, cmd, argv = [ ] , proxy = true , ...opts } , args ] = getOpts ( ...a )
178182
179- const isGlobal = args . some ( a => [ '-g' , '--global' , '--global=true' ] . includes ( a ) )
183+ const isGlobal = args . some ( arg => [ '-g' , '--global' , '--global=true' ] . includes ( arg ) )
180184
181185 const defaultFlags = [
182186 proxy ? `--registry=${ HTTP_PROXY } ` : null ,
@@ -206,29 +210,31 @@ module.exports = async (t, { testdir = {}, debug, registry: _registry = {} } = {
206210 } )
207211 }
208212
209- const npmLocal = ( ...args ) => baseNpm ( {
210- cwd : CLI_ROOT ,
211- cmd : process . execPath ,
212- argv : [ '.' ] ,
213- proxy : false ,
214- } , ...args )
213+ const npmLocal = async ( ...args ) => {
214+ const [ { force = false } ] = getOpts ( ...args )
215+ if ( SMOKE_PUBLISH_NPM && ! force ) {
216+ throw new Error ( 'npmLocal cannot be called during smoke-publish' )
217+ }
218+ return baseNpm ( {
219+ cwd : CLI_ROOT ,
220+ cmd : process . execPath ,
221+ argv : [ '.' ] ,
222+ proxy : false ,
223+ } , ...args )
224+ }
215225
216- const npmPath = ( ...args ) => baseNpm ( {
226+ const npmPath = async ( ...args ) => baseNpm ( {
217227 cwd : paths . project ,
218228 cmd : 'npm' ,
219229 shell : true ,
220230 } , ...args )
221231
222- const npm = ( ...args ) => baseNpm ( {
232+ const npm = async ( ...args ) => baseNpm ( {
223233 cwd : paths . project ,
224234 cmd : process . execPath ,
225235 argv : [ NPM_PATH ] ,
226236 } , ...args )
227237
228- const npmLocalError = async ( ) => {
229- throw new Error ( 'npmLocal cannot be called during smoke-publish' )
230- }
231-
232238 // helpers for reading/writing files and their source
233239 const readFile = async ( f ) => {
234240 const file = await fs . readFile ( join ( paths . project , f ) , 'utf-8' )
@@ -237,22 +243,15 @@ module.exports = async (t, { testdir = {}, debug, registry: _registry = {} } = {
237243
238244 return {
239245 npmPath,
240- npmLocal : SMOKE_PUBLISH_NPM ? npmLocalError : npmLocal ,
246+ npmLocal,
241247 npm : SMOKE_PUBLISH_NPM ? npmPath : npm ,
242248 spawn : baseSpawn ,
243249 readFile,
244250 getPath,
245251 paths,
246252 registry,
247- npmLocalTarball : async ( ) => {
248- if ( SMOKE_PUBLISH_TARBALL ) {
249- return SMOKE_PUBLISH_TARBALL
250- }
251- if ( SMOKE_PUBLISH_NPM ) {
252- return await npmLocalError ( )
253- }
254- return await npmLocal ( 'pack' , `--pack-destination=${ root } ` ) . then ( r => join ( root , r ) )
255- } ,
253+ npmLocalTarball : async ( ) => SMOKE_PUBLISH_TARBALL ??
254+ npmLocal ( 'pack' , `--pack-destination=${ root } ` ) . then ( r => join ( root , r ) ) ,
256255 }
257256}
258257
0 commit comments