@@ -5,7 +5,7 @@ import { format, resolveConfig } from "prettier"
55import { fileURLToPath } from "url"
66import { jsonToZod } from "./json-to-zod.js"
77
8- type TreeResult = { dree : Dree ; allFiles : Dree [ ] }
8+ type TreeResult = { dree : Dree | undefined ; allFiles : Dree [ ] }
99
1010/** Convert a directory tree to a TypeScript type. This is useful for testing
1111 * as the initial state of the test directory is fully known in tests. */
@@ -25,9 +25,9 @@ export function getDirectoryTree(path: string): TreeResult {
2525 dir => {
2626 allFiles . push ( dir )
2727 }
28- )
28+ ) as Dree | null // https://github.com/euberdeveloper/dree/pull/51
2929
30- return { dree : result , allFiles }
30+ return { dree : result ?? undefined , allFiles }
3131}
3232
3333type FileNode = {
@@ -63,10 +63,15 @@ export function convertDree(root: Dree): TreeNode {
6363}
6464
6565export async function buildSchemaForDirectoryTree ( result : TreeResult , name : string ) : Promise < string > {
66- const root = result . dree
67- assert ( root . type === Type . DIRECTORY )
68- const node = convertDree ( root )
69- const schema = ( await jsonToZod ( node , `${ name } Schema` ) ) . split ( "\n" )
66+ let root : TreeNode
67+ if ( result . dree ) {
68+ assert ( result . dree . type === Type . DIRECTORY )
69+ root = convertDree ( result . dree )
70+ } else {
71+ // directory does not exist, or some other problem scanning it
72+ root = { type : Type . DIRECTORY , name : "root" , contents : { } }
73+ }
74+ const schema = ( await jsonToZod ( root , `${ name } Schema` ) ) . split ( "\n" )
7075
7176 const lines = `
7277// Note: This file is autogenerated. Do not edit it directly.
0 commit comments