'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var paths = require('./cjs/paths-cfcd05fc.cjs.js');
var platformPath = require('path');
require('@backstage/cli-common');
require('@backstage/errors');

function overridePackagePathResolution(options) {
  const name = options.packageName;
  if (paths.packagePathMocks.has(name)) {
    throw new Error(
      `Tried to override resolution for '${name}' more than once for package '${name}'`
    );
  }
  paths.packagePathMocks.set(name, (paths) => {
    var _a;
    const joinedPath = platformPath.posix.join(...paths);
    const localResolver = (_a = options.paths) == null ? void 0 : _a[joinedPath];
    if (localResolver) {
      return typeof localResolver === "function" ? localResolver() : localResolver;
    }
    if (options.path) {
      return platformPath.resolve(options.path, ...paths);
    }
    return void 0;
  });
  return {
    restore() {
      paths.packagePathMocks.delete(name);
    }
  };
}

exports.overridePackagePathResolution = overridePackagePathResolution;
//# sourceMappingURL=testUtils.cjs.js.map
