Skip to content

Commit

Permalink
fix: should run next invalidation when watching is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Jan 8, 2025
1 parent 0237d92 commit 5775dc6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const path = require('path');

const mockFn = jest.fn(() => {});

class MyPlugin {
apply(compiler) {
compiler.hooks.watchRun.tap("MyPlugin", mockFn)
}
}

/** @type {import('../../dist').TCompilerCaseConfig} */
module.exports = {
description: "should be invalidated correctly",
options(context) {
return {
context: context.getSource(),
entry: "./abc",
plugins: [new MyPlugin()]
};
},
async build(_, compiler) {
try {
await new Promise((resolve, reject) => {
let firstRun = true;
compiler.watch({}, (err) => {
if (err) {
return reject(err);
}
if (firstRun) {
firstRun = false;
compiler.watching.lazyCompilationInvalidate(path.resolve(__dirname, "../fixtures/a.js"));
compiler.watching.lazyCompilationInvalidate(path.resolve(__dirname, "../fixtures/b.js"));
setTimeout(() => {
resolve()
}, 2000)
}
});
});
} catch(err) {
throw err
}

},
async check() {
expect(mockFn).toHaveBeenCalledTimes(3);
}
};
10 changes: 10 additions & 0 deletions packages/rspack/src/Watching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ export class Watching {
compilation.endTime = Date.now();
stats = new Stats(compilation);

if (
this.invalid &&
!this.suspended &&
!this.blocked &&
!(this.isBlocked() && (this.blocked = true))
) {
this.#go();
return;
}

this.compiler.hooks.done.callAsync(stats, err => {
if (err) return handleError(err, cbs);
this.handler(null, stats);
Expand Down

0 comments on commit 5775dc6

Please sign in to comment.