-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deps): update to rimraf v4, remove path-exists (#3616)
- Loading branch information
1 parent
1625757
commit 2f2ee2a
Showing
8 changed files
with
250 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,18 @@ | ||
"use strict"; | ||
|
||
import { existsSync } from "fs"; | ||
import log from "npmlog"; | ||
import path from "node:path"; | ||
import fs from "node:fs"; | ||
import pathExists from "path-exists"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const childProcess = require("@lerna/child-process"); | ||
|
||
let rimrafBinPath: string | undefined; | ||
|
||
async function useRimrafBinPath(): Promise<string> { | ||
if (typeof rimrafBinPath === "string") { | ||
return rimrafBinPath; | ||
} | ||
|
||
const filePath = require.resolve("rimraf"); | ||
const directoryPath = path.basename(filePath); | ||
|
||
try { | ||
const rawFile = await fs.promises.readFile(path.join(directoryPath, "package.json"), { | ||
encoding: "utf-8", | ||
}); | ||
const file = JSON.parse(rawFile); | ||
|
||
rimrafBinPath = file.bin || require.resolve("rimraf/bin"); | ||
} catch (e) { | ||
rimrafBinPath = require.resolve("rimraf/bin"); | ||
} | ||
|
||
return rimrafBinPath as string; | ||
} | ||
import rimraf from "rimraf"; | ||
|
||
export async function rimrafDir(dirPath: string) { | ||
log.silly("rimrafDir", dirPath); | ||
// Shelling out to a child process for a noop is expensive. | ||
// Checking if `dirPath` exists to be removed is cheap. | ||
// This lets us short-circuit if we don't have anything to do. | ||
|
||
const fileExists = await pathExists(dirPath); | ||
if (!fileExists) { | ||
// Short-circuit if we don't have anything to do. | ||
if (!existsSync(dirPath)) { | ||
return; | ||
} | ||
|
||
const cliPath = await useRimrafBinPath(); | ||
|
||
// globs only return directories with a trailing slash | ||
const slashed = path.normalize(`${dirPath}/`); | ||
const args = [cliPath, "--no-glob", slashed]; | ||
|
||
// We call this resolved CLI path in the "path/to/node path/to/cli <..args>" | ||
// pattern to avoid Windows hangups with shebangs (e.g., WSH can't handle it) | ||
return childProcess.spawn(process.execPath, args).then(() => { | ||
log.verbose("rimrafDir", "removed", dirPath); | ||
|
||
return dirPath; | ||
}); | ||
const isSuccessful = await rimraf(dirPath); | ||
if (!isSuccessful) { | ||
throw new Error(`Failed to fully remove ${dirPath}`); | ||
} | ||
log.verbose("rimrafDir", "removed", dirPath); | ||
} |
Oops, something went wrong.