Skip to content

Commit

Permalink
chore(packages/rspack): add version check for binding
Browse files Browse the repository at this point in the history
  • Loading branch information
lippzhang committed Jul 11, 2023
1 parent 1a37840 commit 1fd012a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/rspack/src/rspack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { Callback } from "tapable";
import MultiStats from "./multiStats";
import assert from "assert";
import { asArray, isNil } from "./util";
import { bindingVersionCheck } from "./util/bindingVersionCheck";
import IgnoreWarningsPlugin from "./lib/ignoreWarningsPlugin";

function createMultiCompiler(options: MultiRspackOptions): MultiCompiler {
Expand Down Expand Up @@ -113,6 +114,9 @@ function rspack(
options: MultiRspackOptions | RspackOptions,
callback?: Callback<Error, MultiStats> | Callback<Error, Stats>
) {
bindingVersionCheck(err => {
if (err) throw err;
});
asArray(options).every(opts => {
validateConfig(opts);
});
Expand Down
24 changes: 24 additions & 0 deletions packages/rspack/src/util/bindingVersionCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function getBindingVersion() {
return require("@rspack/binding/package.json").version;
}
function getRspackVersion() {
return require("../../package.json").version;
}

type Callback = (error: Error | null) => void;

export const bindingVersionCheck = (callback: Callback) => {
const coreVersion = getRspackVersion();
const bindingVersion = getBindingVersion();
if (coreVersion !== bindingVersion) {
return callback(
new Error(
`The rspack core version ${JSON.stringify(
coreVersion
)} is not match to binding version ${JSON.stringify(bindingVersion)}`
)
);
} else {
return callback(null);
}
};

0 comments on commit 1fd012a

Please sign in to comment.