Skip to content

Commit 2f2ee2a

Browse files
authoredMar 24, 2023
fix(deps): update to rimraf v4, remove path-exists (#3616)
1 parent 1625757 commit 2f2ee2a

File tree

8 files changed

+250
-116
lines changed

8 files changed

+250
-116
lines changed
 

‎.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
118118
# Ignored specs currently failing on windows
119119
# TODO: investigate why
120-
npx nx run-many -t test --parallel=3 --ci --maxWorkers=2 --testTimeout=45000 --testPathIgnorePatterns=create-symlink.spec.ts --testPathIgnorePatterns=get-two-factor-auth-required.spec.ts --testPathIgnorePatterns=version-lifecycle-scripts.spec.ts --testPathIgnorePatterns=version-allow-branch.spec.ts --testPathIgnorePatterns=version-message.spec.ts --testPathIgnorePatterns=version-conventional-commits.spec.ts --testPathIgnorePatterns=version-bump-prerelease.spec.ts --testPathIgnorePatterns=version-bump.spec.ts --testPathIgnorePatterns=version-git-hosted-siblings.spec.ts --testPathIgnorePatterns=version-command.spec.ts --testPathIgnorePatterns=bootstrap-command.spec.ts --testPathIgnorePatterns=import-command.spec.ts --testPathIgnorePatterns=publish-command.spec.ts --testPathIgnorePatterns=publish-licenses.spec.ts --testPathIgnorePatterns=publish-lifecycle-scripts.spec.ts --testPathIgnorePatterns=publish-tagging.spec.ts --testPathIgnorePatterns=publish-relative-file-specifiers.spec.ts &
120+
npx nx run-many -t test --parallel=3 --ci --maxWorkers=2 --testTimeout=60000 --testPathIgnorePatterns=create-symlink.spec.ts --testPathIgnorePatterns=get-two-factor-auth-required.spec.ts --testPathIgnorePatterns=version-lifecycle-scripts.spec.ts --testPathIgnorePatterns=version-allow-branch.spec.ts --testPathIgnorePatterns=version-message.spec.ts --testPathIgnorePatterns=version-conventional-commits.spec.ts --testPathIgnorePatterns=version-bump-prerelease.spec.ts --testPathIgnorePatterns=version-bump.spec.ts --testPathIgnorePatterns=version-git-hosted-siblings.spec.ts --testPathIgnorePatterns=version-command.spec.ts --testPathIgnorePatterns=bootstrap-command.spec.ts --testPathIgnorePatterns=import-command.spec.ts --testPathIgnorePatterns=publish-command.spec.ts --testPathIgnorePatterns=publish-licenses.spec.ts --testPathIgnorePatterns=publish-lifecycle-scripts.spec.ts --testPathIgnorePatterns=publish-tagging.spec.ts --testPathIgnorePatterns=publish-relative-file-specifiers.spec.ts &
121121
122122
pids+=($!)
123123

‎libs/commands/import/src/lib/import-command.spec.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import execa from "execa";
1111
import fs from "fs-extra";
1212
import path from "path";
13-
import pathExists from "path-exists";
1413

1514
const promptConfirmation = jest.mocked(_promptConfirmation);
1615

@@ -45,7 +44,7 @@ describe("ImportCommand", () => {
4544
await lernaImport(testDir)(externalDir);
4645

4746
expect(await lastCommitInDir(testDir)).toBe("Init external commit");
48-
expect(await pathExists(packageJson)).toBe(true);
47+
expect(fs.existsSync(packageJson)).toBe(true);
4948
});
5049

5150
it("imports a repo with conflicted merge commits when run with --flatten", async () => {
@@ -84,7 +83,7 @@ describe("ImportCommand", () => {
8483
await lernaImport(testDir)(externalDir, "--flatten");
8584

8685
expect(await lastCommitInDir(testDir)).toBe("Branch merged");
87-
expect(await pathExists(newFilePath)).toBe(true);
86+
expect(fs.existsSync(newFilePath)).toBe(true);
8887
});
8988

9089
it("imports a repo into the root directory when packages are located there", async () => {
@@ -94,8 +93,8 @@ describe("ImportCommand", () => {
9493
await lernaImport(testDir)(externalDir);
9594

9695
expect(await lastCommitInDir(testDir)).toBe("myapp-foo init commit");
97-
expect(await pathExists(path.join(testDir, "myapp-foo/old-file"))).toBe(true);
98-
expect(await pathExists(path.join(testDir, "myapp-foo/package.json"))).toBe(true);
96+
expect(fs.existsSync(path.join(testDir, "myapp-foo/old-file"))).toBe(true);
97+
expect(fs.existsSync(path.join(testDir, "myapp-foo/package.json"))).toBe(true);
9998
});
10099

101100
it("supports moved files within the external repo", async () => {
@@ -108,7 +107,7 @@ describe("ImportCommand", () => {
108107
await lernaImport(testDir)(externalDir);
109108

110109
expect(await lastCommitInDir(testDir)).toBe("Moved old-file to new-file");
111-
expect(await pathExists(newFilePath)).toBe(true);
110+
expect(fs.existsSync(newFilePath)).toBe(true);
112111
});
113112

114113
it("supports filepaths that have spaces within the external repo", async () =>
@@ -128,8 +127,8 @@ describe("ImportCommand", () => {
128127
}
129128

130129
expect(await lastCommitInDir(testDir)).toBe("Init external commit");
131-
expect(await pathExists(newFilePath)).toBe(true);
132-
expect(await pathExists(newDeepFilePath)).toBe(true);
130+
expect(fs.existsSync(newFilePath)).toBe(true);
131+
expect(fs.existsSync(newDeepFilePath)).toBe(true);
133132
})
134133
));
135134

@@ -159,8 +158,8 @@ describe("ImportCommand", () => {
159158
}
160159

161160
expect(await lastCommitInDir(testDir)).toBe("rename");
162-
expect(await pathExists(copyFilePath)).toBe(true);
163-
expect(await pathExists(renameFilePath)).toBe(true);
161+
expect(fs.existsSync(copyFilePath)).toBe(true);
162+
expect(fs.existsSync(renameFilePath)).toBe(true);
164163
})
165164
));
166165

@@ -315,7 +314,7 @@ describe("ImportCommand", () => {
315314
await lernaImport(testDir)(externalDir);
316315

317316
expect(await lastCommitInDir(testDir)).toBe("[ISSUE-10] Moved old-file to new-file");
318-
expect(await pathExists(newFilePath)).toBe(true);
317+
expect(fs.existsSync(newFilePath)).toBe(true);
319318
});
320319
});
321320

