2021-08-04 23:53:15 +02:00
|
|
|
export interface MissingDependency {
|
|
|
|
file: string
|
|
|
|
pkg: string
|
|
|
|
}
|
2021-04-30 13:09:07 +02:00
|
|
|
|
2020-05-29 01:39:46 +02:00
|
|
|
export type NecessaryDependencies = {
|
2021-06-15 03:31:40 +02:00
|
|
|
resolved: Map<string, string>
|
2021-08-04 23:53:15 +02:00
|
|
|
missing: MissingDependency[]
|
2020-05-29 01:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function hasNecessaryDependencies(
|
2021-04-30 13:09:07 +02:00
|
|
|
baseDir: string,
|
2021-08-04 23:53:15 +02:00
|
|
|
requiredPackages: MissingDependency[]
|
2020-05-29 01:39:46 +02:00
|
|
|
): Promise<NecessaryDependencies> {
|
|
|
|
let resolutions = new Map<string, string>()
|
|
|
|
const missingPackages = requiredPackages.filter((p) => {
|
|
|
|
try {
|
2021-01-11 15:43:08 +01:00
|
|
|
resolutions.set(p.pkg, require.resolve(p.file, { paths: [baseDir] }))
|
2020-05-29 01:39:46 +02:00
|
|
|
return false
|
|
|
|
} catch (_) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-08-04 23:53:15 +02:00
|
|
|
return {
|
|
|
|
resolved: resolutions,
|
|
|
|
missing: missingPackages,
|
2020-05-29 01:39:46 +02:00
|
|
|
}
|
|
|
|
}
|