@teambit/forking 1.0.108 → 1.0.109

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.
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.component/forking-preview"]=t():e["teambit.component/forking-preview"]=t()}(self,(()=>(()=>{"use strict";var e={87675:(e,t,o)=>{var n={id:"teambit.component/forking@1.0.109",homepage:"https://bit.cloud/teambit/component/forking",exported:!0};function r(){const e=i(o(87363));return r=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,r.__bit_component=n,i.__bit_component=n;const p=()=>r().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},r().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/forking.svg"}));p.__bit_component=n,t.Logo=p},87363:e=>{e.exports=React}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{compositions:()=>d,compositions_metadata:()=>l,overview:()=>u});var e={};o.r(e),o.d(e,{default:()=>f});var t=o(87675);o(87363);const r=MdxJsReact,i=TeambitMdxUiMdxScopeContext;var p=["components"];function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},c.apply(this,arguments)}var a={},s="wrapper";function f(e){var t=e.components,o=function(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}(e,p);return(0,r.mdx)(s,c({},a,o,{components:t,mdxType:"MDXLayout"}),(0,r.mdx)(i.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"}))}f.isMDXComponent=!0;const d=[t],u=[e],l={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),n})()));
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_forking@1.0.108/dist/forking.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_forking@1.0.108/dist/forking.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_forking@1.0.109/dist/forking.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_forking@1.0.109/dist/forking.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/forking",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "homepage": "https://bit.cloud/teambit/component/forking",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "forking",
9
- "version": "1.0.108"
9
+ "version": "1.0.109"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -16,24 +16,24 @@
16
16
  "@teambit/harmony": "0.4.6",
17
17
  "@teambit/bit-error": "0.0.404",
18
18
  "@teambit/component-id": "1.2.0",
19
- "@teambit/cli": "0.0.840",
20
- "@teambit/generator": "1.0.109",
21
- "@teambit/component": "1.0.108",
22
- "@teambit/graphql": "1.0.108",
23
- "@teambit/dependency-resolver": "1.0.108",
24
- "@teambit/install": "1.0.108",
25
- "@teambit/new-component-helper": "1.0.108",
26
- "@teambit/pkg": "1.0.108",
27
- "@teambit/refactoring": "1.0.108",
28
- "@teambit/typescript": "1.0.108",
29
- "@teambit/workspace": "1.0.108"
19
+ "@teambit/cli": "0.0.841",
20
+ "@teambit/generator": "1.0.110",
21
+ "@teambit/component": "1.0.109",
22
+ "@teambit/graphql": "1.0.109",
23
+ "@teambit/dependency-resolver": "1.0.109",
24
+ "@teambit/install": "1.0.109",
25
+ "@teambit/new-component-helper": "1.0.109",
26
+ "@teambit/pkg": "1.0.109",
27
+ "@teambit/refactoring": "1.0.109",
28
+ "@teambit/typescript": "1.0.109",
29
+ "@teambit/workspace": "1.0.109"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/lodash": "4.14.165",
33
33
  "@types/mocha": "9.1.0",
34
34
  "@types/jest": "^29.2.2",
35
35
  "@types/testing-library__jest-dom": "^5.9.5",
