import { EOL } from "os" ; import { promises as fs } from "fs" ; import { log } from "./logger" ; import { DockerImageName } from "./docker-image-name" ; export const getDockerfileImages = async ( dockerfile ) : Promise < DockerImageName [ ] > => { try { return Array . from ( ( await fs . readFile ( dockerfile , "utf8" ) ) . split ( EOL ) . filter ( ( line ) => line . toUpperCase ( ) . startsWith ( "FROM" ) ) . map ( ( line ) => { const parts = line . split ( " " ) ; return parts [ parts . length - 1 ] ; } ) . reduce ( ( prev , next ) => prev . add ( next ) , new Set < string > ( ) ) . values ( ) ) . map ( ( image ) => DockerImageName . fromString ( image ) ) ; } catch ( err ) { log . error ( `Failed to read Dockerfile "${ dockerfile }": ${ err }` ) ; throw err ; } } ;