Skip to content

Commit

Permalink
feat: use neos code from #634
Browse files Browse the repository at this point in the history
  • Loading branch information
amitksingh1490 committed Nov 17, 2023
1 parent d49023e commit b6ff97b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions npm/gen-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ async function genServerPackage(buildDefinitions: string[]) {
await fs.mkdir(scriptsPath, { recursive: true })
await fs.mkdir(directoryPath, { recursive: true })

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

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


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

Expand Down
27 changes: 27 additions & 0 deletions npm/post-install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @ts-check
// @ts-ignore
import { familySync, GLIBC, MUSL } from "detect-libc"
import { exec } from 'child_process'
import util from 'util'

const execa = util.promisify(exec)
const platform = process.platform
const arch = process.arch

const libcFamily = familySync()
let libc
if (platform === "win32") {
libc = "-msvc"
} else {
libc = libcFamily === GLIBC ? "-gnu" : libcFamily === MUSL ? "-musl" : ""
}

const pkg = `@tailcallhq/core-${platform}-${arch}${libc}`

try {
// @ts-ignore
const { stdout, stderr } = await execa(`npm install ${pkg}@${version} --no-save`)
stderr ? console.log(stderr) : console.log(`Successfully installed optional dependency: ${pkg}`, stdout)
} catch (error) {
console.error(`Failed to install optional dependency: ${pkg}`, error.stderr)
}
3 changes: 1 addition & 2 deletions npm/pre-install.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const os = process.platform
const arch = process.arch
const libc = process.libc

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

0 comments on commit b6ff97b

Please sign in to comment.