Skip to content

Commit

Permalink
0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoaldamav committed Oct 2, 2023
1 parent 3e5ae3d commit 3362016
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 113 deletions.
195 changes: 92 additions & 103 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,265 +5,254 @@
/* auto-generated by NAPI-RS */

const { existsSync, readFileSync } = require('fs')
const { join } = require('path');
const { join } = require('path')

const { platform, arch } = process;
const { platform, arch } = process

let nativeBinding = null;
let localFileExisted = false;
let loadError = null;
let nativeBinding = null
let localFileExisted = false
let loadError = null

function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
const lddPath = require('child_process')
.execSync('which ldd')
.toString()
.trim();
return readFileSync(lddPath, 'utf8').includes('musl');
const lddPath = require('child_process').execSync('which ldd').toString().trim()
return readFileSync(lddPath, 'utf8').includes('musl')
} catch (e) {
return true;
return true
}
} else {
const { glibcVersionRuntime } = process.report.getReport().header;
return !glibcVersionRuntime;
const { glibcVersionRuntime } = process.report.getReport().header
return !glibcVersionRuntime
}
}

switch (platform) {
case 'android':
switch (arch) {
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'refclone.android-arm64.node')
);
localFileExisted = existsSync(join(__dirname, 'refclone.android-arm64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./refclone.android-arm64.node');
nativeBinding = require('./refclone.android-arm64.node')
} else {
nativeBinding = require('@refclone/refclone-android-arm64');
nativeBinding = require('@refclone/refclone-android-arm64')
}
} catch (e) {
loadError = e;
loadError = e
}
break;
break
case 'arm':
localFileExisted = existsSync(
join(__dirname, 'refclone.android-arm-eabi.node')
);
localFileExisted = existsSync(join(__dirname, 'refclone.android-arm-eabi.node'))
try {
if (localFileExisted) {
nativeBinding = require('./refclone.android-arm-eabi.node');
nativeBinding = require('./refclone.android-arm-eabi.node')
} else {
nativeBinding = require('@refclone/refclone-android-arm-eabi');
nativeBinding = require('@refclone/refclone-android-arm-eabi')
}
} catch (e) {
loadError = e;
loadError = e
}
break;
break
default:
throw new Error(`Unsupported architecture on Android ${arch}`);
throw new Error(`Unsupported architecture on Android ${arch}`)
}
break;
break
case 'win32':
switch (arch) {
case 'x64':
localFileExisted = existsSync(
join(__dirname, 'refclone.win32-x64-msvc.node')
);
)
try {
if (localFileExisted) {
nativeBinding = require('./refclone.win32-x64-msvc.node');
nativeBinding = require('./refclone.win32-x64-msvc.node')
} else {
nativeBinding = require('@refclone/refclone-win32-x64-msvc');
nativeBinding = require('@refclone/refclone-win32-x64-msvc')
}
} catch (e) {
loadError = e;
loadError = e
}
break;
break
case 'ia32':
localFileExisted = existsSync(
join(__dirname, 'refclone.win32-ia32-msvc.node')
);
)
try {
if (localFileExisted) {
nativeBinding = require('./refclone.win32-ia32-msvc.node');
nativeBinding = require('./refclone.win32-ia32-msvc.node')
} else {
nativeBinding = require('@refclone/refclone-win32-ia32-msvc');
nativeBinding = require('@refclone/refclone-win32-ia32-msvc')
}
} catch (e) {
loadError = e;
loadError = e
}
break;
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'refclone.win32-arm64-msvc.node')
);
)
try {
if (localFileExisted) {
nativeBinding = require('./refclone.win32-arm64-msvc.node');
nativeBinding = require('./refclone.win32-arm64-msvc.node')
} else {
nativeBinding = require('@refclone/refclone-win32-arm64-msvc');
nativeBinding = require('@refclone/refclone-win32-arm64-msvc')
}
} catch (e) {
loadError = e;
loadError = e
}
break;
break
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`);
throw new Error(`Unsupported architecture on Windows: ${arch}`)
}
break;
break
case 'darwin':
localFileExisted = existsSync(
join(__dirname, 'refclone.darwin-universal.node')
);
localFileExisted = existsSync(join(__dirname, 'refclone.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./refclone.darwin-universal.node');
nativeBinding = require('./refclone.darwin-universal.node')
} else {
nativeBinding = require('@refclone/refclone-darwin-universal');
nativeBinding = require('@refclone/refclone-darwin-universal')
}
break;
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(
join(__dirname, 'refclone.darwin-x64.node')
);
localFileExisted = existsSync(join(__dirname, 'refclone.darwin-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./refclone.darwin-x64.node');
nativeBinding = require('./refclone.darwin-x64.node')
} else {
nativeBinding = require('@refclone/refclone-darwin-x64');
nativeBinding = require('@refclone/refclone-darwin-x64')
}
} catch (e) {
loadError = e;
loadError = e
}
break;
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'refclone.darwin-arm64.node')
);
)
try {
if (localFileExisted) {
nativeBinding = require('./refclone.darwin-arm64.node');
nativeBinding = require('./refclone.darwin-arm64.node')
} else {
nativeBinding = require('@refclone/refclone-darwin-arm64');
nativeBinding = require('@refclone/refclone-darwin-arm64')
}
} catch (e) {
loadError = e;
loadError = e
}
break;
break
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`);
throw new Error(`Unsupported architecture on macOS: ${arch}`)
}
break;
break
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
}
localFileExisted = existsSync(join(__dirname, 'refclone.freebsd-x64.node'));
localFileExisted = existsSync(join(__dirname, 'refclone.freebsd-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./refclone.freebsd-x64.node');
nativeBinding = require('./refclone.freebsd-x64.node')
} else {
nativeBinding = require('@refclone/refclone-freebsd-x64');
nativeBinding = require('@refclone/refclone-freebsd-x64')
}
} catch (e) {
loadError = e;
loadError = e
}
break;
break
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'refclone.linux-x64-musl.node')
);
)
try {
if (localFileExisted) {
nativeBinding = require('./refclone.linux-x64-musl.node');
nativeBinding = require('./refclone.linux-x64-musl.node')
} else {
nativeBinding = require('@refclone/refclone-linux-x64-musl');
nativeBinding = require('@refclone/refclone-linux-x64-musl')
}
} catch (e) {
loadError = e;
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'refclone.linux-x64-gnu.node')
);
)
try {
if (localFileExisted) {
nativeBinding = require('./refclone.linux-x64-gnu.node');
nativeBinding = require('./refclone.linux-x64-gnu.node')
} else {
nativeBinding = require('@refclone/refclone-linux-x64-gnu');
nativeBinding = require('@refclone/refclone-linux-x64-gnu')
}
} catch (e) {
loadError = e;
loadError = e
}
}
break;
break
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'refclone.linux-arm64-musl.node')
);
)
try {
if (localFileExisted) {
nativeBinding = require('./refclone.linux-arm64-musl.node');
nativeBinding = require('./refclone.linux-arm64-musl.node')
} else {
nativeBinding = require('@refclone/refclone-linux-arm64-musl');
nativeBinding = require('@refclone/refclone-linux-arm64-musl')
}
} catch (e) {
loadError = e;
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'refclone.linux-arm64-gnu.node')
);
)
try {
if (localFileExisted) {
nativeBinding = require('./refclone.linux-arm64-gnu.node');
nativeBinding = require('./refclone.linux-arm64-gnu.node')
} else {
nativeBinding = require('@refclone/refclone-linux-arm64-gnu');
nativeBinding = require('@refclone/refclone-linux-arm64-gnu')
}
} catch (e) {
loadError = e;
loadError = e
}
}
break;
break
case 'arm':
localFileExisted = existsSync(
join(__dirname, 'refclone.linux-arm-gnueabihf.node')
);
)
try {
if (localFileExisted) {
nativeBinding = require('./refclone.linux-arm-gnueabihf.node');
nativeBinding = require('./refclone.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('@refclone/refclone-linux-arm-gnueabihf');
nativeBinding = require('@refclone/refclone-linux-arm-gnueabihf')
}
} catch (e) {
loadError = e;
loadError = e
}
break;
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`);
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
break;
break
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
}

if (!nativeBinding) {
if (loadError) {
throw loadError;
throw loadError
}
throw new Error(`Failed to load native binding`);
throw new Error(`Failed to load native binding`)
}

const { reflinkFile, reflinkFileSync } = nativeBinding;
const { reflinkFile, reflinkFileSync } = nativeBinding

module.exports.reflinkFile = reflinkFile;
module.exports.reflinkFileSync = reflinkFileSync;
module.exports.reflinkFile = reflinkFile
module.exports.reflinkFileSync = reflinkFileSync
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@refclone/refclone-darwin-arm64",
"version": "0.1.3",
"version": "0.1.4",
"repository": {
"url": "https://github.com/nachoaldamav/cross-reflink.git",
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@refclone/refclone-darwin-x64",
"version": "0.1.3",
"version": "0.1.4",
"repository": {
"url": "https://github.com/nachoaldamav/cross-reflink.git",
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@refclone/refclone-linux-arm64-gnu",
"version": "0.1.3",
"version": "0.1.4",
"repository": {
"url": "https://github.com/nachoaldamav/cross-reflink.git",
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@refclone/refclone-linux-arm64-musl",
"version": "0.1.3",
"version": "0.1.4",
"repository": {
"url": "https://github.com/nachoaldamav/cross-reflink.git",
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@refclone/refclone-linux-x64-gnu",
"version": "0.1.3",
"version": "0.1.4",
"repository": {
"url": "https://github.com/nachoaldamav/cross-reflink.git",
"type": "git",
Expand Down
Loading

0 comments on commit 3362016

Please sign in to comment.