File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -5,15 +5,22 @@ import { z } from "zod";
55
66const packageJsonZodType = z . object ( {
77 scripts : z . record ( z . string ( ) , z . string ( ) ) . optional ( ) ,
8+ workspaces : z . array ( z . string ( ) ) . optional ( ) ,
89} ) ;
910
1011export type PackageJson = z . infer < typeof packageJsonZodType > ;
1112
1213export async function readPackageJson (
1314 directory : string = "." ,
1415) : Promise < PackageJson > {
15- const text = await readFile ( path . join ( directory , "package.json" ) , {
16- encoding : "utf8" ,
17- } ) ;
18- return packageJsonZodType . passthrough ( ) . parse ( JSON . parse ( text ) ) ;
16+ const data = JSON . parse (
17+ await readFile ( path . join ( directory , "package.json" ) , {
18+ encoding : "utf8" ,
19+ } ) ,
20+ ) ;
21+
22+ // Using Zod for validation only, not for returning, to preserve the ordering
23+ // of keys in the original data.
24+ packageJsonZodType . parse ( data ) ;
25+ return data ;
1926}
You can’t perform that action at this time.
0 commit comments