From 4a2f85e9eb4361a0188a70f8ff3155d8d1e02826 Mon Sep 17 00:00:00 2001 From: Isaac Date: Thu, 24 Aug 2023 23:36:03 +0100 Subject: [PATCH] fix: `npx` workaround for PebbleHost --- scripts/postinstall.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index f36bd39..49b0ceb 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -5,16 +5,26 @@ const util = require('util'); const exec = util.promisify(require('child_process').exec); const { short } = require('leeks.js'); +const fallback = { prisma: './node_modules/prisma/build/index.js' }; + function log(...strings) { console.log(short('&9[postinstall]&r'), ...strings); } async function npx(cmd) { + const parts = cmd.split(' '); + // fallback for environments with no symlink/npx support (PebbleHost) + if (!fs.existsSync(`./node_modules/.bin/${parts[0]}`)) { + const x = parts.shift(); + cmd = 'node ' + fallback[x] + ' ' + parts.join(' '); + } else { + cmd = 'npx ' + cmd; + } log(`> ${cmd}`); const { stderr, stdout, - } = await exec('npx ' + cmd); + } = await exec(cmd); if (stdout) console.log(stdout.toString()); if (stderr) console.log(stderr.toString()); } @@ -32,11 +42,17 @@ if (!providers.includes(provider)) throw new Error(`DB_PROVIDER must be one of: log(`provider=${provider}`); log(`copying ${provider} schema & migrations`); -if (!fs.existsSync('./prisma')) fs.mkdirSync('./prisma'); +if (fs.existsSync('./prisma')) { + fs.rmSync('./prisma', { + force: true, + recursive: true, + }); +} else { + fs.mkdirSync('./prisma'); +} fs.copySync(`./db/${provider}`, './prisma'); // copy schema & migrations (async () => { await npx('prisma generate'); await npx('prisma migrate deploy'); })(); -