@@ -18,6 +18,7 @@ type Schema = {
1818 dependencies ?: Record < string , string >
1919 devDependencies ?: Record < string , string >
2020 private ?: boolean
21+ workspaces ?: string [ ]
2122}
2223
2324export interface EngineSupportResult {
@@ -67,6 +68,10 @@ export class PackageJsonFile {
6768 return this . jsonFile . data . engines
6869 }
6970
71+ public get workspaces ( ) {
72+ return this . jsonFile . data . workspaces
73+ }
74+
7075 supportsEngine ( engine : string , version : string ) : EngineSupportResult {
7176 const requirements = this . engines ?. [ engine ]
7277 if ( requirements === undefined ) {
@@ -105,6 +110,24 @@ export class PackageJsonFile {
105110 return new PackageJsonFile ( jsonFile )
106111 }
107112
113+ static async loadFromSourceFile ( sourceFile : SourceFile ) : Promise < PackageJsonFile | undefined > {
114+ const jsonSourceFile = await JsonSourceFile . loadFromSourceFile < Schema > ( sourceFile )
115+ if ( ! jsonSourceFile ) {
116+ return
117+ }
118+
119+ return PackageJsonFile . loadFromJsonSourceFile ( jsonSourceFile )
120+ }
121+
122+ static async loadFromFilePath ( filePath : string ) : Promise < PackageJsonFile | undefined > {
123+ const sourceFile = await SourceFile . loadFromFilePath ( filePath )
124+ if ( ! sourceFile ) {
125+ return
126+ }
127+
128+ return PackageJsonFile . loadFromSourceFile ( sourceFile )
129+ }
130+
108131 static filePath ( dirPath : string ) {
109132 return path . join ( dirPath , PackageJsonFile . FILENAME )
110133 }
0 commit comments