From 0e3e990e194f81a478d689038f7bbec4711f426f Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Thu, 15 Aug 2024 09:33:45 +0200 Subject: [PATCH] BREAKING_CHANGE: replace v2 as default package exports --- package.json | 3 +- src/{v2.ts => index.ts} | 2 +- src/v2-map-ports.ts | 38 -------------------------- test/{v2 => }/build-test.Dockerfile | 0 test/{v2 => }/compose.test.ts | 4 +-- test/{v2 => }/docker-compose-2.yml | 0 test/{v2 => }/docker-compose-42.yml | 0 test/{v2 => }/docker-compose-build.yml | 0 test/{v2 => }/docker-compose-echo.yml | 0 test/{v2 => }/docker-compose.yml | 0 test/{v2 => }/map-ports.test.ts | 2 +- 11 files changed, 5 insertions(+), 44 deletions(-) rename src/{v2.ts => index.ts} (99%) delete mode 100644 src/v2-map-ports.ts rename test/{v2 => }/build-test.Dockerfile (100%) rename test/{v2 => }/compose.test.ts (99%) rename test/{v2 => }/docker-compose-2.yml (100%) rename test/{v2 => }/docker-compose-42.yml (100%) rename test/{v2 => }/docker-compose-build.yml (100%) rename test/{v2 => }/docker-compose-echo.yml (100%) rename test/{v2 => }/docker-compose.yml (100%) rename test/{v2 => }/map-ports.test.ts (97%) diff --git a/package.json b/package.json index bc344c623..b04c46d18 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,7 @@ "types": "dist/index.d.ts", "scripts": { "ci": "yarn install --frozen-lockfile", - "test-v1": "npx vitest --dir test/v1 --test-timeout=30000", - "test-v2": "npx vitest --dir test/v2 --test-timeout=30000", + "test": "npx vitest --dir test --test-timeout=30000", "lint": "eslint src/**/*.ts test/**/*.ts", "build": "tsc", "prepublishOnly": "tsc", diff --git a/src/v2.ts b/src/index.ts similarity index 99% rename from src/v2.ts rename to src/index.ts index 193459dbc..9058629c3 100644 --- a/src/v2.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import childProcess from 'child_process' import yaml from 'yaml' -import mapPorts from './v2-map-ports' +import mapPorts from './map-ports' export interface IDockerComposeExecutableOptions { executablePath: string diff --git a/src/v2-map-ports.ts b/src/v2-map-ports.ts deleted file mode 100644 index 417169ce6..000000000 --- a/src/v2-map-ports.ts +++ /dev/null @@ -1,38 +0,0 @@ -const mapPorts = ( - ports: string -): Array<{ - mapped?: { address: string; port: number } - exposed: { port: number; protocol: string } -}> => { - if (!ports) { - return [] - } - - return ports.split(',').map((untypedPort) => { - const exposedFragments = untypedPort.trim().split('->') - - const [port, protocol] = - exposedFragments.length === 1 - ? exposedFragments[0].split('/') - : exposedFragments[1].split('/') - - const mapped = exposedFragments[0] - const lastDoubleColon = mapped.lastIndexOf(':') - - if (lastDoubleColon === -1) { - return { - exposed: { port: Number(port), protocol } - } - } - - const address = mapped.substr(0, lastDoubleColon) - const mappedPort = mapped.substr(lastDoubleColon + 1) - - return { - exposed: { port: Number(port), protocol }, - mapped: { port: Number(mappedPort), address } - } - }) -} - -export default mapPorts diff --git a/test/v2/build-test.Dockerfile b/test/build-test.Dockerfile similarity index 100% rename from test/v2/build-test.Dockerfile rename to test/build-test.Dockerfile diff --git a/test/v2/compose.test.ts b/test/compose.test.ts similarity index 99% rename from test/v2/compose.test.ts rename to test/compose.test.ts index 392713d7f..d39676839 100644 --- a/test/v2/compose.test.ts +++ b/test/compose.test.ts @@ -8,10 +8,10 @@ import { beforeAll } from 'vitest' import Docker, { ContainerInfo } from 'dockerode' -import * as compose from '../../src/v2' +import * as compose from '../src' import * as path from 'path' import { readFile } from 'fs' -import { mapPsOutput, mapImListOutput } from '../../src/v2' +import { mapPsOutput, mapImListOutput } from '../src' const docker = new Docker() const isContainerRunning = async (name: string): Promise => diff --git a/test/v2/docker-compose-2.yml b/test/docker-compose-2.yml similarity index 100% rename from test/v2/docker-compose-2.yml rename to test/docker-compose-2.yml diff --git a/test/v2/docker-compose-42.yml b/test/docker-compose-42.yml similarity index 100% rename from test/v2/docker-compose-42.yml rename to test/docker-compose-42.yml diff --git a/test/v2/docker-compose-build.yml b/test/docker-compose-build.yml similarity index 100% rename from test/v2/docker-compose-build.yml rename to test/docker-compose-build.yml diff --git a/test/v2/docker-compose-echo.yml b/test/docker-compose-echo.yml similarity index 100% rename from test/v2/docker-compose-echo.yml rename to test/docker-compose-echo.yml diff --git a/test/v2/docker-compose.yml b/test/docker-compose.yml similarity index 100% rename from test/v2/docker-compose.yml rename to test/docker-compose.yml diff --git a/test/v2/map-ports.test.ts b/test/map-ports.test.ts similarity index 97% rename from test/v2/map-ports.test.ts rename to test/map-ports.test.ts index 73401962d..fcb212fb9 100644 --- a/test/v2/map-ports.test.ts +++ b/test/map-ports.test.ts @@ -1,4 +1,4 @@ -import mapPorts from '../../src/v2-map-ports' +import mapPorts from '../src/map-ports' import { describe, expect, it } from 'vitest' describe('when no ports are exposed', (): void => {