pnpm workspace with turbo and a second project
A pnpm workspace scaled down from a SaaS monorepo: a Hono API and two Vite apps in apps/, two shared packages in packages/ that turbo builds, and a billing app in apps/billing that is a devlanes project of its own. The lane’s values are part of turbo’s cache key, and the two projects read each other’s URLs.
Requirements
Section titled “Requirements”- devlanes, with
devlanes setuprun once - Node 22.12 or later and pnpm 11
Run it
Section titled “Run it”cd workflows-pnpm-monorepodevlanes startdevlanes start --no-ui prints the start as text:
example-pnpm-monorepo@0 (main): 3/3 readyready api http://127.0.0.1:20581 https://api.example-pnpm-monorepo.localhostready web http://127.0.0.1:20582 https://example-pnpm-monorepo.localhostready admin http://127.0.0.1:20580 https://admin.example-pnpm-monorepo.localhostOpen https://example-pnpm-monorepo.localhost. The page lists the accounts it fetched from https://api.example-pnpm-monorepo.localhost and links to https://admin.example-pnpm-monorepo.localhost and to the billing app. Until a lane of the billing project runs, the billing row says no lane of example-pnpm-billing runs.
During a start
Section titled “During a start”installrunspnpm install --frozen-lockfilefor the whole workspace.build-depsruns the rootbuild-depsscript,turbo run build --filter=./packages/*:tsccompiles@acme/configand@acme/uiintopackages/*/dist, which the apps import. Both tasks havewhen: lane.create, so they run on a lane’s first start until they succeed once, and a fresh worktree needs onlydevlanes start.apiextends theapitemplate (tags: [api], a ready check on/healthz) and runstsx watch src/index.tsinapps/api. It serves https://api.example-pnpm-monorepo.localhost and sends CORS headers to the origins inDEVLANES_ORIGINS.webandadminextend thewebtemplate (preset: vite,tags: [web], a ready check on/) and runviteinapps/webandapps/admin, on https://example-pnpm-monorepo.localhost and https://admin.example-pnpm-monorepo.localhost.
Every service points run_script.file at its own package.json, and devlanes runs the script with pnpm, from packageManager in the root package.json.
Lane values in turbo’s cache key
Section titled “Lane values in turbo’s cache key”global_env sets the lane’s index and URLs as VITE_* on every service and task, and vite build copies them into the bundle: lane 1’s apps/web/dist calls https://api.example-pnpm-monorepo1.localhost. turbo.json lists VITE_* in globalEnv, so they are part of every task’s hash and a lane never replays another lane’s bundle. DEVLANES_* is in globalPassThroughEnv: turbo’s strict env mode hides variables it is not told about, and pass-through hands them to scripts without hashing them.
devlanes run build runs turbo run build with the lane’s environment. A second run in the same lane replays all six builds from the cache and ends with FULL TURBO. Run in the second lane from “Try next”, the packages hit the cache that lane’s build-deps filled and the apps rebuild:
build#8 @acme/ui:build: cache hit, replaying logs 09015a7624513ef7build#10 @acme/config:build: cache hit, replaying logs c93795d22b939a00build#12 @acme/admin:build: cache miss, executing b624b36fe97cbf66build#13 @acme/web:build: cache miss, executing de9968b0fbbdd7b7build#14 @acme/billing:build: cache miss, executing fb273c221a9a1c5ebuild#15 @acme/api:build: cache miss, executing a63eeea76061d385globalEnv applies to every task, so any change to a VITE_* value rebuilds packages/* too. Starting example-pnpm-billing changes VITE_BILLING_URL, and the next devlanes run build in lane 0 reported Cached: 0 cached, 6 total.
A second project in apps/billing
Section titled “A second project in apps/billing”apps/billing/devlanes.yaml declares project: example-pnpm-billing. Commands run anywhere under apps/billing use it, the nearest devlanes.yaml, and the rest of the example uses the root one. example-pnpm-billing has its own lanes, ports and domain, example-pnpm-billing.localhost, and its relative paths start at apps/billing, so run_script.file: package.json is apps/billing/package.json. Its install task runs pnpm install from apps/billing, which installs the whole workspace, and its build-deps builds only what billing imports with turbo run build --filter=@acme/billing^....
The two projects read each other’s URLs through projects.<project>.services, with each dash in the project name written as an underscore:
VITE_BILLING_URL: ${{ projects.example_pnpm_billing.services.web.public_url | default('') }}The value is set when the service starts and is empty while no lane of example-pnpm-billing runs. apps/billing/devlanes.yaml does the same in the other direction with projects.example_pnpm_monorepo.services.web.public_url.
Try next
Section titled “Try next”Start the billing project:
cd apps/billing && devlanes start. https://example-pnpm-billing.localhost showsThis is lane 0 of example-pnpm-billing., three invoices and a link back to https://example-pnpm-monorepo.localhost.Still in
apps/billing,devlanes -p example-pnpm-monorepo restart webrestarts the root project’sweb, which now gets the billing URL, and the billing row on https://example-pnpm-monorepo.localhost becomes a link:Terminal window devlanes -p example-pnpm-monorepo env show web | grep VITE_BILLING_URLVITE_BILLING_URL=https://example-pnpm-billing.localhostStart a second lane:
git worktree add ../examples-checkout -b feat/checkout, thencd ../examples-checkout/workflows-pnpm-monorepo && devlanes start. The new worktree has nonode_modulesorpackages/*/dist, and thelane.createtasks create them.Without a worktree,
devlanes lane new --name example-pnpm-monorepo-review --startadds lane 1 to the same folder. https://example-pnpm-monorepo1.localhost showsThis is lane 1 of example-pnpm-monorepo.and200 from lane 1from https://api.example-pnpm-monorepo1.localhost.cd apps/billing && devlanes lane new --name example-pnpm-billing-review --startdoes the same for billing on https://example-pnpm-billing1.localhost. Lanes added to one folder are all onmain, and each lane 1 links to lane 0 of the other project.From the example’s root,
devlanes statuslists the root project’s lanes anddevlanes -p example-pnpm-billing statusthe billing project’s:example-pnpm-billingLANE BRANCH STATE SERVICES CPU MEM URL0 main running 1/1 0.0% 146.3 MiB https://example-pnpm-billing.localhost1 main running 1/1 0.0% 139.5 MiB https://example-pnpm-billing1.localhostEdit the footer in
packages/ui/src/Page.tsxand rundevlanes run build-deps. turbo rebuilds@acme/ui(cache miss) and replays@acme/config, Vite logshmr update /@fs/.../packages/ui/dist/Page.js, and https://example-pnpm-monorepo.localhost and https://admin.example-pnpm-monorepo.localhost show the new footer. So does https://example-pnpm-monorepo1.localhost, because lanes in one folder sharepackages/*/dist.devlanes run typecheckrunstsc --noEmitin all six packages throughturbo run typecheck, after buildingpackages/*.Remove the lanes:
devlanes lane clean example-pnpm-monorepo-review --yesanddevlanes lane clean 0 --yeshere, thendevlanes -p example-pnpm-billing lane clean example-pnpm-billing-review --yesanddevlanes -p example-pnpm-billing lane clean 0 --yes.
devlanes.yaml: the root project, with theVITE_*lane values inglobal_env, theinstall,build-deps,typecheckandbuildtasks, theapiandwebtemplates and the services.apps/billing/devlanes.yaml: theexample-pnpm-billingproject with its owninstallandbuild-depsand one service.turbo.json:globalEnvandglobalPassThroughEnv, and thebuildandtypechecktasks.packages/config/src/index.ts:serverEnv(),pageEnv()andlaneJson().packages/ui/src/: thePage,CardandLaneCardcomponents the Vite apps share.apps/api/src/: the API, with/api/accounts,/laneand/healthzinapp.ts.