Skip to content

Commit

Permalink
Replace rimraf with built-in fs.rm (#1372)
Browse files Browse the repository at this point in the history
Replace rimraf with built-in fs.rm
  • Loading branch information
Torathion authored Mar 8, 2024
1 parent 80a9af3 commit 48bd306
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 53 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"prompts-ncu": "^3.0.0",
"rc-config-loader": "^4.1.3",
"remote-git-tags": "^3.0.0",
"rimraf": "^5.0.5",
"semver": "^7.5.4",
"semver-utils": "^1.1.4",
"source-map-support": "^0.5.21",
Expand Down Expand Up @@ -114,7 +113,6 @@
"@types/progress": "^2.0.6",
"@types/prompts": "^2.4.7",
"@types/remote-git-tags": "^4.0.1",
"@types/rimraf": "^3.0.2",
"@types/semver": "^7.5.4",
"@types/semver-utils": "^1.1.2",
"@types/sinon": "^17.0.0",
Expand Down
19 changes: 9 additions & 10 deletions src/lib/doctor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'fs/promises'
import { rimraf } from 'rimraf'
import spawn from 'spawn-please'
import { printUpgrades } from '../lib/logging'
import spawnBun from '../package-managers/bun'
Expand Down Expand Up @@ -50,10 +49,10 @@ const npm = (
options.packageManager === 'pnpm'
? spawnPnpm
: options.packageManager === 'yarn'
? spawnYarn
: options.packageManager === 'bun'
? spawnBun
: spawnNpm
? spawnYarn
: options.packageManager === 'bun'
? spawnBun
: spawnNpm
)(args, npmOptions, spawnOptionsMerged as any)
}

Expand Down Expand Up @@ -95,10 +94,10 @@ const doctor = async (run: Run, options: Options): Promise<void> => {
options.packageManager === 'yarn'
? 'yarn.lock'
: options.packageManager === 'pnpm'
? 'pnpm-lock.yaml'
: options.packageManager === 'bun'
? 'bun.lockb'
: 'package-lock.json'
? 'pnpm-lock.yaml'
: options.packageManager === 'bun'
? 'bun.lockb'
: 'package-lock.json'
const { pkg, pkgFile }: PackageInfo = await loadPackageFileForDoctor(options)

// flatten all deps into one so we can iterate over them
Expand Down Expand Up @@ -233,7 +232,7 @@ const doctor = async (run: Run, options: Options): Promise<void> => {
if (lockFile) {
await fs.writeFile(lockFileName, lockFile)
} else {
await rimraf(lockFileName)
await fs.rm(lockFileName, { recursive: true, force: true })
}

// save the last package file with passing tests
Expand Down
17 changes: 8 additions & 9 deletions test/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect } from 'chai'
import fs from 'fs/promises'
import { rimraf } from 'rimraf'
import ncu from '../src/'
import { CACHE_DELIMITER, resolvedDefaultCacheFile } from '../src/lib/cache'
import { CacheData } from '../src/types/Cacher'
Expand Down Expand Up @@ -36,7 +35,7 @@ describe('cache', () => {
[`ncu-test-alpha${CACHE_DELIMITER}latest`]: '1.0.0',
})
} finally {
await rimraf(resolvedDefaultCacheFile)
await fs.rm(resolvedDefaultCacheFile, { recursive: true, force: true })
stub.restore()
}
})
Expand All @@ -50,12 +49,12 @@ describe('cache', () => {
'ncu-test-alpha': '1.0.0',
}
: options.target === 'greatest'
? {
'ncu-test-v2': '2.0.0',
'ncu-test-tag': '1.2.0-dev.0',
'ncu-test-alpha': '2.0.0-alpha.2',
}
: null,
? {
'ncu-test-v2': '2.0.0',
'ncu-test-tag': '1.2.0-dev.0',
'ncu-test-alpha': '2.0.0-alpha.2',
}
: null,
)
try {
const packageData = {
Expand Down Expand Up @@ -96,7 +95,7 @@ describe('cache', () => {
[`ncu-test-alpha${CACHE_DELIMITER}greatest`]: '2.0.0-alpha.2',
})
} finally {
await rimraf(resolvedDefaultCacheFile)
await fs.rm(resolvedDefaultCacheFile, { recursive: true, force: true })
stub.restore()
}
})
Expand Down
49 changes: 24 additions & 25 deletions test/doctor.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import { rimraf } from 'rimraf'
import spawn from 'spawn-please'
import { cliOptionsMap } from '../src/cli-options'
import { chalkInit } from '../src/lib/chalk'
Expand Down Expand Up @@ -37,10 +36,10 @@ const testPass = ({ packageManager }: { packageManager: PackageManagerName }) =>
packageManager === 'yarn'
? 'yarn.lock'
: packageManager === 'pnpm'
? 'pnpm-lock.yaml'
: packageManager === 'bun'
? 'bun.lockb'
: 'package-lock.json',
? 'pnpm-lock.yaml'
: packageManager === 'bun'
? 'bun.lockb'
: 'package-lock.json',
)
const pkgOriginal = await fs.readFile(path.join(cwd, 'package.json'), 'utf-8')
let stdout = ''
Expand Down Expand Up @@ -69,13 +68,13 @@ const testPass = ({ packageManager }: { packageManager: PackageManagerName }) =>

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
rimraf.sync(nodeModulesPath)
rimraf.sync(lockfilePath)
await fs.rm(nodeModulesPath, { recursive: true, force: true })
await fs.rm(lockfilePath, { recursive: true, force: true })

