fs-extender
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

FS-EXTENDER

Extender module for node filesystem


Codacy Badge Test Status


Description

The intention of this module is to provide many functions that don't yet exist in node fs module, like copy, move, list, find..., and also normalize their functioning between node versions.

This module don't make any changes to node fs module, except patching close and closeSync, and it can be turned off.

At its core this module works like graceful-fs but instead of cloning the fs module it makes an augmentation of the fs module or any other fs model type like. Environment Variables

This module can be used like a fs replacement module.

Usage

Install the package

npm install --save fs-extender
import * as fs from "fs-extender";

fs.copy(dir, someOtherDir, (err) => {
    if (!err) {
        console.log("Directory copied with sucess.");
    }
});

or

const fs = require("fs-extender");

fs.copy(dir, someOtherDir, (err) => {
    if (!err) {
        console.log("Directory copied with sucess.");
    }
});

Runing tests

  • npm run lint: runs the linter
  • npm run unit: run unit tests
  • npm test: run both lint and unit tests
  • npm testUlimit: run tests defining ulimit to 50
  • npm testMemoryLeak: run tests to check for memoery leakage
  • npm testExternalFs: run tests based on provided fs module
  • npm testExternalMockedFs: run tests based on provided fs module that act like a mock
  • npm test-all: run all the above tests

Contribute

If you find a problem with the package you can

  • Submit a Bug
    • If you provide a test case it will make the issue resolution faster

or even make a

Add something new

If you wan't to add something new, following this steps would be much apreciated:

  • Develop the new helper, with clean and readable code
  • Develop tests for the new helper
  • Include in the comments a description of what the helper does, the input arguments and what it returns

Documentation

Besides the node file system documentation for all the node fs related functions the new methods provided can be found below.

Examples

For more examples just check the tests folder

Why this module

First things first,

Why not use something like the graceful-fs module?

When this module was started graceful-fs changed the fs module directly, that was a no go, if some of the node base modules must change it's way of functioning it must be done very carefully and in very rare occasions, just like the patch that this module implements in close file functions, just like graceful-fs now does, and because there's no way to don't use the graceful-fs when it is loaded in another module in the chain (see why not using jest for tests).

Why not use something like the fs-extra module?

Fisrt, because when this module was started the fs-extra didn't exist or was in their infancy, there where some tools like ncp (abandoned copy module) and other's but it was a pain to use all that separated tools.

Second because fs-extra is a fantastic module but in the background it operates (or used to) on top of graceful-fs (see first awnser) and it doens't have all the tools and options that I needed.

Why not use Jest for tests?

Because jest uses fs-extra as one of the dependencies and as we saw fs-extra uses graceful-fs and that makes impossible to test this module with jest and there's no way to remove graceful-fs from the chain, with this module you can bypass it if you wan't (see Environment Variables), even if it come from another module.

The modules that originated this module where using jest for tests until jest started using fs-extra and then the number of perfectly valid tests failling was impressive, then mocha to the rescue.

Credits

  • ncp - One of the modules that originated all this module (forget about the name of some others)
  • graceful-fs - A very good module for patching the fs module but with some flaws mainly the lack of an option to bypass the module
  • fs-extra - A very good module but that don't have all the tools needed for the job (or options for the tools)
  • mocha - Very good testing framework.

License

MIT License

Copyright (c) 2011 - 2021 Joao Parreira joaofrparreira@gmail.com

Package Sidebar

Install

npm i fs-extender

Weekly Downloads

53

Version

1.0.3

License

MIT

Unpacked Size

825 kB

Total Files

129

Last publish

Collaborators

  • n3okill