Skip to content

Commit 10e1278

Browse files
authored
refactor, remove the legacy hooks (#9023)
1 parent 6071623 commit 10e1278

File tree

18 files changed

+16
-455
lines changed

18 files changed

+16
-455
lines changed
Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,26 @@
11
import { ComponentIdList } from '@teambit/component-id';
2-
import { POST_REMOVE_REMOTE, PRE_REMOVE_REMOTE } from '@teambit/legacy/dist/constants';
3-
import HooksManager from '@teambit/legacy/dist/hooks';
42
import { loadScope } from '@teambit/legacy/dist/scope';
53
import RemovedObjects, { RemovedObjectSerialized } from '@teambit/legacy/dist/scope/removed-components';
64

7-
const HooksManagerInstance = HooksManager.getInstance();
8-
9-
export default async function remove(
10-
{ path, ids, force, lanes }: { path: string; ids: string[]; force: boolean; lanes: boolean },
11-
headers?: Record<string, any>
12-
): Promise<RemovedObjectSerialized> {
5+
export default async function remove({
6+
path,
7+
ids,
8+
force,
9+
lanes,
10+
}: {
11+
path: string;
12+
ids: string[];
13+
force: boolean;
14+
lanes: boolean;
15+
}): Promise<RemovedObjectSerialized> {
1316
const scope = await loadScope(path);
1417
if (lanes) {
1518
const removedLanes = await scope.lanes.removeLanes(scope, ids, force);
1619
const removedObjects = new RemovedObjects({ removedLanes });
1720
return removedObjects.serialize();
1821
}
1922
const bitIds = ComponentIdList.fromStringArray(ids);
20-
const args = { path, bitIds, force };
2123
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
22-
HooksManagerInstance?.triggerHook(PRE_REMOVE_REMOTE, args, headers);
2324
const res = await scope.removeMany(bitIds, force);
24-
const hookArgs = {
25-
removedComponentsIds: res.removedComponentIds.toStringArray(),
26-
missingComponentsIds: res.missingComponents.toStringArray(),
27-
dependentBitsIds: res.dependentBits,
28-
force,
29-
scopePath: path,
30-
componentsIds: bitIds.toStringArray(),
31-
scopeName: scope.scopeJson.name,
32-
};
33-
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
34-
await HooksManagerInstance?.triggerHook(POST_REMOVE_REMOTE, hookArgs, headers);
3525
return res.serialize();
3626
}

components/legacy/scope-api/lib/fetch.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import Queue from 'p-queue';
33
import { ComponentIdList } from '@teambit/component-id';
44
import semver from 'semver';
55
import { LaneId } from '@teambit/lane-id';
6-
import { LATEST_BIT_VERSION, POST_SEND_OBJECTS, PRE_SEND_OBJECTS } from '@teambit/legacy/dist/constants';
7-
import HooksManager from '@teambit/legacy/dist/hooks';
6+
import { LATEST_BIT_VERSION } from '@teambit/legacy/dist/constants';
87
import logger from '@teambit/legacy/dist/logger/logger';
98
import { loadScope, Scope } from '@teambit/legacy/dist/scope';
109
import { Ref } from '@teambit/legacy/dist/scope/objects';
11-
import { ObjectList } from '@teambit/legacy/dist/scope/objects/object-list';
1210
import {
1311
ComponentWithCollectOptions,
1412
ObjectsReadableGenerator,
@@ -77,8 +75,6 @@ export type FETCH_OPTIONS = {
7775

7876
export const CURRENT_FETCH_SCHEMA = '0.0.3';
7977

80-
const HooksManagerInstance = HooksManager.getInstance();
81-
8278
const openConnections: number[] = [];
8379
const openConnectionsMetadata: { [connectionId: string]: Record<string, any> } = {};
8480
let fetchCounter = 0;
@@ -141,12 +137,6 @@ fetchOptions`,
141137
if (fetchOptions.returnNothingIfGivenVersionExists) {
142138
fetchOptions.type = 'component-delta';
143139
}
144-
const args = { path, ids, ...fetchOptions };
145-
// This might be undefined in case of fork process like during bit test command
146-
if (HooksManagerInstance) {
147-
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
148-
HooksManagerInstance?.triggerHook(PRE_SEND_OBJECTS, args, headers);
149-
}
150140
const fetchSchema = fetchOptions.fetchSchema || '0.0.1';
151141
const clientSupportsVersionHistory = semver.gte(fetchSchema, '0.0.2');
152142

@@ -156,7 +146,6 @@ fetchOptions`,
156146
// memory consumption it causes as it caches many objects in-memory.
157147
const useCachedScope = true;
158148
const scope: Scope = await loadScope(path, useCachedScope);
159-
const objectList = new ObjectList();
160149
const finishLog = (err?: Error) => {
161150
const duration = new Date().getTime() - startTime;
162151
openConnections.splice(openConnections.indexOf(currentFetch), 1);
@@ -175,20 +164,6 @@ took: ${duration} ms.`);
175164
finishLog(err);
176165
throw err;
177166
}
178-
179-
if (HooksManagerInstance) {
180-
await HooksManagerInstance?.triggerHook(
181-
POST_SEND_OBJECTS,
182-
{
183-
objectList,
184-
scopePath: path,
185-
ids,
186-
scopeName: scope.scopeJson.name,
187-
},
188-
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
189-
headers
190-
);
191-
}
192167
logger.debug('scope.fetch returns readable');
193168
return objectsReadableGenerator.readable;
194169
}
Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import R from 'ramda';
21
import { ComponentIdList } from '@teambit/component-id';
3-
import { POST_RECEIVE_OBJECTS, PRE_RECEIVE_OBJECTS } from '@teambit/legacy/dist/constants';
4-
import HooksManager from '@teambit/legacy/dist/hooks';
52
import { loadScope } from '@teambit/legacy/dist/scope';
63
import { exportManyBareScope } from '@teambit/legacy/dist/scope/component-ops/export-scope-components';
74
import { ObjectList } from '@teambit/legacy/dist/scope/objects/object-list';
85

9-
const HooksManagerInstance = HooksManager.getInstance();
10-
116
export type ComponentObjectsInput = {
127
path: string;
138
objectList: string | ObjectList;
@@ -18,16 +13,10 @@ export type PushOptions = {
1813
persist?: boolean; // persist the objects immediately with no validation. (for legacy and bit-sign).
1914
};
2015

21-
export async function put(
22-
{ path, objectList }: ComponentObjectsInput,
23-
pushOptions: PushOptions,
24-
headers?: Record<string, any>
25-
): Promise<string[]> {
16+
export async function put({ path, objectList }: ComponentObjectsInput, pushOptions: PushOptions): Promise<string[]> {
2617
if (typeof objectList === 'string') {
2718
objectList = ObjectList.fromJsonString(objectList);
2819
}
29-
30-
await HooksManagerInstance?.triggerHook(PRE_RECEIVE_OBJECTS, { path, objectList }, headers);
3120
const scope = await loadScope(path);
3221
if (pushOptions && pushOptions.clientId) {
3322
// harmony
@@ -37,20 +26,6 @@ export async function put(
3726
// legacy client (non-harmony) or bit-sign.
3827
const componentsBitIds: ComponentIdList = await exportManyBareScope(scope, objectList);
3928
const componentsIds: string[] = componentsBitIds.map((id) => id.toString());
40-
let uniqComponentsIds = componentsIds;
41-
if (componentsIds && componentsIds.length) {
42-
uniqComponentsIds = R.uniq(componentsIds);
43-
}
44-
await HooksManagerInstance?.triggerHook(
45-
POST_RECEIVE_OBJECTS,
46-
{
47-
objectList,
48-
componentsIds: uniqComponentsIds,
49-
scopePath: path,
50-
scopeName: scope.scopeJson.name,
51-
},
52-
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
53-
headers
54-
);
29+
5530
return componentsIds;
5631
}

scopes/component/remove/remove-components.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { ComponentIdList } from '@teambit/component-id';
66
import { compact, isEmpty } from 'lodash';
77
import { CENTRAL_BIT_HUB_NAME, CENTRAL_BIT_HUB_URL, LATEST_BIT_VERSION } from '@teambit/legacy/dist/constants';
88
import { BitError } from '@teambit/bit-error';
9-
import enrichContextFromGlobal from '@teambit/legacy/dist/hooks/utils/enrich-context-from-global';
109
import logger from '@teambit/legacy/dist/logger/logger';
1110
import { Http } from '@teambit/legacy/dist/scope/network/http';
1211
import { Remotes } from '@teambit/legacy/dist/remotes';
@@ -90,7 +89,6 @@ async function removeRemote(
9089
);
9190
}
9291
const context = {};
93-
enrichContextFromGlobal(context);
9492
const removeP = Object.keys(groupedBitsByScope).map(async (key) => {
9593
const resolvedRemote = await remotes.resolve(key, workspace?.scope.legacyScope);
9694
const idsStr = groupedBitsByScope[key].map((id) => id.toStringWithoutVersion());

scopes/component/snapping/snapping.main.runtime.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import { WorkspaceAspect, OutsideWorkspaceError, Workspace } from '@teambit/work
66
import semver, { ReleaseType } from 'semver';
77
import { compact, difference, uniq } from 'lodash';
88
import { ComponentID, ComponentIdList } from '@teambit/component-id';
9-
import { POST_TAG_ALL_HOOK, POST_TAG_HOOK, Extensions, LATEST, BuildStatus } from '@teambit/legacy/dist/constants';
9+
import { Extensions, LATEST, BuildStatus } from '@teambit/legacy/dist/constants';
1010
import { Consumer } from '@teambit/legacy/dist/consumer';
1111
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
12-
import HooksManager from '@teambit/legacy/dist/hooks';
1312
import pMapSeries from 'p-map-series';
1413
import loader from '@teambit/legacy/dist/cli/loader';
1514
import ComponentsPendingImport from '@teambit/legacy/dist/consumer/exceptions/components-pending-import';
@@ -62,8 +61,6 @@ import {
6261
removeLocalVersionsForMultipleComponents,
6362
} from './reset-component';
6463

65-
const HooksManagerInstance = HooksManager.getInstance();
66-
6764
export type TagDataPerComp = {
6865
componentId: ComponentID;
6966
dependencies: ComponentID[];
@@ -183,8 +180,6 @@ export class SnappingMain {
183180

184181
const exactVersion = version;
185182
if (!this.workspace) throw new OutsideWorkspaceError();
186-
const idsHasPattern = this.workspace.hasPattern(ids);
187-
const isAll = Boolean(!ids.length || idsHasPattern);
188183
const validExactVersion = validateVersion(exactVersion);
189184
const consumer = this.workspace.consumer;
190185
const componentsList = new ComponentsList(consumer);
@@ -246,8 +241,6 @@ export class SnappingMain {
246241
removedComponents,
247242
};
248243

249-
const postHook = isAll ? POST_TAG_ALL_HOOK : POST_TAG_HOOK;
250-
HooksManagerInstance?.triggerHook(postHook, tagResults);
251244
await consumer.onDestroy(`tag (message: ${message || 'N/A'})`);
252245
await stagedConfig?.write();
253246
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!

scopes/harmony/bit/bootstrap.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { getBitVersionGracefully } from '@teambit/bit.get-bit-version';
66
import { Analytics } from '@teambit/legacy.analytics';
77
import { handleUnhandledRejection } from '@teambit/cli';
88
import { BIT_VERSION, GLOBAL_CONFIG, GLOBAL_LOGS } from '@teambit/legacy/dist/constants';
9-
import HooksManager from '@teambit/legacy/dist/hooks';
109
import { printWarning, shouldDisableConsole, shouldDisableLoader } from '@teambit/legacy/dist/logger/logger';
1110
import loader from '@teambit/legacy/dist/cli/loader';
1211

@@ -37,7 +36,6 @@ export async function bootstrap() {
3736
verifyNodeVersionCompatibility();
3837
await ensureDirectories();
3938
await Analytics.promptAnalyticsIfNeeded();
40-
HooksManager.init();
4139
}
4240

4341
async function ensureDirectories() {

scopes/lanes/lanes/remove-lanes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import groupArray from 'group-array';
22
import { LaneId } from '@teambit/lane-id';
33
import { Consumer } from '@teambit/legacy/dist/consumer';
4-
import enrichContextFromGlobal from '@teambit/legacy/dist/hooks/utils/enrich-context-from-global';
54
import { Remotes } from '@teambit/legacy/dist/remotes';
65
import { getScopeRemotes } from '@teambit/legacy/dist/scope/scope-remotes';
76
import { Http } from '@teambit/legacy/dist/scope/network/http';
@@ -31,7 +30,6 @@ async function removeRemoteLanes(consumer: Consumer | undefined, lanes: LaneId[]
3130
);
3231
}
3332
const context = {};
34-
enrichContextFromGlobal(context);
3533
const groupedLanesByScope = groupArray(lanes, 'scope');
3634
const removeP = Object.keys(groupedLanesByScope).map(async (key) => {
3735
const resolvedRemote = await remotes.resolve(key, consumer?.scope);

scopes/scope/export/export.main.runtime.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,10 @@ import {
1010
BEFORE_EXPORTS,
1111
BEFORE_LOADING_COMPONENTS,
1212
} from '@teambit/legacy/dist/cli/loader/loader-messages';
13-
import {
14-
CENTRAL_BIT_HUB_NAME,
15-
CENTRAL_BIT_HUB_URL,
16-
POST_EXPORT_HOOK,
17-
PRE_EXPORT_HOOK,
18-
} from '@teambit/legacy/dist/constants';
13+
import { CENTRAL_BIT_HUB_NAME, CENTRAL_BIT_HUB_URL } from '@teambit/legacy/dist/constants';
1914
import { Consumer } from '@teambit/legacy/dist/consumer';
2015
import { BitMap } from '@teambit/legacy.bit-map';
2116
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
22-
import HooksManager from '@teambit/legacy/dist/hooks';
2317
import { RemoveAspect, RemoveMain } from '@teambit/remove';
2418
import { Lane, ModelComponent, Symlink, Version } from '@teambit/legacy/dist/scope/models';
2519
import { hasWildcard } from '@teambit/legacy.utils';
@@ -51,8 +45,6 @@ import { ExportAspect } from './export.aspect';
5145
import { ExportCmd } from './export-cmd';
5246
import { ResumeExportCmd } from './resume-export-cmd';
5347

54-
const HooksManagerInstance = HooksManager.getInstance();
55-
5648
export type OnExportIdTransformer = (id: ComponentID) => ComponentID;
5749

5850
type ModelComponentAndObjects = { component: ModelComponent; objects: BitObject[] };
@@ -100,7 +92,6 @@ export class ExportMain {
10092
) {}
10193

10294
async export(params: ExportParams = {}): Promise<ExportResult> {
103-
HooksManagerInstance?.triggerHook(PRE_EXPORT_HOOK, params);
10495
const { nonExistOnBitMap, missingScope, exported, removedIds, exportedLanes, rippleJobs } =
10596
await this.exportComponents(params);
10697
let ejectResults: EjectResults | undefined;
@@ -115,7 +106,6 @@ export class ExportMain {
115106
exportedLanes,
116107
rippleJobs,
117108
};
118-
HooksManagerInstance?.triggerHook(POST_EXPORT_HOOK, exportResults);
119109
if (Scope.onPostExport) {
120110
await Scope.onPostExport(exported, exportedLanes).catch((err) => {
121111
this.logger.error('fatal: onPostExport encountered an error (this error does not stop the process)', err);

src/constants.ts

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -399,69 +399,6 @@ export const POST_MERGE = 'post-merge';
399399

400400
export const GIT_HOOKS_NAMES = [POST_CHECKOUT, POST_MERGE];
401401

402-
/**
403-
* bit hooks
404-
*/
405-
export const PRE_TAG_HOOK = 'pre-tag';
406-
407-
export const POST_TAG_HOOK = 'post-tag';
408-
409-
export const POST_ADD_HOOK = 'post-add';
410-
411-
export const PRE_TAG_ALL_HOOK = 'pre-tag-all';
412-
413-
export const POST_TAG_ALL_HOOK = 'post-tag-all';
414-
415-
export const PRE_IMPORT_HOOK = 'pre-import';
416-
417-
export const POST_IMPORT_HOOK = 'post-import';
418-
419-
export const PRE_EXPORT_HOOK = 'pre-export';
420-
421-
export const POST_EXPORT_HOOK = 'post-export';
422-
423-
export const PRE_SEND_OBJECTS = 'pre-send-objects'; // pre-fetch
424-
425-
export const POST_SEND_OBJECTS = 'post-send-objects'; // post-fetch
426-
427-
export const PRE_RECEIVE_OBJECTS = 'pre-receive-objects'; // pre-put
428-
429-
export const POST_RECEIVE_OBJECTS = 'post-receive-objects'; // post-put
430-
431-
export const PRE_DEPRECATE_REMOTE = 'pre-deprecate-remote';
432-
433-
export const PRE_UNDEPRECATE_REMOTE = 'pre-undeprecate-remote';
434-
435-
export const POST_DEPRECATE_REMOTE = 'post-deprecate-remote';
436-
437-
export const POST_UNDEPRECATE_REMOTE = 'post-undeprecate-remote';
438-
439-
export const PRE_REMOVE_REMOTE = 'pre-remove-remote';
440-
441-
export const POST_REMOVE_REMOTE = 'post-remove-remote';
442-
443-
export const HOOKS_NAMES = [
444-
PRE_TAG_HOOK,
445-
POST_TAG_HOOK,
446-
POST_ADD_HOOK,
447-
PRE_TAG_ALL_HOOK,
448-
POST_TAG_ALL_HOOK,
449-
PRE_IMPORT_HOOK,
450-
POST_IMPORT_HOOK,
451-
PRE_EXPORT_HOOK,
452-
POST_EXPORT_HOOK,
453-
PRE_SEND_OBJECTS,
454-
POST_SEND_OBJECTS,
455-
PRE_RECEIVE_OBJECTS,
456-
POST_RECEIVE_OBJECTS,
457-
PRE_DEPRECATE_REMOTE,
458-
PRE_UNDEPRECATE_REMOTE,
459-
POST_DEPRECATE_REMOTE,
460-
POST_UNDEPRECATE_REMOTE,
461-
PRE_REMOVE_REMOTE,
462-
POST_REMOVE_REMOTE,
463-
];
464-
465402
/**
466403
* bit registry default URL.
467404
*/

src/error/external-error.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/error/general-error.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/hooks/exceptions/hook-already-exists.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)