@teambit/snapping 1.0.981 → 1.0.983

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,6 +49,10 @@ async function removeLocalVersion(consumer, id, lane, head, force = false) {
49
49
  const component = await consumer.scope.getModelComponent(id);
50
50
  const idStr = id.toString();
51
51
  const fromBitmap = consumer.bitMap.getComponentIdIfExist(id);
52
+ // populate lane-aware heads so `getLocalHashes` diverges against the LANE remote head, not
53
+ // the empty main one — otherwise a hidden cascade entry (no bitmap row, no main-side state)
54
+ // would treat the entire local history as "local" and wipe the seeded base on reset.
55
+ if (lane) await component.populateLocalAndRemoteHeads(consumer.scope.objects, lane);
52
56
  const localVersions = await component.getLocalHashes(consumer.scope.objects, fromBitmap);
53
57
  if (!localVersions.length) throw new (_bitError().BitError)(`unable to untag ${idStr}, the component is not staged`);
54
58
  const headRef = component.getHeadRegardlessOfLane();
@@ -134,6 +138,9 @@ async function removeLocalVersionsForMultipleComponents(consumer, componentsToUn
134
138
  async function getComponentsWithOptionToUntag(workspace, remove) {
135
139
  const componentList = new (_legacy().ComponentsList)(workspace);
136
140
  const laneObj = await workspace.getCurrentLaneObject();
141
+ // The result includes hidden updateDependents — `bit reset` reverts cascade snaps end-to-end.
142
+ // The bitmap-update step in `snapping.reset` skips hidden entries explicitly so we don't try
143
+ // to write workspace state for components that don't live in the workspace.
137
144
  const components = await componentList.listExportPendingComponents(laneObj);
138
145
  const removedStagedIds = await remove.getRemovedStaged();
139
146
  if (!removedStagedIds.length) return components;
@@ -1 +1 @@
1
- {"version":3,"names":["_lodash","data","require","_bitError","_legacy","_legacy2","_legacy3","removeLocalVersion","consumer","id","lane","head","force","component","scope","getModelComponent","idStr","toString","fromBitmap","bitMap","getComponentIdIfExist","localVersions","getLocalHashes","objects","length","BitError","headRef","getHeadRegardlessOfLane","Error","find","v","isEqual","versionsToRemove","versionsToRemoveStr","switchHashesWithTagsIfExist","dependencyGraph","DependencyGraph","loadAllVersions","forEach","versionToRemove","idWithVersion","toComponentId","changeVersion","dependents","getImmediateDependentsPerId","join","batchIds","versionObjects","Promise","all","map","ver","loadVersion","loadedVersions","compact","Set","batchId","headBefore","getHead","sources","removeComponentVersions","headAfter","versionToSetInBitmap","divergeData","getDivergeData","snapBeforeDetached","commonSnapBeforeDiverge","getTagOfRefIfExists","versions","removeLocalVersionsForAllComponents","workspace","remove","componentsToUntag","getComponentsWithOptionToUntag","removeLocalVersionsForMultipleComponents","candidateComponentsIds","bitId","candidateComponentsIdsStr","dependentsNotCandidates","filter","dependent","includes","version","logger","debug","componentList","ComponentsList","laneObj","getCurrentLaneObject","components","listExportPendingComponents","removedStagedIds","getRemovedStaged","removedStagedBitIds","nonExistsInStaged","c","isEqualWithoutVersion","modelComps","push"],"sources":["reset-component.ts"],"sourcesContent":["import { compact } from 'lodash';\nimport { BitError } from '@teambit/bit-error';\nimport type { ComponentID } from '@teambit/component-id';\nimport type { Consumer } from '@teambit/legacy.consumer';\nimport { ComponentsList } from '@teambit/legacy.component-list';\nimport { logger } from '@teambit/legacy.logger';\nimport type { Lane, ModelComponent } from '@teambit/objects';\nimport type { RemoveMain } from '@teambit/remove';\nimport { DependencyGraph } from '@teambit/legacy.dependency-graph';\nimport type { Workspace } from '@teambit/workspace';\n\nexport type ResetResult = {\n id: ComponentID;\n versions: string[];\n component?: ModelComponent;\n /**\n * relevant when the component was detached head so the head didn't change.\n * we want .bitmap to have the version before the detachment. not as the head.\n */\n versionToSetInBitmap?: string;\n /** batchIds from the version objects being removed, used to clean up lane history entries */\n batchIds?: string[];\n};\n\n/**\n * If head is false, remove all local versions.\n */\nexport async function removeLocalVersion(\n consumer: Consumer,\n id: ComponentID,\n lane?: Lane,\n head?: boolean,\n force = false\n): Promise<ResetResult> {\n const component: ModelComponent = await consumer.scope.getModelComponent(id);\n const idStr = id.toString();\n const fromBitmap = consumer.bitMap.getComponentIdIfExist(id);\n const localVersions = await component.getLocalHashes(consumer.scope.objects, fromBitmap);\n if (!localVersions.length) throw new BitError(`unable to untag ${idStr}, the component is not staged`);\n const headRef = component.getHeadRegardlessOfLane();\n if (!headRef) {\n throw new Error(`unable to reset ${idStr}, it has not head`);\n }\n if (head && !localVersions.find((v) => v.isEqual(headRef))) {\n throw new Error(`unable to reset ${idStr}, the head ${headRef.toString()} is exported`);\n }\n const versionsToRemove = head ? [headRef] : localVersions;\n const versionsToRemoveStr = component.switchHashesWithTagsIfExist(versionsToRemove);\n\n if (!force) {\n const dependencyGraph = await DependencyGraph.loadAllVersions(consumer.scope);\n\n versionsToRemoveStr.forEach((versionToRemove) => {\n const idWithVersion = component.toComponentId().changeVersion(versionToRemove);\n const dependents = dependencyGraph.getImmediateDependentsPerId(idWithVersion);\n if (dependents.length) {\n throw new BitError(\n `unable to reset ${idStr}, the version ${versionToRemove} has the following dependent(s) ${dependents.join(\n ', '\n )}`\n );\n }\n });\n }\n\n // Load version objects to extract batchIds before they are removed.\n // These batchIds are used to clean up the corresponding lane history entries.\n // Only needed on lanes — on main there's no lane history to clean up.\n let batchIds: string[] | undefined;\n if (lane) {\n const versionObjects = await Promise.all(\n versionsToRemoveStr.map((ver) => component.loadVersion(ver, consumer.scope.objects, false))\n );\n const loadedVersions = compact(versionObjects);\n batchIds = [...new Set(compact(loadedVersions.map((v) => v.batchId)))];\n }\n\n const headBefore = component.getHead();\n await consumer.scope.sources.removeComponentVersions(component, versionsToRemove, versionsToRemoveStr, lane, head);\n const headAfter = component.getHead();\n let versionToSetInBitmap;\n if (headBefore && headAfter && headBefore.isEqual(headAfter) && !lane) {\n // if it's on main and the head didn't change, it means that it was in a detached-head state.\n const divergeData = component.getDivergeData();\n const snapBeforeDetached = divergeData.commonSnapBeforeDiverge;\n if (snapBeforeDetached) versionToSetInBitmap = component.getTagOfRefIfExists(snapBeforeDetached);\n }\n\n return { id, versions: versionsToRemoveStr, component, versionToSetInBitmap, batchIds };\n}\n\nexport async function removeLocalVersionsForAllComponents(\n workspace: Workspace,\n remove: RemoveMain,\n lane?: Lane,\n head?: boolean\n): Promise<ResetResult[]> {\n const componentsToUntag = await getComponentsWithOptionToUntag(workspace, remove);\n const force = true; // when removing local versions from all components, no need to check if the component is used as a dependency\n return removeLocalVersionsForMultipleComponents(workspace.consumer, componentsToUntag, lane, head, force);\n}\n\nexport async function removeLocalVersionsForMultipleComponents(\n consumer: Consumer,\n componentsToUntag: ModelComponent[],\n lane?: Lane,\n head?: boolean,\n force?: boolean\n) {\n if (!componentsToUntag.length) {\n throw new BitError(`no components found to reset on your workspace`);\n }\n // if only head is removed, there is risk of deleting dependencies version without their dependents.\n if (!force && head) {\n const dependencyGraph = await DependencyGraph.loadAllVersions(consumer.scope);\n const candidateComponentsIds = componentsToUntag.map((component) => {\n const bitId = component.toComponentId();\n const headRef = component.getHeadRegardlessOfLane();\n if (!headRef)\n throw new Error(`component ${bitId.toString()} does not have head. it should not be a candidate for reset`);\n\n return bitId.changeVersion(component.getTagOfRefIfExists(headRef) || headRef.toString());\n });\n const candidateComponentsIdsStr = candidateComponentsIds.map((id) => id.toString());\n candidateComponentsIds.forEach((bitId: ComponentID) => {\n const dependents = dependencyGraph.getImmediateDependentsPerId(bitId);\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const dependentsNotCandidates = dependents.filter((dependent) => !candidateComponentsIdsStr.includes(dependent));\n if (dependentsNotCandidates.length) {\n throw new BitError( // $FlowFixMe\n `unable to untag ${bitId}, the version ${bitId.version} has the following dependent(s) ${dependents.join(\n ', '\n )}`\n );\n }\n });\n }\n logger.debug(`found ${componentsToUntag.length} components to untag`);\n return Promise.all(\n componentsToUntag.map((component) => removeLocalVersion(consumer, component.toComponentId(), lane, head, force))\n );\n}\n\nexport async function getComponentsWithOptionToUntag(\n workspace: Workspace,\n remove: RemoveMain\n): Promise<ModelComponent[]> {\n const componentList = new ComponentsList(workspace);\n const laneObj = await workspace.getCurrentLaneObject();\n const components: ModelComponent[] = await componentList.listExportPendingComponents(laneObj);\n const removedStagedIds = await remove.getRemovedStaged();\n if (!removedStagedIds.length) return components;\n const removedStagedBitIds = removedStagedIds.map((id) => id);\n const nonExistsInStaged = removedStagedBitIds.filter(\n (id) => !components.find((c) => c.toComponentId().isEqualWithoutVersion(id))\n );\n if (!nonExistsInStaged.length) return components;\n const modelComps = await Promise.all(nonExistsInStaged.map((id) => workspace.consumer.scope.getModelComponent(id)));\n components.push(...modelComps);\n\n return components;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,UAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAK,SAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,QAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAgBA;AACA;AACA;AACO,eAAeM,kBAAkBA,CACtCC,QAAkB,EAClBC,EAAe,EACfC,IAAW,EACXC,IAAc,EACdC,KAAK,GAAG,KAAK,EACS;EACtB,MAAMC,SAAyB,GAAG,MAAML,QAAQ,CAACM,KAAK,CAACC,iBAAiB,CAACN,EAAE,CAAC;EAC5E,MAAMO,KAAK,GAAGP,EAAE,CAACQ,QAAQ,CAAC,CAAC;EAC3B,MAAMC,UAAU,GAAGV,QAAQ,CA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AC;EAC5D,MAAMqF,iBAAiB,GAAGD,mBAAmB,CAACd,MAAM,CACjDtE,EAAE,IAAK,CAACgF,UAAU,CAAC5D,IAAI,CAAEkE,CAAC,IAAKA,CAAC,CAACtD,aAAa,CAAC,CAAC,CAACuD,qBAAqB,CAACvF,EAAE,CAAC,CAC7E,CAAC;EACD,IAAI,CAACqF,iBAAiB,CAACtE,MAAM,EAAE,OAAOiE,UAAU;EAChD,MAAMQ,UAAU,GAAG,MAAMjD,OAAO,CAACC,GAAG,CAAC6C,iBAAiB,CAAC5C,GAAG,CAAEzC,EAAE,IAAK6D,SAAS,CAAC9D,QAAQ,CAACM,KAAK,CAACC,iBAAiB,CAACN,EAAE,CAAC,CAAC,CAAC;EACnHgF,UAAU,CAACS,IAAI,CAAC,GAAGD,UAAU,CAAC;EAE9B,OAAOR,UAAU;AACnB","ignoreList":[]}
1
+ {"version":3,"names":["_lodash","data","require","_bitError","_legacy","_legacy2","_legacy3","removeLocalVersion","consumer","id","lane","head","force","component","scope","getModelComponent","idStr","toString","fromBitmap","bitMap","getComponentIdIfExist","populateLocalAndRemoteHeads","objects","localVersions","getLocalHashes","length","BitError","headRef","getHeadRegardlessOfLane","Error","find","v","isEqual","versionsToRemove","versionsToRemoveStr","switchHashesWithTagsIfExist","dependencyGraph","DependencyGraph","loadAllVersions","forEach","versionToRemove","idWithVersion","toComponentId","changeVersion","dependents","getImmediateDependentsPerId","join","batchIds","versionObjects","Promise","all","map","ver","loadVersion","loadedVersions","compact","Set","batchId","headBefore","getHead","sources","removeComponentVersions","headAfter","versionToSetInBitmap","divergeData","getDivergeData","snapBeforeDetached","commonSnapBeforeDiverge","getTagOfRefIfExists","versions","removeLocalVersionsForAllComponents","workspace","remove","componentsToUntag","getComponentsWithOptionToUntag","removeLocalVersionsForMultipleComponents","candidateComponentsIds","bitId","candidateComponentsIdsStr","dependentsNotCandidates","filter","dependent","includes","version","logger","debug","componentList","ComponentsList","laneObj","getCurrentLaneObject","components","listExportPendingComponents","removedStagedIds","getRemovedStaged","removedStagedBitIds","nonExistsInStaged","c","isEqualWithoutVersion","modelComps","push"],"sources":["reset-component.ts"],"sourcesContent":["import { compact } from 'lodash';\nimport { BitError } from '@teambit/bit-error';\nimport type { ComponentID } from '@teambit/component-id';\nimport type { Consumer } from '@teambit/legacy.consumer';\nimport { ComponentsList } from '@teambit/legacy.component-list';\nimport { logger } from '@teambit/legacy.logger';\nimport type { Lane, ModelComponent } from '@teambit/objects';\nimport type { RemoveMain } from '@teambit/remove';\nimport { DependencyGraph } from '@teambit/legacy.dependency-graph';\nimport type { Workspace } from '@teambit/workspace';\n\nexport type ResetResult = {\n id: ComponentID;\n versions: string[];\n component?: ModelComponent;\n /**\n * relevant when the component was detached head so the head didn't change.\n * we want .bitmap to have the version before the detachment. not as the head.\n */\n versionToSetInBitmap?: string;\n /** batchIds from the version objects being removed, used to clean up lane history entries */\n batchIds?: string[];\n};\n\n/**\n * If head is false, remove all local versions.\n */\nexport async function removeLocalVersion(\n consumer: Consumer,\n id: ComponentID,\n lane?: Lane,\n head?: boolean,\n force = false\n): Promise<ResetResult> {\n const component: ModelComponent = await consumer.scope.getModelComponent(id);\n const idStr = id.toString();\n const fromBitmap = consumer.bitMap.getComponentIdIfExist(id);\n // populate lane-aware heads so `getLocalHashes` diverges against the LANE remote head, not\n // the empty main one — otherwise a hidden cascade entry (no bitmap row, no main-side state)\n // would treat the entire local history as \"local\" and wipe the seeded base on reset.\n if (lane) await component.populateLocalAndRemoteHeads(consumer.scope.objects, lane);\n const localVersions = await component.getLocalHashes(consumer.scope.objects, fromBitmap);\n if (!localVersions.length) throw new BitError(`unable to untag ${idStr}, the component is not staged`);\n const headRef = component.getHeadRegardlessOfLane();\n if (!headRef) {\n throw new Error(`unable to reset ${idStr}, it has not head`);\n }\n if (head && !localVersions.find((v) => v.isEqual(headRef))) {\n throw new Error(`unable to reset ${idStr}, the head ${headRef.toString()} is exported`);\n }\n const versionsToRemove = head ? [headRef] : localVersions;\n const versionsToRemoveStr = component.switchHashesWithTagsIfExist(versionsToRemove);\n\n if (!force) {\n const dependencyGraph = await DependencyGraph.loadAllVersions(consumer.scope);\n\n versionsToRemoveStr.forEach((versionToRemove) => {\n const idWithVersion = component.toComponentId().changeVersion(versionToRemove);\n const dependents = dependencyGraph.getImmediateDependentsPerId(idWithVersion);\n if (dependents.length) {\n throw new BitError(\n `unable to reset ${idStr}, the version ${versionToRemove} has the following dependent(s) ${dependents.join(\n ', '\n )}`\n );\n }\n });\n }\n\n // Load version objects to extract batchIds before they are removed.\n // These batchIds are used to clean up the corresponding lane history entries.\n // Only needed on lanes — on main there's no lane history to clean up.\n let batchIds: string[] | undefined;\n if (lane) {\n const versionObjects = await Promise.all(\n versionsToRemoveStr.map((ver) => component.loadVersion(ver, consumer.scope.objects, false))\n );\n const loadedVersions = compact(versionObjects);\n batchIds = [...new Set(compact(loadedVersions.map((v) => v.batchId)))];\n }\n\n const headBefore = component.getHead();\n await consumer.scope.sources.removeComponentVersions(component, versionsToRemove, versionsToRemoveStr, lane, head);\n const headAfter = component.getHead();\n let versionToSetInBitmap;\n if (headBefore && headAfter && headBefore.isEqual(headAfter) && !lane) {\n // if it's on main and the head didn't change, it means that it was in a detached-head state.\n const divergeData = component.getDivergeData();\n const snapBeforeDetached = divergeData.commonSnapBeforeDiverge;\n if (snapBeforeDetached) versionToSetInBitmap = component.getTagOfRefIfExists(snapBeforeDetached);\n }\n\n return { id, versions: versionsToRemoveStr, component, versionToSetInBitmap, batchIds };\n}\n\nexport async function removeLocalVersionsForAllComponents(\n workspace: Workspace,\n remove: RemoveMain,\n lane?: Lane,\n head?: boolean\n): Promise<ResetResult[]> {\n const componentsToUntag = await getComponentsWithOptionToUntag(workspace, remove);\n const force = true; // when removing local versions from all components, no need to check if the component is used as a dependency\n return removeLocalVersionsForMultipleComponents(workspace.consumer, componentsToUntag, lane, head, force);\n}\n\nexport async function removeLocalVersionsForMultipleComponents(\n consumer: Consumer,\n componentsToUntag: ModelComponent[],\n lane?: Lane,\n head?: boolean,\n force?: boolean\n) {\n if (!componentsToUntag.length) {\n throw new BitError(`no components found to reset on your workspace`);\n }\n // if only head is removed, there is risk of deleting dependencies version without their dependents.\n if (!force && head) {\n const dependencyGraph = await DependencyGraph.loadAllVersions(consumer.scope);\n const candidateComponentsIds = componentsToUntag.map((component) => {\n const bitId = component.toComponentId();\n const headRef = component.getHeadRegardlessOfLane();\n if (!headRef)\n throw new Error(`component ${bitId.toString()} does not have head. it should not be a candidate for reset`);\n\n return bitId.changeVersion(component.getTagOfRefIfExists(headRef) || headRef.toString());\n });\n const candidateComponentsIdsStr = candidateComponentsIds.map((id) => id.toString());\n candidateComponentsIds.forEach((bitId: ComponentID) => {\n const dependents = dependencyGraph.getImmediateDependentsPerId(bitId);\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const dependentsNotCandidates = dependents.filter((dependent) => !candidateComponentsIdsStr.includes(dependent));\n if (dependentsNotCandidates.length) {\n throw new BitError( // $FlowFixMe\n `unable to untag ${bitId}, the version ${bitId.version} has the following dependent(s) ${dependents.join(\n ', '\n )}`\n );\n }\n });\n }\n logger.debug(`found ${componentsToUntag.length} components to untag`);\n return Promise.all(\n componentsToUntag.map((component) => removeLocalVersion(consumer, component.toComponentId(), lane, head, force))\n );\n}\n\nexport async function getComponentsWithOptionToUntag(\n workspace: Workspace,\n remove: RemoveMain\n): Promise<ModelComponent[]> {\n const componentList = new ComponentsList(workspace);\n const laneObj = await workspace.getCurrentLaneObject();\n // The result includes hidden updateDependents — `bit reset` reverts cascade snaps end-to-end.\n // The bitmap-update step in `snapping.reset` skips hidden entries explicitly so we don't try\n // to write workspace state for components that don't live in the workspace.\n const components: ModelComponent[] = await componentList.listExportPendingComponents(laneObj);\n const removedStagedIds = await remove.getRemovedStaged();\n if (!removedStagedIds.length) return components;\n const removedStagedBitIds = removedStagedIds.map((id) => id);\n const nonExistsInStaged = removedStagedBitIds.filter(\n (id) => !components.find((c) => c.toComponentId().isEqualWithoutVersion(id))\n );\n if (!nonExistsInStaged.length) return components;\n const modelComps = await Promise.all(nonExistsInStaged.map((id) => workspace.consumer.scope.getModelComponent(id)));\n components.push(...modelComps);\n\n return components;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,UAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAK,SAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,QAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAgBA;AACA;AACA;AACO,eAAeM,kBAAkBA,CACtCC,QAAkB,EAClBC,EAAe,EACfC,IAAW,EACXC,IAAc,EACdC,KAAK,GAAG,KAAK,EACS;EACtB,MAAMC,SAAyB,GAAG,MAAML,QAAQ,CAACM,KAAK,CAACC,iBAAiB,CAACN,EAAE,CAAC;EAC5E,MAAMO,KAAK,GAAGP,EAAE,CAACQ,QAAQ,CAAC,CAAC;EAC3B,MAAMC,UAAU,GAAGV,QAAQ,CAACW,MAAM,CAACC,qBAAqB,CAACX,EAAE,CAAC;EAC5D;EACA;EACA;EACA,IAAIC,IAAI,EAAE,MAAMG,SAAS,CAACQ,2BAA2B,CAACb,QAAQ,CAACM,KAAK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A,EAAE,CAAC;EAC5D,MAAMsF,iBAAiB,GAAGD,mBAAmB,CAACd,MAAM,CACjDvE,EAAE,IAAK,CAACiF,UAAU,CAAC5D,IAAI,CAAEkE,CAAC,IAAKA,CAAC,CAACtD,aAAa,CAAC,CAAC,CAACuD,qBAAqB,CAACxF,EAAE,CAAC,CAC7E,CAAC;EACD,IAAI,CAACsF,iBAAiB,CAACtE,MAAM,EAAE,OAAOiE,UAAU;EAChD,MAAMQ,UAAU,GAAG,MAAMjD,OAAO,CAACC,GAAG,CAAC6C,iBAAiB,CAAC5C,GAAG,CAAE1C,EAAE,IAAK8D,SAAS,CAAC/D,QAAQ,CAACM,KAAK,CAACC,iBAAiB,CAACN,EAAE,CAAC,CAAC,CAAC;EACnHiF,UAAU,CAACS,IAAI,CAAC,GAAGD,UAAU,CAAC;EAE9B,OAAOR,UAAU;AACnB","ignoreList":[]}
@@ -160,6 +160,31 @@ export declare class SnappingMain {
160
160
  unmodified?: boolean;
161
161
  exitOnFirstFailedTask?: boolean;
162
162
  }): Promise<SnapResults | null>;
163
+ /**
164
+ * Workspace-side merge snap. Routes both visible workspace components AND hidden lane
165
+ * lane.updateDependents through the same `makeVersion` pipeline that
166
+ * `snap`/`snapFromScope` use, so cascade snaps get fresh log/buildStatus/flattenedDependencies/
167
+ * lane-history/stagedSnaps just like every other snap.
168
+ *
169
+ * Visible: workspace.getMany picks up files written to disk by `applyVersion`.
170
+ * Hidden: applyVersion's in-memory merged ConsumerComponents are passed in directly — they
171
+ * have no bitmap entry, so they can't go through `loadComponentsForTagOrSnap`.
172
+ *
173
+ * version-maker's `isHiddenLaneEntry` detection (workspace-flow: not-in-bitmap) routes the
174
+ * hidden ones to the right branches (no bitmap update, stagedSnaps tracking,
175
+ * `addToUpdateDependentsInLane`).
176
+ */
177
+ snapForMerge({ visibleIds, hiddenLegacyComponents, message, build, loose, }: {
178
+ visibleIds: ComponentIdList;
179
+ hiddenLegacyComponents: ConsumerComponent[];
180
+ message?: string;
181
+ build?: boolean;
182
+ loose?: boolean;
183
+ }): Promise<{
184
+ snappedComponents: ConsumerComponent[];
185
+ autoSnappedResults: AutoTagResult[];
186
+ removedComponents?: ComponentIdList;
187
+ } | null>;
163
188
  /**
164
189
  * remove tags/snaps that exist locally, which were not exported yet.
165
190
  * once a tag/snap is exported, it's impossible to delete it as other components may depend on it
@@ -638,11 +638,17 @@ class SnappingMain {
638
638
  let exportedIds;
639
639
  if (params.push) {
640
640
  const updatedLane = lane ? await this.scope.legacyScope.loadLane(lane.toLaneId()) : undefined;
641
+ // include auto-tagged ids in the export set. For the bare-scope reverse cascade
642
+ // (`snapFromScope({ updateDependents: true })`), `getLaneAutoTagIdsFromScope` re-snaps
643
+ // lane.components that depend on the new hidden entry, and those new snaps must be pushed
644
+ // alongside the explicit target.
645
+ const autoTaggedIds = (results.autoTaggedResults || []).map(r => r.component.id);
646
+ const idsToExport = _componentId().ComponentIdList.uniqFromArray([...ids, ...autoTaggedIds]);
641
647
  const {
642
648
  exported
643
649
  } = await this.exporter.pushToScopes({
644
650
  scope: this.scope.legacyScope,
645
- ids,
651
+ ids: idsToExport,
646
652
  allVersions: false,
647
653
  laneObject: updatedLane,
648
654
  // no need other snaps. only the latest one. without this option, when snapping on lane from another-scope, it
@@ -769,6 +775,64 @@ in case you're unsure about the pattern syntax, use "bit pattern [--help]"`);
769
775
  }
770
776
  }
771
777
 
778
+ /**
779
+ * Workspace-side merge snap. Routes both visible workspace components AND hidden lane
780
+ * lane.updateDependents through the same `makeVersion` pipeline that
781
+ * `snap`/`snapFromScope` use, so cascade snaps get fresh log/buildStatus/flattenedDependencies/
782
+ * lane-history/stagedSnaps just like every other snap.
783
+ *
784
+ * Visible: workspace.getMany picks up files written to disk by `applyVersion`.
785
+ * Hidden: applyVersion's in-memory merged ConsumerComponents are passed in directly — they
786
+ * have no bitmap entry, so they can't go through `loadComponentsForTagOrSnap`.
787
+ *
788
+ * version-maker's `isHiddenLaneEntry` detection (workspace-flow: not-in-bitmap) routes the
789
+ * hidden ones to the right branches (no bitmap update, stagedSnaps tracking,
790
+ * `addToUpdateDependentsInLane`).
791
+ */
792
+ async snapForMerge({
793
+ visibleIds,
794
+ hiddenLegacyComponents,
795
+ message,
796
+ build,
797
+ loose
798
+ }) {
799
+ if (!this.workspace) throw new (_workspace().OutsideWorkspaceError)();
800
+ if (!visibleIds.length && !hiddenLegacyComponents.length) return null;
801
+ this.logger.debug(`snapForMerge, visible: ${visibleIds.length}, hidden: ${hiddenLegacyComponents.length}`);
802
+ const visibleHarmony = visibleIds.length ? await this.loadComponentsForTagOrSnap(visibleIds) : [];
803
+ const hiddenHarmony = hiddenLegacyComponents.length ? await this.scope.getManyByLegacy(hiddenLegacyComponents) : [];
804
+ // issue checks are workspace-source-tree concerns — hidden entries are scope-only
805
+ if (visibleHarmony.length) await this.throwForVariousIssues(visibleHarmony);
806
+ const hiddenIds = _componentId().ComponentIdList.fromArray(hiddenLegacyComponents.map(c => c.componentId));
807
+ const allIds = _componentId().ComponentIdList.uniqFromArray([...visibleIds, ...hiddenIds]);
808
+ const allComponents = [...visibleHarmony, ...hiddenHarmony];
809
+ const makeVersionParams = {
810
+ ignoreNewestVersion: false,
811
+ message: message || '',
812
+ skipTests: false,
813
+ skipAutoTag: false,
814
+ persist: true,
815
+ soft: false,
816
+ build,
817
+ isSnap: true,
818
+ packageManagerConfigRootDir: this.workspace.path,
819
+ loose
820
+ };
821
+ const {
822
+ taggedComponents,
823
+ autoTaggedResults,
824
+ stagedConfig,
825
+ removedComponents
826
+ } = await this.makeVersion(allIds, allComponents, makeVersionParams);
827
+ await this.workspace.consumer.onDestroy(`merge-snap (message: ${message || 'N/A'})`);
828
+ await stagedConfig?.write();
829
+ return {
830
+ snappedComponents: taggedComponents,
831
+ autoSnappedResults: autoTaggedResults,
832
+ removedComponents
833
+ };
834
+ }
835
+
772
836
  /**
773
837
  * remove tags/snaps that exist locally, which were not exported yet.
774
838
  * once a tag/snap is exported, it's impossible to delete it as other components may depend on it
@@ -828,6 +892,11 @@ in case you're unsure about the pattern syntax, use "bit pattern [--help]"`);
828
892
  versionToSetInBitmap
829
893
  }) => {
830
894
  if (!component) return;
895
+ // hidden lane entries (lane.updateDependents) are not in the workspace bitmap, so skip
896
+ // bitmap updates for them. A soft-deleted (visible) entry is also absent from bitmap but
897
+ // `updateVersions` knows how to restore it from stagedConfig.
898
+ const compId = component.toComponentId();
899
+ if (currentLane?.findUpdateDependent(compId)) return;
831
900
  await (0, _versionMaker().updateVersions)(this.workspace, stagedConfig, currentLaneId, component, versionToSetInBitmap, false);
832
901
  });
833
902
  await this.workspace.scope.legacyScope.stagedSnaps.write();