Skip to content
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

Feat: Add fs-extra #173

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ESLint plugin.
- [`ezspawn`](./process-exec.md)
- [`faker`](./faker.md)
- [`fast-glob`](./glob.md)
- [`fs-extra`](./fs-extra.md)
- [`glob`](./glob.md)
- [`globby`](./glob.md)
- [`ìnvariant`](./invariant.md)
Expand Down
76 changes: 76 additions & 0 deletions docs/modules/fs-extra.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# fs-extra

`fs-extra` adds some file system methods that previously were not included in the native `fs` module and added `Promise` support to the `fs` methods.
Many of the fs-extra modules have since been implemented natively by Node.

[fs-extra](https://github.com/jprichardson/node-fs-extra)

## Alternatives

### `node:fs`

[Node.js File System Module](https://nodejs.org/docs/latest/api/fs.html)

To use the promise-based APIs:

```js
import * as fs from 'node:fs/promises';
```

To use the callback and sync APIs:

```js
import * as fs from 'node:fs';
```

#### Equivalent Methods

| fs-extra | node:fs | Notes |
| ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `copySync(src, dest[, options])` | `fs.copyFileSync(src, dest[, mode])` | |
| `mkdirs(dir[,options][,callback])`, `mkdirp(dir[,options][,callback])`, `ensureDir(dir[,options][,callback])` | `fs.mkdir(dir, { recursive: true }, callback)` | `ensureDir` and `mkdirp` are aliases of `mkdirs` |
| `mkdirpSync(dir[,options])`, `mkdirsSync(dir[,options])`, `ensureDirSync(dir[,options])` | `fs.mkdirSync(dir, { recursive: true })` | `ensureDirSync` and `mkdirpSync` are aliases of `mkdirsSync` |
| `remove(path[,callback])` | `fs.rm(path, { recursive: true, force: true }, callback)` | |
| `removeSync(dir)` | `fs.rmSync(dir, { recursive: true, force: true })` | |
| `move(src, dest, { overwrite: true }, callback)` | `fs.rename(source, destination)` | |
| `moveSync(source, destination, { overwrite: true })` | `fs.renameSync(source, destination)` | These are not strictly equivalent. The `move` methods in fs-extra act like the `mv` command and they will work across devices also. The `rename` methods in fs work like the `rename` system call and will **not** work across devices. Having Node’s `rename` methods work across devices is currently [marked as a "won't fix."](https://github.com/nodejs/node/issues/19077) Also, the `overwrite: true` behaviour is the default/only behaviour in the standard library. |
| `copy(source, destination, callback)` | `fs.cp(source, destination, callback)` | |
| `pathExistsSync(file)` | `fs.existsSync(path)` | |

#### Methods that need migrating or more than one `node:fs` method

For all other methods, a combination of fs methods may be needed rather than there being a one-to-one replacement. See the docs [here](https://nodejs.org/docs/latest/api/fs.html)

##### `emptyDir(dir[, callback])`
walter-0 marked this conversation as resolved.
Show resolved Hide resolved

##### `emptyDirSync(dir)`
walter-0 marked this conversation as resolved.
Show resolved Hide resolved

##### `ensureFile(file[, callback])`

##### `ensureFileSync(file)`

##### `ensureLink(srcPath, destPath[, callback])`

##### `ensureLinkSync(srcPath, destPath)`

##### `ensureSymlink(srcPath, destPath[, type][, callback])`

##### `ensureSymlinkSync(srcPath, destPath[, type])`

##### `outputFile(file, data[, options][, callback])`

##### `outputFileSync(file, data[, options])`

##### `outputJson(file, object[, options][, callback])`

##### `outputJsonSync(file, object[, options])`

##### `pathExists(file[, callback])`

##### `readJson(file[, options][, callback])`

##### `readJsonSync(file[, options])`

##### `writeJson(file, object[, options][, callback])`

##### `writeJsonSync(file, object[, options])`
4 changes: 2 additions & 2 deletions docs/templates/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

{Optional description}

# Alternatives
## Alternatives

## {Alternative package name}
### {Alternative package name}

{Description of alternative package}

Expand Down
6 changes: 6 additions & 0 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
"docPath": "glob",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "fs-extra",
"docPath": "fs-extra",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "glob",
Expand Down