From 6b89e63863448c7607a346fd60c9f5ce5a9f9596 Mon Sep 17 00:00:00 2001 From: Ivan Torres <40922354+torresgol10@users.noreply.github.com> Date: Thu, 19 Sep 2024 00:27:58 +0200 Subject: [PATCH] Remove dependecy graceful-fs and types (#67194) Remove the dependency `graceful-fs` and types. I have looked at the project and it is only used in one file, inside this file only `fs` is imported but not the functionality provided by the library, finally it uses the native one through `graceful-fs`, I have simplified the logic and removed the unnecessary library. The retry functionality is implemented in the file and is not used from the dependency Co-authored-by: torresgol10.it Co-authored-by: JJ Kasper --- packages/next/package.json | 2 -- packages/next/src/lib/fs/rename.ts | 11 +++++------ pnpm-lock.yaml | 6 ------ 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/next/package.json b/packages/next/package.json index a8b20b90e6868..4c363cda60ee4 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -100,7 +100,6 @@ "@swc/helpers": "0.5.13", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", - "graceful-fs": "^4.2.11", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, @@ -188,7 +187,6 @@ "@types/express-serve-static-core": "4.17.33", "@types/fresh": "0.5.0", "@types/glob": "7.1.1", - "@types/graceful-fs": "4.1.9", "@types/jsonwebtoken": "9.0.0", "@types/lodash": "4.14.198", "@types/lodash.curry": "4.1.6", diff --git a/packages/next/src/lib/fs/rename.ts b/packages/next/src/lib/fs/rename.ts index 679bc323e833d..06f1e32288ae6 100644 --- a/packages/next/src/lib/fs/rename.ts +++ b/packages/next/src/lib/fs/rename.ts @@ -25,8 +25,7 @@ SOFTWARE. // This file is based on https://github.com/microsoft/vscode/blob/f860fcf11022f10a992440fd54c6e45674e39617/src/vs/base/node/pfs.ts // See the LICENSE at the top of the file -import * as fs from 'graceful-fs' -import { promisify } from 'util' +import { rename as fsRename, stat } from 'node:fs/promises' /** * A drop-in replacement for `fs.rename` that: @@ -49,7 +48,7 @@ export async function rename( // graceful-fs will immediately return without retry for fs.rename(). await renameWithRetry(source, target, Date.now(), windowsRetryTimeout) } else { - await promisify(fs.rename)(source, target) + await fsRename(source, target) } } @@ -61,7 +60,7 @@ async function renameWithRetry( attempt = 0 ): Promise { try { - return await promisify(fs.rename)(source, target) + return await fsRename(source, target) } catch (error: any) { if ( error.code !== 'EACCES' && @@ -82,8 +81,8 @@ async function renameWithRetry( if (attempt === 0) { let abortRetry = false try { - const stat = await promisify(fs.stat)(target) - if (!stat.isFile()) { + const statTarget = await stat(target) + if (!statTarget.isFile()) { abortRetry = true // if target is not a file, EPERM error may be raised and we should not attempt to retry } } catch (e) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5ca11843bd779..17135cf6d8ae7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -864,9 +864,6 @@ importers: caniuse-lite: specifier: 1.0.30001579 version: 1.0.30001579 - graceful-fs: - specifier: ^4.2.11 - version: 4.2.11 postcss: specifier: 8.4.31 version: 8.4.31 @@ -1061,9 +1058,6 @@ importers: '@types/glob': specifier: 7.1.1 version: 7.1.1 - '@types/graceful-fs': - specifier: 4.1.9 - version: 4.1.9 '@types/jsonwebtoken': specifier: 9.0.0 version: 9.0.0