Skip to content

Commit 86761b0

Browse files
committed
sorting
1 parent bcdad65 commit 86761b0

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,28 @@ describe("Find entrypoint", () => {
510510
},
511511
};
512512

513+
const mainFile = findEntrypointFile(ft);
514+
expect(mainFile).toBe("aaa-dir/main.tf");
515+
});
516+
it("with dirs, multiple main.tf, unordered file tree", () => {
517+
const ft: FileTree = {
518+
"ccc-dir": {
519+
"aaa.tf": "hello",
520+
"bbb.tf": "world",
521+
"main.tf": "foobar",
522+
},
523+
"aaa-dir": {
524+
"aaa.tf": "hello",
525+
"bbb.tf": "world",
526+
"main.tf": "foobar",
527+
},
528+
"zzz-dir": {
529+
"aaa.tf": "hello",
530+
"bbb.tf": "world",
531+
"main.tf": "foobar",
532+
},
533+
};
534+
513535
const mainFile = findEntrypointFile(ft);
514536
expect(mainFile).toBe("aaa-dir/main.tf");
515537
});

site/src/utils/filetree.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ test("traverse() go trough all the file tree files", () => {
122122
traverse(fileTree, (_content, _filename, fullPath) => {
123123
filePaths.push(fullPath);
124124
});
125-
const expectedFilePaths = ["main.tf", "images", "images/java.Dockerfile"];
125+
const expectedFilePaths = ["images", "images/java.Dockerfile", "main.tf"];
126126
expect(filePaths).toEqual(expectedFilePaths);
127127
});

site/src/utils/filetree.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ export const traverse = (
9696
) => void,
9797
parent?: string,
9898
) => {
99-
for (const [filename, content] of Object.entries(fileTree)) {
99+
for (const [filename, content] of Object.entries(fileTree).sort(([a], [b]) =>
100+
a.localeCompare(b),
101+
)) {
100102
const fullPath = parent ? `${parent}/${filename}` : filename;
101103
callback(content, filename, fullPath);
102104
if (typeof content === "object") {

0 commit comments

Comments
 (0)