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

fix(deps): update to rimraf v4, remove path-exists #3616

Merged
merged 4 commits into from
Mar 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:

# Ignored specs currently failing on windows
# TODO: investigate why
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 &
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 &

pids+=($!)

Expand Down
25 changes: 12 additions & 13 deletions libs/commands/import/src/lib/import-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import execa from "execa";
import fs from "fs-extra";
import path from "path";
import pathExists from "path-exists";

const promptConfirmation = jest.mocked(_promptConfirmation);

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

expect(await lastCommitInDir(testDir)).toBe("Init external commit");
expect(await pathExists(packageJson)).toBe(true);
expect(fs.existsSync(packageJson)).toBe(true);
});

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

expect(await lastCommitInDir(testDir)).toBe("Branch merged");
expect(await pathExists(newFilePath)).toBe(true);
expect(fs.existsSync(newFilePath)).toBe(true);
});

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

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

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

expect(await lastCommitInDir(testDir)).toBe("Moved old-file to new-file");
expect(await pathExists(newFilePath)).toBe(true);
expect(fs.existsSync(newFilePath)).toBe(true);
});

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

expect(await lastCommitInDir(testDir)).toBe("Init external commit");
expect(await pathExists(newFilePath)).toBe(true);
expect(await pathExists(newDeepFilePath)).toBe(true);
expect(fs.existsSync(newFilePath)).toBe(true);
expect(fs.existsSync(newDeepFilePath)).toBe(true);
})
));

Expand Down Expand Up @@ -159,8 +158,8 @@ describe("ImportCommand", () => {
}

expect(await lastCommitInDir(testDir)).toBe("rename");
expect(await pathExists(copyFilePath)).toBe(true);
expect(await pathExists(renameFilePath)).toBe(true);
expect(fs.existsSync(copyFilePath)).toBe(true);
expect(fs.existsSync(renameFilePath)).toBe(true);
})
));

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

expect(await lastCommitInDir(testDir)).toBe("[ISSUE-10] Moved old-file to new-file");
expect(await pathExists(newFilePath)).toBe(true);
expect(fs.existsSync(newFilePath)).toBe(true);
});
});

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

expect(await lastCommitInDir(rootDir)).toBe("Init external commit");
expect(await pathExists(packageJson)).toBe(true);
expect(fs.existsSync(packageJson)).toBe(true);
});
});

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

expect(await lastCommitInDir(testDir)).toBe("Init external commit");
expect(await pathExists(packageJson)).toBe(true);
expect(fs.existsSync(packageJson)).toBe(true);
});

it("throws error when the package directory does not match with config", async () => {
Expand Down
38 changes: 0 additions & 38 deletions libs/core/src/lib/rimraf-dir.spec.ts

This file was deleted.

59 changes: 9 additions & 50 deletions libs/core/src/lib/rimraf-dir.ts
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);
}