Comparing version 1.4.0 to 1.4.1
{ | ||
"name": "fs-require", | ||
"version": "1.4.0", | ||
"description": "Create a require() function from any file-system", | ||
"keywords": [ | ||
"fs-require", | ||
"fs", | ||
"require", | ||
"memfs", | ||
"testing" | ||
], | ||
"license": "MIT", | ||
"repository": "privatenumber/fs-require", | ||
"funding": "https://github.com/privatenumber/fs-require?sponsor=1", | ||
"author": { | ||
"name": "Hiroki Osame", | ||
"email": "hiroki.osame@gmail.com" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"main": "dist/fs-require.js", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"build": "rm -rf dist && tsc", | ||
"test": "jest" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm run build && lint-staged && npm test" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts}": [ | ||
"eslint", | ||
"jest --bail --findRelatedTests" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@pvtnbr/eslint-config": "^0.4.1", | ||
"@types/jest": "^26.0.24", | ||
"@types/node": "^15.14.9", | ||
"es-jest": "^1.2.0", | ||
"eslint": "^7.32.0", | ||
"esno": "^0.5.0", | ||
"husky": "^4.3.8", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.4", | ||
"memfs": "^3.2.2", | ||
"typescript": "^4.4.4" | ||
}, | ||
"eslintConfig": { | ||
"extends": "@pvtnbr/eslint-config" | ||
} | ||
} | ||
"name": "fs-require", | ||
"version": "1.4.1", | ||
"description": "Create a require() function from any file-system", | ||
"keywords": [ | ||
"fs-require", | ||
"fs", | ||
"require", | ||
"memfs", | ||
"testing" | ||
], | ||
"license": "MIT", | ||
"repository": "privatenumber/fs-require", | ||
"funding": "https://github.com/privatenumber/fs-require?sponsor=1", | ||
"author": { | ||
"name": "Hiroki Osame", | ||
"email": "hiroki.osame@gmail.com" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"imports": { | ||
"#fs-require": { | ||
"types": "./src/index.ts", | ||
"development": "./src/index.ts", | ||
"default": "./dist/index.mjs" | ||
} | ||
} | ||
} |
@@ -5,2 +5,4 @@ # 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) | ||
Pass in a [virtual file-system](https://github.com/streamich/memfs) for in-memory testing without writing to disk. | ||
### Features | ||
@@ -11,5 +13,14 @@ - 💞 Works well with [memfs](https://github.com/streamich/memfs)! | ||
- 📍 `__dirname` & `__filename` | ||
- ✅ `require.resolve()` & `require.cache` | ||
- 👻 Mocks `fs` within fsRequire | ||
- 👣 Call stack shows paths with `fs-require://` protocol | ||
<sub>Support this project by ⭐️ starring and sharing it. [Follow me](https://github.com/privatenumber) to see what other cool projects I'm working on! ❤️</sub> | ||
## 🚀 Install | ||
```bash | ||
npm i fs-require | ||
``` | ||
## 🙋♀️ Why? | ||
@@ -20,2 +31,3 @@ Using fs-require with [memfs](https://github.com/streamich/memfs) is a great combination for writing tests that interact with the file-system. | ||
## 👨🏫 Usage | ||
@@ -48,3 +60,3 @@ | ||
### createFsRequire(fs, options?) | ||
Returns a `require(modulePath)` function that resolves from the file-system passed in. | ||
Returns a `fsRequire(modulePath)` function that resolves from the file-system passed in. | ||
@@ -72,2 +84,32 @@ #### fs | ||
### fsRequire(modulePath) | ||
#### modulePath | ||
Type: `string` | ||
Required | ||
Path to the module you want to "require". Mocks Node.js [`require`](https://nodejs.org/api/modules.html#requireid). | ||
### fsRequire.resolve(modulePath) | ||
#### modulePath | ||
Type: `string` | ||
Required | ||
Path to the module you want to "resolve". Mocks Node.js [`require.resolve`](https://nodejs.org/api/modules.html#requireresolverequest-options). | ||
### fsRequire.cache | ||
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`](https://nodejs.org/api/modules.html#requirecache). | ||
To re-load a module that has already been loaded, you can delete the cache the same way you would in Node.js: | ||
```js | ||
delete fsRequire.cache[fsRequire.resolve('/some-module.js')] | ||
``` | ||
## 💁♂️ FAQ | ||
@@ -74,0 +116,0 @@ ### Can it resolve case insensitive paths? |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
0
117
10476
6
36
2
6
1