Skip to content

Commit d9df85c

Browse files
committed
refactor(cli): address review feedback on bundled workspace packaging
- Add JSDoc to bundledWorkspacePackages.mjs (file header + all exports/functions) - Deep-freeze entry objects so mutations cannot desync derived exports - Extend post-build artifact check to cover all bundled workspace packages (previously only checked packages/protocol/dist; now checks dist/ for each package immediately after runTsc so a misconfigured tsconfig is caught early)
1 parent 3919fb0 commit d9df85c

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

apps/cli/scripts/buildSharedDeps.mjs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,10 @@ function sanitizeBundledWorkspacePackageJson(raw) {
140140
export function main() {
141141
for (const pkg of bundledWorkspaceDirs) {
142142
runTsc(resolve(repoRoot, 'packages', pkg, 'tsconfig.json'));
143-
}
144-
145-
const protocolDist = resolve(repoRoot, 'packages', 'protocol', 'dist', 'index.js');
146-
if (!existsSync(protocolDist)) {
147-
throw new Error(`Expected @happier-dev/protocol build output missing: ${protocolDist}`);
143+
const distDir = resolve(repoRoot, 'packages', pkg, 'dist');
144+
if (!existsSync(distDir)) {
145+
throw new Error(`Expected @happier-dev/${pkg} build output missing: ${distDir}`);
146+
}
148147
}
149148

150149
// If the CLI currently has bundled workspace deps under apps/cli/node_modules,

apps/cli/scripts/bundledWorkspacePackages.mjs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,55 @@
1+
/**
2+
* Canonical list of workspace packages that are bundled into the CLI npm package.
3+
*
4+
* This module is the single source of truth consumed by both the build step
5+
* (`buildSharedDeps.mjs`) and the bundle step (`bundleWorkspaceDeps.mjs`).
6+
* Adding or removing a package here automatically keeps both steps in sync.
7+
*/
8+
19
import { resolve } from 'node:path';
210

11+
/**
12+
* Frozen array of all workspace packages that must be compiled and bundled
13+
* during `yarn prepack`. Each entry is itself frozen to prevent accidental
14+
* mutation that could desync the derived exports.
15+
*
16+
* @type {ReadonlyArray<{dirName: string, packageName: string}>}
17+
*/
318
export const bundledWorkspacePackages = Object.freeze([
4-
{ dirName: 'agents', packageName: '@happier-dev/agents' },
5-
{ dirName: 'cli-common', packageName: '@happier-dev/cli-common' },
6-
{ dirName: 'protocol', packageName: '@happier-dev/protocol' },
7-
{ dirName: 'release-runtime', packageName: '@happier-dev/release-runtime' },
19+
Object.freeze({ dirName: 'agents', packageName: '@happier-dev/agents' }),
20+
Object.freeze({ dirName: 'cli-common', packageName: '@happier-dev/cli-common' }),
21+
Object.freeze({ dirName: 'protocol', packageName: '@happier-dev/protocol' }),
22+
Object.freeze({ dirName: 'release-runtime', packageName: '@happier-dev/release-runtime' }),
823
]);
924

25+
/**
26+
* Frozen array of directory names derived from {@link bundledWorkspacePackages}.
27+
* Matches the subdirectory names under `packages/` in the monorepo root.
28+
*
29+
* @type {ReadonlyArray<string>}
30+
*/
1031
export const bundledWorkspaceDirNames = Object.freeze(
1132
bundledWorkspacePackages.map(({ dirName }) => dirName),
1233
);
1334

35+
/**
36+
* Frozen array of npm package names derived from {@link bundledWorkspacePackages}.
37+
* Must stay in sync with the `bundledDependencies` field in `apps/cli/package.json`.
38+
*
39+
* @type {ReadonlyArray<string>}
40+
*/
1441
export const bundledWorkspacePackageNames = Object.freeze(
1542
bundledWorkspacePackages.map(({ packageName }) => packageName),
1643
);
1744

45+
/**
46+
* Creates the bundle descriptor objects used by `bundleWorkspaceDeps.mjs`.
47+
* Each descriptor maps a workspace package to its source directory (in the
48+
* monorepo) and the destination directory under `apps/cli/node_modules`.
49+
*
50+
* @param {{ repoRoot: string, happyCliDir: string }} opts
51+
* @returns {Array<{ packageName: string, srcDir: string, destDir: string }>}
52+
*/
1853
export function createBundledWorkspaceBundles({ repoRoot, happyCliDir }) {
1954
return bundledWorkspacePackages.map(({ dirName, packageName }) => ({
2055
packageName,

0 commit comments

Comments
 (0)