Skip to content

Commit

Permalink
deps: remove mkdirp and rimraf (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Feb 8, 2023
1 parent cc2b7a7 commit 1095bed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
35 changes: 18 additions & 17 deletions lib/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const spawn = require('./spawn.js')
const { isWindows } = require('./utils.js')

const pickManifest = require('npm-pick-manifest')
const fs = require('fs')
const mkdirp = require('mkdirp')
const fs = require('fs/promises')

module.exports = (repo, ref = 'HEAD', target = null, opts = {}) =>
getRevs(repo, opts).then(revs => clone(
Expand Down Expand Up @@ -93,7 +92,7 @@ const other = (repo, revDoc, target, opts) => {
.concat(shallow ? ['--depth=1'] : [])

const git = (args) => spawn(args, { ...opts, cwd: target })
return mkdirp(target)
return fs.mkdir(target, { recursive: true })
.then(() => git(['init']))
.then(() => isWindows(opts)
? git(['config', '--local', '--add', 'core.longpaths', 'true'])
Expand Down Expand Up @@ -141,27 +140,29 @@ const plain = (repo, revDoc, target, opts) => {
return spawn(args, opts).then(() => revDoc.sha)
}

const updateSubmodules = (target, opts) => new Promise(resolve =>
fs.stat(target + '/.gitmodules', er => {
if (er) {
return resolve(null)
}
return resolve(spawn([
'submodule',
'update',
'-q',
'--init',
'--recursive',
], { ...opts, cwd: target }))
}))
const updateSubmodules = async (target, opts) => {
const hasSubmodules = await fs.stat(`${target}/.gitmodules`)
.then(() => true)
.catch(() => false)
if (!hasSubmodules) {
return null
}
return spawn([
'submodule',
'update',
'-q',
'--init',
'--recursive',
], { ...opts, cwd: target })
}

const unresolved = (repo, ref, target, opts) => {
// can't do this one shallowly, because the ref isn't advertised
// but we can avoid checking out the working dir twice, at least
const lp = isWindows(opts) ? ['--config', 'core.longpaths=true'] : []
const cloneArgs = ['clone', '--mirror', '-q', repo, target + '/.git']
const git = (args) => spawn(args, { ...opts, cwd: target })
return mkdirp(target)
return fs.mkdir(target, { recursive: true })
.then(() => git(cloneArgs.concat(lp)))
.then(() => git(['init']))
.then(() => git(['checkout', ref]))
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.11.3",
"npm-package-arg": "^10.0.0",
"rimraf": "^3.0.2",
"slash": "^3.0.0",
"tap": "^16.0.1"
},
"dependencies": {
"@npmcli/promise-spawn": "^6.0.0",
"lru-cache": "^7.4.4",
"mkdirp": "^1.0.4",
"npm-pick-manifest": "^8.0.0",
"proc-log": "^3.0.0",
"promise-inflight": "^1.0.1",
Expand Down
6 changes: 2 additions & 4 deletions test/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ const revs = require('../lib/revs.js')
const t = require('tap')
const fs = require('fs')
const { spawn } = require('child_process')
const rimraf = require('rimraf')
const { resolve, join } = require('path')
const mkdirp = require('mkdirp')

// keep the fixture, because Windows fails when it tries to delete it,
// due to all the git operations happening inside.
Expand Down Expand Up @@ -99,7 +97,7 @@ t.test('spawn daemon', { bail: true }, t => {
}
daemon.stderr.on('data', onDaemonData)
// only clean up the dir once the daemon is banished
daemon.on('close', () => rimraf.sync(me))
daemon.on('close', () => fs.rmSync(me, { recursive: true, force: true }))
})

t.test('create a repo with a submodule', { bail: true }, t => {
Expand Down Expand Up @@ -205,7 +203,7 @@ t.test('again, with a submodule', async t => {
const safeRef = `${ref}`.replace(/[^a-z0-9.]/g, '-')
const name = `withsub-${fakePlatform}-${gitShallow}-${safeRef}`
const cwd = resolve(me, name)
mkdirp.sync(cwd)
fs.mkdirSync(cwd, { recursive: true })
const target = resolve(cwd, 'submodule-repo')
const spec = ref === undefined ? undefined : npa(remote + (ref ? `#${ref}` : ''))
const opts = { fakePlatform, gitShallow, cwd, spec }
Expand Down

0 comments on commit 1095bed

Please sign in to comment.