@@ -27,8 +27,7 @@ const spawn = require('./spawn.js')
2727const { isWindows } = require ( './utils.js' )
2828
2929const pickManifest = require ( 'npm-pick-manifest' )
30- const fs = require ( 'fs' )
31- const mkdirp = require ( 'mkdirp' )
30+ const fs = require ( 'fs/promises' )
3231
3332module . exports = ( repo , ref = 'HEAD' , target = null , opts = { } ) =>
3433 getRevs ( repo , opts ) . then ( revs => clone (
@@ -93,7 +92,7 @@ const other = (repo, revDoc, target, opts) => {
9392 . concat ( shallow ? [ '--depth=1' ] : [ ] )
9493
9594 const git = ( args ) => spawn ( args , { ...opts , cwd : target } )
96- return mkdirp ( target )
95+ return fs . mkdir ( target , { recursive : true } )
9796 . then ( ( ) => git ( [ 'init' ] ) )
9897 . then ( ( ) => isWindows ( opts )
9998 ? git ( [ 'config' , '--local' , '--add' , 'core.longpaths' , 'true' ] )
@@ -141,27 +140,29 @@ const plain = (repo, revDoc, target, opts) => {
141140 return spawn ( args , opts ) . then ( ( ) => revDoc . sha )
142141}
143142
144- const updateSubmodules = ( target , opts ) => new Promise ( resolve =>
145- fs . stat ( target + '/.gitmodules' , er => {
146- if ( er ) {
147- return resolve ( null )
148- }
149- return resolve ( spawn ( [
150- 'submodule' ,
151- 'update' ,
152- '-q' ,
153- '--init' ,
154- '--recursive' ,
155- ] , { ...opts , cwd : target } ) )
156- } ) )
143+ const updateSubmodules = async ( target , opts ) => {
144+ const hasSubmodules = await fs . stat ( `${ target } /.gitmodules` )
145+ . then ( ( ) => true )
146+ . catch ( ( ) => false )
147+ if ( ! hasSubmodules ) {
148+ return null
149+ }
150+ return spawn ( [
151+ 'submodule' ,
152+ 'update' ,
153+ '-q' ,
154+ '--init' ,
155+ '--recursive' ,
156+ ] , { ...opts , cwd : target } )
157+ }
157158
158159const unresolved = ( repo , ref , target , opts ) => {
159160 // can't do this one shallowly, because the ref isn't advertised
160161 // but we can avoid checking out the working dir twice, at least
161162 const lp = isWindows ( opts ) ? [ '--config' , 'core.longpaths=true' ] : [ ]
162163 const cloneArgs = [ 'clone' , '--mirror' , '-q' , repo , target + '/.git' ]
163164 const git = ( args ) => spawn ( args , { ...opts , cwd : target } )
164- return mkdirp ( target )
165+ return fs . mkdir ( target , { recursive : true } )
165166 . then ( ( ) => git ( cloneArgs . concat ( lp ) ) )
166167 . then ( ( ) => git ( [ 'init' ] ) )
167168 . then ( ( ) => git ( [ 'checkout' , ref ] ) )
0 commit comments