@reflink/reflink
Advanced tools
Comparing version 0.1.15 to 0.1.16-canary.bf50305
@@ -1,7 +0,14 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/* auto-generated by NAPI-RS */ | ||
export function reflinkFile(src: string, dst: string): Promise<number> | ||
export function reflinkFileSync(src: string, dst: string): number | ||
/** | ||
* Create a reflink asynchronously. | ||
* @param {String} src Source of the reflink. | ||
* @param {String} dst Target of the reflink. | ||
* @returns {Promise.<number>} | ||
*/ | ||
export function reflinkFile(src: string, dst: string): Promise<number>; | ||
/** | ||
* Create a reflink asynchronously. | ||
* @param {String} src Source of the reflink. | ||
* @param {String} dst Target of the reflink. | ||
* @returns {number} | ||
*/ | ||
export function reflinkFileSync(src: string, dst: string): number; |
293
index.js
@@ -1,258 +0,51 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/* prettier-ignore */ | ||
//@ts-check | ||
const binding = require('./binding'); | ||
/* auto-generated by NAPI-RS */ | ||
/** | ||
* Throw a reflink error. | ||
* @param {binding.ReflinkError} reflinkError Error properties. | ||
* @returns {Error & binding.ReflinkError} | ||
*/ | ||
function createReflinkError(reflinkError) { | ||
const error = new Error(reflinkError.message) | ||
return Object.assign(error, { | ||
path: reflinkError.path, | ||
dest: reflinkError.dest, | ||
code: reflinkError.code, | ||
errno: reflinkError.errno, | ||
}); | ||
} | ||
const { existsSync, readFileSync } = require('fs') | ||
const { join } = require('path') | ||
const { platform, arch } = process | ||
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') | ||
} catch (e) { | ||
return true | ||
} | ||
/** | ||
* Either throw the reflink error or return the number. | ||
* @param {number | binding.ReflinkError} result Result of the binding function. | ||
* @returns {number} | ||
*/ | ||
function handleReflinkResult(result) { | ||
if (typeof result === 'number') { | ||
return result; | ||
} else { | ||
const { glibcVersionRuntime } = process.report.getReport().header | ||
return !glibcVersionRuntime | ||
throw createReflinkError(result); | ||
} | ||
} | ||
switch (platform) { | ||
case 'android': | ||
switch (arch) { | ||
case 'arm64': | ||
localFileExisted = existsSync(join(__dirname, 'reflink.android-arm64.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.android-arm64.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-android-arm64') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'arm': | ||
localFileExisted = existsSync(join(__dirname, 'reflink.android-arm-eabi.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.android-arm-eabi.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-android-arm-eabi') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
default: | ||
throw new Error(`Unsupported architecture on Android ${arch}`) | ||
} | ||
break | ||
case 'win32': | ||
switch (arch) { | ||
case 'x64': | ||
localFileExisted = existsSync( | ||
join(__dirname, 'reflink.win32-x64-msvc.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.win32-x64-msvc.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-win32-x64-msvc') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'ia32': | ||
localFileExisted = existsSync( | ||
join(__dirname, 'reflink.win32-ia32-msvc.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.win32-ia32-msvc.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-win32-ia32-msvc') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'arm64': | ||
localFileExisted = existsSync( | ||
join(__dirname, 'reflink.win32-arm64-msvc.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.win32-arm64-msvc.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-win32-arm64-msvc') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
default: | ||
throw new Error(`Unsupported architecture on Windows: ${arch}`) | ||
} | ||
break | ||
case 'darwin': | ||
localFileExisted = existsSync(join(__dirname, 'reflink.darwin-universal.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.darwin-universal.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-darwin-universal') | ||
} | ||
break | ||
} catch {} | ||
switch (arch) { | ||
case 'x64': | ||
localFileExisted = existsSync(join(__dirname, 'reflink.darwin-x64.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.darwin-x64.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-darwin-x64') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'arm64': | ||
localFileExisted = existsSync( | ||
join(__dirname, 'reflink.darwin-arm64.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.darwin-arm64.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-darwin-arm64') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
default: | ||
throw new Error(`Unsupported architecture on macOS: ${arch}`) | ||
} | ||
break | ||
case 'freebsd': | ||
if (arch !== 'x64') { | ||
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`) | ||
} | ||
localFileExisted = existsSync(join(__dirname, 'reflink.freebsd-x64.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.freebsd-x64.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-freebsd-x64') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'linux': | ||
switch (arch) { | ||
case 'x64': | ||
if (isMusl()) { | ||
localFileExisted = existsSync( | ||
join(__dirname, 'reflink.linux-x64-musl.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.linux-x64-musl.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-linux-x64-musl') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
} else { | ||
localFileExisted = existsSync( | ||
join(__dirname, 'reflink.linux-x64-gnu.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.linux-x64-gnu.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-linux-x64-gnu') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
} | ||
break | ||
case 'arm64': | ||
if (isMusl()) { | ||
localFileExisted = existsSync( | ||
join(__dirname, 'reflink.linux-arm64-musl.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.linux-arm64-musl.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-linux-arm64-musl') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
} else { | ||
localFileExisted = existsSync( | ||
join(__dirname, 'reflink.linux-arm64-gnu.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.linux-arm64-gnu.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-linux-arm64-gnu') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
} | ||
break | ||
case 'arm': | ||
localFileExisted = existsSync( | ||
join(__dirname, 'reflink.linux-arm-gnueabihf.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./reflink.linux-arm-gnueabihf.node') | ||
} else { | ||
nativeBinding = require('@reflink/reflink-linux-arm-gnueabihf') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
default: | ||
throw new Error(`Unsupported architecture on Linux: ${arch}`) | ||
} | ||
break | ||
default: | ||
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) | ||
} | ||
/** | ||
* Create a reflink asynchronously. | ||
* @param {String} src Source of the reflink. | ||
* @param {String} dst Target of the reflink. | ||
* @returns {Promise.<number>} | ||
*/ | ||
const reflinkFile = (src, dst) => binding.reflinkFile(src, dst).then(handleReflinkResult); | ||
if (!nativeBinding) { | ||
if (loadError) { | ||
throw loadError | ||
} | ||
throw new Error(`Failed to load native binding`) | ||
} | ||
/** | ||
* Create a reflink asynchronously. | ||
* @param {String} src Source of the reflink. | ||
* @param {String} dst Target of the reflink. | ||
* @returns {number} | ||
*/ | ||
const reflinkFileSync = (src, dst) => handleReflinkResult(binding.reflinkFileSync(src, dst)); | ||
const { reflinkFile, reflinkFileSync } = nativeBinding | ||
module.exports.reflinkFile = reflinkFile | ||
module.exports.reflinkFileSync = reflinkFileSync | ||
module.exports = { | ||
reflinkFile, | ||
reflinkFileSync, | ||
}; |
{ | ||
"name": "@reflink/reflink", | ||
"version": "0.1.15", | ||
"version": "0.1.16-canary.bf50305", | ||
"main": "index.js", | ||
@@ -23,2 +23,4 @@ "types": "index.d.ts", | ||
"files": [ | ||
"binding.js", | ||
"binding.d.ts", | ||
"index.js", | ||
@@ -41,7 +43,8 @@ "index.d.ts" | ||
"artifacts": "napi artifacts", | ||
"build": "napi build --platform --release", | ||
"build:debug": "napi build --platform", | ||
"build": "pnpm gen-dts && napi build --js binding.js --dts binding.d.ts --platform --release", | ||
"build:debug": "pnpm gen-dts && napi build --js binding.js --dts binding.d.ts --platform", | ||
"gen-dts": "tsc --checkJs index.js --declaration --emitDeclarationOnly", | ||
"prepublishOnly": "napi prepublish -t npm", | ||
"pretest": "pnpm build", | ||
"test": "cargo t && vitest", | ||
"test": "cargo t && vitest && rimraf -g __reflink-tests-*", | ||
"bench": "node benchmark.mjs", | ||
@@ -51,13 +54,13 @@ "universal": "napi universal", | ||
}, | ||
"packageManager": "pnpm@8.10.0", | ||
"packageManager": "pnpm@9.12.3", | ||
"optionalDependencies": { | ||
"@reflink/reflink-win32-x64-msvc": "0.1.15", | ||
"@reflink/reflink-darwin-x64": "0.1.15", | ||
"@reflink/reflink-linux-x64-gnu": "0.1.15", | ||
"@reflink/reflink-darwin-arm64": "0.1.15", | ||
"@reflink/reflink-linux-arm64-gnu": "0.1.15", | ||
"@reflink/reflink-linux-arm64-musl": "0.1.15", | ||
"@reflink/reflink-win32-arm64-msvc": "0.1.15", | ||
"@reflink/reflink-linux-x64-musl": "0.1.15" | ||
"@reflink/reflink-win32-x64-msvc": "0.1.16-canary.bf50305", | ||
"@reflink/reflink-darwin-x64": "0.1.16-canary.bf50305", | ||
"@reflink/reflink-linux-x64-gnu": "0.1.16-canary.bf50305", | ||
"@reflink/reflink-darwin-arm64": "0.1.16-canary.bf50305", | ||
"@reflink/reflink-linux-arm64-gnu": "0.1.16-canary.bf50305", | ||
"@reflink/reflink-linux-arm64-musl": "0.1.16-canary.bf50305", | ||
"@reflink/reflink-win32-arm64-msvc": "0.1.16-canary.bf50305", | ||
"@reflink/reflink-linux-x64-musl": "0.1.16-canary.bf50305" | ||
} | ||
} |
@@ -0,0 +0,0 @@ # @reflink/reflink |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13034
6
324
2