pax_global_header00006660000000000000000000000064135061041640014512gustar00rootroot0000000000000052 comment=ed2fcde9acaec943427a6756563a39aeb858d1e8 import-fresh-3.1.0/000077500000000000000000000000001350610416400141325ustar00rootroot00000000000000import-fresh-3.1.0/.editorconfig000066400000000000000000000002571350610416400166130ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 import-fresh-3.1.0/.gitattributes000066400000000000000000000000231350610416400170200ustar00rootroot00000000000000* text=auto eol=lf import-fresh-3.1.0/.github/000077500000000000000000000000001350610416400154725ustar00rootroot00000000000000import-fresh-3.1.0/.github/funding.yml000066400000000000000000000001721350610416400176470ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/require-uncached custom: https://sindresorhus.com/donate import-fresh-3.1.0/.github/security.md000066400000000000000000000002631350610416400176640ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. import-fresh-3.1.0/.gitignore000066400000000000000000000000461350610416400161220ustar00rootroot00000000000000node_modules yarn.lock *.heapsnapshot import-fresh-3.1.0/.npmrc000066400000000000000000000000231350610416400152450ustar00rootroot00000000000000package-lock=false import-fresh-3.1.0/.travis.yml000066400000000000000000000000751350610416400162450ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' - '6' import-fresh-3.1.0/fixture.js000066400000000000000000000000661350610416400161600ustar00rootroot00000000000000'use strict'; let i = 0; module.exports = () => ++i; import-fresh-3.1.0/heapdump.js000066400000000000000000000006151350610416400162750ustar00rootroot00000000000000'use strict'; const heapdump = require('heapdump'); // eslint-disable-line import/no-unresolved const importFresh = require('.'); for (let i = 0; i < 100000; i++) { require('./fixture.js')(); } heapdump.writeSnapshot(`require-${Date.now()}.heapsnapshot`); for (let i = 0; i < 100000; i++) { importFresh('./fixture.js')(); } heapdump.writeSnapshot(`import-fresh-${Date.now()}.heapsnapshot`); import-fresh-3.1.0/index.d.ts000066400000000000000000000005701350610416400160350ustar00rootroot00000000000000/** Import a module while bypassing the cache. @example ``` // foo.js let i = 0; module.exports = () => ++i; // index.js import importFresh = require('import-fresh'); require('./foo')(); //=> 1 require('./foo')(); //=> 2 importFresh('./foo')(); //=> 1 importFresh('./foo')(); //=> 1 ``` */ declare function importFresh(moduleId: string): unknown; export = importFresh; import-fresh-3.1.0/index.js000066400000000000000000000014021350610416400155740ustar00rootroot00000000000000'use strict'; const path = require('path'); const resolveFrom = require('resolve-from'); const parentModule = require('parent-module'); module.exports = moduleId => { if (typeof moduleId !== 'string') { throw new TypeError('Expected a string'); } const filePath = resolveFrom(path.dirname(parentModule(__filename)), moduleId); // Delete itself from module parent if (require.cache[filePath] && require.cache[filePath].parent) { let i = require.cache[filePath].parent.children.length; while (i--) { if (require.cache[filePath].parent.children[i].id === filePath) { require.cache[filePath].parent.children.splice(i, 1); } } } // Delete module from cache delete require.cache[filePath]; // Return fresh module return require(filePath); }; import-fresh-3.1.0/index.test-d.ts000066400000000000000000000002301350610416400170030ustar00rootroot00000000000000import {expectType, expectError} from 'tsd'; import importFresh = require('.'); expectType(importFresh('hello')); expectError(importFresh()); import-fresh-3.1.0/license000066400000000000000000000021251350610416400154770ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import-fresh-3.1.0/package.json000066400000000000000000000013341350610416400164210ustar00rootroot00000000000000{ "name": "import-fresh", "version": "3.1.0", "description": "Import a module while bypassing the cache", "license": "MIT", "repository": "sindresorhus/import-fresh", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=6" }, "scripts": { "test": "xo && ava && tsd", "heapdump": "node heapdump.js" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "require", "cache", "uncache", "uncached", "module", "fresh", "bypass" ], "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" }, "devDependencies": { "ava": "^1.0.1", "heapdump": "^0.3.12", "tsd": "^0.7.3", "xo": "^0.23.0" } } import-fresh-3.1.0/readme.md000066400000000000000000000027051350610416400157150ustar00rootroot00000000000000# import-fresh [![Build Status](https://travis-ci.org/sindresorhus/import-fresh.svg?branch=master)](https://travis-ci.org/sindresorhus/import-fresh) > Import a module while bypassing the [cache](https://nodejs.org/api/modules.html#modules_caching) Useful for testing purposes when you need to freshly import a module. ## Install ``` $ npm install import-fresh ``` ## Usage ```js // foo.js let i = 0; module.exports = () => ++i; ``` ```js const importFresh = require('import-fresh'); require('./foo')(); //=> 1 require('./foo')(); //=> 2 importFresh('./foo')(); //=> 1 importFresh('./foo')(); //=> 1 ``` ## Related - [clear-module](https://github.com/sindresorhus/clear-module) - Clear a module from the import cache - [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path - [import-cwd](https://github.com/sindresorhus/import-cwd) - Import a module from the current working directory - [import-lazy](https://github.com/sindresorhus/import-lazy) - Import modules lazily ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
import-fresh-3.1.0/test.js000066400000000000000000000004111350610416400154430ustar00rootroot00000000000000import test from 'ava'; import importFresh from '.'; test('main', t => { const id = './fixture'; t.is(require(id)(), 1); t.is(require(id)(), 2); t.is(require(id)(), 3); t.is(importFresh(id)(), 1); t.is(importFresh(id)(), 1); t.is(importFresh(id)(), 1); });