From fc7de024c659868398affa07da7fd38e73585f9a Mon Sep 17 00:00:00 2001 From: naskya Date: Fri, 10 May 2024 02:24:25 +0900 Subject: [PATCH] chore: let pnpm detect dependencies --- package.json | 4 +- scripts/build.mjs | 38 ------------------- scripts/{dev-build.mjs => copy-index-dev.mjs} | 35 +++-------------- scripts/copy-index.mjs | 16 ++++++++ 4 files changed, 24 insertions(+), 69 deletions(-) delete mode 100644 scripts/build.mjs rename scripts/{dev-build.mjs => copy-index-dev.mjs} (62%) create mode 100644 scripts/copy-index.mjs diff --git a/package.json b/package.json index 63be65d6bd..df6d7d6979 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,9 @@ "private": true, "scripts": { "rebuild": "pnpm run clean && pnpm run build", - "build": "pnpm node ./scripts/build.mjs && pnpm run build:assets", + "build": "pnpm --recursive --color run build && pnpm node ./scripts/copy-index.mjs && pnpm run build:assets", "build:assets": "pnpm node ./scripts/copy-assets.mjs", - "build:debug": "pnpm run clean && pnpm node ./scripts/dev-build.mjs && pnpm run build:assets", + "build:debug": "pnpm run clean && pnpm --recursive --color run build:debug && pnpm node ./scripts/copy-index-dev.mjs && pnpm run build:assets", "start": "pnpm --filter backend run start", "start:container": "pnpm run build:assets && pnpm run migrate && pnpm run start", "start:test": "pnpm --filter backend run start:test", diff --git a/scripts/build.mjs b/scripts/build.mjs deleted file mode 100644 index 073d4f006c..0000000000 --- a/scripts/build.mjs +++ /dev/null @@ -1,38 +0,0 @@ -import fs from "node:fs"; -import path, { join } from "node:path"; -import { fileURLToPath } from "node:url"; -import { execa } from "execa"; - -(async () => { - const __dirname = path.dirname(fileURLToPath(import.meta.url)); - - await execa( - "pnpm", [ - "--recursive", - "--parallel", - "--filter=backend-rs", - "--filter=firefish-js", - "run", - "build", - ], { - cwd: join(__dirname, "/../"), - stdio: "inherit", - } - ); - - await execa( - "pnpm", [ - "--recursive", - "--parallel", - "--filter=!backend-rs", - "--filter=!firefish-js", - "run", - "build", - ], { - cwd: join(__dirname, "/../"), - stdio: "inherit", - } - ); - - fs.copyFileSync("packages/backend-rs/index.js", "packages/backend-rs/built/index.js"); -})(); diff --git a/scripts/dev-build.mjs b/scripts/copy-index-dev.mjs similarity index 62% rename from scripts/dev-build.mjs rename to scripts/copy-index-dev.mjs index 9825be3033..028dd609f5 100644 --- a/scripts/dev-build.mjs +++ b/scripts/copy-index-dev.mjs @@ -1,39 +1,15 @@ +// To mitigate this issue https://github.com/napi-rs/napi-rs/issues/1768 + +// During development, the contents of index.js/index.d.ts may change, +// so this script only copies these files when this bug occurs + import path, { join } from "node:path"; import { fileURLToPath } from "node:url"; -import { execa } from "execa"; import fs from "node:fs"; (async () => { const __dirname = path.dirname(fileURLToPath(import.meta.url)); - await execa( - "pnpm", [ - "--recursive", - "--parallel", - "--filter=backend-rs", - "--filter=firefish-js", - "run", - "build:debug", - ], { - cwd: join(__dirname, "/../"), - stdio: "inherit", - } - ); - - await execa( - "pnpm", [ - "--recursive", - "--parallel", - "--filter=!backend-rs", - "--filter=!firefish-js", - "run", - "build:debug", - ], { - cwd: join(__dirname, "/../"), - stdio: "inherit", - } - ); - if (!fs.existsSync(join(__dirname, "/../packages/backend-rs/built/index.js"))) { fs.copyFileSync( join(__dirname, "/../packages/backend-rs/index.js"), @@ -46,5 +22,6 @@ import fs from "node:fs"; join(__dirname, "/../packages/backend-rs/index.d.ts"), join(__dirname, "/../packages/backend-rs/built/index.d.ts"), ); + console.warn("backend-rs/built/index.d.ts has not been updated (https://github.com/napi-rs/napi-rs/issues/1768)"); } })(); diff --git a/scripts/copy-index.mjs b/scripts/copy-index.mjs new file mode 100644 index 0000000000..2a18661b9a --- /dev/null +++ b/scripts/copy-index.mjs @@ -0,0 +1,16 @@ +// To mitigate this issue https://github.com/napi-rs/napi-rs/issues/1768 + +// Adding index.js/index.d.ts to the repository is recommended by +// napi-rs maintainer: https://github.com/napi-rs/napi-rs/issues/1807#issuecomment-1814510181 + +import path, { join } from "node:path"; +import { fileURLToPath } from "node:url"; +import fs from "node:fs"; + +(async () => { + const __dirname = path.dirname(fileURLToPath(import.meta.url)); + fs.copyFileSync( + join(__dirname, "/../packages/backend-rs/index.js"), + join(__dirname, "/../packages/backend-rs/built/index.js"), + ); +})();