@appsignal/nodejs-ext
Advanced tools
Comparing version
{ | ||
"name": "@appsignal/nodejs-ext", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"main": "dist/index", | ||
@@ -9,5 +9,6 @@ "types": "dist/index", | ||
"node-addon-api": "^3.0.1", | ||
"node-gyp": "^7.0.0" | ||
"node-gyp": "^7.1.0" | ||
}, | ||
"scripts": { | ||
"install": "node scripts/extension.js && node-gyp rebuild", | ||
"build": "tsc -p tsconfig.json", | ||
@@ -18,4 +19,3 @@ "build:ext": "node-gyp rebuild", | ||
"link:npm": "npm link", | ||
"link:yarn": "yarn link", | ||
"install": "node scripts/extension.js && node-gyp rebuild" | ||
"link:yarn": "yarn link" | ||
}, | ||
@@ -37,3 +37,3 @@ "os": [ | ||
}, | ||
"gitHead": "28fb7d1c3458d77a3804c385d349b1b7fa2e0198" | ||
"gitHead": "a67c186b2855477400f4c70987684f4e23e02762" | ||
} |
@@ -17,3 +17,7 @@ #!/usr/bin/env node | ||
const { createReport } = require("./report") | ||
const { | ||
createReport, | ||
createBuildReport, | ||
createDownloadReport | ||
} = require("./report") | ||
@@ -64,5 +68,19 @@ const EXT_PATH = path.join(__dirname, "/../ext/") | ||
function getMetadataForTarget(report) { | ||
const { architecture, target, muslOverride } = report.build | ||
function dumpReport(report) { | ||
return new Promise(resolve => { | ||
fs.writeFile( | ||
"/tmp/appsignal-install-report.json", | ||
JSON.stringify(report, null, 2), | ||
() => { | ||
return resolve() | ||
} | ||
) | ||
}) | ||
} | ||
function getMetadataForTarget({ | ||
architecture, | ||
target, | ||
musl_override: muslOverride | ||
}) { | ||
const triple = [ | ||
@@ -79,4 +97,2 @@ architecture === "x64" ? "x86_64" : "i686", | ||
;(function () { | ||
const report = createReport() | ||
if (hasLocalBuild()) { | ||
@@ -88,3 +104,3 @@ // check for a local build (dev only) | ||
if (!hasSupportedArchitecture(report)) { | ||
if (!hasSupportedArchitecture(process.arch)) { | ||
console.error( | ||
@@ -99,3 +115,3 @@ `AppSignal currently does not support your system architecture | ||
if (!hasSupportedOs(report)) { | ||
if (!hasSupportedOs(process.platform)) { | ||
console.error( | ||
@@ -110,4 +126,7 @@ `AppSignal currently does not support your operating system (${process.platform}). | ||
const report = createReport() | ||
report.build = createBuildReport({}) | ||
// try and get one from the CDN | ||
const metadata = getMetadataForTarget(report) | ||
const metadata = getMetadataForTarget(report.build) | ||
const filename = metadata.downloadUrl.split("/")[4] | ||
@@ -117,15 +136,33 @@ const outputPath = path.join(EXT_PATH, filename) | ||
return download(metadata.downloadUrl, outputPath) | ||
.then(filepath => { | ||
return verify(filepath, metadata.checksum).then(() => extract(filepath)) | ||
}) | ||
.then(filepath => | ||
verify(filepath, metadata.checksum).then(() => extract(filepath)) | ||
) | ||
.then(() => { | ||
// once extracted, we can then hand off to node-gyp for building | ||
// @TODO: add cleanup step | ||
console.log("The agent has installed successfully!") | ||
process.exit(0) | ||
console.log("The agent has downloaded successfully! Building...") | ||
report.download = createDownloadReport({ | ||
verified: true, | ||
downloadUrl: metadata.downloadUrl | ||
}) | ||
report.result.status = "success" | ||
return dumpReport(report).then(() => { | ||
process.exit(0) | ||
}) | ||
}) | ||
.catch(error => { | ||
console.error(error) | ||
process.exit(1) | ||
report.download = createDownloadReport({ | ||
verified: false, | ||
downloadUrl: metadata.downloadUrl | ||
}) | ||
return dumpReport(report).then(() => { | ||
process.exit(1) | ||
}) | ||
}) | ||
})() |
@@ -25,7 +25,5 @@ const path = require("path") | ||
*/ | ||
function hasSupportedArchitecture(report) { | ||
function hasSupportedArchitecture(arch) { | ||
// 'x32' and 'x64' supported | ||
return ( | ||
report.build.architecture === "x32" || report.build.architecture === "x64" | ||
) | ||
return arch === "x32" || arch === "x64" | ||
} | ||
@@ -40,8 +38,4 @@ | ||
*/ | ||
function hasSupportedOs(report) { | ||
return ( | ||
report.build.target === "darwin" || | ||
report.build.target === "freebsd" || | ||
report.build.target === "linux" | ||
) | ||
function hasSupportedOs(os) { | ||
return os === "darwin" || os === "freebsd" || os === "linux" | ||
} | ||
@@ -48,0 +42,0 @@ |
const path = require("path") | ||
const { AGENT_VERSION } = require("./extension/constants") | ||
const { hasMusl } = require("./extension/helpers") | ||
@@ -6,16 +8,12 @@ | ||
return { | ||
result: { status: "incomplete" }, | ||
language: { | ||
name: "nodejs", | ||
version: process.versions["node"] | ||
version: process.versions["node"], | ||
implementation: "nodejs" | ||
}, | ||
build: { | ||
time: new Date().toISOString(), | ||
packagePath: path.join(__dirname, "/../ext/"), | ||
architecture: process.arch, | ||
target: process.platform, | ||
muslOverride: (process.env["APPSIGNAL_BUILD_FOR_MUSL"] === "true") || hasMusl(), | ||
libraryType: "static" | ||
}, | ||
download: {}, | ||
build: {}, | ||
host: { | ||
rootUser: process.getuid && process.getuid() === 0, | ||
root_user: process.getuid && process.getuid() === 0, | ||
dependencies: {} | ||
@@ -26,2 +24,30 @@ } | ||
exports.createReport = createReport | ||
function createBuildReport({ isLocalBuild = false }) { | ||
return { | ||
time: new Date().toISOString(), | ||
package_path: path.join(__dirname, "/../ext/"), | ||
architecture: process.arch, | ||
target: process.platform, | ||
musl_override: | ||
process.env["APPSIGNAL_BUILD_FOR_MUSL"] === "true" || hasMusl(), | ||
library_type: "static", | ||
dependencies: {}, | ||
flags: {}, | ||
source: isLocalBuild ? "local" : "remote", | ||
agent_version: AGENT_VERSION | ||
} | ||
} | ||
function createDownloadReport({ verified = false, downloadUrl: download_url }) { | ||
return { | ||
checksum: verified ? "verified" : "unverified", | ||
http_proxy: null, | ||
download_url | ||
} | ||
} | ||
module.exports = { | ||
createReport, | ||
createBuildReport, | ||
createDownloadReport | ||
} |
31958
3.79%276
21.59%Updated