diff --git a/src/index.ts b/src/index.ts index b3e62ed..efc0a51 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,10 @@ export type DockerComposePortResult = { port: number } +export type DockerComposeVersionResult = { + version: string +} + export interface IDockerComposeLogOptions extends IDockerComposeOptions { follow?: boolean } @@ -377,8 +381,17 @@ export const port = async function ( } } -export const version = function ( +export const version = async function ( options?: IDockerComposeOptions -): Promise { - return execCompose('version', ['--short'], options) +): Promise> { + try { + const result = await execCompose('version', ['--short'], options) + const version = result.out.replace('\n', '') + return { + ...result, + data: { version } + } + } catch (error) { + return Promise.reject(error) + } } diff --git a/test/index.test.ts b/test/index.test.ts index 3a96b79..7d83e28 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -641,7 +641,7 @@ test('removes container', async (): Promise => { }) test('returns version information', async (): Promise => { - const version = await compose.version() + const version = await (await compose.version()).data.version - expect(version.out).toBeTruthy() + expect(version).toMatch(/^(\d+\.)?(\d+\.)?(\*|\d+)$/) })