Skip to content
Snippets Groups Projects
Select Git revision
  • c449c85d77955a0bc7a2414c610e6401906cc1a3
  • main default protected
  • fix/36615b-branch-reuse-no-cache
  • renovate/main-redis-5.x
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • chore/punycode
  • 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
  • gh-readonly-queue/next/pr-35009-9d5e583b7d7251148ab0d11ee8dd38149618d162
  • 41.38.2
  • 41.38.1
  • 41.38.0
  • 41.37.12
  • 41.37.11
  • 41.37.10
  • 41.37.9
  • 41.37.8
  • 41.37.7
  • 41.37.6
  • 41.37.5
  • 41.37.4
  • 41.37.3
  • 41.37.2
  • 41.37.1
  • 41.37.0
  • 41.36.2
  • 41.36.1
  • 41.36.0
  • 41.35.2
41 results

extract.ts

Blame
  • extract.ts 2.13 KiB
    import { logger } from '../../../logger';
    import { findLocalSiblingOrParent, localPathExists } from '../../../util/fs';
    import { newlineRegex, regEx } from '../../../util/regex';
    import { HexDatasource } from '../../datasource/hex';
    import type { PackageDependency, PackageFile } from '../types';
    
    const depSectionRegExp = regEx(/defp\s+deps.*do/g);
    const depMatchRegExp = regEx(
      /{:(?<depName>\w+),\s*(?<datasource>[^:"]+)?:?\s*"(?<currentValue>[^"]+)",?\s*(?:organization: "(?<organization>.*)")?.*}/gm
    );
    
    export async function extractPackageFile(
      content: string,
      fileName: string
    ): Promise<PackageFile | null> {
      logger.trace('mix.extractPackageFile()');
      const deps: PackageDependency[] = [];
      const contentArr = content.split(newlineRegex);
    
      for (let lineNumber = 0; lineNumber < contentArr.length; lineNumber += 1) {
        if (contentArr[lineNumber].match(depSectionRegExp)) {
          logger.trace(`Matched dep section on line ${lineNumber}`);
          let depBuffer = '';
          do {
            depBuffer += contentArr[lineNumber] + '\n';
            lineNumber += 1;
          } while (!contentArr[lineNumber].includes('end'));
          let depMatchGroups = depMatchRegExp.exec(depBuffer)?.groups;
          while (depMatchGroups) {
            const { depName, datasource, currentValue, organization } =
              depMatchGroups;
    
            const dep: PackageDependency = {
              depName,
              currentValue,
            };
    
            dep.datasource = datasource || HexDatasource.id;
    
            if (dep.datasource === HexDatasource.id) {
              dep.currentValue = currentValue;
              dep.packageName = depName;
            }
    
            if (organization) {
              dep.packageName += ':' + organization;
            }
    
            if (dep.datasource !== HexDatasource.id) {
              dep.skipReason = 'non-hex-dep-types';
            }
    
            deps.push(dep);
            depMatchGroups = depMatchRegExp.exec(depBuffer)?.groups;
          }
        }
      }
      const res: PackageFile = { deps };
      const lockFileName =
        (await findLocalSiblingOrParent(fileName, 'mix.lock')) ?? 'mix.lock';
      // istanbul ignore if
      if (await localPathExists(lockFileName)) {
        res.lockFiles = [lockFileName];
      }
      return res;
    }