Merge pull request #12548 from logseq/feat/desktop-bundle-cli

Feat/desktop bundle cli
This commit is contained in:
Tienson Qin
2026-04-30 18:09:35 +08:00
committed by GitHub
parent 464c5375ee
commit abbc1ad628
12 changed files with 697 additions and 24 deletions

View File

@@ -18,6 +18,10 @@ const builtinModuleSet = new Set([
...builtinModules,
...builtinModules.map((moduleName) => `node:${moduleName}`),
]);
const externalModuleSet = new Set([
"keytar",
"ws",
]);
async function exists(targetPath) {
try {
@@ -101,7 +105,10 @@ async function main() {
},
rollupOptions: {
external: (id) =>
id.endsWith(".node") || id.startsWith("node:") || builtinModuleSet.has(id),
id.endsWith(".node") ||
id.startsWith("node:") ||
builtinModuleSet.has(id) ||
externalModuleSet.has(id),
output: {
format: "cjs",
exports: "auto",
@@ -116,6 +123,18 @@ async function main() {
throw new Error(`vite bundle missing output file: ${bundleEntry}`);
}
const bundleContents = await fs.readFile(bundleEntry, "utf8");
if (bundleContents.includes("node_modules/.pnpm/keytar")) {
throw new Error(
"vite bundle contains a pnpm keytar native path; keytar must stay external"
);
}
if (bundleContents.includes("ws does not work in the browser")) {
throw new Error(
"vite bundle contains the ws browser stub; ws must stay external"
);
}
let filesAfter = await listFilesRecursive(distDir);
if (filesAfter.includes("index.html") && !filesBefore.includes("index.html")) {
await removeIfExists(path.join(distDir, "index.html"));

View File

@@ -0,0 +1,65 @@
#!/usr/bin/env node
import { promises as fs } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const repoRoot = path.resolve(__dirname, "..");
const staticDir = path.join(repoRoot, "static");
const staticJsDir = path.join(staticDir, "js");
const distDir = path.join(repoRoot, "dist");
const copyPairs = [
{
from: path.join(staticDir, "logseq-cli.js"),
to: path.join(staticJsDir, "logseq-cli.js"),
},
{
from: path.join(staticDir, "logseq-cli.js.map"),
to: path.join(staticJsDir, "logseq-cli.js.map"),
optional: true,
},
{
from: path.join(distDir, "db-worker-node.js"),
to: path.join(staticJsDir, "db-worker-node.js"),
},
];
async function exists(filePath) {
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
}
async function copyOne({ from, to, optional = false }) {
if (!(await exists(from))) {
if (optional) return;
throw new Error(`missing required source file: ${from}`);
}
await fs.copyFile(from, to);
}
async function main() {
await fs.mkdir(staticJsDir, { recursive: true });
for (const pair of copyPairs) {
await copyOne(pair);
}
// Keep release app runtime files only in static/js.
await fs.rm(path.join(staticDir, "logseq-cli.js"), { force: true });
await fs.rm(path.join(staticDir, "logseq-cli.js.map"), { force: true });
await fs.rm(path.join(staticDir, "db-worker-node.js"), { force: true });
await fs.rm(path.join(staticDir, "db-worker-node.js.map"), { force: true });
}
main().catch((error) => {
console.error(`[prepare-desktop-runtime-js] ${error.message}`);
process.exit(1);
});