@teambit/builder 1.0.107 → 1.0.108

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.
Files changed (55) hide show
  1. package/build-pipe.ts +216 -0
  2. package/build-pipeline-order.ts +192 -0
  3. package/build-pipeline-result-list.ts +97 -0
  4. package/build-task.ts +151 -0
  5. package/build.cmd.ts +157 -0
  6. package/builder-env-type.ts +16 -0
  7. package/builder.aspect.ts +5 -0
  8. package/builder.graphql.ts +185 -0
  9. package/builder.main.runtime.ts +493 -0
  10. package/builder.route.ts +95 -0
  11. package/dist/artifact/artifact-definition.d.ts +2 -2
  12. package/dist/artifact/artifact-extractor.d.ts +3 -3
  13. package/dist/artifact/artifact-factory.d.ts +1 -1
  14. package/dist/artifact/artifact-factory.js +1 -2
  15. package/dist/artifact/artifact-factory.js.map +1 -1
  16. package/dist/artifact/artifact-list.d.ts +1 -1
  17. package/dist/artifact/artifact.d.ts +1 -1
  18. package/dist/artifact/artifacts.cmd.d.ts +1 -1
  19. package/dist/build-pipe.d.ts +3 -3
  20. package/dist/build-pipe.js +5 -12
  21. package/dist/build-pipe.js.map +1 -1
  22. package/dist/build-pipeline-result-list.d.ts +2 -2
  23. package/dist/build-pipeline-result-list.js +1 -2
  24. package/dist/build-pipeline-result-list.js.map +1 -1
  25. package/dist/build-task.d.ts +1 -1
  26. package/dist/build.cmd.d.ts +1 -1
  27. package/dist/builder.composition.d.ts +2 -2
  28. package/dist/builder.graphql.d.ts +17 -17
  29. package/dist/builder.graphql.js +4 -8
  30. package/dist/builder.graphql.js.map +1 -1
  31. package/dist/builder.main.runtime.d.ts +5 -5
  32. package/dist/builder.main.runtime.js +11 -14
  33. package/dist/builder.main.runtime.js.map +1 -1
  34. package/dist/builder.route.d.ts +1 -1
  35. package/dist/builder.route.js +3 -3
  36. package/dist/builder.route.js.map +1 -1
  37. package/dist/builder.service.d.ts +9 -9
  38. package/dist/builder.service.js +4 -4
  39. package/dist/builder.service.js.map +1 -1
  40. package/dist/pipeline.d.ts +1 -1
  41. package/dist/{preview-1703590665075.js → preview-1703647408454.js} +2 -2
  42. package/dist/storage/storage-resolver.d.ts +2 -2
  43. package/dist/task-results-list.js +2 -8
  44. package/dist/task-results-list.js.map +1 -1
  45. package/dist/tasks-queue.d.ts +1 -1
  46. package/dist/types.d.ts +2 -2
  47. package/index.ts +20 -0
  48. package/package.json +26 -33
  49. package/pipeline.ts +104 -0
  50. package/task-results-list.ts +68 -0
  51. package/task.ts +50 -0
  52. package/tasks-queue.ts +40 -0
  53. package/tsconfig.json +16 -21
  54. package/types/asset.d.ts +15 -3
  55. package/types.ts +37 -0
