import-fresh

  • Version 4.0.0
  • Published
  • 31.1 kB
  • No dependencies
  • MIT license

Install

npm i import-fresh
yarn add import-fresh
pnpm add import-fresh

Overview

Import a module while bypassing the cache

Index

Functions

function createImportFresh

createImportFresh: (
parentURL: string | URL,
options?: Options
) => ImportFreshFunction;

    Type Aliases

    type ImportAttributes

    type ImportAttributes = Record<string, string>;

      type ImportFreshFunction

      type ImportFreshFunction = <T = unknown>(
      moduleSpecifier: string,
      options?: ImportFreshOptions
      ) => Promise<T>;

        type ImportFreshOptions

        type ImportFreshOptions = {
        /**
        Import attributes passed to `import()`.
        Each value must be a string.
        */
        importAttributes?: ImportAttributes;
        };

          type Options

          type Options = {
          /**
          When `true`, modules under `node_modules` are not cache-busted.
          This option is process-global, so every `createImportFresh()` call in one process must use the same value.
          */
          skipNodeModules?: boolean;
          };
          • Import a module while bypassing the cache.

            Example 1

            // foo.js
            let count = 0;
            export default function increment() {
            count += 1;
            return count;
            }
            // index.js
            import createImportFresh from 'import-fresh';
            const importFresh = createImportFresh(import.meta.url);
            const {default: increment} = await importFresh('./foo.js');
            increment();
            //=> 1
            increment();
            //=> 2
            const {default: freshIncrement} = await importFresh('./foo.js');
            freshIncrement();
            //=> 1
            const foo = await importFresh<typeof import('./foo.js')>('./foo.js');

          Package Files (1)

          Dependencies (0)

          No dependencies.

          Dev Dependencies (4)

          Peer Dependencies (0)

          No peer dependencies.

          Badge

          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/import-fresh.

          • Markdown
            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/import-fresh)
          • HTML
            <a href="https://www.jsdocs.io/package/import-fresh"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>