36
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
36
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "react": "^17.0.0 || ^18.0.0",
package/fork.cmd.ts DELETED
@@ -1,72 +0,0 @@
1
- import { Command, CommandOptions } from '@teambit/cli';
2
- import { ComponentConfig } from '@teambit/generator';
3
- import chalk from 'chalk';
4
- import { ForkingMain } from '.';
5
-
6
- export type ForkOptions = {
7
- scope?: string;
8
- path?: string;
9
- refactor?: boolean;
10
- skipDependencyInstallation?: boolean;
11
- skipConfig?: boolean;
12
- preserve?: boolean;
13
- noLink?: boolean;
14
- env?: string;
15
- config?: ComponentConfig;
16
- ast?: boolean;
17
- };
18
-
19
- export class ForkCmd implements Command {
20
- name = 'fork <source-component-id> [target-component-name]';
21
- description = 'create a new component forked from an existing one (copies source files and configs)';
22
- helpUrl = 'docs/getting-started/collaborate/importing-components#fork-a-component';
23
- arguments = [
24
- { name: 'source-component-id', description: 'the component id of the source component' },
25
- {
26
- name: 'target-component-name',
27
- description:
28
- "the name for the new component (component name without scope, e.g. name/spaces/my-button). to set a different scope, use the '--scope' flag",
29
- },
30
- ];
31
- group = 'collaborate';
32
- skipWorkspace = true;
33
- alias = '';
34
-
35
- options = [
36
- ['s', 'scope <string>', 'default scope for the new component'],
37
- [
38
- 'p',
39
- 'path <string>',
40
- 'relative path in the workspace for the new component. by default the path is `<scope>/<namespace>/<name>`',
41
- ],
42
- ['r', 'refactor', 'update the import/require statements in all dependent components (in the same workspace)'],
43
- ['x', 'skip-dependency-installation', 'do not install packages of the imported components'],
44
- ['e', 'env <string>', 'set the environment for the new component'],
45
- [
46
- '',
47
- 'skip-config',
48
- 'do not copy the config (aspects-config, env, etc) to the new component. helpful when it fails during aspect loading',
49
- ],
50
- ['', 'preserve', 'avoid refactoring file and variable/class names according to the new component name'],
51
- ['', 'no-link', 'avoid saving a reference to the original component'],
52
- ['', 'ast', 'EXPERIMENTAL. use ast to transform files instead of regex'],
53
- ] as CommandOptions;
54
-
55
- example: [
56
- {
57
- cmd: 'fork teambit.base-ui/input/button ui/button';
58
- description: "create a component named 'ui/button', forked from the remote 'input/button' component";
59
- }
60
- ];
61
- loader = true;
62
- migration = true;
63
- remoteOp = true;
64
-
65
- constructor(private forking: ForkingMain) {}
66
-
67
- async report([sourceId, targetId]: [string, string], options: ForkOptions): Promise<string> {
68
- const results = await this.forking.fork(sourceId, targetId, options);
69
- const targetIdStr = results.toString();
70
- return chalk.green(`successfully forked ${chalk.bold(targetIdStr)} from ${chalk.bold(sourceId)}`);
71
- }
72
- }
package/forking.aspect.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const ForkingAspect = Aspect.create({
4
- id: 'teambit.component/forking',
5
- });
@@ -1,26 +0,0 @@
1
- import { Component, ShowFragment } from '@teambit/component';
2
- import { ForkingMain } from './forking.main.runtime';
3
-
4
- export class ForkingFragment implements ShowFragment {
5
- constructor(private forking: ForkingMain) {}
6
-
7
- title = 'forking';
8
-
9
- async renderRow(component: Component) {
10
- const forkingInfo = this.forking.getForkInfo(component);
11
- const content = forkingInfo ? `origin: ${forkingInfo.forkedFrom.toString()}` : '';
12
- return {
13
- title: this.title,
14
- content,
15
- };
16
- }
17
-
18
- async json(component: Component) {
19
- return {
20
- title: this.title,
21
- json: this.forking.getForkInfo(component),
22
- };
23
- }
24
-
25
- weight = 3;
26
- }
@@ -1,28 +0,0 @@
1
- import { Component } from '@teambit/component';
2
- import { Schema } from '@teambit/graphql';
3
- import gql from 'graphql-tag';
4
- import { ForkingMain } from './forking.main.runtime';
5
-
6
- export function forkingSchema(forking: ForkingMain): Schema {
7
- return {
8
- typeDefs: gql`
9
- extend type Component {
10
- forking: ForkingInfo
11
- }
12
-
13
- type ForkingInfo {
14
- forkedFrom: String
15
- }
16
- `,
17
- resolvers: {
18
- Component: {
19
- forking: (component: Component) => {
20
- const forkInfo = forking.getForkInfo(component);
21
- return {
22
- forkedFrom: forkInfo?.forkedFrom.toString(),
23
- };
24
- },
25
- },
26
- },
27
- };
28
- }
@@ -1,356 +0,0 @@
1
- import { BitError } from '@teambit/bit-error';
2
- import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
3
- import { importTransformer, exportTransformer } from '@teambit/typescript';
4
- import ComponentAspect, { Component, ComponentMain } from '@teambit/component';
5
- import { ComponentDependency, DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';
6
- import { ComponentConfig } from '@teambit/generator';
7
- import GraphqlAspect, { GraphqlMain } from '@teambit/graphql';
8
- import { InstallAspect, InstallMain } from '@teambit/install';
9
- import { ComponentID, ComponentIdObj, ComponentIdList } from '@teambit/component-id';
10
- import NewComponentHelperAspect, { NewComponentHelperMain } from '@teambit/new-component-helper';
11
- import PkgAspect, { PkgMain } from '@teambit/pkg';
12
- import RefactoringAspect, { MultipleStringsReplacement, RefactoringMain } from '@teambit/refactoring';
13
- import WorkspaceAspect, { OutsideWorkspaceError, Workspace } from '@teambit/workspace';
14
- import { uniqBy } from 'lodash';
15
- import pMapSeries from 'p-map-series';
16
- import { ForkCmd, ForkOptions } from './fork.cmd';
17
- import { ForkingAspect } from './forking.aspect';
18
- import { ForkingFragment } from './forking.fragment';
19
- import { forkingSchema } from './forking.graphql';
20
- import { ScopeForkCmd, ScopeForkOptions } from './scope-fork.cmd';
21
-
22
- export type ForkInfo = {
23
- forkedFrom: ComponentID;
24
- };
25
-
26
- type MultipleForkInfo = {
27
- targetCompId: ComponentID;
28
- sourceId: string;
29
- component: Component;
30
- };
31
-
32
- type MultipleComponentsToFork = Array<{
33
- sourceId: string;
34
- targetId?: string; // if not specified, it'll be the same as the source
35
- targetScope?: string; // if not specified, it'll be taken from the options or from the default scope
36
- path?: string; // if not specified, use the default component path
37
- env?: string; // if not specified, use the default env
38
- config?: ComponentConfig; // if specified, adds to/overrides the existing config
39
- }>;
40
-
41
- type MultipleForkOptions = {
42
- refactor?: boolean;
43
- scope?: string; // different scope-name than the original components
44
- install?: boolean; // whether to run "bit install" once done.
45
- ast?: boolean; // whether to use AST to transform files instead of regex
46
- };
47
-
48
- export class ForkingMain {
49
- constructor(
50
- private workspace: Workspace,
51
- private install: InstallMain,
52
- private dependencyResolver: DependencyResolverMain,
53
- private newComponentHelper: NewComponentHelperMain,
54
- private refactoring: RefactoringMain,
55
- private pkg: PkgMain
56
- ) {}
57
-
58
- /**
59
- * create a new copy of existing/remote component.
60
- * the new component holds a reference to the old one for future reference.
61
- * if refactor option is enable, change the source-code to update all dependencies with the new name.
62
- */
63
- async fork(sourceId: string, targetId?: string, options?: ForkOptions): Promise<ComponentID> {
64
- if (!this.workspace) throw new OutsideWorkspaceError();
65
- const sourceCompId = await this.workspace.resolveComponentId(sourceId);
66
- const exists = this.workspace.exists(sourceCompId);
67
- if (exists) {
68
- const existingInWorkspace = await this.workspace.get(sourceCompId);
69
- return this.forkExistingInWorkspace(existingInWorkspace, targetId, options);
70
- }
71
- const sourceIdWithScope = sourceCompId._legacy.scope ? sourceCompId : ComponentID.fromString(sourceId);
72
- const { targetCompId, component } = await this.forkRemoteComponent(sourceIdWithScope, targetId, options);
73
- await this.saveDeps(component);
74
- if (!options?.skipDependencyInstallation) await this.installDeps();
75
- return targetCompId;
76
- }
77
-
78
- /**
79
- * get the forking data, such as the source where a component was forked from
80
- */
81
- getForkInfo(component: Component): ForkInfo | null {
82
- const forkConfig = component.state.aspects.get(ForkingAspect.id)?.config as ForkConfig | undefined;
83
- if (!forkConfig) return null;
84
- return {
85
- forkedFrom: ComponentID.fromObject(forkConfig.forkedFrom),
86
- };
87
- }
88
-
89
- async forkMultipleFromRemote(componentsToFork: MultipleComponentsToFork, options: MultipleForkOptions = {}) {
90
- const componentsToForkSorted = this.sortComponentsToFork(componentsToFork);
91
- const { scope } = options;
92
- const results = await pMapSeries(
93
- componentsToForkSorted,
94
- async ({ sourceId, targetId, path, env, config, targetScope }) => {
95
- const sourceCompId = await this.workspace.resolveComponentId(sourceId);
96
- const sourceIdWithScope = sourceCompId._legacy.scope ? sourceCompId : ComponentID.fromString(sourceId);
97
- const { targetCompId, component } = await this.forkRemoteComponent(sourceIdWithScope, targetId, {
98
- scope: targetScope || scope,
99
- path,
100
- env,
101
- config,
102
- });
103
- return { targetCompId, sourceId, component };
104
- }
105
- );
106
- await this.refactorMultipleAndInstall(results, options);
107
- }
108
-
109
- /**
110
- * sort the components to fork so that components without "env" prop will be forked first.
111
- * this way, if some components are envs, their "env" prop is empty and will be forked first, then components that
112
- * depends on them.
113
- * otherwise, forking the components first result in errors when loading them as their envs are missing at that point
114
- */
115
- private sortComponentsToFork(componentsToFork: MultipleComponentsToFork) {
116
- return componentsToFork.sort((a, b) => {
117
- if (a.env && b.env) return 0;
118
- if (a.env) return 1;
119
- return -1;
120
- });
121
- }
122
-
123
- private async refactorMultipleAndInstall(results: MultipleForkInfo[], options: MultipleForkOptions = {}) {
124
- const oldPackages: string[] = [];
125
- const stringsToReplace: MultipleStringsReplacement = results
126
- .map(({ targetCompId, sourceId, component }) => {
127
- const oldPackageName = this.pkg.getPackageName(component);
128
- oldPackages.push(oldPackageName);
129
- const newName = targetCompId.fullName.replace(/\//g, '.');
130
- const scopeToReplace = targetCompId.scope.replace('.', '/');
131
- const newPackageName = `@${scopeToReplace}.${newName}`;
132
- return [
133
- { oldStr: oldPackageName, newStr: newPackageName },
134
- { oldStr: sourceId, newStr: targetCompId.toStringWithoutVersion() },
135
- ];
136
- })
137
- .flat();
138
- const allComponents = await this.workspace.list();
139
- if (options.refactor) {
140
- const { changedComponents } = await this.refactoring.replaceMultipleStrings(
141
- allComponents,
142
- stringsToReplace,
143
- options.ast ? [importTransformer, exportTransformer] : undefined
144
- );
145
- await Promise.all(changedComponents.map((comp) => this.workspace.write(comp)));
146
- }
147
- const forkedComponents = results.map((result) => result.component);
148
- const policy = await Promise.all(forkedComponents.map((comp) => this.extractDeps(comp)));
149
- const policyFlatAndUnique = uniqBy(policy.flat(), 'dependencyId');
150
- const policyWithoutWorkspaceComps = policyFlatAndUnique.filter((dep) => !oldPackages.includes(dep.dependencyId));
151
- this.dependencyResolver.addToRootPolicy(policyWithoutWorkspaceComps, { updateExisting: true });
152
- await this.dependencyResolver.persistConfig(this.workspace.path);
153
- if (options.install) {
154
- await this.installDeps();
155
- }
156
- }
157
-
158
- /**
159
- * fork all components of the given scope
160
- */
161
- async forkScope(
162
- originalScope: string,
163
- newScope: string,
164
- pattern?: string,
165
- options?: ScopeForkOptions
166
- ): Promise<ComponentID[]> {
167
- const allIdsFromOriginalScope = await this.workspace.scope.listRemoteScope(originalScope);
168
- if (!allIdsFromOriginalScope.length) {
169
- throw new Error(`unable to find components to fork from ${originalScope}`);
170
- }
171
- const getPatternWithScopeName = () => {
172
- if (!pattern) return undefined;
173
- if (pattern.startsWith(`${originalScope}/`)) return pattern;
174
- return `${originalScope}/${pattern}`;
175
- };
176
- const patternWithScopeName = getPatternWithScopeName();
177
- const idsFromOriginalScope = patternWithScopeName
178
- ? await this.workspace.scope.filterIdsFromPoolIdsByPattern(patternWithScopeName, allIdsFromOriginalScope)
179
- : allIdsFromOriginalScope;
180
- const workspaceIds = await this.workspace.listIds();
181
- const workspaceBitIds = ComponentIdList.fromArray(workspaceIds.map((id) => id));
182
- idsFromOriginalScope.forEach((id) => {
183
- const existInWorkspace = workspaceBitIds.searchWithoutVersion(id);
184
- if (existInWorkspace) {
185
- throw new Error(
186
- `unable to fork "${id.toString()}". the workspace has a component "${existInWorkspace.toString()}" with the same name and same scope`
187
- );
188
- }
189
- });
190
- const multipleForkInfo: MultipleForkInfo[] = [];
191
- const components = await this.workspace.scope.getManyRemoteComponents(idsFromOriginalScope);
192
- await pMapSeries(components, async (component) => {
193
- const config = await this.getConfig(component);
194
- const targetCompId = ComponentID.fromObject({ name: component.id.fullName }, newScope);
195
- await this.newComponentHelper.writeAndAddNewComp(component, targetCompId, { scope: newScope }, config);
196
- multipleForkInfo.push({ targetCompId, sourceId: component.id.toStringWithoutVersion(), component });
197
- });
198
- await this.refactorMultipleAndInstall(multipleForkInfo, {
199
- refactor: true,
200
- install: !options?.skipDependencyInstallation,
201
- ast: options?.ast,
202
- });
203
- return multipleForkInfo.map((info) => info.targetCompId);
204
- }
205
-
206
- private async forkExistingInWorkspace(existing: Component, targetId?: string, options?: ForkOptions) {
207
- targetId = targetId || existing.id.fullName;
208
- const targetCompId = this.newComponentHelper.getNewComponentId(targetId, undefined, options?.scope);
209
-
210
- const config = await this.getConfig(existing, options);
211
- await this.newComponentHelper.writeAndAddNewComp(existing, targetCompId, options, config);
212
- if (options?.refactor) {
213
- const allComponents = await this.workspace.list();
214
- const { changedComponents } = await this.refactoring.refactorDependencyName(allComponents, existing.id, targetId);
215
- await Promise.all(changedComponents.map((comp) => this.workspace.write(comp)));
216
- }
217
- return targetCompId;
218
- }
219
-
220
- private async forkRemoteComponent(
221
- sourceId: ComponentID,
222
- targetId?: string,
223
- options?: ForkOptions
224
- ): Promise<{
225
- targetCompId: ComponentID;
226
- component: Component;
227
- }> {
228
- if (options?.refactor) {
229
- throw new BitError(`the component ${sourceId.toStringWithoutVersion()} is not in the workspace, you can't use the --refactor flag.
230
- the reason is that the refactor changes the components using ${sourceId.toStringWithoutVersion()}, since it's not in the workspace, no components were using it, so nothing to refactor`);
231
- }
232
- const targetName = targetId || sourceId.fullName;
233
- const targetCompId = this.newComponentHelper.getNewComponentId(targetName, undefined, options?.scope);
234
- const component = await this.workspace.scope.getRemoteComponent(sourceId);
235
- await this.refactoring.replaceMultipleStrings(
236
- [component],
237
- [
238
- {
239
- oldStr: sourceId.toStringWithoutVersion(),
240
- newStr: targetCompId.toStringWithoutVersion(),
241
- },
242
- ],
243
- options?.ast ? [importTransformer, exportTransformer] : undefined
244
- );
245
- if (!options?.preserve) {
246
- await this.refactoring.refactorVariableAndClasses(component, sourceId, targetCompId);
247
- this.refactoring.refactorFilenames(component, sourceId, targetCompId);
248
- }
249
- const config = await this.getConfig(component, options);
250
- await this.newComponentHelper.writeAndAddNewComp(component, targetCompId, options, config);
251
-
252
- return { targetCompId, component };
253
- }
254
-
255
- private async saveDeps(component: Component) {
256
- const workspacePolicyEntries = await this.extractDeps(component);
257
- this.dependencyResolver.addToRootPolicy(workspacePolicyEntries, { updateExisting: true });
258
- await this.dependencyResolver.persistConfig(this.workspace.path);
259
- }
260
-
261
- private async installDeps() {
262
- await this.install.install(undefined, {
263
- dedupe: true,
264
- import: false,
265
- copyPeerToRuntimeOnRoot: true,
266
- copyPeerToRuntimeOnComponents: false,
267
- updateExisting: false,
268
- });
269
- }
270
-
271
- private async extractDeps(component: Component) {
272
- const deps = await this.dependencyResolver.getDependencies(component);
273
- const excludePackages = ['@teambit/legacy'];
274
- const excludeCompIds = this.dependencyResolver.getCompIdsThatShouldNotBeInPolicy();
275
- return deps
276
- .filter((dep) => dep.source === 'auto')
277
- .filter((dep) => {
278
- if (dep instanceof ComponentDependency) {
279
- const compIdStr = dep.componentId.toStringWithoutVersion();
280
- return !excludeCompIds.includes(compIdStr);
281
- }
282
- return !excludePackages.includes(dep.id);
283
- })
284
- .map((dep) => ({
285
- dependencyId: dep.getPackageName?.() || dep.id,
286
- lifecycleType: dep.lifecycle === 'dev' ? 'runtime' : dep.lifecycle,
287
- value: {
288
- version: dep.version,
289
- },
290
- }));
291
- }
292
-
293
- private async getConfig(comp: Component, options?: ForkOptions) {
294
- const config = options?.config || {};
295
- const fromExisting = options?.skipConfig
296
- ? {}
297
- : await this.newComponentHelper.getConfigFromExistingToNewComponent(comp);
298
- const linkToOriginal = options?.noLink ? {} : { [ForkingAspect.id]: { forkedFrom: comp.id.toObject() } };
299
- return {
300
- ...fromExisting,
301
- ...linkToOriginal,
302
- ...config,
303
- };
304
- }
305
-
306
- static slots = [];
307
- static dependencies = [
308
- CLIAspect,
309
- WorkspaceAspect,
310
- DependencyResolverAspect,
311
- ComponentAspect,
312
- NewComponentHelperAspect,
313
- GraphqlAspect,
314
- RefactoringAspect,
315
- PkgAspect,
316
- InstallAspect,
317
- ];
318
- static runtime = MainRuntime;
319
- static async provider([
320
- cli,
321
- workspace,
322
- dependencyResolver,
323
- componentMain,
324
- newComponentHelper,
325
- graphql,
326
- refactoring,
327
- pkg,
328
- install,
329
- ]: [
330
- CLIMain,
331
- Workspace,
332
- DependencyResolverMain,
333
- ComponentMain,
334
- NewComponentHelperMain,
335
- GraphqlMain,
336
- RefactoringMain,
337
- PkgMain,
338
- InstallMain
339
- ]) {
340
- const forkingMain = new ForkingMain(workspace, install, dependencyResolver, newComponentHelper, refactoring, pkg);
341
- cli.register(new ForkCmd(forkingMain));
342
- graphql.register(forkingSchema(forkingMain));
343
- componentMain.registerShowFragments([new ForkingFragment(forkingMain)]);
344
-
345
- const scopeCommand = cli.getCommand('scope');
346
- scopeCommand?.commands?.push(new ScopeForkCmd(forkingMain));
347
-
348
- return forkingMain;
349
- }
350
- }
351
-
352
- ForkingAspect.addRuntime(ForkingMain);
353
-
354
- export type ForkConfig = {
355
- forkedFrom: ComponentIdObj;
356
- };
package/index.ts DELETED
@@ -1,5 +0,0 @@
1
- import { ForkingAspect } from './forking.aspect';
2
-
3
- export type { ForkingMain } from './forking.main.runtime';
4
- export default ForkingAspect;
5
- export { ForkingAspect };
package/scope-fork.cmd.ts DELETED
@@ -1,45 +0,0 @@
1
- import { Command, CommandOptions } from '@teambit/cli';
2
- import { COMPONENT_PATTERN_HELP } from '@teambit/legacy/dist/constants';
3
- import chalk from 'chalk';
4
- import { ForkingMain } from './forking.main.runtime';
5
-
6
- export type ScopeForkOptions = {
7
- ast?: boolean;
8
- skipDependencyInstallation?: boolean;
9
- };
10
- export class ScopeForkCmd implements Command {
11
- name = 'fork <original-scope> <new-scope> [pattern]';
12
- arguments = [
13
- {
14
- name: 'original-scope',
15
- description: 'the original scope to fork',
16
- },
17
- {
18
- name: 'new-scope',
19
- description: 'the new scope to fork to',
20
- },
21
- {
22
- name: 'pattern',
23
- description: COMPONENT_PATTERN_HELP,
24
- },
25
- ];
26
- description = 'fork all components of the original-scope and refactor the source-code to use the new scope name';
27
- extendedDescription = 'optionally, provide [pattern] to limit the fork to specific components';
28
- options = [
29
- ['', 'ast', 'EXPERIMENTAL. use ast to transform files instead of regex'],
30
- ['x', 'skip-dependency-installation', 'do not install packages of the imported components'],
31
- ] as CommandOptions;
32
- group = 'development';
33
-
34
- constructor(private forking: ForkingMain) {}
35
-
36
- async report([originalScope, newScope, pattern]: [string, string, string], options: ScopeForkOptions) {
37
- const forkedIds = await this.forking.forkScope(originalScope, newScope, pattern, options);
38
- const title = chalk.green(
39
- `successfully forked ${chalk.bold(originalScope)} into ${chalk.bold(
40
- newScope
41
- )}. the following components were created`
42
- );
43
- return `${title}\n${forkedIds.map((id) => id.toString()).join('\n')}`;
44
- }
45
- }