@teambit/builder 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.
- package/artifacts/preview/teambit_pipelines_builder-preview.js +1 -0
- package/dist/{preview-1703647408454.js → preview-1703698405864.js} +2 -2
- package/package.json +18 -18
- package/build-pipe.ts +0 -216
- package/build-pipeline-order.ts +0 -192
- package/build-pipeline-result-list.ts +0 -97
- package/build-task.ts +0 -151
- package/build.cmd.ts +0 -157
- package/builder-env-type.ts +0 -16
- package/builder.aspect.ts +0 -5
- package/builder.graphql.ts +0 -185
- package/builder.main.runtime.ts +0 -493
- package/builder.route.ts +0 -95
- package/index.ts +0 -20
- package/pipeline.ts +0 -104
- package/task-results-list.ts +0 -68
- package/task.ts +0 -50
- package/tasks-queue.ts +0 -40
- package/types.ts +0 -37
package/pipeline.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { BuildTask } from '@teambit/builder';
|
|
2
|
-
import { EnvContext, EnvHandler } from '@teambit/envs';
|
|
3
|
-
import { clone, findIndex } from 'lodash';
|
|
4
|
-
import { Task } from './task';
|
|
5
|
-
|
|
6
|
-
export type TaskHandler = {
|
|
7
|
-
handler: EnvHandler<Task>;
|
|
8
|
-
name: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* create and maintain build pipelines for component
|
|
13
|
-
* dev environments.
|
|
14
|
-
*/
|
|
15
|
-
export class Pipeline {
|
|
16
|
-
constructor(private _tasks: TaskHandler[]) {}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* list all tasks in the build pipeline.
|
|
20
|
-
*/
|
|
21
|
-
get tasks() {
|
|
22
|
-
return this._tasks;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private initiateTasks(tasks: TaskHandler[], context: EnvContext, envId: string) {
|
|
26
|
-
const _tasks = tasks.map((task) => {
|
|
27
|
-
return task.handler(context);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const buildTasks: BuildTask[] = _tasks.map((task) => {
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
const aspectId = task.aspectId || envId;
|
|
33
|
-
const buildTask: BuildTask = Object.assign(clone(task), { aspectId });
|
|
34
|
-
return buildTask;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return buildTasks;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* add a build task to the pipeline.
|
|
42
|
-
*/
|
|
43
|
-
add(tasks: TaskHandler[]) {
|
|
44
|
-
this._tasks = this._tasks.concat(tasks);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* remove a build task from the pipeline.
|
|
50
|
-
*/
|
|
51
|
-
remove(taskNames: string[]) {
|
|
52
|
-
this._tasks = this._tasks.filter((task) => {
|
|
53
|
-
return !taskNames.includes(task.name);
|
|
54
|
-
});
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* replace a build task in the pipeline.
|
|
60
|
-
*/
|
|
61
|
-
replace(tasks: TaskHandler[]) {
|
|
62
|
-
tasks.forEach((task) => {
|
|
63
|
-
// Find task index using _.findIndex
|
|
64
|
-
const matchIndex = findIndex(this._tasks, (origTask) => {
|
|
65
|
-
return origTask.name === task.name;
|
|
66
|
-
});
|
|
67
|
-
if (matchIndex !== -1) {
|
|
68
|
-
// Replace task at index using native splice
|
|
69
|
-
this._tasks.splice(matchIndex, 1, task);
|
|
70
|
-
} else {
|
|
71
|
-
// Add task if there's no existing task to replace
|
|
72
|
-
this._tasks.push(task);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* return a new pipeline with the tasks from the pipeline args added.
|
|
80
|
-
* @param pipeline
|
|
81
|
-
* @returns
|
|
82
|
-
*/
|
|
83
|
-
concat(pipeline: Pipeline) {
|
|
84
|
-
return new Pipeline(this._tasks.concat(pipeline.tasks));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* compute the pipeline.
|
|
89
|
-
*/
|
|
90
|
-
compute(context: EnvContext): BuildTask[] {
|
|
91
|
-
const buildTasks = this.initiateTasks(this._tasks, context, context.envId.toString());
|
|
92
|
-
return buildTasks;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
static from(tasks: TaskHandler[]) {
|
|
96
|
-
return new Pipeline(tasks);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// static concat(...pipelines: EnvHandler<Pipeline>[]) {
|
|
100
|
-
// return reduceServiceHandlersFactories(pipelines, (acc, pipeline) => {
|
|
101
|
-
// return acc.concat(pipeline);
|
|
102
|
-
// });
|
|
103
|
-
// }
|
|
104
|
-
}
|
package/task-results-list.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { BitError } from '@teambit/bit-error';
|
|
3
|
-
import { BuildTaskHelper } from './build-task';
|
|
4
|
-
import { TasksQueue } from './tasks-queue';
|
|
5
|
-
import { TaskResults } from './build-pipe';
|
|
6
|
-
import { ComponentResult } from './types';
|
|
7
|
-
|
|
8
|
-
export class TaskResultsList {
|
|
9
|
-
constructor(
|
|
10
|
-
public tasksQueue: TasksQueue,
|
|
11
|
-
/**
|
|
12
|
-
* results of all tasks executed in the build pipeline.
|
|
13
|
-
*/
|
|
14
|
-
public tasksResults: TaskResults[],
|
|
15
|
-
|
|
16
|
-
public capsuleRootDir: string
|
|
17
|
-
) {}
|
|
18
|
-
|
|
19
|
-
hasErrors(): boolean {
|
|
20
|
-
return this.tasksResults.some((taskResult) => taskResult.componentsResults.find((c) => c.errors?.length));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
throwErrorsIfExist() {
|
|
24
|
-
const errorMessage = this.getErrorMessageFormatted();
|
|
25
|
-
if (errorMessage) {
|
|
26
|
-
throw new BitError(errorMessage);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* group errors from all tasks and show them nicely to the user
|
|
32
|
-
*/
|
|
33
|
-
public getErrorMessageFormatted(): string | null {
|
|
34
|
-
const tasksErrors: string[] = [];
|
|
35
|
-
let totalErrors = 0;
|
|
36
|
-
this.tasksResults.forEach((taskResult) => {
|
|
37
|
-
const compsWithErrors = taskResult.componentsResults.filter((c) => c.errors?.length);
|
|
38
|
-
if (!compsWithErrors.length) return;
|
|
39
|
-
const title = chalk.bold(
|
|
40
|
-
`Failed task ${tasksErrors.length + 1}: "${BuildTaskHelper.serializeId(taskResult.task)}" of env "${
|
|
41
|
-
taskResult.env.id
|
|
42
|
-
}"\n`
|
|
43
|
-
);
|
|
44
|
-
const errorsStr = compsWithErrors
|
|
45
|
-
.map((compWithErrors) => this.aggregateTaskErrorsToOneString(compWithErrors))
|
|
46
|
-
.join('\n\n');
|
|
47
|
-
const taskErrors = compsWithErrors.reduce((acc, current) => acc + (current.errors || []).length, 0);
|
|
48
|
-
const summery = `\n\nFound ${taskErrors} errors in ${compsWithErrors.length} components`;
|
|
49
|
-
totalErrors += taskErrors;
|
|
50
|
-
tasksErrors.push(title + errorsStr + summery);
|
|
51
|
-
});
|
|
52
|
-
if (!tasksErrors.length) return null;
|
|
53
|
-
const title = `\nThe following errors were found while running the build pipeline\n`;
|
|
54
|
-
const errorsStr = tasksErrors.join('\n\n');
|
|
55
|
-
const totalTasks = this.tasksQueue.length;
|
|
56
|
-
const totalFailed = tasksErrors.length;
|
|
57
|
-
const totalSucceed = this.tasksResults.length - totalFailed;
|
|
58
|
-
const totalSkipped = totalTasks - this.tasksResults.length;
|
|
59
|
-
const summery = `\n\n\n✖ Total ${totalTasks} tasks. ${totalSucceed} succeeded. ${totalFailed} failed. ${totalSkipped} skipped. Total errors: ${totalErrors}.`;
|
|
60
|
-
return title + errorsStr + summery;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private aggregateTaskErrorsToOneString(componentResult: ComponentResult) {
|
|
64
|
-
const rawErrors = componentResult.errors || [];
|
|
65
|
-
const errors = rawErrors.map((e) => (typeof e === 'string' ? e : e.toString()));
|
|
66
|
-
return `component: ${componentResult.component.id.toString()}\n${errors.join('\n')}`;
|
|
67
|
-
}
|
|
68
|
-
}
|
package/task.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { BuildContext, BuiltTaskResult } from './build-task';
|
|
2
|
-
import { TaskResultsList } from './task-results-list';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* this is the external interface for task. please make
|
|
6
|
-
* sure to use only this interface outside of this builder
|
|
7
|
-
* aspect.
|
|
8
|
-
*/
|
|
9
|
-
export interface Task {
|
|
10
|
-
/**
|
|
11
|
-
* names ideally with dashes 'typescript'
|
|
12
|
-
*/
|
|
13
|
-
name: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* description of what the task does.
|
|
17
|
-
*/
|
|
18
|
-
description?: string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* execute a task in a build context
|
|
22
|
-
*/
|
|
23
|
-
execute(context: BuildContext): Promise<BuiltTaskResult>;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* run before the build pipeline has started. this is useful when some preparation are needed to
|
|
27
|
-
* be done on all envs before the build starts.
|
|
28
|
-
* e.g. typescript compiler needs to write the tsconfig file. doing it during the task, will
|
|
29
|
-
* cause dependencies from other envs to get this tsconfig written.
|
|
30
|
-
*/
|
|
31
|
-
preBuild?(context: BuildContext): Promise<void>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* run after the build pipeline completed for all envs. useful for doing some cleanup on the
|
|
35
|
-
* capsules before the deployment starts.
|
|
36
|
-
*/
|
|
37
|
-
postBuild?(context: BuildContext, tasksResults: TaskResultsList): Promise<void>;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* needed if you want the task to be running only after the dependencies were completed
|
|
41
|
-
* for *all* envs.
|
|
42
|
-
* normally this is not needed because the build-pipeline runs the tasks in the same order
|
|
43
|
-
* they're located in the `getBuildPipe()` array and according to the task.location.
|
|
44
|
-
* the case where this is useful is when a task not only needs to be after another task, but also
|
|
45
|
-
* after all environments were running that task.
|
|
46
|
-
* a dependency is task.aspectId. if an aspect has multiple tasks, to be more specific, use
|
|
47
|
-
* "aspectId:name", e.g. "teambit.compilation/compiler:TypescriptCompiler".
|
|
48
|
-
*/
|
|
49
|
-
dependencies?: string[];
|
|
50
|
-
}
|
package/tasks-queue.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { EnvDefinition } from '@teambit/envs';
|
|
2
|
-
import { BuildTask, BuildTaskHelper } from './build-task';
|
|
3
|
-
import { InvalidTask } from './exceptions';
|
|
4
|
-
|
|
5
|
-
type EnvTask = { env: EnvDefinition; task: BuildTask };
|
|
6
|
-
|
|
7
|
-
export class TasksQueue extends Array<EnvTask> {
|
|
8
|
-
toString() {
|
|
9
|
-
return this.map(({ env, task }) => `env ${env.id}, task ${BuildTaskHelper.serializeId(task)}`).join('\n');
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* make sure tasks names are valid and there are no duplications
|
|
13
|
-
*/
|
|
14
|
-
validate() {
|
|
15
|
-
this.forEach(({ task }) => {
|
|
16
|
-
this.validateTaskName(task);
|
|
17
|
-
});
|
|
18
|
-
this.validateDuplications();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private validateTaskName(task: BuildTask) {
|
|
22
|
-
if (!task.name) throw new InvalidTask(task.aspectId, 'name is missing');
|
|
23
|
-
const regexWord = /^\w+$/; // match any word: a-zA-Z0-9 and underscore.
|
|
24
|
-
const isValid = regexWord.test(task.name);
|
|
25
|
-
if (!isValid)
|
|
26
|
-
throw new InvalidTask(task.aspectId, `name "${task.name}" is invalid, only alphanumeric characters are allowed`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private validateDuplications() {
|
|
30
|
-
const uniqueTasks = this.map(({ env, task }) => `${env.id} ${task.aspectId}:${task.name}`);
|
|
31
|
-
uniqueTasks.forEach((uniqTask) => {
|
|
32
|
-
if (uniqueTasks.filter((u) => u === uniqTask).length > 1) {
|
|
33
|
-
throw new InvalidTask(
|
|
34
|
-
uniqTask,
|
|
35
|
-
'there are two or more tasks with the same name and aspectId in the same environment'
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
package/types.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Component } from '@teambit/component';
|
|
2
|
-
|
|
3
|
-
export type TaskMetadata = { [key: string]: any };
|
|
4
|
-
|
|
5
|
-
export type ComponentResult = {
|
|
6
|
-
/**
|
|
7
|
-
* instance of the component
|
|
8
|
-
*/
|
|
9
|
-
component: Component;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* metadata generated during component build.
|
|
13
|
-
* this eventually gets saved into `aspectsData` prop of the builder aspect data.
|
|
14
|
-
* it can be retrieved later on by `builder.getDataByAspect()` method.
|
|
15
|
-
*/
|
|
16
|
-
metadata?: TaskMetadata;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* returning errors from build tasks will cause a pipeline failure and logs all returned errors.
|
|
20
|
-
*/
|
|
21
|
-
errors?: Array<Error | string>;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* warnings generated throughout the build task.
|
|
25
|
-
*/
|
|
26
|
-
warnings?: string[];
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* timestamp in milliseconds when the task started
|
|
30
|
-
*/
|
|
31
|
-
startTime?: number;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* timestamp in milliseconds when the task ended
|
|
35
|
-
*/
|
|
36
|
-
endTime?: number;
|
|
37
|
-
};
|