@@ -1 +1 @@
1
- {"version":3,"names":["_chalk","data","_interopRequireDefault","require","_bitError","_buildTask","obj","__esModule","default","TaskResultsList","constructor","tasksQueue","tasksResults","capsuleRootDir","hasErrors","some","taskResult","componentsResults","find","c","_c$errors","errors","length","throwErrorsIfExist","errorMessage","getErrorMessageFormatted","BitError","tasksErrors","totalErrors","forEach","compsWithErrors","filter","_c$errors2","title","chalk","bold","BuildTaskHelper","serializeId","task","env","id","errorsStr","map","compWithErrors","aggregateTaskErrorsToOneString","join","taskErrors","reduce","acc","current","summery","push","totalTasks","totalFailed","totalSucceed","totalSkipped","componentResult","rawErrors","e","toString","component","exports"],"sources":["task-results-list.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { BitError } from '@teambit/bit-error';\nimport { BuildTaskHelper } from './build-task';\nimport { TasksQueue } from './tasks-queue';\nimport { TaskResults } from './build-pipe';\nimport { ComponentResult } from './types';\n\nexport class TaskResultsList {\n constructor(\n public tasksQueue: TasksQueue,\n /**\n * results of all tasks executed in the build pipeline.\n */\n public tasksResults: TaskResults[],\n\n public capsuleRootDir: string\n ) {}\n\n hasErrors(): boolean {\n return this.tasksResults.some((taskResult) => taskResult.componentsResults.find((c) => c.errors?.length));\n }\n\n throwErrorsIfExist() {\n const errorMessage = this.getErrorMessageFormatted();\n if (errorMessage) {\n throw new BitError(errorMessage);\n }\n }\n\n /**\n * group errors from all tasks and show them nicely to the user\n */\n public getErrorMessageFormatted(): string | null {\n const tasksErrors: string[] = [];\n let totalErrors = 0;\n this.tasksResults.forEach((taskResult) => {\n const compsWithErrors = taskResult.componentsResults.filter((c) => c.errors?.length);\n if (!compsWithErrors.length) return;\n const title = chalk.bold(\n `Failed task ${tasksErrors.length + 1}: \"${BuildTaskHelper.serializeId(taskResult.task)}\" of env \"${\n taskResult.env.id\n }\"\\n`\n );\n const errorsStr = compsWithErrors\n .map((compWithErrors) => this.aggregateTaskErrorsToOneString(compWithErrors))\n .join('\\n\\n');\n const taskErrors = compsWithErrors.reduce((acc, current) => acc + (current.errors || []).length, 0);\n const summery = `\\n\\nFound ${taskErrors} errors in ${compsWithErrors.length} components`;\n totalErrors += taskErrors;\n tasksErrors.push(title + errorsStr + summery);\n });\n if (!tasksErrors.length) return null;\n const title = `\\nThe following errors were found while running the build pipeline\\n`;\n const errorsStr = tasksErrors.join('\\n\\n');\n const totalTasks = this.tasksQueue.length;\n const totalFailed = tasksErrors.length;\n const totalSucceed = this.tasksResults.length - totalFailed;\n const totalSkipped = totalTasks - this.tasksResults.length;\n const summery = `\\n\\n\\n✖ Total ${totalTasks} tasks. ${totalSucceed} succeeded. ${totalFailed} failed. ${totalSkipped} skipped. Total errors: ${totalErrors}.`;\n return title + errorsStr + summery;\n }\n\n private aggregateTaskErrorsToOneString(componentResult: ComponentResult) {\n const rawErrors = componentResult.errors || [];\n const errors = rawErrors.map((e) => (typeof e === 'string' ? e : e.toString()));\n return `component: ${componentResult.component.id.toString()}\\n${errors.join('\\n')}`;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,SAAA,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D,MAAM4B,OAAO,GAAI,iBAAgBE,UAAW,WAAUE,YAAa,eAAcD,WAAY,YAAWE,YAAa,2BAA0B3B,WAAY,GAAE;IAC7J,OAAOK,KAAK,GAAGQ,SAAS,GAAGS,OAAO;EACpC;EAEQN,8BAA8BA,CAACY,eAAgC,EAAE;IACvE,MAAMC,SAAS,GAAGD,eAAe,CAACnC,MAAM,IAAI,EAAE;IAC9C,MAAMA,MAAM,GAAGoC,SAAS,CAACf,GAAG,CAAEgB,CAAC,IAAM,OAAOA,CAAC,KAAK,QAAQ,GAAGA,CAAC,GAAGA,CAAC,CAACC,QAAQ,CAAC,CAAE,CAAC;IAC/E,OAAQ,cAAaH,eAAe,CAACI,SAAS,CAACpB,EAAE,CAACmB,QAAQ,CAAC,CAAE,KAAItC,MAAM,CAACwB,IAAI,CAAC,IAAI,CAAE,EAAC;EACtF;AACF;AAACgB,OAAA,CAAApD,eAAA,GAAAA,eAAA"}
1
+ {"version":3,"names":["_chalk","data","_interopRequireDefault","require","_bitError","_buildTask","obj","__esModule","default","TaskResultsList","constructor","tasksQueue","tasksResults","capsuleRootDir","hasErrors","some","taskResult","componentsResults","find","c","errors","length","throwErrorsIfExist","errorMessage","getErrorMessageFormatted","BitError","tasksErrors","totalErrors","forEach","compsWithErrors","filter","title","chalk","bold","BuildTaskHelper","serializeId","task","env","id","errorsStr","map","compWithErrors","aggregateTaskErrorsToOneString","join","taskErrors","reduce","acc","current","summery","push","totalTasks","totalFailed","totalSucceed","totalSkipped","componentResult","rawErrors","e","toString","component","exports"],"sources":["task-results-list.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { BitError } from '@teambit/bit-error';\nimport { BuildTaskHelper } from './build-task';\nimport { TasksQueue } from './tasks-queue';\nimport { TaskResults } from './build-pipe';\nimport { ComponentResult } from './types';\n\nexport class TaskResultsList {\n constructor(\n public tasksQueue: TasksQueue,\n /**\n * results of all tasks executed in the build pipeline.\n */\n public tasksResults: TaskResults[],\n\n public capsuleRootDir: string\n ) {}\n\n hasErrors(): boolean {\n return this.tasksResults.some((taskResult) => taskResult.componentsResults.find((c) => c.errors?.length));\n }\n\n throwErrorsIfExist() {\n const errorMessage = this.getErrorMessageFormatted();\n if (errorMessage) {\n throw new BitError(errorMessage);\n }\n }\n\n /**\n * group errors from all tasks and show them nicely to the user\n */\n public getErrorMessageFormatted(): string | null {\n const tasksErrors: string[] = [];\n let totalErrors = 0;\n this.tasksResults.forEach((taskResult) => {\n const compsWithErrors = taskResult.componentsResults.filter((c) => c.errors?.length);\n if (!compsWithErrors.length) return;\n const title = chalk.bold(\n `Failed task ${tasksErrors.length + 1}: \"${BuildTaskHelper.serializeId(taskResult.task)}\" of env \"${\n taskResult.env.id\n }\"\\n`\n );\n const errorsStr = compsWithErrors\n .map((compWithErrors) => this.aggregateTaskErrorsToOneString(compWithErrors))\n .join('\\n\\n');\n const taskErrors = compsWithErrors.reduce((acc, current) => acc + (current.errors || []).length, 0);\n const summery = `\\n\\nFound ${taskErrors} errors in ${compsWithErrors.length} components`;\n totalErrors += taskErrors;\n tasksErrors.push(title + errorsStr + summery);\n });\n if (!tasksErrors.length) return null;\n const title = `\\nThe following errors were found while running the build pipeline\\n`;\n const errorsStr = tasksErrors.join('\\n\\n');\n const totalTasks = this.tasksQueue.length;\n const totalFailed = tasksErrors.length;\n const totalSucceed = this.tasksResults.length - totalFailed;\n const totalSkipped = totalTasks - this.tasksResults.length;\n const summery = `\\n\\n\\n✖ Total ${totalTasks} tasks. ${totalSucceed} succeeded. ${totalFailed} failed. ${totalSkipped} skipped. Total errors: ${totalErrors}.`;\n return title + errorsStr + summery;\n }\n\n private aggregateTaskErrorsToOneString(componentResult: ComponentResult) {\n const rawErrors = componentResult.errors || [];\n const errors = rawErrors.map((e) => (typeof e === 'string' ? e : e.toString()));\n return `component: ${componentResult.component.id.toString()}\\n${errors.join('\\n')}`;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAA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IAC1D,MAAM2B,OAAO,GAAI,iBAAgBE,UAAW,WAAUE,YAAa,eAAcD,WAAY,YAAWE,YAAa,2BAA0B1B,WAAY,GAAE;IAC7J,OAAOI,KAAK,GAAGQ,SAAS,GAAGS,OAAO;EACpC;EAEQN,8BAA8BA,CAACY,eAAgC,EAAE;IACvE,MAAMC,SAAS,GAAGD,eAAe,CAAClC,MAAM,IAAI,EAAE;IAC9C,MAAMA,MAAM,GAAGmC,SAAS,CAACf,GAAG,CAAEgB,CAAC,IAAM,OAAOA,CAAC,KAAK,QAAQ,GAAGA,CAAC,GAAGA,CAAC,CAACC,QAAQ,CAAC,CAAE,CAAC;IAC/E,OAAQ,cAAaH,eAAe,CAACI,SAAS,CAACpB,EAAE,CAACmB,QAAQ,CAAC,CAAE,KAAIrC,MAAM,CAACuB,IAAI,CAAC,IAAI,CAAE,EAAC;EACtF;AACF;AAACgB,OAAA,CAAAlD,eAAA,GAAAA,eAAA"}
@@ -1,6 +1,6 @@
1
1
  import { EnvDefinition } from '@teambit/envs';
2
2
  import { BuildTask } from './build-task';
3
- declare type EnvTask = {
3
+ type EnvTask = {
4
4
  env: EnvDefinition;
5
5
  task: BuildTask;
6
6
  };
package/dist/types.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Component } from '@teambit/component';
2
- export declare type TaskMetadata = {
2
+ export type TaskMetadata = {
3
3
  [key: string]: any;
4
4
  };
5
- export declare type ComponentResult = {
5
+ export type ComponentResult = {
6
6
  /**
7
7
  * instance of the component
8
8
  */
package/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { BuilderAspect } from './builder.aspect';
2
+
3
+ export { ArtifactVinyl } from '@teambit/legacy/dist/consumer/component/sources/artifact';
4
+ export { BuildPipe } from './build-pipe';
5
+ export type { TaskResults } from './build-pipe';
6
+ export type { ComponentResult, TaskMetadata } from './types';
7
+ export type { BuildContext, BuildTask, BuiltTaskResult, TaskLocation } from './build-task';
8
+ export { CAPSULE_ARTIFACTS_DIR } from './build-task';
9
+ export type { PipeName } from './builder.service';
10
+ export type { BuilderMain, RawBuilderData, BuilderData, OnTagOpts } from './builder.main.runtime';
11
+ export type { TaskHandler } from './pipeline';
12
+ export { Pipeline } from './pipeline';
13
+ export type { PipelineReport } from './build-pipeline-result-list';
14
+ export type { BuilderEnv } from './builder-env-type';
15
+ export type { WholeArtifactStorageResolver, FileStorageResolver, ArtifactStorageResolver } from './storage';
16
+ export type { ArtifactDefinition, ArtifactModelDefinition } from './artifact';
17
+ export { Artifact, ArtifactList, ArtifactFactory } from './artifact';
18
+ export type { Task } from './task';
19
+ export { TaskResultsList } from './task-results-list';
20
+ export { BuilderAspect, BuilderAspect as default };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/builder",
3
- "version": "1.0.107",
3
+ "version": "1.0.108",
4
4
  "homepage": "https://bit.cloud/teambit/pipelines/builder",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.pipelines",
8
8
  "name": "builder",
9
- "version": "1.0.107"
9
+ "version": "1.0.108"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -22,48 +22,44 @@
22
22
  "fs-extra": "10.0.0",
23
23
  "minimatch": "3.0.5",
24
24
  "globby": "11.0.1",
25
- "core-js": "^3.0.0",
26
- "@babel/runtime": "7.20.0",
27
25
  "@teambit/graph.cleargraph": "0.0.1",
28
26
  "@teambit/lane-id": "0.0.311",
29
27
  "@teambit/harmony": "0.4.6",
30
28
  "@teambit/bit-error": "0.0.404",
31
29
  "@teambit/component-id": "1.2.0",
32
- "@teambit/component": "1.0.107",
33
- "@teambit/envs": "1.0.107",
34
- "@teambit/logger": "0.0.932",
30
+ "@teambit/component": "1.0.108",
31
+ "@teambit/envs": "1.0.108",
32
+ "@teambit/logger": "0.0.933",
35
33
  "@teambit/toolbox.string.capitalize": "0.0.494",
36
- "@teambit/tester": "1.0.107",
37
- "@teambit/isolator": "1.0.107",
38
- "@teambit/cli": "0.0.839",
39
- "@teambit/workspace": "1.0.107",
40
- "@teambit/aspect-loader": "1.0.107",
41
- "@teambit/aspect": "1.0.107",
42
- "@teambit/generator": "1.0.108",
43
- "@teambit/global-config": "0.0.841",
44
- "@teambit/graphql": "1.0.107",
45
- "@teambit/scope": "1.0.107",
46
- "@teambit/ui": "1.0.107",
47
- "@teambit/express": "0.0.938"
34
+ "@teambit/tester": "1.0.108",
35
+ "@teambit/isolator": "1.0.108",
36
+ "@teambit/cli": "0.0.840",
37
+ "@teambit/workspace": "1.0.108",
38
+ "@teambit/aspect-loader": "1.0.108",
39
+ "@teambit/aspect": "1.0.108",
40
+ "@teambit/generator": "1.0.109",
41
+ "@teambit/global-config": "0.0.842",
42
+ "@teambit/graphql": "1.0.108",
43
+ "@teambit/scope": "1.0.108",
44
+ "@teambit/ui": "1.0.108",
45
+ "@teambit/express": "0.0.939"
48
46
  },
49
47
  "devDependencies": {
50
48
  "@types/lodash": "4.14.165",
51
- "@types/react": "^17.0.8",
52
49
  "@types/archiver": "5.3.1",
53
50
  "@types/mime": "2.0.3",
54
51
  "@types/fs-extra": "9.0.7",
55
52
  "@types/minimatch": "3.0.4",
56
53
  "@types/mocha": "9.1.0",
57
- "@types/node": "12.20.4",
58
- "@types/react-dom": "^17.0.5",
59
- "@types/jest": "^26.0.0",
60
- "@types/testing-library__jest-dom": "5.9.5",
54
+ "@types/jest": "^29.2.2",
55
+ "@types/testing-library__jest-dom": "^5.9.5",
56
+ "@teambit/harmony.envs.core-aspect-env": "0.0.13",
61
57
  "@teambit/pipelines.aspect-docs.builder": "0.0.165"
62
58
  },
63
59
  "peerDependencies": {
64
- "@teambit/legacy": "1.0.624",
65
- "react": "^16.8.0 || ^17.0.0",
66
- "react-dom": "^16.8.0 || ^17.0.0"
60
+ "react": "^17.0.0 || ^18.0.0",
61
+ "@types/react": "^18.2.12",
62
+ "@teambit/legacy": "1.0.624"
67
63
  },
68
64
  "license": "Apache-2.0",
69
65
  "optionalDependencies": {},
@@ -77,7 +73,7 @@
77
73
  },
78
74
  "private": false,
79
75
  "engines": {
80
- "node": ">=12.22.0"
76
+ "node": ">=16.0.0"
81
77
  },
82
78
  "repository": {
83
79
  "type": "git",
@@ -86,12 +82,9 @@
86
82
  "keywords": [
87
83
  "bit",
88
84
  "bit-aspect",
85
+ "bit-core-aspect",
89
86
  "components",
90
87
  "collaboration",
91
- "web",
92
- "react",
93
- "react-components",
94
- "angular",
95
- "angular-components"
88
+ "web"
96
89
  ]
97
90
  }
package/pipeline.ts ADDED
@@ -0,0 +1,104 @@
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
+ }
@@ -0,0 +1,68 @@
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 ADDED
@@ -0,0 +1,50 @@
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 ADDED
@@ -0,0 +1,40 @@
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/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }
package/types.ts ADDED
@@ -0,0 +1,37 @@
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
+ };