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

refactor, extract legacy component-list into a new component "teambit.legacy/component-list" #9024

Merged
merged 3 commits into from
Jul 11, 2024
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
7 changes: 7 additions & 0 deletions .bitmap
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@
"mainFile": "index.ts",
"rootDir": "components/component-issues"
},
"component-list": {
"name": "component-list",
"scope": "teambit.legacy",
"version": "0.0.2",
"mainFile": "index.ts",
"rootDir": "components/legacy/component-list"
},
"component-log": {
"name": "component-log",
"scope": "teambit.component",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { ComponentID, ComponentIdList } from '@teambit/component-id';
import { ModelComponent } from '../../scope/models';
import ComponentsList from './components-list';
import { ModelComponent } from '@teambit/legacy/dist/scope/models';
import { ComponentsList } from './components-list';

describe('ComponentList', function () {
// @ts-ignore
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('ComponentList', function () {
const results = await componentList.listAll(false, true);
const result = results[0];
expect(result).to.have.property('id');
expect(result.id).to.be.an.instanceOf(ComponentID);
expect(result.id.constructor.name).to.equal(ComponentID.name);
});
});
describe('filterComponentsByWildcard', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { compact } from 'lodash';
import pFilter from 'p-filter';
import { ComponentID, ComponentIdList } from '@teambit/component-id';
import R from 'ramda';
import { LATEST } from '../../constants';
import { SnapsDistance } from '../../scope/component-ops/snaps-distance';
import { getDivergeData } from '../../scope/component-ops/get-diverge-data';
import { Lane } from '../../scope/models';
import ModelComponent from '../../scope/models/model-component';
import Scope from '../../scope/scope';
import { fetchRemoteVersions } from '../../scope/scope-remotes';
import { LATEST } from '@teambit/legacy/dist/constants';
import { SnapsDistance } from '@teambit/legacy/dist/scope/component-ops/snaps-distance';
import { getDivergeData } from '@teambit/legacy/dist/scope/component-ops/get-diverge-data';
import { Lane } from '@teambit/legacy/dist/scope/models';
import ModelComponent from '@teambit/legacy/dist/scope/models/model-component';
import Scope from '@teambit/legacy/dist/scope/scope';
import { fetchRemoteVersions } from '@teambit/legacy/dist/scope/scope-remotes';
import { isBitIdMatchByWildcards } from '@teambit/legacy.utils';
import { BitMap, ComponentMap } from '@teambit/legacy.bit-map';
import Component from '../component';
import { InvalidComponent } from '../component/consumer-component';
import Consumer from '../consumer';
import { ComponentLoadOptions } from './component-loader';
import Component from '@teambit/legacy/dist/consumer/component';
import { InvalidComponent } from '@teambit/legacy/dist/consumer/component/consumer-component';
import Consumer from '@teambit/legacy/dist/consumer/consumer';
import { ComponentLoadOptions } from '@teambit/legacy/dist/consumer/component/component-loader';

export type DivergeDataPerId = { id: ComponentID; divergeData: SnapsDistance };
export type ListScopeResult = {
Expand All @@ -29,7 +29,7 @@ export type ListScopeResult = {
export type DivergedComponent = { id: ComponentID; diverge: SnapsDistance };
export type OutdatedComponent = { id: ComponentID; headVersion: string; latestVersion?: string };

export default class ComponentsList {
export class ComponentsList {
consumer: Consumer;
scope: Scope;
bitMap: BitMap;
Expand All @@ -43,6 +43,7 @@ export default class ComponentsList {
constructor(consumer: Consumer) {
this.consumer = consumer;
this.scope = consumer.scope;
// @ts-ignore todo: remove after deleting teambit.legacy
this.bitMap = consumer.bitMap;
}

Expand Down
1 change: 1 addition & 0 deletions components/legacy/component-list/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ComponentsList, DivergeDataPerId, ListScopeResult } from './components-list';
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@pnpm/node-fetch": "^1.0.0",
"@teambit/defender.fs.global-bit-temp-dir": "0.0.1",
"@teambit/legacy.analytics": "~0.0.1",
"@teambit/legacy.component-list": "~0.0.2",
"@teambit/component.sources": "~0.0.1",
"@teambit/bit.get-bit-version": "~0.0.1",
"@teambit/legacy.utils": "~0.0.2",
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/lister/lister.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ComponentID } from '@teambit/component-id';
import { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';
import { Remote } from '@teambit/legacy/dist/remotes';
import getRemoteByName from '@teambit/legacy/dist/remotes/get-remote-by-name';
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import { BitError } from '@teambit/bit-error';
import { ListCmd } from './list.cmd';
import { ListerAspect } from './lister.aspect';
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/merging/merging.main.runtime.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
import { WorkspaceAspect, OutsideWorkspaceError, Workspace } from '@teambit/workspace';
import { Consumer } from '@teambit/legacy/dist/consumer';
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import { SnappingAspect, SnappingMain, TagResults } from '@teambit/snapping';
import mapSeries from 'p-map-series';
import { ComponentID, ComponentIdList } from '@teambit/component-id';
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/remove/remove-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Http } from '@teambit/legacy/dist/scope/network/http';
import { Remotes } from '@teambit/legacy/dist/remotes';
import { getScopeRemotes } from '@teambit/legacy/dist/scope/scope-remotes';
import { deleteComponentsFiles } from './delete-component-files';
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import Component from '@teambit/legacy/dist/consumer/component/consumer-component';
import RemovedObjects from '@teambit/legacy/dist/scope/removed-components';
import pMapSeries from 'p-map-series';
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/snapping/reset-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BitError } from '@teambit/bit-error';
import { ComponentID } from '@teambit/component-id';
import { Scope } from '@teambit/legacy/dist/scope';
import { Consumer } from '@teambit/legacy/dist/consumer';
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import logger from '@teambit/legacy/dist/logger/logger';
import { Lane, ModelComponent } from '@teambit/legacy/dist/scope/models';

Expand Down
2 changes: 1 addition & 1 deletion scopes/component/snapping/snapping.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { compact, difference, uniq } from 'lodash';
import { ComponentID, ComponentIdList } from '@teambit/component-id';
import { Extensions, LATEST, BuildStatus } from '@teambit/legacy/dist/constants';
import { Consumer } from '@teambit/legacy/dist/consumer';
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import pMapSeries from 'p-map-series';
import loader from '@teambit/legacy/dist/cli/loader';
import ComponentsPendingImport from '@teambit/legacy/dist/consumer/exceptions/components-pending-import';
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/status/status.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { BEFORE_STATUS } from '@teambit/legacy/dist/cli/loader/loader-messages';
import { RemoveAspect, RemoveMain } from '@teambit/remove';
import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
import ComponentsPendingImport from '@teambit/legacy/dist/consumer/exceptions/components-pending-import';
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import { ModelComponent } from '@teambit/legacy/dist/scope/models';
import { InsightsAspect, InsightsMain } from '@teambit/insights';
import { SnapsDistance } from '@teambit/legacy/dist/scope/component-ops/snaps-distance';
Expand Down
2 changes: 1 addition & 1 deletion scopes/lanes/lanes/create-lane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ScopeMain } from '@teambit/scope';
// import { ComponentIdList } from '@teambit/component-id';
import Lane, { LaneComponent } from '@teambit/legacy/dist/scope/models/lane';
import { isSnap } from '@teambit/component-version';
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import { Ref } from '@teambit/legacy/dist/scope/objects';
import { Workspace } from '@teambit/workspace';
import { compact } from 'lodash';
Expand Down
2 changes: 1 addition & 1 deletion scopes/lanes/lanes/lanes.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { SnapsDistance } from '@teambit/legacy/dist/scope/component-ops/snaps-di
import { RemoveAspect, RemoveMain } from '@teambit/remove';
import { CheckoutAspect, CheckoutMain } from '@teambit/checkout';
import { ChangeType } from '@teambit/lanes.entities.lane-diff';
import ComponentsList, { DivergeDataPerId } from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList, DivergeDataPerId } from '@teambit/legacy.component-list';
import { NoCommonSnap } from '@teambit/legacy/dist/scope/exceptions/no-common-snap';
import { concurrentComponentsLimit } from '@teambit/harmony.modules.concurrency';
import { SUPPORT_LANE_HISTORY, isFeatureEnabled } from '@teambit/harmony.modules.feature-toggle';
Expand Down
2 changes: 1 addition & 1 deletion scopes/scope/export/export.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { CENTRAL_BIT_HUB_NAME, CENTRAL_BIT_HUB_URL } from '@teambit/legacy/dist/constants';
import { Consumer } from '@teambit/legacy/dist/consumer';
import { BitMap } from '@teambit/legacy.bit-map';
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import { RemoveAspect, RemoveMain } from '@teambit/remove';
import { Lane, ModelComponent, Symlink, Version } from '@teambit/legacy/dist/scope/models';
import { hasWildcard } from '@teambit/legacy.utils';
Expand Down
2 changes: 1 addition & 1 deletion scopes/workspace/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { LaneId } from '@teambit/lane-id';
import { Consumer, loadConsumer } from '@teambit/legacy/dist/consumer';
import { GetBitMapComponentOptions, MissingBitMapComponent } from '@teambit/legacy.bit-map';
import { getMaxSizeForComponents, InMemoryCache, createInMemoryCache } from '@teambit/harmony.modules.in-memory-cache';
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import { ExtensionDataList, ExtensionDataEntry } from '@teambit/legacy/dist/consumer/config/extension-data';
import {
PathOsBased,
Expand Down
2 changes: 1 addition & 1 deletion src/remotes/remote.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentID } from '@teambit/component-id';
import { PushOptions, CURRENT_FETCH_SCHEMA, FETCH_OPTIONS } from '@teambit/legacy.scope-api';
import { ListScopeResult } from '../consumer/component/components-list';
import { ListScopeResult } from '@teambit/legacy.component-list';
import Component from '../consumer/component/consumer-component';
import logger from '../logger/logger';
import type { Scope } from '../scope';
Expand Down
6 changes: 5 additions & 1 deletion src/scope/graph/scope-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import GraphLib, { Graph } from 'graphlib';
import pMapSeries from 'p-map-series';
import { ComponentID, ComponentIdList } from '@teambit/component-id';
import { VERSION_DELIMITER } from '../../constants';
import ComponentsList from '../../consumer/component/components-list';
import { ComponentsList } from '@teambit/legacy.component-list';
import Component from '../../consumer/component/consumer-component';
import { DEPENDENCIES_TYPES_UI_MAP } from '../../consumer/component/dependencies/dependencies';
import Consumer from '../../consumer/consumer';
Expand Down Expand Up @@ -135,7 +135,9 @@ export default class DependencyGraph {

// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
static async buildGraphFromWorkspace(consumer: Consumer, onlyLatest = false, reverse = false): Promise<Graph> {
// @ts-ignore todo: remove after deleting teambit.legacy
const componentsList = new ComponentsList(consumer);
// @ts-ignore todo: remove after deleting teambit.legacy
const workspaceComponents: Component[] = await componentsList.getFromFileSystem();
const graph = new Graph();
const allModelComponents: ModelComponent[] = await consumer.scope.list();
Expand Down Expand Up @@ -170,7 +172,9 @@ export default class DependencyGraph {
* returns a graph that each node is a ComponentID object.
*/
static async buildGraphFromCurrentlyUsedComponents(consumer: Consumer): Promise<Graph> {
// @ts-ignore todo: remove after deleting teambit.legacy
const componentsList = new ComponentsList(consumer);
// @ts-ignore todo: remove after deleting teambit.legacy
const workspaceComponents: Component[] = await componentsList.getComponentsFromFS();
const graph = new Graph();
workspaceComponents.forEach((component: Component) => {
Expand Down
3 changes: 2 additions & 1 deletion src/scope/network/fs/fs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentID } from '@teambit/component-id';
import { fetch, put, remove, action, FETCH_OPTIONS, PushOptions } from '@teambit/legacy.scope-api';
import ComponentsList, { ListScopeResult } from '../../../consumer/component/components-list';
import { ComponentsList, ListScopeResult } from '@teambit/legacy.component-list';
import Component from '../../../consumer/component/consumer-component';
import DependencyGraph from '../../graph/scope-graph';
import { LaneData } from '../../lanes/lanes';
Expand Down Expand Up @@ -65,6 +65,7 @@ export default class Fs implements Network {
}

list(namespacesUsingWildcards?: string): Promise<ListScopeResult[]> {
// @ts-ignore todo: remove after deleting teambit.legacy
return ComponentsList.listLocalScope(this.getScope(), namespacesUsingWildcards);
}

Expand Down
2 changes: 1 addition & 1 deletion src/scope/network/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { HttpProxyAgent } from 'http-proxy-agent';
import { CLOUD_IMPORTER, CLOUD_IMPORTER_V2, isFeatureEnabled } from '@teambit/harmony.modules.feature-toggle';
import { LaneId } from '@teambit/lane-id';
import { getAgent, AgentOptions } from '@teambit/toolbox.network.agent';
import { ListScopeResult } from '@teambit/legacy.component-list';
import { Network } from '../network';
import Component from '../../../consumer/component';
import { ListScopeResult } from '../../../consumer/component/components-list';
import DependencyGraph from '../../graph/scope-graph';
import { LaneData } from '../../lanes/lanes';
import { ComponentLog } from '../../models/model-component';
Expand Down
2 changes: 1 addition & 1 deletion src/scope/network/network.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentID, ComponentIdList } from '@teambit/component-id';
import { PushOptions, FETCH_OPTIONS } from '@teambit/legacy.scope-api';
import Component from '../../consumer/component';
import { ListScopeResult } from '../../consumer/component/components-list';
import { ListScopeResult } from '@teambit/legacy.component-list';
import DependencyGraph from '../graph/scope-graph';
import { LaneData } from '../lanes/lanes';
import { ComponentLog } from '../models/model-component';
Expand Down