From c6f31c1360b9eb844cee80b05c00f9c3f02a045a Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 23 Feb 2020 01:07:03 +0700 Subject: [PATCH] Meta tweaks --- index.d.ts | 18 +++--------------- index.js | 4 +--- license | 2 +- package.json | 3 ++- readme.md | 23 ++--------------------- 5 files changed, 9 insertions(+), 41 deletions(-) diff --git a/index.d.ts b/index.d.ts index a9407d0..978c6a7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -40,23 +40,11 @@ declare const clear: { match(regex: RegExp): void; /** - Clear one module from cache non-recursively. No parent or child modules should be affected. - Relevant for systems with a state that's dependant on Singelton pattern. When user would want to clear a specific module from memory without it having any "side effects" such as clearing a child module from memory as well. - @param moduleId - What you would use with `require()`. - - @example - In the following example, `stats` module will **not** be cleared from memory + Clear a single module from the cache non-recursively. No parent or children modules will be affected. - **some-application-route.js** - ```js - const stats = require('stats'); - module.exports = () => {...} - ``` + This is mostly only useful if you use singletons, where you would want to clear a specific module without causing any side effects. - **code manager** - ```js - clearModule.single('some-application-route'); - ``` + @param moduleId - What you would use with `require()`. */ single(moduleId: string): void; }; diff --git a/index.js b/index.js index ca97b1a..7f54a8f 100644 --- a/index.js +++ b/index.js @@ -6,9 +6,7 @@ const parentModule = require('parent-module'); const resolve = moduleId => { try { return resolveFrom(path.dirname(parentModule(__filename)), moduleId); - } catch (error) { - return undefined; - } + } catch (_) {} }; const clear = moduleId => { diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/package.json b/package.json index 323a79d..0ebca80 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,11 @@ "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" }, "engines": { "node": ">=8" diff --git a/readme.md b/readme.md index 58927e1..e49507d 100644 --- a/readme.md +++ b/readme.md @@ -4,14 +4,12 @@ Useful for testing purposes when you need to freshly import a module. - ## Install ``` $ npm install clear-module ``` - ## Usage ```js @@ -35,7 +33,6 @@ require('./foo')(); //=> 1 ``` - ## API ### clearModule(moduleId) @@ -62,25 +59,9 @@ Regex to match against the module IDs. ### clearModule.single(moduleId) -Clear one module from cache non-recursively. No parent or child modules should be affected - -
-Example use -Relevant for systems with a state that's dependant on Singelton pattern. When user would want to clear a specific module from memory without it having any "side effects" such as clearing a child module from memory as well. - -In the following example, `stats` module will **not** be cleared from memory +Clear a single module from the cache non-recursively. No parent or children modules will be affected. -**some-application-route.js** -```js -const stats = require('stats'); -module.exports = () => {...} -``` - -**code manager** -```js -clearModule.single('some-application-route'); -``` -
+This is mostly only useful if you use singletons, where you would want to clear a specific module without causing any side effects. #### moduleId