@teambit/builder 1.0.281 → 1.0.283
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/__bit_junit.xml +1 -1
- package/artifacts/preview/teambit_pipelines_builder-preview.js +1 -1
- package/artifacts/schema.json +8 -8
- package/dist/artifact/artifact-extractor.js +1 -1
- package/dist/artifact/artifact-extractor.js.map +1 -1
- package/dist/artifact/artifact-factory.js +1 -1
- package/dist/artifact/artifact-factory.js.map +1 -1
- package/dist/artifact/artifact-list.js +1 -1
- package/dist/artifact/artifact-list.js.map +1 -1
- package/dist/artifact/artifact.js.map +1 -1
- package/dist/artifact/artifacts.cmd.js +2 -2
- package/dist/artifact/artifacts.cmd.js.map +1 -1
- package/dist/build-pipe.js +2 -2
- package/dist/build-pipe.js.map +1 -1
- package/dist/build-pipeline-order.js.map +1 -1
- package/dist/build-pipeline-result-list.js +1 -1
- package/dist/build-pipeline-result-list.js.map +1 -1
- package/dist/build-task.js.map +1 -1
- package/dist/build.cmd.js +2 -2
- package/dist/build.cmd.js.map +1 -1
- package/dist/builder.composition.js +1 -1
- package/dist/builder.composition.js.map +1 -1
- package/dist/builder.graphql.js +2 -2
- package/dist/builder.graphql.js.map +1 -1
- package/dist/builder.main.runtime.js +1 -1
- package/dist/builder.main.runtime.js.map +1 -1
- package/dist/builder.route.js +2 -2
- package/dist/builder.route.js.map +1 -1
- package/dist/builder.service.js +2 -2
- package/dist/builder.service.js.map +1 -1
- package/dist/exceptions/artifact-definition-no-glob.js.map +1 -1
- package/dist/exceptions/artifact-storage-error.js.map +1 -1
- package/dist/exceptions/capsule-not-found.js.map +1 -1
- package/dist/exceptions/invalid-task.js.map +1 -1
- package/dist/{preview-1716434516635.js → preview-1716607230882.js} +2 -2
- package/dist/storage/default-resolver.js +1 -1
- package/dist/task-results-list.js +1 -1
- package/dist/task-results-list.js.map +1 -1
- package/dist/tasks-queue.js.map +1 -1
- package/dist/templates/build-task/files/index-file.js.map +1 -1
- package/dist/templates/build-task/files/task-file.js.map +1 -1
- package/dist/templates/build-task/index.js.map +1 -1
- package/package.json +13 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<testsuites tests="0" failures="0" errors="0" skipped="0">
|
|
3
|
-
<testsuite name="teambit.pipelines/builder@1.0.
|
|
3
|
+
<testsuite name="teambit.pipelines/builder@1.0.283" tests="0" failures="0" errors="0" skipped="0"/>
|
|
4
4
|
</testsuites>
|
|
@@ -1 +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={82740:(e,n,t)=>{var i={id:"teambit.pipelines/aspect-docs/builder@0.0.168",homepage:"https://bit.cloud/teambit/pipelines/aspect-docs/builder",exported:!0};Object.defineProperty(n,"__esModule",{value:!0}),n.default=u,o(t(41594));var a=t(5016),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={};for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){if(n.indexOf(i)>=0)continue;t[i]=e[i]}return t}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},20265:(e,n,t)=>{Object.defineProperty(n,"M",{enumerable:!0,get:function(){return i.default}});var i=a(t(82740));function a(e){return e&&e.__esModule?e:{default:e}}a.__bit_component={id:"teambit.pipelines/aspect-docs/builder@0.0.168",homepage:"https://bit.cloud/teambit/pipelines/aspect-docs/builder",exported:!0}},22790:(e,n,t)=>{var i={id:"teambit.pipelines/builder@1.0.281",homepage:"https://bit.cloud/teambit/pipelines/builder",exported:!0};function a(){const e=r(t(41594));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},5016:e=>{e.exports=MdxJsReact},41594: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(22790),a=(t(41594),t(5016));const r=TeambitMdxUiMdxScopeContext;var o=t(20265),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={};for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){if(n.indexOf(i)>=0)continue;t[i]=e[i]}return t}(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.M},mdxType:"MDXScopeProvider"},(0,a.mdx)(o.M,{mdxType:"Builder"})))}m.isMDXComponent=!0;const u=[n],c=[e],h={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),i})()));
|
|
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={60359:(e,n,t)=>{var i={id:"teambit.pipelines/aspect-docs/builder@0.0.168",homepage:"https://bit.cloud/teambit/pipelines/aspect-docs/builder",exported:!0};Object.defineProperty(n,"__esModule",{value:!0}),n.default=u,o(t(41594));var a=t(5016),r=["components"];function o(e){return e&&e.__esModule?e:{default:e}}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)}function s(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={};for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){if(n.indexOf(i)>=0)continue;t[i]=e[i]}return t}o.__bit_component=i,l.__bit_component=i,s.__bit_component=i,d.__bit_component=i;var p={},m="wrapper";function u(e){var n=e.components,t=s(e,r);return(0,a.mdx)(m,l({},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},20265:(e,n,t)=>{Object.defineProperty(n,"M",{enumerable:!0,get:function(){return i.default}});var i=a(t(60359));function a(e){return e&&e.__esModule?e:{default:e}}a.__bit_component={id:"teambit.pipelines/aspect-docs/builder@0.0.168",homepage:"https://bit.cloud/teambit/pipelines/aspect-docs/builder",exported:!0}},44796:(e,n,t)=>{var i={id:"teambit.pipelines/builder@1.0.283",homepage:"https://bit.cloud/teambit/pipelines/builder",exported:!0};function a(){const e=r(t(41594));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},5016:e=>{e.exports=MdxJsReact},41594: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(44796),a=(t(41594),t(5016));const r=TeambitMdxUiMdxScopeContext;var o=t(20265),l=["components"];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)({}).hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},s.apply(null,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={};for(var i in e)if({}.hasOwnProperty.call(e,i)){if(n.indexOf(i)>=0)continue;t[i]=e[i]}return t}(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(i=0;i<r.length;i++)t=r[i],n.indexOf(t)>=0||{}.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}(e,l);return(0,a.mdx)(p,s({},d,t,{components:n,mdxType:"MDXLayout"}),(0,a.mdx)(r.MDXScopeProvider,{components:{Builder:o.M},mdxType:"MDXScopeProvider"},(0,a.mdx)(o.M,{mdxType:"Builder"})))}m.isMDXComponent=!0;const u=[n],c=[e],h={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),i})()));
|
package/artifacts/schema.json
CHANGED
|
@@ -1117,7 +1117,7 @@
|
|
|
1117
1117
|
"_legacy": {
|
|
1118
1118
|
"scope": "teambit.pipelines",
|
|
1119
1119
|
"name": "builder",
|
|
1120
|
-
"version": "1.0.
|
|
1120
|
+
"version": "1.0.283"
|
|
1121
1121
|
},
|
|
1122
1122
|
"_scope": "teambit.pipelines"
|
|
1123
1123
|
}
|
|
@@ -1705,7 +1705,7 @@
|
|
|
1705
1705
|
"line": 51,
|
|
1706
1706
|
"character": 1
|
|
1707
1707
|
},
|
|
1708
|
-
"signature": "type PipeName = \"
|
|
1708
|
+
"signature": "type PipeName = \"tag\" | \"build\" | \"snap\"",
|
|
1709
1709
|
"name": "PipeName",
|
|
1710
1710
|
"type": {
|
|
1711
1711
|
"__schema": "TypeUnionSchema",
|
|
@@ -6038,7 +6038,7 @@
|
|
|
6038
6038
|
"line": 30,
|
|
6039
6039
|
"character": 1
|
|
6040
6040
|
},
|
|
6041
|
-
"signature": "type ArtifactStorageResolver =
|
|
6041
|
+
"signature": "type ArtifactStorageResolver = WholeArtifactStorageResolver | FileStorageResolver",
|
|
6042
6042
|
"name": "ArtifactStorageResolver",
|
|
6043
6043
|
"type": {
|
|
6044
6044
|
"__schema": "TypeUnionSchema",
|
|
@@ -7629,7 +7629,7 @@
|
|
|
7629
7629
|
"_legacy": {
|
|
7630
7630
|
"scope": "teambit.pipelines",
|
|
7631
7631
|
"name": "builder",
|
|
7632
|
-
"version": "1.0.
|
|
7632
|
+
"version": "1.0.283"
|
|
7633
7633
|
},
|
|
7634
7634
|
"_scope": "teambit.pipelines"
|
|
7635
7635
|
}
|
|
@@ -9923,7 +9923,7 @@
|
|
|
9923
9923
|
"_legacy": {
|
|
9924
9924
|
"scope": "teambit.pipelines",
|
|
9925
9925
|
"name": "builder",
|
|
9926
|
-
"version": "1.0.
|
|
9926
|
+
"version": "1.0.283"
|
|
9927
9927
|
},
|
|
9928
9928
|
"_scope": "teambit.pipelines"
|
|
9929
9929
|
}
|
|
@@ -14932,7 +14932,7 @@
|
|
|
14932
14932
|
"line": 30,
|
|
14933
14933
|
"character": 1
|
|
14934
14934
|
},
|
|
14935
|
-
"signature": "type ArtifactStorageResolver =
|
|
14935
|
+
"signature": "type ArtifactStorageResolver = WholeArtifactStorageResolver | FileStorageResolver",
|
|
14936
14936
|
"name": "ArtifactStorageResolver",
|
|
14937
14937
|
"type": {
|
|
14938
14938
|
"__schema": "TypeUnionSchema",
|
|
@@ -16658,7 +16658,7 @@
|
|
|
16658
16658
|
"_legacy": {
|
|
16659
16659
|
"scope": "teambit.pipelines",
|
|
16660
16660
|
"name": "builder",
|
|
16661
|
-
"version": "1.0.
|
|
16661
|
+
"version": "1.0.283"
|
|
16662
16662
|
},
|
|
16663
16663
|
"_scope": "teambit.pipelines"
|
|
16664
16664
|
}
|
|
@@ -16943,7 +16943,7 @@
|
|
|
16943
16943
|
"componentId": {
|
|
16944
16944
|
"scope": "teambit.pipelines",
|
|
16945
16945
|
"name": "builder",
|
|
16946
|
-
"version": "1.0.
|
|
16946
|
+
"version": "1.0.283"
|
|
16947
16947
|
},
|
|
16948
16948
|
"taggedModuleExports": []
|
|
16949
16949
|
}
|
|
@@ -74,7 +74,7 @@ function _artifact() {
|
|
|
74
74
|
};
|
|
75
75
|
return data;
|
|
76
76
|
}
|
|
77
|
-
function _interopRequireDefault(
|
|
77
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
78
78
|
class ArtifactExtractor {
|
|
79
79
|
constructor(componentMain, builder, pattern, options) {
|
|
80
80
|
this.componentMain = componentMain;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_path","data","_interopRequireDefault","require","_filenamify","_fsExtra","_scope","_componentId","_pMapSeries","_minimatch","_artifactFiles","_artifactList","_artifact","obj","__esModule","default","ArtifactExtractor","constructor","componentMain","builder","pattern","options","list","host","getHost","ids","idsByPattern","scope","ScopeAspect","id","legacyScope","scopeImporter","importWithoutDeps","ComponentIdList","fromArray","reason","components","getMany","artifactListPerId","map","component","artifacts","getArtifacts","filterByOptions","saveFilesInFileSystemIfAsked","artifactsObjectsToExtractorResults","groupResultsByAspect","extractorResult","result","reduce","acc","current","aspectId","push","outDir","pMapSeries","vinyls","getVinylsAndImportIfMissing","idAsFilename","filenamify","toStringWithoutVersion","replacement","compPath","path","join","Promise","all","vinyl","fs","outputFile","contents","results","artifact","artifactName","name","task","taskName","generatedBy","files","refs","ref","relativePath","aspect","filteredArtifacts","forEach","item","filter","minimatch","Artifact","def","ArtifactFiles","isEmpty","ArtifactList","exports"],"sources":["artifact-extractor.ts"],"sourcesContent":["import path from 'path';\nimport filenamify from 'filenamify';\nimport fs from 'fs-extra';\nimport { ComponentMain } from '@teambit/component';\nimport { ScopeAspect, ScopeMain } from '@teambit/scope';\nimport { ComponentID, ComponentIdList } from '@teambit/component-id';\nimport pMapSeries from 'p-map-series';\nimport minimatch from 'minimatch';\nimport { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport { BuilderMain } from '../builder.main.runtime';\nimport { ArtifactsOpts } from './artifacts.cmd';\nimport { ArtifactList } from './artifact-list';\nimport { Artifact } from './artifact';\n\nexport type ExtractorResult = {\n id: ComponentID;\n artifacts: ExtractorArtifactResult[];\n};\n\nexport type ExtractorArtifactResult = {\n artifactName: string;\n aspectId: string;\n taskName: string;\n files: string[];\n};\n\nexport type ExtractorResultGrouped = {\n id: ComponentID;\n artifacts: { [aspectId: string]: ExtractorArtifactResult[] };\n};\n\ntype ArtifactListPerId = {\n id: ComponentID;\n artifacts: ArtifactList<Artifact>;\n};\n\nexport class ArtifactExtractor {\n constructor(\n private componentMain: ComponentMain,\n private builder: BuilderMain,\n private pattern: string,\n private options: ArtifactsOpts\n ) {}\n\n async list(): Promise<ExtractorResult[]> {\n const host = this.componentMain.getHost();\n const ids = await host.idsByPattern(this.pattern);\n const scope = this.componentMain.getHost(ScopeAspect.id) as ScopeMain;\n // import in case the components are with build status \"pending\"\n await scope.legacyScope.scopeImporter.importWithoutDeps(ComponentIdList.fromArray(ids), { reason: 'artifact' });\n const components = await host.getMany(ids);\n const artifactListPerId: ArtifactListPerId[] = components.map((component) => {\n return {\n id: component.id,\n artifacts: this.builder.getArtifacts(component),\n };\n });\n this.filterByOptions(artifactListPerId);\n await this.saveFilesInFileSystemIfAsked(artifactListPerId);\n\n return this.artifactsObjectsToExtractorResults(artifactListPerId);\n }\n\n groupResultsByAspect(extractorResult: ExtractorResult[]) {\n return extractorResult.map((result) => {\n const artifacts = result.artifacts.reduce((acc, current) => {\n (acc[current.aspectId] ||= []).push(current);\n return acc;\n }, {});\n return { id: result.id, artifacts };\n });\n }\n\n private async saveFilesInFileSystemIfAsked(artifactListPerId: ArtifactListPerId[]) {\n const outDir = this.options.outDir;\n if (!outDir) {\n return;\n }\n const scope = this.componentMain.getHost(ScopeAspect.id) as ScopeMain;\n // @todo: optimize this to first import all missing hashes.\n await pMapSeries(artifactListPerId, async ({ id, artifacts }) => {\n const vinyls = await artifacts.getVinylsAndImportIfMissing(id, scope.legacyScope);\n // make sure the component-dir is just one dir. without this, every slash in the component-id will create a new dir.\n const idAsFilename = filenamify(id.toStringWithoutVersion(), { replacement: '_' });\n const compPath = path.join(outDir, idAsFilename);\n await Promise.all(vinyls.map((vinyl) => fs.outputFile(path.join(compPath, vinyl.path), vinyl.contents)));\n });\n }\n\n private artifactsObjectsToExtractorResults(artifactListPerId: ArtifactListPerId[]): ExtractorResult[] {\n return artifactListPerId.map(({ id, artifacts }) => {\n const results: ExtractorArtifactResult[] = artifacts.map((artifact) => {\n return {\n artifactName: artifact.name,\n aspectId: artifact.task.aspectId,\n taskName: artifact.task.name || artifact.generatedBy,\n files: artifact.files.refs.map((ref) => ref.relativePath),\n };\n });\n return {\n id,\n artifacts: results,\n };\n });\n }\n\n private filterByOptions(artifactListPerId: ArtifactListPerId[]) {\n const { aspect, task, files } = this.options;\n let filteredArtifacts: Artifact[] = [];\n\n artifactListPerId.forEach((item) => {\n filteredArtifacts = item.artifacts.filter((artifact) => {\n if (aspect && aspect !== artifact.task.aspectId) return false;\n if (task && task !== artifact.task.name) return false;\n return true;\n });\n if (files) {\n filteredArtifacts = item.artifacts\n .map((artifact) => {\n const refs = artifact.files.refs.filter((ref) => minimatch(ref.relativePath, files));\n return new Artifact(artifact.def, new ArtifactFiles([], [], refs), artifact.task);\n })\n // remove artifacts with no files\n .filter((artifact) => !artifact.isEmpty());\n }\n item.artifacts = ArtifactList.fromArray(filteredArtifacts);\n });\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,OAAA;EAAA,M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QACnF,CAAC;QACD;QAAA,CACCW,MAAM,CAAEd,QAAQ,IAAK,CAACA,QAAQ,CAACmB,OAAO,CAAC,CAAC,CAAC;MAC9C;MACAN,IAAI,CAAC5C,SAAS,GAAGmD,4BAAY,CAAC1D,SAAS,CAACiD,iBAAiB,CAAC;IAC5D,CAAC,CAAC;EACJ;AACF;AAACU,OAAA,CAAA7E,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_path","data","_interopRequireDefault","require","_filenamify","_fsExtra","_scope","_componentId","_pMapSeries","_minimatch","_artifactFiles","_artifactList","_artifact","e","__esModule","default","ArtifactExtractor","constructor","componentMain","builder","pattern","options","list","host","getHost","ids","idsByPattern","scope","ScopeAspect","id","legacyScope","scopeImporter","importWithoutDeps","ComponentIdList","fromArray","reason","components","getMany","artifactListPerId","map","component","artifacts","getArtifacts","filterByOptions","saveFilesInFileSystemIfAsked","artifactsObjectsToExtractorResults","groupResultsByAspect","extractorResult","result","reduce","acc","current","aspectId","push","outDir","pMapSeries","vinyls","getVinylsAndImportIfMissing","idAsFilename","filenamify","toStringWithoutVersion","replacement","compPath","path","join","Promise","all","vinyl","fs","outputFile","contents","results","artifact","artifactName","name","task","taskName","generatedBy","files","refs","ref","relativePath","aspect","filteredArtifacts","forEach","item","filter","minimatch","Artifact","def","ArtifactFiles","isEmpty","ArtifactList","exports"],"sources":["artifact-extractor.ts"],"sourcesContent":["import path from 'path';\nimport filenamify from 'filenamify';\nimport fs from 'fs-extra';\nimport { ComponentMain } from '@teambit/component';\nimport { ScopeAspect, ScopeMain } from '@teambit/scope';\nimport { ComponentID, ComponentIdList } from '@teambit/component-id';\nimport pMapSeries from 'p-map-series';\nimport minimatch from 'minimatch';\nimport { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport { BuilderMain } from '../builder.main.runtime';\nimport { ArtifactsOpts } from './artifacts.cmd';\nimport { ArtifactList } from './artifact-list';\nimport { Artifact } from './artifact';\n\nexport type ExtractorResult = {\n id: ComponentID;\n artifacts: ExtractorArtifactResult[];\n};\n\nexport type ExtractorArtifactResult = {\n artifactName: string;\n aspectId: string;\n taskName: string;\n files: string[];\n};\n\nexport type ExtractorResultGrouped = {\n id: ComponentID;\n artifacts: { [aspectId: string]: ExtractorArtifactResult[] };\n};\n\ntype ArtifactListPerId = {\n id: ComponentID;\n artifacts: ArtifactList<Artifact>;\n};\n\nexport class ArtifactExtractor {\n constructor(\n private componentMain: ComponentMain,\n private builder: BuilderMain,\n private pattern: string,\n private options: ArtifactsOpts\n ) {}\n\n async list(): Promise<ExtractorResult[]> {\n const host = this.componentMain.getHost();\n const ids = await host.idsByPattern(this.pattern);\n const scope = this.componentMain.getHost(ScopeAspect.id) as ScopeMain;\n // import in case the components are with build status \"pending\"\n await scope.legacyScope.scopeImporter.importWithoutDeps(ComponentIdList.fromArray(ids), { reason: 'artifact' });\n const components = await host.getMany(ids);\n const artifactListPerId: ArtifactListPerId[] = components.map((component) => {\n return {\n id: component.id,\n artifacts: this.builder.getArtifacts(component),\n };\n });\n this.filterByOptions(artifactListPerId);\n await this.saveFilesInFileSystemIfAsked(artifactListPerId);\n\n return this.artifactsObjectsToExtractorResults(artifactListPerId);\n }\n\n groupResultsByAspect(extractorResult: ExtractorResult[]) {\n return extractorResult.map((result) => {\n const artifacts = result.artifacts.reduce((acc, current) => {\n (acc[current.aspectId] ||= []).push(current);\n return acc;\n }, {});\n return { id: result.id, artifacts };\n });\n }\n\n private async saveFilesInFileSystemIfAsked(artifactListPerId: ArtifactListPerId[]) {\n const outDir = this.options.outDir;\n if (!outDir) {\n return;\n }\n const scope = this.componentMain.getHost(ScopeAspect.id) as ScopeMain;\n // @todo: optimize this to first import all missing hashes.\n await pMapSeries(artifactListPerId, async ({ id, artifacts }) => {\n const vinyls = await artifacts.getVinylsAndImportIfMissing(id, scope.legacyScope);\n // make sure the component-dir is just one dir. without this, every slash in the component-id will create a new dir.\n const idAsFilename = filenamify(id.toStringWithoutVersion(), { replacement: '_' });\n const compPath = path.join(outDir, idAsFilename);\n await Promise.all(vinyls.map((vinyl) => fs.outputFile(path.join(compPath, vinyl.path), vinyl.contents)));\n });\n }\n\n private artifactsObjectsToExtractorResults(artifactListPerId: ArtifactListPerId[]): ExtractorResult[] {\n return artifactListPerId.map(({ id, artifacts }) => {\n const results: ExtractorArtifactResult[] = artifacts.map((artifact) => {\n return {\n artifactName: artifact.name,\n aspectId: artifact.task.aspectId,\n taskName: artifact.task.name || artifact.generatedBy,\n files: artifact.files.refs.map((ref) => ref.relativePath),\n };\n });\n return {\n id,\n artifacts: results,\n };\n });\n }\n\n private filterByOptions(artifactListPerId: ArtifactListPerId[]) {\n const { aspect, task, files } = this.options;\n let filteredArtifacts: Artifact[] = [];\n\n artifactListPerId.forEach((item) => {\n filteredArtifacts = item.artifacts.filter((artifact) => {\n if (aspect && aspect !== artifact.task.aspectId) return false;\n if (task && task !== artifact.task.name) return false;\n return true;\n });\n if (files) {\n filteredArtifacts = item.artifacts\n .map((artifact) => {\n const refs = artifact.files.refs.filter((ref) => minimatch(ref.relativePath, files));\n return new Artifact(artifact.def, new ArtifactFiles([], [], refs), artifact.task);\n })\n // remove artifacts with no files\n .filter((artifact) => !artifact.isEmpty());\n }\n item.artifacts = ArtifactList.fromArray(filteredArtifacts);\n });\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAJ,I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AAE,EAAE,EAAEX,IAAI,CAAC,EAAEP,QAAQ,CAACG,IAAI,CAAC;QACnF,CAAC;QACD;QAAA,CACCW,MAAM,CAAEd,QAAQ,IAAK,CAACA,QAAQ,CAACmB,OAAO,CAAC,CAAC,CAAC;MAC9C;MACAN,IAAI,CAAC5C,SAAS,GAAGmD,4BAAY,CAAC1D,SAAS,CAACiD,iBAAiB,CAAC;IAC5D,CAAC,CAAC;EACJ;AACF;AAACU,OAAA,CAAA7E,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -74,7 +74,7 @@ function _fsArtifact() {
|
|
|
74
74
|
};
|
|
75
75
|
return data;
|
|
76
76
|
}
|
|
77
|
-
function _interopRequireDefault(
|
|
77
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
78
78
|
const DEFAULT_CONTEXT = exports.DEFAULT_CONTEXT = 'component';
|
|
79
79
|
class ArtifactFactory {
|
|
80
80
|
resolvePaths(root, def) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_path","data","require","_globby","_interopRequireDefault","_lodash","_artifactFiles","_component","_utils","_storage","_artifactList","_exceptions","_fsArtifact","
|
|
1
|
+
{"version":3,"names":["_path","data","require","_globby","_interopRequireDefault","_lodash","_artifactFiles","_component","_utils","_storage","_artifactList","_exceptions","_fsArtifact","e","__esModule","default","DEFAULT_CONTEXT","exports","ArtifactFactory","resolvePaths","root","def","patternsFlattened","flatten","globPatterns","patternsFlattenedLinux","map","pathNormalizeToLinux","paths","globby","sync","cwd","getArtifactContextPath","context","component","artifactContext","getArtifactContext","capsulePath","capsuleNetwork","graphCapsules","getCapsule","id","path","CapsuleNotFound","capsulesRootDir","createFromComponent","task","contextPath","rootDir","getRootDir","length","undefined","FsArtifact","ArtifactFiles","getStorageResolver","storageResolver","DefaultResolver","toComponentMap","artifactMap","ComponentMap","as","components","toString","artifacts","filter","targetId","artifact","ArtifactList","fromArray","join","generate","defs","tupleArr","forEach","capsuleDir","push"],"sources":["artifact-factory.ts"],"sourcesContent":["import { join } from 'path';\nimport globby from 'globby';\nimport { flatten } from 'lodash';\nimport { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport { Component, ComponentMap } from '@teambit/component';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport { PathLinux } from '@teambit/legacy/dist/utils/path';\nimport { ArtifactDefinition } from './artifact-definition';\nimport { DefaultResolver } from '../storage';\nimport { ArtifactList } from './artifact-list';\nimport type { BuildContext, BuildTask } from '../build-task';\nimport { CapsuleNotFound } from '../exceptions';\nimport { FsArtifact } from './fs-artifact';\n\nexport const DEFAULT_CONTEXT = 'component';\n\nexport type ArtifactMap = ComponentMap<ArtifactList<FsArtifact>>;\n\nexport class ArtifactFactory {\n resolvePaths(root: string, def: ArtifactDefinition): string[] {\n const patternsFlattened = flatten(def.globPatterns);\n const patternsFlattenedLinux: PathLinux[] = patternsFlattened.map(pathNormalizeToLinux);\n const paths = globby.sync(patternsFlattenedLinux, { cwd: root });\n return paths;\n }\n\n private getArtifactContextPath(context: BuildContext, component: Component, def: ArtifactDefinition) {\n const artifactContext = this.getArtifactContext(def);\n if (artifactContext === 'component') {\n const capsulePath = context.capsuleNetwork.graphCapsules.getCapsule(component.id)?.path;\n if (!capsulePath) throw new CapsuleNotFound(component.id);\n return capsulePath;\n }\n\n return context.capsuleNetwork.capsulesRootDir;\n }\n\n private getArtifactContext(def: ArtifactDefinition) {\n return def.context || DEFAULT_CONTEXT;\n }\n\n createFromComponent(\n context: BuildContext,\n component: Component,\n def: ArtifactDefinition,\n task: BuildTask\n ): FsArtifact | undefined {\n const contextPath = this.getArtifactContextPath(context, component, def);\n const rootDir = this.getRootDir(contextPath, def);\n const paths = this.resolvePaths(rootDir, def);\n if (!paths || !paths.length) {\n return undefined;\n }\n return new FsArtifact(def, new ArtifactFiles(paths), task, rootDir);\n }\n\n private getStorageResolver(def: ArtifactDefinition) {\n return def.storageResolver || new DefaultResolver();\n }\n\n private toComponentMap(context: BuildContext, artifactMap: [string, FsArtifact][]) {\n return ComponentMap.as<ArtifactList<FsArtifact>>(context.components, (component) => {\n const id = component.id.toString();\n const artifacts = artifactMap.filter(([targetId]) => targetId === id).map(([, artifact]) => artifact);\n\n return ArtifactList.fromArray(artifacts);\n });\n }\n\n getRootDir(rootDir: string, def: ArtifactDefinition) {\n if (!def.rootDir) return rootDir;\n return join(rootDir, def.rootDir);\n }\n\n /**\n * generate artifacts from a build context according to the spec defined in the artifact definitions.\n */\n generate(context: BuildContext, defs: ArtifactDefinition[], task: BuildTask): ComponentMap<ArtifactList<FsArtifact>> {\n const tupleArr: [string, FsArtifact][] = [];\n\n defs.forEach((def) => {\n const artifactContext = this.getArtifactContext(def);\n if (artifactContext === 'env') {\n const capsuleDir = context.capsuleNetwork.capsulesRootDir;\n const rootDir = this.getRootDir(capsuleDir, def);\n const paths = this.resolvePaths(rootDir, def);\n if (paths && paths.length) {\n const artifact = new FsArtifact(def, new ArtifactFiles(this.resolvePaths(rootDir, def)), task, rootDir);\n\n return context.components.forEach((component) => {\n tupleArr.push([component.id.toString(), artifact]);\n });\n }\n }\n\n return context.components.forEach((component) => {\n const artifact = this.createFromComponent(context, component, def, task);\n if (artifact) {\n tupleArr.push([component.id.toString(), artifact]);\n }\n });\n });\n\n return this.toComponentMap(context, tupleArr);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;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,CAAC6B,OAAO,EAAE3B,GAAG,CAAC;QAC7C,IAAIO,KAAK,IAAIA,KAAK,CAACsB,MAAM,EAAE;UACzB,MAAMgB,QAAQ,GAAG,KAAId,wBAAU,EAAC/B,GAAG,EAAE,KAAIgC,8BAAa,EAAC,IAAI,CAAClC,YAAY,CAAC6B,OAAO,EAAE3B,GAAG,CAAC,CAAC,EAAEyB,IAAI,EAAEE,OAAO,CAAC;UAEvG,OAAOf,OAAO,CAAC4B,UAAU,CAACY,OAAO,CAAEvC,SAAS,IAAK;YAC/CsC,QAAQ,CAACG,IAAI,CAAC,CAACzC,SAAS,CAACO,EAAE,CAACqB,QAAQ,CAAC,CAAC,EAAEI,QAAQ,CAAC,CAAC;UACpD,CAAC,CAAC;QACJ;MACF;MAEA,OAAOjC,OAAO,CAAC4B,UAAU,CAACY,OAAO,CAAEvC,SAAS,IAAK;QAC/C,MAAMgC,QAAQ,GAAG,IAAI,CAACrB,mBAAmB,CAACZ,OAAO,EAAEC,SAAS,EAAEb,GAAG,EAAEyB,IAAI,CAAC;QACxE,IAAIoB,QAAQ,EAAE;UACZM,QAAQ,CAACG,IAAI,CAAC,CAACzC,SAAS,CAACO,EAAE,CAACqB,QAAQ,CAAC,CAAC,EAAEI,QAAQ,CAAC,CAAC;QACpD;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI,CAACT,cAAc,CAACxB,OAAO,EAAEuC,QAAQ,CAAC;EAC/C;AACF;AAACvD,OAAA,CAAAC,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -25,7 +25,7 @@ function _storage() {
|
|
|
25
25
|
};
|
|
26
26
|
return data;
|
|
27
27
|
}
|
|
28
|
-
function _interopRequireDefault(
|
|
28
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
29
|
class ArtifactList extends Array {
|
|
30
30
|
byAspectNameAndName(aspectName, name) {
|
|
31
31
|
const filtered = this.filter(artifact => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_pMapSeries","data","_interopRequireDefault","require","_artifact","_storage","obj","__esModule","default","ArtifactList","Array","byAspectNameAndName","aspectName","name","filtered","filter","artifact","cond","task","aspectId","fromArray","byAspectNameAndTaskName","findByName","find","findByTaskName","isEmpty","every","files","groupByResolver","resolverMap","forEach","storageResolver","resolverArray","length","push","toObject","map","groupByTaskId","reduce","acc","taskId","getVinylsAndImportIfMissing","id","scope","vinyls","pMapSeries","flat","store","component","byResolvers","promises","Object","keys","key","artifacts","artifactList","artifactPromises","storeArtifact","Promise","all","defaultResolver","DefaultResolver","storeWholeArtifactByResolver","storeArtifactFilesByResolver","results","file","url","relative","storeFile","fromArtifactObjects","artifactObjects","object","Artifact","fromArtifactObject","exports"],"sources":["artifact-list.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport pMapSeries from 'p-map-series';\nimport type { ArtifactObject } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport { ComponentID } from '@teambit/component-id';\nimport { Scope } from '@teambit/legacy/dist/scope';\nimport { ArtifactVinyl } from '@teambit/legacy/dist/consumer/component/sources/artifact';\nimport { FsArtifact } from './fs-artifact';\nimport { Artifact } from './artifact';\nimport {\n ArtifactStorageResolver,\n FileStorageResolver,\n WholeArtifactStorageResolver,\n DefaultResolver,\n} from '../storage';\n\nexport type ResolverMap<T extends Artifact> = { [key: string]: T[] };\n\nexport class ArtifactList<T extends Artifact> extends Array<T> {\n byAspectNameAndName(aspectName?: string, name?: string): ArtifactList<T> {\n const filtered = this.filter((artifact) => {\n let cond = true;\n if (aspectName) {\n cond = cond && artifact.task.aspectId === aspectName;\n }\n if (name) {\n cond = cond && artifact.name === name;\n }\n return cond;\n });\n return ArtifactList.fromArray(filtered);\n }\n\n byAspectNameAndTaskName(aspectName?: string, name?: string): ArtifactList<T> {\n const filtered = this.filter((artifact) => {\n let cond = true;\n if (aspectName) {\n cond = cond && artifact.task.aspectId === aspectName;\n }\n if (name) {\n cond = cond && artifact.task.name === name;\n }\n return cond;\n });\n return ArtifactList.fromArray(filtered);\n }\n\n /**\n * find by the artifact name. it's possible to have multiple artifacts with the same name, in which case it returns the first.\n */\n findByName(name: string): Artifact | undefined {\n return this.find((artifact) => artifact.name === name);\n }\n\n /**\n * find by the task name. it's possible to have multiple tasks with the same name (different aspects), in which case it returns the first.\n */\n findByTaskName(name: string): Artifact | undefined {\n return this.find((artifact) => artifact.task.name === name);\n }\n\n isEmpty(): boolean {\n return this.every((artifact) => artifact.files.isEmpty());\n }\n\n /**\n * group artifacts by the storage resolver.\n */\n groupByResolver(): ResolverMap<T> {\n const resolverMap: ResolverMap<T> = {};\n this.forEach((artifact) => {\n const storageResolver = artifact.storageResolver;\n const resolverArray = resolverMap[storageResolver.name];\n if (!resolverArray) {\n resolverMap[storageResolver.name] = [artifact];\n return;\n }\n if (resolverArray.length) {\n resolverMap[storageResolver.name].push(artifact);\n }\n });\n\n return resolverMap;\n }\n\n toObject(): ArtifactObject[] {\n return this.map((artifact) => artifact.toObject());\n }\n\n groupByTaskId() {\n return this.reduce((acc: { [key: string]: T }, artifact) => {\n const taskId = artifact.task.aspectId;\n acc[taskId] = artifact;\n return acc;\n }, {});\n }\n\n async getVinylsAndImportIfMissing(id: ComponentID, scope: Scope): Promise<ArtifactVinyl[]> {\n if (this.isEmpty()) return [];\n const vinyls = await pMapSeries(this, (artifact) => artifact.files.getVinylsAndImportIfMissing(id, scope));\n return vinyls.flat();\n }\n\n /**\n * store all artifacts using the configured storage resolvers.\n */\n async store(component: Component) {\n const byResolvers = this.groupByResolver();\n const promises = Object.keys(byResolvers).map(async (key) => {\n const artifacts = byResolvers[key];\n if (!artifacts.length) return;\n const storageResolver = artifacts[0].storageResolver;\n const artifactList = ArtifactList.fromArray(artifacts);\n const artifactPromises = artifactList.map(async (artifact) => {\n return this.storeArtifact(storageResolver, artifact, component);\n });\n await Promise.all(artifactPromises);\n });\n\n return Promise.all(promises);\n }\n\n private async storeArtifact(storageResolver: ArtifactStorageResolver, artifact: Artifact, component: Component) {\n // For now we are always storing also using the default resolver\n if (storageResolver.name !== 'default') {\n const defaultResolver = new DefaultResolver();\n await defaultResolver.store(component, artifact as FsArtifact);\n }\n // @ts-ignore\n if (storageResolver.store && typeof storageResolver.store === 'function') {\n return this.storeWholeArtifactByResolver(storageResolver as WholeArtifactStorageResolver, artifact, component);\n }\n return this.storeArtifactFilesByResolver(storageResolver as FileStorageResolver, artifact, component);\n }\n\n /**\n * Send the entire artifact to the resolver then get back the result for all files from the resolver\n * @param storageResolver\n * @param artifact\n * @param component\n */\n private async storeWholeArtifactByResolver(\n storageResolver: WholeArtifactStorageResolver,\n artifact: Artifact,\n component: Component\n ) {\n const results = await storageResolver.store(component, artifact as FsArtifact);\n if (!results) return;\n artifact.files.vinyls.map((file) => {\n const url = results[file.relative];\n if (url) {\n file.url = url;\n }\n });\n }\n\n /**\n * Go over the artifact files and send them to the resolver one by one\n * @param storageResolver\n * @param artifact\n * @param component\n */\n private storeArtifactFilesByResolver(storageResolver: FileStorageResolver, artifact: Artifact, component: Component) {\n const promises = artifact.files.vinyls.map(async (file) => {\n const url = await storageResolver.storeFile(component, artifact as FsArtifact, file);\n if (url) {\n file.url = url;\n }\n });\n return Promise.all(promises);\n }\n\n static fromArtifactObjects(artifactObjects: ArtifactObject[]): ArtifactList<Artifact> {\n const artifacts = artifactObjects.map((object) => Artifact.fromArtifactObject(object));\n return ArtifactList.fromArray(artifacts);\n }\n\n static fromArray<T extends Artifact>(artifacts: T[]) {\n return new ArtifactList(...artifacts);\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAA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AG;MAChB;IACF,CAAC,CAAC;IACF,OAAOR,OAAO,CAACC,GAAG,CAACT,QAAQ,CAAC;EAC9B;EAEA,OAAOmB,mBAAmBA,CAACC,eAAiC,EAA0B;IACpF,MAAMhB,SAAS,GAAGgB,eAAe,CAAClC,GAAG,CAAEmC,MAAM,IAAKC,oBAAQ,CAACC,kBAAkB,CAACF,MAAM,CAAC,CAAC;IACtF,OAAO9D,YAAY,CAACW,SAAS,CAACkC,SAAS,CAAC;EAC1C;EAEA,OAAOlC,SAASA,CAAqBkC,SAAc,EAAE;IACnD,OAAO,IAAI7C,YAAY,CAAC,GAAG6C,SAAS,CAAC;EACvC;AACF;AAACoB,OAAA,CAAAjE,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_pMapSeries","data","_interopRequireDefault","require","_artifact","_storage","e","__esModule","default","ArtifactList","Array","byAspectNameAndName","aspectName","name","filtered","filter","artifact","cond","task","aspectId","fromArray","byAspectNameAndTaskName","findByName","find","findByTaskName","isEmpty","every","files","groupByResolver","resolverMap","forEach","storageResolver","resolverArray","length","push","toObject","map","groupByTaskId","reduce","acc","taskId","getVinylsAndImportIfMissing","id","scope","vinyls","pMapSeries","flat","store","component","byResolvers","promises","Object","keys","key","artifacts","artifactList","artifactPromises","storeArtifact","Promise","all","defaultResolver","DefaultResolver","storeWholeArtifactByResolver","storeArtifactFilesByResolver","results","file","url","relative","storeFile","fromArtifactObjects","artifactObjects","object","Artifact","fromArtifactObject","exports"],"sources":["artifact-list.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport pMapSeries from 'p-map-series';\nimport type { ArtifactObject } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport { ComponentID } from '@teambit/component-id';\nimport { Scope } from '@teambit/legacy/dist/scope';\nimport { ArtifactVinyl } from '@teambit/legacy/dist/consumer/component/sources/artifact';\nimport { FsArtifact } from './fs-artifact';\nimport { Artifact } from './artifact';\nimport {\n ArtifactStorageResolver,\n FileStorageResolver,\n WholeArtifactStorageResolver,\n DefaultResolver,\n} from '../storage';\n\nexport type ResolverMap<T extends Artifact> = { [key: string]: T[] };\n\nexport class ArtifactList<T extends Artifact> extends Array<T> {\n byAspectNameAndName(aspectName?: string, name?: string): ArtifactList<T> {\n const filtered = this.filter((artifact) => {\n let cond = true;\n if (aspectName) {\n cond = cond && artifact.task.aspectId === aspectName;\n }\n if (name) {\n cond = cond && artifact.name === name;\n }\n return cond;\n });\n return ArtifactList.fromArray(filtered);\n }\n\n byAspectNameAndTaskName(aspectName?: string, name?: string): ArtifactList<T> {\n const filtered = this.filter((artifact) => {\n let cond = true;\n if (aspectName) {\n cond = cond && artifact.task.aspectId === aspectName;\n }\n if (name) {\n cond = cond && artifact.task.name === name;\n }\n return cond;\n });\n return ArtifactList.fromArray(filtered);\n }\n\n /**\n * find by the artifact name. it's possible to have multiple artifacts with the same name, in which case it returns the first.\n */\n findByName(name: string): Artifact | undefined {\n return this.find((artifact) => artifact.name === name);\n }\n\n /**\n * find by the task name. it's possible to have multiple tasks with the same name (different aspects), in which case it returns the first.\n */\n findByTaskName(name: string): Artifact | undefined {\n return this.find((artifact) => artifact.task.name === name);\n }\n\n isEmpty(): boolean {\n return this.every((artifact) => artifact.files.isEmpty());\n }\n\n /**\n * group artifacts by the storage resolver.\n */\n groupByResolver(): ResolverMap<T> {\n const resolverMap: ResolverMap<T> = {};\n this.forEach((artifact) => {\n const storageResolver = artifact.storageResolver;\n const resolverArray = resolverMap[storageResolver.name];\n if (!resolverArray) {\n resolverMap[storageResolver.name] = [artifact];\n return;\n }\n if (resolverArray.length) {\n resolverMap[storageResolver.name].push(artifact);\n }\n });\n\n return resolverMap;\n }\n\n toObject(): ArtifactObject[] {\n return this.map((artifact) => artifact.toObject());\n }\n\n groupByTaskId() {\n return this.reduce((acc: { [key: string]: T }, artifact) => {\n const taskId = artifact.task.aspectId;\n acc[taskId] = artifact;\n return acc;\n }, {});\n }\n\n async getVinylsAndImportIfMissing(id: ComponentID, scope: Scope): Promise<ArtifactVinyl[]> {\n if (this.isEmpty()) return [];\n const vinyls = await pMapSeries(this, (artifact) => artifact.files.getVinylsAndImportIfMissing(id, scope));\n return vinyls.flat();\n }\n\n /**\n * store all artifacts using the configured storage resolvers.\n */\n async store(component: Component) {\n const byResolvers = this.groupByResolver();\n const promises = Object.keys(byResolvers).map(async (key) => {\n const artifacts = byResolvers[key];\n if (!artifacts.length) return;\n const storageResolver = artifacts[0].storageResolver;\n const artifactList = ArtifactList.fromArray(artifacts);\n const artifactPromises = artifactList.map(async (artifact) => {\n return this.storeArtifact(storageResolver, artifact, component);\n });\n await Promise.all(artifactPromises);\n });\n\n return Promise.all(promises);\n }\n\n private async storeArtifact(storageResolver: ArtifactStorageResolver, artifact: Artifact, component: Component) {\n // For now we are always storing also using the default resolver\n if (storageResolver.name !== 'default') {\n const defaultResolver = new DefaultResolver();\n await defaultResolver.store(component, artifact as FsArtifact);\n }\n // @ts-ignore\n if (storageResolver.store && typeof storageResolver.store === 'function') {\n return this.storeWholeArtifactByResolver(storageResolver as WholeArtifactStorageResolver, artifact, component);\n }\n return this.storeArtifactFilesByResolver(storageResolver as FileStorageResolver, artifact, component);\n }\n\n /**\n * Send the entire artifact to the resolver then get back the result for all files from the resolver\n * @param storageResolver\n * @param artifact\n * @param component\n */\n private async storeWholeArtifactByResolver(\n storageResolver: WholeArtifactStorageResolver,\n artifact: Artifact,\n component: Component\n ) {\n const results = await storageResolver.store(component, artifact as FsArtifact);\n if (!results) return;\n artifact.files.vinyls.map((file) => {\n const url = results[file.relative];\n if (url) {\n file.url = url;\n }\n });\n }\n\n /**\n * Go over the artifact files and send them to the resolver one by one\n * @param storageResolver\n * @param artifact\n * @param component\n */\n private storeArtifactFilesByResolver(storageResolver: FileStorageResolver, artifact: Artifact, component: Component) {\n const promises = artifact.files.vinyls.map(async (file) => {\n const url = await storageResolver.storeFile(component, artifact as FsArtifact, file);\n if (url) {\n file.url = url;\n }\n });\n return Promise.all(promises);\n }\n\n static fromArtifactObjects(artifactObjects: ArtifactObject[]): ArtifactList<Artifact> {\n const artifacts = artifactObjects.map((object) => Artifact.fromArtifactObject(object));\n return ArtifactList.fromArray(artifacts);\n }\n\n static fromArray<T extends Artifact>(artifacts: T[]) {\n return new ArtifactList(...artifacts);\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAKoB,SAAAC,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIb,MAAMG,YAAY,SAA6BC,KAAK,CAAI;EAC7DC,mBAAmBA,CAACC,UAAmB,EAAEC,IAAa,EAAmB;IACvE,MAAMC,QAAQ,GAAG,IAAI,CAACC,MAAM,CAAEC,QAAQ,IAAK;MACzC,IAAIC,IAAI,GAAG,IAAI;MACf,IAAIL,UAAU,EAAE;QACdK,IAAI,GAAGA,IAAI,IAAID,QAAQ,CAACE,IAAI,CAACC,QAAQ,KAAKP,UAAU;MACtD;MACA,IAAIC,IAAI,EAAE;QACRI,IAAI,GAAGA,IAAI,IAAID,QAAQ,CAACH,IAAI,KAAKA,IAAI;MACvC;MACA,OAAOI,IAAI;IACb,CAAC,CAAC;IACF,OAAOR,YAAY,CAACW,SAAS,CAACN,QAAQ,CAAC;EACzC;EAEAO,uBAAuBA,CAACT,UAAmB,EAAEC,IAAa,E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,CAAC;MAClC,IAAID,GAAG,EAAE;QACPD,IAAI,CAACC,GAAG,GAAGA,GAAG;MAChB;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;EACUH,4BAA4BA,CAAChC,eAAoC,EAAEf,QAAkB,EAAEgC,SAAoB,EAAE;IACnH,MAAME,QAAQ,GAAGlC,QAAQ,CAACW,KAAK,CAACiB,MAAM,CAACR,GAAG,CAAC,MAAO6B,IAAI,IAAK;MACzD,MAAMC,GAAG,GAAG,MAAMnC,eAAe,CAACqC,SAAS,CAACpB,SAAS,EAAEhC,QAAQ,EAAgBiD,IAAI,CAAC;MACpF,IAAIC,GAAG,EAAE;QACPD,IAAI,CAACC,GAAG,GAAGA,GAAG;MAChB;IACF,CAAC,CAAC;IACF,OAAOR,OAAO,CAACC,GAAG,CAACT,QAAQ,CAAC;EAC9B;EAEA,OAAOmB,mBAAmBA,CAACC,eAAiC,EAA0B;IACpF,MAAMhB,SAAS,GAAGgB,eAAe,CAAClC,GAAG,CAAEmC,MAAM,IAAKC,oBAAQ,CAACC,kBAAkB,CAACF,MAAM,CAAC,CAAC;IACtF,OAAO9D,YAAY,CAACW,SAAS,CAACkC,SAAS,CAAC;EAC1C;EAEA,OAAOlC,SAASA,CAAqBkC,SAAc,EAAE;IACnD,OAAO,IAAI7C,YAAY,CAAC,GAAG6C,SAAS,CAAC;EACvC;AACF;AAACoB,OAAA,CAAAjE,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_defaultResolver","data","require","Artifact","constructor","def","files","task","timestamp","Date","now","storage","storageResolver","name","DefaultResolver","description","generatedBy","aspectId","artifactDir","rootDir","pathsLinux","paths","map","p","replace","firstPath","includes","undefined","potentialSharedDir","split","isSharedDir","every","startsWith","isEmpty","tar","toObject","id","fromArtifactObject","object","artifactDef","exports"],"sources":["artifact.ts"],"sourcesContent":["import type { ArtifactFiles, ArtifactObject } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport type { TaskDescriptor } from '../build-task';\nimport type { ArtifactDefinition } from './artifact-definition';\nimport { DefaultResolver } from '../storage/default-resolver';\n\nexport class Artifact {\n constructor(\n /**\n * definition of the artifact.\n */\n readonly def: ArtifactDefinition,\n\n readonly files: ArtifactFiles,\n /**\n * the declaring task.\n */\n readonly task: TaskDescriptor,\n /**\n * timestamp of the artifact creation.\n */\n readonly timestamp: number = Date.now()\n ) {}\n\n get storage() {\n return this.storageResolver.name;\n }\n\n get storageResolver() {\n return this.def.storageResolver || new DefaultResolver();\n }\n\n /**\n * name of the artifact.\n */\n get name(): string {\n return this.def.name;\n }\n\n /**\n * description of the artifact.\n */\n get description() {\n return this.def.description;\n }\n\n /**\n * aspect id (string) that generated the artifact\n */\n get generatedBy(): string {\n return this.def.generatedBy || this.task.aspectId;\n }\n\n /**\n * calculate what could possibly be the root directory of the artifact.\n * in case the deprecated rootDir is set, use it.\n * otherwise, get the common first directory of all files.\n * if there is no common directory, or there are multiple directories return undefined.\n */\n get artifactDir(): string | undefined {\n if (this.def.rootDir) return this.def.rootDir;\n\n // not sure if needed, it's unclear whether the paths are OS specific or not. (coming from globby).\n const pathsLinux = this.files.paths.map((p) => p.replace(/\\\\/g, '/'));\n // get the common dir of all paths.\n const firstPath = pathsLinux[0];\n // it's a file in the root, so there is no shared root directory.\n if (!firstPath.includes('/')) return undefined;\n const [potentialSharedDir] = firstPath.split('/');\n const isSharedDir = pathsLinux.every((p) => p.startsWith(`${potentialSharedDir}/`));\n if (!isSharedDir) return undefined;\n return potentialSharedDir;\n }\n\n isEmpty(): boolean {\n return this.files.isEmpty();\n }\n\n /**\n * archive all artifact files into a tar.\n */\n tar() {}\n\n toObject(): ArtifactObject {\n return {\n name: this.name,\n description: this.description,\n generatedBy: this.generatedBy,\n storage: this.storageResolver.name,\n task: {\n id: this.task.aspectId,\n name: this.task.name,\n },\n files: this.files,\n };\n }\n\n static fromArtifactObject(object: ArtifactObject): Artifact {\n const artifactDef: ArtifactDefinition = {\n name: object.name,\n generatedBy: object.generatedBy,\n description: object.description,\n };\n\n const task: TaskDescriptor = {\n aspectId: object.task.id,\n name: object.task.name,\n };\n\n return new Artifact(artifactDef, object.files, task);\n }\n}\n"],"mappings":";;;;;;AAGA,SAAAA,iBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,gBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,MAAME,QAAQ,CAAC;EACpBC,WAAWA;EACT;AACJ;AACA;EACaC,GAAuB,EAEvBC,KAAoB;EAC7B;AACJ;AACA;EACaC,IAAoB;EAC7B;AACJ;AACA;EACaC,SAAiB,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EACvC;IAAA,KAXSL,GAAuB,GAAvBA,GAAuB;IAAA,KAEvBC,KAAoB,GAApBA,KAAoB;IAAA,KAIpBC,IAAoB,GAApBA,IAAoB;IAAA,KAIpBC,SAAiB,GAAjBA,SAAiB;EACzB;EAEH,IAAIG,OAAOA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACC,eAAe,CAACC,IAAI;EAClC;EAEA,IAAID,eAAeA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACP,GAAG,CAACO,eAAe,IAAI,KAAIE,kCAAe,EAAC,CAAC;EAC1D;;EAEA;AACF;AACA;EACE,IAAID,IAAIA,CAAA,EAAW;IACjB,OAAO,IAAI,CAACR,GAAG,CAACQ,IAAI;EACtB;;EAEA;AACF;AACA;EACE,IAAIE,WAAWA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACV,GAAG,CAACU,WAAW;EAC7B;;EAEA;AACF;AACA;EACE,IAAIC,WAAWA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACX,GAAG,CAACW,WAAW,IAAI,IAAI,CAACT,IAAI,CAACU,QAAQ;EACnD;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,IAAIC,WAAWA,CAAA,EAAuB;IACpC,IAAI,IAAI,CAACb,GAAG,CAACc,OAAO,EAAE,OAAO,IAAI,CAACd,GAAG,CAACc,OAAO;;IAE7C;IACA,MAAMC,UAAU,GAAG,IAAI,CAACd,KAAK,CAACe,KAAK,CAACC,GAAG,CAAEC,CAAC,IAAKA,CAAC,CAACC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACrE;IACA,MAAMC,SAAS,GAAGL,UAAU,CAAC,CAAC,CAAC;IAC/B;IACA,IAAI,CAACK,SAAS,CAACC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAOC,SAAS;IAC9C,MAAM,CAACC,kBAAkB,CAAC,GAAGH,SAAS,CAACI,KAAK,CAAC,GAAG,CAAC;IACjD,MAAMC,WAAW,GAAGV,UAAU,CAACW,KAAK,CAAER,CAAC,IAAKA,CAAC,CAACS,UAAU,
|
|
1
|
+
{"version":3,"names":["_defaultResolver","data","require","Artifact","constructor","def","files","task","timestamp","Date","now","storage","storageResolver","name","DefaultResolver","description","generatedBy","aspectId","artifactDir","rootDir","pathsLinux","paths","map","p","replace","firstPath","includes","undefined","potentialSharedDir","split","isSharedDir","every","startsWith","isEmpty","tar","toObject","id","fromArtifactObject","object","artifactDef","exports"],"sources":["artifact.ts"],"sourcesContent":["import type { ArtifactFiles, ArtifactObject } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport type { TaskDescriptor } from '../build-task';\nimport type { ArtifactDefinition } from './artifact-definition';\nimport { DefaultResolver } from '../storage/default-resolver';\n\nexport class Artifact {\n constructor(\n /**\n * definition of the artifact.\n */\n readonly def: ArtifactDefinition,\n\n readonly files: ArtifactFiles,\n /**\n * the declaring task.\n */\n readonly task: TaskDescriptor,\n /**\n * timestamp of the artifact creation.\n */\n readonly timestamp: number = Date.now()\n ) {}\n\n get storage() {\n return this.storageResolver.name;\n }\n\n get storageResolver() {\n return this.def.storageResolver || new DefaultResolver();\n }\n\n /**\n * name of the artifact.\n */\n get name(): string {\n return this.def.name;\n }\n\n /**\n * description of the artifact.\n */\n get description() {\n return this.def.description;\n }\n\n /**\n * aspect id (string) that generated the artifact\n */\n get generatedBy(): string {\n return this.def.generatedBy || this.task.aspectId;\n }\n\n /**\n * calculate what could possibly be the root directory of the artifact.\n * in case the deprecated rootDir is set, use it.\n * otherwise, get the common first directory of all files.\n * if there is no common directory, or there are multiple directories return undefined.\n */\n get artifactDir(): string | undefined {\n if (this.def.rootDir) return this.def.rootDir;\n\n // not sure if needed, it's unclear whether the paths are OS specific or not. (coming from globby).\n const pathsLinux = this.files.paths.map((p) => p.replace(/\\\\/g, '/'));\n // get the common dir of all paths.\n const firstPath = pathsLinux[0];\n // it's a file in the root, so there is no shared root directory.\n if (!firstPath.includes('/')) return undefined;\n const [potentialSharedDir] = firstPath.split('/');\n const isSharedDir = pathsLinux.every((p) => p.startsWith(`${potentialSharedDir}/`));\n if (!isSharedDir) return undefined;\n return potentialSharedDir;\n }\n\n isEmpty(): boolean {\n return this.files.isEmpty();\n }\n\n /**\n * archive all artifact files into a tar.\n */\n tar() {}\n\n toObject(): ArtifactObject {\n return {\n name: this.name,\n description: this.description,\n generatedBy: this.generatedBy,\n storage: this.storageResolver.name,\n task: {\n id: this.task.aspectId,\n name: this.task.name,\n },\n files: this.files,\n };\n }\n\n static fromArtifactObject(object: ArtifactObject): Artifact {\n const artifactDef: ArtifactDefinition = {\n name: object.name,\n generatedBy: object.generatedBy,\n description: object.description,\n };\n\n const task: TaskDescriptor = {\n aspectId: object.task.id,\n name: object.task.name,\n };\n\n return new Artifact(artifactDef, object.files, task);\n }\n}\n"],"mappings":";;;;;;AAGA,SAAAA,iBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,gBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,MAAME,QAAQ,CAAC;EACpBC,WAAWA;EACT;AACJ;AACA;EACaC,GAAuB,EAEvBC,KAAoB;EAC7B;AACJ;AACA;EACaC,IAAoB;EAC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
@@ -25,8 +25,8 @@ function _artifactExtractor() {
|
|
|
25
25
|
};
|
|
26
26
|
return data;
|
|
27
27
|
}
|
|
28
|
-
function _interopRequireDefault(
|
|
29
|
-
function _defineProperty(
|
|
28
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
30
30
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
31
31
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
32
32
|
const INDENT_TITLE = ' '.repeat(2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_chalk","data","_interopRequireDefault","require","_constants","_artifactExtractor","
|
|
1
|
+
{"version":3,"names":["_chalk","data","_interopRequireDefault","require","_constants","_artifactExtractor","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","INDENT_TITLE","repeat","INDENT_SUB_TITLE","INDENT_FILES","ArtifactsCmd","constructor","builder","componentMain","name","description","COMPONENT_PATTERN_HELP","report","componentPattern","artifactsOpts","artifactExtractor","ArtifactExtractor","list","grouped","groupResultsByAspect","outputArtifacts","aspectId","artifactData","title","chalk","green","artifactDataStr","map","artifact","subTitle","white","taskName","artifactName","files","f","dim","join","outputResult","result","idStr","cyan","id","toString","artifacts","keys","footer","outDir","exports"],"sources":["artifacts.cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { COMPONENT_PATTERN_HELP } from '@teambit/legacy/dist/constants';\nimport { ComponentMain } from '@teambit/component';\nimport { BuilderMain } from '../builder.main.runtime';\nimport { ArtifactExtractor, ExtractorArtifactResult, ExtractorResultGrouped } from './artifact-extractor';\n\nconst INDENT_TITLE = ' '.repeat(2);\nconst INDENT_SUB_TITLE = ' '.repeat(4);\nconst INDENT_FILES = ' '.repeat(6);\n\nexport type ArtifactsOpts = {\n aspect?: string;\n task?: string;\n files?: string;\n outDir?: string;\n};\n\nexport class ArtifactsCmd implements Command {\n name = 'artifacts <component-pattern>';\n description = 'list and download component artifacts';\n extendedDescription = `artifacts are created on isolated capsules during tag or snap commands.\nexample of artifacts are dists files generated by a compiler, a JUnit.xml file generated by a tester\nand a package.tgz file generated by pkg aspect.\n`;\n arguments = [\n {\n name: 'component-pattern',\n description: COMPONENT_PATTERN_HELP,\n },\n ];\n alias = '';\n group = 'development';\n helpUrl = 'reference/components/component-artifacts';\n options = [\n ['', 'aspect <aspect-id>', 'show/download only artifacts generated by this aspect-id'],\n ['', 'task <task-id>', 'show/download only artifacts generated by this task-id'],\n [\n '',\n 'files <glob>',\n 'show/download only artifacts matching the given files or the glob pattern (wrap glob patterns in quotes)',\n ],\n ['', 'out-dir <string>', 'download the files to the specified dir'],\n ] as CommandOptions;\n\n constructor(private builder: BuilderMain, private componentMain: ComponentMain) {}\n\n async report([componentPattern]: [string], artifactsOpts: ArtifactsOpts): Promise<string> {\n const artifactExtractor = new ArtifactExtractor(this.componentMain, this.builder, componentPattern, artifactsOpts);\n const list = await artifactExtractor.list();\n const grouped = artifactExtractor.groupResultsByAspect(list);\n const outputArtifacts = (aspectId: string, artifactData: ExtractorArtifactResult[]) => {\n const title = chalk.green(aspectId);\n const artifactDataStr = artifactData\n .map((artifact) => {\n const subTitle = chalk.white(`${artifact.taskName} (${artifact.artifactName})`);\n const files = artifact.files.map((f) => INDENT_FILES + chalk.dim(f)).join('\\n');\n return `${INDENT_SUB_TITLE}${subTitle}\\n${files}`;\n })\n .join('\\n');\n return `${INDENT_TITLE}${title}\\n${artifactDataStr}`;\n };\n const outputResult = (result: ExtractorResultGrouped) => {\n const idStr = chalk.cyan(result.id.toString());\n const artifacts = Object.keys(result.artifacts)\n .map((aspectId) => outputArtifacts(aspectId, result.artifacts[aspectId]))\n .join('\\n\\n');\n return `${idStr}\\n${artifacts}`;\n };\n const footer = artifactsOpts.outDir\n ? chalk.green('\\n\\nThe above files were saved successfully to the file system')\n : '';\n return grouped.map(outputResult).join('\\n\\n') + footer;\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,WAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAI,mBAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,kBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA0G,SAAAC,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,gBAAAH,CAAA,EAAAI,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAJ,CAAA,GAAAO,MAAA,CAAAC,cAAA,CAAAR,CAAA,EAAAI,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAZ,CAAA,CAAAI,CAAA,IAAAC,CAAA,EAAAL,CAAA;AAAA,SAAAM,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAA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QAAQ,CAAC,CAAC,CAAC,CACxEe,IAAI,CAAC,MAAM,CAAC;MACf,OAAO,GAAGG,KAAK,KAAKI,SAAS,EAAE;IACjC,CAAC;IACD,MAAME,MAAM,GAAG/B,aAAa,CAACgC,MAAM,GAC/BtB,gBAAK,CAACC,KAAK,CAAC,gEAAgE,CAAC,GAC7E,EAAE;IACN,OAAOP,OAAO,CAACS,GAAG,CAACU,YAAY,CAAC,CAACD,IAAI,CAAC,MAAM,CAAC,GAAGS,MAAM;EACxD;AACF;AAACE,OAAA,CAAA1C,YAAA,GAAAA,YAAA","ignoreList":[]}
|
package/dist/build-pipe.js
CHANGED
|
@@ -53,8 +53,8 @@ function _taskResultsList() {
|
|
|
53
53
|
};
|
|
54
54
|
return data;
|
|
55
55
|
}
|
|
56
|
-
function _interopRequireDefault(
|
|
57
|
-
function _defineProperty(
|
|
56
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
57
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
58
58
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
59
59
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
60
60
|
class BuildPipe {
|