@@ -330,7 +329,7 @@ describe("ImportCommand", () => {
330329
await lernaImport(testDir)(externalDir);
331330

332331
expect(await lastCommitInDir(rootDir)).toBe("Init external commit");
333-
expect(await pathExists(packageJson)).toBe(true);
332+
expect(fs.existsSync(packageJson)).toBe(true);
334333
});
335334
});
336335

@@ -344,7 +343,7 @@ describe("ImportCommand", () => {
344343
await lernaImport(testDir)(externalDir, "--dest=packages");
345344

346345
expect(await lastCommitInDir(testDir)).toBe("Init external commit");
347-
expect(await pathExists(packageJson)).toBe(true);
346+
expect(fs.existsSync(packageJson)).toBe(true);
348347
});
349348

350349
it("throws error when the package directory does not match with config", async () => {

‎libs/core/src/lib/rimraf-dir.spec.ts

-38
This file was deleted.

‎libs/core/src/lib/rimraf-dir.ts

+9-50
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,18 @@
1-
"use strict";
2-
1+
import { existsSync } from "fs";
32
import log from "npmlog";
4-
import path from "node:path";
5-
import fs from "node:fs";
6-
import pathExists from "path-exists";
7-
8-
// eslint-disable-next-line @typescript-eslint/no-var-requires
9-
const childProcess = require("@lerna/child-process");
10-
11-
let rimrafBinPath: string | undefined;
12-
13-
async function useRimrafBinPath(): Promise<string> {
14-
if (typeof rimrafBinPath === "string") {
15-
return rimrafBinPath;
16-
}
17-
18-
const filePath = require.resolve("rimraf");
19-
const directoryPath = path.basename(filePath);
20-
21-
try {
22-
const rawFile = await fs.promises.readFile(path.join(directoryPath, "package.json"), {
23-
encoding: "utf-8",
24-
});
25-
const file = JSON.parse(rawFile);
26-
27-
rimrafBinPath = file.bin || require.resolve("rimraf/bin");
28-
} catch (e) {
29-
rimrafBinPath = require.resolve("rimraf/bin");
30-
}
31-
32-
return rimrafBinPath as string;
33-
}
3+
import rimraf from "rimraf";
344

355
export async function rimrafDir(dirPath: string) {
366
log.silly("rimrafDir", dirPath);
37-
// Shelling out to a child process for a noop is expensive.
38-
// Checking if `dirPath` exists to be removed is cheap.
39-
// This lets us short-circuit if we don't have anything to do.
407

41-
const fileExists = await pathExists(dirPath);
42-
if (!fileExists) {
8+
// Short-circuit if we don't have anything to do.
9+
if (!existsSync(dirPath)) {
4310
return;
4411
}
4512

46-
const cliPath = await useRimrafBinPath();
47-
48-
// globs only return directories with a trailing slash
49-
const slashed = path.normalize(`${dirPath}/`);
50-
const args = [cliPath, "--no-glob", slashed];
51-
52-
// We call this resolved CLI path in the "path/to/node path/to/cli <..args>"
53-
// pattern to avoid Windows hangups with shebangs (e.g., WSH can't handle it)
54-
return childProcess.spawn(process.execPath, args).then(() => {
55-
log.verbose("rimrafDir", "removed", dirPath);
56-
57-
return dirPath;
58-
});
13+
const isSuccessful = await rimraf(dirPath);
14+
if (!isSuccessful) {
15+
throw new Error(`Failed to fully remove ${dirPath}`);
16+
}
17+
log.verbose("rimrafDir", "removed", dirPath);
5918
}

‎package-lock.json

+226-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,11 @@
8888
"p-reduce": "^2.1.0",
8989
"p-waterfall": "^2.1.1",
9090
"pacote": "^13.6.2",
91-
"path-exists": "^4.0.0",
9291
"pify": "^5.0.0",
9392
"read-cmd-shim": "^3.0.0",
9493
"read-package-json": "^5.0.1",
9594
"resolve-from": "^5.0.0",
96-
"rimraf": "^3.0.2",
95+
"rimraf": "^4.4.1",
9796
"semver": "^7.3.8",
9897
"signal-exit": "^3.0.3",
9998
"slash": "^3.0.0",

‎packages/legacy-package-management/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"p-queue": "6.6.2",
7171
"p-waterfall": "2.1.1",
7272
"pacote": "13.6.2",
73-
"path-exists": "4.0.0",
7473
"pify": "5.0.0",
7574
"pretty-format": "29.4.3",
7675
"read-cmd-shim": "3.0.0",

‎packages/lerna/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@
9292
"p-reduce": "2.1.0",
9393
"p-waterfall": "2.1.1",
9494
"pacote": "13.6.2",
95-
"path-exists": "4.0.0",
9695
"pify": "5.0.0",
9796
"read-cmd-shim": "3.0.0",
9897
"read-package-json": "5.0.1",
9998
"resolve-from": "5.0.0",
100-
"rimraf": "^3.0.2",
99+
"rimraf": "^4.4.1",
101100
"semver": "^7.3.8",
102101
"signal-exit": "3.0.7",
103102
"slash": "3.0.0",

0 commit comments

Comments
 (0)
Please sign in to comment.