diff --git a/package.json b/package.json index 502e5ea6..02f3fc7b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "@changesets/changelog-github": "^0.4.2", "@changesets/cli": "^2.20.0", "@changesets/write": "^0.1.6", - "@types/fs-extra": "^8.0.0", "@types/node": "^22.15.17", "@types/semver": "^7.5.0", "esbuild": "^0.25.4", @@ -41,7 +40,6 @@ "@octokit/core": "^5.2.1", "@octokit/plugin-throttling": "^8.0.0", "@types/mdast": "^3.0.0", - "fs-extra": "^8.1.0", "mdast-util-to-string": "^1.0.6", "remark-parse": "^7.0.1", "remark-stringify": "^7.0.3", diff --git a/src/index.ts b/src/index.ts index c5b0dc92..e3ad4218 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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` ); diff --git a/src/run.test.ts b/src/run.test.ts index 299376cc..147fcf3b 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -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: [] })); diff --git a/src/run.ts b/src/run.ts index 60dba996..6ac71c16 100644 --- a/src/run.ts +++ b/src/run.ts @@ -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"; diff --git a/src/utils.ts b/src/utils.ts index f2bfacbf..319b69d9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 + ); +} diff --git a/yarn.lock b/yarn.lock index ff294486..20fa1bb9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -694,13 +694,6 @@ resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.7.tgz#4158d3105276773d5b7695cd4834b1722e4f37a8" 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": version "3.0.0" 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" 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": version "12.20.55" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"