import { getRegistry, getImageDirectory } from './BJUOU4DR.js';
import { findToolVersionsForCombination, getImageName } from './3XEUJAQB.js';
import { init_esm_shims, __name } from './CWKWODSW.js';
import { join, basename } from 'path';
import { env } from 'process';

// src/utils/docker.ts
init_esm_shims();
var getImageUriForTool = /* @__PURE__ */ __name(async (context, toolName, version) => {
  const [image] = context.versionCombinations.flatMap((combination) => {
    const imageId = combination.images[toolName];
    if (!imageId) {
      return [];
    }
    const image2 = context.images[imageId];
    return image2 && findToolVersionsForCombination(context, combination)[toolName] === version ? [
      image2
    ] : [];
  });
  if (!image) {
    throw new Error(`No version combination found for tool ${toolName} with version ${version}`);
  }
  return getImageUri(image);
}, "getImageUriForTool");
var getImageUri = /* @__PURE__ */ __name(async (image) => join(await getRegistry(), await getImageDirectory(), `${getImageName(image.name)}:${getImageTag(image)}`), "getImageUri");
var getImageTag = /* @__PURE__ */ __name(({ versions, patch }) => [
  ...Object.entries(versions).sort().flat(),
  ...patch ? [
    "patch",
    patch
  ] : []
].join("-"), "getImageTag");
var qualifyVolumeName = /* @__PURE__ */ __name((volume) => {
  if (volume.type !== "isolate") {
    return volume;
  }
  const components = [
    "lz-tooling-cache",
    volume.name
  ];
  if (!volume.shared) {
    const packageName = env.npm_package_name;
    if (!packageName) {
      throw new Error("npm_package_name environment variable not defined");
    }
    components.push(basename(packageName));
  }
  return {
    ...volume,
    name: components.join("-")
  };
}, "qualifyVolumeName");

export { getImageTag, getImageUri, getImageUriForTool, qualifyVolumeName };
//# sourceMappingURL=AXL4SBDJ.js.map
//# sourceMappingURL=AXL4SBDJ.js.map