Skip to content

Commit

Permalink
Merge branch 'main' into node-api
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind authored Apr 1, 2024
2 parents 35fd25e + 48aa3b9 commit fef60d0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
18 changes: 11 additions & 7 deletions packages/rspack-dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,18 @@ export class RspackDevServer extends WebpackDevServer {
if (req.url.indexOf("/lazy-compilation-web/") > -1) {
const path = req.url.replace("/lazy-compilation-web/", "");
if (fs.existsSync(path)) {
compiler.rebuild(new Set([path]), new Set(), error => {
if (error) {
throw error;
compiler.__internal__rebuild(
new Set([path]),
new Set(),
error => {
if (error) {
throw error;
}
res.write("");
res.end();
console.log("lazy compiler success");
}
res.write("");
res.end();
console.log("lazy compiler success");
});
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
});
});
await new Promise((resolve, reject) => {
compiler.rebuild(
compiler.__internal__rebuild(
new Set([context.getSource("./fixtures/a")]),
new Set(),
err => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
});
});
await new Promise((resolve, reject) => {
compiler.rebuild(
compiler.__internal__rebuild(
new Set([context.getSource("./fixtures/a")]),
new Set(),
err => {
Expand Down
21 changes: 9 additions & 12 deletions packages/rspack/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Compiler {
compilation?: Compilation;
compilationParams?: CompilationParams;
// TODO: remove this after remove rebuild on the rust side.
first: boolean = true;
#initial: boolean = true;
builtinPlugins: binding.BuiltinPlugin[];
root: Compiler;
running: boolean;
Expand Down Expand Up @@ -945,15 +945,12 @@ class Compiler {
doRun();
}
}
/**
* Safety: This method is only valid to call if the previous rebuild task is finished, or there will be data races.
*/
build(callback?: (error: Error | null) => void) {
#build(callback?: (error: Error | null) => void) {
this.#getInstance((error, instance) => {
if (error) {
return callback?.(error);
}
if (!this.first) {
if (!this.#initial) {
instance!.rebuild(
Array.from(this.modifiedFiles || []),
Array.from(this.removedFiles || []),
Expand All @@ -966,7 +963,7 @@ class Compiler {
);
return;
}
this.first = false;
this.#initial = false;
instance!.build(error => {
if (error) {
return callback?.(error);
Expand All @@ -977,10 +974,10 @@ class Compiler {
}

/**
* Safety: This method is only valid to call if the previous rebuild task is finished, or there will be data races.
* @deprecated This is a low-level incremental rebuild API, which shouldn't be used intentionally. Use `compiler.build` instead.
* * Note: This is not a webpack public API, maybe removed in future.
* @internal
*/
rebuild(
__internal__rebuild(
modifiedFiles?: ReadonlySet<string>,
removedFiles?: ReadonlySet<string>,
callback?: (error: Error | null) => void
Expand Down Expand Up @@ -1041,7 +1038,7 @@ class Compiler {
this.hooks.compile.call(params);
this.#resetThisCompilation();

this.build(err => {
this.#build(err => {
if (err) {
return callback(err);
}
Expand Down Expand Up @@ -1077,7 +1074,7 @@ class Compiler {

close(callback: (error?: Error | null) => void) {
if (this.watching) {
// When there is still an active watching, close this first
// When there is still an active watching, close this #initial
this.watching.close(() => {
this.close(callback);
});
Expand Down

0 comments on commit fef60d0

Please sign in to comment.