From 51b20b43d6eccac45653553437a546e4ccee51a6 Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Sun, 11 Apr 2021 15:57:29 +0200 Subject: [PATCH] feat: make result for `config --volumes` command type safe --- src/index.ts | 20 +++++++++++++++++--- test/docker-compose-42.yml | 2 +- test/index.test.ts | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index c949b73..7fdece3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,10 @@ export type DockerComposeConfigServicesResult = { services: string[] } +export type DockerComposeConfigVolumesResult = { + volumes: string[] +} + export interface IDockerComposeLogOptions extends IDockerComposeOptions { follow?: boolean } @@ -335,10 +339,20 @@ export const configServices = async function ( } } -export const configVolumes = function ( +export const configVolumes = async function ( options?: IDockerComposeOptions -): Promise { - return execCompose('config', ['--volumes'], options) +): Promise> { + try { + const result = await execCompose('config', ['--volumes'], options) + const nonEmpty = (v: string) => v !== '' + const volumes = result.out.split('\n').filter(nonEmpty) + return { + ...result, + data: { volumes } + } + } catch (error) { + return Promise.reject(error) + } } export const ps = function ( diff --git a/test/docker-compose-42.yml b/test/docker-compose-42.yml index 4d635a2..37b3b65 100644 --- a/test/docker-compose-42.yml +++ b/test/docker-compose-42.yml @@ -5,7 +5,7 @@ services: image: nginx:1.19.9-alpine command: 'nginx -g "daemon off;"' volumes: - - ./volume:/mountedvolume + # - ./volume:/mountedvolume - db-data:/mountedsecondvolume volumes: diff --git a/test/index.test.ts b/test/index.test.ts index 19d145c..48fcf25 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -540,8 +540,9 @@ test('config show data for docker-compose files (volumes)', async (): Promise => {