当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript semver.maxSatisfying函数代码示例

本文整理汇总了TypeScript中semver.maxSatisfying函数的典型用法代码示例。如果您正苦于以下问题:TypeScript maxSatisfying函数的具体用法?TypeScript maxSatisfying怎么用?TypeScript maxSatisfying使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了maxSatisfying函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: _getVersionFromNpmPackage

function _getVersionFromNpmPackage(json: JsonObject, version: string, loose: boolean): string {
  const distTags = json['dist-tags'] as JsonObject;
  if (distTags && distTags[version]) {
    return (loose ? '~' : '') + distTags[version] as string;
  } else {
    if (!semver.validRange(version)) {
      throw new SchematicsException(`Invalid range or version: "${version}".`);
    }
    if (semver.valid(version) && loose) {
      version = '~' + version;
    }

    const packageVersions = Object.keys(json['versions'] as JsonObject);
    const maybeMatch = semver.maxSatisfying(packageVersions, version);

    if (!maybeMatch) {
      throw new SchematicsException(
        `Version "${version}" has no satisfying version for package ${json['name']}`,
      );
    }

    const maybeOperator = version.match(/^[~^]/);
    if (version == '*') {
      return maybeMatch;
    } else if (maybeOperator) {
      return maybeOperator[0] + maybeMatch;
    } else {
      return (loose ? '~' : '') + maybeMatch;
    }
  }
}
开发者ID:fmalcher,项目名称:angular-cli,代码行数:31,代码来源:npm.ts

示例2: mergeMap

    mergeMap(({version, depName, depVersion, npmPackageJson}) => {
      const updateVersion = _getVersionFromNpmPackage(npmPackageJson, version, loose);
      const npmPackageVersions = Object.keys(npmPackageJson['versions'] as JsonObject);
      const match = semver.maxSatisfying(npmPackageVersions, updateVersion);
      if (!match) {
        return EMPTY;
      }
      if (semver.lt(
        semverIntersect.parseRange(updateVersion).version,
        semverIntersect.parseRange(depVersion).version)
      ) {
        throw new SchematicsException(`Cannot downgrade package ${
          JSON.stringify(depName)} from version "${depVersion}" to "${updateVersion}".`,
        );
      }

      const innerNpmPackageJson = (npmPackageJson['versions'] as JsonObject)[match] as JsonObject;
      const dependencies: { [name: string]: string } = {};

      const deps = innerNpmPackageJson['peerDependencies'] as JsonObject;
      if (deps) {
        for (const depName of Object.keys(deps)) {
          dependencies[depName] = deps[depName] as string;
        }
      }

      logger.debug(`Recording update for ${JSON.stringify(depName)} to version ${updateVersion}.`);

      if (allVersions[depName]) {
        if (!semver.intersects(allVersions[depName], updateVersion)) {
          throw new SchematicsException(
            'Cannot update safely because packages have conflicting dependencies. Package '
            + `${depName} would need to match both versions "${updateVersion}" and `
            + `"${allVersions[depName]}, which are not compatible.`,
          );
        }

        allVersions[depName] = semverIntersect.intersect(allVersions[depName], updateVersion);
      } else {
        allVersions[depName] = updateVersion;
      }

      return _getRecursiveVersions(
        packageJson,
        dependencies,
        allVersions,
        logger,
        loose,
      );
    }),
开发者ID:fmalcher,项目名称:angular-cli,代码行数:50,代码来源:npm.ts

示例3: getLatestCompatibleVersion

	public async getLatestCompatibleVersion(packageName: string, referenceVersion?: string): Promise<string> {
		referenceVersion = referenceVersion || this.$staticConfig.version;
		const isPreReleaseVersion = semver.prerelease(referenceVersion) !== null;
		// if the user has some v.v.v-prerelease-xx.xx pre-release version, include pre-release versions in the search query.
		const compatibleVersionRange = isPreReleaseVersion
			? `~${referenceVersion}`
			: `~${semver.major(referenceVersion)}.${semver.minor(referenceVersion)}.0`;
		const latestVersion = await this.getLatestVersion(packageName);
		if (semver.satisfies(latestVersion, compatibleVersionRange)) {
			return latestVersion;
		}

		const data = await this.$npm.view(packageName, { "versions": true });

		const maxSatisfying = semver.maxSatisfying(data, compatibleVersionRange);
		return maxSatisfying || latestVersion;
	}
开发者ID:NathanaelA,项目名称:nativescript-cli,代码行数:17,代码来源:npm-installation-manager.ts

示例4: getMatchingVersionFromList

