Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to the update command #6983

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,28 @@ describe('DepenendencyResolverMain.getOutdatedPkgsFromPolicies()', () => {
const packageManagerSlot = {
// @ts-ignore
get: () => ({
resolveRemoteVersion: (spec: string) => ({
version: {
'root-runtime-dep1@latest': '2.0.0',
'root-peer-dep1@latest': '2.0.0',
'variant1-runtime-dep1@latest': '2.0.0',
'variant1-runtime-dep3@latest': '2.0.0',
'variant1-dev-dep1@latest': '2.0.0',
'variant1-dev-dep3@latest': '2.0.0',
'variant1-peer-dep1@latest': '2.0.0',
'variant1-peer-dep3@latest': '2.0.0',
'component1-runtime-dep1@latest': '2.0.0',
'component1-runtime-dep3@latest': '2.0.0',
'component1-dev-dep1@latest': '2.0.0',
'component1-dev-dep3@latest': '2.0.0',
'component1-peer-dep1@latest': '2.0.0',
'component1-peer-dep3@latest': '2.0.0',
}[spec],
}),
resolveRemoteVersion: (spec: string) => {
if (spec === 'cannot-resolve@latest') throw new Error('Cannot resolve latest');
return {
version: {
'root-runtime-dep1@latest': '2.0.0',
'root-peer-dep1@latest': '2.0.0',
'variant1-runtime-dep1@latest': '2.0.0',
'variant1-runtime-dep3@latest': '2.0.0',
'variant1-dev-dep1@latest': '2.0.0',
'variant1-dev-dep3@latest': '2.0.0',
'variant1-peer-dep1@latest': '2.0.0',
'variant1-peer-dep3@latest': '2.0.0',
'component1-runtime-dep1@latest': '2.0.0',
'component1-runtime-dep3@latest': '2.0.0',
'component1-dev-dep1@latest': '2.0.0',
'component1-dev-dep3@latest': '2.0.0',
'component1-peer-dep1@latest': '2.0.0',
'component1-peer-dep3@latest': '2.0.0',
'pkg-with-old-latest@latest': '0.0.0',
}[spec],
};
},
getNetworkConfig: () => ({}),
}),
};
Expand Down Expand Up @@ -274,6 +278,8 @@ describe('DepenendencyResolverMain.getOutdatedPkgsFromPolicies()', () => {
componentPoliciesById: {
component1: {
dependencies: {
'pkg-with-old-latest': '1.0.0',
'cannot-resolve': '1.0.0',
'component1-runtime-dep1': '1.0.0',
'component1-runtime-dep2': '1.0.0',
'component1-runtime-dep3': '-',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getAllCoreAspectsIds } from '@teambit/bit';
import ComponentAspect, { Component, ComponentMap, ComponentMain, IComponent, ComponentID } from '@teambit/component';
import type { ConfigMain } from '@teambit/config';
import { join } from 'path';
import { get, pick, uniq } from 'lodash';
import { compact, get, pick, uniq } from 'lodash';
import { ConfigAspect } from '@teambit/config';
import { DependenciesEnv, EnvDefinition, EnvsAspect, EnvsMain } from '@teambit/envs';
import { Slot, SlotRegistry, ExtensionManifest, Aspect, RuntimeManifest } from '@teambit/harmony';
Expand Down Expand Up @@ -1308,23 +1308,34 @@ export class DependencyResolverMain {
): Promise<Array<{ name: string; currentRange: string; latestRange: string } & T>> {
this.logger.setStatusLine('checking the latest versions of dependencies');
const resolver = await this.getVersionResolver();
const resolve = async (spec: string) =>
(
await resolver.resolveRemoteVersion(spec, {
rootDir,
})
).version;
const outdatedPkgs = (
const tryResolve = async (spec: string) => {
try {
return (
await resolver.resolveRemoteVersion(spec, {
rootDir,
})
).version;
} catch {
// If latest cannot be found for the package, then just ignore it
return null;
}
};
const outdatedPkgs = compact(
await Promise.all(
pkgs.map(async (pkg) => {
const latestVersion = await resolve(`${pkg.name}@latest`);
const latestVersion = await tryResolve(`${pkg.name}@latest`);
if (!latestVersion) return null;
const currentVersion = semver.valid(pkg.currentRange.replace(/[\^~]/, ''));
// If the current version is newer than the latest, then no need to update the dependency
if (currentVersion && (semver.gt(currentVersion, latestVersion) || currentVersion === latestVersion))
return null;
return {
...pkg,
latestRange: latestVersion ? repeatPrefix(pkg.currentRange, latestVersion) : null,
latestRange: repeatPrefix(pkg.currentRange, latestVersion),
} as any;
})
)
).filter(({ latestRange, currentRange }) => latestRange != null && latestRange !== currentRange);
);
this.logger.consoleSuccess();
return outdatedPkgs;
}
Expand Down