// delete yarn cache
if (packageManager === 'yarn') {
rimraf.sync(path.join(cwd, '.yarn'))
rimraf.sync(path.join(cwd, '.pnp.js'))
await fs.rm(path.join(cwd, '.yarn'), { recursive: true, force: true })
await fs.rm(path.join(cwd, '.pnp.js'), { recursive: true, force: true })
}

// bun prints the run header to stderr instead of stdout
Expand Down Expand Up @@ -105,10 +104,10 @@ const testFail = ({ packageManager }: { packageManager: PackageManagerName }) =>
packageManager === 'yarn'
? 'yarn.lock'
: packageManager === 'pnpm'
? 'pnpm-lock.yaml'
: packageManager === 'bun'
? 'bun.lockb'
: 'package-lock.json',
? 'pnpm-lock.yaml'
: packageManager === 'bun'
? 'bun.lockb'
: 'package-lock.json',
)
const pkgOriginal = await fs.readFile(path.join(cwd, 'package.json'), 'utf-8')
let stdout = ''
Expand All @@ -134,13 +133,13 @@ const testFail = ({ packageManager }: { packageManager: PackageManagerName }) =>
} finally {
pkgUpgraded = await fs.readFile(pkgPath, 'utf-8')
await fs.writeFile(pkgPath, pkgOriginal)
rimraf.sync(nodeModulesPath)
rimraf.sync(lockfilePath)
await fs.rm(nodeModulesPath, { recursive: true, force: true })
await fs.rm(lockfilePath, { recursive: true, force: true })

// delete yarn cache
if (packageManager === 'yarn') {
rimraf.sync(path.join(cwd, '.yarn'))
rimraf.sync(path.join(cwd, '.pnp.js'))
await fs.rm(path.join(cwd, '.yarn'), { recursive: true, force: true })
await fs.rm(path.join(cwd, '.pnp.js'), { recursive: true, force: true })
}
}

Expand Down Expand Up @@ -235,8 +234,8 @@ describe('doctor', function () {

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
rimraf.sync(lockfilePath)
rimraf.sync(nodeModulesPath)
await fs.rm(lockfilePath, { recursive: true, force: true })
await fs.rm(nodeModulesPath, { recursive: true, force: true })

// stderr should be empty
stderr.should.equal('')
Expand Down Expand Up @@ -277,8 +276,8 @@ describe('doctor', function () {

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
rimraf.sync(lockfilePath)
rimraf.sync(nodeModulesPath)
await fs.rm(lockfilePath, { recursive: true, force: true })
await fs.rm(nodeModulesPath, { recursive: true, force: true })

// stderr should be empty
stderr.should.equal('')
Expand Down Expand Up @@ -318,8 +317,8 @@ describe('doctor', function () {

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
rimraf.sync(lockfilePath)
rimraf.sync(nodeModulesPath)
await fs.rm(lockfilePath, { recursive: true, force: true })
await fs.rm(nodeModulesPath, { recursive: true, force: true })

// stderr should be empty
stderr.should.equal('')
Expand Down Expand Up @@ -359,8 +358,8 @@ describe('doctor', function () {

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
rimraf.sync(lockfilePath)
rimraf.sync(nodeModulesPath)
await fs.rm(lockfilePath, { recursive: true, force: true })
await fs.rm(nodeModulesPath, { recursive: true, force: true })

// stderr should be empty
stderr.should.equal('')
Expand Down
14 changes: 7 additions & 7 deletions test/peer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs/promises'
import path from 'path'
import { rimraf } from 'rimraf'
import ncu from '../src/'
import spawnNpm from '../src/package-managers/npm'
import chaiSetup from './helpers/chaiSetup'
Expand All @@ -16,8 +16,8 @@ describe('peer dependencies', function () {
'ncu-test-return-version': '2.0.0',
})
} finally {
rimraf.sync(path.join(cwd, 'node_modules'))
rimraf.sync(path.join(cwd, 'package-lock.json'))
await fs.rm(path.join(cwd, 'node_modules'), { recursive: true, force: true })
await fs.rm(path.join(cwd, 'package-lock.json'), { recursive: true, force: true })
}
})

Expand All @@ -30,8 +30,8 @@ describe('peer dependencies', function () {
'ncu-test-return-version': '1.1.0',
})
} finally {
rimraf.sync(path.join(cwd, 'node_modules'))
rimraf.sync(path.join(cwd, 'package-lock.json'))
await fs.rm(path.join(cwd, 'node_modules'), { recursive: true, force: true })
await fs.rm(path.join(cwd, 'package-lock.json'), { recursive: true, force: true })
}
})

Expand All @@ -45,8 +45,8 @@ describe('peer dependencies', function () {
'ncu-test-peer-update': '1.1.0',
})
} finally {
rimraf.sync(path.join(cwd, 'node_modules'))
rimraf.sync(path.join(cwd, 'package-lock.json'))
await fs.rm(path.join(cwd, 'node_modules'), { recursive: true, force: true })
await fs.rm(path.join(cwd, 'package-lock.json'), { recursive: true, force: true })
}
})
})

0 comments on commit 48bd306

Please sign in to comment.