Skip to content

Commit b6ff97b

Browse files
feat: use neos code from #634
1 parent d49023e commit b6ff97b

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

npm/gen-root.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ async function genServerPackage(buildDefinitions: string[]) {
6363
await fs.mkdir(scriptsPath, { recursive: true })
6464
await fs.mkdir(directoryPath, { recursive: true })
6565

66+
const postInstallScript = await fs.readFile(resolve(__dirname, "./post-install.js"), "utf8")
6667
const preInstallScript = await fs.readFile(resolve(__dirname, "./pre-install.js"), "utf8")
6768

69+
const postInstallScriptContent = `const version = "${packageVersion}";\n${postInstallScript}`
6870
const preInstallScriptContent = `const optionalDependencies = ${JSON.stringify(optionalDependencies)};\n${preInstallScript}`
6971

7072

73+
await fs.writeFile(resolve(scriptsPath, "post-install.js"), postInstallScriptContent, "utf8")
7174
await fs.writeFile(resolve(scriptsPath, "pre-install.js"), preInstallScriptContent, "utf8")
7275
await fs.writeFile(resolve(directoryPath, "./package.json"), JSON.stringify(tailcallPackage, null, 2), "utf8")
7376

npm/post-install.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// @ts-check
2+
// @ts-ignore
3+
import { familySync, GLIBC, MUSL } from "detect-libc"
4+
import { exec } from 'child_process'
5+
import util from 'util'
6+
7+
const execa = util.promisify(exec)
8+
const platform = process.platform
9+
const arch = process.arch
10+
11+
const libcFamily = familySync()
12+
let libc
13+
if (platform === "win32") {
14+
libc = "-msvc"
15+
} else {
16+
libc = libcFamily === GLIBC ? "-gnu" : libcFamily === MUSL ? "-musl" : ""
17+
}
18+
19+
const pkg = `@tailcallhq/core-${platform}-${arch}${libc}`
20+
21+
try {
22+
// @ts-ignore
23+
const { stdout, stderr } = await execa(`npm install ${pkg}@${version} --no-save`)
24+
stderr ? console.log(stderr) : console.log(`Successfully installed optional dependency: ${pkg}`, stdout)
25+
} catch (error) {
26+
console.error(`Failed to install optional dependency: ${pkg}`, error.stderr)
27+
}

npm/pre-install.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const os = process.platform
22
const arch = process.arch
3-
const libc = process.libc
43

5-
const dependency = libc ? Object.keys(optionalDependencies).find((name) => name.includes(`${os}-${arch}-${libc}`)) : Object.keys(optionalDependencies).find((name) => name.includes(`${os}-${arch}`))
4+
const dependency = Object.keys(optionalDependencies).find((name) => name.includes(`${os}-${arch}`))
65
if (!dependency) {
76
const redColor = "\x1b[31m"
87
const resetColor = "\x1b[0m"

0 commit comments

Comments
 (0)