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

fix(snap), avoid importing-delta when isolating non-modified comps #7284

Merged
merged 1 commit into from
Apr 19, 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
24 changes: 2 additions & 22 deletions src/consumer/component/sources/artifact-files.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra';
import path from 'path';
import R from 'ramda';
import { BitId, BitIds } from '../../../bit-id';
import { BitId } from '../../../bit-id';
import ShowDoctorError from '../../../error/show-doctor-error';
import logger from '../../../logger/logger';
import { Scope } from '../../../scope';
Expand Down Expand Up @@ -162,31 +162,12 @@ export async function importMultipleDistsArtifacts(scope: Scope, components: Com
const extensionsNamesForDistArtifacts = 'teambit.compilation/compiler';
const lane = await scope.getCurrentLaneObject();
const scopeComponentsImporter = scope.scopeImporter;
if (lane) {
// when on lane, locally, it's possible that not all components have their entire history (e.g. during "bit sign").
// as a result, the following "scope.isIdOnLane" fails to traverse the history.
// in terms of performance it's not ideal. once we have the lane-history, it'll be faster to get this data.
const compsIds = BitIds.fromArray(components.map((c) => c.id));
const compsToImport = BitIds.uniqFromArray(lane.toBitIds().filter((id) => compsIds.hasWithoutVersion(id)));
await scopeComponentsImporter.importManyDeltaWithoutDeps({
ids: compsToImport,
fromHead: true,
lane,
ignoreMissingHead: true,
});
// fetch also the components from main, otherwise, in some cases, you'll get an error: "error: version "some-snap" of component some-comp was not found on the filesystem."
await scopeComponentsImporter.importManyDeltaWithoutDeps({
ids: compsToImport.toVersionLatest(),
fromHead: true,
ignoreMissingHead: true,
});
}
const groupedHashes: { [scopeName: string]: string[] } = {};
const debugHashesOrigin = {};
await Promise.all(
components.map(async (component) => {
const artifactsFiles = getArtifactFilesByExtension(component.extensions, extensionsNamesForDistArtifacts);
const isIdOnLane = await scope.isIdOnLane(component.id, lane);
const isIdOnLane = await scope.isIdOnLane(component.id, lane, false);
const getScopes = () => {
if (isIdOnLane === null) {
// we're not sure wether it's on the lane or not. try to fetch from both.
Expand Down Expand Up @@ -216,7 +197,6 @@ export async function importMultipleDistsArtifacts(scope: Scope, components: Com
logger.error('failed fetching the following hashes', { groupedHashes, debugHashesOrigin });
throw err;
}

logger.debug(`importMultipleDistsArtifacts: ${components.length} components. completed successfully`);
}

Expand Down
4 changes: 3 additions & 1 deletion src/scope/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,15 @@ once done, to continue working, please run "bit cc"`

/**
* returns null if we can't determine whether it's on the lane or not.
* if throwForDivergeDataErr is false, it also returns null when divergeData wasn't able to get Version objects or failed for whatever reason.
*
* sadly, there are not good tests for this. it pretty complex to create them as it involves multiple scopes and
* packages installations. be careful when changing this.
* the goal is to check whether a given id with the given version exits on the given lane or it's on main.
* it's needed for importing artifacts to know whether the artifact could be found on the origin scope or on the
* lane-scope
*/
async isIdOnLane(id: BitId, lane?: Lane | null): Promise<boolean | null> {
async isIdOnLane(id: BitId, lane?: Lane | null, throwForDivergeDataErr = true): Promise<boolean | null> {
if (!lane) return false;

// it's possible that main was merged to the lane, so the ref in the lane object is actually a tag.
Expand All @@ -373,6 +374,7 @@ once done, to continue working, please run "bit cc"`
const divergeData = await getDivergeData({
repo: this.objects,
modelComponent: component,
throws: throwForDivergeDataErr,
targetHead: component.head, // target is main
sourceHead: Ref.from(laneIdWithDifferentVersion.version as string), // source is lane
});
Expand Down