Removed fs-extra dependency (#481)

* Removed `fs-extra` dependency

* use `fs/promises` consistently
This commit is contained in:
Mateusz Burzyński
2025-05-15 21:41:09 +02:00
committed by GitHub
parent 9f7e23e7ee
commit 0564b8428f
6 changed files with 23 additions and 28 deletions
+6 -5
View File
@@ -1,9 +1,10 @@
import * as core from "@actions/core";
import fs from "fs-extra";
import fs from "node:fs/promises";
import { Git } from "./git";
import { setupOctokit } from "./octokit";
import readChangesetState from "./readChangesetState";
import { runPublish, runVersion } from "./run";
import { fileExists } from "./utils";
const getOptionalInput = (name: string) => core.getInput(name) || undefined;
@@ -30,7 +31,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
}
const git = new Git({
octokit: commitMode === "github-api" ? octokit : undefined,
cwd
cwd,
});
let setupGitUser = core.getBooleanInput("setupGitUser");
@@ -71,7 +72,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
);
let userNpmrcPath = `${process.env.HOME}/.npmrc`;
if (fs.existsSync(userNpmrcPath)) {
if (await fileExists(userNpmrcPath)) {
core.info("Found existing user .npmrc file");
const userNpmrcContent = await fs.readFile(userNpmrcPath, "utf8");
const authLine = userNpmrcContent.split("\n").find((line) => {
@@ -86,14 +87,14 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
core.info(
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
);
fs.appendFileSync(
await fs.appendFile(
userNpmrcPath,
`\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
);
}
} else {
core.info("No user .npmrc file found, creating one");
fs.writeFileSync(
await fs.writeFile(
userNpmrcPath,
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
);
+7 -7
View File
@@ -1,8 +1,8 @@
import { Changeset } from "@changesets/types";
import writeChangeset from "@changesets/write";
import fixturez from "fixturez";
import fs from "fs-extra";
import path from "path";
import fs from "node:fs/promises";
import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Git } from "./git";
import { setupOctokit } from "./octokit";
@@ -53,7 +53,7 @@ beforeEach(() => {
describe("version", () => {
it("creates simple PR", async () => {
let cwd = f.copy("simple-project");
linkNodeModules(cwd);
await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
@@ -91,7 +91,7 @@ describe("version", () => {
it("only includes bumped packages in the PR body", async () => {
let cwd = f.copy("simple-project");
linkNodeModules(cwd);
await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
@@ -125,7 +125,7 @@ describe("version", () => {
it("doesn't include ignored package that got a dependency update in the PR body", async () => {
let cwd = f.copy("ignored-package");
linkNodeModules(cwd);
await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
@@ -159,7 +159,7 @@ describe("version", () => {
it("does not include changelog entries if full message exceeds size limit", async () => {
let cwd = f.copy("simple-project");
linkNodeModules(cwd);
await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
@@ -217,7 +217,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
it("does not include any release information if a message with simplified release info exceeds size limit", async () => {
let cwd = f.copy("simple-project");
linkNodeModules(cwd);
await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
+2 -2
View File
@@ -3,8 +3,8 @@ import { exec, getExecOutput } from "@actions/exec";
import * as github from "@actions/github";
import { PreState } from "@changesets/types";
import { Package, getPackages } from "@manypkg/get-packages";
import fs from "fs-extra";
import path from "path";
import fs from "node:fs/promises";
import path from "node:path";
import resolveFrom from "resolve-from";
import semverLt from "semver/functions/lt";
import { Git } from "./git";
+8
View File
@@ -1,6 +1,7 @@
import unified from "unified";
import remarkParse from "remark-parse";
import remarkStringify from "remark-stringify";
import fs from "node:fs/promises";
import type { Root } from "mdast";
// @ts-ignore
import mdastToString from "mdast-util-to-string";
@@ -105,3 +106,10 @@ export function isErrorWithCode(err: unknown, code: string) {
err.code === code
);
}
export function fileExists(filePath: string) {
return fs.access(filePath, fs.constants.F_OK).then(
() => true,
() => false
);
}