@@ -28,6 +28,7 @@ import VersionDependencies from '../version-dependencies';
2828import { BitObjectList } from '../objects/bit-object-list' ;
2929import { ObjectFetcher } from '../objects-fetcher/objects-fetcher' ;
3030import { concurrentComponentsLimit } from '../../utils/concurrency' ;
31+ import { BuildStatus } from '../../constants' ;
3132
3233const removeNils = R . reject ( R . isNil ) ;
3334
@@ -82,9 +83,10 @@ export default class ScopeComponentsImporter {
8283 } ) : Promise < VersionDependencies [ ] > {
8384 logger . debugAndAddBreadCrumb (
8485 'importMany' ,
85- `cache ${ cache } , throwForDependencyNotFound: ${ throwForDependencyNotFound } . ids: {ids}` ,
86+ `cache ${ cache } , throwForDependencyNotFound: ${ throwForDependencyNotFound } . ids: {ids}, lanes: {lanes} ` ,
8687 {
8788 ids : ids . toString ( ) ,
89+ lanes : lanes ? lanes . map ( ( lane ) => lane . id ( ) ) . join ( ', ' ) : undefined ,
8890 }
8991 ) ;
9092 const idsToImport = compact ( ids . filter ( ( id ) => id . hasScope ( ) ) ) ;
@@ -232,7 +234,7 @@ export default class ScopeComponentsImporter {
232234 * delta between the local head and the remote head. mainly to improve performance
233235 * not applicable and won't work for legacy. for legacy, refer to importManyWithAllVersions
234236 */
235- async importManyDeltaWithoutDeps ( ids : BitIds , allHistory = false ) : Promise < void > {
237+ async importManyDeltaWithoutDeps ( ids : BitIds , allHistory = false , lane ?: Lane ) : Promise < void > {
236238 logger . debugAndAddBreadCrumb ( 'importManyDeltaWithoutDeps' , `Ids: {ids}` , { ids : ids . toString ( ) } ) ;
237239 const idsWithoutNils = BitIds . uniqFromArray ( compact ( ids ) ) ;
238240 if ( R . isEmpty ( idsWithoutNils ) ) return ;
@@ -243,8 +245,7 @@ export default class ScopeComponentsImporter {
243245 // remove the version to fetch it with all versions.
244246 return id . changeVersion ( undefined ) ;
245247 }
246- // @todo : fix to consider local lane
247- const remoteLaneId = LaneId . from ( DEFAULT_LANE , id . scope as string ) ;
248+ const remoteLaneId = lane ? lane . toLaneId ( ) : LaneId . from ( DEFAULT_LANE , id . scope as string ) ;
248249 const remoteHead = await this . repo . remoteLanes . getRef ( remoteLaneId , id ) ;
249250 if ( ! remoteHead ) {
250251 return id . changeVersion ( undefined ) ;
@@ -258,7 +259,7 @@ export default class ScopeComponentsImporter {
258259 }
259260 return id . changeVersion ( remoteHead . toString ( ) ) ;
260261 } ) ;
261- const groupedIds = groupByScopeName ( idsToFetch ) ;
262+ const groupedIds = lane ? groupByLanes ( idsToFetch , [ lane ] ) : groupByScopeName ( idsToFetch ) ;
262263 const idsOnlyDelta = idsToFetch . filter ( ( id ) => id . hasVersion ( ) ) ;
263264 const idsAllHistory = idsToFetch . filter ( ( id ) => ! id . hasVersion ( ) ) ;
264265 const remotesCount = Object . keys ( groupedIds ) . length ;
@@ -273,8 +274,10 @@ export default class ScopeComponentsImporter {
273274 {
274275 type : 'component-delta' ,
275276 withoutDependencies : true ,
277+ laneId : lane ? lane . id ( ) : undefined ,
276278 } ,
277- idsToFetch
279+ idsToFetch ,
280+ lane ? [ lane ] : undefined
278281 ) . fetchFromRemoteAndWrite ( ) ;
279282 }
280283
@@ -338,15 +341,15 @@ export default class ScopeComponentsImporter {
338341 return compact ( componentVersionArr ) ;
339342 }
340343
341- async fetchWithDeps ( ids : BitIds , allowExternal : boolean ) : Promise < VersionDependencies [ ] > {
344+ async fetchWithDeps ( ids : BitIds , allowExternal : boolean , onlyIfBuild = false ) : Promise < VersionDependencies [ ] > {
342345 logger . debugAndAddBreadCrumb ( 'fetchWithDeps' , `ids: {ids}` , { ids : ids . toString ( ) } ) ;
343346 if ( ! allowExternal ) this . throwIfExternalFound ( ids ) ;
344347 // avoid race condition of getting multiple "fetch" requests, which later translates into
345348 // multiple getExternalMany calls, which saves objects and write refs files at the same time
346349 return this . fetchWithDepsMutex . runExclusive ( async ( ) => {
347350 logger . debug ( 'fetchWithDeps, acquiring a lock' ) ;
348351 const localDefs : ComponentDef [ ] = await this . sources . getMany ( ids ) ;
349- const versionDeps = await this . multipleCompsDefsToVersionDeps ( localDefs ) ;
352+ const versionDeps = await this . multipleCompsDefsToVersionDeps ( localDefs , undefined , onlyIfBuild ) ;
350353 logger . debug ( 'fetchWithDeps, releasing the lock' ) ;
351354 return versionDeps ;
352355 } ) ;
@@ -453,7 +456,8 @@ export default class ScopeComponentsImporter {
453456
454457 private async multipleCompsDefsToVersionDeps (
455458 compsDefs : ComponentDef [ ] ,
456- lanes : Lane [ ] = [ ]
459+ lanes : Lane [ ] = [ ] ,
460+ onlyIfBuilt = false
457461 ) : Promise < VersionDependencies [ ] > {
458462 const concurrency = concurrentComponentsLimit ( ) ;
459463 const componentsWithVersionsWithNulls = await pMap (
@@ -474,6 +478,14 @@ export default class ScopeComponentsImporter {
474478 if ( ! version ) {
475479 throw new Error ( `ScopeComponentImporter, expect ${ id . toString ( ) } to have a Version object` ) ;
476480 }
481+ if ( onlyIfBuilt && version . buildStatus !== BuildStatus . Succeed ) {
482+ logger . debug (
483+ `multipleCompsDefsToVersionDeps, id: ${ id . toString ( ) } is skipped because its build-status is ${
484+ version . buildStatus
485+ } `
486+ ) ;
487+ return null ;
488+ }
477489
478490 return { componentVersion : versionComp , versionObj : version } ;
479491 } ,
@@ -508,21 +520,29 @@ export default class ScopeComponentsImporter {
508520 lanes : Lane [ ] = [ ]
509521 ) : Promise < VersionDependencies [ ] > {
510522 if ( ! ids . length ) return [ ] ;
511- logger . debugAndAddBreadCrumb ( 'ScopeComponentsImporter.getExternalMany' , `fetching from remote scope. Ids: {ids}` , {
512- ids : ids . join ( ', ' ) ,
513- } ) ;
523+ logger . debugAndAddBreadCrumb (
524+ 'ScopeComponentsImporter.getExternalMany' ,
525+ `fetching from remote scope. Ids: {ids}, Lanes: {lanes}` ,
526+ {
527+ ids : ids . join ( ', ' ) ,
528+ lanes : lanes . map ( ( lane ) => lane . id ( ) ) . join ( ', ' ) ,
529+ }
530+ ) ;
514531 const context = { } ;
515532 ids . forEach ( ( id ) => {
516533 if ( id . isLocal ( this . scope . name ) )
517534 throw new Error ( `getExternalMany expects to get external ids only, got ${ id . toString ( ) } ` ) ;
518535 } ) ;
519536 enrichContextFromGlobal ( Object . assign ( { } , { requestedBitIds : ids . map ( ( id ) => id . toString ( ) ) } ) ) ;
537+ // avoid re-fetching the components with all deps if they're still un-built
538+ const onlyIfBuilt = ids . every ( ( id ) => this . sources . isUnBuiltInCache ( id ) ) ;
520539 await new ObjectFetcher (
521540 this . repo ,
522541 this . scope ,
523542 remotes ,
524543 {
525544 withoutDependencies : false ,
545+ onlyIfBuilt,
526546 } ,
527547 ids ,
528548 lanes ,
0 commit comments