AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(desktop): exclude development files from production packages
tianma-if70d486e4d7d6
diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.ymlindex 9a8ecf7b..0af5b19c 100644--- a/apps/desktop/electron-builder.yml+++ b/apps/desktop/electron-builder.yml@@ -26,6 +26,15 @@ directories:files:- src/**- package.json+ # Apply to application code and production dependencies. Keep executable JS,+ # npm commands (including test.js), node-gyp, schemas and license notices.+ - "!**/*.{test,spec}.{js,cjs,mjs,ts,cts,mts}"+ - "!**/{test,tests,__tests__,__mocks__}/**"+ - "!**/*.map"+ - "!**/*.d.{ts,cts,mts}"+ # Zod's standard import/require exports use compiled JS/CJS; src is only+ # selected by its opt-in @zod/source development condition.+ - "!**/node_modules/zod/src/**"extraResources:- from: ../../scriptsto: mcp-bridge@@ -36,6 +45,7 @@ extraResources:to: webfilter:- "**/*"+ - "!**/*.map"- from: assetsto: trayfilter:diff --git a/scripts/desktop-build-workflow.test.mjs b/scripts/desktop-build-workflow.test.mjsindex aca511a7..431a2149 100644--- a/scripts/desktop-build-workflow.test.mjs+++ b/scripts/desktop-build-workflow.test.mjs@@ -17,6 +17,12 @@ function step(name) {}describe("desktop release workflow", () => {+ test("checks archive contents and packaged dependencies before accepting installers", () => {+ expect(desktopPackageVerifier).toContain("assertDesktopProductionFiles(paths)");+ expect(desktopPackageVerifier).toContain("verify-desktop-production-runtime.cjs");+ expect(desktopPackageVerifier).toContain('ELECTRON_RUN_AS_NODE: "1"');+ expect(desktopPackageVerifier.match(/listAsarFiles\(asarPath, executable\)/g)).toHaveLength(3);+ });test("keeps the installed application and automatic update identity stable", () => {expect(desktopBuilderConfig).toContain("appId: org.edgeever.desktop");expect(desktopBuilderConfig).toContain([diff --git a/scripts/desktop-production-files.mjs b/scripts/desktop-production-files.mjsnew file mode 100644index 00000000..44ae624e--- /dev/null+++ b/scripts/desktop-production-files.mjs@@ -0,0 +1,31 @@+import assert from "node:assert/strict";++// Check the actual archive, not just the configured globs. Dependency collection+// has separate filtering in electron-builder and must obey the same exclusions.+export const assertDesktopProductionFiles = (files) => {+ const paths = [...files].map((file) => file.replaceAll("\\", "/"));+ const unwanted = paths.filter((file) =>+ /\.(?:test|spec)\.(?:js|cjs|mjs|ts|cts|mts)$/.test(file)+ || /\/(?:test|tests|__tests__|__mocks__)\//.test(file)+ || /\.map$/.test(file)+ || /\.d\.(?:ts|cts|mts)$/.test(file)+ || /\/node_modules\/zod\/src\//.test(file),+ );+ assert.deepEqual(unwanted, [], "Desktop archive contains test or development files");+ for (const required of [+ "/src/main/index.mjs",+ "/src/preload/index.cjs",+ "/node_modules/npm/bin/npm-cli.js",+ "/node_modules/npm/lib/commands/install.js",+ "/node_modules/npm/lib/commands/test.js",+ "/node_modules/node-gyp/bin/node-gyp.js",+ "/node_modules/node-gyp/gyp/gyp_main.py",+ "/node_modules/@agentclientprotocol/sdk/dist/acp.js",+ "/node_modules/@agentclientprotocol/sdk/schema/schema.json",+ "/node_modules/zod/index.js",+ "/node_modules/zod/index.cjs",+ "/node_modules/electron-updater/out/main.js",+ ]) {+ assert.ok(paths.includes(required), `Desktop archive is missing runtime file: ${required}`);+ }+};diff --git a/scripts/desktop-production-files.test.mjs b/scripts/desktop-production-files.test.mjsnew file mode 100644index 00000000..59720ab6--- /dev/null+++ b/scripts/desktop-production-files.test.mjs@@ -0,0 +1,64 @@+import { describe, expect, test } from "bun:test";+import { createRequire } from "node:module";+import { readFileSync } from "node:fs";+import { join, resolve } from "node:path";+import { assertDesktopProductionFiles } from "./desktop-production-files.mjs";++const desktopRequire = createRequire(new URL("../apps/desktop/package.json", import.meta.url));+const builderRequire = createRequire(createRequire(desktopRequire.resolve("electron-builder")).resolve("app-builder-lib"));+const { FileMatcher, getNodeModuleFileMatcher } = builderRequire("./fileMatcher.js");+const { load } = createRequire(desktopRequire.resolve("electron-updater"))("js-yaml");+const config = load(readFileSync(new URL("../apps/desktop/electron-builder.yml", import.meta.url), "utf8"));+const appDir = resolve("apps/desktop");+const applicationFilter = new FileMatcher(appDir, "/unused", (value) => value, config.files).createFilter();+const dependencyFilter = getNodeModuleFileMatcher(appDir, "/unused", (value) => value, {}, {+ config, debugLogger: { isEnabled: false },+}).createFilter();++describe("desktop production archive", () => {+ test("electron-builder removes development files in app code and nested dependencies", () => {+ for (const file of [+ "src/main/example.test.mjs", "src/main/example.spec.cjs",+ "src/main/__tests__/helper.js", "src/main/example.mjs.map",+ "node_modules/@agentclientprotocol/sdk/dist/acp.test.js",+ "node_modules/npm/node_modules/example/dist/tests/helper.js",+ "node_modules/zod/index.d.cts", "node_modules/example/index.d.mts",+ "node_modules/example/index.js.map", "node_modules/zod/src/index.ts",+ ]) {+ const filter = file.startsWith("node_modules/") ? dependencyFilter : applicationFilter;+ expect(filter(join(appDir, file), { isDirectory: () => false })).toBe(false);+ }+ });++ test("preserves runtime commands, Python support, schemas and license notices", () => {+ for (const file of [+ "src/main/index.mjs", "src/preload/index.cjs",+ "node_modules/npm/lib/commands/test.js", "node_modules/npm/bin/npm-cli.js",+ "node_modules/node-gyp/gyp/gyp_main.py",+ "node_modules/@agentclientprotocol/sdk/dist/acp.js",+ "node_modules/@agentclientprotocol/sdk/schema/schema.json",+ "node_modules/@agentclientprotocol/sdk/LICENSE-APACHE",+ "node_modules/zod/index.js", "node_modules/zod/index.cjs",+ "node_modules/electron-updater/out/main.js",+ "node_modules/npm/docs/output/commands/npm-install.html",+ ]) {+ const filter = file.startsWith("node_modules/") ? dependencyFilter : applicationFilter;+ expect(filter(join(appDir, file), { isDirectory: () => false })).toBe(true);+ }+ });++ test("rejects an archive with omitted runtime files or leaked development files", () => {+ expect(() => assertDesktopProductionFiles(["/src/main/index.mjs"])).toThrow("missing runtime file");+ expect(() => assertDesktopProductionFiles(["/node_modules/sdk/dist/acp.test.js"])).toThrow("development files");+ });++ test("excludes renderer source maps while retaining every font format", () => {+ const web = config.extraResources.find((resource) => resource.to === "web");+ const root = resolve("apps/web/dist");+ const filter = new FileMatcher(root, "/unused", (value) => value, web.filter).createFilter();+ expect(filter(join(root, "assets/app.js.map"), { isDirectory: () => false })).toBe(false);+ for (const file of ["index.html", "assets/app.js", "assets/font.woff2", "poster-fonts/font.ttf", "poster-fonts/LICENSE.txt"]) {+ expect(filter(join(root, file), { isDirectory: () => false })).toBe(true);+ }+ });+});diff --git a/scripts/plan-native-release.mjs b/scripts/plan-native-release.mjsindex 457f4cd3..e25460ca 100644--- a/scripts/plan-native-release.mjs+++ b/scripts/plan-native-release.mjs@@ -67,6 +67,8 @@ export const planNativeRelease = (platform, changedFiles) => {"scripts/sign-windows-update-manifest.mjs","scripts/verify-windows-update-release.mjs","scripts/verify-desktop-package.mjs",+ "scripts/desktop-production-files.mjs",+ "scripts/verify-desktop-production-runtime.cjs","scripts/verify-desktop-cross-version-startup.mjs","scripts/verify-packaged-desktop-startup.mjs","scripts/verify-renderer-origin-migration.mjs",diff --git a/scripts/plan-native-release.test.mjs b/scripts/plan-native-release.test.mjsindex 981cde1e..eedaf8fa 100644--- a/scripts/plan-native-release.test.mjs+++ b/scripts/plan-native-release.test.mjs@@ -2,6 +2,11 @@ import { describe, expect, test } from "bun:test";import { planNativeRelease } from "./plan-native-release.mjs";describe("native release planning", () => {+ test("rebuilds desktop when production archive validation changes", () => {+ for (const file of ["scripts/desktop-production-files.mjs", "scripts/verify-desktop-production-runtime.cjs"]) {+ expect(planNativeRelease("desktop", [file])).toEqual({ rebuild: true, relevantChanges: [file] });+ }+ });test("does not rebuild Android for root scripts, versions, or documentation", () => {expect(planNativeRelease("mobile", [diff --git a/scripts/verify-desktop-package.mjs b/scripts/verify-desktop-package.mjsindex 1602751d..1b846cc9 100644--- a/scripts/verify-desktop-package.mjs+++ b/scripts/verify-desktop-package.mjs@@ -1,10 +1,12 @@import assert from "node:assert/strict";-import { spawnSync } from "node:child_process";+import { execFileSync, spawnSync } from "node:child_process";+import { fileURLToPath } from "node:url";import { existsSync, openSync, closeSync, readFileSync, readSync, readdirSync, rmSync, statSync } from "node:fs";import { join } from "node:path";import { listPackage } from "@electron/asar";import { assertMacIcnsComplete } from "./desktop-icns.mjs";import { isVisualCppRuntimeDll, readPeImportedDlls } from "./pe-imports.mjs";+import { assertDesktopProductionFiles } from "./desktop-production-files.mjs";const outputDirectory = join(process.cwd(), "release", "desktop");const version = JSON.parse(@@ -25,9 +27,16 @@ const walk = (directory) => {const files = walk(outputDirectory);const requestedPlatform = process.env.EDGE_EVER_VERIFY_TARGET ?? process.platform;const requestedArch = process.env.EDGE_EVER_DESKTOP_ARCH ?? process.arch;-const listAsarFiles = (asarPath) => new Set(- listPackage(asarPath).map((path) => path.replaceAll("\\", "/")),-);+const listAsarFiles = (asarPath, executable) => {+ const paths = new Set(listPackage(asarPath).map((path) => path.replaceAll("\\", "/")));+ assertDesktopProductionFiles(paths);+ execFileSync(executable, [fileURLToPath(new URL("./verify-desktop-production-runtime.cjs", import.meta.url)), asarPath], {+ env: { ...process.env, ELECTRON_RUN_AS_NODE: "1" },+ timeout: 150_000,+ stdio: "inherit",+ });+ return paths;+};const verifyMachOArch = (path, arch, label) => {const result = spawnSync("lipo", ["-archs", path], { encoding: "utf8" });@@ -104,7 +113,7 @@ if (requestedPlatform === "darwin") {assert.match(shareExtensionInfo, /NSExtensionActivationSupportsFileWithMaxCount/, "WeChat share extension must accept shared files");const asarPath = join(appResources, "app.asar");assert.ok(existsSync(asarPath), `macOS app bundle is missing app.asar: ${asarPath}`);- const asarFiles = listAsarFiles(asarPath);+ const asarFiles = listAsarFiles(asarPath, executable);assert.ok(asarFiles.has("/src/preload/index.cjs"), "macOS app bundle must contain the sandbox-compatible CommonJS preload");assert.ok(!asarFiles.has("/src/preload/index.mjs"), "macOS app bundle must not contain the unsupported ESM preload");const appIconPath = join(appResources, "icon.icns");@@ -138,7 +147,7 @@ if (requestedPlatform === "darwin") {);const asarPath = join(resources, "app.asar");assert.ok(existsSync(asarPath), `Windows app bundle is missing app.asar: ${asarPath}`);- const asarFiles = listAsarFiles(asarPath);+ const asarFiles = listAsarFiles(asarPath, executable);assert.ok(asarFiles.has("/src/preload/index.cjs"), "Windows app bundle must contain the sandbox-compatible CommonJS preload");assert.ok(!asarFiles.has("/src/preload/index.mjs"), "Windows app bundle must not contain the unsupported ESM preload");} else if (requestedPlatform === "linux") {@@ -162,7 +171,7 @@ if (requestedPlatform === "darwin") {verifyGlibcBaseline(sidecar);const asarPath = join(resources, "app.asar");assert.ok(existsSync(asarPath), `Linux app bundle is missing app.asar: ${asarPath}`);- const asarFiles = listAsarFiles(asarPath);+ const asarFiles = listAsarFiles(asarPath, executable);assert.ok(asarFiles.has("/src/preload/index.cjs"), "Linux app bundle must contain the sandbox-compatible CommonJS preload");assert.ok(!asarFiles.has("/src/preload/index.mjs"), "Linux app bundle must not contain the unsupported ESM preload");} else {diff --git a/scripts/verify-desktop-production-runtime.cjs b/scripts/verify-desktop-production-runtime.cjsnew file mode 100644index 00000000..7ab2806b--- /dev/null+++ b/scripts/verify-desktop-production-runtime.cjs@@ -0,0 +1,62 @@+// Run using the packaged Electron executable with ELECTRON_RUN_AS_NODE=1.+// This exercises only temporary files, without launching the app or its updater.+const assert = require("node:assert/strict");+const { execFileSync } = require("node:child_process");+const { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } = require("node:fs");+const { createRequire } = require("node:module");+const { tmpdir } = require("node:os");+const { dirname, join, resolve, sep } = require("node:path");+const { pathToFileURL } = require("node:url");++async function main() {+ const archive = realpathSync(resolve(process.argv[2]));+ const appRequire = createRequire(join(archive, "package.json"));+ const resolveDependency = (name) => {+ const file = appRequire.resolve(name);+ assert.ok(file.startsWith(archive + sep), `${name} resolved outside packaged archive: ${file}`);+ return file;+ };+ const zod = appRequire(resolveDependency("zod"));+ assert.equal(zod.z.string().parse("packaged"), "packaged");+ const esmZod = await import(pathToFileURL(join(dirname(resolveDependency("zod/package.json")), "index.js")).href);+ assert.equal(esmZod.z.string().parse("packaged"), "packaged");+ const sdk = await import(pathToFileURL(resolveDependency("@agentclientprotocol/sdk")).href);+ assert.equal(typeof sdk.ClientSideConnection, "function");+ const updater = appRequire(resolveDependency("electron-updater"));+ for (const name of ["MacUpdater", "NsisUpdater", "AppImageUpdater"]) {+ assert.equal(typeof updater[name], "function", `Missing updater: ${name}`);+ }+ const manager = await import(pathToFileURL(join(archive, "src/main/acp-adapter-manager.mjs")).href);+ assert.equal(typeof manager.createAcpAdapterManager, "function");++ const npmCli = join(dirname(resolveDependency("npm")), "bin/npm-cli.js");+ const npmRequire = createRequire(npmCli);+ const tar = npmRequire("tar");+ const root = mkdtempSync(join(tmpdir(), "edgeever-packaged-npm-"));+ try {+ const fixture = join(root, "fixture/package");+ mkdirSync(fixture, { recursive: true });+ writeFileSync(join(fixture, "index.js"), "module.exports = 42;\n");+ for (const version of ["1.0.0", "1.0.1"]) {+ writeFileSync(join(fixture, "package.json"), JSON.stringify({ name: "edgeever-packaging-fixture", version, main: "index.js" }));+ const tarball = join(root, `fixture-${version}.tgz`);+ await tar.c({ gzip: true, cwd: join(root, "fixture"), file: tarball }, ["package"]);+ execFileSync(process.execPath, [npmCli, "install", "--prefix", join(root, "installed"),+ "--cache", join(root, "cache"), "--offline", "--ignore-scripts", "--no-audit", "--no-fund",+ "--package-lock=false", tarball], {+ cwd: root,+ env: { ...process.env, ELECTRON_RUN_AS_NODE: "1", npm_config_update_notifier: "false" },+ timeout: 60_000,+ stdio: "pipe",+ });+ const installed = join(root, "installed/node_modules/edgeever-packaging-fixture");+ assert.equal(JSON.parse(readFileSync(join(installed, "package.json"), "utf8")).version, version);+ assert.equal(require(join(installed, "index.js")), 42);+ }+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+ console.log(JSON.stringify({ ok: true, packagedDependencies: true, offlineNpmInstallAndUpgrade: true }));+}++main().catch((error) => { console.error(error); process.exitCode = 1; });