From 1095bed420065fb2e04577b627b1d8d7622c7fe3 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 8 Feb 2023 09:42:57 -0700 Subject: [PATCH] deps: remove mkdirp and rimraf (#118) --- lib/clone.js | 35 ++++++++++++++++++----------------- package.json | 2 -- test/clone.js | 6 ++---- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/lib/clone.js b/lib/clone.js index 3f165dd..e25a4d1 100644 --- a/lib/clone.js +++ b/lib/clone.js @@ -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( @@ -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']) @@ -141,19 +140,21 @@ 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 @@ -161,7 +162,7 @@ const unresolved = (repo, ref, target, opts) => { 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])) diff --git a/package.json b/package.json index 296f377..d7a52ab 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/clone.js b/test/clone.js index e1cd26b..6d802a9 100644 --- a/test/clone.js +++ b/test/clone.js @@ -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. @@ -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 => { @@ -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 }