clear-module
Advanced tools
+9
-0
@@ -41,4 +41,13 @@ declare const clear: { | ||
| match(regex: RegExp): void; | ||
| /** | ||
| Clear a single module from the cache non-recursively. No parent or children modules will be affected. | ||
| This is mostly only useful if you use singletons, where you would want to clear a specific module without causing any side effects. | ||
| @param moduleId - What you would use with `require()`. | ||
| */ | ||
| single(moduleId: string): void; | ||
| }; | ||
| export = clear; |
+9
-3
@@ -9,5 +9,3 @@ 'use strict'; | ||
| return resolveFrom(path.dirname(parentModule(__filename)), moduleId); | ||
| } catch (error) { | ||
| return undefined; | ||
| } | ||
| } catch (_) {} | ||
| }; | ||
@@ -64,2 +62,10 @@ | ||
| clear.single = moduleId => { | ||
| if (typeof moduleId !== 'string') { | ||
| throw new TypeError(`Expected a \`string\`, got \`${typeof moduleId}\``); | ||
| } | ||
| delete require.cache[resolve(moduleId)]; | ||
| }; | ||
| module.exports = clear; |
+3
-2
| { | ||
| "name": "clear-module", | ||
| "version": "4.0.0", | ||
| "version": "4.1.0", | ||
| "description": "Clear a module from the cache", | ||
| "license": "MIT", | ||
| "repository": "sindresorhus/clear-module", | ||
| "funding": "https://github.com/sponsors/sindresorhus", | ||
| "author": { | ||
| "name": "Sindre Sorhus", | ||
| "email": "sindresorhus@gmail.com", | ||
| "url": "sindresorhus.com" | ||
| "url": "https://sindresorhus.com" | ||
| }, | ||
@@ -12,0 +13,0 @@ "engines": { |
+11
-3
@@ -7,3 +7,2 @@ # clear-module [](https://travis-ci.org/sindresorhus/clear-module) | ||
| ## Install | ||
@@ -15,3 +14,2 @@ | ||
| ## Usage | ||
@@ -40,3 +38,2 @@ | ||
| ## API | ||
@@ -66,3 +63,14 @@ | ||
| ### clearModule.single(moduleId) | ||
| Clear a single module from the cache non-recursively. No parent or children modules will be affected. | ||
| This is mostly only useful if you use singletons, where you would want to clear a specific module without causing any side effects. | ||
| #### moduleId | ||
| Type: `string` | ||
| What you would use with `require()`. | ||
| ## Related | ||
@@ -69,0 +77,0 @@ |
Sorry, the diff of this file is not supported yet
6144
17.39%93
12.05%78
11.43%