77 echo ' Starting development build 🐣'
88fi
99
10+ # Optional Vite mode forwarded to every `vite build`. Empty by default so the
11+ # existing builds keep running in Vite's default production mode.
12+ MODE_ARG=" "
13+
14+ # ## Local backend target (ADDON_ENV=local, via build:dev:system:local).
15+ # ## Points the bundle at a locally running Send backend + client instead of the
16+ # ## prod/stage hosts baked into the developer's .env.
17+ if [ " $ADDON_ENV " = " local" ]; then
18+ echo ' Targeting local backend (localhost) 🏠'
19+ # ## Vite `build` defaults to production mode regardless of NODE_ENV. Force
20+ # ## development so import.meta.env.MODE === 'development': that makes the
21+ # ## frontend probe the local backend for its storage type (api.ts), sets
22+ # ## IS_DEV, and keeps prod Sentry off (sentry.ts). Production mode would
23+ # ## instead assume bucket storage and skip that probe.
24+ MODE_ARG=" --mode development"
25+
26+ # ## Force localhost URLs. Exported so Vite's loadEnv reads them from
27+ # ## process.env, where VITE_* vars take precedence over the .env file — whose
28+ # ## prod block (send.tb.pro / send-backend.tb.pro) would otherwise win via
29+ # ## last-key-wins. Assigned with := so a developer can still override any of
30+ # ## them inline (e.g. a different local port) before invoking the build.
31+ : " ${VITE_SEND_SERVER_URL:= https:// localhost: 8088} "
32+ : " ${VITE_SEND_CLIENT_URL:= http:// localhost: 5173} "
33+ # ## No local Keycloak: authenticate against the stage identity provider.
34+ : " ${VITE_OIDC_CLIENT_ID:= desktop} "
35+ : " ${VITE_OIDC_ROOT_URL:= https:// auth-stage.tb.pro/ realms/ tbpro/ } "
36+ # ## Keep local builds out of the shared Sentry / PostHog projects.
37+ : " ${VITE_SENTRY_DSN:= } "
38+ : " ${VITE_POSTHOG_PROJECT_KEY:= } "
39+ export VITE_SEND_SERVER_URL VITE_SEND_CLIENT_URL \
40+ VITE_OIDC_CLIENT_ID VITE_OIDC_ROOT_URL \
41+ VITE_SENTRY_DSN VITE_POSTHOG_PROJECT_KEY
42+
43+ echo " VITE_SEND_SERVER_URL=$VITE_SEND_SERVER_URL "
44+ echo " VITE_SEND_CLIENT_URL=$VITE_SEND_CLIENT_URL "
45+ echo " VITE_OIDC_ROOT_URL=$VITE_OIDC_ROOT_URL "
46+ # ## CORS: the Send backend auto-allows any moz-extension:// origin
47+ # ## (origins.ts), and the built-in/system add-on still runs under a
48+ # ## moz-extension:// origin, so its requests pass CORS unchanged. The local
49+ # ## backend must still have SEND_BACKEND_CORS_ORIGINS set (it throws
50+ # ## otherwise) and include $VITE_SEND_CLIENT_URL, and Thunderbird must trust
51+ # ## the self-signed https://localhost cert (used for fetch + wss uploads).
52+ fi
53+
1054# Get version from package.json and replace dots with hyphens
1155VERSION=$( jq -r .version < package.json | sed ' s/\./-/g' )
1256
@@ -36,7 +80,7 @@ node scripts/subset-fonts.mjs
3680echo " ================================================================"
3781echo " =============== extension UI ==================================="
3882# ## Extension UI
39- vite build --config vite.config.extension.js
83+ vite build --config vite.config.extension.js $MODE_ARG
4084cp -R dist/extension/assets/* dist/assets/
4185cp -R dist/extension/* .* dist/
4286if [ -d dist/extension/chunks ]; then
@@ -48,7 +92,7 @@ rm -rf dist/extension
4892echo " ================================================================"
4993echo " =============== management page================================="
5094# ## Management page, commenting out for now
51- vite build --config vite.config.management.js
95+ vite build --config vite.config.management.js $MODE_ARG
5296cp -R dist/pages/assets/* dist/assets/
5397cp -R dist/pages/* .* dist/
5498if [ -d dist/pages/chunks ]; then
@@ -100,14 +144,30 @@ find dist/assets -name '*.css' -exec perl -pi -e \
100144echo " ================================================================"
101145echo " =============== background.js =================================="
102146# ## Build `background.js` as a library
103- vite build --config vite.config.background.js
147+ vite build --config vite.config.background.js $MODE_ARG
104148cp -R dist/background/* dist/
105149# cp -R dist/background/*.map dist/f
106150# cp -R dist/background/manifest.json dist/
107151rm -rf dist/background
108152
109153rm -rf dist/pages
110154
155+ # ## When building the system/built-in add-on variant (ADDON_VARIANT=system),
156+ # ## rewrite the built dist manifest's prod id to the system add-on id
157+ # ## (tbpro-system-add-on@thunderbird.net) so the local build matches the id
158+ # ## Thunderbird ships it under and exercises the id-keyed runtime guards
159+ # ## (installGate.ts / selfUninstall.ts). Operates on the built copy only — the
160+ # ## source public/manifest.json keeps the prod id. Reuses set-system-id.ts, the
161+ # ## same script CI uses when repacking the system XPI.
162+ if [ " $ADDON_VARIANT " = " system" ]; then
163+ echo " ================================================================"
164+ echo " =============== system add-on id ==============================="
165+ # ## --allow-stage: a dev build's dist manifest carries the STAGE id (set-id.ts
166+ # ## only runs for prod), so accept STAGE too. CI's prod-XPI repack omits the
167+ # ## flag and keeps its strict PROD-only guard.
168+ bun run scripts/set-system-id.ts dist/manifest.json --allow-stage
169+ fi
170+
111171cd dist
112172# Create xpi with version number
113173zip -r -FS ../tbpro-addon-${VERSION} .xpi *
0 commit comments