mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-07-09 17:28:58 +00:00
fix(build): improve Windows support based on PR #13 review feedback
Unify BUILD_PLATFORM macro with optional suffix parameter to eliminate duplication, centralize IS_WINDOWS/BINARY_NAME exports in install.js, add Windows-safe rename-then-replace strategy in update.js, and add PATH guidance in README for Windows users.
This commit is contained in:
parent
89effb6b22
commit
558ffe9a91
6 changed files with 42 additions and 20 deletions
|
|
@ -240,6 +240,8 @@ if (require.main === module) {
|
|||
});
|
||||
} else {
|
||||
module.exports = {
|
||||
IS_WINDOWS,
|
||||
BINARY_NAME,
|
||||
detectPlatform,
|
||||
loadPackageJson,
|
||||
buildUrl,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ const https = require("https");
|
|||
const { spawnSync } = require("child_process");
|
||||
|
||||
const {
|
||||
IS_WINDOWS,
|
||||
BINARY_NAME,
|
||||
detectPlatform,
|
||||
loadPackageJson,
|
||||
buildUrl,
|
||||
|
|
@ -16,9 +18,6 @@ const {
|
|||
downloadBinary,
|
||||
computeChecksum,
|
||||
} = require("./install.js");
|
||||
|
||||
const IS_WINDOWS = process.platform === "win32";
|
||||
const BINARY_NAME = IS_WINDOWS ? "opencodereview.exe" : "opencodereview";
|
||||
const packageRoot = path.join(__dirname, "..");
|
||||
const binDir = path.join(packageRoot, "bin");
|
||||
const binaryPath = path.join(binDir, BINARY_NAME);
|
||||
|
|
@ -197,7 +196,26 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
fs.renameSync(tempPath, binaryPath);
|
||||
if (IS_WINDOWS) {
|
||||
const oldPath = binaryPath + ".old";
|
||||
try { fs.unlinkSync(oldPath); } catch (_) {}
|
||||
try {
|
||||
fs.renameSync(binaryPath, oldPath);
|
||||
} catch (e) {
|
||||
if (fs.existsSync(binaryPath)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
try {
|
||||
fs.renameSync(tempPath, binaryPath);
|
||||
} catch (e) {
|
||||
try { fs.renameSync(oldPath, binaryPath); } catch (_) {}
|
||||
throw e;
|
||||
}
|
||||
try { fs.unlinkSync(oldPath); } catch (_) {}
|
||||
} else {
|
||||
fs.renameSync(tempPath, binaryPath);
|
||||
}
|
||||
} catch (_) {
|
||||
cleanupTemp();
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue