From 300634deb1b33998a4a7cced5150faba3273662b Mon Sep 17 00:00:00 2001 From: amit Date: Fri, 17 Nov 2023 13:56:43 +0530 Subject: [PATCH] feat: use neos code from https://github.com/tailcallhq/tailcall/pull/634 --- npm/gen-root.ts | 3 +++ npm/post-install.js | 27 +++++++++++++++++++++++++++ npm/pre-install.js | 3 +-- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 npm/post-install.js diff --git a/npm/gen-root.ts b/npm/gen-root.ts index 18a5a82e77..1e79274d67 100644 --- a/npm/gen-root.ts +++ b/npm/gen-root.ts @@ -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") diff --git a/npm/post-install.js b/npm/post-install.js new file mode 100644 index 0000000000..40f6471ed7 --- /dev/null +++ b/npm/post-install.js @@ -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) +} \ No newline at end of file diff --git a/npm/pre-install.js b/npm/pre-install.js index f3d242291f..6d008b256b 100644 --- a/npm/pre-install.js +++ b/npm/pre-install.js @@ -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"