Skip to content

Commit 0564b84

Browse files
authored
Removed fs-extra dependency (#481)
* Removed `fs-extra` dependency * use `fs/promises` consistently
1 parent 9f7e23e commit 0564b84

File tree

6 files changed

+23
-28
lines changed

6 files changed

+23
-28
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"@changesets/changelog-github": "^0.4.2",
88
"@changesets/cli": "^2.20.0",
99
"@changesets/write": "^0.1.6",
10-
"@types/fs-extra": "^8.0.0",
1110
"@types/node": "^22.15.17",
1211
"@types/semver": "^7.5.0",
1312
"esbuild": "^0.25.4",
@@ -41,7 +40,6 @@
4140
"@octokit/core": "^5.2.1",
4241
"@octokit/plugin-throttling": "^8.0.0",
4342
"@types/mdast": "^3.0.0",
44-
"fs-extra": "^8.1.0",
4543
"mdast-util-to-string": "^1.0.6",
4644
"remark-parse": "^7.0.1",
4745
"remark-stringify": "^7.0.3",

src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as core from "@actions/core";
2-
import fs from "fs-extra";
2+
import fs from "node:fs/promises";
33
import { Git } from "./git";
44
import { setupOctokit } from "./octokit";
55
import readChangesetState from "./readChangesetState";
66
import { runPublish, runVersion } from "./run";
7+
import { fileExists } from "./utils";
78

89
const getOptionalInput = (name: string) => core.getInput(name) || undefined;
910

@@ -30,7 +31,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
3031
}
3132
const git = new Git({
3233
octokit: commitMode === "github-api" ? octokit : undefined,
33-
cwd
34+
cwd,
3435
});
3536

3637
let setupGitUser = core.getBooleanInput("setupGitUser");
@@ -71,7 +72,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
7172
);
7273

7374
let userNpmrcPath = `${process.env.HOME}/.npmrc`;
74-
if (fs.existsSync(userNpmrcPath)) {
75+
if (await fileExists(userNpmrcPath)) {
7576
core.info("Found existing user .npmrc file");
7677
const userNpmrcContent = await fs.readFile(userNpmrcPath, "utf8");
7778
const authLine = userNpmrcContent.split("\n").find((line) => {
@@ -86,14 +87,14 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
8687
core.info(
8788
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
8889
);
89-
fs.appendFileSync(
90+
await fs.appendFile(
9091
userNpmrcPath,
9192
`\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
9293
);
9394
}
9495
} else {
9596
core.info("No user .npmrc file found, creating one");
96-
fs.writeFileSync(
97+
await fs.writeFile(
9798
userNpmrcPath,
9899
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
99100
);

src/run.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Changeset } from "@changesets/types";
22
import writeChangeset from "@changesets/write";
33
import fixturez from "fixturez";
4-
import fs from "fs-extra";
5-
import path from "path";
4+
import fs from "node:fs/promises";
5+
import path from "node:path";
66
import { beforeEach, describe, expect, it, vi } from "vitest";
77
import { Git } from "./git";
88
import { setupOctokit } from "./octokit";
@@ -53,7 +53,7 @@ beforeEach(() => {
5353
describe("version", () => {
5454
it("creates simple PR", async () => {
5555
let cwd = f.copy("simple-project");
56-
linkNodeModules(cwd);
56+
await linkNodeModules(cwd);
5757

5858
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
5959

@@ -91,7 +91,7 @@ describe("version", () => {
9191

9292
it("only includes bumped packages in the PR body", async () => {
9393
let cwd = f.copy("simple-project");
94-
linkNodeModules(cwd);
94+
await linkNodeModules(cwd);
9595

9696
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
9797

@@ -125,7 +125,7 @@ describe("version", () => {
125125

126126
it("doesn't include ignored package that got a dependency update in the PR body", async () => {
127127
let cwd = f.copy("ignored-package");
128-
linkNodeModules(cwd);
128+
await linkNodeModules(cwd);
129129

130130
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
131131

@@ -159,7 +159,7 @@ describe("version", () => {
159159

160160
it("does not include changelog entries if full message exceeds size limit", async () => {
161161
let cwd = f.copy("simple-project");
162-
linkNodeModules(cwd);
162+
await linkNodeModules(cwd);
163163

164164
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
165165

@@ -217,7 +217,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
217217

218218
it("does not include any release information if a message with simplified release info exceeds size limit", async () => {
219219
let cwd = f.copy("simple-project");
220-
linkNodeModules(cwd);
220+
await linkNodeModules(cwd);
221221

222222
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
223223

src/run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { exec, getExecOutput } from "@actions/exec";
33
import * as github from "@actions/github";
44
import { PreState } from "@changesets/types";
55
import { Package, getPackages } from "@manypkg/get-packages";
6-
import fs from "fs-extra";
7-
import path from "path";
6+
import fs from "node:fs/promises";
7+
import path from "node:path";
88
import resolveFrom from "resolve-from";
99
import semverLt from "semver/functions/lt";
1010
import { Git } from "./git";

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unified from "unified";
22
import remarkParse from "remark-parse";
33
import remarkStringify from "remark-stringify";
4+
import fs from "node:fs/promises";
45
import type { Root } from "mdast";
56
// @ts-ignore
67
import mdastToString from "mdast-util-to-string";
@@ -105,3 +106,10 @@ export function isErrorWithCode(err: unknown, code: string) {
105106
err.code === code
106107
);
107108
}
109+
110+
export function fileExists(filePath: string) {
111+
return fs.access(filePath, fs.constants.F_OK).then(
112+
() => true,
113+
() => false
114+
);
115+
}

yarn.lock

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,6 @@
694694
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.7.tgz#4158d3105276773d5b7695cd4834b1722e4f37a8"
695695
integrity sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==
696696

697-
"@types/fs-extra@^8.0.0":
698-
version "8.1.2"
699-
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.2.tgz#7125cc2e4bdd9bd2fc83005ffdb1d0ba00cca61f"
700-
integrity sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==
701-
dependencies:
702-
"@types/node" "*"
703-
704697
"@types/is-ci@^3.0.0":
705698
version "3.0.0"
706699
resolved "https://registry.yarnpkg.com/@types/is-ci/-/is-ci-3.0.0.tgz#7e8910af6857601315592436f030aaa3ed9783c3"
@@ -720,11 +713,6 @@
720713
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
721714
integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==
722715

723-
"@types/node@*":
724-
version "20.2.1"
725-
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.2.1.tgz#de559d4b33be9a808fd43372ccee822c70f39704"
726-
integrity sha512-DqJociPbZP1lbZ5SQPk4oag6W7AyaGMO6gSfRwq3PWl4PXTwJpRQJhDq4W0kzrg3w6tJ1SwlvGZ5uKFHY13LIg==
727-
728716
"@types/node@^12.7.1":
729717
version "12.20.55"
730718
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"

0 commit comments

Comments
 (0)