Skip to content

Commit

Permalink
Remove dependecy graceful-fs and types (#67194)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: JJ Kasper <[email protected]>
  • Loading branch information
3 people committed Sep 18, 2024
1 parent 5b0b68a commit 6b89e63
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
2 changes: 0 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 5 additions & 6 deletions packages/next/src/lib/fs/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
}
}

Expand All @@ -61,7 +60,7 @@ async function renameWithRetry(
attempt = 0
): Promise<void> {
try {
return await promisify(fs.rename)(source, target)
return await fsRename(source, target)
} catch (error: any) {
if (
error.code !== 'EACCES' &&
Expand All @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b89e63

Please sign in to comment.