Skip to content

Commit 97fc797

Browse files
authored
feat: fix build + posthog integration (#476)
1 parent 73b73a3 commit 97fc797

3 files changed

Lines changed: 56 additions & 42 deletions

File tree

.github/workflows/array-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
runs-on: macos-latest
2323
env:
2424
NODE_ENV: production
25+
VITE_POSTHOG_API_KEY: ${{ secrets.VITE_POSTHOG_API_KEY }}
26+
VITE_POSTHOG_API_HOST: ${{ secrets.VITE_POSTHOG_API_HOST }}
2527
APPLE_CODESIGN_IDENTITY: ${{ secrets.APPLE_CODESIGN_IDENTITY }}
2628
APPLE_ID: ${{ secrets.APPLE_ID }}
2729
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}

apps/array/vite.main.config.mts

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { execSync } from "node:child_process";
22
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
33
import path, { join } from "node:path";
44
import { fileURLToPath } from "node:url";
5-
import { defineConfig, type Plugin } from "vite";
5+
import { defineConfig, loadEnv, type Plugin } from "vite";
66
import tsconfigPaths from "vite-tsconfig-paths";
77
import { autoServicesPlugin } from "./vite-plugin-auto-services.js";
88

@@ -154,48 +154,60 @@ function copyClaudeExecutable(): Plugin {
154154
// Allow forcing dev mode in packaged builds via FORCE_DEV_MODE=1
155155
const forceDevMode = process.env.FORCE_DEV_MODE === "1";
156156

157-
export default defineConfig({
158-
plugins: [
159-
tsconfigPaths(),
160-
autoServicesPlugin(join(__dirname, "src/main/services")),
161-
fixFilenameCircularRef(),
162-
copyAgentTemplates(),
163-
copyClaudeExecutable(),
164-
],
165-
define: {
166-
__BUILD_COMMIT__: JSON.stringify(_getGitCommit()),
167-
__BUILD_DATE__: JSON.stringify(_getBuildDate()),
168-
...(forceDevMode
169-
? {
170-
"import.meta.env.DEV": "true",
171-
"import.meta.env.PROD": "false",
172-
"import.meta.env.MODE": '"development"',
173-
}
174-
: {}),
175-
},
176-
resolve: {
177-
alias: {
178-
"@": path.resolve(__dirname, "./src"),
179-
"@main": path.resolve(__dirname, "./src/main"),
180-
"@renderer": path.resolve(__dirname, "./src/renderer"),
181-
"@shared": path.resolve(__dirname, "./src/shared"),
182-
"@api": path.resolve(__dirname, "./src/api"),
157+
export default defineConfig(({ mode }) => {
158+
// Load VITE_* env vars from monorepo root .env file
159+
const env = loadEnv(mode, path.resolve(__dirname, "../.."), "VITE_");
160+
161+
return {
162+
plugins: [
163+
tsconfigPaths(),
164+
autoServicesPlugin(join(__dirname, "src/main/services")),
165+
fixFilenameCircularRef(),
166+
copyAgentTemplates(),
167+
copyClaudeExecutable(),
168+
],
169+
define: {
170+
__BUILD_COMMIT__: JSON.stringify(_getGitCommit()),
171+
__BUILD_DATE__: JSON.stringify(_getBuildDate()),
172+
// Inject PostHog env vars at build time (process.env is not available in packaged builds)
173+
"process.env.VITE_POSTHOG_API_KEY": JSON.stringify(
174+
env.VITE_POSTHOG_API_KEY || "",
175+
),
176+
"process.env.VITE_POSTHOG_API_HOST": JSON.stringify(
177+
env.VITE_POSTHOG_API_HOST || "",
178+
),
179+
...(forceDevMode
180+
? {
181+
"import.meta.env.DEV": "true",
182+
"import.meta.env.PROD": "false",
183+
"import.meta.env.MODE": '"development"',
184+
}
185+
: {}),
183186
},
184-
},
185-
cacheDir: ".vite/cache",
186-
build: {
187-
target: "node18",
188-
minify: false,
189-
reportCompressedSize: false,
190-
commonjsOptions: {
191-
transformMixedEsModules: true,
187+
resolve: {
188+
alias: {
189+
"@": path.resolve(__dirname, "./src"),
190+
"@main": path.resolve(__dirname, "./src/main"),
191+
"@renderer": path.resolve(__dirname, "./src/renderer"),
192+
"@shared": path.resolve(__dirname, "./src/shared"),
193+
"@api": path.resolve(__dirname, "./src/api"),
194+
},
192195
},
193-
rollupOptions: {
194-
external: ["node-pty", "@parcel/watcher", "file-icon"],
195-
onwarn(warning, warn) {
196-
if (warning.code === "UNUSED_EXTERNAL_IMPORT") return;
197-
warn(warning);
196+
cacheDir: ".vite/cache",
197+
build: {
198+
target: "node18",
199+
minify: false,
200+
reportCompressedSize: false,
201+
commonjsOptions: {
202+
transformMixedEsModules: true,
203+
},
204+
rollupOptions: {
205+
external: ["node-pty", "@parcel/watcher", "file-icon"],
206+
onwarn(warning, warn) {
207+
if (warning.code === "UNUSED_EXTERNAL_IMPORT") return;
208+
warn(warning);
209+
},
198210
},
199211
},
200-
},
212+
};
201213
});

apps/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"type": "module",
99
"scripts": {
10-
"build": "bun build ./src/index.ts --outdir ./dist --target bun",
10+
"build": "bun build ./src/cli.ts --outdir ./dist --target bun",
1111
"dev": "bun run ./bin/arr.ts",
1212
"typecheck": "tsc --noEmit",
1313
"test:pty": "vitest run tests/e2e/pty.test.ts"

0 commit comments

Comments
 (0)