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
-2
View File
@@ -7,7 +7,6 @@
"@changesets/changelog-github": "^0.4.2", "@changesets/changelog-github": "^0.4.2",
"@changesets/cli": "^2.20.0", "@changesets/cli": "^2.20.0",
"@changesets/write": "^0.1.6", "@changesets/write": "^0.1.6",
"@types/fs-extra": "^8.0.0",
"@types/node": "^22.15.17", "@types/node": "^22.15.17",
"@types/semver": "^7.5.0", "@types/semver": "^7.5.0",
"esbuild": "^0.25.4", "esbuild": "^0.25.4",
@@ -41,7 +40,6 @@
"@octokit/core": "^5.2.1", "@octokit/core": "^5.2.1",
"@octokit/plugin-throttling": "^8.0.0", "@octokit/plugin-throttling": "^8.0.0",
"@types/mdast": "^3.0.0", "@types/mdast": "^3.0.0",
"fs-extra": "^8.1.0",
"mdast-util-to-string": "^1.0.6", "mdast-util-to-string": "^1.0.6",
"remark-parse": "^7.0.1", "remark-parse": "^7.0.1",
"remark-stringify": "^7.0.3", "remark-stringify": "^7.0.3",
+6 -5
View File
@@ -1,9 +1,10 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import fs from "fs-extra"; import fs from "node:fs/promises";
import { Git } from "./git"; import { Git } from "./git";
import { setupOctokit } from "./octokit"; import { setupOctokit } from "./octokit";
import readChangesetState from "./readChangesetState"; import readChangesetState from "./readChangesetState";
import { runPublish, runVersion } from "./run"; import { runPublish, runVersion } from "./run";
import { fileExists } from "./utils";
const getOptionalInput = (name: string) => core.getInput(name) || undefined; const getOptionalInput = (name: string) => core.getInput(name) || undefined;
@@ -30,7 +31,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
} }
const git = new Git({ const git = new Git({
octokit: commitMode === "github-api" ? octokit : undefined, octokit: commitMode === "github-api" ? octokit : undefined,
cwd cwd,
}); });
let setupGitUser = core.getBooleanInput("setupGitUser"); let setupGitUser = core.getBooleanInput("setupGitUser");
@@ -71,7 +72,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
); );
let userNpmrcPath = `${process.env.HOME}/.npmrc`; let userNpmrcPath = `${process.env.HOME}/.npmrc`;
if (fs.existsSync(userNpmrcPath)) { if (await fileExists(userNpmrcPath)) {
core.info("Found existing user .npmrc file"); core.info("Found existing user .npmrc file");
const userNpmrcContent = await fs.readFile(userNpmrcPath, "utf8"); const userNpmrcContent = await fs.readFile(userNpmrcPath, "utf8");
const authLine = userNpmrcContent.split("\n").find((line) => { const authLine = userNpmrcContent.split("\n").find((line) => {
@@ -86,14 +87,14 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
core.info( core.info(
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one" "Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
); );
fs.appendFileSync( await fs.appendFile(
userNpmrcPath, userNpmrcPath,
`\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n` `\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
); );
} }
} else { } else {
core.info("No user .npmrc file found, creating one"); core.info("No user .npmrc file found, creating one");
fs.writeFileSync( await fs.writeFile(
userNpmrcPath, userNpmrcPath,
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n` `//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
); );
+7 -7
View File
@@ -1,8 +1,8 @@
import { Changeset } from "@changesets/types"; import { Changeset } from "@changesets/types";
import writeChangeset from "@changesets/write"; import writeChangeset from "@changesets/write";
import fixturez from "fixturez"; import fixturez from "fixturez";
import fs from "fs-extra"; import fs from "node:fs/promises";
import path from "path"; import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest"; import { beforeEach, describe, expect, it, vi } from "vitest";
import { Git } from "./git"; import { Git } from "./git";
import { setupOctokit } from "./octokit"; import { setupOctokit } from "./octokit";
@@ -53,7 +53,7 @@ beforeEach(() => {
describe("version", () => { describe("version", () => {
it("creates simple PR", async () => { it("creates simple PR", async () => {
let cwd = f.copy("simple-project"); let cwd = f.copy("simple-project");
linkNodeModules(cwd); await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
@@ -91,7 +91,7 @@ describe("version", () => {
it("only includes bumped packages in the PR body", async () => { it("only includes bumped packages in the PR body", async () => {
let cwd = f.copy("simple-project"); let cwd = f.copy("simple-project");
linkNodeModules(cwd); await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); 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 () => { it("doesn't include ignored package that got a dependency update in the PR body", async () => {
let cwd = f.copy("ignored-package"); let cwd = f.copy("ignored-package");
linkNodeModules(cwd); await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
@@ -159,7 +159,7 @@ describe("version", () => {
it("does not include changelog entries if full message exceeds size limit", async () => { it("does not include changelog entries if full message exceeds size limit", async () => {
let cwd = f.copy("simple-project"); let cwd = f.copy("simple-project");
linkNodeModules(cwd); await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); 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 () => { it("does not include any release information if a message with simplified release info exceeds size limit", async () => {
let cwd = f.copy("simple-project"); let cwd = f.copy("simple-project");
linkNodeModules(cwd); await linkNodeModules(cwd);
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); 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 * as github from "@actions/github";
import { PreState } from "@changesets/types"; import { PreState } from "@changesets/types";
import { Package, getPackages } from "@manypkg/get-packages"; import { Package, getPackages } from "@manypkg/get-packages";
import fs from "fs-extra"; import fs from "node:fs/promises";
import path from "path"; import path from "node:path";
import resolveFrom from "resolve-from"; import resolveFrom from "resolve-from";
import semverLt from "semver/functions/lt"; import semverLt from "semver/functions/lt";
import { Git } from "./git"; import { Git } from "./git";
+8
View File
@@ -1,6 +1,7 @@
import unified from "unified"; import unified from "unified";
import remarkParse from "remark-parse"; import remarkParse from "remark-parse";
import remarkStringify from "remark-stringify"; import remarkStringify from "remark-stringify";
import fs from "node:fs/promises";
import type { Root } from "mdast"; import type { Root } from "mdast";
// @ts-ignore // @ts-ignore
import mdastToString from "mdast-util-to-string"; import mdastToString from "mdast-util-to-string";
@@ -105,3 +106,10 @@ export function isErrorWithCode(err: unknown, code: string) {
err.code === code err.code === code
); );
} }
export function fileExists(filePath: string) {
return fs.access(filePath, fs.constants.F_OK).then(
() => true,
() => false
);
}
-12
View File
@@ -694,13 +694,6 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.7.tgz#4158d3105276773d5b7695cd4834b1722e4f37a8" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.7.tgz#4158d3105276773d5b7695cd4834b1722e4f37a8"
integrity sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ== integrity sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==
"@types/fs-extra@^8.0.0":
version "8.1.2"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.2.tgz#7125cc2e4bdd9bd2fc83005ffdb1d0ba00cca61f"
integrity sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==
dependencies:
"@types/node" "*"
"@types/is-ci@^3.0.0": "@types/is-ci@^3.0.0":
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/is-ci/-/is-ci-3.0.0.tgz#7e8910af6857601315592436f030aaa3ed9783c3" resolved "https://registry.yarnpkg.com/@types/is-ci/-/is-ci-3.0.0.tgz#7e8910af6857601315592436f030aaa3ed9783c3"
@@ -720,11 +713,6 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c" resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ== integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==
"@types/node@*":
version "20.2.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.2.1.tgz#de559d4b33be9a808fd43372ccee822c70f39704"
integrity sha512-DqJociPbZP1lbZ5SQPk4oag6W7AyaGMO6gSfRwq3PWl4PXTwJpRQJhDq4W0kzrg3w6tJ1SwlvGZ5uKFHY13LIg==
"@types/node@^12.7.1": "@types/node@^12.7.1":
version "12.20.55" version "12.20.55"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"