Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: remove mkdirp and rimraf #118

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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