🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

docker-compose

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docker-compose - npm Package Compare versions

Comparing version

to
1.2.0

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [1.2.0](https://github.com/PDMLab/docker-compose/compare/v1.1.1...v1.2.0) (2025-03-14)
### Features
* using standalone binary ([297183d](https://github.com/PDMLab/docker-compose/commit/297183dcd1df4f2115f52c660baa192e377d5d16))
### [1.1.1](https://github.com/PDMLab/docker-compose/compare/v1.1.0...v1.1.1) (2025-02-11)

@@ -7,0 +14,0 @@

9

dist/index.d.ts
/// <reference types="node" />
export interface IDockerComposeExecutableOptions {
export type IDockerComposeExecutableOptions = {
executablePath: string;
options?: string[] | (string | string[])[];
}
standalone?: never;
} | {
executablePath?: string;
options?: never;
standalone: true;
};
export interface IDockerComposeOptions {

@@ -7,0 +12,0 @@ cwd?: string;

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -63,17 +7,15 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.stats = exports.version = exports.port = exports.logs = exports.restartOne = exports.restartMany = exports.restartAll = exports.push = exports.images = exports.ps = exports.configVolumes = exports.configServices = exports.config = exports.pullOne = exports.pullMany = exports.pullAll = exports.createOne = exports.createMany = exports.createAll = exports.buildOne = exports.buildMany = exports.buildAll = exports.run = exports.exec = exports.rm = exports.kill = exports.unpauseOne = exports.pauseOne = exports.stopMany = exports.stopOne = exports.stop = exports.downOne = exports.downMany = exports.down = exports.downAll = exports.upOne = exports.upMany = exports.upAll = exports.execCompose = exports.mapImListOutput = exports.mapPsOutput = void 0;
var child_process_1 = __importDefault(require("child_process"));
var yaml_1 = __importDefault(require("yaml"));
var map_ports_1 = __importDefault(require("./map-ports"));
var nonEmptyString = function (v) { return v !== ''; };
var arrayIncludesTuple = function (arr, tuple) {
return arr.some(function (subArray) {
return Array.isArray(subArray) &&
subArray.length === tuple.length &&
subArray.every(function (value, index) { return value === tuple[index]; });
});
const child_process_1 = __importDefault(require("child_process"));
const yaml_1 = __importDefault(require("yaml"));
const map_ports_1 = __importDefault(require("./map-ports"));
const nonEmptyString = (v) => v !== '';
const arrayIncludesTuple = (arr, tuple) => {
return arr.some((subArray) => Array.isArray(subArray) &&
subArray.length === tuple.length &&
subArray.every((value, index) => value === tuple[index]));
};
var mapPsOutput = function (output, options) {
var isQuiet = false;
var isJson = false;
if (options === null || options === void 0 ? void 0 : options.commandOptions) {
const mapPsOutput = (output, options) => {
let isQuiet = false;
let isJson = false;
if (options?.commandOptions) {
isQuiet =

@@ -85,14 +27,14 @@ options.commandOptions.includes('-q') ||

}
var services = output
.split("\n")
const services = output
.split(`\n`)
.filter(nonEmptyString)
.filter(function (_, index) { return isQuiet || isJson || index >= 1; })
.map(function (line) {
var nameFragment = line;
var commandFragment = '';
var stateFragment = '';
var untypedPortsFragment = '';
.filter((_, index) => isQuiet || isJson || index >= 1)
.map((line) => {
let nameFragment = line;
let commandFragment = '';
let stateFragment = '';
let untypedPortsFragment = '';
if (!isQuiet) {
if (isJson) {
var serviceLine = JSON.parse(line);
const serviceLine = JSON.parse(line);
nameFragment = serviceLine.Name;

@@ -104,3 +46,3 @@ commandFragment = serviceLine.Command;

else {
var lineColumns = line.split(/\s{3,}/);
const lineColumns = line.split(/\s{3,}/);
// the line has the columns in the following order:

@@ -122,9 +64,9 @@ // NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS

});
return { services: services };
return { services };
};
exports.mapPsOutput = mapPsOutput;
var mapImListOutput = function (output, options) {
var isQuiet = false;
var isJson = false;
if (options === null || options === void 0 ? void 0 : options.commandOptions) {
const mapImListOutput = (output, options) => {
let isQuiet = false;
let isJson = false;
if (options?.commandOptions) {
isQuiet =

@@ -136,7 +78,7 @@ options.commandOptions.includes('-q') ||

if (isJson) {
var data = JSON.parse(output);
var services_1 = data.map(function (serviceLine) {
var idFragment = serviceLine.ID;
const data = JSON.parse(output);
const services = data.map((serviceLine) => {
let idFragment = serviceLine.ID;
// trim json 64B id format "type:id" to 12B id
var idTypeIndex = idFragment.indexOf(':');
const idTypeIndex = idFragment.indexOf(':');
if (idTypeIndex > 0)

@@ -151,16 +93,16 @@ idFragment = idFragment.slice(idTypeIndex + 1, idTypeIndex + 13);

});
return { services: services_1 };
return { services };
}
var services = output
.split("\n")
const services = output
.split(`\n`)
.filter(nonEmptyString)
.filter(function (_, index) { return isQuiet || isJson || index >= 1; })
.map(function (line) {
.filter((_, index) => isQuiet || isJson || index >= 1)
.map((line) => {
// the line has the columns in the following order:
// CONTAINER REPOSITORY TAG IMAGE ID SIZE
var lineColumns = line.split(/\s{3,}/);
var containerFragment = lineColumns[0] || line;
var repositoryFragment = lineColumns[1] || '';
var tagFragment = lineColumns[2] || '';
var idFragment = lineColumns[3] || '';
const lineColumns = line.split(/\s{3,}/);
const containerFragment = lineColumns[0] || line;
const repositoryFragment = lineColumns[1] || '';
const tagFragment = lineColumns[2] || '';
const idFragment = lineColumns[3] || '';
return {

@@ -173,3 +115,3 @@ container: containerFragment.trim(),

});
return { services: services };
return { services };
};

@@ -181,3 +123,3 @@ exports.mapImListOutput = mapImListOutput;

*/
var configToArgs = function (config) {
const configToArgs = (config) => {
if (typeof config === 'undefined') {

@@ -190,5 +132,5 @@ return [];

else if (config instanceof Array) {
return config.reduce(function (args, item) { return args.concat(['-f', item]); }, []);
return config.reduce((args, item) => args.concat(['-f', item]), []);
}
throw new Error("Invalid argument supplied: ".concat(config));
throw new Error(`Invalid argument supplied: ${config}`);
};

@@ -198,5 +140,5 @@ /**

*/
var composeOptionsToArgs = function (composeOptions) {
var composeArgs = [];
composeOptions.forEach(function (option) {
const composeOptionsToArgs = (composeOptions) => {
let composeArgs = [];
composeOptions.forEach((option) => {
if (option instanceof Array) {

@@ -214,61 +156,64 @@ composeArgs = composeArgs.concat(option);

*/
var execCompose = function (command, args, options) {
if (options === void 0) { options = {}; }
return new Promise(function (resolve, reject) {
var composeOptions = options.composeOptions || [];
var commandOptions = options.commandOptions || [];
var composeArgs = composeOptionsToArgs(composeOptions);
var isConfigProvidedAsString = !!options.configAsString;
var configArgs = isConfigProvidedAsString
? ['-f', '-']
: configToArgs(options.config);
composeArgs = composeArgs.concat(configArgs.concat([command].concat(composeOptionsToArgs(commandOptions), args)));
var cwd = options.cwd;
var env = options.env || undefined;
var executable = options.executable || { executablePath: 'docker' };
var executableOptions = executable.options || [];
var executableArgs = composeOptionsToArgs(executableOptions);
var childProc = child_process_1.default.spawn(executable.executablePath, __spreadArray(__spreadArray(__spreadArray([], executableArgs, true), ['compose'], false), composeArgs, true), {
cwd: cwd,
env: env
});
childProc.on('error', function (err) {
reject(err);
});
var result = {
exitCode: null,
err: '',
out: ''
};
childProc.stdout.on('data', function (chunk) {
var _a;
result.out += chunk.toString();
(_a = options.callback) === null || _a === void 0 ? void 0 : _a.call(options, chunk, 'stdout');
});
childProc.stderr.on('data', function (chunk) {
var _a;
result.err += chunk.toString();
(_a = options.callback) === null || _a === void 0 ? void 0 : _a.call(options, chunk, 'stderr');
});
childProc.on('exit', function (exitCode) {
result.exitCode = exitCode;
setTimeout(function () {
if (exitCode === 0) {
resolve(result);
}
else {
reject(result);
}
}, 500);
});
if (isConfigProvidedAsString) {
childProc.stdin.write(options.configAsString);
childProc.stdin.end();
}
if (options.log) {
childProc.stdout.pipe(process.stdout);
childProc.stderr.pipe(process.stderr);
}
const execCompose = (command, args, options = {}) => new Promise((resolve, reject) => {
const composeOptions = options.composeOptions || [];
const commandOptions = options.commandOptions || [];
let composeArgs = composeOptionsToArgs(composeOptions);
const isConfigProvidedAsString = !!options.configAsString;
const configArgs = isConfigProvidedAsString
? ['-f', '-']
: configToArgs(options.config);
composeArgs = composeArgs.concat(configArgs.concat([command].concat(composeOptionsToArgs(commandOptions), args)));
const cwd = options.cwd;
const env = options.env || undefined;
const executable = options.executable;
let executablePath;
let executableArgs = [];
if (executable?.standalone && !executable.executablePath) {
executablePath = 'docker-compose';
}
else {
executablePath = executable?.executablePath || 'docker';
const executableOptions = executable?.options || [];
executableArgs = [...composeOptionsToArgs(executableOptions), 'compose'];
}
const childProc = child_process_1.default.spawn(executablePath, [...executableArgs, ...composeArgs], {
cwd,
env
});
};
childProc.on('error', (err) => {
reject(err);
});
const result = {
exitCode: null,
err: '',
out: ''
};
childProc.stdout.on('data', (chunk) => {
result.out += chunk.toString();
options.callback?.(chunk, 'stdout');
});
childProc.stderr.on('data', (chunk) => {
result.err += chunk.toString();
options.callback?.(chunk, 'stderr');
});
childProc.on('exit', (exitCode) => {
result.exitCode = exitCode;
setTimeout(() => {
if (exitCode === 0) {
resolve(result);
}
else {
reject(result);
}
}, 500);
});
if (isConfigProvidedAsString) {
childProc.stdin.write(options.configAsString);
childProc.stdin.end();
}
if (options.log) {
childProc.stdout.pipe(process.stdout);
childProc.stderr.pipe(process.stderr);
}
});
exports.execCompose = execCompose;

@@ -278,6 +223,5 @@ /**

*/
var shouldUseDefaultNonInteractiveFlag = function (options) {
if (options === void 0) { options = {}; }
var commandOptions = options.commandOptions || [];
var noDetachModeFlags = [
const shouldUseDefaultNonInteractiveFlag = function (options = {}) {
const commandOptions = options.commandOptions || [];
const noDetachModeFlags = [
'--abort-on-container-exit',

@@ -289,14 +233,14 @@ '--no-start',

];
var containsOtherNonInteractiveFlag = commandOptions.reduce(function (memo, item) {
return memo && noDetachModeFlags.every(function (flag) { return !item.includes(flag); });
const containsOtherNonInteractiveFlag = commandOptions.reduce((memo, item) => {
return memo && noDetachModeFlags.every((flag) => !item.includes(flag));
}, true);
return containsOtherNonInteractiveFlag;
};
var upAll = function (options) {
var args = shouldUseDefaultNonInteractiveFlag(options) ? ['-d'] : [];
const upAll = function (options) {
const args = shouldUseDefaultNonInteractiveFlag(options) ? ['-d'] : [];
return (0, exports.execCompose)('up', args, options);
};
exports.upAll = upAll;
var upMany = function (services, options) {
var args = shouldUseDefaultNonInteractiveFlag(options)
const upMany = function (services, options) {
const args = shouldUseDefaultNonInteractiveFlag(options)
? ['-d'].concat(services)

@@ -307,4 +251,4 @@ : services;

exports.upMany = upMany;
var upOne = function (service, options) {
var args = shouldUseDefaultNonInteractiveFlag(options)
const upOne = function (service, options) {
const args = shouldUseDefaultNonInteractiveFlag(options)
? ['-d', service]

@@ -315,3 +259,3 @@ : [service];

exports.upOne = upOne;
var downAll = function (options) {
const downAll = function (options) {
return (0, exports.execCompose)('down', [], options);

@@ -321,227 +265,176 @@ };

exports.down = exports.downAll;
var downMany = function (services, options) {
var args = services;
const downMany = function (services, options) {
const args = services;
return (0, exports.execCompose)('down', args, options);
};
exports.downMany = downMany;
var downOne = function (service, options) {
var args = [service];
const downOne = function (service, options) {
const args = [service];
return (0, exports.execCompose)('down', args, options);
};
exports.downOne = downOne;
var stop = function (options) {
const stop = function (options) {
return (0, exports.execCompose)('stop', [], options);
};
exports.stop = stop;
var stopOne = function (service, options) {
const stopOne = function (service, options) {
return (0, exports.execCompose)('stop', [service], options);
};
exports.stopOne = stopOne;
var stopMany = function (options) {
var services = [];
for (var _i = 1; _i < arguments.length; _i++) {
services[_i - 1] = arguments[_i];
}
return (0, exports.execCompose)('stop', __spreadArray([], services, true), options);
const stopMany = function (options, ...services) {
return (0, exports.execCompose)('stop', [...services], options);
};
exports.stopMany = stopMany;
var pauseOne = function (service, options) {
const pauseOne = function (service, options) {
return (0, exports.execCompose)('pause', [service], options);
};
exports.pauseOne = pauseOne;
var unpauseOne = function (service, options) {
const unpauseOne = function (service, options) {
return (0, exports.execCompose)('unpause', [service], options);
};
exports.unpauseOne = unpauseOne;
var kill = function (options) {
const kill = function (options) {
return (0, exports.execCompose)('kill', [], options);
};
exports.kill = kill;
var rm = function (options) {
var services = [];
for (var _i = 1; _i < arguments.length; _i++) {
services[_i - 1] = arguments[_i];
}
return (0, exports.execCompose)('rm', __spreadArray(['-f'], services, true), options);
const rm = function (options, ...services) {
return (0, exports.execCompose)('rm', ['-f', ...services], options);
};
exports.rm = rm;
var exec = function (container, command, options) {
var args = Array.isArray(command) ? command : command.split(/\s+/);
const exec = function (container, command, options) {
const args = Array.isArray(command) ? command : command.split(/\s+/);
return (0, exports.execCompose)('exec', ['-T', container].concat(args), options);
};
exports.exec = exec;
var run = function (container, command, options) {
var args = Array.isArray(command) ? command : command.split(/\s+/);
const run = function (container, command, options) {
const args = Array.isArray(command) ? command : command.split(/\s+/);
return (0, exports.execCompose)('run', ['-T', container].concat(args), options);
};
exports.run = run;
var buildAll = function (options) {
if (options === void 0) { options = {}; }
const buildAll = function (options = {}) {
return (0, exports.execCompose)('build', options.parallel ? ['--parallel'] : [], options);
};
exports.buildAll = buildAll;
var buildMany = function (services, options) {
if (options === void 0) { options = {}; }
const buildMany = function (services, options = {}) {
return (0, exports.execCompose)('build', options.parallel ? ['--parallel'].concat(services) : services, options);
};
exports.buildMany = buildMany;
var buildOne = function (service, options) {
const buildOne = function (service, options) {
return (0, exports.execCompose)('build', [service], options);
};
exports.buildOne = buildOne;
var createAll = function (options) {
if (options === void 0) { options = {}; }
const createAll = function (options = {}) {
return (0, exports.execCompose)('create', [], options);
};
exports.createAll = createAll;
var createMany = function (services, options) {
if (options === void 0) { options = {}; }
const createMany = function (services, options = {}) {
return (0, exports.execCompose)('create', services, options);
};
exports.createMany = createMany;
var createOne = function (service, options) {
const createOne = function (service, options) {
return (0, exports.execCompose)('create', [service], options);
};
exports.createOne = createOne;
var pullAll = function (options) {
if (options === void 0) { options = {}; }
const pullAll = function (options = {}) {
return (0, exports.execCompose)('pull', [], options);
};
exports.pullAll = pullAll;
var pullMany = function (services, options) {
if (options === void 0) { options = {}; }
const pullMany = function (services, options = {}) {
return (0, exports.execCompose)('pull', services, options);
};
exports.pullMany = pullMany;
var pullOne = function (service, options) {
const pullOne = function (service, options) {
return (0, exports.execCompose)('pull', [service], options);
};
exports.pullOne = pullOne;
var config = function (options) {
return __awaiter(this, void 0, void 0, function () {
var result, config_1, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, (0, exports.execCompose)('config', [], options)];
case 1:
result = _a.sent();
config_1 = yaml_1.default.parse(result.out);
return [2 /*return*/, __assign(__assign({}, result), { data: { config: config_1 } })];
case 2:
error_1 = _a.sent();
return [2 /*return*/, Promise.reject(error_1)];
case 3: return [2 /*return*/];
}
});
});
const config = async function (options) {
try {
const result = await (0, exports.execCompose)('config', [], options);
const config = yaml_1.default.parse(result.out);
return {
...result,
data: { config }
};
}
catch (error) {
return Promise.reject(error);
}
};
exports.config = config;
var configServices = function (options) {
return __awaiter(this, void 0, void 0, function () {
var result, services, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, (0, exports.execCompose)('config', ['--services'], options)];
case 1:
result = _a.sent();
services = result.out.split('\n').filter(nonEmptyString);
return [2 /*return*/, __assign(__assign({}, result), { data: { services: services } })];
case 2:
error_2 = _a.sent();
return [2 /*return*/, Promise.reject(error_2)];
case 3: return [2 /*return*/];
}
});
});
const configServices = async function (options) {
try {
const result = await (0, exports.execCompose)('config', ['--services'], options);
const services = result.out.split('\n').filter(nonEmptyString);
return {
...result,
data: { services }
};
}
catch (error) {
return Promise.reject(error);
}
};
exports.configServices = configServices;
var configVolumes = function (options) {
return __awaiter(this, void 0, void 0, function () {
var result, volumes, error_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, (0, exports.execCompose)('config', ['--volumes'], options)];
case 1:
result = _a.sent();
volumes = result.out.split('\n').filter(nonEmptyString);
return [2 /*return*/, __assign(__assign({}, result), { data: { volumes: volumes } })];
case 2:
error_3 = _a.sent();
return [2 /*return*/, Promise.reject(error_3)];
case 3: return [2 /*return*/];
}
});
});
const configVolumes = async function (options) {
try {
const result = await (0, exports.execCompose)('config', ['--volumes'], options);
const volumes = result.out.split('\n').filter(nonEmptyString);
return {
...result,
data: { volumes }
};
}
catch (error) {
return Promise.reject(error);
}
};
exports.configVolumes = configVolumes;
var ps = function (options) {
return __awaiter(this, void 0, void 0, function () {
var result, data, error_4;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, (0, exports.execCompose)('ps', [], options)];
case 1:
result = _a.sent();
data = (0, exports.mapPsOutput)(result.out, options);
return [2 /*return*/, __assign(__assign({}, result), { data: data })];
case 2:
error_4 = _a.sent();
return [2 /*return*/, Promise.reject(error_4)];
case 3: return [2 /*return*/];
}
});
});
const ps = async function (options) {
try {
const result = await (0, exports.execCompose)('ps', [], options);
const data = (0, exports.mapPsOutput)(result.out, options);
return {
...result,
data
};
}
catch (error) {
return Promise.reject(error);
}
};
exports.ps = ps;
var images = function (options) {
return __awaiter(this, void 0, void 0, function () {
var result, data, error_5;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, (0, exports.execCompose)('images', [], options)];
case 1:
result = _a.sent();
data = (0, exports.mapImListOutput)(result.out, options);
return [2 /*return*/, __assign(__assign({}, result), { data: data })];
case 2:
error_5 = _a.sent();
return [2 /*return*/, Promise.reject(error_5)];
case 3: return [2 /*return*/];
}
});
});
const images = async function (options) {
try {
const result = await (0, exports.execCompose)('images', [], options);
const data = (0, exports.mapImListOutput)(result.out, options);
return {
...result,
data
};
}
catch (error) {
return Promise.reject(error);
}
};
exports.images = images;
var push = function (options) {
if (options === void 0) { options = {}; }
const push = function (options = {}) {
return (0, exports.execCompose)('push', options.ignorePushFailures ? ['--ignore-push-failures'] : [], options);
};
exports.push = push;
var restartAll = function (options) {
const restartAll = function (options) {
return (0, exports.execCompose)('restart', [], options);
};
exports.restartAll = restartAll;
var restartMany = function (services, options) {
const restartMany = function (services, options) {
return (0, exports.execCompose)('restart', services, options);
};
exports.restartMany = restartMany;
var restartOne = function (service, options) {
const restartOne = function (service, options) {
return (0, exports.restartMany)([service], options);
};
exports.restartOne = restartOne;
var logs = function (services, options) {
if (options === void 0) { options = {}; }
var args = Array.isArray(services) ? services : [services];
const logs = function (services, options = {}) {
let args = Array.isArray(services) ? services : [services];
if (options.follow) {
args = __spreadArray(['--follow'], args, true);
args = ['--follow', ...args];
}

@@ -551,74 +444,45 @@ return (0, exports.execCompose)('logs', args, options);

exports.logs = logs;
var port = function (service, containerPort, options) {
return __awaiter(this, void 0, void 0, function () {
var args, result, _a, address, port_1, error_6;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
args = [service, containerPort];
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, exports.execCompose)('port', args, options)];
case 2:
result = _b.sent();
_a = result.out.split(':'), address = _a[0], port_1 = _a[1];
return [2 /*return*/, __assign(__assign({}, result), { data: {
address: address,
port: Number(port_1)
} })];
case 3:
error_6 = _b.sent();
return [2 /*return*/, Promise.reject(error_6)];
case 4: return [2 /*return*/];
const port = async function (service, containerPort, options) {
const args = [service, containerPort];
try {
const result = await (0, exports.execCompose)('port', args, options);
const [address, port] = result.out.split(':');
return {
...result,
data: {
address,
port: Number(port)
}
});
});
};
}
catch (error) {
return Promise.reject(error);
}
};
exports.port = port;
var version = function (options) {
return __awaiter(this, void 0, void 0, function () {
var result, version_1, error_7;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, (0, exports.execCompose)('version', ['--short'], options)];
case 1:
result = _a.sent();
version_1 = result.out.replace('\n', '').trim();
return [2 /*return*/, __assign(__assign({}, result), { data: { version: version_1 } })];
case 2:
error_7 = _a.sent();
return [2 /*return*/, Promise.reject(error_7)];
case 3: return [2 /*return*/];
}
});
});
const version = async function (options) {
try {
const result = await (0, exports.execCompose)('version', ['--short'], options);
const version = result.out.replace('\n', '').trim();
return {
...result,
data: { version }
};
}
catch (error) {
return Promise.reject(error);
}
};
exports.version = version;
var stats = function (service, options) {
return __awaiter(this, void 0, void 0, function () {
var args, result, output, error_8;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
args = ['--no-stream', '--format', '"{{ json . }}"', service];
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, exports.execCompose)('stats', args, options)
// Remove first and last quote from output, as well as newline.
];
case 2:
result = _a.sent();
output = result.out.replace('\n', '').trim().slice(1, -1);
return [2 /*return*/, JSON.parse(output)];
case 3:
error_8 = _a.sent();
return [2 /*return*/, Promise.reject(error_8)];
case 4: return [2 /*return*/];
}
});
});
const stats = async function (service, options) {
const args = ['--no-stream', '--format', '"{{ json . }}"', service];
try {
const result = await (0, exports.execCompose)('stats', args, options);
// Remove first and last quote from output, as well as newline.
const output = result.out.replace('\n', '').trim().slice(1, -1);
return JSON.parse(output);
}
catch (error) {
return Promise.reject(error);
}
};

@@ -625,0 +489,0 @@ exports.stats = stats;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var mapPorts = function (ports) {
const mapPorts = (ports) => {
if (!ports) {
return [];
}
return ports.split(',').map(function (untypedPort) {
var exposedFragments = untypedPort.trim().split('->');
var _a = exposedFragments.length === 1
return ports.split(',').map((untypedPort) => {
const exposedFragments = untypedPort.trim().split('->');
const [port, protocol] = exposedFragments.length === 1
? exposedFragments[0].split('/')
: exposedFragments[1].split('/'), port = _a[0], protocol = _a[1];
var mapped = exposedFragments[0];
var lastDoubleColon = mapped.lastIndexOf(':');
: exposedFragments[1].split('/');
const mapped = exposedFragments[0];
const lastDoubleColon = mapped.lastIndexOf(':');
if (lastDoubleColon === -1) {
return {
exposed: { port: Number(port), protocol: protocol }
exposed: { port: Number(port), protocol }
};
}
var address = mapped.substr(0, lastDoubleColon);
var mappedPort = mapped.substr(lastDoubleColon + 1);
const address = mapped.substr(0, lastDoubleColon);
const mappedPort = mapped.substr(lastDoubleColon + 1);
return {
exposed: { port: Number(port), protocol: protocol },
mapped: { port: Number(mappedPort), address: address }
exposed: { port: Number(port), protocol },
mapped: { port: Number(mappedPort), address }
};

@@ -25,0 +25,0 @@ });

{
"name": "docker-compose",
"version": "1.1.1",
"version": "1.2.0",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "typings": "dist/index.d.ts",

@@ -10,3 +10,3 @@ [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)

As of version 1.0, this library only supports `docker compose` (v2, the docker "compose" plugin). The `docker-compose` (v1) has been removed from recent releases of Docker Desktop and is no longer supported. Use the `0.x` versions of this library if you still need to use the old `docker-compose` (v1).
As of version 1.0, this library supports `docker compose` (v2, the docker "compose" plugin) by default. The `docker-compose` (v1) has been removed from recent releases of Docker Desktop and is no longer supported. However, you can still force the use of `docker-compose` by using the [standanlone mode](#standalone-mode).

@@ -92,2 +92,17 @@ ## Installation

### Standalone mode
While the `docker-compose` executable is no longer part of a default docker installation, it is still possible to download its binary [standalone](https://docs.docker.com/compose/install/standalone/). This is useful for example when building docker images, avoiding the need to install the whole docker stack.
To use a standalone binary, you can set the `executable.standalone` option to `true`. You can also set the `executablePath` option to the path of the `docker-compose` binary.
```js
compose.upAll({
executable: {
standalone: true,
executablePath: '/path/to/docker-compose' // optional
}
})
```
## Known issues

@@ -94,0 +109,0 @@

@@ -5,6 +5,6 @@ {

// "incremental": true, /* Enable incremental compilation */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"target": "ES2021" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "node16" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"es2015",
"es2021",
"dom"

@@ -11,0 +11,0 @@ ] /* Specify library files to be included in the compilation. */,