Skip to content

Commit

Permalink
feat(xsnap): force rebuild if binary version mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Jul 1, 2024
1 parent a22772e commit 2b53896
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/xsnap/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ const updateSubmodules = async (showEnv, { env, stdout, spawn, fs }) => {
* type: typeof import('os').type,
* }
* }} io
* @param {object} [options]
* @param {boolean} [options.forceBuild]
*/
const makeXsnap = async ({ spawn, fs, os }) => {
const makeXsnap = async ({ spawn, fs, os }, { forceBuild = false } = {}) => {
const pjson = await fs.readFile(asset('../package.json'), 'utf-8');
const pkg = JSON.parse(pjson);

Expand All @@ -242,7 +244,7 @@ const makeXsnap = async ({ spawn, fs, os }) => {
: '';

const expectedConfigEnvs = configEnvs.concat('').join('\n');
if (existingConfigEnvs.trim() !== expectedConfigEnvs.trim()) {
if (forceBuild || existingConfigEnvs.trim() !== expectedConfigEnvs.trim()) {
await fs.writeFile(configEnvFile, expectedConfigEnvs);
}

Expand Down Expand Up @@ -347,7 +349,18 @@ async function main(args, { env, stdout, spawn, fs, os }) {

if (!showEnv) {
if (hasSource) {
await makeXsnap({ spawn, fs, os });
// Force a rebuild if for some reason the binary is out of date
// Since the make checks may not always detect that situation
let forceBuild = !hasBin;
if (hasBin) {
const npm = makeCLI('npm', { spawn });
await npm
.run(['run', '-s', 'check-version'], { cwd: asset('..') })
.catch(() => {
forceBuild = true;
});
}
await makeXsnap({ spawn, fs, os }, { forceBuild });
} else if (!hasBin) {
throw new Error(
'XSnap has neither sources nor a pre-built binary. Docker? .dockerignore? npm files?',
Expand Down

0 comments on commit 2b53896

Please sign in to comment.