Skip to content

Commit

Permalink
install時にビルドが走るように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
Kawabuchi Kota(川渕 皓太)A authored and ota-meshi committed Dec 13, 2022
1 parent d7e6cf0 commit 850f135
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 114 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ yarn.lock
*.node
*.tgz
.yarn
test.js
__test__
renovate.json
234 changes: 121 additions & 113 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,241 +1,249 @@
const { existsSync, readFileSync } = require('fs')
const { join } = require('path')
const { existsSync, readFileSync } = require("fs");
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') {
if (!process.report || typeof process.report.getReport !== "function") {
try {
return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
return readFileSync("/usr/bin/ldd", "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':
case "android":
switch (arch) {
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'uroborosql-fmt-napi.android-arm64.node'))
case "arm64":
localFileExisted = existsSync(
join(__dirname, "uroborosql-fmt-napi.android-arm64.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.android-arm64.node')
nativeBinding = require("./uroborosql-fmt-napi.android-arm64.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-android-arm64')
nativeBinding = require("uroborosql-fmt-napi-android-arm64");
}
} catch (e) {
loadError = e
loadError = e;
}
break
case 'arm':
localFileExisted = existsSync(join(__dirname, 'uroborosql-fmt-napi.android-arm-eabi.node'))
break;
case "arm":
localFileExisted = existsSync(
join(__dirname, "uroborosql-fmt-napi.android-arm-eabi.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.android-arm-eabi.node')
nativeBinding = require("./uroborosql-fmt-napi.android-arm-eabi.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-android-arm-eabi')
nativeBinding = require("uroborosql-fmt-napi-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
case 'win32':
break;
case "win32":
switch (arch) {
case 'x64':
case "x64":
localFileExisted = existsSync(
join(__dirname, 'uroborosql-fmt-napi.win32-x64-msvc.node')
)
join(__dirname, "uroborosql-fmt-napi.win32-x64-gnu.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.win32-x64-msvc.node')
nativeBinding = require("./uroborosql-fmt-napi.win32-x64-gnu.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-win32-x64-msvc')
nativeBinding = require("uroborosql-fmt-napi-win32-x64-gnu");
}
} catch (e) {
loadError = e
loadError = e;
}
break
case 'ia32':
break;
case "ia32":
localFileExisted = existsSync(
join(__dirname, 'uroborosql-fmt-napi.win32-ia32-msvc.node')
)
join(__dirname, "uroborosql-fmt-napi.win32-ia32-msvc.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.win32-ia32-msvc.node')
nativeBinding = require("./uroborosql-fmt-napi.win32-ia32-msvc.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-win32-ia32-msvc')
nativeBinding = require("uroborosql-fmt-napi-win32-ia32-msvc");
}
} catch (e) {
loadError = e
loadError = e;
}
break
case 'arm64':
break;
case "arm64":
localFileExisted = existsSync(
join(__dirname, 'uroborosql-fmt-napi.win32-arm64-msvc.node')
)
join(__dirname, "uroborosql-fmt-napi.win32-arm64-msvc.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.win32-arm64-msvc.node')
nativeBinding = require("./uroborosql-fmt-napi.win32-arm64-msvc.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-win32-arm64-msvc')
nativeBinding = require("uroborosql-fmt-napi-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
case 'darwin':
break;
case "darwin":
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'uroborosql-fmt-napi.darwin-x64.node'))
case "x64":
localFileExisted = existsSync(
join(__dirname, "uroborosql-fmt-napi.darwin-x64.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.darwin-x64.node')
nativeBinding = require("./uroborosql-fmt-napi.darwin-x64.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-darwin-x64')
nativeBinding = require("uroborosql-fmt-napi-darwin-x64");
}
} catch (e) {
loadError = e
loadError = e;
}
break
case 'arm64':
break;
case "arm64":
localFileExisted = existsSync(
join(__dirname, 'uroborosql-fmt-napi.darwin-arm64.node')
)
join(__dirname, "uroborosql-fmt-napi.darwin-arm64.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.darwin-arm64.node')
nativeBinding = require("./uroborosql-fmt-napi.darwin-arm64.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-darwin-arm64')
nativeBinding = require("uroborosql-fmt-napi-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
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
break;
case "freebsd":
if (arch !== "x64") {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
}
localFileExisted = existsSync(join(__dirname, 'uroborosql-fmt-napi.freebsd-x64.node'))
localFileExisted = existsSync(
join(__dirname, "uroborosql-fmt-napi.freebsd-x64.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.freebsd-x64.node')
nativeBinding = require("./uroborosql-fmt-napi.freebsd-x64.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-freebsd-x64')
nativeBinding = require("uroborosql-fmt-napi-freebsd-x64");
}
} catch (e) {
loadError = e
loadError = e;
}
break
case 'linux':
break;
case "linux":
switch (arch) {
case 'x64':
case "x64":
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'uroborosql-fmt-napi.linux-x64-musl.node')
)
join(__dirname, "uroborosql-fmt-napi.linux-x64-musl.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.linux-x64-musl.node')
nativeBinding = require("./uroborosql-fmt-napi.linux-x64-musl.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-linux-x64-musl')
nativeBinding = require("uroborosql-fmt-napi-linux-x64-musl");
}
} catch (e) {
loadError = e
loadError = e;
}
} else {
localFileExisted = existsSync(
join(__dirname, 'uroborosql-fmt-napi.linux-x64-gnu.node')
)
join(__dirname, "uroborosql-fmt-napi.linux-x64-gnu.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.linux-x64-gnu.node')
nativeBinding = require("./uroborosql-fmt-napi.linux-x64-gnu.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-linux-x64-gnu')
nativeBinding = require("uroborosql-fmt-napi-linux-x64-gnu");
}
} catch (e) {
loadError = e
loadError = e;
}
}
break
case 'arm64':
break;
case "arm64":
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'uroborosql-fmt-napi.linux-arm64-musl.node')
)
join(__dirname, "uroborosql-fmt-napi.linux-arm64-musl.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.linux-arm64-musl.node')
nativeBinding = require("./uroborosql-fmt-napi.linux-arm64-musl.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-linux-arm64-musl')
nativeBinding = require("uroborosql-fmt-napi-linux-arm64-musl");
}
} catch (e) {
loadError = e
loadError = e;
}
} else {
localFileExisted = existsSync(
join(__dirname, 'uroborosql-fmt-napi.linux-arm64-gnu.node')
)
join(__dirname, "uroborosql-fmt-napi.linux-arm64-gnu.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.linux-arm64-gnu.node')
nativeBinding = require("./uroborosql-fmt-napi.linux-arm64-gnu.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-linux-arm64-gnu')
nativeBinding = require("uroborosql-fmt-napi-linux-arm64-gnu");
}
} catch (e) {
loadError = e
loadError = e;
}
}
break
case 'arm':
break;
case "arm":
localFileExisted = existsSync(
join(__dirname, 'uroborosql-fmt-napi.linux-arm-gnueabihf.node')
)
join(__dirname, "uroborosql-fmt-napi.linux-arm-gnueabihf.node")
);
try {
if (localFileExisted) {
nativeBinding = require('./uroborosql-fmt-napi.linux-arm-gnueabihf.node')
nativeBinding = require("./uroborosql-fmt-napi.linux-arm-gnueabihf.node");
} else {
nativeBinding = require('uroborosql-fmt-napi-linux-arm-gnueabihf')
nativeBinding = require("uroborosql-fmt-napi-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 { runfmt } = nativeBinding
const { runfmt } = nativeBinding;

module.exports.runfmt = runfmt
module.exports.runfmt = runfmt;
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"@napi-rs/cli": "^2.12.0",
"ava": "^4.3.3"
},
"dependencies": {
"@napi-rs/cli": "^2.12.0"
},
"ava": {
"timeout": "3m"
},
Expand All @@ -20,10 +23,11 @@
},
"scripts": {
"artifacts": "napi artifacts",
"postinstall": "npm run build",
"build": "napi build --platform --release",
"build:debug": "napi build --platform",
"prepublishOnly": "napi prepublish -t npm",
"test": "ava",
"version": "napi version"
}
}
}

0 comments on commit 850f135

Please sign in to comment.