Skip to content

Commit bf4bf1a

Browse files
fix(web): a bare filename on a fence's first line labels the package file (CL-8517) (#911)
1 parent 9c38b64 commit bf4bf1a

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

apps/web/src/chat/deployable-package.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ describe("deployablePackageFromBody", () => {
3030
expect(result?.strippedBody).toBe("Here is the package:\n\nPress Deploy.");
3131
});
3232

33+
test("reads a bare filename on the fence's first line", () => {
34+
const body =
35+
`\`\`\`json\npackage.json\n${PACKAGE_JSON}\n\`\`\`\n\n` +
36+
`\`\`\`json\ndefinition.json\n${DEFINITION_JSON}\n\`\`\``;
37+
expect(deployablePackageFromBody(body)?.pkg.name).toBe("Echo");
38+
});
39+
3340
test("is null when only one of the two files is present", () => {
3441
const body = `package.json\n\`\`\`\n${PACKAGE_JSON}\n\`\`\``;
3542
expect(deployablePackageFromBody(body)).toBeNull();

apps/web/src/chat/deployable-package.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,14 @@ function findNamedFencedBlocks(lines: readonly string[]): Map<string, FencedBloc
119119
}
120120
const end = Math.min(index + 1, lines.length);
121121
index = end;
122-
// A comment label on the fence's first line (`// Scribe/definition.json`)
123-
// names the file too; it is not part of the file.
122+
// A label on the fence's first line (`// Scribe/definition.json`, or the
123+
// bare filename) names the file too; it is not part of the file.
124124
if (name === null) {
125125
const firstContent = contentLines.findIndex((content) => content.trim() !== "");
126-
const first = contentLines[firstContent] ?? "";
127-
if (/^\s*(\/\/|#)/.test(first)) {
128-
const fromComment = namedFile(first);
129-
if (fromComment !== null) {
130-
name = fromComment;
131-
contentLines.splice(0, firstContent + 1);
132-
}
126+
const fromFirstLine = namedFile(contentLines[firstContent] ?? "");
127+
if (fromFirstLine !== null) {
128+
name = fromFirstLine;
129+
contentLines.splice(0, firstContent + 1);
133130
}
134131
}
135132
if (name !== null && !found.has(name)) {

0 commit comments

Comments
 (0)