Skip to content
Snippets Groups Projects
Select Git revision
  • 36e2b328bba5f7b1a21c3e51dfb98887600e5668
  • main default protected
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • renovate/main-redis-5.x
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • 41.34.1
  • 41.34.0
  • 41.33.0
  • 41.32.3
  • 41.32.2
  • 41.32.1
  • 41.32.0
  • 41.31.1
  • 41.31.0
  • 41.30.5
  • 41.30.4
  • 41.30.3
  • 41.30.2
  • 41.30.1
  • 41.30.0
  • 41.29.1
  • 41.29.0
  • 41.28.2
  • 41.28.1
  • 41.28.0
41 results

error-config.ts

Blame
  • extract.ts 4.03 KiB
    import { logger } from '../../../logger';
    import { getSiblingFileName, localPathExists } from '../../../util/fs';
    import { newlineRegex, regEx } from '../../../util/regex';
    import { GitTagsDatasource } from '../../datasource/git-tags';
    import { GithubTagsDatasource } from '../../datasource/github-tags';
    import { GitlabTagsDatasource } from '../../datasource/gitlab-tags';
    import { PodDatasource } from '../../datasource/pod';
    import type { PackageDependency, PackageFile } from '../types';
    import type { ParsedLine } from './types';
    
    const regexMappings = [
      regEx(`^\\s*pod\\s+(['"])(?<spec>[^'"/]+)(\\/(?<subspec>[^'"]+))?(['"])`),
      regEx(
        `^\\s*pod\\s+(['"])[^'"]+(['"])\\s*,\\s*(['"])(?<currentValue>[^'"]+)(['"])\\s*$`
      ),
      regEx(`,\\s*:git\\s*=>\\s*(['"])(?<git>[^'"]+)(['"])`),
      regEx(`,\\s*:tag\\s*=>\\s*(['"])(?<tag>[^'"]+)(['"])`),
      regEx(`,\\s*:path\\s*=>\\s*(['"])(?<path>[^'"]+)(['"])`),
      regEx(`^\\s*source\\s*(['"])(?<source>[^'"]+)(['"])`),
    ];
    
    export function parseLine(line: string): ParsedLine {
      let result: ParsedLine = {};
      if (!line) {
        return result;
      }
      for (const regex of Object.values(regexMappings)) {
        const match = regex.exec(line.replace(regEx(/#.*$/), ''));
        if (match?.groups) {
          result = { ...result, ...match.groups };
        }
      }
    
      if (result.spec) {
        const depName = result.subspec
          ? `${result.spec}/${result.subspec}`
          : result.spec;
        const groupName = result.spec;
        if (depName) {
          result.depName = depName;
        }
        if (groupName) {
          result.groupName = groupName;
        }
        delete result.spec;
        delete result.subspec;
      }
    
      return result;
    }
    
    export function gitDep(parsedLine: ParsedLine): PackageDependency | null {
      const { depName, git, tag } = parsedLine;
    
      const platformMatch = regEx(
        /[@/](?<platform>github|gitlab)\.com[:/](?<account>[^/]+)\/(?<repo>[^/]+)/
      ).exec(git);
    
      if (platformMatch) {
        const { account, repo, platform } = platformMatch?.groups || {};
        if (account && repo) {
          const datasource =
            platform === 'github'
              ? GithubTagsDatasource.id
              : GitlabTagsDatasource.id;
          return {
            datasource,
            depName,
            packageName: `${account}/${repo.replace(regEx(/\.git$/), '')}`,
            currentValue: tag,
          };
        }
      }
    
      return {
        datasource: GitTagsDatasource.id,
        depName,
        packageName: git,
        currentValue: tag,
      };
    }
    
    export async function extractPackageFile(
      content: string,
      fileName: string
    ): Promise<PackageFile | null> {
      logger.trace('cocoapods.extractPackageFile()');
      const deps: PackageDependency[] = [];
      const lines: string[] = content.split(newlineRegex);
    
      const registryUrls: string[] = [];
    
      for (let lineNumber = 0; lineNumber < lines.length; lineNumber += 1) {
        const line = lines[lineNumber];
        const parsedLine = parseLine(line);
        const {
          depName,
          groupName,
          currentValue,
          git,
          tag,
          path,
          source,
        }: ParsedLine = parsedLine;
    
        if (source) {
          registryUrls.push(source.replace(regEx(/\/*$/), ''));
        }
    
        if (depName) {
          const managerData = { lineNumber };
          let dep: PackageDependency = {
            depName,
            groupName,
            skipReason: 'unknown-version',
          };
    
          if (currentValue) {
            dep = {
              depName,
              groupName,
              datasource: PodDatasource.id,
              currentValue,
              managerData,
              registryUrls,
            };
          } else if (git) {
            if (tag) {
              dep = { ...gitDep(parsedLine), managerData };
            } else {
              dep = {
                depName,
                groupName,
                skipReason: 'git-dependency',
              };
            }
          } else if (path) {
            dep = {
              depName,
              groupName,
              skipReason: 'path-dependency',
            };
          }
    
          deps.push(dep);
        }
      }
      const res: PackageFile = { deps };
      const lockFile = getSiblingFileName(fileName, 'Podfile.lock');
      // istanbul ignore if
      if (await localPathExists(lockFile)) {
        res.lockFiles = [lockFile];
      }
      return res;
    }