Fix fallback to source builds

Continue to run build-on-demand.mjs to permit a fallback to a
from-source build for users who run `npm install slint-ui` on a platform
where we don't provide binaries for (such as linux-armv7/64). However,
this is only done when run from the installed package, not from git.
From git, the prestart trick remains in use.
This commit is contained in:
Simon Hausmann 2024-11-14 11:15:36 +01:00 committed by Simon Hausmann
parent 0461abfc73
commit 9f7e407eff
8 changed files with 26 additions and 14 deletions

View file

@ -6,6 +6,7 @@
import { Worker } from "node:worker_threads";
import { spawn } from "node:child_process";
import { existsSync } from "node:fs";
const worker = new Worker("./rust-module.cjs");
// Define dummy error handler to prevent node from aborting on errors
@ -14,9 +15,19 @@ worker.on("error", (error) => {
});
worker.on("exit", (code) => {
if (code !== 0) {
console.log("slint-ui: loading rust-module.cjs failed, building now");
spawn("npm", ["run", "build"], {
stdio: "inherit",
});
// HACK: npm package removes .npmignore. If the file is present, then it means that we're in the Slint git repo,
// and we don't want to automatically build (see https://github.com/slint-ui/slint/pull/6780).
if (existsSync("./.npmignore")) {
console.log(
"slint-ui: loading rust-module.cjs failed, please run `npm run build` first.",
);
} else {
console.log(
"slint-ui: loading rust-module.cjs failed, building now",
);
spawn("npm", ["run", "build"], {
stdio: "inherit",
});
}
}
});

View file

@ -40,6 +40,7 @@
"build": "napi build --platform --release --js rust-module.cjs --dts rust-module.d.ts -c binaries.json",
"build:debug": "napi build --platform --js rust-module.cjs --dts rust-module.d.ts -c binaries.json && pnpm compile",
"build:testing": "napi build --platform --js rust-module.cjs --dts rust-module.d.ts -c binaries.json --features testing && pnpm compile",
"install": "node build-on-demand.mjs",
"docs": "pnpm build && typedoc --hideGenerator --treatWarningsAsErrors --readme cover.md typescript/index.ts",
"check": "biome check",
"format": "biome format",

View file

@ -9,7 +9,7 @@
},
"scripts": {
"start": "node .",
"prestart": "cd ../../../api/node/ && node build-on-demand.mjs && pnpm compile",
"prestart": "cd ../../../api/node/ && pnpm run build && pnpm compile",
"check": "biome check",
"format": "biome format",
"format:fix": "biome format --write",

View file

@ -8,6 +8,6 @@
},
"scripts": {
"start": "node .",
"prestart": "cd ../../../api/node/ && node build-on-demand.mjs && pnpm compile"
"prestart": "cd ../../../api/node/ && pnpm run build && pnpm compile"
}
}
}

View file

@ -8,6 +8,6 @@
},
"scripts": {
"start": "node .",
"prestart": "cd ../../../api/node/ && node build-on-demand.mjs && pnpm compile"
"prestart": "cd ../../../api/node/ && pnpm run build && pnpm compile"
}
}
}

View file

@ -13,7 +13,7 @@
},
"scripts": {
"start": "tsc --build && node ./main.js",
"prestart": "cd ../../../api/node/ && node build-on-demand.mjs && pnpm compile",
"prestart": "cd ../../../api/node/ && pnpm run build && pnpm compile",
"type-check": "tsc --noEmit"
}
}

View file

@ -8,6 +8,6 @@
},
"scripts": {
"start": "node .",
"prestart": "cd ../../api/node/ && node build-on-demand.mjs && pnpm compile"
"prestart": "cd ../../api/node/ && pnpm run build && pnpm compile"
}
}
}

View file

@ -8,6 +8,6 @@
},
"scripts": {
"start": "node .",
"prestart": "cd ../../../api/node/ && node build-on-demand.mjs && pnpm compile"
"prestart": "cd ../../../api/node/ && pnpm run build && pnpm compile"
}
}
}