Gathering detailed insights and metrics for fs-require
Gathering detailed insights and metrics for fs-require
Gathering detailed insights and metrics for fs-require
Gathering detailed insights and metrics for fs-require
fs-constants
Require constants across node and the browser
@formily-editor/extensions
```javascript const fs = require('fs'); const path = require('path') const pick = require('lodash.pick')
craydent-fs
Node module to extend fs functionality and simplify code for maintainability and readability
mock-fs-require-fix
Fork of the tschaub/mock-fs project.
Create a require() function from any file-system. Great for in-memory fs testing!
npm install fs-require
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
16 Stars
41 Commits
1 Forks
2 Watchers
5 Branches
1 Contributors
Updated on Aug 28, 2024
Latest Version
1.6.0
Package Id
fs-require@1.6.0
Unpacked Size
11.23 kB
Size
4.51 kB
File Count
7
NPM Version
8.19.2
Node Version
18.12.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
Create a require()
function from any file-system.
Pass in a virtual file-system for in-memory testing without writing to disk.
index
and implicit extensions js
and json
__dirname
& __filename
require.resolve()
& require.cache
fs
within fsRequirefs-require://
protocolSupport this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️
1npm i fs-require
Using fs-require with memfs is a great combination for writing tests that interact with the file-system.
Testing functionality that interacts with the file-system can be brittle because they expect a clean slate and can also be dangerous if the path is wrong. Creating a virtual file-system with memfs
and testing its contents with fsRequire
makes it secure and fast!
1import { Volume } from 'memfs'
2import { createFsRequire } from 'fs-require'
3
4// Create a virtual fs from JSON
5const virtualFs = Volume.fromJSON({
6 '/hello-world.js': `
7 module.exports = function () {
8 return 'Hello world!'
9 }
10 `
11})
12
13// Create fsRequire
14const fsRequire = createFsRequire(virtualFs)
15
16// Import virtual module
17const helloWorld = fsRequire('/hello-world')
18
19console.log(helloWorld()) // Hello world!
Returns a fsRequire(modulePath)
function that resolves from the file-system passed in.
Type: FileSystem
Required
The file-system to resolve requires from.
Type: boolean | FileSystem
Code executed the virtual file-system may require('fs')
and this may either pose as a security concern or yield inconsistent results as the virtual file won't not accessible through the actual fs
module.
By default require('fs')
is shimmed to the file-system passed into createFsRequire
.
To disable this behavior and resolve to the real fs
module, set this to true
.
You can also pass in a different file-system too.
Type: string
Required
Path to the module you want to "require". Mocks Node.js require
.
Type: string
Required
Path to the module you want to "resolve". Mocks Node.js require.resolve
.
Type: Record<string, Module>
An object that contains the cache for modules that have been loaded so far. The key is the absolute path to the module, and the value is the module instance. Mocks Node.js require.cache
.
To re-load a module that has already been loaded, you can delete the cache the same way you would in Node.js:
1delete fsRequire.cache[fsRequire.resolve('/some-module.js')]
Case sensitivity in paths is a file-system concern so it would depend on the fs
passed in. For example, macOS (native fs) is case insensitive. memfs is case sensitive.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/26 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More