Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fs-require

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-require - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

5

dist/fs-require.d.ts
import { FileSystem, fsRequire } from './types';
export type { FileSystem };
export declare const createFsRequire: (mfs: FileSystem) => fsRequire;
declare type Options = {
fs?: boolean | FileSystem;
};
export declare const createFsRequire: (mfs: FileSystem, options?: Options | undefined) => fsRequire;

14

dist/fs-require.js

@@ -48,3 +48,3 @@ "use strict";

let idCounter = 0;
const createFsRequire = (mfs) => {
const createFsRequire = (mfs, options) => {
idCounter += 1;

@@ -59,6 +59,12 @@ const fsRequireId = idCounter;

if (moduleName === 'fs') {
if (moduleSubpath) {
throw new Error(`Cannot find module '${modulePath}'`);
const { fs } = options !== null && options !== void 0 ? options : {};
if (!fs) {
if (moduleSubpath) {
throw new Error(`Cannot find module '${modulePath}'`);
}
return mfs;
}
return mfs;
if (fs !== true) {
return fs;
}
}

@@ -65,0 +71,0 @@ return realRequire(modulePath);

{
"name": "fs-require",
"version": "1.0.0",
"version": "1.1.0",
"description": "Create a require() function from any file-system",

@@ -5,0 +5,0 @@ "keywords": [

@@ -42,3 +42,29 @@ # fs-require [![Latest version](https://badgen.net/npm/v/fs-require)](https://npm.im/fs-require) <!-- [![Monthly downloads](https://badgen.net/npm/dm/fs-require)](https://npm.im/fs-require) -->[![Install size](https://packagephobia.now.sh/badge?p=fs-require)](https://packagephobia.now.sh/result?p=fs-require) [![Bundle size](https://badgen.net/bundlephobia/minzip/fs-require)](https://bundlephobia.com/result?p=fs-require)

## ⚙️ API
### createFsRequire(fs, options?)
Returns a `require(modulePath)` function that resolves from the file-system passed in.
#### fs
Type: `FileSystem`
Required
The file-system to resolve requires from.
#### options
##### options.fs
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.
## 👨‍👩‍👧 Related
- [fs-monkey](https://github.com/streamich/fs-monkey) - By the same author of [memfs](https://github.com/streamich/memfs). Patches the global `require` to access a virtual fs.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc