Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ export class JsonSourceFile<Schema> {
// Ignore.
}
}

static async loadFromFilePath<Schema> (filePath: string): Promise<JsonSourceFile<Schema> | undefined> {
const sourceFile = await SourceFile.loadFromFilePath(filePath)
if (!sourceFile) {
return
}

return JsonSourceFile.loadFromSourceFile(sourceFile)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Schema = {
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
private?: boolean
workspaces?: string[]
}

export interface EngineSupportResult {
Expand Down Expand Up @@ -67,6 +68,10 @@ export class PackageJsonFile {
return this.jsonFile.data.engines
}

public get workspaces () {
return this.jsonFile.data.workspaces
}

supportsEngine (engine: string, version: string): EngineSupportResult {
const requirements = this.engines?.[engine]
if (requirements === undefined) {
Expand Down Expand Up @@ -105,6 +110,24 @@ export class PackageJsonFile {
return new PackageJsonFile(jsonFile)
}

static async loadFromSourceFile (sourceFile: SourceFile): Promise<PackageJsonFile | undefined> {
const jsonSourceFile = await JsonSourceFile.loadFromSourceFile<Schema>(sourceFile)
if (!jsonSourceFile) {
return
}

return PackageJsonFile.loadFromJsonSourceFile(jsonSourceFile)
}

static async loadFromFilePath (filePath: string): Promise<PackageJsonFile | undefined> {
const sourceFile = await SourceFile.loadFromFilePath(filePath)
if (!sourceFile) {
return
}

return PackageJsonFile.loadFromSourceFile(sourceFile)
}

static filePath (dirPath: string) {
return path.join(dirPath, PackageJsonFile.FILENAME)
}
Expand Down
Loading
Loading