export function getMatchingVersionFromList(versionInfoList: VersionInfo[], versionSpec: string, includePreviewVersions: boolean = false): VersionInfo {
    let versionList: string[] = [];
    versionInfoList.forEach(versionInfo => {
        if (versionInfo && versionInfo.getVersion()) {
            versionList.push(versionInfo.getVersion());
        }
    });

    if (versionList.length > 0) {
        let matchedVersion = semver.maxSatisfying(versionList, versionSpec, { includePrerelease: includePreviewVersions });
        if (matchedVersion) {
            return versionInfoList.find(versionInfo => {
                return versionInfo.getVersion() == matchedVersion
            });
        }
    }

    return null;
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:19,代码来源:versionutilities.ts

示例5: _buildPackageInfo

function _buildPackageInfo(
  tree: Tree,
  packages: Map<string, VersionRange>,
  allDependencies: Map<string, VersionRange>,
  npmPackageJson: NpmRepositoryPackageJson,
  logger: logging.LoggerApi,
): PackageInfo {
  const name = npmPackageJson.name;
  const packageJsonRange = allDependencies.get(name);
  if (!packageJsonRange) {
    throw new SchematicsException(
      `Package ${JSON.stringify(name)} was not found in package.json.`,
    );
  }

  // Find out the currently installed version. Either from the package.json or the node_modules/
  // TODO: figure out a way to read package-lock.json and/or yarn.lock.
  let installedVersion: string | undefined;
  const packageContent = tree.read(`/node_modules/${name}/package.json`);
  if (packageContent) {
    const content = JSON.parse(packageContent.toString()) as JsonSchemaForNpmPackageJsonFiles;
    installedVersion = content.version;
  }
  if (!installedVersion) {
    // Find the version from NPM that fits the range to max.
    installedVersion = semver.maxSatisfying(
      Object.keys(npmPackageJson.versions),
      packageJsonRange,
    );
  }

  const installedPackageJson = npmPackageJson.versions[installedVersion] || packageContent;
  if (!installedPackageJson) {
    throw new SchematicsException(
      `An unexpected error happened; package ${name} has no version ${installedVersion}.`,
    );
  }

  let targetVersion: VersionRange | undefined = packages.get(name);
  if (targetVersion) {
    if (npmPackageJson['dist-tags'][targetVersion]) {
      targetVersion = npmPackageJson['dist-tags'][targetVersion] as VersionRange;
    } else if (targetVersion == 'next') {
      targetVersion = npmPackageJson['dist-tags']['latest'] as VersionRange;
    } else {
      targetVersion = semver.maxSatisfying(
        Object.keys(npmPackageJson.versions),
        targetVersion,
      ) as VersionRange;
    }
  }

  if (targetVersion && semver.lte(targetVersion, installedVersion)) {
    logger.debug(`Package ${name} already satisfied by package.json (${packageJsonRange}).`);
    targetVersion = undefined;
  }

  const target: PackageVersionInfo | undefined = targetVersion
    ? {
      version: targetVersion,
      packageJson: npmPackageJson.versions[targetVersion],
      updateMetadata: _getUpdateMetadata(npmPackageJson.versions[targetVersion], logger),
    }
    : undefined;

  // Check if there's an installed version.
  return {
    name,
    npmPackageJson,
    installed: {
      version: installedVersion as VersionRange,
      packageJson: installedPackageJson,
      updateMetadata: _getUpdateMetadata(installedPackageJson, logger),
    },
    target,
    packageJsonRange,
  };
}
开发者ID:iwe7,项目名称:devkit,代码行数:78,代码来源:index.ts

示例6:

bool = semver.lte(v1, v2, loose);
bool = semver.eq(v1, v2, loose);
bool = semver.neq(v1, v2, loose);
bool = semver.cmp(v1, op, v2, loose);
comparatorResult = semver.compare(v1, v2, loose);
comparatorResult = semver.rcompare(v1, v2, loose);
comparatorResult = semver.compareIdentifiers(str, str);
comparatorResult = semver.rcompareIdentifiers(str, str);
versionsArr = semver.sort(['', new semver.SemVer('')]);
versionsArr = semver.rsort(['', new semver.SemVer('')]);
diff = semver.diff(v1, v2, loose);

// Ranges
str = semver.validRange(str, loose);
bool = semver.satisfies(version, str, loose);
str = semver.maxSatisfying(versions, str, loose);
str = semver.minSatisfying(versions, str, loose);
bool = semver.gtr(version, str, loose);
bool = semver.ltr(version, str, loose);
bool = semver.outside(version, str, '<', loose);
bool = semver.intersects(str, str, loose);

let ver = new semver.SemVer(str, bool);
str = ver.raw;
bool = ver.loose;
str = ver.format();
str = ver.inspect();
str = ver.toString();

num = ver.major;
num = ver.minor;
开发者ID:PriceSpider-NeuIntel,项目名称:DefinitelyTyped,代码行数:31,代码来源:semver-tests.ts


注:本文中的semver.maxSatisfying函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。