Skip to content
Snippets Groups Projects
Select Git revision
  • ee153e560ee4327d70b6fded1cf5172bbbf67c5f
  • main default protected
  • renovate/main-ghcr.io-renovatebot-base-image-11.x
  • chore/update-pr-template
  • chore/maintainers-rarkins
  • refactor/pin-new-value
  • fix/user-agent
  • feat/37517-base64-private-key
  • next
  • feat/gnupg
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • 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
  • 41.82.6
  • 41.82.5
  • 41.82.4
  • 41.82.3
  • 41.82.2
  • 41.82.1
  • 41.82.0
  • 41.81.6
  • 41.81.5
  • 41.81.4
  • 41.81.3
  • 41.81.2
  • 41.81.1
  • 41.81.0
  • 41.80.0
  • 41.79.0
  • 41.78.1
  • 41.78.0
  • 41.77.0
  • 41.76.1
41 results

extract.ts

Blame
  • user avatar
    Florian Greinacher authored and Rhys Arkins committed
    4274166b
    History
    extract.ts 1.68 KiB
    import { logger } from '../../logger';
    import { get } from '../../versioning';
    import { PackageDependency, ExtractConfig, PackageFile } from '../common';
    
    export function extractPackageFile(
      content: string,
      packageFile: string,
      config: ExtractConfig = {}
    ): PackageFile {
      logger.trace(`nuget.extractPackageFile(${packageFile})`);
      const { isVersion } = get(config.versionScheme || 'semver');
      const deps: PackageDependency[] = [];
    
      let lineNumber = 0;
      for (const line of content.split('\n')) {
        /**
         * https://docs.microsoft.com/en-us/nuget/concepts/package-versioning
         * This article mentions that  Nuget 3.x and later tries to restore the lowest possible version
         * regarding to given version range.
         * 1.3.4 equals [1.3.4,)
         * Due to guarantee that an update of package version will result in its usage by the next restore + build operation,
         * only following constrained versions make sense
         * 1.3.4, [1.3.4], [1.3.4, ], [1.3.4, )
         * The update of the right boundary does not make sense regarding to the lowest version restore rule,
         * so we don't include it in the extracting regexp
         */
    
        const match = line.match(
          /<PackageReference.*Include\s*=\s*"([^"]+)".*Version\s*=\s*"(?:[[])?(?:([^"(,[\]]+)\s*(?:,\s*[)\]]|])?)"/
        );
        if (match) {
          const depName = match[1];
          const currentValue = match[2];
          const dep: PackageDependency = {
            depType: 'nuget',
            depName,
            currentValue,
            managerData: { lineNumber },
            datasource: 'nuget',
          };
          if (!isVersion(currentValue)) {
            dep.skipReason = 'not-version';
          }
          deps.push(dep);
        }
        lineNumber += 1;
      }
      return { deps };
    }