Skip to content

Commit

Permalink
Merge pull request #12567 from mattcompiles/fix-broken-rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Feb 3, 2021
2 parents 82edd91 + 0e5cabd commit 9393124
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Compilation.js
Expand Up @@ -1872,6 +1872,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
});
}

this.processDependenciesQueue.invalidate(module);
this.processModuleDependencies(module, err => {
if (err) return callback(err);
this.removeReasonsOfDependencyBlock(module, {
Expand Down
1 change: 1 addition & 0 deletions test/configCases/rebuild/rebuildWithNewDependencies/a.js
@@ -0,0 +1 @@
export default "a.js";
7 changes: 7 additions & 0 deletions test/configCases/rebuild/rebuildWithNewDependencies/index.js
@@ -0,0 +1,7 @@
import A from "./a";

it("should compile", function (done) {
expect(A).toBe("other-file.js");

done();
});
7 changes: 7 additions & 0 deletions test/configCases/rebuild/rebuildWithNewDependencies/loader.js
@@ -0,0 +1,7 @@
module.exports = function (source) {
if (this.shouldReplace)
return `import otherFile from './other-file.js';
export default otherFile;
`;
return source;
};
@@ -0,0 +1 @@
export default "other-file.js";
@@ -0,0 +1,60 @@
const { resolve, join } = require("path");
const { NormalModule } = require("../../../../");

/**
* @param {import("../../../../").Compiler} compiler the compiler
*/
var testPlugin = compiler => {
compiler.hooks.compilation.tap("TestPlugin", compilation => {
let shouldReplace = false;
NormalModule.getCompilationHooks(compilation).loader.tap(
"TestPlugin",
loaderContext => {
/** @type {any} */ (loaderContext).shouldReplace = shouldReplace;
}
);
compilation.hooks.finishModules.tapAsync(
"TestPlugin",
function (modules, callback) {
const src = resolve(join(__dirname, "a.js"));

/**
*
* @param {any} m test
* @returns {boolean} test
*/
function matcher(m) {
return m.resource && m.resource === src;
}

const module = Array.from(modules).find(matcher);

if (!module) {
throw new Error("something went wrong");
}

shouldReplace = true;
compilation.rebuildModule(module, err => {
shouldReplace = false;
callback(err);
});
}
);
});
};

/** @type {import("../../../../").Configuration} */
module.exports = {
module: {
rules: [
{
test: /a.js/,
use: "./loader"
}
]
},
optimization: {
concatenateModules: false
},
plugins: [testPlugin]
};

0 comments on commit 9393124

Please sign in to comment.