Skip to content

Commit

Permalink
chore: update node-pty-prebuilt-multiarch to 0.11.10
Browse files Browse the repository at this point in the history
Apparently the NPM package name changed; I opened an issue upstream to clarify
because the github repo still links to the old NPM repo.

homebridge/node-pty-prebuilt-multiarch#31
  • Loading branch information
stefreak committed Nov 7, 2023
1 parent 14dd9e4 commit d7fb8c1
Show file tree
Hide file tree
Showing 4 changed files with 5,475 additions and 5,629 deletions.
108 changes: 69 additions & 39 deletions cli/src/build-pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,27 +335,8 @@ async function buildBinaries(args: string[]) {
console.log(chalk.green(` ✓ Using cached node ${spec.node} for ${targetName} at ${nodeArchiveFilename}`))
} else {
console.log(chalk.cyan(`Downloading node ${spec.node} for ${targetName} from ${spec.url}`))
const response = await fetch(spec.url)

if (!response.body) {
throw new Error(`No response body for ${spec.url}`)
}

const body = Readable.fromWeb(response.body)

const hash = body.pipe(createHash("sha256"))

const writeStream = createWriteStream(nodeArchiveFilename)
await finished(body.pipe(writeStream))

console.log(chalk.green(` ✓ Downloaded node ${spec.node} for ${targetName}`))

const sha256 = hash.digest("hex")

if (sha256 !== spec.checksum) {
throw new Error(`Checksum mismatch for ${spec.url}! Expected ${spec.checksum} but got ${sha256}`)
}
console.log(chalk.green(` ✓ Verified checksum for ${targetName}`))
await downloadFromWeb({ url: spec.url, checksum: spec.checksum, targetPath: nodeArchiveFilename })
console.log(chalk.green(` ✓ Downloaded node ${spec.node} and verified checksum for ${targetName}`))
}

console.log(chalk.cyan(`Extracting node ${spec.node} for ${targetName}`))
Expand Down Expand Up @@ -475,34 +456,54 @@ async function pkgCommon({ targetName, spec }: { targetName: string; spec: Targe
console.log(` - ${targetName} -> node-pty`)
const abi = getAbi(spec.node, "node")

if (spec.nodeBinaryPlatform === "win32") {
const tmpDir = await makeTempDir()
// Seriously, this is so much easier than anything more native...
await exec(
"sh",
[
"-c",
dedent`
set -e
curl -s -L https://github.com/oznu/node-pty-prebuilt-multiarch/releases/download/v0.10.1-pre.5/node-pty-prebuilt-multiarch-v0.10.1-pre.5-node-v108-win32-x64.tar.gz | tar -xzv -C .
cp build/Release/* '${targetPath}'
`,
],
{ cwd: tmpDir.path }
)

await tmpDir.cleanup()
} else {
if (spec.nodeBinaryPlatform === "linux") {
const filename = spec.os === "alpine" ? `node.abi${abi}.musl.node` : `node.abi${abi}.node`
const abiPath = resolve(
GARDEN_CORE_ROOT,
"node_modules",
"@homebridge",
"node-pty-prebuilt-multiarch",
"prebuilds",
`${spec.nodeBinaryPlatform}-${spec.arch}`,
filename
)
await copy(abiPath, resolve(targetPath, "pty.node"))
} else {
const tmpDir = await makeTempDir()
const ptyArchiveFilename = resolve(tmpDir.path, "pty.tar.gz")

const checksums = {
"120-win32-x64": "344921e4036277b1edcbc01d2c7b4a22a3e0a85c911bdf9255fe1168e8e439b6",
"120-darwin-x64": "c406d1ba59ffa750c8a456ae22a75a221eaee2579f3b6f54296e72a5d79c6853",
"120-darwin-arm64": "2818fd6a31dd5889fa9612ceb7ae5ebe5c2422964a4a908d1f05aec120ebccaf",
}

const key = `${abi}-${spec.nodeBinaryPlatform}-${spec.arch}`
const checksum = checksums[key]

if (!checksum) {
throw new Error(
`Missing checksum for ${key}. Needs to be updated when changing the NodeJS version or pty version.`
)
}

await downloadFromWeb({
url: `https://github.com/homebridge/node-pty-prebuilt-multiarch/releases/download/v0.11.8/node-pty-prebuilt-multiarch-v0.11.8-node-v${abi}-${spec.nodeBinaryPlatform}-${spec.arch}.tar.gz`,
checksum,
targetPath: ptyArchiveFilename,
})

// extract
const extractStream = tar.x({
C: targetPath,
// The stripping removes the outer directories, so we end up with the files directly in the target directory.
strip: 2,
filter: (path) => {
return path.startsWith(`/build/Release/`)
},
})
await finished(createReadStream(ptyArchiveFilename).pipe(extractStream))
await tmpDir.cleanup()
}

if (spec.os === "macos") {
Expand Down Expand Up @@ -566,3 +567,32 @@ if (process.argv[1] === modulePath) {
process.exit(1)
})
}

async function downloadFromWeb({
url: downloadUrl,
targetPath,
checksum,
}: {
url: string
targetPath: string
checksum: string
}) {
const response = await fetch(downloadUrl)

if (!response.body) {
throw new Error(`No response body for ${downloadUrl}`)
}

const body = Readable.fromWeb(response.body)

const hash = body.pipe(createHash("sha256"))

const writeStream = createWriteStream(targetPath)
await finished(body.pipe(writeStream))

const sha256 = hash.digest("hex")

if (sha256 !== checksum) {
throw new Error(`Checksum mismatch for ${downloadUrl}! Expected ${checksum} but got ${sha256}`)
}
}
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"moment": "^2.29.4",
"node-fetch": "^3.3.2",
"node-forge": "^1.3.1",
"node-pty-prebuilt-multiarch": "^0.10.1-pre.5",
"@homebridge/node-pty-prebuilt-multiarch": "^0.11.10",
"normalize-path": "^3.0.0",
"normalize-url": "^5.3.1",
"open": "^9.1.0",
Expand Down
4 changes: 2 additions & 2 deletions core/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { Server } from "http"
import chalk from "chalk"
import Koa from "koa"
import Router from "koa-router"
import type PTY from "node-pty-prebuilt-multiarch"
import websockify from "koa-websocket"
import bodyParser from "koa-bodyparser"
import getPort, { portNumbers } from "get-port"
Expand Down Expand Up @@ -50,7 +49,8 @@ import { omitUndefined } from "../util/objects.js"
import { createServer } from "http"
import { defaultServerPort } from "../commands/serve.js"

import pty from "node-pty-prebuilt-multiarch"
import type PTY from "@homebridge/node-pty-prebuilt-multiarch"
import pty from "@homebridge/node-pty-prebuilt-multiarch"

const skipLogsForCommands = ["autocomplete"]

Expand Down
Loading

0 comments on commit d7fb8c1

Please sign in to comment.