Skip to content

Commit ba30306

Browse files
committed
🐛 Ship packaged documents that sit in subdirectories (#83)
`packagedDocuments()` lists `src/documents/` recursively and every entry it returns becomes a `copyFile`. A recursive listing names the directories as well as the files inside them, so the first package whose documents are not flat fails the whole npm build with `EINVAL` — "the source path is neither a regular file nor a symlink to a regular file". Nothing had noticed because `packages/cli/src/documents/` is flat. The review graph keeps its documents under `components/` and `policies/`, so it is the first, and `packages/code-review-agent` became a CLI dependency in this stack — which is what put it in the CLI's npm build at all. Only Node and Bun would have seen it: Deno resolves the assets from the source tree and stays green, which is why `scripts/tests/cli-npm-bin.test.ts` is where it surfaced. Verified by building the package: 30 component documents, 5 policies and `components.md` land under `npm/esm/src/`.
1 parent 932bbe4 commit ba30306

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

‎scripts/build-npm.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
import { listWorkspacePaths } from "./lib/workspace.ts";
3939
import { join, sep } from "node:path";
4040
// Recursive directory copy and temp-dir creation are not part of @effectionx/fs.
41-
import { cp, mkdtemp, readdir } from "node:fs/promises";
41+
import { cp, mkdtemp, readdir, stat } from "node:fs/promises";
4242
import { tmpdir } from "node:os";
4343
import { z } from "npm:zod@^4";
4444

@@ -72,8 +72,21 @@ function* packagedDocuments(pkgDir: URL): Operation<string[]> {
7272
if (!(yield* exists(documents))) {
7373
return shipped;
7474
}
75-
const names = yield* until(readdir(fromFileUrl(documents), { recursive: true }));
76-
return [...shipped, ...names.map((name) => `src/documents/${name.split(sep).join("/")}`)];
75+
const root = fromFileUrl(documents);
76+
const names = yield* until(readdir(root, { recursive: true }));
77+
const found: string[] = [];
78+
for (const name of names) {
79+
// A recursive listing names the directories as well as what is in them, and
80+
// each entry here becomes a `copyFile`. Packages whose documents sit flat in
81+
// `src/documents/` never noticed; the review graph keeps its documents under
82+
// `components/` and `policies/`, and copying a directory as a file fails the
83+
// whole npm build with `EINVAL`.
84+
const info = yield* until(stat(join(root, name)));
85+
if (info.isFile()) {
86+
found.push(`src/documents/${name.split(sep).join("/")}`);
87+
}
88+
}
89+
return [...shipped, ...found];
7790
}
7891

7992
const ExportsSchema = z.union([z.string(), z.record(z.string(), z.string())]);

0 commit comments

Comments
 (0)