Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/web/src/chat/deployable-package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ describe("deployablePackageFromBody", () => {
expect(result?.strippedBody).toBe("Here is the package:\n\nPress Deploy.");
});

test("reads a bare filename on the fence's first line", () => {
const body =
`\`\`\`json\npackage.json\n${PACKAGE_JSON}\n\`\`\`\n\n` +
`\`\`\`json\ndefinition.json\n${DEFINITION_JSON}\n\`\`\``;
expect(deployablePackageFromBody(body)?.pkg.name).toBe("Echo");
});

test("is null when only one of the two files is present", () => {
const body = `package.json\n\`\`\`\n${PACKAGE_JSON}\n\`\`\``;
expect(deployablePackageFromBody(body)).toBeNull();
Expand Down
15 changes: 6 additions & 9 deletions apps/web/src/chat/deployable-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,14 @@ function findNamedFencedBlocks(lines: readonly string[]): Map<string, FencedBloc
}
const end = Math.min(index + 1, lines.length);
index = end;
// A comment label on the fence's first line (`// Scribe/definition.json`)
// names the file too; it is not part of the file.
// A label on the fence's first line (`// Scribe/definition.json`, or the
// bare filename) names the file too; it is not part of the file.
if (name === null) {
const firstContent = contentLines.findIndex((content) => content.trim() !== "");
const first = contentLines[firstContent] ?? "";
if (/^\s*(\/\/|#)/.test(first)) {
const fromComment = namedFile(first);
if (fromComment !== null) {
name = fromComment;
contentLines.splice(0, firstContent + 1);
}
const fromFirstLine = namedFile(contentLines[firstContent] ?? "");
if (fromFirstLine !== null) {
name = fromFirstLine;
contentLines.splice(0, firstContent + 1);
}
}
if (name !== null && !found.has(name)) {
Expand Down
Loading