@teambit/builder 0.0.880 → 0.0.882

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 (74) hide show
  1. package/dist/artifact/artifact-extractor.js +6 -47
  2. package/dist/artifact/artifact-extractor.js.map +1 -1
  3. package/dist/artifact/artifact-factory.js +1 -52
  4. package/dist/artifact/artifact-factory.js.map +1 -1
  5. package/dist/artifact/artifact-list.js +6 -43
  6. package/dist/artifact/artifact-list.js.map +1 -1
  7. package/dist/artifact/artifact.js +4 -20
  8. package/dist/artifact/artifact.js.map +1 -1
  9. package/dist/artifact/artifacts.cmd.js +0 -29
  10. package/dist/artifact/artifacts.cmd.js.map +1 -1
  11. package/dist/artifact/extension-artifact.js +0 -4
  12. package/dist/artifact/extension-artifact.js.map +1 -1
  13. package/dist/artifact/fs-artifact.js +0 -6
  14. package/dist/artifact/fs-artifact.js.map +1 -1
  15. package/dist/artifact/index.js +0 -18
  16. package/dist/artifact/index.js.map +1 -1
  17. package/dist/build-pipe.js +2 -44
  18. package/dist/build-pipe.js.map +1 -1
  19. package/dist/build-pipeline-order.js +7 -44
  20. package/dist/build-pipeline-order.js.map +1 -1
  21. package/dist/build-pipeline-result-list.js +2 -35
  22. package/dist/build-pipeline-result-list.js.map +1 -1
  23. package/dist/build-task.js +1 -9
  24. package/dist/build-task.js.map +1 -1
  25. package/dist/build.cmd.js +0 -27
  26. package/dist/build.cmd.js.map +1 -1
  27. package/dist/builder.aspect.js +0 -5
  28. package/dist/builder.aspect.js.map +1 -1
  29. package/dist/builder.composition.js +0 -6
  30. package/dist/builder.composition.js.map +1 -1
  31. package/dist/builder.graphql.js +0 -19
  32. package/dist/builder.graphql.js.map +1 -1
  33. package/dist/builder.main.runtime.js +8 -137
  34. package/dist/builder.main.runtime.js.map +1 -1
  35. package/dist/builder.route.js +3 -27
  36. package/dist/builder.route.js.map +1 -1
  37. package/dist/builder.service.js +1 -37
  38. package/dist/builder.service.js.map +1 -1
  39. package/dist/exceptions/artifact-definition-no-glob.js +0 -3
  40. package/dist/exceptions/artifact-definition-no-glob.js.map +1 -1
  41. package/dist/exceptions/artifact-storage-error.js +0 -3
  42. package/dist/exceptions/artifact-storage-error.js.map +1 -1
  43. package/dist/exceptions/capsule-not-found.js +0 -3
  44. package/dist/exceptions/capsule-not-found.js.map +1 -1
  45. package/dist/exceptions/index.js +0 -9
  46. package/dist/exceptions/index.js.map +1 -1
  47. package/dist/exceptions/invalid-task.js +0 -6
  48. package/dist/exceptions/invalid-task.js.map +1 -1
  49. package/dist/index.js +0 -24
  50. package/dist/index.js.map +1 -1
  51. package/dist/pipeline/index.js +0 -3
  52. package/dist/pipeline/index.js.map +1 -1
  53. package/dist/pipeline/pipeline-results.js +0 -2
  54. package/dist/pipeline/pipeline-results.js.map +1 -1
  55. package/dist/storage/default-resolver.js +0 -9
  56. package/dist/storage/default-resolver.js.map +1 -1
  57. package/dist/storage/index.js +0 -6
  58. package/dist/storage/index.js.map +1 -1
  59. package/dist/storage/s3-resolver.js +4 -0
  60. package/dist/storage/s3-resolver.js.map +1 -1
  61. package/dist/task-results-list.js +1 -23
  62. package/dist/task-results-list.js.map +1 -1
  63. package/dist/tasks-queue.js +0 -14
  64. package/dist/tasks-queue.js.map +1 -1
  65. package/dist/templates/build-task/files/index-file.js +0 -1
  66. package/dist/templates/build-task/files/index-file.js.map +1 -1
  67. package/dist/templates/build-task/files/task-file.js +0 -1
  68. package/dist/templates/build-task/files/task-file.js.map +1 -1
  69. package/dist/templates/build-task/index.js +0 -7
  70. package/dist/templates/build-task/index.js.map +1 -1
  71. package/package-tar/teambit-builder-0.0.882.tgz +0 -0
  72. package/package.json +16 -16
  73. package/{preview-1666312873430.js → preview-1666496165706.js} +2 -2
  74. package/package-tar/teambit-builder-0.0.880.tgz +0 -0
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { ArtifactDefinition, ArtifactModelDefinition } from './artifact-definition';\nexport { ExtensionArtifact } from './extension-artifact';\nexport { Artifact } from './artifact';\nexport { ArtifactList } from './artifact-list';\nexport { ArtifactFactory, ArtifactMap } from './artifact-factory';\nexport { FsArtifact } from './fs-artifact';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { ArtifactDefinition, ArtifactModelDefinition } from './artifact-definition';\nexport { ExtensionArtifact } from './extension-artifact';\nexport { Artifact } from './artifact';\nexport { ArtifactList } from './artifact-list';\nexport { ArtifactFactory, ArtifactMap } from './artifact-factory';\nexport { FsArtifact } from './fs-artifact';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
@@ -1,68 +1,48 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.symbol.description.js");
6
-
7
5
  require("core-js/modules/es.array.iterator.js");
8
-
9
6
  require("core-js/modules/es.promise.js");
10
-
11
7
  Object.defineProperty(exports, "__esModule", {
12
8
  value: true
13
9
  });
14
10
  exports.BuildPipe = void 0;
15
-
16
11
  function _defineProperty2() {
17
12
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
-
19
13
  _defineProperty2 = function () {
20
14
  return data;
21
15
  };
22
-
23
16
  return data;
24
17
  }
25
-
26
18
  function _pMapSeries() {
27
19
  const data = _interopRequireDefault(require("p-map-series"));
28
-
29
20
  _pMapSeries = function () {
30
21
  return data;
31
22
  };
32
-
33
23
  return data;
34
24
  }
35
-
36
25
  function _prettyTime() {
37
26
  const data = _interopRequireDefault(require("pretty-time"));
38
-
39
27
  _prettyTime = function () {
40
28
  return data;
41
29
  };
42
-
43
30
  return data;
44
31
  }
45
-
46
32
  function _buildTask() {
47
33
  const data = require("./build-task");
48
-
49
34
  _buildTask = function () {
50
35
  return data;
51
36
  };
52
-
53
37
  return data;
54
38
  }
55
-
56
39
  function _taskResultsList() {
57
40
  const data = require("./task-results-list");
58
-
59
41
  _taskResultsList = function () {
60
42
  return data;
61
43
  };
62
-
63
44
  return data;
64
45
  }
