From 6ed501591566d4d5960afe95d21ce32aed355681 Mon Sep 17 00:00:00 2001 From: David First Date: Thu, 22 Feb 2024 09:32:46 -0500 Subject: [PATCH] fix(merge-from-scope), do not throw an error about missing artifacts when merging main to a lane (#8557) Previously, `collectVersionsObjects` had a bug, `ignoreMissingLocalArtifacts` didn't do anything, even when it was `false`, it was still ignoring local artifacts because `locallyChangedHashes.includes(versionObject.hash.toString())` always returned `false`. The `versionObject.hash.toString()` printed the hash method instead of the hash content. It's fixed to be `versionObject.hash().toString()` to make it work. Because of the that bug, https://github.com/teambit/bit/pull/7119 was adding new flag `ignoreMissingExternalArtifacts` unnecessarily. It assumed that an error wasn't thrown because it was external which wasn't correct. In this PR this flag has removed. In addition to this, when merging from scope and merging main to a lane, we can skip the import of the artifacts because once the user asks for the artifacts we retrieve it from main if not found in the lane. One last thing, because until now `ignoreMissingLocalArtifacts` practically did nothing, I'm afraid that after this fix it'll throw errors unnecessarily, so I made the default to not throw when missing. We didn't get any complain about missing artifacts in the remote scopes, so it should be fine. This flag was renamed to `throwForMissingLocalArtifacts` for clarity. The only place we throw is when merging-from-scope and the source is a lane, not main. --- scopes/lanes/merge-lanes/merge-lanes.main.runtime.ts | 7 ++++--- scopes/scope/export/export.main.runtime.ts | 9 +++------ src/scope/models/model-component.ts | 11 +++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/scopes/lanes/merge-lanes/merge-lanes.main.runtime.ts b/scopes/lanes/merge-lanes/merge-lanes.main.runtime.ts index 6228ca520fdd..302710bf8d49 100644 --- a/scopes/lanes/merge-lanes/merge-lanes.main.runtime.ts +++ b/scopes/lanes/merge-lanes/merge-lanes.main.runtime.ts @@ -390,9 +390,10 @@ export class MergeLanesMain { // no need to export anything else other than the head. the normal calculation of what to export won't apply here // as it is done from the scope. exportHeadsOnly: shouldSquash, - // all artifacts must be pushed. they're all considered "external" in this case, because it's running from a - // bare-scope, but we don't want to ignore them, otherwise, they'll be missing from the component-scopes. - ignoreMissingExternalArtifacts: false, + // all artifacts must be pushed. otherwise, they'll be missing from the component-scopes. + // unless this is a merge from main to a lane, in which case it's not necessary to export the artifacts as + // the user importing them will get them from main. + throwForMissingArtifacts: !fromLaneId.isDefault(), exportOrigin: 'lane-merge', }); return exported; diff --git a/scopes/scope/export/export.main.runtime.ts b/scopes/scope/export/export.main.runtime.ts index 706747a24b1a..408122ffce6e 100644 --- a/scopes/scope/export/export.main.runtime.ts +++ b/scopes/scope/export/export.main.runtime.ts @@ -234,8 +234,7 @@ if the export fails with missing objects/versions/components, run "bit fetch --l originDirectly, idsWithFutureScope, resumeExportId, - ignoreMissingArtifacts, - ignoreMissingExternalArtifacts = true, + throwForMissingArtifacts, isOnMain = true, exportHeadsOnly, // relevant when exporting from bare-scope, especially when re-exporting existing versions, the normal calculation based on getDivergeData won't work filterOutExistingVersions, // go to the remote and check whether the version exists there. if so, don't export it @@ -248,8 +247,7 @@ if the export fails with missing objects/versions/components, run "bit fetch --l originDirectly?: boolean; idsWithFutureScope: ComponentIdList; resumeExportId?: string | undefined; - ignoreMissingArtifacts?: boolean; - ignoreMissingExternalArtifacts?: boolean; + throwForMissingArtifacts?: boolean; isOnMain?: boolean; exportHeadsOnly?: boolean; filterOutExistingVersions?: boolean; @@ -419,8 +417,7 @@ if the export fails with missing objects/versions/components, run "bit fetch --l const objectItems = await modelComponent.collectVersionsObjects( scope.objects, refs.map((ref) => ref.toString()), - ignoreMissingArtifacts, - ignoreMissingExternalArtifacts + throwForMissingArtifacts ); const objectsList = await new ObjectList(objectItems).toBitObjects(); const componentAndObject = { component: modelComponent, objects: objectsList.getAll() }; diff --git a/src/scope/models/model-component.ts b/src/scope/models/model-component.ts index b35be4cfea37..7db59682a38c 100644 --- a/src/scope/models/model-component.ts +++ b/src/scope/models/model-component.ts @@ -796,8 +796,7 @@ export default class Component extends BitObject { async collectVersionsObjects( repo: Repository, versions: string[], - ignoreMissingLocalArtifacts = false, - ignoreMissingExternalArtifacts = true + throwForMissingLocalArtifacts = false ): Promise { const refsWithoutArtifacts: Ref[] = []; const artifactsRefs: Ref[] = []; @@ -816,7 +815,7 @@ export default class Component extends BitObject { const refs = versionObject.refsWithOptions(false, false); refsWithoutArtifacts.push(...refs); const refsFromExtensions = getRefsFromExtensions(versionObject.extensions); - locallyChangedHashes.includes(versionObject.hash.toString()) || !ignoreMissingExternalArtifacts + locallyChangedHashes.includes(versionObject.hash().toString()) ? artifactsRefs.push(...refsFromExtensions) : artifactsRefsFromExportedVersions.push(...refsFromExtensions); }); @@ -832,9 +831,9 @@ for a component "${this.id()}", versions: ${versions.join(', ')}`); throw err; } try { - const loaded = ignoreMissingLocalArtifacts - ? await repo.loadManyRawIgnoreMissing(artifactsRefs) - : await repo.loadManyRaw(artifactsRefs); + const loaded = throwForMissingLocalArtifacts + ? await repo.loadManyRaw(artifactsRefs) + : await repo.loadManyRawIgnoreMissing(artifactsRefs); loadedRefs.push(...loaded); // ignore missing artifacts when exporting old versions that were exported in the past and are now exported to a // different scope. this is happening for example when exporting a lane that has components from different