-
-
Notifications
You must be signed in to change notification settings - Fork 93
docs: more consistent usage of node:fs #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ description: Native Node.js alternatives to the rimraf package for recursive dir | |
|
|
||
| # Replacements for `rimraf` | ||
|
|
||
| ## `fs.rm` (native, Node.js) | ||
| ## `fs.rmSync` and `fs.promises.rm` (native, Node.js) | ||
|
|
||
| Node.js v14.14.0 and above provide a native alternative: [`fs.rm`](https://nodejs.org/api/fs.html#fspromisesrmpath-options) and [`fs.rmSync`](https://nodejs.org/api/fs.html#fsrmsyncpath-options). It supports recursive deletion and works as a direct replacement. | ||
|
|
||
|
|
@@ -13,19 +13,15 @@ Node.js v14.14.0 and above provide a native alternative: [`fs.rm`](https://nodej | |
| ```ts | ||
| import rimraf from 'rimraf' // [!code --] | ||
| import { rm } from 'node:fs/promises' // [!code ++] | ||
| import { rmSync } from 'node:fs' // [!code ++] | ||
|
|
||
| // Async | ||
| await rimraf('./dist') // [!code --] | ||
| await rm('./dist', { recursive: true, force: true }) // [!code ++] | ||
| ``` | ||
|
|
||
| ### Sync methods | ||
|
|
||
| ```ts | ||
| import rimraf from 'rimraf' // [!code --] | ||
| import * as fs from 'node:fs' // [!code ++] | ||
|
|
||
|
Comment on lines
-19
to
26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should remove this
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I combined them into one code block as I've seen some other docs do that too
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should change the "### Async methods" heading then |
||
| // Sync | ||
| rimraf.sync('./dist') // [!code --] | ||
| fs.rmSync('./dist', { recursive: true, force: true }) // [!code ++] | ||
| rmSync('./dist', { recursive: true, force: true }) // [!code ++] | ||
| ``` | ||
|
|
||
| > [!IMPORTANT] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,9 @@ description: Modern alternatives to the temp and tempy packages for creating tem | |
|
|
||
| # Replacements for `temp` / `tempy` | ||
|
|
||
| ## `fs.mkdtemp` (native, since Node.js v14.x) | ||
| ## `fs.mkdtemp` and `fs.promises.mkdtemp` (native, since Node.js v14.x) | ||
|
|
||
| Node.js has the [`fs.mkdtemp`](https://nodejs.org/api/fs.html#fsmkdtempprefix-options-callback) function for creating a unique temporary directory. Directory cleanup can be done by passing `{recursive: true}` to [`fs.rm`](https://nodejs.org/api/fs.html#fsrmpath-options-callback). | ||
| Node.js has the [`fs.mkdtemp`](https://nodejs.org/api/fs.html#fsmkdtempprefix-options-callback) and [`fs.promises.mkdtemp`](https://nodejs.org/api/fs.html#fspromisesmkdtempprefix-options) functions for creating a unique temporary directory. Directory cleanup can be done by passing `{recursive: true}` to [`fs.rm`](https://nodejs.org/api/fs.html#fsrmpath-options-callback). | ||
|
|
||
| Example: | ||
|
|
||
|
|
@@ -20,9 +20,9 @@ const tempDirPath = temp.mkdirSync('foo') // [!code --] | |
| const tempDirPath = await mkdtemp(join(await realpath(tmpdir()), 'foo-')) // [!code ++] | ||
| ``` | ||
|
|
||
| ## `fs.mkdtempDisposable` (native, since Node.js v20.4.0) | ||
| ## `fs.promises.mkdtempDisposable` (native, since Node.js v20.4.0) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should consider adding this to the manifest 👀 |
||
|
|
||
| Node.js now provides [`fs.mkdtempDisposable`](https://nodejs.org/api/fs.html#fspromisesmkdtempdisposableprefix-options) which leverages the `using` keyword for automatic cleanup. This eliminates the need for `temp.track()` or manual cleanup logic. | ||
| Node.js now provides [`fs.promises.mkdtempDisposable`](https://nodejs.org/api/fs.html#fspromisesmkdtempdisposableprefix-options) which leverages the `using` keyword for automatic cleanup. This eliminates the need for `temp.track()` or manual cleanup logic. | ||
|
|
||
| Example: | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.