Skip to Content
Technical GuideCode Export

Code Export

The monorepo can emit three kinds of standalone artifacts: a full open-source copy of the codebase (defaults tenant, whole monorepo), a single-tenant monorepo (the same copy with one tenant in it) and a single-tenant frontend promoted to its own repo. All strip the internals that must not ship and produce an installable project.

Pair a tenant export with Feature Removal to produce a lean build: export the tenant, then delete the code behind its disabled flags. See also Multi-tenant System for how overrides resolve.

Three products

CommandOutputScopeUse case
pnpm export:oss../portal-monorepo-ossWhole monorepo, defaults tenantPublic OSS release
pnpm export:tenant <tenant> [outputDir]../portal-monorepo-<tenant>Whole monorepo, defaults + one tenantTenant handoff
pnpm export:tenant <tenant> [outputDir] --standalone../<tenant>-frontendFrontend only, one tenant, flat rootFrontend-only handoff

export:tenant <tenant> [outputDir] is the backend’s command too (npm run export:tenant). outputDir replaces the default output folder.

All share pure helpers in scripts/oss-shared.ts (exclusion globs, file scan, the next.config brace-matcher, package.json filtering, the fork flattener and the destination cleanup).

Every export empties its output folder except .git. Files deleted from the source do not linger, and a clone of the published repo kept right in the output folder shows each export as a diff to review and commit — no separate working copy to copy into.

Open-source monorepo export

pnpm export:oss

Runs three scripts into ../portal-monorepo-oss:

  1. copy-oss.ts — mirrors packages/** as git sees it (tracked + untracked-but-not-ignored files), so gitignored build output, local tool artifacts and *.generated.json never ship. Keeps only the defaults tenant: excludes every other tenant (config folders and _<tenant>/ component forks), secrets (.env*), the override machinery (webpack-override.js, turbopack-override.js, generate-tsconfig.js, fetch-features.ts), middleware.ts, our Heroku hosting tooling, and one-off client-feed tooling with its data (the blacklist lives in scripts/oss-shared.ts). The frontend’s own .npmrc + pnpm-lock.yaml (its standalone Heroku install) stay behind — the workspace installs from the root ones. _opensource/ override folders are flattened onto their siblings.
  2. copy-oss-package.ts — rebuilds the root + frontend package.json: drops blacklisted deps and strips instance-specific and internal scripts. prebuild stays, minus the internal generators (generate:rewrites && generate:deployment-id), so the shipped dev/build regenerate the files the export does not carry.
  3. copy-oss-configs.ts — copies the config whitelist, strips the webpack and turbopack sections from next.config.js (the OverridePlugin is internal — the export runs on Turbopack), copies a whitelist of public/ assets plus the docs screenshots (packages/docs/public/img), copies the root README.md + LICENSE + pnpm-workspace.yaml + .npmrc + .gitignore + pnpm-lock.yaml, then prunes that lockfile to the exported packages (pnpm install --lockfile-only) — so the export installs the versions the monorepo tested.

The export ships both docs sites inside the portal: pnpm frontend:build:docs builds them as static exports into packages/portal-frontend/public/documentation (served at /documentation, /documentation/frontend, /documentation/backend); run it before pnpm frontend:build / pnpm frontend:dev. pnpm frontend:clean:docs removes them. In that build each site’s navbar links the hub (All Docs) and the sibling site (desktop only); the standalone docs builds omit those links.

Standalone tenant export

pnpm export:tenant <tenant> --standalone # e.g. pnpm export:tenant justinhavre-avm --standalone

Produces ../<tenant>-frontend/ — the contents of packages/portal-frontend promoted to the repo root (no monorepo wrapper, no ai-agent-client / docs / backend). scripts/export-tenant.ts:

  1. Mirror + filter — copies the frontend as git sees it (gitignored files never ship), keeping both defaults and <tenant> configs/content/icons, filtering every other tenant.
  2. Flatten forks — physically overlays _<tenant>/ (and _opensource/) component forks onto their default siblings, since the resolver plugin does not ship (see gotcha below).
  3. Bake tsconfig — writes a static, tenant-first tsconfig.json (@configs/@content resolve <tenant> → defaults; @icons falls back to defaults when the tenant has no icon overrides).
  4. Transform next.config.js — strips webpack/turbopack and rewrites outputFileTracingRoot to __dirname (the frontend is now its own root).
  5. Standalone package.json — removes workspaces, resets dev/build/start to clean Turbopack forms (no --webpack), and merges root-level devDeps (e.g. @types/suncalc) that were previously hoisted.
  6. Assets + env — copies the default public whitelist plus public/<tenant>/, and writes a non-secret .env with NEXT_PUBLIC_APP_CONFIGURATION=<tenant>.
  7. Lockfile — generates pnpm-lock.yaml (pnpm install --lockfile-only).

The config alias mechanism stays live (tenant-first tsconfig paths), while the component _<tenant>/ forks are resolved at export time by flattening.

Gotchas

Exports install with pnpm and run on Turbopack. Both exports ship a pnpm-lock.yaml (matching the monorepo and the Heroku deploy) — install with pnpm install, not npm. Because the webpack block is stripped, the exports run on Turbopack — dev and build alike (build-remote.js picks Turbopack when webpack-override.js is not shipped); the OverridePlugin (and --webpack) stay in the main repo only, where _<tenant>/ forks still need the resolver. A side effect: deep type-imports into a package’s .d.ts tree (e.g. recharts/types/util/types) that webpack tolerated will fail Turbopack resolution — import the type from the package’s public entry instead.

Fork flattening rewrites relative imports. A fork file lives one directory deeper (inside _<tenant>/), so it is authored with an extra .. to reach the real tree (../components in a fork means the sibling components/). When flattened up a level, the flattener strips one .. from every specifier that climbs out of the fork, and removes any competing parent file/dir of the same base name so the fork wins default resolution.

The export is the first full type-check of a tenant. In the monorepo, tsc always sees the defaults components — the _<tenant>/ overrides are webpack-only. After a tenant export the overrides are flattened in, so pnpm --filter portal-frontend type-check in the exported folder surfaces tenant-only type issues for the first time. Only TS2307 (module-not-found) breaks the build; the rest is tolerated by typescript.ignoreBuildErrors.

Two traps to re-audit on any rename. (1) The copy scripts hardcode source filenames, so renaming a root config or a scripts/ file silently breaks the export — re-audit oss-shared.ts + the three copy scripts. (2) A shared/default file that hardcodes another tenant’s _<other>/ path breaks every export that strips that tenant; grep from '..._<tenant>/' in non-fork files.

/documentation is served only while the folder exists. generate-rewrites.ts emits the /documentation rewrites (and thereby the route-guard allowlist) only when public/documentation is present, so build:docs / clean:docs regenerate the rewrites themselves. Restart a running dev server afterwards. On a Heroku deploy the docs are built in the Bitbucket pipeline (Heroku only sees packages/portal-frontend), opted in per deployment with BUILD_DOCUMENTATION=true.

After export

cd ../<tenant>-frontend pnpm install pnpm build # or: npx tsc --noEmit -p tsconfig.json

A full production build also needs the tenant’s runtime env (API proxy URL, Mapbox key, etc.) — the export ships only the non-secret tenant selector. To trim further, apply the Feature Removal map for the tenant’s disabled flags.

Last updated on