Files
Maciej Lisiewski 7062229090 chore(js): switch the workspaces from npm to pnpm
pnpm 12.15.0 (native executable) installs every JS workspace from one
pnpm-lock.yaml, imported from package-lock.json with the same resolved
versions. website/, the WhatsApp bridge and the photon sidecar stay separate
npm projects.

Configuration moves from .npmrc and the root manifest into
pnpm-workspace.yaml: the 14-day minimumReleaseAge and its excludes,
overrides, allowBuilds (the old allowScripts set, with strictDepBuilds
failing any unlisted build script), engineStrict, sideEffectsCache: false
(in-place rebuilds must not write into the store) and
verifyDepsBeforeRun: false (a `pnpm run` never installs).

The pnpm version is pinned in pm/lock.json and in root devEngines.
pmOnFail: ignore keeps that pin out of pnpm-lock.yaml: a leading pin
document makes osv-scanner read zero packages. scripts/build/node-deps.mjs
enforces the exact version instead, and every lock reader refuses a
multi-document lock. A root preinstall refuses `npm install`; devEngines
onFail is warn so npx (MCP servers, the tsc linter) keeps working inside
the checkout.

User-machine installs run --frozen-lockfile --trust-lockfile (release age is
checked when locking, in CI, not per user). node-deps removes npm-era
node_modules trees before the first pnpm install. Nix builds the store with
fetchPnpmDeps and a hash file that CI checks.
2026-11-06 04:08:24 +01:00

73 lines
3.3 KiB
JavaScript

// The source-development composition for the browser-hosted renderer.
//
// Dependencies are installed into a private workspace, never the checkout:
// a frozen install there would relink the native Desktop install (node-pty,
// Electron), and headless hosts have no toolchain for its lifecycle scripts.
// The workspace mirrors exactly the inputs the Webapp receipt covers and keeps
// its node_modules between builds, so pnpm reinstalls only when the lock changes.
import { copyFileSync, mkdirSync, rmSync } from 'node:fs'
import { dirname, join, resolve } from 'node:path'
import { parseArgs } from 'node:util'
import { isMain, repoRoot } from '../../../scripts/build/frontend-common.mjs'
import { sourceEntries } from '../../../scripts/build/freshness.mjs'
import { prepareNodeDependencies } from '../../../scripts/build/node-deps.mjs'
import { buildWebapp } from '../../../scripts/build/webapp.mjs'
/** Make the workspace hash exactly like the checkout for the Webapp product. The filtered
* frozen install needs no other workspace's manifest, so none is copied. */
export function mirrorWebappInputs(source, workspace) {
const wanted = new Map(sourceEntries(source, 'webapp').map(({ name, kind }) => [name, kind]))
// Children before parents. Generated trees (node_modules) are never listed, so never removed.
for (const { name, kind } of sourceEntries(workspace, 'webapp').reverse()) {
if (wanted.get(name) !== kind) rmSync(join(workspace, name), { recursive: true, force: true })
}
for (const [name, kind] of wanted) {
const target = join(workspace, name)
// Loose inputs such as pm/lock.json have no listed parent directory.
mkdirSync(kind === 'directory' ? target : dirname(target), { recursive: true })
if (kind === 'file') copyFileSync(join(source, name), target)
}
}
/** Mirror the inputs into the private workspace and install its dependencies, without compiling.
* On its own it lets an image cache the install in a layer that only the manifests key. */
export function prepareWebappWorkspace({
source = repoRoot, workspace, install = true, prepare = prepareNodeDependencies,
} = {}) {
source = resolve(source)
workspace = resolve(workspace ?? join(source, '.build/webapp-workspace'))
mkdirSync(workspace, { recursive: true })
mirrorWebappInputs(source, workspace)
prepare({
source: workspace, workspaces: ['apps/desktop'], reuse: true, install,
env: { ...process.env, pnpm_config_ignore_scripts: 'true' },
// The browser bundle never runs Electron, so its binary is not downloaded.
electron: false,
})
return { source, workspace }
}
export async function buildSourceWebapp(options = {}) {
const { source, workspace } = prepareWebappWorkspace(options)
return buildWebapp({ source, workspace, out: join(source, 'apps/desktop/dist-webapp') })
}
if (isMain(import.meta.url)) {
try {
const { values } = parseArgs({ options: {
'no-install': { type: 'boolean', default: false },
'deps-only': { type: 'boolean', default: false },
} })
if (values['deps-only']) {
const { workspace } = prepareWebappWorkspace({ install: !values['no-install'] })
console.log(`prepared ${workspace}`)
} else {
const result = await buildSourceWebapp({ install: !values['no-install'] })
console.log(`built ${result.index}`)
}
} catch (error) {
console.error(error)
process.exitCode = 1
}
}