Git Product home page Git Product logo

cached-module-loader's Issues

Simplify API

I think the API for that module could be simple and export only one factory function, which returns a modified require():

const cachedRequire = require('cached-module-loader'){
  cachePath: join(__dirname, '.module-cache'),
  ignore: [/regex/, /to/, /ignore/]
});

const babel = cachedRequire('babel-core');
const got = cachedRequire('got');

cachedRequire()'s source would be something along:

function cachedRequire(moduleId) {
  if (!isCacheExists(moduleId)) {
    bundleDependencies(moduleId);
  }

  return loadInThisContext(moduleId);
}

What do you think?

Needs tests

  • From the perspective of the module, it shouldn't really be able to tell whether it was loaded from a cache or through Node.js module system. This means that all properties on the module object must be the same (aside from module.parent).
  • Circular dependencies must work as expected
  • Depending on built-in modules must work as expected
  • Dynamic requires are not cached, but must still resolve
  • โ€ฆ?

Caching strategies

Module caches may include lots of files. These are dependent on file system location, Node.js version, and indeed package version. This package should explain appropriate caching strategies.

I reckon that the cache should be discarded when the Node.js version changes. Perhaps we should generate a cache key that takes the version into account, allowing caches for different versions to live side-by-side.

The cache contains hardcoded file paths, so we need an easy way to verify the presumed location of the sources.

Integration with package-hash should be easy.

Perhaps we can resolve the npm modules the cache depends on. Then the respective package.json files could be hashed and verified before using the cache.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.