export function match()

in packages/blueprints/blueprint/src/resynthesis/merge-strategies/match.ts [10:39]


export function match(sourceCodePath: string, strategies: { [bundlepath: string]: Strategy[] }): Strategy {
  const directories = sourceCodePath.split('/');

  while (directories.length > 0) {
    directories.pop();

    // path we would expect for if the ownership is declared in memory at this location
    const syntheticPath = path.join(...directories);
    // path we would expect for a ownership override file at this location
    const ownershipPath = path.join(syntheticPath, Ownership.DEFAULT_FILE_NAME);

    const commonPath = directories.join('/') + '/';
    const relativeStrategies = [...(strategies[syntheticPath] || []), ...(strategies[ownershipPath] || [])];
    if (!relativeStrategies.length) {
      continue;
    }

    const relativeBundlePath = sourceCodePath.startsWith(commonPath) ? sourceCodePath.slice(commonPath.length) : sourceCodePath;
    const matchedStrategy = matchStrategies(relativeBundlePath, relativeStrategies);
    if (matchedStrategy) {
      return matchedStrategy;
    }
  }

  return {
    identifier: FALLBACK_STRATEGY_ID,
    strategy: FALLBACK_STRATEGY,
    globs: ['*'],
  };
}