Comparing version 1.0.0 to 1.1.0
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; |
@@ -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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11087
142
70