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
| Command | Output | Scope | Use case |
|---|---|---|---|
pnpm export:oss | ../portal-monorepo-oss | Whole monorepo, defaults tenant | Public OSS release |
pnpm export:tenant <tenant> [outputDir] | ../portal-monorepo-<tenant> | Whole monorepo, defaults + one tenant | Tenant handoff |
pnpm export:tenant <tenant> [outputDir] --standalone | ../<tenant>-frontend | Frontend only, one tenant, flat root | Frontend-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:ossRuns three scripts into ../portal-monorepo-oss:
copy-oss.ts— mirrorspackages/**as git sees it (tracked + untracked-but-not-ignored files), so gitignored build output, local tool artifacts and*.generated.jsonnever ship. Keeps only thedefaultstenant: 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 inscripts/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.copy-oss-package.ts— rebuilds the root + frontendpackage.json: drops blacklisted deps and strips instance-specific and internal scripts.prebuildstays, minus the internal generators (generate:rewrites && generate:deployment-id), so the shippeddev/buildregenerate the files the export does not carry.copy-oss-configs.ts— copies the config whitelist, strips thewebpackandturbopacksections fromnext.config.js(theOverridePluginis internal — the export runs on Turbopack), copies a whitelist ofpublic/assets plus the docs screenshots (packages/docs/public/img), copies the rootREADME.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 --standaloneProduces ../<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:
- Mirror + filter — copies the frontend as git sees it (gitignored files never ship), keeping both
defaultsand<tenant>configs/content/icons, filtering every other tenant. - Flatten forks — physically overlays
_<tenant>/(and_opensource/) component forks onto their default siblings, since the resolver plugin does not ship (see gotcha below). - Bake tsconfig — writes a static, tenant-first
tsconfig.json(@configs/@contentresolve<tenant>→defaults;@iconsfalls back todefaultswhen the tenant has no icon overrides). - Transform
next.config.js— stripswebpack/turbopackand rewritesoutputFileTracingRootto__dirname(the frontend is now its own root). - Standalone
package.json— removesworkspaces, resetsdev/build/startto clean Turbopack forms (no--webpack), and merges root-level devDeps (e.g.@types/suncalc) that were previously hoisted. - Assets + env — copies the default public whitelist plus
public/<tenant>/, and writes a non-secret.envwithNEXT_PUBLIC_APP_CONFIGURATION=<tenant>. - 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.jsonA 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.