Skip to content

Commit d68c453

Browse files
thecodedriftclaude
andcommitted
ref(cli): factor the entry-chunk lookup out of assert-prompts-graph
Both lookups in the plugin were the same five-line `Object.values(bundle) .find()` with an inline type predicate, differing only in the entry name. `findEntryChunk` names that operation once and leaves the two call sites reading as what they are. Also renames the traversal variable to `imported`. It holds a chunk file name only when the import resolved inside the bundle; for anything rollup left external it is the bare specifier, which is exactly the case the lookup below is testing for. Calling it `fileName` made the miss look like a lookup bug rather than the check. Behaviour is unchanged: the emitted bundles are byte-identical, and the guard still fails the build with "prompts entry graph imports node:fs" when the prompts entry is given a host-capability import. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jwc9FFroR3mTZ4hLiSkkX3
1 parent 7ae1f2b commit d68c453

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

‎packages/cli/vite.config.ts‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ function shebang(): Plugin {
168168
};
169169
}
170170

171+
/** The entry chunk this build emitted under `name`, if it emitted one. */
172+
function findEntryChunk(
173+
bundle: Rollup.OutputBundle,
174+
name: string
175+
): Rollup.OutputChunk | undefined {
176+
return Object.values(bundle).find(
177+
(chunk): chunk is Rollup.OutputChunk =>
178+
chunk.type === "chunk" && chunk.isEntry && chunk.name === name
179+
);
180+
}
181+
171182
/**
172183
* Refuse to emit a prompts entry that drags the CLI runtime along with it.
173184
*
@@ -198,40 +209,34 @@ function assertPromptsGraph(): Plugin {
198209
return {
199210
name: "assert-prompts-graph",
200211
generateBundle(_options, bundle) {
201-
const entry = Object.values(bundle).find(
202-
(chunk): chunk is Rollup.OutputChunk =>
203-
chunk.type === "chunk" &&
204-
chunk.isEntry &&
205-
chunk.name === PROMPTS_ENTRY
206-
);
212+
const entry = findEntryChunk(bundle, PROMPTS_ENTRY);
207213
// Not an error: `build:self`/`build:dev` and any future single-entry
208214
// build legitimately emit no prompts entry. Nothing to check, not a
209215
// failure to check it.
210216
if (entry === undefined) return;
211217

212-
const binFile = Object.values(bundle).find(
213-
(chunk): chunk is Rollup.OutputChunk =>
214-
chunk.type === "chunk" && chunk.isEntry && chunk.name === BIN_ENTRY
215-
)?.fileName;
218+
const binFile = findEntryChunk(bundle, BIN_ENTRY)?.fileName;
216219

217220
const seen = new Set<string>();
218221
const queue = [entry.fileName];
219222
while (queue.length > 0) {
220-
const fileName = queue.pop()!;
221-
if (seen.has(fileName)) continue;
222-
seen.add(fileName);
223+
// A chunk's file name, or — for anything rollup left external — the
224+
// bare specifier itself, which is why the bundle lookup below can miss.
225+
const imported = queue.pop()!;
226+
if (seen.has(imported)) continue;
227+
seen.add(imported);
223228

224-
const chunk = bundle[fileName];
229+
const chunk = bundle[imported];
225230
if (chunk === undefined || chunk.type !== "chunk") {
226231
// Resolved to something outside the bundle: an external module.
227232
this.error(
228-
`prompts entry graph imports ${fileName}; the render path must not ` +
233+
`prompts entry graph imports ${imported}; the render path must not ` +
229234
`reach a host capability`
230235
);
231236
}
232-
if (binFile !== undefined && fileName === binFile) {
237+
if (imported === binFile) {
233238
this.error(
234-
`prompts entry graph reaches the CLI entry (${fileName}); ` +
239+
`prompts entry graph reaches the CLI entry (${imported}); ` +
235240
`importing @taskless/cli/prompts would load the command layer`
236241
);
237242
}

0 commit comments

Comments
 (0)