Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(vite): unify dist output (#2862)

Sean Ayeff246ef3a0f4
diff --git a/flake.nix b/flake.nix
index fc90658538..a5b13d3781 100644
--- a/flake.nix
+++ b/flake.nix
@@ -23,6 +23,7 @@
packages = with pkgs; [
parallel
docker-compose
+ zip
cargo-info
cargo-udeps
cargo-lambda
diff --git a/infra/stacks/web-app/README.md b/infra/stacks/web-app/README.md
index 59c37bc290..def051b3b9 100644
--- a/infra/stacks/web-app/README.md
+++ b/infra/stacks/web-app/README.md
@@ -3,5 +3,5 @@
This is Pulumi IaC for Macro Web App, deploying to AWS S3 and CloudFront Distribution with Route53 and ACM
## Dev Environment
-1. Run `yarn build:web` in the root of the `app-monorepo`.
-2. Run the command `$ yarn run deploy:dev` from this directory or `$ yarn workspace @macro-inc/infra-web-app run deploy:dev` from root directory will deploy `packages/app/dist` to https://app-dev.macro.com
+1. Run `just build-dev` from `js/app/`.
+2. Run `$ yarn run deploy:dev` from this directory or `$ yarn workspace @macro-inc/infra-web-app run deploy:dev` from root directory to deploy the build artifact from `js/app/packages/app/dist` to https://app-dev.macro.com
diff --git a/js/app/justfile b/js/app/justfile
index 1186c719f2..3062c41042 100644
--- a/js/app/justfile
+++ b/js/app/justfile
@@ -1,5 +1,5 @@
dev-tauri:
- cd packages/app && bun run --bun dev:tauri
+ cd packages/app && bun run --bun dev
# List available local service names
local-services:
@@ -35,20 +35,18 @@ build-prod:
cd packages/app && MODE=production NODE_ENV=production bun run --bun build
build-tauri:
- cd packages/app && MODE=production NODE_ENV=production bun run --bun build:tauri
+ cd packages/app && MODE=production NODE_ENV=production bun run --bun build
-# Build the web bundle for `platform` (default: ios), zip it, and install it at
+# Build the bundle, zip it, and install it at
# rust/cloud-storage/tools/native_app_server/app-archive.zip for the bundle
# updater test server. The server hashes the archive at request time, so no
# checksum wiring is needed.
-dist-archive platform='ios':
+dist-archive: build-prod
#!/usr/bin/env bash
set -euo pipefail
- cd packages/app
- MODE=production NODE_ENV=production bun run --bun build:{{platform}}
TARGET="$(cd {{ justfile_directory() }}/../../rust/cloud-storage/tools/native_app_server && pwd)/app-archive.zip"
rm -f "$TARGET"
- (cd dist && zip -qr "$TARGET" .)
+ (cd packages/app/dist && zip -qr "$TARGET" .)
echo "Archive: $TARGET"
test-watch:
diff --git a/js/app/packages/app/lib/analytics/analytics.ts b/js/app/packages/app/lib/analytics/analytics.ts
index e792318665..40074235dd 100644
--- a/js/app/packages/app/lib/analytics/analytics.ts
+++ b/js/app/packages/app/lib/analytics/analytics.ts
@@ -12,13 +12,12 @@ import { DEV_MODE_ENV, PROD_MODE_ENV } from '@core/constant/featureFlags';
/**
* Resolves the user's device context for analytics enrichment.
*
- * `getPlatform()` reads the build-time `VITE_PLATFORM` env var:
- * - Tauri iOS/Android builds → 'ios' | 'android' → 'mobile-app'
- * - Tauri desktop build → 'desktop' → 'desktop-app'
- * - Web build → 'web' (used by both desktop and mobile browsers)
+ * `getPlatform()` runtime-detects via `isTauri()` + `@tauri-apps/plugin-os`:
+ * - Tauri iOS/Android → 'ios' | 'android' → 'mobile-app'
+ * - Tauri desktop OS → 'desktop' → 'desktop-app'
+ * - Plain browser → 'web'
*
- * Desktop and mobile browsers share the same web build, so we use
- * `isTouchDevice()` (checks `pointer: coarse` media query) to distinguish
+ * On web, `isTouchDevice()` (checks `pointer: coarse` media query) distinguishes
* a phone/tablet browser ('mobile-web') from a desktop browser ('desktop-web').
*/
const DEVICE_PROPERTY = 'macro_device' as const;
diff --git a/js/app/packages/app/package.json b/js/app/packages/app/package.json
index a4f8b167d0..d6a2f4b242 100644
--- a/js/app/packages/app/package.json
+++ b/js/app/packages/app/package.json
@@ -5,18 +5,8 @@
"type": "module",
"version": "2.5.0",
"scripts": {
- "dev": "bun run dev:web",
- "dev:web": "VITE_PLATFORM=web vite -c vite.config.ts",
- "dev:tauri": "sh -c 'case \"${TAURI_ENV_PLATFORM:-desktop}\" in ios) bun run dev:ios ;; android) bun run dev:android ;; *) bun run dev:desktop ;; esac'",
- "dev:desktop": "VITE_PLATFORM=desktop vite -c vite.desktop.config.ts",
- "dev:ios": "VITE_PLATFORM=ios vite -c vite.ios.config.ts",
- "dev:android": "VITE_PLATFORM=android vite -c vite.android.config.ts",
- "build": "bun run build:web",
- "build:web": "VITE_PLATFORM=web vite build -c vite.config.ts && bun run postbuild:semver",
- "build:tauri": "sh -c 'case \"${TAURI_ENV_PLATFORM:-desktop}\" in ios) bun run build:ios ;; android) bun run build:android ;; *) bun run build:desktop ;; esac'",
- "build:desktop": "VITE_PLATFORM=desktop vite build -c vite.desktop.config.ts && bun run postbuild:semver",
- "build:ios": "VITE_PLATFORM=ios vite build -c vite.ios.config.ts && bun run postbuild:semver",
- "build:android": "VITE_PLATFORM=android vite build -c vite.android.config.ts && bun run postbuild:semver",
+ "dev": "vite -c vite.config.ts",
+ "build": "vite build -c vite.config.ts && bun run postbuild:semver",
"postbuild:semver": "echo $npm_package_version+$(git rev-parse --short HEAD) > ./dist/semver.txt",
"preview:dev": "vite preview -c vite-ci.config.ts --outDir dist --base /app",
"preview:prod": "vite preview -c vite-ci.config.ts --outDir dist --base /app",
diff --git a/js/app/packages/app/vite-env.d.ts b/js/app/packages/app/vite-env.d.ts
index dcbec3a025..815845479e 100644
--- a/js/app/packages/app/vite-env.d.ts
+++ b/js/app/packages/app/vite-env.d.ts
@@ -2,7 +2,6 @@ interface ImportMetaEnv {
readonly __APP_VERSION__: string;
readonly __LOCAL_JWT__: string;
readonly __GIT_BRANCH__: string;
- readonly VITE_PLATFORM: 'web' | 'desktop' | 'ios' | 'android';
readonly VITE_SEGMENT_WRITE_KEY: string;
readonly VITE_DD_WEB_APP_ID: string;
diff --git a/js/app/packages/app/vite.android.config.ts b/js/app/packages/app/vite.android.config.ts
deleted file mode 100644
index 2651a9efaa..0000000000
--- a/js/app/packages/app/vite.android.config.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import { defineConfig } from 'vite';
-import { createAppViteConfig } from './vite.base.ts';
-
-export default defineConfig(createAppViteConfig({ platform: 'android' }));
diff --git a/js/app/packages/app/vite.base.ts b/js/app/packages/app/vite.base.ts
index e98aa4ac0a..905881a3d0 100644
--- a/js/app/packages/app/vite.base.ts
+++ b/js/app/packages/app/vite.base.ts
@@ -78,22 +78,10 @@ function gitBranchHmrPlugin(): Plugin {
};
}
-const PLATFORMS = ['web', 'desktop', 'ios', 'android'] as const;
-
-export type AppPlatform = (typeof PLATFORMS)[number];
-
-export interface CreateAppViteConfigOptions {
- platform: AppPlatform;
-}
-
-export const createAppViteConfig = ({
- platform,
-}: CreateAppViteConfigOptions): UserConfigFn => {
+export const createAppViteConfig = (): UserConfigFn => {
return ({ command, mode }) => {
const ENV_MODE = process.env.MODE ?? mode;
const NO_MINIFY = process.env.NO_MINIFY === 'true';
- const isLegacyTauriBuild = process.env.VITE_TAURI === 'true';
- const _isTauriPlatform = platform !== 'web' || isLegacyTauriBuild;
return {
base: command === 'serve' ? '/' : '/app',
@@ -116,7 +104,7 @@ export const createAppViteConfig = ({
}),
gitBranchHmrPlugin(),
],
- define: defineEnv(ENV_MODE, command, platform),
+ define: defineEnv(ENV_MODE, command),
clearScreen: false,
worker: {
format: 'es',
@@ -234,10 +222,9 @@ function getAssetsPath(mode: string, command: string): string {
}
}
-function defineEnv(mode: string, command: string, platform: AppPlatform) {
+function defineEnv(mode: string, command: string) {
return {
'import.meta.env.__APP_VERSION__': JSON.stringify(appVersion),
- 'import.meta.env.VITE_PLATFORM': JSON.stringify(platform),
'import.meta.env.ASSETS_PATH': JSON.stringify(getAssetsPath(mode, command)),
'import.meta.env.__LOCAL_DOCKER__': process.env.LOCAL_DOCKER === 'true',
'import.meta.env.__LOCAL_JWT__': JSON.stringify(process.env.LOCAL_JWT),
diff --git a/js/app/packages/app/vite.config.ts b/js/app/packages/app/vite.config.ts
index 1d655c4e46..41e61c6f1e 100644
--- a/js/app/packages/app/vite.config.ts
+++ b/js/app/packages/app/vite.config.ts
@@ -1,4 +1,4 @@
import { defineConfig } from 'vite';
import { createAppViteConfig } from './vite.base.ts';
-export default defineConfig(createAppViteConfig({ platform: 'web' }));
+export default defineConfig(createAppViteConfig());
diff --git a/js/app/packages/app/vite.desktop.config.ts b/js/app/packages/app/vite.desktop.config.ts
deleted file mode 100644
index 4758442e0a..0000000000
--- a/js/app/packages/app/vite.desktop.config.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import { defineConfig } from 'vite';
-import { createAppViteConfig } from './vite.base.ts';
-
-export default defineConfig(createAppViteConfig({ platform: 'desktop' }));
diff --git a/js/app/packages/app/vite.ios.config.ts b/js/app/packages/app/vite.ios.config.ts
deleted file mode 100644
index d5f9b03be1..0000000000
--- a/js/app/packages/app/vite.ios.config.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import { defineConfig } from 'vite';
-import { createAppViteConfig } from './vite.base.ts';
-
-export default defineConfig(createAppViteConfig({ platform: 'ios' }));
diff --git a/js/app/packages/core/util/platform.ts b/js/app/packages/core/util/platform.ts
index 1ade6704a7..590d5deaf9 100644
--- a/js/app/packages/core/util/platform.ts
+++ b/js/app/packages/core/util/platform.ts
@@ -1,23 +1,21 @@
+import { type as osType } from '@tauri-apps/plugin-os';
+
export type MacroPlatform = 'web' | 'desktop' | 'ios' | 'android';
export type NativeMobilePlatform = Extract<MacroPlatform, 'ios' | 'android'>;
-const VALID_PLATFORMS: ReadonlyArray<MacroPlatform> = [
- 'web',
- 'desktop',
- 'ios',
- 'android',
-];
-
-function resolveBuildPlatform(): MacroPlatform {
- const platform = import.meta.env.VITE_PLATFORM;
- if (platform && VALID_PLATFORMS.includes(platform)) return platform;
- return 'web';
-}
+let cached: MacroPlatform | undefined;
-const buildPlatform = resolveBuildPlatform();
+function detectPlatform(): MacroPlatform {
+ if (!isTauri()) return 'web';
+ const os = osType();
+ if (os === 'ios') return 'ios';
+ if (os === 'android') return 'android';
+ return 'desktop';
+}
export function getPlatform(): MacroPlatform {
- return buildPlatform;
+ if (cached === undefined) cached = detectPlatform();
+ return cached;
}
export function isPlatform(target: MacroPlatform | MacroPlatform[]): boolean {
diff --git a/js/app/tauri/src-tauri/README.md b/js/app/tauri/src-tauri/README.md
index e1ea4e1d56..a621b6b04b 100644
--- a/js/app/tauri/src-tauri/README.md
+++ b/js/app/tauri/src-tauri/README.md
@@ -1,8 +1,9 @@
# Tauri / Mobile Frontend
-This crate wraps the shared web client that lives in `packages/app`. All
-platform-specific behaviour is injected via environment variables and the Vite
-config variants in that package.
+This crate wraps the shared web client that lives in `packages/app`. There is a
+single Vite build that runs identically for web, desktop, iOS, and Android — the
+platform is detected at runtime via `getPlatform()` rather than baked into the
+bundle.
## Running in development
@@ -17,15 +18,8 @@ cargo tauri ios dev
cargo tauri android dev
```
-Tauri sets `TAURI_ENV_PLATFORM` before executing `beforeDevCommand`
-(`bun run dev:tauri`). The scripts in `packages/app` read that variable and pick
-the correct Vite config:
-
-| `TAURI_ENV_PLATFORM` | Script invoked | Resulting `VITE_PLATFORM` |
-| -------------------- | ------------------------- | ------------------------- |
-| `macos`/`windows`/`linux` (default) | `dev:desktop` | `desktop` |
-| `ios` | `dev:ios` | `ios` |
-| `android` | `dev:android` | `android` |
+The `beforeDevCommand` is `just dev-tauri`, which runs `bun run dev` against the
+single `vite.config.ts`.
You can override the dev server host for devices/emulators by exporting
`TAURI_DEV_HOST` before running `cargo tauri …`.
@@ -41,10 +35,9 @@ cargo tauri ios build
cargo tauri android build
```
-The `beforeBuildCommand` is `just build-tauri`, which uses the same
-`TAURI_ENV_PLATFORM` switch to pick the right Vite entrypoint and emit the
-frontend into `packages/app/dist`. Tauri then packages that output according to
-`tauri.conf.json`.
+The `beforeBuildCommand` is `just build-tauri`, which runs `bun run build` and
+emits the frontend into `packages/app/dist`. Tauri then packages that output
+according to `tauri.conf.json`.
## Platform aware UI
diff --git a/rust/cloud-storage/tools/native_app_server/src/main.rs b/rust/cloud-storage/tools/native_app_server/src/main.rs
index ba5bf5cc0d..2ceeefaeb1 100644
--- a/rust/cloud-storage/tools/native_app_server/src/main.rs
+++ b/rust/cloud-storage/tools/native_app_server/src/main.rs
@@ -57,7 +57,7 @@ async fn sha256_hex(path: &Path) -> std::io::Result<String> {
Ok(format!("{:x}", hasher.finalize()))
}
-const ADDR: &str = "127.0.0.1:3001";
+const ADDR: &str = "0.0.0.0:3001";
const ARCHIVE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/app-archive.zip");
#[tokio::main]