@teambit/builder 0.0.551 → 0.0.556
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.
- package/dist/artifact/artifact-definition.d.ts +35 -0
- package/dist/artifact/artifact-factory.d.ts +3 -0
- package/dist/artifact/artifact-list.d.ts +9 -0
- package/dist/artifact/artifact.d.ts +52 -1
- package/dist/build-pipe.d.ts +33 -1
- package/dist/build-pipeline-order.d.ts +30 -0
- package/dist/build-pipeline-result-list.d.ts +3 -0
- package/dist/build-task.d.ts +57 -0
- package/dist/builder.main.runtime.d.ts +27 -0
- package/dist/builder.service.d.ts +39 -1
- package/dist/storage/storage-resolver.d.ts +6 -0
- package/dist/task-results-list.d.ts +11 -1
- package/dist/tasks-queue.d.ts +3 -0
- package/dist/types.d.ts +18 -0
- package/package.json +23 -17
- package/artifact/artifact-definition.ts +0 -52
- package/artifact/artifact-extractor.ts +0 -116
- package/artifact/artifact-factory.ts +0 -119
- package/artifact/artifact-list.ts +0 -64
- package/artifact/artifact.ts +0 -81
- package/artifact/artifacts.cmd.ts +0 -68
- package/artifact/extension-artifact.ts +0 -12
- package/artifact/index.ts +0 -5
- package/build-pipe.ts +0 -167
- package/build-pipeline-order.ts +0 -197
- package/build-pipeline-result-list.ts +0 -97
- package/build-task.ts +0 -114
- package/build.cmd.ts +0 -91
- package/builder.aspect.ts +0 -5
- package/builder.docs.mdx +0 -8
- package/builder.graphql.ts +0 -38
- package/builder.main.runtime.ts +0 -346
- package/builder.service.tsx +0 -163
- package/exceptions/artifact-storage-error.ts +0 -7
- package/exceptions/capsule-not-found.ts +0 -7
- package/exceptions/index.ts +0 -3
- package/exceptions/invalid-task.ts +0 -7
- package/index.ts +0 -9
- package/package-tar/teambit-builder-0.0.551.tgz +0 -0
- package/pipeline/index.ts +0 -1
- package/pipeline/pipeline-results.ts +0 -1
- package/storage/default-resolver.ts +0 -13
- package/storage/index.ts +0 -2
- package/storage/s3-resolver.ts +0 -40
- package/storage/storage-resolver.ts +0 -18
- package/task-results-list.ts +0 -66
- package/tasks-queue.ts +0 -40
- package/tsconfig.json +0 -35
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/types.ts +0 -39
package/build-pipeline-order.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { Graph } from 'cleargraph';
|
|
2
|
-
import TesterAspect from '@teambit/tester';
|
|
3
|
-
import { EnvDefinition, Environment } from '@teambit/envs';
|
|
4
|
-
import { BuildTask, BuildTaskHelper } from './build-task';
|
|
5
|
-
import type { TaskSlot } from './builder.main.runtime';
|
|
6
|
-
import { TasksQueue } from './tasks-queue';
|
|
7
|
-
|
|
8
|
-
type TaskDependenciesGraph = Graph<string, string>;
|
|
9
|
-
type Location = 'start' | 'middle' | 'end';
|
|
10
|
-
type TasksLocationGraph = { location: Location; graph: TaskDependenciesGraph };
|
|
11
|
-
type PipelineEnv = { env: EnvDefinition; pipeline: BuildTask[] };
|
|
12
|
-
type DataPerLocation = { location: Location; graph: TaskDependenciesGraph; pipelineEnvs: PipelineEnv[] };
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* there are two ways how to add tasks to build pipeline.
|
|
16
|
-
* 1. `getBuildPipe()` method of the env.
|
|
17
|
-
* 2. registering to the `builder.registerBuildTask()`.
|
|
18
|
-
*
|
|
19
|
-
* in the option #1, it's possible to determine the order. e.g. `getBuildPipe() { return [taskA, taskB, taskC]; }`
|
|
20
|
-
* in the option #2, the register happens once the extension is loaded, so there is no way to put
|
|
21
|
-
* one task before/after another task.
|
|
22
|
-
*
|
|
23
|
-
* To be able to determine the order, you can do the following
|
|
24
|
-
* 1. "task.location", it has two options "start" and "end". the rest are "middle".
|
|
25
|
-
* 2. "task.dependencies", the dependencies must be completed for all envs before this task starts.
|
|
26
|
-
* the dependencies are applicable inside a location and not across locations. see getLocation()
|
|
27
|
-
* or/and continue reading for more info about this.
|
|
28
|
-
*
|
|
29
|
-
* to determine the final order of the tasks, the following is done:
|
|
30
|
-
* 1. split all tasks to three groups: start, middle and end.
|
|
31
|
-
* 2. for each group define a dependencies graph for the tasks with "dependencies" prop and the pipeline.
|
|
32
|
-
* 3. start with the first group "start", toposort the dependencies graph and push the found tasks
|
|
33
|
-
* to a queue. once completed, iterate the pipeline and add all tasks to the queue.
|
|
34
|
-
* 4. do the same for the "middle" and "end" groups.
|
|
35
|
-
*
|
|
36
|
-
* the reason for splitting the tasks to the three groups and not using the "dependencies" field
|
|
37
|
-
* alone to determine the order is that the "start" and "end" groups are mostly core and "middle"
|
|
38
|
-
* is mostly the user entering tasks to the pipeline and we as the core don't know about the users
|
|
39
|
-
* tasks. For example, a core task "PublishComponent" must happen after the compiler, however, a
|
|
40
|
-
* user might have an env without a compiler. if we determine the order only by the dependencies
|
|
41
|
-
* field, the "PublishComponent" would have a dependency "compiler" and because in this case there
|
|
42
|
-
* is no compiler task, it would throw an error about missing dependencies.
|
|
43
|
-
*/
|
|
44
|
-
export function calculatePipelineOrder(
|
|
45
|
-
taskSlot: TaskSlot,
|
|
46
|
-
envs: EnvDefinition[],
|
|
47
|
-
pipeNameOnEnv = 'getBuildPipe',
|
|
48
|
-
tasks: string[] = [],
|
|
49
|
-
skipTests = false
|
|
50
|
-
): TasksQueue {
|
|
51
|
-
const graphs: TasksLocationGraph[] = [];
|
|
52
|
-
const locations: Location[] = ['start', 'middle', 'end']; // the order is important here!
|
|
53
|
-
locations.forEach((location) => {
|
|
54
|
-
graphs.push({ location, graph: new Graph<string, string>() });
|
|
55
|
-
});
|
|
56
|
-
const pipelineEnvs: PipelineEnv[] = [];
|
|
57
|
-
envs.forEach((envDefinition) => {
|
|
58
|
-
if (envDefinition.env.getPipe) {
|
|
59
|
-
// @todo: remove once this confusion is over
|
|
60
|
-
throw new Error(
|
|
61
|
-
`Fatal: a breaking API has introduced. Please change "getPipe()" method on "${envDefinition.id}" to "getBuildPipe()"`
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
const pipeline = getPipelineForEnv(taskSlot, envDefinition.env, pipeNameOnEnv);
|
|
65
|
-
pipelineEnvs.push({ env: envDefinition, pipeline });
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const flattenedPipeline: BuildTask[] = pipelineEnvs.map((pipelineEnv) => pipelineEnv.pipeline).flat();
|
|
69
|
-
flattenedPipeline.forEach((task) => addDependenciesToGraph(graphs, flattenedPipeline, task));
|
|
70
|
-
|
|
71
|
-
const dataPerLocation: DataPerLocation[] = graphs.map(({ location, graph }) => {
|
|
72
|
-
const pipelineEnvsPerLocation: PipelineEnv[] = pipelineEnvs.map(({ env, pipeline }) => {
|
|
73
|
-
return { env, pipeline: pipeline.filter((task) => (task.location || 'middle') === location) };
|
|
74
|
-
});
|
|
75
|
-
return { location, graph, pipelineEnvs: pipelineEnvsPerLocation };
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const tasksQueue = new TasksQueue();
|
|
79
|
-
locations.forEach((location) => addTasksToGraph(tasksQueue, dataPerLocation, location));
|
|
80
|
-
if (tasks.length) {
|
|
81
|
-
return new TasksQueue(
|
|
82
|
-
...tasksQueue.filter(({ task }) => tasks.includes(task.name) || tasks.includes(task.aspectId))
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
if (skipTests) {
|
|
86
|
-
return new TasksQueue(...tasksQueue.filter(({ task }) => task.aspectId !== TesterAspect.id));
|
|
87
|
-
}
|
|
88
|
-
return tasksQueue;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function addTasksToGraph(tasksQueue: TasksQueue, dataPerLocation: DataPerLocation[], location: Location) {
|
|
92
|
-
const data = dataPerLocation.find((d) => d.location === location);
|
|
93
|
-
if (!data) return;
|
|
94
|
-
const sorted = data.graph.toposort();
|
|
95
|
-
sorted.forEach((taskNode) => {
|
|
96
|
-
const { aspectId, name } = BuildTaskHelper.deserializeId(taskNode.attr);
|
|
97
|
-
data.pipelineEnvs.forEach(({ env, pipeline }) => {
|
|
98
|
-
const taskIndex = pipeline.findIndex(
|
|
99
|
-
(pipelineTask) => pipelineTask.aspectId === aspectId && pipelineTask.name === name
|
|
100
|
-
);
|
|
101
|
-
if (taskIndex < 0) return;
|
|
102
|
-
const task = pipeline[taskIndex];
|
|
103
|
-
tasksQueue.push({ env, task });
|
|
104
|
-
pipeline.splice(taskIndex, 1); // delete the task from the pipeline
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
data.pipelineEnvs.forEach(({ env, pipeline }) => {
|
|
108
|
-
pipeline.forEach((task) => tasksQueue.push({ env, task }));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function addDependenciesToGraph(graphs: TasksLocationGraph[], pipeline: BuildTask[], task: BuildTask) {
|
|
113
|
-
if (!task.dependencies || !task.dependencies.length) return;
|
|
114
|
-
const taskId = BuildTaskHelper.serializeId(task);
|
|
115
|
-
task.dependencies.forEach((dependency) => {
|
|
116
|
-
const { aspectId, name } = BuildTaskHelper.deserializeId(dependency);
|
|
117
|
-
const dependencyTasks = pipeline.filter((pipelineTask) => {
|
|
118
|
-
if (pipelineTask.aspectId !== aspectId) return false;
|
|
119
|
-
return name ? name === pipelineTask.name : true;
|
|
120
|
-
});
|
|
121
|
-
if (dependencyTasks.length === 0) {
|
|
122
|
-
throw new Error(
|
|
123
|
-
`unable to find dependency "${dependency}" of "${BuildTaskHelper.serializeId(task)}" in the pipeline`
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
dependencyTasks.forEach((dependencyTask) => {
|
|
127
|
-
const location = getLocation(task, dependencyTask);
|
|
128
|
-
if (!location) {
|
|
129
|
-
// the dependency is behind and will be in the correct order regardless the graph.
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const graphLocation = graphs.find((g) => g.location === location);
|
|
133
|
-
if (!graphLocation) throw new Error(`unable to find graph for location ${location}`);
|
|
134
|
-
const dependencyId = BuildTaskHelper.serializeId(dependencyTask);
|
|
135
|
-
const graph = graphLocation.graph;
|
|
136
|
-
graph.setNode(taskId, taskId);
|
|
137
|
-
graph.setNode(dependencyId, dependencyId);
|
|
138
|
-
graph.setEdge(dependencyId, taskId, 'dependency');
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* since the task execution is happening per group: "start", "middle" and "end", the dependencies
|
|
145
|
-
* need to be inside the same group.
|
|
146
|
-
* e.g. if a dependency located at "end" group and the task located at "start", it's impossible to
|
|
147
|
-
* complete the dependency before the task, there it throws an error.
|
|
148
|
-
* it's ok to have the dependency located earlier, e.g. "start" and the task at "end", and in this
|
|
149
|
-
* case, it will not be part of the graph because there is no need to do any special calculation.
|
|
150
|
-
*/
|
|
151
|
-
function getLocation(task: BuildTask, dependencyTask: BuildTask): Location | null {
|
|
152
|
-
const taskLocation = task.location || 'middle';
|
|
153
|
-
const dependencyLocation = dependencyTask.location || 'middle';
|
|
154
|
-
|
|
155
|
-
const isDependencyAhead =
|
|
156
|
-
(taskLocation === 'start' && dependencyLocation !== 'start') ||
|
|
157
|
-
(taskLocation === 'middle' && dependencyLocation === 'end');
|
|
158
|
-
|
|
159
|
-
const isDependencyEqual = taskLocation === dependencyLocation;
|
|
160
|
-
|
|
161
|
-
if (isDependencyAhead) {
|
|
162
|
-
throw new Error(`a task "${BuildTaskHelper.serializeId(task)}" located at ${taskLocation}
|
|
163
|
-
has a dependency "${BuildTaskHelper.serializeId(dependencyTask)} located at ${dependencyLocation},
|
|
164
|
-
which is invalid. the dependency must be located earlier or in the same location as the task"`);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (isDependencyEqual) {
|
|
168
|
-
return taskLocation;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// dependency is behind. e.g. task is "end" and dependency is "start". no need to enter to the
|
|
172
|
-
// graph as it's going to be executed in the right order regardless the graph.
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function getPipelineForEnv(taskSlot: TaskSlot, env: Environment, pipeNameOnEnv: string): BuildTask[] {
|
|
177
|
-
const buildTasks: BuildTask[] = env[pipeNameOnEnv] ? env[pipeNameOnEnv]() : [];
|
|
178
|
-
const slotsTasks = taskSlot.values().flat();
|
|
179
|
-
const tasksAtStart: BuildTask[] = [];
|
|
180
|
-
const tasksAtEnd: BuildTask[] = [];
|
|
181
|
-
slotsTasks.forEach((task) => {
|
|
182
|
-
if (task.location === 'start') {
|
|
183
|
-
tasksAtStart.push(task);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
if (task.location === 'end') {
|
|
187
|
-
tasksAtEnd.push(task);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
tasksAtStart.push(task);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
// merge with extension registered tasks.
|
|
194
|
-
const mergedTasks = [...tasksAtStart, ...buildTasks, ...tasksAtEnd];
|
|
195
|
-
|
|
196
|
-
return mergedTasks;
|
|
197
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { ComponentID, ComponentMap, Component } from '@teambit/component';
|
|
2
|
-
import { isEmpty, compact } from 'lodash';
|
|
3
|
-
import type { ArtifactObject } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';
|
|
4
|
-
import { Artifact, ArtifactList } from './artifact';
|
|
5
|
-
import { TaskResults } from './build-pipe';
|
|
6
|
-
import { Serializable, TaskMetadata } from './types';
|
|
7
|
-
|
|
8
|
-
export type PipelineReport = {
|
|
9
|
-
taskId: string;
|
|
10
|
-
taskName?: string;
|
|
11
|
-
taskDescription?: string;
|
|
12
|
-
startTime?: number;
|
|
13
|
-
endTime?: number;
|
|
14
|
-
errors?: Array<Error | string>;
|
|
15
|
-
warnings?: string[];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type AspectData = {
|
|
19
|
-
aspectId: string;
|
|
20
|
-
data: Serializable;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Helper to get the data and artifacts from the TasksResultsList before saving during the tag
|
|
25
|
-
*/
|
|
26
|
-
export class BuildPipelineResultList {
|
|
27
|
-
private artifactListsMap: ComponentMap<ArtifactList>;
|
|
28
|
-
constructor(private tasksResults: TaskResults[], private components: Component[]) {
|
|
29
|
-
this.artifactListsMap = this.getFlattenedArtifactListsMapFromAllTasks();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private getFlattenedArtifactListsMapFromAllTasks(): ComponentMap<ArtifactList> {
|
|
33
|
-
const artifactListsMaps = this.tasksResults.flatMap((t) => (t.artifacts ? [t.artifacts] : []));
|
|
34
|
-
return ComponentMap.as<ArtifactList>(this.components, (component) => {
|
|
35
|
-
const artifacts: Artifact[] = [];
|
|
36
|
-
artifactListsMaps.forEach((artifactListMap) => {
|
|
37
|
-
const artifactList = artifactListMap.getValueByComponentId(component.id);
|
|
38
|
-
if (artifactList) artifacts.push(...artifactList.toArray());
|
|
39
|
-
});
|
|
40
|
-
return new ArtifactList(artifacts);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public getMetadataFromTaskResults(componentId: ComponentID): { [taskId: string]: TaskMetadata } {
|
|
45
|
-
const compResults = this.tasksResults.reduce((acc, current: TaskResults) => {
|
|
46
|
-
const foundComponent = current.componentsResults.find((c) => c.component.id.isEqual(componentId));
|
|
47
|
-
const taskId = current.task.aspectId;
|
|
48
|
-
if (foundComponent && foundComponent.metadata) {
|
|
49
|
-
acc[taskId] = this.mergeDataIfPossible(foundComponent.metadata, acc[taskId], taskId);
|
|
50
|
-
}
|
|
51
|
-
return acc;
|
|
52
|
-
}, {});
|
|
53
|
-
return compResults;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public getPipelineReportOfComponent(componentId: ComponentID): PipelineReport[] {
|
|
57
|
-
const compResults = this.tasksResults.map((taskResults: TaskResults) => {
|
|
58
|
-
const foundComponent = taskResults.componentsResults.find((c) => c.component.id.isEqual(componentId));
|
|
59
|
-
if (!foundComponent) return null;
|
|
60
|
-
const pipelineReport: PipelineReport = {
|
|
61
|
-
taskId: taskResults.task.aspectId,
|
|
62
|
-
taskName: taskResults.task.name,
|
|
63
|
-
taskDescription: taskResults.task.description,
|
|
64
|
-
errors: foundComponent.errors,
|
|
65
|
-
warnings: foundComponent.warnings,
|
|
66
|
-
startTime: foundComponent.startTime,
|
|
67
|
-
endTime: foundComponent.endTime,
|
|
68
|
-
};
|
|
69
|
-
return pipelineReport;
|
|
70
|
-
});
|
|
71
|
-
return compact(compResults);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public getDataOfComponent(componentId: ComponentID): AspectData[] {
|
|
75
|
-
const tasksData = this.getMetadataFromTaskResults(componentId);
|
|
76
|
-
return Object.keys(tasksData).map((taskId) => ({
|
|
77
|
-
aspectId: taskId,
|
|
78
|
-
data: tasksData[taskId],
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public getArtifactsDataOfComponent(componentId: ComponentID): ArtifactObject[] | undefined {
|
|
83
|
-
return this.artifactListsMap.getValueByComponentId(componentId)?.toObject();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private mergeDataIfPossible(currentData: Serializable, existingData: Serializable | undefined, taskId: string) {
|
|
87
|
-
if (!existingData || isEmpty(existingData)) return currentData;
|
|
88
|
-
// both exist
|
|
89
|
-
if (typeof currentData !== 'object') {
|
|
90
|
-
throw new Error(`task data must be "object", get ${typeof currentData} for ${taskId}`);
|
|
91
|
-
}
|
|
92
|
-
if (Array.isArray(currentData)) {
|
|
93
|
-
throw new Error(`task data must be "object", get Array for ${taskId}`);
|
|
94
|
-
}
|
|
95
|
-
return { ...currentData, ...existingData };
|
|
96
|
-
}
|
|
97
|
-
}
|
package/build-task.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { Component } from '@teambit/component';
|
|
2
|
-
import { ExecutionContext } from '@teambit/envs';
|
|
3
|
-
import type { Network } from '@teambit/isolator';
|
|
4
|
-
import type { ComponentResult } from './types';
|
|
5
|
-
import type { ArtifactDefinition } from './artifact';
|
|
6
|
-
import { TaskResultsList } from './task-results-list';
|
|
7
|
-
import { TaskResults } from './build-pipe';
|
|
8
|
-
|
|
9
|
-
export type TaskLocation = 'start' | 'end';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* delimiter between task.aspectId and task.name
|
|
13
|
-
*/
|
|
14
|
-
export const TaskIdDelimiter = ':';
|
|
15
|
-
|
|
16
|
-
export interface BuildContext extends ExecutionContext {
|
|
17
|
-
/**
|
|
18
|
-
* all components about to be built/tagged.
|
|
19
|
-
*/
|
|
20
|
-
components: Component[];
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* network of capsules ready to be built.
|
|
24
|
-
*/
|
|
25
|
-
capsuleNetwork: Network;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* data generated by tasks that were running before this task
|
|
29
|
-
*/
|
|
30
|
-
previousTasksResults: TaskResults[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface BuildTask {
|
|
34
|
-
/**
|
|
35
|
-
* aspect id serialized of the creator of the task.
|
|
36
|
-
* todo: automate this so then it won't be needed to pass manually.
|
|
37
|
-
*/
|
|
38
|
-
aspectId: string;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* name of the task. function as an identifier among other tasks of the same aspectId.
|
|
42
|
-
* spaces and special characters are not allowed. as a convention, use UpperCamelCase style.
|
|
43
|
-
* (e.g. TypescriptCompiler).
|
|
44
|
-
*/
|
|
45
|
-
name: string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* description of what the task does.
|
|
49
|
-
* if available, the logger will log it show it in the status-line.
|
|
50
|
-
*/
|
|
51
|
-
description?: string;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* where to put the task, before the env pipeline or after
|
|
55
|
-
*/
|
|
56
|
-
location?: TaskLocation;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* execute a task in a build context
|
|
60
|
-
*/
|
|
61
|
-
execute(context: BuildContext): Promise<BuiltTaskResult>;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* run before the build pipeline has started. this is useful when some preparation are needed to
|
|
65
|
-
* be done on all envs before the build starts.
|
|
66
|
-
* e.g. typescript compiler needs to write the tsconfig file. doing it during the task, will
|
|
67
|
-
* cause dependencies from other envs to get this tsconfig written.
|
|
68
|
-
*/
|
|
69
|
-
preBuild?(context: BuildContext): Promise<void>;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* run after the build pipeline completed for all envs. useful for doing some cleanup on the
|
|
73
|
-
* capsules before the deployment starts.
|
|
74
|
-
*/
|
|
75
|
-
postBuild?(context: BuildContext, tasksResults: TaskResultsList): Promise<void>;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* needed if you want the task to be running only after the dependencies were completed
|
|
79
|
-
* for *all* envs.
|
|
80
|
-
* normally this is not needed because the build-pipeline runs the tasks in the same order
|
|
81
|
-
* they're located in the `getBuildPipe()` array and according to the task.location.
|
|
82
|
-
* the case where this is useful is when a task not only needs to be after another task, but also
|
|
83
|
-
* after all environments were running that task.
|
|
84
|
-
* a dependency is task.aspectId. if an aspect has multiple tasks, to be more specific, use
|
|
85
|
-
* "aspectId:name", e.g. "teambit.compilation/compiler:TypescriptCompiler".
|
|
86
|
-
*/
|
|
87
|
-
dependencies?: string[];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// TODO: rename to BuildTaskResults
|
|
91
|
-
export interface BuiltTaskResult {
|
|
92
|
-
/**
|
|
93
|
-
* build results for each of the components in the build context.
|
|
94
|
-
*/
|
|
95
|
-
componentsResults: ComponentResult[];
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* array of artifact definitions to generate after a successful build.
|
|
99
|
-
*/
|
|
100
|
-
artifacts?: ArtifactDefinition[];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export class BuildTaskHelper {
|
|
104
|
-
static serializeId({ aspectId, name }: BuildTask): string {
|
|
105
|
-
return aspectId + TaskIdDelimiter + name;
|
|
106
|
-
}
|
|
107
|
-
static deserializeId(id: string): { aspectId: string; name?: string } {
|
|
108
|
-
const split = id.split(TaskIdDelimiter);
|
|
109
|
-
if (split.length === 0) throw new Error(`deserializeId, ${id} is empty`);
|
|
110
|
-
if (split.length === 1) return { aspectId: split[0] };
|
|
111
|
-
if (split.length === 2) return { aspectId: split[0], name: split[1] };
|
|
112
|
-
throw new Error(`deserializeId, id ${id} has more than one ${TaskIdDelimiter}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
package/build.cmd.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
-
import { Logger } from '@teambit/logger';
|
|
3
|
-
import { Workspace } from '@teambit/workspace';
|
|
4
|
-
import { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import { BuilderMain } from './builder.main.runtime';
|
|
7
|
-
|
|
8
|
-
type BuildOpts = {
|
|
9
|
-
rebuild: boolean;
|
|
10
|
-
install: boolean;
|
|
11
|
-
cachePackagesOnCapsulesRoot: boolean;
|
|
12
|
-
reuseCapsules: boolean;
|
|
13
|
-
tasks: string;
|
|
14
|
-
listTasks?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export class BuilderCmd implements Command {
|
|
18
|
-
name = 'build [pattern]';
|
|
19
|
-
description = 'run set of tasks for build';
|
|
20
|
-
alias = '';
|
|
21
|
-
group = 'development';
|
|
22
|
-
options = [
|
|
23
|
-
['', 'install', 'install core aspects in capsules'],
|
|
24
|
-
['', 'reuse-capsules', 'avoid deleting the capsules root-dir before starting the build'],
|
|
25
|
-
[
|
|
26
|
-
'',
|
|
27
|
-
'tasks <string>',
|
|
28
|
-
`build the specified task(s) only. for multiple tasks, separate by a comma and wrap with quotes.
|
|
29
|
-
specify the task-name (e.g. "TypescriptCompiler") or the task-aspect-id (e.g. teambit.compilation/compiler)`,
|
|
30
|
-
],
|
|
31
|
-
['', 'cache-packages-on-capsule-root', 'set the package-manager cache on the capsule root'],
|
|
32
|
-
[
|
|
33
|
-
'',
|
|
34
|
-
'list-tasks <string>',
|
|
35
|
-
'list tasks of an env or a component-id for each one of the pipelines: build, tag and snap',
|
|
36
|
-
],
|
|
37
|
-
] as CommandOptions;
|
|
38
|
-
|
|
39
|
-
constructor(private builder: BuilderMain, private workspace: Workspace, private logger: Logger) {}
|
|
40
|
-
|
|
41
|
-
async report(
|
|
42
|
-
[userPattern]: [string],
|
|
43
|
-
{ install = false, cachePackagesOnCapsulesRoot = false, reuseCapsules = false, tasks, listTasks }: BuildOpts
|
|
44
|
-
): Promise<string> {
|
|
45
|
-
if (!this.workspace) throw new ConsumerNotFound();
|
|
46
|
-
if (listTasks) {
|
|
47
|
-
return this.getListTasks(listTasks);
|
|
48
|
-
}
|
|
49
|
-
const longProcessLogger = this.logger.createLongProcessLogger('build');
|
|
50
|
-
const pattern = userPattern && userPattern.toString();
|
|
51
|
-
const components = pattern ? await this.workspace.byPattern(pattern) : await this.workspace.list();
|
|
52
|
-
|
|
53
|
-
const envsExecutionResults = await this.builder.build(
|
|
54
|
-
components,
|
|
55
|
-
{
|
|
56
|
-
installOptions: {
|
|
57
|
-
installTeambitBit: install,
|
|
58
|
-
},
|
|
59
|
-
linkingOptions: { linkTeambitBit: !install },
|
|
60
|
-
emptyRootDir: !reuseCapsules,
|
|
61
|
-
getExistingAsIs: reuseCapsules,
|
|
62
|
-
cachePackagesOnCapsulesRoot,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
tasks: tasks ? tasks.split(',').map((task) => task.trim()) : [],
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
longProcessLogger.end();
|
|
69
|
-
envsExecutionResults.throwErrorsIfExist();
|
|
70
|
-
this.logger.consoleSuccess();
|
|
71
|
-
return chalk.green(`the build has been completed. total: ${envsExecutionResults.tasksQueue.length} tasks`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private async getListTasks(componentIdStr: string): Promise<string> {
|
|
75
|
-
const compId = await this.workspace.resolveComponentId(componentIdStr);
|
|
76
|
-
const component = await this.workspace.get(compId);
|
|
77
|
-
const results = this.builder.listTasks(component);
|
|
78
|
-
return `${chalk.green('Tasks List')}
|
|
79
|
-
id: ${results.id.toString()}
|
|
80
|
-
envId: ${results.envId}
|
|
81
|
-
|
|
82
|
-
${chalk.bold('Build Pipeline Tasks:')}
|
|
83
|
-
${results.buildTasks.join('\n')}
|
|
84
|
-
|
|
85
|
-
${chalk.bold('Tag Pipeline Tasks:')}
|
|
86
|
-
${results.tagTasks.join('\n')}
|
|
87
|
-
|
|
88
|
-
${chalk.bold('Snap Pipeline Tasks:')}
|
|
89
|
-
${results.snapTasks.join('\n') || '<N/A>'}`;
|
|
90
|
-
}
|
|
91
|
-
}
|
package/builder.aspect.ts
DELETED
package/builder.docs.mdx
DELETED
package/builder.graphql.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Component } from '@teambit/component';
|
|
2
|
-
import gql from 'graphql-tag';
|
|
3
|
-
|
|
4
|
-
import { BuilderMain } from './builder.main.runtime';
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
-
export function builderSchema(builder: BuilderMain) {
|
|
8
|
-
return {
|
|
9
|
-
typeDefs: gql`
|
|
10
|
-
type ExtensionDescriptor {
|
|
11
|
-
# extension ID.
|
|
12
|
-
id: String
|
|
13
|
-
|
|
14
|
-
# icon of the extension.
|
|
15
|
-
icon: String
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type ExtensionArtifact {
|
|
19
|
-
# descriptor of the artifact's extension
|
|
20
|
-
extensionDescriptor: ExtensionDescriptor
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
extend type Component {
|
|
24
|
-
# list of extension artifacts.
|
|
25
|
-
getArtifacts(hash: String!): [ExtensionArtifact]
|
|
26
|
-
}
|
|
27
|
-
`,
|
|
28
|
-
resolvers: {
|
|
29
|
-
Component: {
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
31
|
-
getArtifacts: async (component: Component, { hash }: { hash: string }) => {
|
|
32
|
-
// const artifacts = await builder.getArtifacts(component.id, hash);
|
|
33
|
-
// return artifacts.map((artifact) => artifact.toObject());
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
}
|