import { executeToolCommand } from './HCY4ASBG.js';
import { init_esm_shims, __name } from './4RNWLMHM.js';

// src/commands/utility/sui-like.ts
init_esm_shims();
var permissionFixScripts = [
  "chmod -R 777 build",
  "find build -type f -exec chmod 644 {} +",
  "chmod 644 Move.lock"
];
var SuiWrapper = class {
  static {
    __name(this, "SuiWrapper");
  }
  command;
  configScript;
  defaultVolumes;
  constructor(command, configScript, defaultVolumes) {
    this.command = command;
    this.configScript = configScript;
    this.defaultVolumes = defaultVolumes;
  }
  async run(subcommand, args, options) {
    if (options.volumes.length) {
      throw new Error(`Volume option is not supported by the \`${this.command}\` wrapper`);
    }
    await this.initializeConfig(options);
    await this.downloadDependencies(subcommand, options);
    await executeToolCommand(this.command, [
      "move",
      subcommand,
      "--skip-fetch-latest-git-deps",
      ...args
    ], {
      ...options,
      volumes: this.defaultVolumes
    });
    await this.fixArtifactPermissions(options);
  }
  // Initialize config in the Docker volume if it doesn't exist.
  async initializeConfig(options) {
    await executeToolCommand(this.command, [
      "-c",
      this.configScript
    ], {
      ...options,
      volumes: this.defaultVolumes.map((volume) => ({
        ...volume,
        locked: true
      })),
      customEntrypoint: "/bin/sh"
    });
  }
  // Fetch dependencies into the shared Docker volume with a lock.
  // TODO Fetch dependencies with a read write lock.
  async downloadDependencies(subcommand, options) {
    await executeToolCommand(this.command, [
      "move",
      subcommand,
      "--fetch-deps-only"
    ], {
      ...options,
      volumes: this.defaultVolumes.map((volume) => ({
        ...volume,
        locked: true
      }))
    });
  }
  async fixArtifactPermissions(options) {
    for (const script of permissionFixScripts) {
      await executeToolCommand(this.command, [
        "-c",
        script
      ], {
        ...options,
        customEntrypoint: "/bin/sh"
      });
    }
  }
};

export { SuiWrapper };
//# sourceMappingURL=UKPHRO5A.js.map
//# sourceMappingURL=UKPHRO5A.js.map