UNPKG

@teambit/checkout

Version:
56 lines (55 loc) 3.4 kB
import type { Consumer } from '@teambit/legacy.consumer'; import type { ComponentID } from '@teambit/component-id'; import type { Version } from '@teambit/objects'; import type { SourceFile } from '@teambit/component.sources'; import type { ConsumerComponent } from '@teambit/legacy.consumer-component'; import type { ApplyVersionResult, FilesStatus, MergeResultsThreeWay } from '@teambit/component.modules.merge-helper'; import type { CheckoutProps } from './checkout.main.runtime'; export type ComponentStatusBase = { currentComponent?: ConsumerComponent; componentFromModel?: Version; id: ComponentID; shouldBeRemoved?: boolean; unchangedMessage?: string; unchangedLegitimately?: boolean; }; export type ComponentStatus = ComponentStatusBase & { mergeResults?: MergeResultsThreeWay | null | undefined; }; export type ApplyVersionWithComps = { applyVersionResult: ApplyVersionResult; component?: ConsumerComponent; legacyCompToWrite?: ConsumerComponent; }; /** * This function optionally returns "component" object. If it returns, it means it needs to be written to the filesystem. * Otherwise, it means the component is already up to date and no need to write it. * * If no need to change anything (ours), then don't return the component object. * Otherwise, either return the component object as is (if no conflicts or "theirs"), or change the files in this * component object. Later, this component object is written to the filesystem. * * 1) when the files are modified with conflicts and the strategy is "ours", or forceOurs was used, leave the FS as is. * * 2) when the files are modified with conflicts and the strategy is "theirs", or forceTheirs was used, write the * component according to "component" object * * 3) when files are modified with no conflict or files are modified with conflicts and the * strategy is manual, load the component according to id.version and update component.files. * applyModifiedVersion() docs explains what files are updated/added. * * Side note: * Deleted file => if files are in used version but not in the modified one, no need to delete it. (similar to git). * Added file => if files are not in used version but in the modified one, they'll be under mergeResults.addFiles */ export declare function applyVersion(consumer: Consumer, id: ComponentID, componentFromFS: ConsumerComponent | null | undefined, // it can be null only when isLanes is true mergeResults: MergeResultsThreeWay | null | undefined, checkoutProps: CheckoutProps): Promise<ApplyVersionWithComps>; export declare function updateFileStatus(files: SourceFile[], filesStatus: FilesStatus, componentFromFS?: ConsumerComponent): void; /** * when files exist on the filesystem but not on the checked out versions, they need to be deleted. * without this function, these files would be left on the filesystem. (we don't delete the comp-dir before writing). * this needs to be done *before* the component is written to the filesystem, otherwise, it won't work when a file * has a case change. e.g. from uppercase to lowercase. (see merge-lane.e2e 'renaming files from uppercase to lowercase'). */ export declare function removeFilesIfNeeded(filesStatus: FilesStatus, consumer: Consumer, componentFromFS?: ConsumerComponent): Promise<void>; export declare function throwForFailures(allComponentsStatus: ComponentStatusBase[]): void;