@teambit/builder 1.0.108 → 1.0.110
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-1703733956734.js} +2 -2
- package/package.json +26 -22
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["teambit.pipelines/builder-preview"]=n():e["teambit.pipelines/builder-preview"]=n()}(self,(()=>(()=>{"use strict";var e={51221:(e,n,t)=>{var i={id:"teambit.pipelines/builder@1.0.110",homepage:"https://bit.cloud/teambit/pipelines/builder",exported:!0};function a(){const e=r(t(87363));return a=function(){return e},e}function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.Logo=void 0,a.__bit_component=i,r.__bit_component=i;const o=()=>a().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},a().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/builder.svg"}));o.__bit_component=i,n.Logo=o},86991:(e,n,t)=>{var i={id:"teambit.pipelines/aspect-docs/builder@0.0.165",homepage:"https://bit.cloud/teambit/pipelines/aspect-docs/builder",exported:!0};Object.defineProperty(n,"__esModule",{value:!0}),n.default=u,o(t(87363));var a=t(40040),r=["components"];function o(e){return e&&e.__esModule?e:{default:e}}function s(){return s=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},s.apply(this,arguments)}function l(e,n){if(null==e)return{};var t,i,a=d(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(i=0;i<r.length;i++)t=r[i],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}function d(e,n){if(null==e)return{};var t,i,a={},r=Object.keys(e);for(i=0;i<r.length;i++)t=r[i],n.indexOf(t)>=0||(a[t]=e[t]);return a}o.__bit_component=i,s.__bit_component=i,l.__bit_component=i,d.__bit_component=i;var p={},m="wrapper";function u(e){var n=e.components,t=l(e,r);return(0,a.mdx)(m,s({},p,t,{components:n,mdxType:"MDXLayout"}),(0,a.mdx)("h2",null,"Background"),(0,a.mdx)("p",null,"Bit's build process is an extensible CI for independent components. It validates a component is not dependent on its context (the workspace), tests it, and generates all artifacts necessary for it to be viewed and consumed as an independent module (its distributable code, bundled preview, etc.)."),(0,a.mdx)("p",null,"The Build Pipeline is an Environment Service responsible for sequencing and executing a component's Build Tasks. As mentioned earlier, these tasks are performed on a component only after it's been isolated from the rest of the workspace."),(0,a.mdx)("p",null,"A component's default series of Build Tasks is composed of tasks set by Bit and by its environment."),(0,a.mdx)("h2",null,"Isolated builds"),(0,a.mdx)("p",null,"Components authored in a Bit workspace are created to be completely portable, and thus independent. To address that, the build process starts by creating a component 'capsule' which is an isolated instance of a component, generated in a separate directory in your filesystem."),(0,a.mdx)("p",null,'As part of the capsule creation, all packages listed as dependencies of that component will be installed. This step is necessary to validate there are no dependency-graph issues (a component that is not totally isolated will be able to use packages installed in parent directories in your workspace, by other components. This will translate into a "false positive" result when testing for dependency-graph issues in a non-isolated location).'),(0,a.mdx)("h2",null,"Incremental builds"),(0,a.mdx)("p",null,'When a component "goes through" the build pipeline, all of its dependencies are built as well. If a dependency has not changed since its last build, the build process will use its artifacts from the previous build (and will not process it again). This optimization to the build process supplements the "innate optimization" that naturally comes from developing (and building) independent components instead of a single monolithic codebase.'),(0,a.mdx)("h2",null,"Environment-specific builds"),(0,a.mdx)("p",null,"Each Bit environment determines its own build pipeline. That means, a single workspace that uses multiple environments will run a different set of build tasks on different components depending on their associated environment. This is another Bit feature that enables seamless transitioning between different development environments, all in the same workspace. It also makes it much easier to integrate the Build Pipeline in your (remote) CI, as it only requires executing the build step - all other per-component build configurations are already set by the various environments being used."),(0,a.mdx)("p",null,"Since environments are extensible, so are the build pipelines configured by them."),(0,a.mdx)("h2",null,"Build task"),(0,a.mdx)("p",null,"An example of a build-task is ",(0,a.mdx)("inlineCode",{parentName:"p"},"compile"),", it's written in the compiler aspect and is running on each one of the capsules created by the build process. build-tasks in many cases generate artifacts, in this case, the compiler generates ",(0,a.mdx)("inlineCode",{parentName:"p"},"dists")," files and write them on the isolated capsules. There artifacts files are used later for example when creating packages."),(0,a.mdx)("h2",null,"Pipelines"),(0,a.mdx)("p",null,"There are three pipelines: ",(0,a.mdx)("inlineCode",{parentName:"p"},"build"),", ",(0,a.mdx)("inlineCode",{parentName:"p"},"tag")," and ",(0,a.mdx)("inlineCode",{parentName:"p"},"snap"),"."),(0,a.mdx)("ul",null,(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("inlineCode",{parentName:"li"},"bit build")," runs the build pipeline."),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("inlineCode",{parentName:"li"},"bit tag")," runs the build pipeline and then the tag pipeline."),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("inlineCode",{parentName:"li"},"bit snap")," runs the build pipeline and then the snap pipeline.")),(0,a.mdx)("h2",null,"List Build Tasks"),(0,a.mdx)("p",null,"To get a list of all the tasks that will be running per pipeline on a specific component, run ",(0,a.mdx)("inlineCode",{parentName:"p"},"bit build --list-tasks <id>"),".\nHere is an example of the relevant part from the output:"),(0,a.mdx)("pre",null,(0,a.mdx)("code",{parentName:"pre"},"➜ bit build --list-tasks ui/tooltip\nTasks List\nid: teambit.design/ui/tooltip@0.0.347\nenvId: teambit.react/react\n\nBuild Pipeline Tasks:\nteambit.harmony/aspect:CoreExporter\nteambit.compilation/compiler:TSCompiler\nteambit.defender/tester:TestComponents\nteambit.pkg/pkg:PreparePackages\nteambit.pkg/pkg:PublishDryRun\nteambit.preview/preview:GeneratePreview\n\nTag Pipeline Tasks:\nteambit.harmony/application:build_ui_application\nteambit.pkg/pkg:PublishComponents\n\nSnap Pipeline Tasks:\n<N/A>\n")),(0,a.mdx)("h2",null,"Implementing Build Tasks"),(0,a.mdx)("p",null,"The ",(0,a.mdx)("inlineCode",{parentName:"p"},"BuildTask")," interface is a good start to understand how to implement a new build-task.\nWhen writing a build task, the ",(0,a.mdx)("inlineCode",{parentName:"p"},"Network")," object is passed and it includes the seeders capsules, as well as the entire graph including the dependencies.\nKeep in mind that the entire graph may contain components from other envs."),(0,a.mdx)("p",null,"Some tasks, such as, compiling in typescript and bundling with Webpack, need the entire graph.\nOthers, such as, Babel, need only the seeders. However, normally, the bundling is running after the compilation and it expects to have the dependencies compiled, so you might need the entire graph regardless."),(0,a.mdx)("h2",null,"Adding Tasks to a pipeline"),(0,a.mdx)("p",null,"There are two ways of adding tasks to the build pipeline."),(0,a.mdx)("ol",null,(0,a.mdx)("li",{parentName:"ol"},(0,a.mdx)("inlineCode",{parentName:"li"},"getBuildPipe()")," method of the env. (or ",(0,a.mdx)("inlineCode",{parentName:"li"},"getTagPipe()")," and ",(0,a.mdx)("inlineCode",{parentName:"li"},"getSnapPipe()"),")"),(0,a.mdx)("li",{parentName:"ol"},"registering to the slot via ",(0,a.mdx)("inlineCode",{parentName:"li"},"builder.registerBuildTask()"),". (or ",(0,a.mdx)("inlineCode",{parentName:"li"},"registerTagTask()")," and ",(0,a.mdx)("inlineCode",{parentName:"li"},"registerSnapTask()"),")")),(0,a.mdx)("p",null,"in the option #1, it's possible to determine the order. e.g. ",(0,a.mdx)("inlineCode",{parentName:"p"},"getBuildPipe() { return [taskA, taskB, taskC]; }"),"\nin the option #2, the register happens once the extension is loaded, so there is no way to put\none task before/after another task as of now."),(0,a.mdx)("h2",null,"Sequencing the build tasks"),(0,a.mdx)("p",null,"The Build Pipeline takes into consideration the following factors when deciding the order of which to execute each task:"),(0,a.mdx)("ul",null,(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("strong",{parentName:"li"},"Location"),": A task can be executed either at the start or end of the build pipeline. This can be explicitly configured by the task itself."),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("strong",{parentName:"li"},"Dependencies"),": A task can depend on other tasks. That means, the dependencies must be completed successfully for all envs before this task starts. The dependencies are applicable inside a location and not across locations. This is configured by the task itself."),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("strong",{parentName:"li"},"An environment's list of build tasks"),": This is the array of tasks as it is defined by an environment")),(0,a.mdx)("h2",null,"Executing the pipelines"),(0,a.mdx)("p",null,"Commands that trigger the build pipeline:"),(0,a.mdx)("ul",null,(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("inlineCode",{parentName:"li"},"bit build")," - runs the build pipeline on your local machine, for the entire workspace. The output data will not persist. - That is most often used for testing and debugging the build process."),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("inlineCode",{parentName:"li"},"bit tag")," - runs the tag pipeline in addition to the build pipeline, before creating a new component release version. The output data will persist."),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("inlineCode",{parentName:"li"},"bit snap")," - runs the snap pipeline in addition to the build pipeline. The output data will persist.")),(0,a.mdx)("p",null,"Build pipelines are determined by the environments in use. That means, in order to override the default pipeline, we need to create a new environment extension or modify an existing one."),(0,a.mdx)("p",null,"The example task below, shown being used by a customized environment, prints out the component name of every component handled by it. In addition to that, the task returns the component name as custom metadata to be logged and/or stored in the component tagged version. ",(0,a.mdx)("a",{parentName:"p",href:"https://github.com/teambit/harmony-build-examples"},"See a demo project here"),"."),(0,a.mdx)("blockquote",null,(0,a.mdx)("p",{parentName:"blockquote"},"Information returned by a build task will only persist if the build-pipeline was triggered by the 'hard-tag' command (",(0,a.mdx)("inlineCode",{parentName:"p"},"bit tag <component-id>"),").")),(0,a.mdx)("pre",null,(0,a.mdx)("code",{parentName:"pre",className:"language-ts",metastring:'title="print-cmp-name-task.ts"',title:'"print-cmp-name-task.ts"'},"import { BuildTask, BuildContext, BuiltTaskResult, ComponentResult } from '@teambit/builder';\n\n// A task is an implementation of 'BuildTask' provided by the 'builder' aspect\nexport class PrintCmpNameTask implements BuildTask {\n // The constructor leaves these properties up to the hands of the environment using this task\n constructor(readonly aspectId: string, readonly name: string) {}\n\n // This is where the task logic is placed. It will be executed by the build pipeline\n async execute(context: BuildContext): Promise<BuiltTaskResult> {\n const componentsResults: ComponentResult[] = [];\n\n // Go through every isolated component instance\n context.capsuleNetwork.seedersCapsules.forEach((capsule) => {\n console.log(`The current component name is: ${capsule.component.id.name}`);\n\n componentsResults.push({\n component: capsule.component,\n metadata: { customProp: capsule.component.id.name },\n });\n });\n return {\n // An array of component objects, enriched with additional data produced by the task\n componentsResults,\n };\n }\n}\n")),(0,a.mdx)("pre",null,(0,a.mdx)("code",{parentName:"pre",className:"language-ts",metastring:'title="customized-react.extension.ts"',title:'"customized-react.extension.ts"'},"import { EnvsMain, EnvsAspect } from '@teambit/envs';\nimport { ReactAspect, ReactMain } from '@teambit/react';\n\n// Import the task\nimport { PrintCmpNameTask } from './print-cmp-name-task';\n\nexport class CustomReact {\n constructor(private react: ReactMain) {}\n\n static dependencies: any = [EnvsAspect, ReactAspect];\n\n static async provider([envs, react]: [EnvsMain, ReactMain]) {\n // Get the environment's default build pipeline\n const reactPipe = react.env.getBuildPipe();\n\n // Add the custom task to the end of the build tasks sequence.\n // Provide the task with the component ID of the extension using it.\n // Provide the ask with a name.\n const tasks = [...reactPipe, new PrintCompTask('extensions/custom-react', 'PrintCmpNameTask')];\n\n // Create a new environment by merging these configurations with the env's default ones\n const customReactEnv = react.compose([react.overrideBuildPipe(tasks)]);\n\n // register the extension as an environment\n envs.registerEnv(customReactEnv);\n return new CustomReact(react);\n }\n}\n")),(0,a.mdx)("h2",null,"Positioning a build task in the pipeline"),(0,a.mdx)("p",null,"A build task is positioned in the build pipeline sequence either by overriding the entire ",(0,a.mdx)("em",{parentName:"p"},"customizable")," pipeline or, by registering it to a location in the pipeline using the designated builder slot."),(0,a.mdx)("h3",null,"Override the build pipeline sequence"),(0,a.mdx)("p",null,"This methodology leaves the task completely agnostic as to its position in the build pipeline. Instead, the task position is determined by the environment using the ",(0,a.mdx)("inlineCode",{parentName:"p"},"getBuildPipe")," Environment Handler."),(0,a.mdx)("p",null,"The example above shows the React environment ",(0,a.mdx)("inlineCode",{parentName:"p"},"overrideBuildPipe")," method being used to override its default pipeline. This method uses the ",(0,a.mdx)("inlineCode",{parentName:"p"},"getBuildPipe()")," Environment Handler, internally."),(0,a.mdx)("h3",null,"Append to the start or end of the pipeline, in relation to other tasks"),(0,a.mdx)("p",null,"This methodology places the task at the start or end of the build pipeline sequence, and lists all other tasks needed to run successfully before it is executed."),(0,a.mdx)("p",null,"Example:"),(0,a.mdx)("pre",null,(0,a.mdx)("code",{parentName:"pre",className:"language-ts",metastring:'title="print-cmp-name-task.ts"',title:'"print-cmp-name-task.ts"'},"import { BuildTask, BuildContext, BuiltTaskResult, ComponentResult } from '@teambit/builder';\n\nexport class PrintCmpNameTask implements BuildTask {\n constructor(readonly aspectId: string, readonly name: string) {}\n\n // Place the task at the end of the build pipeline\n readonly location = 'end';\n\n // Run this task only after the '@teambit/preview' task is completed successfully\n readonly dependencies = ['@teambit/preview'];\n\n async execute(context: BuildContext): Promise<BuiltTaskResult> {\n const componentsResults: ComponentResult[] = [];\n context.capsuleNetwork.seedersCapsules.forEach((capsule) => {\n console.log(`The current component name is: ${capsule.component.id.name}`);\n\n componentsResults.push({\n component: capsule.component,\n metadata: { customProp: capsule.component.id.name },\n });\n });\n return {\n componentsResults,\n };\n }\n}\n")),(0,a.mdx)("pre",null,(0,a.mdx)("code",{parentName:"pre",className:"language-ts",metastring:'title="customized-react.extension.ts"',title:'"customized-react.extension.ts"'},"import { EnvsMain, EnvsAspect } from '@teambit/envs';\nimport { ReactAspect, ReactMain } from '@teambit/react';\nimport { BuilderMain } from '@teambit/builder';\n\n// Import the task (in reality, it should be an independent component)\nimport { PrintCmpNameTask } from './print-cmp-name-task';\n\nexport class CustomReact {\n constructor(private react: ReactMain) {}\n\n static dependencies: any = [EnvsAspect, ReactAspect];\n\n // Inject the builder\n static async provider([envs, react, builder]: [EnvsMain, ReactMain, BuilderMain]) {\n // Register this task using the registration slot, made available by the 'builder'.\n // Here, the environment has no say in the positioning of the task\n builder.registerBuildTasks([new ExampleTask('extensions/custom-react', 'PrintCmpNameTask')]);\n\n const customReactEnv = react.compose([]);\n\n envs.registerEnv(customReactEnv);\n return new CustomReact(react);\n }\n}\n")),(0,a.mdx)("h2",null,"A build task anatomy"),(0,a.mdx)("ul",null,(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"aspectId")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"aspectId: string"),(0,a.mdx)("br",null),"\nThe component ID of the environment using this task.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"name")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"name: string")," ",(0,a.mdx)("br",null),"\nA name for this task. Only alphanumerical characters are allowed. PascalCase should be used as a convention.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"location")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"location?: 'start' | 'end'")," ",(0,a.mdx)("br",null),"\nThe section of the build-pipeline to which to append this task.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"dependencies")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"dependencies?: string[]")," ",(0,a.mdx)("br",null),"\nAn list of tasks that must be completed before this task gets executed. ",(0,a.mdx)("br",null),"\nFor example ",(0,a.mdx)("inlineCode",{parentName:"p"},"dependencies = ['@teambit/preview']"),".")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"execute")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"execute(context: BuildContext): Promise<BuiltTaskResult>")," ",(0,a.mdx)("br",null),"\nThe execute method is where all the task logic is placed."),(0,a.mdx)("ul",{parentName:"li"},(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"context")," (argument) ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"context: BuildContext")," ",(0,a.mdx)("br",null),"\nThe context of the build pipeline. Use this object (provided by the build pipeline) to get information regarding all components handled by the build pipeline. ",(0,a.mdx)("br",null),(0,a.mdx)("br",null),"\nFor example, ",(0,a.mdx)("inlineCode",{parentName:"p"},"context.capsuleNetwork.seedersCapsules")," are models representing isolated instances of components handled by the build pipeline. These isolated instances are independent projects, generated in your local filesystem (by the build pipeline).")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"return")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"Promise<BuiltTaskResult>")," ",(0,a.mdx)("br",null),"\nA ",(0,a.mdx)("inlineCode",{parentName:"p"},"context")," method returns an object with data regarding the build task process, additional data regarding the components handled by the task and, if available, data regarding the different artifacts generated by this task.",(0,a.mdx)("br",null),"\nThe returned object has the following attributes:"),(0,a.mdx)("ul",{parentName:"li"},(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"componentsResults")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"componentsResults: ComponentResult[]"),"\nAn array of objects, each containing an instance of an object handled the task and additional information regarding the process and the component itself.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"component")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"component: Component")," ",(0,a.mdx)("br",null),"\nAn instance of the component handled by the task (see the above task example).")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"metadata")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"metadata?: { [key: string]: Serializable }")," ",(0,a.mdx)("br",null),"\nComponent metadata generated during the build task.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"errors")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"errors?: Array<Error | string>")," ",(0,a.mdx)("br",null),"\nBuild task errors. A task returning errors will abort the build pipeline and log the returned errors.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"warnings")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"warnings?: string[]")," ",(0,a.mdx)("br",null),"\nwarnings generated throughout the build task.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"startTime")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"startTime?: number")," ",(0,a.mdx)("br",null),"\nA timestamp (in milliseconds) of when the task started")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"endTime")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"endTime?: number")," ",(0,a.mdx)("br",null),"\nA timestamp (in milliseconds) of when the task ended")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"artifacts")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"artifacts?: ArtifactDefinition[]")," ",(0,a.mdx)("br",null),"\nAn array of artifact definitions to generate after a successful build")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"name")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"name: string")," ",(0,a.mdx)("br",null),"\nThe name of the artifact. ",(0,a.mdx)("br",null),"\nFor example, a project might utilize two different artifacts for the same typescript compiler, one that generates ES5 files and another for ES6. This prop helps to distinguish between the two.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"generatedBy")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"generatedBy?: string;")," ",(0,a.mdx)("br",null),"\nId of the component that generated this artifact.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"description")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"description?: string")," ",(0,a.mdx)("br",null),"\nA description of the artifact. ",(0,a.mdx)("br",null))),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"globPatterns")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"globPatterns: string[]")," ",(0,a.mdx)("br",null),"\nGlob patterns of files to include upon artifact creation. Minimatch is used to match the patterns. ",(0,a.mdx)("br",null),"\nFor example, ",(0,a.mdx)("inlineCode",{parentName:"p"},"['*.ts', '!foo.ts']")," matches all ts files but ignores ",(0,a.mdx)("inlineCode",{parentName:"p"},"foo.ts"),".")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"rootDir")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"rootDir?: string")," ",(0,a.mdx)("br",null),"\nDefines the root directory of the artifacts in the capsule file system. The rootDir must be unique for every artifact, otherwise data might be overridden.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"dirPrefix")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"dirPrefix?: string")," ",(0,a.mdx)("br",null),"\nAdds a directory prefix for all artifact files.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"context")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"context?: 'component' | 'env'")," ",(0,a.mdx)("br",null),"\nDetermine the context of the artifact. The default artifact context is ",(0,a.mdx)("inlineCode",{parentName:"p"},"component"),". ",(0,a.mdx)("inlineCode",{parentName:"p"},"env"),' is useful when the same file is generated for all components, for example, a "preview" task may create the same webpack file for all components of that env.')),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"storageResolver")," ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"storageResolver?: string")," ",(0,a.mdx)("br",null),"\nUsed to replace the location of the stored artifacts. The default resolver persists artifacts on scope (that's not recommended for large files).")))))),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"preBuild")," (advanced) ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"preBuild?(context: BuildContext): Promise<void>")," ",(0,a.mdx)("br",null),"\nRuns before the build pipeline has started. This method should only be used when preparations are needed to be done on all environments before the build starts.")),(0,a.mdx)("li",{parentName:"ul"},(0,a.mdx)("p",{parentName:"li"},(0,a.mdx)("strong",{parentName:"p"},"postBuild")," (advanced) ",(0,a.mdx)("br",null),"\n",(0,a.mdx)("inlineCode",{parentName:"p"},"postBuild?(context: BuildContext, tasksResults: TaskResultsList): Promise<void>")," ",(0,a.mdx)("br",null),"\nRuns after the dependencies were completed for all environments."))))}u.__bit_component=i,u.isMDXComponent=!0},17184:(e,n,t)=>{Object.defineProperty(n,"I",{enumerable:!0,get:function(){return i.default}});var i=a(t(86991));function a(e){return e&&e.__esModule?e:{default:e}}a.__bit_component={id:"teambit.pipelines/aspect-docs/builder@0.0.165",homepage:"https://bit.cloud/teambit/pipelines/aspect-docs/builder",exported:!0}},40040:e=>{e.exports=MdxJsReact},87363:e=>{e.exports=React}},n={};function t(i){var a=n[i];if(void 0!==a)return a.exports;var r=n[i]={exports:{}};return e[i](r,r.exports,t),r.exports}t.d=(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},t.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{t.r(i),t.d(i,{compositions:()=>u,compositions_metadata:()=>h,overview:()=>c});var e={};t.r(e),t.d(e,{default:()=>m});var n=t(51221),a=(t(87363),t(40040));const r=TeambitMdxUiMdxScopeContext;var o=t(17184),s=["components"];function l(){return l=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},l.apply(this,arguments)}var d={},p="wrapper";function m(e){var n=e.components,t=function(e,n){if(null==e)return{};var t,i,a=function(e,n){if(null==e)return{};var t,i,a={},r=Object.keys(e);for(i=0;i<r.length;i++)t=r[i],n.indexOf(t)>=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(i=0;i<r.length;i++)t=r[i],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}(e,s);return(0,a.mdx)(p,l({},d,t,{components:n,mdxType:"MDXLayout"}),(0,a.mdx)(r.MDXScopeProvider,{components:{Builder:o.I},mdxType:"MDXScopeProvider"},(0,a.mdx)(o.I,{mdxType:"Builder"})))}m.isMDXComponent=!0;const u=[n],c=[e],h={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),i})()));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.pipelines_builder@1.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.pipelines_builder@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.pipelines_builder@1.0.110/dist/builder.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.pipelines_builder@1.0.110/dist/builder.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/builder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.110",
|
|
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.
|
|
9
|
+
"version": "1.0.110"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chalk": "2.4.2",
|
|
@@ -27,22 +27,22 @@
|
|
|
27
27
|
"@teambit/harmony": "0.4.6",
|
|
28
28
|
"@teambit/bit-error": "0.0.404",
|
|
29
29
|
"@teambit/component-id": "1.2.0",
|
|
30
|
-
"@teambit/component": "1.0.
|
|
31
|
-
"@teambit/envs": "1.0.
|
|
32
|
-
"@teambit/logger": "0.0.
|
|
30
|
+
"@teambit/component": "1.0.110",
|
|
31
|
+
"@teambit/envs": "1.0.110",
|
|
32
|
+
"@teambit/logger": "0.0.935",
|
|
33
33
|
"@teambit/toolbox.string.capitalize": "0.0.494",
|
|
34
|
-
"@teambit/tester": "1.0.
|
|
35
|
-
"@teambit/isolator": "1.0.
|
|
36
|
-
"@teambit/cli": "0.0.
|
|
37
|
-
"@teambit/workspace": "1.0.
|
|
38
|
-
"@teambit/aspect-loader": "1.0.
|
|
39
|
-
"@teambit/aspect": "1.0.
|
|
40
|
-
"@teambit/generator": "1.0.
|
|
41
|
-
"@teambit/global-config": "0.0.
|
|
42
|
-
"@teambit/graphql": "1.0.
|
|
43
|
-
"@teambit/scope": "1.0.
|
|
44
|
-
"@teambit/ui": "1.0.
|
|
45
|
-
"@teambit/express": "0.0.
|
|
34
|
+
"@teambit/tester": "1.0.110",
|
|
35
|
+
"@teambit/isolator": "1.0.110",
|
|
36
|
+
"@teambit/cli": "0.0.842",
|
|
37
|
+
"@teambit/workspace": "1.0.110",
|
|
38
|
+
"@teambit/aspect-loader": "1.0.110",
|
|
39
|
+
"@teambit/aspect": "1.0.110",
|
|
40
|
+
"@teambit/generator": "1.0.111",
|
|
41
|
+
"@teambit/global-config": "0.0.844",
|
|
42
|
+
"@teambit/graphql": "1.0.110",
|
|
43
|
+
"@teambit/scope": "1.0.110",
|
|
44
|
+
"@teambit/ui": "1.0.110",
|
|
45
|
+
"@teambit/express": "0.0.941"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/lodash": "4.14.165",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@types/mocha": "9.1.0",
|
|
54
54
|
"@types/jest": "^29.2.2",
|
|
55
55
|
"@types/testing-library__jest-dom": "^5.9.5",
|
|
56
|
-
"@teambit/harmony.envs.core-aspect-env": "0.0.
|
|
56
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.15",
|
|
57
57
|
"@teambit/pipelines.aspect-docs.builder": "0.0.165"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
@@ -65,11 +65,15 @@
|
|
|
65
65
|
"optionalDependencies": {},
|
|
66
66
|
"peerDependenciesMeta": {},
|
|
67
67
|
"exports": {
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
68
|
+
".": {
|
|
69
|
+
"node": {
|
|
70
|
+
"require": "./dist/index.js",
|
|
71
|
+
"import": "./dist/esm.mjs"
|
|
72
|
+
},
|
|
73
|
+
"default": "./dist/index.js"
|
|
71
74
|
},
|
|
72
|
-
"
|
|
75
|
+
"./dist/*": "./dist/*",
|
|
76
|
+
"./artifacts/*": "./artifacts/*"
|
|
73
77
|
},
|
|
74
78
|
"private": false,
|
|
75
79
|
"engines": {
|
package/build-pipe.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { EnvDefinition } from '@teambit/envs';
|
|
2
|
-
import { ComponentMap, ComponentID } from '@teambit/component';
|
|
3
|
-
import { Logger, LongProcessLogger } from '@teambit/logger';
|
|
4
|
-
import mapSeries from 'p-map-series';
|
|
5
|
-
import prettyTime from 'pretty-time';
|
|
6
|
-
import { capitalize } from '@teambit/toolbox.string.capitalize';
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import { ArtifactFactory, ArtifactList, FsArtifact } from './artifact';
|
|
9
|
-
import { BuildContext, BuildTask, BuildTaskHelper, BuiltTaskResult } from './build-task';
|
|
10
|
-
import { ComponentResult } from './types';
|
|
11
|
-
import { TasksQueue } from './tasks-queue';
|
|
12
|
-
import { EnvsBuildContext } from './builder.service';
|
|
13
|
-
import { TaskResultsList } from './task-results-list';
|
|
14
|
-
|
|
15
|
-
export type TaskResults = {
|
|
16
|
-
/**
|
|
17
|
-
* task itself. useful for getting its id/description later on.
|
|
18
|
-
*/
|
|
19
|
-
task: BuildTask;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* environment were the task was running
|
|
23
|
-
*/
|
|
24
|
-
env: EnvDefinition;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* component build results.
|
|
28
|
-
*/
|
|
29
|
-
componentsResults: ComponentResult[];
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* artifacts generated by the build pipeline.
|
|
33
|
-
* in case the task finished with errors, this prop is undefined.
|
|
34
|
-
*/
|
|
35
|
-
artifacts: ComponentMap<ArtifactList<FsArtifact>> | undefined;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* timestamp of start initiation.
|
|
39
|
-
*/
|
|
40
|
-
startTime: number;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* timestamp of task completion.
|
|
44
|
-
*/
|
|
45
|
-
endTime: number;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
type PipeOptions = {
|
|
49
|
-
exitOnFirstFailedTask?: boolean; // by default it skips only when a dependent failed.
|
|
50
|
-
showEnvNameInOutput?: boolean;
|
|
51
|
-
showEnvVersionInOutput?: boolean; // in case it shows the env-name, whether should show also the version
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export class BuildPipe {
|
|
55
|
-
private failedTasks: BuildTask[] = [];
|
|
56
|
-
private failedDependencyTask: BuildTask | undefined;
|
|
57
|
-
private longProcessLogger: LongProcessLogger;
|
|
58
|
-
private taskResults: TaskResults[] = [];
|
|
59
|
-
constructor(
|
|
60
|
-
/**
|
|
61
|
-
* array of services to apply on the components.
|
|
62
|
-
*/
|
|
63
|
-
readonly tasksQueue: TasksQueue,
|
|
64
|
-
readonly envsBuildContext: EnvsBuildContext,
|
|
65
|
-
readonly logger: Logger,
|
|
66
|
-
readonly artifactFactory: ArtifactFactory,
|
|
67
|
-
private previousTaskResults?: TaskResults[],
|
|
68
|
-
private options?: PipeOptions
|
|
69
|
-
) {}
|
|
70
|
-
|
|
71
|
-
get allTasksResults(): TaskResults[] {
|
|
72
|
-
return [...(this.previousTaskResults || []), ...(this.taskResults || [])];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* execute a pipeline of build tasks.
|
|
77
|
-
*/
|
|
78
|
-
async execute(): Promise<TaskResultsList> {
|
|
79
|
-
this.addSignalListener();
|
|
80
|
-
await this.executePreBuild();
|
|
81
|
-
this.longProcessLogger = this.logger.createLongProcessLogger('running tasks', this.tasksQueue.length);
|
|
82
|
-
await mapSeries(this.tasksQueue, async ({ task, env }) => this.executeTask(task, env));
|
|
83
|
-
this.longProcessLogger.end();
|
|
84
|
-
const capsuleRootDir = Object.values(this.envsBuildContext)[0]?.capsuleNetwork.capsulesRootDir;
|
|
85
|
-
const tasksResultsList = new TaskResultsList(this.tasksQueue, this.taskResults, capsuleRootDir);
|
|
86
|
-
await this.executePostBuild(tasksResultsList);
|
|
87
|
-
|
|
88
|
-
return tasksResultsList;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* for some reason, some tasks (such as typescript compilation) ignore ctrl+C. this fixes it.
|
|
93
|
-
*/
|
|
94
|
-
private addSignalListener() {
|
|
95
|
-
process.on('SIGTERM', () => {
|
|
96
|
-
process.exit();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
process.on('SIGINT', () => {
|
|
100
|
-
process.exit();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private async executePreBuild() {
|
|
105
|
-
this.logger.setStatusLine('executing pre-build for all tasks');
|
|
106
|
-
const longProcessLogger = this.logger.createLongProcessLogger('running pre-build for all tasks');
|
|
107
|
-
await mapSeries(this.tasksQueue, async ({ task, env }) => {
|
|
108
|
-
if (!task.preBuild) return;
|
|
109
|
-
await task.preBuild(this.getBuildContext(env.id));
|
|
110
|
-
});
|
|
111
|
-
longProcessLogger.end();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private async executeTask(task: BuildTask, env: EnvDefinition): Promise<void> {
|
|
115
|
-
const taskId = BuildTaskHelper.serializeId(task);
|
|
116
|
-
const envName = this.options?.showEnvNameInOutput ? `(${this.getPrettyEnvName(env.id)}) ` : '';
|
|
117
|
-
const taskLogPrefix = `${envName}[${this.getPrettyAspectName(task.aspectId)}: ${task.name}]`;
|
|
118
|
-
this.longProcessLogger.logProgress(`${taskLogPrefix}${task.description ? ` ${task.description}` : ''}`, false);
|
|
119
|
-
this.updateFailedDependencyTask(task);
|
|
120
|
-
if (this.shouldSkipTask(taskId, env.id)) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const startTask = process.hrtime();
|
|
124
|
-
const taskStartTime = Date.now();
|
|
125
|
-
const buildContext = this.getBuildContext(env.id);
|
|
126
|
-
let buildTaskResult: BuiltTaskResult;
|
|
127
|
-
try {
|
|
128
|
-
buildTaskResult = await task.execute(buildContext);
|
|
129
|
-
} catch (err) {
|
|
130
|
-
this.logger.consoleFailure(`env: ${env.id}, task "${taskId}" threw an error`);
|
|
131
|
-
throw err;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const endTime = Date.now();
|
|
135
|
-
const compsWithErrors = buildTaskResult.componentsResults.filter((c) => c.errors?.length);
|
|
136
|
-
let artifacts: ComponentMap<ArtifactList<FsArtifact>> | undefined;
|
|
137
|
-
const duration = prettyTime(process.hrtime(startTask));
|
|
138
|
-
if (compsWithErrors.length) {
|
|
139
|
-
this.logger.consoleFailure(`env: ${env.id}, task "${taskId}" has failed`);
|
|
140
|
-
this.logger.consoleFailure(
|
|
141
|
-
chalk.red(`${this.longProcessLogger.getProgress()} env: ${env.id}, task "${taskId}" has failed in ${duration}`)
|
|
142
|
-
);
|
|
143
|
-
this.failedTasks.push(task);
|
|
144
|
-
} else {
|
|
145
|
-
this.logger.consoleSuccess(
|
|
146
|
-
chalk.green(`${this.longProcessLogger.getProgress()} ${taskLogPrefix} Completed successfully in ${duration}`)
|
|
147
|
-
);
|
|
148
|
-
const defs = buildTaskResult.artifacts || [];
|
|
149
|
-
artifacts = this.artifactFactory.generate(buildContext, defs, task);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const taskResults: TaskResults = {
|
|
153
|
-
task,
|
|
154
|
-
env,
|
|
155
|
-
componentsResults: buildTaskResult.componentsResults,
|
|
156
|
-
artifacts,
|
|
157
|
-
startTime: taskStartTime,
|
|
158
|
-
endTime,
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
this.taskResults.push(taskResults);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private getPrettyAspectName(aspectId: string): string {
|
|
165
|
-
const resolvedId = ComponentID.fromString(aspectId);
|
|
166
|
-
const tokens = resolvedId.name.split('-').map((token) => capitalize(token));
|
|
167
|
-
return tokens.join(' ');
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
private getPrettyEnvName(envId: string) {
|
|
171
|
-
const resolvedId = ComponentID.fromString(envId);
|
|
172
|
-
const ver = this.options?.showEnvVersionInOutput ? `@${resolvedId.version}` : '';
|
|
173
|
-
return `${resolvedId.fullName}${ver}`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
private async executePostBuild(tasksResults: TaskResultsList) {
|
|
177
|
-
const longProcessLogger = this.logger.createLongProcessLogger('running post-build for all tasks');
|
|
178
|
-
this.logger.setStatusLine('executing post-build for all tasks');
|
|
179
|
-
await mapSeries(this.tasksQueue, async ({ task, env }) => {
|
|
180
|
-
if (!task.postBuild) return;
|
|
181
|
-
await task.postBuild(this.getBuildContext(env.id), tasksResults);
|
|
182
|
-
});
|
|
183
|
-
longProcessLogger.end();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
private updateFailedDependencyTask(task: BuildTask) {
|
|
187
|
-
if (!this.failedDependencyTask && this.failedTasks.length && task.dependencies) {
|
|
188
|
-
task.dependencies.forEach((dependency) => {
|
|
189
|
-
const { aspectId, name } = BuildTaskHelper.deserializeIdAllowEmptyName(dependency);
|
|
190
|
-
this.failedDependencyTask = this.failedTasks.find((failedTask) => {
|
|
191
|
-
if (name && name !== failedTask.name) return false;
|
|
192
|
-
return aspectId === failedTask.aspectId;
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private shouldSkipTask(taskId: string, envId: string): boolean {
|
|
199
|
-
if (this.options?.exitOnFirstFailedTask && this.failedTasks.length) {
|
|
200
|
-
const failedTaskId = BuildTaskHelper.serializeId(this.failedTasks[0]);
|
|
201
|
-
this.logger.consoleWarning(`env: ${envId}, task "${taskId}" has skipped due to "${failedTaskId}" failure`);
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
if (!this.failedDependencyTask) return false;
|
|
205
|
-
const failedTaskId = BuildTaskHelper.serializeId(this.failedDependencyTask);
|
|
206
|
-
this.logger.consoleWarning(`env: ${envId}, task "${taskId}" has skipped due to "${failedTaskId}" failure`);
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private getBuildContext(envId: string): BuildContext {
|
|
211
|
-
const buildContext = this.envsBuildContext[envId];
|
|
212
|
-
if (!buildContext) throw new Error(`unable to find buildContext for ${envId}`);
|
|
213
|
-
buildContext.previousTasksResults = this.allTasksResults;
|
|
214
|
-
return buildContext;
|
|
215
|
-
}
|
|
216
|
-
}
|
package/build-pipeline-order.ts
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { Graph, Node, Edge } from '@teambit/graph.cleargraph';
|
|
2
|
-
import TesterAspect from '@teambit/tester';
|
|
3
|
-
import { EnvDefinition, Environment } from '@teambit/envs';
|
|
4
|
-
import { BuildTask, BuildTaskHelper } from './build-task';
|
|
5
|
-
import type { TaskSlot } from './builder.main.runtime';
|
|
6
|
-
import { TasksQueue } from './tasks-queue';
|
|
7
|
-
import { PipeFunctionNames } from './builder.service';
|
|
8
|
-
|
|
9
|
-
type TaskDependenciesGraph = Graph<string, string>;
|
|
10
|
-
type Location = 'start' | 'middle' | 'end';
|
|
11
|
-
type TasksLocationGraph = { location: Location; graph: TaskDependenciesGraph };
|
|
12
|
-
type PipelineEnv = { env: EnvDefinition; pipeline: BuildTask[] };
|
|
13
|
-
type DataPerLocation = { location: Location; graph: TaskDependenciesGraph; pipelineEnvs: PipelineEnv[] };
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* there are two ways how to add tasks to build pipeline.
|
|
17
|
-
* 1. `getBuildPipe()` method of the env.
|
|
18
|
-
* 2. registering to the `builder.registerBuildTask()`.
|
|
19
|
-
*
|
|
20
|
-
* in the option #1, it's possible to determine the order. e.g. `getBuildPipe() { return [taskA, taskB, taskC]; }`
|
|
21
|
-
* in the option #2, the register happens once the extension is loaded, so there is no way to put
|
|
22
|
-
* one task before/after another task.
|
|
23
|
-
*
|
|
24
|
-
* To be able to determine the order, you can do the following
|
|
25
|
-
* 1. "task.location", it has two options "start" and "end". the rest are "middle".
|
|
26
|
-
* 2. "task.dependencies", the dependencies must be completed for all envs before this task starts.
|
|
27
|
-
* the dependencies are applicable inside a location and not across locations. see getLocation()
|
|
28
|
-
* or/and continue reading for more info about this.
|
|
29
|
-
*
|
|
30
|
-
* to determine the final order of the tasks, the following is done:
|
|
31
|
-
* 1. split all tasks to three groups: start, middle and end.
|
|
32
|
-
* 2. for each group define a dependencies graph for the tasks with "dependencies" prop and the pipeline.
|
|
33
|
-
* 3. start with the first group "start", toposort the dependencies graph and push the found tasks
|
|
34
|
-
* to a queue. once completed, iterate the pipeline and add all tasks to the queue.
|
|
35
|
-
* 4. do the same for the "middle" and "end" groups.
|
|
36
|
-
*
|
|
37
|
-
* the reason for splitting the tasks to the three groups and not using the "dependencies" field
|
|
38
|
-
* alone to determine the order is that the "start" and "end" groups are mostly core and "middle"
|
|
39
|
-
* is mostly the user entering tasks to the pipeline and we as the core don't know about the users
|
|
40
|
-
* tasks. For example, a core task "PublishComponent" must happen after the compiler, however, a
|
|
41
|
-
* user might have an env without a compiler. if we determine the order only by the dependencies
|
|
42
|
-
* field, the "PublishComponent" would have a dependency "compiler" and because in this case there
|
|
43
|
-
* is no compiler task, it would throw an error about missing dependencies.
|
|
44
|
-
*/
|
|
45
|
-
export function calculatePipelineOrder(
|
|
46
|
-
taskSlot: TaskSlot,
|
|
47
|
-
envs: EnvDefinition[],
|
|
48
|
-
pipeNameOnEnv: PipeFunctionNames,
|
|
49
|
-
tasks: string[] = [],
|
|
50
|
-
skipTests = false
|
|
51
|
-
): TasksQueue {
|
|
52
|
-
const graphs: TasksLocationGraph[] = [];
|
|
53
|
-
const locations: Location[] = ['start', 'middle', 'end']; // the order is important here!
|
|
54
|
-
locations.forEach((location) => {
|
|
55
|
-
graphs.push({ location, graph: new Graph<string, string>() });
|
|
56
|
-
});
|
|
57
|
-
const pipelineEnvs: PipelineEnv[] = [];
|
|
58
|
-
envs.forEach((envDefinition) => {
|
|
59
|
-
const pipeline = getPipelineForEnv(taskSlot, envDefinition.env, pipeNameOnEnv);
|
|
60
|
-
pipelineEnvs.push({ env: envDefinition, pipeline });
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const flattenedPipeline: BuildTask[] = pipelineEnvs.map((pipelineEnv) => pipelineEnv.pipeline).flat();
|
|
64
|
-
flattenedPipeline.forEach((task) => addDependenciesToGraph(graphs, flattenedPipeline, task));
|
|
65
|
-
|
|
66
|
-
const dataPerLocation: DataPerLocation[] = graphs.map(({ location, graph }) => {
|
|
67
|
-
const pipelineEnvsPerLocation: PipelineEnv[] = pipelineEnvs.map(({ env, pipeline }) => {
|
|
68
|
-
return { env, pipeline: pipeline.filter((task) => (task.location || 'middle') === location) };
|
|
69
|
-
});
|
|
70
|
-
return { location, graph, pipelineEnvs: pipelineEnvsPerLocation };
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const tasksQueue = new TasksQueue();
|
|
74
|
-
locations.forEach((location) => addTasksToGraph(tasksQueue, dataPerLocation, location));
|
|
75
|
-
if (tasks.length) {
|
|
76
|
-
return new TasksQueue(
|
|
77
|
-
...tasksQueue.filter(({ task }) => tasks.includes(task.name) || tasks.includes(task.aspectId))
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
if (skipTests) {
|
|
81
|
-
return new TasksQueue(...tasksQueue.filter(({ task }) => task.aspectId !== TesterAspect.id));
|
|
82
|
-
}
|
|
83
|
-
return tasksQueue;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function addTasksToGraph(tasksQueue: TasksQueue, dataPerLocation: DataPerLocation[], location: Location) {
|
|
87
|
-
const data = dataPerLocation.find((d) => d.location === location);
|
|
88
|
-
if (!data) return;
|
|
89
|
-
const sorted = data.graph.toposort();
|
|
90
|
-
sorted.forEach((taskNode) => {
|
|
91
|
-
const { aspectId, name } = BuildTaskHelper.deserializeId(taskNode.attr);
|
|
92
|
-
data.pipelineEnvs.forEach(({ env, pipeline }) => {
|
|
93
|
-
const taskIndex = pipeline.findIndex(
|
|
94
|
-
(pipelineTask) => pipelineTask.aspectId === aspectId && pipelineTask.name === name
|
|
95
|
-
);
|
|
96
|
-
if (taskIndex < 0) return;
|
|
97
|
-
const task = pipeline[taskIndex];
|
|
98
|
-
tasksQueue.push({ env, task });
|
|
99
|
-
pipeline.splice(taskIndex, 1); // delete the task from the pipeline
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
data.pipelineEnvs.forEach(({ env, pipeline }) => {
|
|
103
|
-
pipeline.forEach((task) => tasksQueue.push({ env, task }));
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function addDependenciesToGraph(graphs: TasksLocationGraph[], pipeline: BuildTask[], task: BuildTask) {
|
|
108
|
-
if (!task.dependencies || !task.dependencies.length) return;
|
|
109
|
-
const taskId = BuildTaskHelper.serializeId(task);
|
|
110
|
-
task.dependencies.forEach((dependency) => {
|
|
111
|
-
const { aspectId, name } = BuildTaskHelper.deserializeIdAllowEmptyName(dependency);
|
|
112
|
-
const dependencyTasks = pipeline.filter((pipelineTask) => {
|
|
113
|
-
if (pipelineTask.aspectId !== aspectId) return false;
|
|
114
|
-
return name ? name === pipelineTask.name : true;
|
|
115
|
-
});
|
|
116
|
-
if (dependencyTasks.length === 0) {
|
|
117
|
-
throw new Error(
|
|
118
|
-
`Pipeline error - missing task dependency "${dependency}" of the "${BuildTaskHelper.serializeId(task)}"`
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
dependencyTasks.forEach((dependencyTask) => {
|
|
122
|
-
const location = getLocation(task, dependencyTask);
|
|
123
|
-
if (!location) {
|
|
124
|
-
// the dependency is behind and will be in the correct order regardless the graph.
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const graphLocation = graphs.find((g) => g.location === location);
|
|
128
|
-
if (!graphLocation) throw new Error(`unable to find graph for location ${location}`);
|
|
129
|
-
const dependencyId = BuildTaskHelper.serializeId(dependencyTask);
|
|
130
|
-
const graph = graphLocation.graph;
|
|
131
|
-
graph.setNode(new Node(taskId, taskId));
|
|
132
|
-
graph.setNode(new Node(dependencyId, dependencyId));
|
|
133
|
-
graph.setEdge(new Edge(dependencyId, taskId, 'dependency'));
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* since the task execution is happening per group: "start", "middle" and "end", the dependencies
|
|
140
|
-
* need to be inside the same group.
|
|
141
|
-
* e.g. if a dependency located at "end" group and the task located at "start", it's impossible to
|
|
142
|
-
* complete the dependency before the task, there it throws an error.
|
|
143
|
-
* it's ok to have the dependency located earlier, e.g. "start" and the task at "end", and in this
|
|
144
|
-
* case, it will not be part of the graph because there is no need to do any special calculation.
|
|
145
|
-
*/
|
|
146
|
-
function getLocation(task: BuildTask, dependencyTask: BuildTask): Location | null {
|
|
147
|
-
const taskLocation = task.location || 'middle';
|
|
148
|
-
const dependencyLocation = dependencyTask.location || 'middle';
|
|
149
|
-
|
|
150
|
-
const isDependencyAhead =
|
|
151
|
-
(taskLocation === 'start' && dependencyLocation !== 'start') ||
|
|
152
|
-
(taskLocation === 'middle' && dependencyLocation === 'end');
|
|
153
|
-
|
|
154
|
-
const isDependencyEqual = taskLocation === dependencyLocation;
|
|
155
|
-
|
|
156
|
-
if (isDependencyAhead) {
|
|
157
|
-
throw new Error(`a task "${BuildTaskHelper.serializeId(task)}" located at ${taskLocation}
|
|
158
|
-
has a dependency "${BuildTaskHelper.serializeId(dependencyTask)} located at ${dependencyLocation},
|
|
159
|
-
which is invalid. the dependency must be located earlier or in the same location as the task"`);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (isDependencyEqual) {
|
|
163
|
-
return taskLocation;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// dependency is behind. e.g. task is "end" and dependency is "start". no need to enter to the
|
|
167
|
-
// graph as it's going to be executed in the right order regardless the graph.
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function getPipelineForEnv(taskSlot: TaskSlot, env: Environment, pipeNameOnEnv: string): BuildTask[] {
|
|
172
|
-
const buildTasks: BuildTask[] = env[pipeNameOnEnv] ? env[pipeNameOnEnv]() : [];
|
|
173
|
-
const slotsTasks = taskSlot.values().flat();
|
|
174
|
-
const tasksAtStart: BuildTask[] = [];
|
|
175
|
-
const tasksAtEnd: BuildTask[] = [];
|
|
176
|
-
slotsTasks.forEach((task) => {
|
|
177
|
-
if (task.location === 'start') {
|
|
178
|
-
tasksAtStart.push(task);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (task.location === 'end') {
|
|
182
|
-
tasksAtEnd.push(task);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
tasksAtStart.push(task);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// merge with extension registered tasks.
|
|
189
|
-
const mergedTasks = [...tasksAtStart, ...buildTasks, ...tasksAtEnd];
|
|
190
|
-
|
|
191
|
-
return mergedTasks;
|
|
192
|
-
}
|