diff --git a/api/node/build-on-demand.mjs b/api/node/build-on-demand.mjs index d515c950d..6943f6026 100644 --- a/api/node/build-on-demand.mjs +++ b/api/node/build-on-demand.mjs @@ -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", + }); + } } }); diff --git a/api/node/package.json b/api/node/package.json index 98a9c4312..17b5e009c 100644 --- a/api/node/package.json +++ b/api/node/package.json @@ -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", diff --git a/demos/home-automation/node/package.json b/demos/home-automation/node/package.json index d12e64a60..baa93dc2e 100644 --- a/demos/home-automation/node/package.json +++ b/demos/home-automation/node/package.json @@ -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", diff --git a/demos/printerdemo/node/package.json b/demos/printerdemo/node/package.json index 982273884..fa504d9ca 100644 --- a/demos/printerdemo/node/package.json +++ b/demos/printerdemo/node/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/examples/carousel/node/package.json b/examples/carousel/node/package.json index 03bb18a1e..5f7f44227 100644 --- a/examples/carousel/node/package.json +++ b/examples/carousel/node/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/examples/imagefilter/node/package.json b/examples/imagefilter/node/package.json index 554c9be59..59f200f12 100644 --- a/examples/imagefilter/node/package.json +++ b/examples/imagefilter/node/package.json @@ -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" } } diff --git a/examples/memory/package.json b/examples/memory/package.json index f7505c0e8..c4de24815 100644 --- a/examples/memory/package.json +++ b/examples/memory/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/examples/todo/node/package.json b/examples/todo/node/package.json index 6e6cc4579..3a8ac7e4a 100644 --- a/examples/todo/node/package.json +++ b/examples/todo/node/package.json @@ -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" } -} \ No newline at end of file +}