How to use semver-intersect - 5 common examples

To help you get started, we’ve selected a few semver-intersect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / jsii / packages / jsii / lib / project-info.ts View on Github external
for (const name of Object.keys(dependencies)) {
    if (bundled.has(name)) { continue; }
    const { version: versionString, localPackage } = _resolveVersion(dependencies[name], searchPath);
    const version = new semver.Range(versionString!);
    if (!version) {
      throw new Error(`Invalid semver expression for ${name}: ${versionString}`);
    }
    const pkg = _tryResolveAssembly(name, localPackage, searchPath);
    LOG.debug(`Resolved dependency ${name} to ${pkg}`);
    // eslint-disable-next-line no-await-in-loop
    const assm = await loadAndValidateAssembly(pkg);
    if (!version.intersects(new semver.Range(assm.version))) {
      throw new Error(`Declared dependency on version ${versionString} of ${name}, but version ${assm.version} was found`);
    }
    packageVersions[assm.name] = packageVersions[assm.name] != null
      ? intersect(versionString!, packageVersions[assm.name])
      : versionString!;
    transitiveAssemblies[assm.name] = assm;
    const pkgDir = path.dirname(pkg);
    if (assm.dependencies) {
      // eslint-disable-next-line no-await-in-loop
      await _loadDependencies(assm.dependencies, pkgDir, transitiveAssemblies);
    }
  }
  return packageVersions;
}
github angular / angular-cli / packages / schematics / package_update / utility / npm.ts View on Github external
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,
      );
    }),
  );
github angular / angular-cli / packages / schematics / package_update / utility / npm.ts View on Github external
mergeMap(([depName, depVersion]: [string, string]) => {
      if (!packages[depName] || packages[depName] === depVersion) {
        return EMPTY;
      }
      if (allVersions[depName] && semver.intersects(allVersions[depName], depVersion)) {
        allVersions[depName] = semverIntersect.intersect(allVersions[depName], depVersion);

        return EMPTY;
      }

      return _getNpmPackageJson(depName, logger).pipe(
        map(json => ({ version: packages[depName], depName, depVersion, npmPackageJson: json })),
      );
    }),
    mergeMap(({version, depName, depVersion, npmPackageJson}) => {
github angular / angular-cli / packages / schematics / package_update / utility / npm.ts View on Github external
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;
        }
      }
github angular / angular-cli / packages / schematics / package_update / utility / npm.ts View on Github external
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;
        }
      }

semver-intersect

Get the intersection of multiple semver ranges

MIT
Latest version published 12 months ago

Package Health Score

66 / 100
Full package analysis