Git Product home page Git Product logo

Comments (3)

mzgoddard avatar mzgoddard commented on June 8, 2024

Here is some code I tried in the resolver to replace existing built modules at a later point for when modules depending on old resolutions need to be busted.

var walkDependencyBlock = function(block, callback) {
  console.log(block);
  block.dependencies.forEach(callback);
  block.variables.forEach(function(variable) {
    variable.dependencies.forEach(callback);
  });
  block.blocks.forEach(function(block) {
    walkDependencyBlock(block, callback);
  });
};

// Invalidate any dependencies that request this resolution. For
// normal modules nothing needs to be done. But cached modules
// depending on this need to be busted, removed from the
// compilation, reasons for it re-processed, and the cache entry
// removed.
var willBust = [];
compilation.modules.forEach(function(module) {
  if (module instanceof CacheModule) {
    var dependsOnRequest = true;
    walkDependencyBlock(module, function(dependency) {
      dependsOnRequest = dependsOnRequest &&
        module.context === request.context &&
        dependency.request === request.request;
    });
    if (dependsOnRequest) {
      willBust.push(module);
    }
  }
});
var addModuleDependencies = Promise.promisify(compilation.addModuleDependencies, {context: compilation});
var whenBusted = Promise.all(willBust.map(function(module) {
  var reasons = module.reasons.slice();
  module.disconnect();
  compilation._modules[module.identifier()] = null;
  compilation.modules.splice(compilation.modules.indexOf(module), 1);
  return Promise.all(reasons.map(function(reason) {
    reason.dependency.module = null;
    return addModuleDependencies(reason.module, [[reason.dependency]], compilation.bail, null, true);
  }));
}));

// Remove the out of date cache modules.
Object.keys(moduleCache).forEach(function(key) {
  if (key === 'fileDependencies') {return;}
  var module = moduleCache[key];
  if (typeof module === 'string') {
    module = JSON.parse(module);
    moduleCache[key] = module;
  }
  var dependsOnRequest = true;
  walkDependencyBlock(module, function(cacheDependency) {
    dependsOnRequest = dependsOnRequest &&
      module.context === request.context &&
      cacheDependency.request === request.request;
  });
  if (dependsOnRequest) {
    moduleCache[key] = null;
  }
});

// Remove the out of date resolution.
resolveCache[cacheId] = null;

// Resolve normally.
whenBusted.then(next);

from hard-source-webpack-plugin.

mzgoddard avatar mzgoddard commented on June 8, 2024

Took a look at invalidating with the pre-compiling step idea. Current shot seems to work though a test for it doesn't seem to pick the file changes and a plugin eval-source-map test fails.

The main block is:

    .then(function() {
      var childCompiler = compiler.createChildCompiler();

      var params = childCompiler.newCompilationParams();
      childCompiler.applyPlugins("compile", params);

      var compilation = childCompiler.newCompilation(params);

      var entries = moduleCache.entries;

      return Promise.all(entries.map(function(entry) {
        return Promise.promisify(compilation.addEntry, {context: compilation})('', new SingleEntryDependency(entry), '');
      }))
      .then(function() {
        return Promise.promisify(compilation.seal, {context: compilation})();
      })
      .then(function() {return compilation;});
    })
    .then(function(compilation) {
      // console.log(compilation.modules);
      compilation.modules.forEach(function(module) {
        if (!(module instanceof HardModule)) {
          return;
        }

        var cacheItem = moduleCache[module.request];
        if (!cacheItem) {
          return;
        }

        if (
          !lodash.isEqual(cacheItem.used, module.used) ||
          !lodash.isEqual(cacheItem.usedExports, module.usedExports)
        ) {
          cacheItem.invalid = true;
          moduleCache[module.request] = null;
        }
      });
    })

from hard-source-webpack-plugin.

mzgoddard avatar mzgoddard commented on June 8, 2024

Closing with the merge of #15. #15 uses an improved version of the last above block. It runs a pre-emptive compiler pass and compares output to invalidate modules. This works and I don't think a more complex single pass would work as the work that builds up used and usedExports happens in a step of compilation.seal so we'd need to wait to some point in seal and replace invalid modules and then re-run necessary parts of seal for the newly built modules. This would make a single pass really really complicated.

from hard-source-webpack-plugin.

Related Issues (20)

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.