npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-hypothetical

v2.1.1

Published

gives Rollup an imaginary file system, e.g. for testing other plugins

Downloads

88,490

Readme

rollup-plugin-hypothetical npm Build Status

This allows Rollup modules to import hypothetical files passed in as options to the plugin.

Installation

npm install --save-dev rollup-plugin-hypothetical

Usage

// rollup.config.js
import hypothetical from 'rollup-plugin-hypothetical';

export default {
  entry: './dir/a.js',
  plugins: [hypothetical({
    files: {
      './dir/a.js': `
        import foo from './b.js';
        foo();
      `,
      './dir/b.js': `
        import message from 'external';
        export default function foo() {
          console.log(message);
        }
      `,
      'external/': `
        export default "Hello, World!";
      `
    }
  })]
};

Sourcemaps

To attach a sourcemap to a hypothetical file, simply pass in a { code, map } object instead of a string. The sourcemap can have its own sources, sourcesContent, etc.

Options

options.files

An object whose keys are paths, either relative to the current working directory or absolute, and whose values are the code within the hypothetical files at those paths.

options.filesMap

Rather than supplying a plain object to options.files, you may choose to supply a Map to options.filesMap. This will allow you to do things like naming your hypothetical files __proto__.

options.allowFallthrough

Defaults to false. Set this to true to allow non-external imports to fall through. That way they can be handled either by Rollup's default behavior (reading from the filesystem) or by a plugin further down the chain if there is one.

options.allowExternalFallthrough

Defaults to true. Set this to false to forbid external imports from falling through.

options.allowRelativeExternalFallthrough

Defaults to false. Set this to true to allow relative imports from supplied external modules to fall through. For instance, suppose you have the following options.files:

{
  './main.js': `
    import 'external/x.js';
  `,
  'external/x.js': `
    import './y.js';
  `
}

The supplied file external/x.js imports external/y.js, but external/y.js isn't supplied. This sort of thing is probably a mistake. If it isn't, set options.allowRelativeExternalFallthrough to true and remember to include external: ['external/y.js'] in the options you pass to rollup.rollup. If you forget that part, your build won't work, and weird things may happen instead!

options.leaveIdsAlone

When this is set to true, the IDs in import statements won't be treated as paths and will instead be looked up directly in the files object. There will be no relative importing, path normalization, or restrictions on the contents of IDs.

options.impliedExtensions

Set this to an array of file extensions to try appending to imports if an exact match isn't found. Defaults to ['.js', '/']. If this is set to false or an empty array, file extensions and trailing slashes in imports will be treated as mandatory.

options.cwd

When this is set to a directory name, relative file paths will be resolved relative to that directory rather than process.cwd(). When it's set to false, they will be resolved relative to an imaginary directory that cannot be expressed as an absolute path.

License

MIT