65
-
66
46
  class BuildPipe {
67
47
  constructor(
68
48
  /**
@@ -79,15 +59,13 @@ class BuildPipe {
79
59
  (0, _defineProperty2().default)(this, "longProcessLogger", void 0);
80
60
  (0, _defineProperty2().default)(this, "taskResults", []);
81
61
  }
82
-
83
62
  get allTasksResults() {
84
63
  return [...(this.previousTaskResults || []), ...(this.taskResults || [])];
85
64
  }
65
+
86
66
  /**
87
67
  * execute a pipeline of build tasks.
88
68
  */
89
-
90
-
91
69
  async execute() {
92
70
  this.addSignalListener();
93
71
  await this.executePreBuild();
@@ -101,11 +79,10 @@ class BuildPipe {
101
79
  await this.executePostBuild(tasksResultsList);
102
80
  return tasksResultsList;
103
81
  }
82
+
104
83
  /**
105
84
  * for some reason, some tasks (such as typescript compilation) ignore ctrl+C. this fixes it.
106
85
  */
107
-
108
-
109
86
  addSignalListener() {
110
87
  process.on('SIGTERM', () => {
111
88
  process.exit();
@@ -114,7 +91,6 @@ class BuildPipe {
114
91
  process.exit();
115
92
  });
116
93
  }
117
-
118
94
  async executePreBuild() {
119
95
  this.logger.setStatusLine('executing pre-build for all tasks');
120
96
  await (0, _pMapSeries().default)(this.tasksQueue, async ({
@@ -126,38 +102,30 @@ class BuildPipe {
126
102
  });
127
103
  this.logger.consoleSuccess();
128
104
  }
129
-
130
105
  async executeTask(task, env) {
131
106
  const taskId = _buildTask().BuildTaskHelper.serializeId(task);
132
-
133
107
  const taskName = `${taskId}${task.description ? ` (${task.description})` : ''}`;
134
108
  this.longProcessLogger.logProgress(`env "${env.id}", task "${taskName}"`);
135
109
  this.updateFailedDependencyTask(task);
136
-
137
110
  if (this.shouldSkipTask(taskId, env.id)) {
138
111
  return;
139
112
  }
140
-
141
113
  const startTask = process.hrtime();
142
114
  const taskStartTime = Date.now();
143
115
  const buildContext = this.getBuildContext(env.id);
144
116
  let buildTaskResult;
145
-
146
117
  try {
147
118
  buildTaskResult = await task.execute(buildContext);
148
119
  } catch (err) {
149
120
  this.logger.consoleFailure(`env: ${env.id}, task "${taskId}" threw an error`);
150
121
  throw err;
151
122
  }
152
-
153
123
  const endTime = Date.now();
154
124
  const compsWithErrors = buildTaskResult.componentsResults.filter(c => {
155
125
  var _c$errors;
156
-
157
126
  return (_c$errors = c.errors) === null || _c$errors === void 0 ? void 0 : _c$errors.length;
158
127
  });
159
128
  let artifacts;
160
-
161
129
  if (compsWithErrors.length) {
162
130
  this.logger.consoleFailure(`env: ${env.id}, task "${taskId}" has failed`);
163
131
  this.failedTasks.push(task);
@@ -167,7 +135,6 @@ class BuildPipe {
167
135
  const defs = buildTaskResult.artifacts || [];
168
136
  artifacts = this.artifactFactory.generate(buildContext, defs, task);
169
137
  }
170
-
171
138
  const taskResults = {
172
139
  task,
173
140
  env,
@@ -178,7 +145,6 @@ class BuildPipe {
178
145
  };
179
146
  this.taskResults.push(taskResults);
180
147
  }
181
-
182
148
  async executePostBuild(tasksResults) {
183
149
  this.logger.setStatusLine('executing post-build for all tasks');
184
150
  await (0, _pMapSeries().default)(this.tasksQueue, async ({
@@ -190,7 +156,6 @@ class BuildPipe {
190
156
  });
191
157
  this.logger.consoleSuccess();
192
158
  }
193
-
194
159
  updateFailedDependencyTask(task) {
195
160
  if (!this.failedDependencyTask && this.failedTasks.length && task.dependencies) {
196
161
  task.dependencies.forEach(dependency => {
@@ -198,7 +163,6 @@ class BuildPipe {
198
163
  aspectId,
199
164
  name
200
165
  } = _buildTask().BuildTaskHelper.deserializeIdAllowEmptyName(dependency);
201
-
202
166
  this.failedDependencyTask = this.failedTasks.find(failedTask => {
203
167
  if (name && name !== failedTask.name) return false;
204
168
  return aspectId === failedTask.aspectId;
@@ -206,25 +170,19 @@ class BuildPipe {
206
170
  });
207
171
  }
208
172
  }
209
-
210
173
  shouldSkipTask(taskId, envId) {
211
174
  if (!this.failedDependencyTask) return false;
212
-
213
175
  const failedTaskId = _buildTask().BuildTaskHelper.serializeId(this.failedDependencyTask);
214
-
215
176
  this.logger.consoleWarning(`env: ${envId}, task "${taskId}" has skipped due to "${failedTaskId}" failure`);
216
177
  return true;
217
178
  }
218
-
219
179
  getBuildContext(envId) {
220
180
  const buildContext = this.envsBuildContext[envId];
221
181
  if (!buildContext) throw new Error(`unable to find buildContext for ${envId}`);
222
182
  buildContext.previousTasksResults = this.allTasksResults;
223
183
  return buildContext;
224
184
  }
225
-
226
185
  }
227
-
228
186
  exports.BuildPipe = BuildPipe;
229
187
 
230
188
  //# sourceMappingURL=build-pipe.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["BuildPipe","constructor","tasksQueue","envsBuildContext","logger","artifactFactory","previousTaskResults","allTasksResults","taskResults","execute","addSignalListener","executePreBuild","longProcessLogger","createLongProcessLogger","length","mapSeries","task","env","executeTask","end","tasksResultsList","TaskResultsList","executePostBuild","process","on","exit","setStatusLine","preBuild","getBuildContext","id","consoleSuccess","taskId","BuildTaskHelper","serializeId","taskName","description","logProgress","updateFailedDependencyTask","shouldSkipTask","startTask","hrtime","taskStartTime","Date","now","buildContext","buildTaskResult","err","consoleFailure","endTime","compsWithErrors","componentsResults","filter","c","errors","artifacts","failedTasks","push","duration","prettyTime","defs","generate","startTime","tasksResults","postBuild","failedDependencyTask","dependencies","forEach","dependency","aspectId","name","deserializeIdAllowEmptyName","find","failedTask","envId","failedTaskId","consoleWarning","Error","previousTasksResults"],"sources":["build-pipe.ts"],"sourcesContent":["import { EnvDefinition } from '@teambit/envs';\nimport { ComponentMap } from '@teambit/component';\nimport { Logger, LongProcessLogger } from '@teambit/logger';\nimport mapSeries from 'p-map-series';\nimport prettyTime from 'pretty-time';\nimport { ArtifactFactory, ArtifactList, FsArtifact } from './artifact';\nimport { BuildContext, BuildTask, BuildTaskHelper, BuiltTaskResult } from './build-task';\nimport { ComponentResult } from './types';\nimport { TasksQueue } from './tasks-queue';\nimport { EnvsBuildContext } from './builder.service';\nimport { TaskResultsList } from './task-results-list';\n\nexport type TaskResults = {\n /**\n * task itself. useful for getting its id/description later on.\n */\n task: BuildTask;\n\n /**\n * environment were the task was running\n */\n env: EnvDefinition;\n\n /**\n * component build results.\n */\n componentsResults: ComponentResult[];\n\n /**\n * artifacts generated by the build pipeline.\n * in case the task finished with errors, this prop is undefined.\n */\n artifacts: ComponentMap<ArtifactList<FsArtifact>> | undefined;\n\n /**\n * timestamp of start initiation.\n */\n startTime: number;\n\n /**\n * timestamp of task completion.\n */\n endTime: number;\n};\n\nexport class BuildPipe {\n private failedTasks: BuildTask[] = [];\n private failedDependencyTask: BuildTask | undefined;\n private longProcessLogger: LongProcessLogger;\n private taskResults: TaskResults[] = [];\n constructor(\n /**\n * array of services to apply on the components.\n */\n readonly tasksQueue: TasksQueue,\n readonly envsBuildContext: EnvsBuildContext,\n readonly logger: Logger,\n readonly artifactFactory: ArtifactFactory,\n private previousTaskResults?: TaskResults[]\n ) {}\n\n get allTasksResults(): TaskResults[] {\n return [...(this.previousTaskResults || []), ...(this.taskResults || [])];\n }\n\n /**\n * execute a pipeline of build tasks.\n */\n async execute(): Promise<TaskResultsList> {\n this.addSignalListener();\n await this.executePreBuild();\n this.longProcessLogger = this.logger.createLongProcessLogger('running tasks', this.tasksQueue.length);\n await mapSeries(this.tasksQueue, async ({ task, env }) => this.executeTask(task, env));\n this.longProcessLogger.end();\n const tasksResultsList = new TaskResultsList(this.tasksQueue, this.taskResults);\n await this.executePostBuild(tasksResultsList);\n\n return tasksResultsList;\n }\n\n /**\n * for some reason, some tasks (such as typescript compilation) ignore ctrl+C. this fixes it.\n */\n private addSignalListener() {\n process.on('SIGTERM', () => {\n process.exit();\n });\n\n process.on('SIGINT', () => {\n process.exit();\n });\n }\n\n private async executePreBuild() {\n this.logger.setStatusLine('executing pre-build for all tasks');\n await mapSeries(this.tasksQueue, async ({ task, env }) => {\n if (!task.preBuild) return;\n await task.preBuild(this.getBuildContext(env.id));\n });\n this.logger.consoleSuccess();\n }\n\n private async executeTask(task: BuildTask, env: EnvDefinition): Promise<void> {\n const taskId = BuildTaskHelper.serializeId(task);\n const taskName = `${taskId}${task.description ? ` (${task.description})` : ''}`;\n this.longProcessLogger.logProgress(`env \"${env.id}\", task \"${taskName}\"`);\n this.updateFailedDependencyTask(task);\n if (this.shouldSkipTask(taskId, env.id)) {\n return;\n }\n const startTask = process.hrtime();\n const taskStartTime = Date.now();\n const buildContext = this.getBuildContext(env.id);\n let buildTaskResult: BuiltTaskResult;\n try {\n buildTaskResult = await task.execute(buildContext);\n } catch (err) {\n this.logger.consoleFailure(`env: ${env.id}, task \"${taskId}\" threw an error`);\n throw err;\n }\n\n const endTime = Date.now();\n const compsWithErrors = buildTaskResult.componentsResults.filter((c) => c.errors?.length);\n let artifacts: ComponentMap<ArtifactList<FsArtifact>> | undefined;\n if (compsWithErrors.length) {\n this.logger.consoleFailure(`env: ${env.id}, task \"${taskId}\" has failed`);\n this.failedTasks.push(task);\n } else {\n const duration = prettyTime(process.hrtime(startTask));\n this.logger.consoleSuccess(`env \"${env.id}\", task \"${taskName}\" has completed successfully in ${duration}`);\n const defs = buildTaskResult.artifacts || [];\n artifacts = this.artifactFactory.generate(buildContext, defs, task);\n }\n\n const taskResults: TaskResults = {\n task,\n env,\n componentsResults: buildTaskResult.componentsResults,\n artifacts,\n startTime: taskStartTime,\n endTime,\n };\n\n this.taskResults.push(taskResults);\n }\n\n private async executePostBuild(tasksResults: TaskResultsList) {\n this.logger.setStatusLine('executing post-build for all tasks');\n await mapSeries(this.tasksQueue, async ({ task, env }) => {\n if (!task.postBuild) return;\n await task.postBuild(this.getBuildContext(env.id), tasksResults);\n });\n this.logger.consoleSuccess();\n }\n\n private updateFailedDependencyTask(task: BuildTask) {\n if (!this.failedDependencyTask && this.failedTasks.length && task.dependencies) {\n task.dependencies.forEach((dependency) => {\n const { aspectId, name } = BuildTaskHelper.deserializeIdAllowEmptyName(dependency);\n this.failedDependencyTask = this.failedTasks.find((failedTask) => {\n if (name && name !== failedTask.name) return false;\n return aspectId === failedTask.aspectId;\n });\n });\n }\n }\n\n private shouldSkipTask(taskId: string, envId: string): boolean {\n if (!this.failedDependencyTask) return false;\n const failedTaskId = BuildTaskHelper.serializeId(this.failedDependencyTask);\n this.logger.consoleWarning(`env: ${envId}, task \"${taskId}\" has skipped due to \"${failedTaskId}\" failure`);\n return true;\n }\n\n private getBuildContext(envId: string): BuildContext {\n const buildContext = this.envsBuildContext[envId];\n if (!buildContext) throw new Error(`unable to find buildContext for ${envId}`);\n buildContext.previousTasksResults = this.allTasksResults;\n return buildContext;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAmCO,MAAMA,SAAN,CAAgB;EAKrBC,WAAW;EACT;AACJ;AACA;EACaC,UAJA,EAKAC,gBALA,EAMAC,MANA,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AnD,CAAN;IACnB7B,YAAY,CAACiC,oBAAb,GAAoC,KAAKtE,eAAzC;IACA,OAAOqC,YAAP;EACD;;AAtIoB"}
1
+ {"version":3,"names":["BuildPipe","constructor","tasksQueue","envsBuildContext","logger","artifactFactory","previousTaskResults","allTasksResults","taskResults","execute","addSignalListener","executePreBuild","longProcessLogger","createLongProcessLogger","length","mapSeries","task","env","executeTask","end","tasksResultsList","TaskResultsList","executePostBuild","process","on","exit","setStatusLine","preBuild","getBuildContext","id","consoleSuccess","taskId","BuildTaskHelper","serializeId","taskName","description","logProgress","updateFailedDependencyTask","shouldSkipTask","startTask","hrtime","taskStartTime","Date","now","buildContext","buildTaskResult","err","consoleFailure","endTime","compsWithErrors","componentsResults","filter","c","errors","artifacts","failedTasks","push","duration","prettyTime","defs","generate","startTime","tasksResults","postBuild","failedDependencyTask","dependencies","forEach","dependency","aspectId","name","deserializeIdAllowEmptyName","find","failedTask","envId","failedTaskId","consoleWarning","Error","previousTasksResults"],"sources":["build-pipe.ts"],"sourcesContent":["import { EnvDefinition } from '@teambit/envs';\nimport { ComponentMap } from '@teambit/component';\nimport { Logger, LongProcessLogger } from '@teambit/logger';\nimport mapSeries from 'p-map-series';\nimport prettyTime from 'pretty-time';\nimport { ArtifactFactory, ArtifactList, FsArtifact } from './artifact';\nimport { BuildContext, BuildTask, BuildTaskHelper, BuiltTaskResult } from './build-task';\nimport { ComponentResult } from './types';\nimport { TasksQueue } from './tasks-queue';\nimport { EnvsBuildContext } from './builder.service';\nimport { TaskResultsList } from './task-results-list';\n\nexport type TaskResults = {\n /**\n * task itself. useful for getting its id/description later on.\n */\n task: BuildTask;\n\n /**\n * environment were the task was running\n */\n env: EnvDefinition;\n\n /**\n * component build results.\n */\n componentsResults: ComponentResult[];\n\n /**\n * artifacts generated by the build pipeline.\n * in case the task finished with errors, this prop is undefined.\n */\n artifacts: ComponentMap<ArtifactList<FsArtifact>> | undefined;\n\n /**\n * timestamp of start initiation.\n */\n startTime: number;\n\n /**\n * timestamp of task completion.\n */\n endTime: number;\n};\n\nexport class BuildPipe {\n private failedTasks: BuildTask[] = [];\n private failedDependencyTask: BuildTask | undefined;\n private longProcessLogger: LongProcessLogger;\n private taskResults: TaskResults[] = [];\n constructor(\n /**\n * array of services to apply on the components.\n */\n readonly tasksQueue: TasksQueue,\n readonly envsBuildContext: EnvsBuildContext,\n readonly logger: Logger,\n readonly artifactFactory: ArtifactFactory,\n private previousTaskResults?: TaskResults[]\n ) {}\n\n get allTasksResults(): TaskResults[] {\n return [...(this.previousTaskResults || []), ...(this.taskResults || [])];\n }\n\n /**\n * execute a pipeline of build tasks.\n */\n async execute(): Promise<TaskResultsList> {\n this.addSignalListener();\n await this.executePreBuild();\n this.longProcessLogger = this.logger.createLongProcessLogger('running tasks', this.tasksQueue.length);\n await mapSeries(this.tasksQueue, async ({ task, env }) => this.executeTask(task, env));\n this.longProcessLogger.end();\n const tasksResultsList = new TaskResultsList(this.tasksQueue, this.taskResults);\n await this.executePostBuild(tasksResultsList);\n\n return tasksResultsList;\n }\n\n /**\n * for some reason, some tasks (such as typescript compilation) ignore ctrl+C. this fixes it.\n */\n private addSignalListener() {\n process.on('SIGTERM', () => {\n process.exit();\n });\n\n process.on('SIGINT', () => {\n process.exit();\n });\n }\n\n private async executePreBuild() {\n this.logger.setStatusLine('executing pre-build for all tasks');\n await mapSeries(this.tasksQueue, async ({ task, env }) => {\n if (!task.preBuild) return;\n await task.preBuild(this.getBuildContext(env.id));\n });\n this.logger.consoleSuccess();\n }\n\n private async executeTask(task: BuildTask, env: EnvDefinition): Promise<void> {\n const taskId = BuildTaskHelper.serializeId(task);\n const taskName = `${taskId}${task.description ? ` (${task.description})` : ''}`;\n this.longProcessLogger.logProgress(`env \"${env.id}\", task \"${taskName}\"`);\n this.updateFailedDependencyTask(task);\n if (this.shouldSkipTask(taskId, env.id)) {\n return;\n }\n const startTask = process.hrtime();\n const taskStartTime = Date.now();\n const buildContext = this.getBuildContext(env.id);\n let buildTaskResult: BuiltTaskResult;\n try {\n buildTaskResult = await task.execute(buildContext);\n } catch (err) {\n this.logger.consoleFailure(`env: ${env.id}, task \"${taskId}\" threw an error`);\n throw err;\n }\n\n const endTime = Date.now();\n const compsWithErrors = buildTaskResult.componentsResults.filter((c) => c.errors?.length);\n let artifacts: ComponentMap<ArtifactList<FsArtifact>> | undefined;\n if (compsWithErrors.length) {\n this.logger.consoleFailure(`env: ${env.id}, task \"${taskId}\" has failed`);\n this.failedTasks.push(task);\n } else {\n const duration = prettyTime(process.hrtime(startTask));\n this.logger.consoleSuccess(`env \"${env.id}\", task \"${taskName}\" has completed successfully in ${duration}`);\n const defs = buildTaskResult.artifacts || [];\n artifacts = this.artifactFactory.generate(buildContext, defs, task);\n }\n\n const taskResults: TaskResults = {\n task,\n env,\n componentsResults: buildTaskResult.componentsResults,\n artifacts,\n startTime: taskStartTime,\n endTime,\n };\n\n this.taskResults.push(taskResults);\n }\n\n private async executePostBuild(tasksResults: TaskResultsList) {\n this.logger.setStatusLine('executing post-build for all tasks');\n await mapSeries(this.tasksQueue, async ({ task, env }) => {\n if (!task.postBuild) return;\n await task.postBuild(this.getBuildContext(env.id), tasksResults);\n });\n this.logger.consoleSuccess();\n }\n\n private updateFailedDependencyTask(task: BuildTask) {\n if (!this.failedDependencyTask && this.failedTasks.length && task.dependencies) {\n task.dependencies.forEach((dependency) => {\n const { aspectId, name } = BuildTaskHelper.deserializeIdAllowEmptyName(dependency);\n this.failedDependencyTask = this.failedTasks.find((failedTask) => {\n if (name && name !== failedTask.name) return false;\n return aspectId === failedTask.aspectId;\n });\n });\n }\n }\n\n private shouldSkipTask(taskId: string, envId: string): boolean {\n if (!this.failedDependencyTask) return false;\n const failedTaskId = BuildTaskHelper.serializeId(this.failedDependencyTask);\n this.logger.consoleWarning(`env: ${envId}, task \"${taskId}\" has skipped due to \"${failedTaskId}\" failure`);\n return true;\n }\n\n private getBuildContext(envId: string): BuildContext {\n const buildContext = this.envsBuildContext[envId];\n if (!buildContext) throw new Error(`unable to find buildContext for ${envId}`);\n buildContext.previousTasksResults = this.allTasksResults;\n return buildContext;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAmCO,MAAMA,SAAS,CAAC;EAKrBC,WAAW;EACT;AACJ;AACA;EACaC,UAAsB,EACtBC,gBAAkC,EAClCC,MAAc,EACdC,eAAgC,EACjCC,mBAAmC,EAC3C;IAAA,KALSJ,UAAsB,GAAtBA,UAAsB;IAAA,KACtBC,gBAAkC,GAAlCA,gBAAkC;IAAA,KAClCC,MAAc,GAAdA,MAAc;IAAA,KACdC,eAAgC,GAAhCA,eAAgC;IAAA,KACjCC,mBAAmC,GAAnCA,mBAAmC;IAAA,qDAZV,EAAE;IAAA;IAAA;IAAA,qDAGA,EAAE;EAUpC;EAEH,IAAIC,eAAe,GAAkB;IACnC,OAAO,CAAC,IAAI,IAAI,CAACD,mBAAmB,IAAI,EAAE,CAAC,EAAE,IAAI,IAAI,CAACE,WAAW,IAAI,EAAE,CAAC,CAAC;EAC3E;;EAEA;AACF;AACA;EACE,MAAMC,OAAO,GAA6B;IACxC,IAAI,CAACC,iBAAiB,EAAE;IACxB,MAAM,IAAI,CAACC,eAAe,EAAE;IAC5B,IAAI,CAACC,iBAAiB,GAAG,IAAI,CAACR,MAAM,CAACS,uBAAuB,CAAC,eAAe,EAAE,IAAI,CAACX,UAAU,CAACY,MAAM,CAAC;IACrG,MAAM,IAAAC,qBAAS,EAAC,IAAI,CAACb,UAAU,EAAE,OAAO;MAAEc,IAAI;MAAEC;IAAI,CAAC,KAAK,IAAI,CAACC,WAAW,CAACF,IAAI,EAAEC,GAAG,CAAC,CAAC;IACtF,IAAI,CAACL,iBAAiB,CAACO,GAAG,EAAE;IAC5B,M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CAAC;MACJ,CAAC,CAAC;IACJ;EACF;EAEQ9B,cAAc,CAACP,MAAc,EAAE0C,KAAa,EAAW;IAC7D,IAAI,CAAC,IAAI,CAACT,oBAAoB,EAAE,OAAO,KAAK;IAC5C,MAAMU,YAAY,GAAG1C,4BAAe,CAACC,WAAW,CAAC,IAAI,CAAC+B,oBAAoB,CAAC;IAC3E,IAAI,CAAC5D,MAAM,CAACuE,cAAc,CAAE,QAAOF,KAAM,WAAU1C,MAAO,yBAAwB2C,YAAa,WAAU,CAAC;IAC1G,OAAO,IAAI;EACb;EAEQ9C,eAAe,CAAC6C,KAAa,EAAgB;IACnD,MAAM7B,YAAY,GAAG,IAAI,CAACzC,gBAAgB,CAACsE,KAAK,CAAC;IACjD,IAAI,CAAC7B,YAAY,EAAE,MAAM,IAAIgC,KAAK,CAAE,mCAAkCH,KAAM,EAAC,CAAC;IAC9E7B,YAAY,CAACiC,oBAAoB,GAAG,IAAI,CAACtE,eAAe;IACxD,OAAOqC,YAAY;EACrB;AACF;AAAC"}
@@ -1,58 +1,41 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.array.flat.js");
6
-
7
5
  require("core-js/modules/es.array.iterator.js");
8
-
9
6
  require("core-js/modules/es.array.unscopables.flat.js");
10
-
11
7
  Object.defineProperty(exports, "__esModule", {
12
8
  value: true
13
9
  });
14
10
  exports.calculatePipelineOrder = calculatePipelineOrder;
15
-
16
11
  function _graph() {
17
12
  const data = require("@teambit/graph.cleargraph");
18
-
19
13
  _graph = function () {
20
14
  return data;
21
15
  };
22
-
23
16
  return data;
24
17
  }
25
-
26
18
  function _tester() {
27
19
  const data = _interopRequireDefault(require("@teambit/tester"));
28
-
29
20
  _tester = function () {
30
21
  return data;
31
22
  };
32
-
33
23
  return data;
34
24
  }
35
-
36
25
  function _buildTask() {
37
26
  const data = require("./build-task");
38
-
39
27
  _buildTask = function () {
40
28
  return data;
41
29
  };
42
-
43
30
  return data;
44
31
  }
45
-
46
32
  function _tasksQueue() {
47
33
  const data = require("./tasks-queue");
48
-
49
34
  _tasksQueue = function () {
50
35
  return data;
51
36
  };
52
-
53
37
  return data;
54
38
  }
55
-
56
39
  /**
57
40
  * there are two ways how to add tasks to build pipeline.
58
41
  * 1. `getBuildPipe()` method of the env.
@@ -86,7 +69,6 @@ function _tasksQueue() {
86
69
  function calculatePipelineOrder(taskSlot, envs, pipeNameOnEnv = 'getBuildPipe', tasks = [], skipTests = false) {
87
70
  const graphs = [];
88
71
  const locations = ['start', 'middle', 'end']; // the order is important here!
89
-
90
72
  locations.forEach(location => {
91
73
  graphs.push({
92
74
  location,
@@ -124,22 +106,18 @@ function calculatePipelineOrder(taskSlot, envs, pipeNameOnEnv = 'getBuildPipe',
124
106
  });
125
107
  const tasksQueue = new (_tasksQueue().TasksQueue)();
126
108
  locations.forEach(location => addTasksToGraph(tasksQueue, dataPerLocation, location));
127
-
128
109
  if (tasks.length) {
129
110
  return new (_tasksQueue().TasksQueue)(...tasksQueue.filter(({
130
111
  task
131
112
  }) => tasks.includes(task.name) || tasks.includes(task.aspectId)));
132
113
  }
133
-
134
114
  if (skipTests) {
135
115
  return new (_tasksQueue().TasksQueue)(...tasksQueue.filter(({
136
116
  task
137
117
  }) => task.aspectId !== _tester().default.id));
138
118
  }
139
-
140
119
  return tasksQueue;
141
120
  }
142
-
143
121
  function addTasksToGraph(tasksQueue, dataPerLocation, location) {
144
122
  const data = dataPerLocation.find(d => d.location === location);
145
123
  if (!data) return;
@@ -149,7 +127,6 @@ function addTasksToGraph(tasksQueue, dataPerLocation, location) {
149
127
  aspectId,
150
128
  name
151
129
  } = _buildTask().BuildTaskHelper.deserializeId(taskNode.attr);
152
-
153
130
  data.pipelineEnvs.forEach(({
154
131
  env,
155
132
  pipeline
@@ -164,6 +141,7 @@ function addTasksToGraph(tasksQueue, dataPerLocation, location) {
164
141
  pipeline.splice(taskIndex, 1); // delete the task from the pipeline
165
142
  });
166
143
  });
144
+
167
145
  data.pipelineEnvs.forEach(({
168
146
  env,
169
147
  pipeline
@@ -174,40 +152,30 @@ function addTasksToGraph(tasksQueue, dataPerLocation, location) {
174
152
  }));
175
153
  });
176
154
  }
177
-
178
155
  function addDependenciesToGraph(graphs, pipeline, task) {
179
156
  if (!task.dependencies || !task.dependencies.length) return;
180
-
181
157
  const taskId = _buildTask().BuildTaskHelper.serializeId(task);
182
-
183
158
  task.dependencies.forEach(dependency => {
184
159
  const {
185
160
  aspectId,
186
161
  name
187
162
  } = _buildTask().BuildTaskHelper.deserializeIdAllowEmptyName(dependency);
188
-
189
163
  const dependencyTasks = pipeline.filter(pipelineTask => {
190
164
  if (pipelineTask.aspectId !== aspectId) return false;
191
165
  return name ? name === pipelineTask.name : true;
192
166
  });
193
-
194
167
  if (dependencyTasks.length === 0) {
195
168
  throw new Error(`unable to find dependency "${dependency}" of "${_buildTask().BuildTaskHelper.serializeId(task)}" in the pipeline`);
196
169
  }
197
-
198
170
  dependencyTasks.forEach(dependencyTask => {
199
171
  const location = getLocation(task, dependencyTask);
200
-
201
172
  if (!location) {
202
173
  // the dependency is behind and will be in the correct order regardless the graph.
203
174
  return;
204
175
  }
205
-
206
176
  const graphLocation = graphs.find(g => g.location === location);
207
177
  if (!graphLocation) throw new Error(`unable to find graph for location ${location}`);
208
-
209
178
  const dependencyId = _buildTask().BuildTaskHelper.serializeId(dependencyTask);
210
-
211
179
  const graph = graphLocation.graph;
212
180
  graph.setNode(new (_graph().Node)(taskId, taskId));
213
181
  graph.setNode(new (_graph().Node)(dependencyId, dependencyId));
@@ -215,6 +183,7 @@ function addDependenciesToGraph(graphs, pipeline, task) {
215
183
  });
216
184
  });
217
185
  }
186
+
218
187
  /**
219
188
  * since the task execution is happening per group: "start", "middle" and "end", the dependencies
220
189
  * need to be inside the same group.
@@ -223,29 +192,24 @@ function addDependenciesToGraph(graphs, pipeline, task) {
223
192
  * it's ok to have the dependency located earlier, e.g. "start" and the task at "end", and in this
224
193
  * case, it will not be part of the graph because there is no need to do any special calculation.
225
194
  */
226
-
227
-
228
195
  function getLocation(task, dependencyTask) {
229
196
  const taskLocation = task.location || 'middle';
230
197
  const dependencyLocation = dependencyTask.location || 'middle';
231
198
  const isDependencyAhead = taskLocation === 'start' && dependencyLocation !== 'start' || taskLocation === 'middle' && dependencyLocation === 'end';
232
199
  const isDependencyEqual = taskLocation === dependencyLocation;
233
-
234
200
  if (isDependencyAhead) {
235
201
  throw new Error(`a task "${_buildTask().BuildTaskHelper.serializeId(task)}" located at ${taskLocation}
236
202
  has a dependency "${_buildTask().BuildTaskHelper.serializeId(dependencyTask)} located at ${dependencyLocation},
237
203
  which is invalid. the dependency must be located earlier or in the same location as the task"`);
238
204
  }
239
-
240
205
  if (isDependencyEqual) {
241
206
  return taskLocation;
242
- } // dependency is behind. e.g. task is "end" and dependency is "start". no need to enter to the
243
- // graph as it's going to be executed in the right order regardless the graph.
244
-
207
+ }
245
208
 
209
+ // dependency is behind. e.g. task is "end" and dependency is "start". no need to enter to the
210
+ // graph as it's going to be executed in the right order regardless the graph.
246
211
  return null;
247
212
  }
248
-
249
213
  function getPipelineForEnv(taskSlot, env, pipeNameOnEnv) {
250
214
  const buildTasks = env[pipeNameOnEnv] ? env[pipeNameOnEnv]() : [];
251
215
  const slotsTasks = taskSlot.values().flat();
@@ -256,15 +220,14 @@ function getPipelineForEnv(taskSlot, env, pipeNameOnEnv) {
256
220
  tasksAtStart.push(task);
257
221
  return;
258
222
  }
259
-
260
223
  if (task.location === 'end') {
261
224
  tasksAtEnd.push(task);
262
225
  return;
263
226
  }
264
-
265
227
  tasksAtStart.push(task);
266
- }); // merge with extension registered tasks.
228
+ });
267
229
 
230
+ // merge with extension registered tasks.
268
231
  const mergedTasks = [...tasksAtStart, ...buildTasks, ...tasksAtEnd];
269
232
  return mergedTasks;
270
233
  }
@@ -1 +1 @@
1
- {"version":3,"names":["calculatePipelineOrder","taskSlot","envs","pipeNameOnEnv","tasks","skipTests","graphs","locations","forEach","location","push","graph","Graph","pipelineEnvs","envDefinition","pipeline","getPipelineForEnv","env","flattenedPipeline","map","pipelineEnv","flat","task","addDependenciesToGraph","dataPerLocation","pipelineEnvsPerLocation","filter","tasksQueue","TasksQueue","addTasksToGraph","length","includes","name","aspectId","TesterAspect","id","data","find","d","sorted","toposort","taskNode","BuildTaskHelper","deserializeId","attr","taskIndex","findIndex","pipelineTask","splice","dependencies","taskId","serializeId","dependency","deserializeIdAllowEmptyName","dependencyTasks","Error","dependencyTask","getLocation","graphLocation","g","dependencyId","setNode","Node","setEdge","Edge","taskLocation","dependencyLocation","isDependencyAhead","isDependencyEqual","buildTasks","slotsTasks","values","tasksAtStart","tasksAtEnd","mergedTasks"],"sources":["build-pipeline-order.ts"],"sourcesContent":["import { Graph, Node, Edge } from '@teambit/graph.cleargraph';\nimport TesterAspect from '@teambit/tester';\nimport { EnvDefinition, Environment } from '@teambit/envs';\nimport { BuildTask, BuildTaskHelper } from './build-task';\nimport type { TaskSlot } from './builder.main.runtime';\nimport { TasksQueue } from './tasks-queue';\n\ntype TaskDependenciesGraph = Graph<string, string>;\ntype Location = 'start' | 'middle' | 'end';\ntype TasksLocationGraph = { location: Location; graph: TaskDependenciesGraph };\ntype PipelineEnv = { env: EnvDefinition; pipeline: BuildTask[] };\ntype DataPerLocation = { location: Location; graph: TaskDependenciesGraph; pipelineEnvs: PipelineEnv[] };\n\n/**\n * there are two ways how to add tasks to build pipeline.\n * 1. `getBuildPipe()` method of the env.\n * 2. registering to the `builder.registerBuildTask()`.\n *\n * in the option #1, it's possible to determine the order. e.g. `getBuildPipe() { return [taskA, taskB, taskC]; }`\n * in the option #2, the register happens once the extension is loaded, so there is no way to put\n * one task before/after another task.\n *\n * To be able to determine the order, you can do the following\n * 1. \"task.location\", it has two options \"start\" and \"end\". the rest are \"middle\".\n * 2. \"task.dependencies\", the dependencies must be completed for all envs before this task starts.\n * the dependencies are applicable inside a location and not across locations. see getLocation()\n * or/and continue reading for more info about this.\n *\n * to determine the final order of the tasks, the following is done:\n * 1. split all tasks to three groups: start, middle and end.\n * 2. for each group define a dependencies graph for the tasks with \"dependencies\" prop and the pipeline.\n * 3. start with the first group \"start\", toposort the dependencies graph and push the found tasks\n * to a queue. once completed, iterate the pipeline and add all tasks to the queue.\n * 4. do the same for the \"middle\" and \"end\" groups.\n *\n * the reason for splitting the tasks to the three groups and not using the \"dependencies\" field\n * alone to determine the order is that the \"start\" and \"end\" groups are mostly core and \"middle\"\n * is mostly the user entering tasks to the pipeline and we as the core don't know about the users\n * tasks. For example, a core task \"PublishComponent\" must happen after the compiler, however, a\n * user might have an env without a compiler. if we determine the order only by the dependencies\n * field, the \"PublishComponent\" would have a dependency \"compiler\" and because in this case there\n * is no compiler task, it would throw an error about missing dependencies.\n */\nexport function calculatePipelineOrder(\n taskSlot: TaskSlot,\n envs: EnvDefinition[],\n pipeNameOnEnv = 'getBuildPipe',\n tasks: string[] = [],\n skipTests = false\n): TasksQueue {\n const graphs: TasksLocationGraph[] = [];\n const locations: Location[] = ['start', 'middle', 'end']; // the order is important here!\n locations.forEach((location) => {\n graphs.push({ location, graph: new Graph<string, string>() });\n });\n const pipelineEnvs: PipelineEnv[] = [];\n envs.forEach((envDefinition) => {\n const pipeline = getPipelineForEnv(taskSlot, envDefinition.env, pipeNameOnEnv);\n pipelineEnvs.push({ env: envDefinition, pipeline });\n });\n\n const flattenedPipeline: BuildTask[] = pipelineEnvs.map((pipelineEnv) => pipelineEnv.pipeline).flat();\n flattenedPipeline.forEach((task) => addDependenciesToGraph(graphs, flattenedPipeline, task));\n\n const dataPerLocation: DataPerLocation[] = graphs.map(({ location, graph }) => {\n const pipelineEnvsPerLocation: PipelineEnv[] = pipelineEnvs.map(({ env, pipeline }) => {\n return { env, pipeline: pipeline.filter((task) => (task.location || 'middle') === location) };\n });\n return { location, graph, pipelineEnvs: pipelineEnvsPerLocation };\n });\n\n const tasksQueue = new TasksQueue();\n locations.forEach((location) => addTasksToGraph(tasksQueue, dataPerLocation, location));\n if (tasks.length) {\n return new TasksQueue(\n ...tasksQueue.filter(({ task }) => tasks.includes(task.name) || tasks.includes(task.aspectId))\n );\n }\n if (skipTests) {\n return new TasksQueue(...tasksQueue.filter(({ task }) => task.aspectId !== TesterAspect.id));\n }\n return tasksQueue;\n}\n\nfunction addTasksToGraph(tasksQueue: TasksQueue, dataPerLocation: DataPerLocation[], location: Location) {\n const data = dataPerLocation.find((d) => d.location === location);\n if (!data) return;\n const sorted = data.graph.toposort();\n sorted.forEach((taskNode) => {\n const { aspectId, name } = BuildTaskHelper.deserializeId(taskNode.attr);\n data.pipelineEnvs.forEach(({ env, pipeline }) => {\n const taskIndex = pipeline.findIndex(\n (pipelineTask) => pipelineTask.aspectId === aspectId && pipelineTask.name === name\n );\n if (taskIndex < 0) return;\n const task = pipeline[taskIndex];\n tasksQueue.push({ env, task });\n pipeline.splice(taskIndex, 1); // delete the task from the pipeline\n });\n });\n data.pipelineEnvs.forEach(({ env, pipeline }) => {\n pipeline.forEach((task) => tasksQueue.push({ env, task }));\n });\n}\n\nfunction addDependenciesToGraph(graphs: TasksLocationGraph[], pipeline: BuildTask[], task: BuildTask) {\n if (!task.dependencies || !task.dependencies.length) return;\n const taskId = BuildTaskHelper.serializeId(task);\n task.dependencies.forEach((dependency) => {\n const { aspectId, name } = BuildTaskHelper.deserializeIdAllowEmptyName(dependency);\n const dependencyTasks = pipeline.filter((pipelineTask) => {\n if (pipelineTask.aspectId !== aspectId) return false;\n return name ? name === pipelineTask.name : true;\n });\n if (dependencyTasks.length === 0) {\n throw new Error(\n `unable to find dependency \"${dependency}\" of \"${BuildTaskHelper.serializeId(task)}\" in the pipeline`\n );\n }\n dependencyTasks.forEach((dependencyTask) => {\n const location = getLocation(task, dependencyTask);\n if (!location) {\n // the dependency is behind and will be in the correct order regardless the graph.\n return;\n }\n const graphLocation = graphs.find((g) => g.location === location);\n if (!graphLocation) throw new Error(`unable to find graph for location ${location}`);\n const dependencyId = BuildTaskHelper.serializeId(dependencyTask);\n const graph = graphLocation.graph;\n graph.setNode(new Node(taskId, taskId));\n graph.setNode(new Node(dependencyId, dependencyId));\n graph.setEdge(new Edge(dependencyId, taskId, 'dependency'));\n });\n });\n}\n\n/**\n * since the task execution is happening per group: \"start\", \"middle\" and \"end\", the dependencies\n * need to be inside the same group.\n * e.g. if a dependency located at \"end\" group and the task located at \"start\", it's impossible to\n * complete the dependency before the task, there it throws an error.\n * it's ok to have the dependency located earlier, e.g. \"start\" and the task at \"end\", and in this\n * case, it will not be part of the graph because there is no need to do any special calculation.\n */\nfunction getLocation(task: BuildTask, dependencyTask: BuildTask): Location | null {\n const taskLocation = task.location || 'middle';\n const dependencyLocation = dependencyTask.location || 'middle';\n\n const isDependencyAhead =\n (taskLocation === 'start' && dependencyLocation !== 'start') ||\n (taskLocation === 'middle' && dependencyLocation === 'end');\n\n const isDependencyEqual = taskLocation === dependencyLocation;\n\n if (isDependencyAhead) {\n throw new Error(`a task \"${BuildTaskHelper.serializeId(task)}\" located at ${taskLocation}\nhas a dependency \"${BuildTaskHelper.serializeId(dependencyTask)} located at ${dependencyLocation},\nwhich is invalid. the dependency must be located earlier or in the same location as the task\"`);\n }\n\n if (isDependencyEqual) {\n return taskLocation;\n }\n\n // dependency is behind. e.g. task is \"end\" and dependency is \"start\". no need to enter to the\n // graph as it's going to be executed in the right order regardless the graph.\n return null;\n}\n\nfunction getPipelineForEnv(taskSlot: TaskSlot, env: Environment, pipeNameOnEnv: string): BuildTask[] {\n const buildTasks: BuildTask[] = env[pipeNameOnEnv] ? env[pipeNameOnEnv]() : [];\n const slotsTasks = taskSlot.values().flat();\n const tasksAtStart: BuildTask[] = [];\n const tasksAtEnd: BuildTask[] = [];\n slotsTasks.forEach((task) => {\n if (task.location === 'start') {\n tasksAtStart.push(task);\n return;\n }\n if (task.location === 'end') {\n tasksAtEnd.push(task);\n return;\n }\n tasksAtStart.push(task);\n });\n\n // merge with extension registered tasks.\n const mergedTasks = [...tasksAtStart, ...buildT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AAlC;EACA,MAAMC,UAAuB,GAAG,EAAhC;EACAH,UAAU,CAAC9D,OAAX,CAAoBc,IAAD,IAAU;IAC3B,IAAIA,IAAI,CAACb,QAAL,KAAkB,OAAtB,EAA+B;MAC7B+D,YAAY,CAAC9D,IAAb,CAAkBY,IAAlB;MACA;IACD;;IACD,IAAIA,IAAI,CAACb,QAAL,KAAkB,KAAtB,EAA6B;MAC3BgE,UAAU,CAAC/D,IAAX,CAAgBY,IAAhB;MACA;IACD;;IACDkD,YAAY,CAAC9D,IAAb,CAAkBY,IAAlB;EACD,CAVD,EALmG,CAiBnG;;EACA,MAAMoD,WAAW,GAAG,CAAC,GAAGF,YAAJ,EAAkB,GAAGH,UAArB,EAAiC,GAAGI,UAApC,CAApB;EAEA,OAAOC,WAAP;AACD"}
1
+ {"version":3,"names":["calculatePipelineOrder","taskSlot","envs","pipeNameOnEnv","tasks","skipTests","graphs","locations","forEach","location","push","graph","Graph","pipelineEnvs","envDefinition","pipeline","getPipelineForEnv","env","flattenedPipeline","map","pipelineEnv","flat","task","addDependenciesToGraph","dataPerLocation","pipelineEnvsPerLocation","filter","tasksQueue","TasksQueue","addTasksToGraph","length","includes","name","aspectId","TesterAspect","id","data","find","d","sorted","toposort","taskNode","BuildTaskHelper","deserializeId","attr","taskIndex","findIndex","pipelineTask","splice","dependencies","taskId","serializeId","dependency","deserializeIdAllowEmptyName","dependencyTasks","Error","dependencyTask","getLocation","graphLocation","g","dependencyId","setNode","Node","setEdge","Edge","taskLocation","dependencyLocation","isDependencyAhead","isDependencyEqual","buildTasks","slotsTasks","values","tasksAtStart","tasksAtEnd","mergedTasks"],"sources":["build-pipeline-order.ts"],"sourcesContent":["import { Graph, Node, Edge } from '@teambit/graph.cleargraph';\nimport TesterAspect from '@teambit/tester';\nimport { EnvDefinition, Environment } from '@teambit/envs';\nimport { BuildTask, BuildTaskHelper } from './build-task';\nimport type { TaskSlot } from './builder.main.runtime';\nimport { TasksQueue } from './tasks-queue';\n\ntype TaskDependenciesGraph = Graph<string, string>;\ntype Location = 'start' | 'middle' | 'end';\ntype TasksLocationGraph = { location: Location; graph: TaskDependenciesGraph };\ntype PipelineEnv = { env: EnvDefinition; pipeline: BuildTask[] };\ntype DataPerLocation = { location: Location; graph: TaskDependenciesGraph; pipelineEnvs: PipelineEnv[] };\n\n/**\n * there are two ways how to add tasks to build pipeline.\n * 1. `getBuildPipe()` method of the env.\n * 2. registering to the `builder.registerBuildTask()`.\n *\n * in the option #1, it's possible to determine the order. e.g. `getBuildPipe() { return [taskA, taskB, taskC]; }`\n * in the option #2, the register happens once the extension is loaded, so there is no way to put\n * one task before/after another task.\n *\n * To be able to determine the order, you can do the following\n * 1. \"task.location\", it has two options \"start\" and \"end\". the rest are \"middle\".\n * 2. \"task.dependencies\", the dependencies must be completed for all envs before this task starts.\n * the dependencies are applicable inside a location and not across locations. see getLocation()\n * or/and continue reading for more info about this.\n *\n * to determine the final order of the tasks, the following is done:\n * 1. split all tasks to three groups: start, middle and end.\n * 2. for each group define a dependencies graph for the tasks with \"dependencies\" prop and the pipeline.\n * 3. start with the first group \"start\", toposort the dependencies graph and push the found tasks\n * to a queue. once completed, iterate the pipeline and add all tasks to the queue.\n * 4. do the same for the \"middle\" and \"end\" groups.\n *\n * the reason for splitting the tasks to the three groups and not using the \"dependencies\" field\n * alone to determine the order is that the \"start\" and \"end\" groups are mostly core and \"middle\"\n * is mostly the user entering tasks to the pipeline and we as the core don't know about the users\n * tasks. For example, a core task \"PublishComponent\" must happen after the compiler, however, a\n * user might have an env without a compiler. if we determine the order only by the dependencies\n * field, the \"PublishComponent\" would have a dependency \"compiler\" and because in this case there\n * is no compiler task, it would throw an error about missing dependencies.\n */\nexport function calculatePipelineOrder(\n taskSlot: TaskSlot,\n envs: EnvDefinition[],\n pipeNameOnEnv = 'getBuildPipe',\n tasks: string[] = [],\n skipTests = false\n): TasksQueue {\n const graphs: TasksLocationGraph[] = [];\n const locations: Location[] = ['start', 'middle', 'end']; // the order is important here!\n locations.forEach((location) => {\n graphs.push({ location, graph: new Graph<string, string>() });\n });\n const pipelineEnvs: PipelineEnv[] = [];\n envs.forEach((envDefinition) => {\n const pipeline = getPipelineForEnv(taskSlot, envDefinition.env, pipeNameOnEnv);\n pipelineEnvs.push({ env: envDefinition, pipeline });\n });\n\n const flattenedPipeline: BuildTask[] = pipelineEnvs.map((pipelineEnv) => pipelineEnv.pipeline).flat();\n flattenedPipeline.forEach((task) => addDependenciesToGraph(graphs, flattenedPipeline, task));\n\n const dataPerLocation: DataPerLocation[] = graphs.map(({ location, graph }) => {\n const pipelineEnvsPerLocation: PipelineEnv[] = pipelineEnvs.map(({ env, pipeline }) => {\n return { env, pipeline: pipeline.filter((task) => (task.location || 'middle') === location) };\n });\n return { location, graph, pipelineEnvs: pipelineEnvsPerLocation };\n });\n\n const tasksQueue = new TasksQueue();\n locations.forEach((location) => addTasksToGraph(tasksQueue, dataPerLocation, location));\n if (tasks.length) {\n return new TasksQueue(\n ...tasksQueue.filter(({ task }) => tasks.includes(task.name) || tasks.includes(task.aspectId))\n );\n }\n if (skipTests) {\n return new TasksQueue(...tasksQueue.filter(({ task }) => task.aspectId !== TesterAspect.id));\n }\n return tasksQueue;\n}\n\nfunction addTasksToGraph(tasksQueue: TasksQueue, dataPerLocation: DataPerLocation[], location: Location) {\n const data = dataPerLocation.find((d) => d.location === location);\n if (!data) return;\n const sorted = data.graph.toposort();\n sorted.forEach((taskNode) => {\n const { aspectId, name } = BuildTaskHelper.deserializeId(taskNode.attr);\n data.pipelineEnvs.forEach(({ env, pipeline }) => {\n const taskIndex = pipeline.findIndex(\n (pipelineTask) => pipelineTask.aspectId === aspectId && pipelineTask.name === name\n );\n if (taskIndex < 0) return;\n const task = pipeline[taskIndex];\n tasksQueue.push({ env, task });\n pipeline.splice(taskIndex, 1); // delete the task from the pipeline\n });\n });\n data.pipelineEnvs.forEach(({ env, pipeline }) => {\n pipeline.forEach((task) => tasksQueue.push({ env, task }));\n });\n}\n\nfunction addDependenciesToGraph(graphs: TasksLocationGraph[], pipeline: BuildTask[], task: BuildTask) {\n if (!task.dependencies || !task.dependencies.length) return;\n const taskId = BuildTaskHelper.serializeId(task);\n task.dependencies.forEach((dependency) => {\n const { aspectId, name } = BuildTaskHelper.deserializeIdAllowEmptyName(dependency);\n const dependencyTasks = pipeline.filter((pipelineTask) => {\n if (pipelineTask.aspectId !== aspectId) return false;\n return name ? name === pipelineTask.name : true;\n });\n if (dependencyTasks.length === 0) {\n throw new Error(\n `unable to find dependency \"${dependency}\" of \"${BuildTaskHelper.serializeId(task)}\" in the pipeline`\n );\n }\n dependencyTasks.forEach((dependencyTask) => {\n const location = getLocation(task, dependencyTask);\n if (!location) {\n // the dependency is behind and will be in the correct order regardless the graph.\n return;\n }\n const graphLocation = graphs.find((g) => g.location === location);\n if (!graphLocation) throw new Error(`unable to find graph for location ${location}`);\n const dependencyId = BuildTaskHelper.serializeId(dependencyTask);\n const graph = graphLocation.graph;\n graph.setNode(new Node(taskId, taskId));\n graph.setNode(new Node(dependencyId, dependencyId));\n graph.setEdge(new Edge(dependencyId, taskId, 'dependency'));\n });\n });\n}\n\n/**\n * since the task execution is happening per group: \"start\", \"middle\" and \"end\", the dependencies\n * need to be inside the same group.\n * e.g. if a dependency located at \"end\" group and the task located at \"start\", it's impossible to\n * complete the dependency before the task, there it throws an error.\n * it's ok to have the dependency located earlier, e.g. \"start\" and the task at \"end\", and in this\n * case, it will not be part of the graph because there is no need to do any special calculation.\n */\nfunction getLocation(task: BuildTask, dependencyTask: BuildTask): Location | null {\n const taskLocation = task.location || 'middle';\n const dependencyLocation = dependencyTask.location || 'middle';\n\n const isDependencyAhead =\n (taskLocation === 'start' && dependencyLocation !== 'start') ||\n (taskLocation === 'middle' && dependencyLocation === 'end');\n\n const isDependencyEqual = taskLocation === dependencyLocation;\n\n if (isDependencyAhead) {\n throw new Error(`a task \"${BuildTaskHelper.serializeId(task)}\" located at ${taskLocation}\nhas a dependency \"${BuildTaskHelper.serializeId(dependencyTask)} located at ${dependencyLocation},\nwhich is invalid. the dependency must be located earlier or in the same location as the task\"`);\n }\n\n if (isDependencyEqual) {\n return taskLocation;\n }\n\n // dependency is behind. e.g. task is \"end\" and dependency is \"start\". no need to enter to the\n // graph as it's going to be executed in the right order regardless the graph.\n return null;\n}\n\nfunction getPipelineForEnv(taskSlot: TaskSlot, env: Environment, pipeNameOnEnv: string): BuildTask[] {\n const buildTasks: BuildTask[] = env[pipeNameOnEnv] ? env[pipeNameOnEnv]() : [];\n const slotsTasks = taskSlot.values().flat();\n const tasksAtStart: BuildTask[] = [];\n const tasksAtEnd: BuildTask[] = [];\n slotsTasks.forEach((task) => {\n if (task.location === 'start') {\n tasksAtStart.push(task);\n return;\n }\n if (task.location === 'end') {\n tasksAtEnd.push(task);\n return;\n }\n tasksAtStart.push(task);\n });\n\n // merge with extension registered tasks.\n const mergedTasks = [...tasksAtStart, ...buildTasks, ...tasksAtEnd];\n\n return mergedTasks;\n}\n"],"mappings":";;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,sBAAsB,CACpCC,QAAkB,EAClBC,IAAqB,EACrBC,aAAa,GAAG,cAAc,EAC9BC,KAAe,GAAG,EAAE,EACpBC,SAAS,GAAG,KAAK,EACL;EACZ,MAAMC,MAA4B,GAAG,EAAE;EACvC,MAAMC,SAAqB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;EAC1DA,SAAS,CAACC,OAAO,CAAEC,QAAQ,IAAK;IAC9BH,MAAM,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