-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (43 loc) · 1.79 KB
/
Copy pathindex.js
File metadata and controls
50 lines (43 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const fs = require('fs');
const path = require('path');
function loadNative() {
// 开发环境:本地编译产物优先于随包分发的 prebuild(与 node-gyp-build 的顺序一致)
const localBuild = path.join(__dirname, 'build/Release/hdiffpatch.node');
if (fs.existsSync(localBuild)) {
return require(localBuild);
}
// 静态 require 路径便于打包工具分析;失败(缺文件、musl 等 ABI 不符)时回退 node-gyp-build
try {
switch (`${process.platform}-${process.arch}`) {
case 'darwin-arm64':
return require('./prebuilds/darwin-arm64/node-hdiffpatch.node');
case 'darwin-x64':
return require('./prebuilds/darwin-x64/node-hdiffpatch.node');
case 'linux-x64':
return require('./prebuilds/linux-x64/node-hdiffpatch.node');
case 'linux-arm64':
return require('./prebuilds/linux-arm64/node-hdiffpatch.node');
case 'win32-x64':
return require('./prebuilds/win32-x64/node-hdiffpatch.node');
}
} catch (err) {}
return require('node-gyp-build')(__dirname);
}
const native = loadNative();
exports.native = native;
exports.diff = native.diff;
exports.patch = native.patch;
exports.diffStream = native.diffStream;
exports.patchStream = native.patchStream;
exports.diffSingleStream = native.diffSingleStream;
exports.patchSingleStream = native.patchSingleStream;
exports.diffWindow = native.diffWindow;
// Every native diff entry point performs a complete apply-and-compare check
// before returning. Consumers that would otherwise repeat the same round trip
// can use these explicit capabilities to safely avoid duplicate work.
exports.capabilities = Object.freeze({
diffStreamVerifiesOutput: true,
diffSingleStreamVerifiesOutput: true,
diffWindowVerifiesOutput: true,
maxCompressionThreads: 2,
});