@teambit/builder 0.0.555 → 0.0.559

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.
@@ -3,6 +3,7 @@ import { Logger } from '@teambit/logger';
3
3
  import { Workspace } from '@teambit/workspace';
4
4
  import { BuilderMain } from './builder.main.runtime';
5
5
  declare type BuildOpts = {
6
+ all: boolean;
6
7
  rebuild: boolean;
7
8
  install: boolean;
8
9
  cachePackagesOnCapsulesRoot: boolean;
@@ -20,7 +21,7 @@ export declare class BuilderCmd implements Command {
20
21
  group: string;
21
22
  options: CommandOptions;
22
23
  constructor(builder: BuilderMain, workspace: Workspace, logger: Logger);
23
- report([userPattern]: [string], { install, cachePackagesOnCapsulesRoot, reuseCapsules, tasks, listTasks }: BuildOpts): Promise<string>;
24
+ report([userPattern]: [string], { all, install, cachePackagesOnCapsulesRoot, reuseCapsules, tasks, listTasks, }: BuildOpts): Promise<string>;
24
25
  private getListTasks;
25
26
  }
26
27
  export {};
package/dist/build.cmd.js CHANGED
@@ -54,11 +54,12 @@ class BuilderCmd {
54
54
  (0, _defineProperty2().default)(this, "description", 'run set of tasks for build');
55
55
  (0, _defineProperty2().default)(this, "alias", '');
56
56
  (0, _defineProperty2().default)(this, "group", 'development');
57
- (0, _defineProperty2().default)(this, "options", [['', 'install', 'install core aspects in capsules'], ['', 'reuse-capsules', 'avoid deleting the capsules root-dir before starting the build'], ['', 'tasks <string>', `build the specified task(s) only. for multiple tasks, separate by a comma and wrap with quotes.
57
+ (0, _defineProperty2().default)(this, "options", [['a', 'all', 'build all components, not only modified and new'], ['', 'install', 'install core aspects in capsules'], ['', 'reuse-capsules', 'avoid deleting the capsules root-dir before starting the build'], ['', 'tasks <string>', `build the specified task(s) only. for multiple tasks, separate by a comma and wrap with quotes.
58
58
  specify the task-name (e.g. "TypescriptCompiler") or the task-aspect-id (e.g. teambit.compilation/compiler)`], ['', 'cache-packages-on-capsule-root', 'set the package-manager cache on the capsule root'], ['', 'list-tasks <string>', 'list tasks of an env or a component-id for each one of the pipelines: build, tag and snap']]);
59
59
  }
60
60
 
61
61
  async report([userPattern], {
62
+ all = false,
62
63
  install = false,
63
64
  cachePackagesOnCapsulesRoot = false,
64
65
  reuseCapsules = false,
@@ -72,8 +73,13 @@ specify the task-name (e.g. "TypescriptCompiler") or the task-aspect-id (e.g. te
72
73
  }
73
74
 
74
75
  const longProcessLogger = this.logger.createLongProcessLogger('build');
75
- const pattern = userPattern && userPattern.toString();
76
- const components = pattern ? await this.workspace.byPattern(pattern) : await this.workspace.list();
76
+ const components = await this.workspace.getComponentsByUserInputDefaultToChanged(all, userPattern);
77
+
78
+ if (!components.length) {
79
+ return _chalk().default.bold(`no components found to build. use "--all" flag to build all components or specify the ids to build, otherwise, only new and modified components will be built`);
80
+ }
81
+
82
+ this.logger.consoleSuccess(`found ${components.length} components to build`);
77
83
  const envsExecutionResults = await this.builder.build(components, {
78
84
  installOptions: {
79
85
  installTeambitBit: install
@@ -1 +1 @@
1
- {"version":3,"sources":["build.cmd.ts"],"names":["BuilderCmd","constructor","builder","workspace","logger","report","userPattern","install","cachePackagesOnCapsulesRoot","reuseCapsules","tasks","listTasks","ConsumerNotFound","getListTasks","longProcessLogger","createLongProcessLogger","pattern","toString","components","byPattern","list","envsExecutionResults","build","installOptions","installTeambitBit","linkingOptions","linkTeambitBit","emptyRootDir","getExistingAsIs","split","map","task","trim","end","throwErrorsIfExist","consoleSuccess","chalk","green","tasksQueue","length","componentIdStr","compId","resolveComponentId","component","get","results","id","envId","bold","buildTasks","join","tagTasks","snapTasks"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAYO,MAAMA,UAAN,CAAoC;AAsBzCC,EAAAA,WAAW,CAASC,OAAT,EAAuCC,SAAvC,EAAqEC,MAArE,EAAqF;AAAA,SAA5EF,OAA4E,GAA5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B,CAAsB,IAAtB,CAA4B;AAC9B;AACA,EAAEd,iBAAMY,IAAN,CAAW,sBAAX,CAAmC;AACrC,EAAEH,OAAO,CAACO,SAAR,CAAkBF,IAAlB,CAAuB,IAAvB,KAAgC,OAAQ,EAXtC;AAYD;;AAzEwC","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport { Logger } from '@teambit/logger';\nimport { Workspace } from '@teambit/workspace';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport chalk from 'chalk';\nimport { BuilderMain } from './builder.main.runtime';\n\ntype BuildOpts = {\n rebuild: boolean;\n install: boolean;\n cachePackagesOnCapsulesRoot: boolean;\n reuseCapsules: boolean;\n tasks: string;\n listTasks?: string;\n};\n\nexport class BuilderCmd implements Command {\n name = 'build [pattern]';\n description = 'run set of tasks for build';\n alias = '';\n group = 'development';\n options = [\n ['', 'install', 'install core aspects in capsules'],\n ['', 'reuse-capsules', 'avoid deleting the capsules root-dir before starting the build'],\n [\n '',\n 'tasks <string>',\n `build the specified task(s) only. for multiple tasks, separate by a comma and wrap with quotes.\nspecify the task-name (e.g. \"TypescriptCompiler\") or the task-aspect-id (e.g. teambit.compilation/compiler)`,\n ],\n ['', 'cache-packages-on-capsule-root', 'set the package-manager cache on the capsule root'],\n [\n '',\n 'list-tasks <string>',\n 'list tasks of an env or a component-id for each one of the pipelines: build, tag and snap',\n ],\n ] as CommandOptions;\n\n constructor(private builder: BuilderMain, private workspace: Workspace, private logger: Logger) {}\n\n async report(\n [userPattern]: [string],\n { install = false, cachePackagesOnCapsulesRoot = false, reuseCapsules = false, tasks, listTasks }: BuildOpts\n ): Promise<string> {\n if (!this.workspace) throw new ConsumerNotFound();\n if (listTasks) {\n return this.getListTasks(listTasks);\n }\n const longProcessLogger = this.logger.createLongProcessLogger('build');\n const pattern = userPattern && userPattern.toString();\n const components = pattern ? await this.workspace.byPattern(pattern) : await this.workspace.list();\n\n const envsExecutionResults = await this.builder.build(\n components,\n {\n installOptions: {\n installTeambitBit: install,\n },\n linkingOptions: { linkTeambitBit: !install },\n emptyRootDir: !reuseCapsules,\n getExistingAsIs: reuseCapsules,\n cachePackagesOnCapsulesRoot,\n },\n {\n tasks: tasks ? tasks.split(',').map((task) => task.trim()) : [],\n }\n );\n longProcessLogger.end();\n envsExecutionResults.throwErrorsIfExist();\n this.logger.consoleSuccess();\n return chalk.green(`the build has been completed. total: ${envsExecutionResults.tasksQueue.length} tasks`);\n }\n\n private async getListTasks(componentIdStr: string): Promise<string> {\n const compId = await this.workspace.resolveComponentId(componentIdStr);\n const component = await this.workspace.get(compId);\n const results = this.builder.listTasks(component);\n return `${chalk.green('Tasks List')}\nid: ${results.id.toString()}\nenvId: ${results.envId}\n\n${chalk.bold('Build Pipeline Tasks:')}\n${results.buildTasks.join('\\n')}\n\n${chalk.bold('Tag Pipeline Tasks:')}\n${results.tagTasks.join('\\n')}\n\n${chalk.bold('Snap Pipeline Tasks:')}\n${results.snapTasks.join('\\n') || '<N/A>'}`;\n }\n}\n"]}
1
+ {"version":3,"sources":["build.cmd.ts"],"names":["BuilderCmd","constructor","builder","workspace","logger","report","userPattern","all","install","cachePackagesOnCapsulesRoot","reuseCapsules","tasks","listTasks","ConsumerNotFound","getListTasks","longProcessLogger","createLongProcessLogger","components","getComponentsByUserInputDefaultToChanged","length","chalk","bold","consoleSuccess","envsExecutionResults","build","installOptions","installTeambitBit","linkingOptions","linkTeambitBit","emptyRootDir","getExistingAsIs","split","map","task","trim","end","throwErrorsIfExist","green","tasksQueue","componentIdStr","compId","resolveComponentId","component","get","results","id","toString","envId","buildTasks","join","tagTasks","snapTasks"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAaO,MAAMA,UAAN,CAAoC;AAuBzCC,EAAAA,WAAW,CAASC,OAAT,EAAuCC,SAAvC,EAAqEC,MAArE,EAA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AAEuB,OAAO,CAACI,UAAR,CAAmBC,IAAnB,CAAwB,IAAxB,CAA8B;AAChC;AACA,EAAE7B,iBAAMC,IAAN,CAAW,qBAAX,CAAkC;AACpC,EAAEuB,OAAO,CAACM,QAAR,CAAiBD,IAAjB,CAAsB,IAAtB,CAA4B;AAC9B;AACA,EAAE7B,iBAAMC,IAAN,CAAW,sBAAX,CAAmC;AACrC,EAAEuB,OAAO,CAACO,SAAR,CAAkBF,IAAlB,CAAuB,IAAvB,KAAgC,OAAQ,EAXtC;AAYD;;AAvFwC","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport { Logger } from '@teambit/logger';\nimport { Workspace } from '@teambit/workspace';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport chalk from 'chalk';\nimport { BuilderMain } from './builder.main.runtime';\n\ntype BuildOpts = {\n all: boolean;\n rebuild: boolean;\n install: boolean;\n cachePackagesOnCapsulesRoot: boolean;\n reuseCapsules: boolean;\n tasks: string;\n listTasks?: string;\n};\n\nexport class BuilderCmd implements Command {\n name = 'build [pattern]';\n description = 'run set of tasks for build';\n alias = '';\n group = 'development';\n options = [\n ['a', 'all', 'build all components, not only modified and new'],\n ['', 'install', 'install core aspects in capsules'],\n ['', 'reuse-capsules', 'avoid deleting the capsules root-dir before starting the build'],\n [\n '',\n 'tasks <string>',\n `build the specified task(s) only. for multiple tasks, separate by a comma and wrap with quotes.\nspecify the task-name (e.g. \"TypescriptCompiler\") or the task-aspect-id (e.g. teambit.compilation/compiler)`,\n ],\n ['', 'cache-packages-on-capsule-root', 'set the package-manager cache on the capsule root'],\n [\n '',\n 'list-tasks <string>',\n 'list tasks of an env or a component-id for each one of the pipelines: build, tag and snap',\n ],\n ] as CommandOptions;\n\n constructor(private builder: BuilderMain, private workspace: Workspace, private logger: Logger) {}\n\n async report(\n [userPattern]: [string],\n {\n all = false,\n install = false,\n cachePackagesOnCapsulesRoot = false,\n reuseCapsules = false,\n tasks,\n listTasks,\n }: BuildOpts\n ): Promise<string> {\n if (!this.workspace) throw new ConsumerNotFound();\n if (listTasks) {\n return this.getListTasks(listTasks);\n }\n\n const longProcessLogger = this.logger.createLongProcessLogger('build');\n const components = await this.workspace.getComponentsByUserInputDefaultToChanged(all, userPattern);\n if (!components.length) {\n return chalk.bold(\n `no components found to build. use \"--all\" flag to build all components or specify the ids to build, otherwise, only new and modified components will be built`\n );\n }\n this.logger.consoleSuccess(`found ${components.length} components to build`);\n\n const envsExecutionResults = await this.builder.build(\n components,\n {\n installOptions: {\n installTeambitBit: install,\n },\n linkingOptions: { linkTeambitBit: !install },\n emptyRootDir: !reuseCapsules,\n getExistingAsIs: reuseCapsules,\n cachePackagesOnCapsulesRoot,\n },\n {\n tasks: tasks ? tasks.split(',').map((task) => task.trim()) : [],\n }\n );\n longProcessLogger.end();\n envsExecutionResults.throwErrorsIfExist();\n this.logger.consoleSuccess();\n return chalk.green(`the build has been completed. total: ${envsExecutionResults.tasksQueue.length} tasks`);\n }\n\n private async getListTasks(componentIdStr: string): Promise<string> {\n const compId = await this.workspace.resolveComponentId(componentIdStr);\n const component = await this.workspace.get(compId);\n const results = this.builder.listTasks(component);\n return `${chalk.green('Tasks List')}\nid: ${results.id.toString()}\nenvId: ${results.envId}\n\n${chalk.bold('Build Pipeline Tasks:')}\n${results.buildTasks.join('\\n')}\n\n${chalk.bold('Tag Pipeline Tasks:')}\n${results.tagTasks.join('\\n')}\n\n${chalk.bold('Snap Pipeline Tasks:')}\n${results.snapTasks.join('\\n') || '<N/A>'}`;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/builder",
3
- "version": "0.0.555",
3
+ "version": "0.0.559",
4
4
  "homepage": "https://bit.dev/teambit/pipelines/builder",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.pipelines",
8
8
  "name": "builder",
9
- "version": "0.0.555"
9
+ "version": "0.0.559"
10
10
  },
11
11
  "dependencies": {
12
12
  "p-map-series": "2.1.0",
@@ -22,18 +22,18 @@
22
22
  "globby": "11.0.1",
23
23
  "@babel/runtime": "7.12.18",
24
24
  "core-js": "^3.0.0",
25
- "@teambit/component": "0.0.555",
26
- "@teambit/envs": "0.0.555",
27
- "@teambit/logger": "0.0.471",
28
- "@teambit/tester": "0.0.555",
29
- "@teambit/isolator": "0.0.555",
30
- "@teambit/cli": "0.0.386",
31
- "@teambit/workspace": "0.0.555",
32
- "@teambit/aspect-loader": "0.0.555",
33
- "@teambit/graphql": "0.0.555",
34
- "@teambit/scope": "0.0.555",
35
- "@teambit/bit-error": "0.0.372",
36
- "@teambit/component-id": "0.0.376"
25
+ "@teambit/component": "0.0.559",
26
+ "@teambit/envs": "0.0.559",
27
+ "@teambit/logger": "0.0.474",
28
+ "@teambit/tester": "0.0.559",
29
+ "@teambit/isolator": "0.0.559",
30
+ "@teambit/cli": "0.0.389",
31
+ "@teambit/workspace": "0.0.559",
32
+ "@teambit/aspect-loader": "0.0.559",
33
+ "@teambit/graphql": "0.0.559",
34
+ "@teambit/scope": "0.0.559",
35
+ "@teambit/bit-error": "0.0.375",
36
+ "@teambit/component-id": "0.0.379"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/lodash": "4.14.165",
@@ -45,10 +45,10 @@
45
45
  "@types/jest": "^26.0.0",
46
46
  "@types/react-dom": "^17.0.5",
47
47
  "@types/node": "12.20.4",
48
- "@teambit/pipelines.aspect-docs.builder": "0.0.105"
48
+ "@teambit/pipelines.aspect-docs.builder": "0.0.108"
49
49
  },
50
50
  "peerDependencies": {
51
- "@teambit/legacy": "1.0.172",
51
+ "@teambit/legacy": "1.0.175",
52
52
  "react-dom": "^16.8.0 || ^17.0.0",
53
53
  "react": "^16.8.0 || ^17.0.0"
54
54
  },
@@ -76,12 +76,27 @@
76
76
  "react": "-"
77
77
  },
78
78
  "peerDependencies": {
79
- "@teambit/legacy": "1.0.172",
79
+ "@teambit/legacy": "1.0.175",
80
80
  "react-dom": "^16.8.0 || ^17.0.0",
81
81
  "react": "^16.8.0 || ^17.0.0"
82
82
  }
83
83
  }
84
84
  },
85
+ "files": [
86
+ "dist",
87
+ "!dist/tsconfig.tsbuildinfo",
88
+ "**/*.md",
89
+ "**/*.mdx",
90
+ "**/*.js",
91
+ "**/*.json",
92
+ "**/*.sass",
93
+ "**/*.scss",
94
+ "**/*.less",
95
+ "**/*.css",
96
+ "**/*.css",
97
+ "**/*.jpeg",
98
+ "**/*.gif"
99
+ ],
85
100
  "private": false,
86
101
  "engines": {
87
102
  "node": ">=12.22.0"
package/tsconfig.json CHANGED
@@ -15,9 +15,9 @@
15
15
  "skipLibCheck": true,
16
16
  "moduleResolution": "node",
17
17
  "esModuleInterop": true,
18
- "outDir": "dist",
19
18
  "composite": true,
20
19
  "emitDeclarationOnly": true,
20
+ "outDir": "dist",
21
21
  "experimentalDecorators": true,
22
22
  "emitDecoratorMetadata": true,
23
23
  "allowSyntheticDefaultImports": true,
@@ -1,52 +0,0 @@
1
- export type ArtifactDefinition = {
2
- /**
3
- * name of the artifact.
4
- * e.g. a project might utilize two different artifacts for the same typescript compiler, one
5
- * that generates ES5 files and another for ES6, this prop helps to distinguish between the two.
6
- */
7
- name: string;
8
-
9
- /**
10
- * aspect id that created the artifact. sometimes it's not the same as the task.id.
11
- * e.g. teambit.compilation/compiler executes teambit.typescript/typescript code that generates dists artifacts
12
- * the generatedBy in this case is the teambit.typescript/typescript while the task.id is
13
- * teambit.compilation/compiler
14
- */
15
- generatedBy?: string;
16
-
17
- /**
18
- * description of the artifact.
19
- */
20
- description?: string;
21
-
22
- /**
23
- * glob patterns of files to include upon artifact creation. minimatch is used to match the patterns.
24
- * e.g. ['*.ts', '!foo.ts'] matches all ts files but ignores foo.ts.
25
- */
26
- globPatterns: string[];
27
-
28
- /**
29
- * define the root directory for reading the artifacts from the capsule file system.
30
- * the rootDir must be unique per artifacts, otherwise we risk overriding data between artifacts.
31
- */
32
- rootDir?: string;
33
-
34
- /**
35
- * adds a directory prefix for all artifact files.
36
- */
37
- dirPrefix?: string;
38
-
39
- /**
40
- * determine the context of the artifact.
41
- * default artifact context is `component`.
42
- * "env" is useful when the same file is generated for all components, for example, "preview"
43
- * task may create the same webpack file for all components of that env.
44
- */
45
- context?: 'component' | 'env';
46
-
47
- /**
48
- * storage resolver. can be used to replace where artifacts are stored.
49
- * default resolver persists artifacts on scope. (not recommended for large files!)
50
- */
51
- storageResolver?: string;
52
- };
@@ -1,116 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs-extra';
3
- import { ScopeMain } from '@teambit/scope';
4
- import { ComponentID } from '@teambit/component-id';
5
- import pMapSeries from 'p-map-series';
6
- import minimatch from 'minimatch';
7
- import { ArtifactFiles, ArtifactObject } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';
8
- import { BuilderMain } from '../builder.main.runtime';
9
- import { ArtifactsOpts } from './artifacts.cmd';
10
-
11
- export type ExtractorResult = {
12
- id: ComponentID;
13
- artifacts: ExtractorArtifactResult[];
14
- };
15
-
16
- export type ExtractorArtifactResult = {
17
- aspectId: string;
18
- taskName: string;
19
- files: string[];
20
- };
21
-
22
- export type ExtractorResultGrouped = {
23
- id: ComponentID;
24
- artifacts: { [aspectId: string]: ExtractorArtifactResult[] };
25
- };
26
-
27
- type ArtifactObjectsPerId = {
28
- id: ComponentID;
29
- artifacts: ArtifactObject[];
30
- };
31
-
32
- export class ArtifactExtractor {
33
- constructor(
34
- private scope: ScopeMain,
35
- private builder: BuilderMain,
36
- private patterns: string[],
37
- private options: ArtifactsOpts
38
- ) {}
39
-
40
- async list(): Promise<ExtractorResult[]> {
41
- const components = await this.scope.byPattern(this.patterns);
42
- const artifactObjectsPerId: ArtifactObjectsPerId[] = components.map((component) => {
43
- return {
44
- id: component.id,
45
- artifacts: this.builder.getArtifacts(component) || [],
46
- };
47
- });
48
- this.filterByOptions(artifactObjectsPerId);
49
- await this.saveFilesInFileSystemIfAsked(artifactObjectsPerId);
50
-
51
- return this.artifactsObjectsToExtractorResults(artifactObjectsPerId);
52
- }
53
-
54
- groupResultsByAspect(extractorResult: ExtractorResult[]) {
55
- return extractorResult.map((result) => {
56
- const artifacts = result.artifacts.reduce((acc, current) => {
57
- (acc[current.aspectId] ||= []).push(current);
58
- return acc;
59
- }, {});
60
- return { id: result.id, artifacts };
61
- });
62
- }
63
-
64
- private async saveFilesInFileSystemIfAsked(artifactObjectsPerId: ArtifactObjectsPerId[]) {
65
- const outDir = this.options.outDir;
66
- if (!outDir) {
67
- return;
68
- }
69
- // @todo: optimize this to first import all missing hashes.
70
- await pMapSeries(artifactObjectsPerId, async ({ id, artifacts }) => {
71
- const vinyls = await Promise.all(
72
- artifacts.map((artifactObject) =>
73
- artifactObject.files.getVinylsAndImportIfMissing(id.scope as string, this.scope.legacyScope)
74
- )
75
- );
76
- const flattenedVinyls = vinyls.flat();
77
- const compPath = path.join(outDir, id.toStringWithoutVersion());
78
- await Promise.all(flattenedVinyls.map((vinyl) => fs.outputFile(path.join(compPath, vinyl.path), vinyl.contents)));
79
- });
80
- }
81
-
82
- private artifactsObjectsToExtractorResults(artifactObjectsPerId: ArtifactObjectsPerId[]): ExtractorResult[] {
83
- return artifactObjectsPerId.map(({ id, artifacts }) => {
84
- const results: ExtractorArtifactResult[] = artifacts.map((artifact) => {
85
- return {
86
- aspectId: artifact.task.id,
87
- taskName: artifact.task.name || artifact.generatedBy,
88
- files: artifact.files.refs.map((ref) => ref.relativePath),
89
- };
90
- });
91
- return {
92
- id,
93
- artifacts: results,
94
- };
95
- });
96
- }
97
-
98
- private filterByOptions(artifactObjectsPerId: ArtifactObjectsPerId[]) {
99
- const { aspect, task, files } = this.options;
100
- artifactObjectsPerId.forEach((item) => {
101
- item.artifacts = item.artifacts.filter((artifact) => {
102
- if (aspect && aspect !== artifact.task.id) return false;
103
- if (task && task !== artifact.task.name) return false;
104
- return true;
105
- });
106
- if (files) {
107
- item.artifacts.forEach((artifact) => {
108
- const refs = artifact.files.refs.filter((ref) => minimatch(ref.relativePath, files));
109
- artifact.files = new ArtifactFiles([], [], refs);
110
- });
111
- // remove artifacts with no files
112
- item.artifacts = item.artifacts.filter((artifact) => artifact.files.refs.length);
113
- }
114
- });
115
- }
116
- }
@@ -1,119 +0,0 @@
1
- import { join } from 'path';
2
- import globby from 'globby';
3
- import { flatten } from 'lodash';
4
- import { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';
5
- import { Component, ComponentMap } from '@teambit/component';
6
- import type { StorageResolverSlot } from '../builder.main.runtime';
7
- import { ArtifactDefinition } from './artifact-definition';
8
- import { DefaultResolver, StorageResolver } from '../storage';
9
- import { ArtifactList } from './artifact-list';
10
- import { Artifact } from './artifact';
11
- import type { BuildContext, BuildTask } from '../build-task';
12
- import { CapsuleNotFound } from '../exceptions';
13
-
14
- export const DEFAULT_CONTEXT = 'component';
15
-
16
- export type ArtifactMap = ComponentMap<ArtifactList>;
17
-
18
- export class ArtifactFactory {
19
- constructor(private storageResolverSlot: StorageResolverSlot) {}
20
-
21
- private getResolver(resolvers: StorageResolver[], name?: string) {
22
- const defaultResolver = new DefaultResolver();
23
- const userResolver = resolvers.find((resolver) => resolver.name === name);
24
- return userResolver || defaultResolver;
25
- }
26
-
27
- private resolvePaths(root: string, def: ArtifactDefinition): string[] {
28
- const patternsFlattened = flatten(def.globPatterns);
29
- const paths = globby.sync(patternsFlattened, { cwd: root });
30
- return paths;
31
- }
32
-
33
- private getArtifactContextPath(context: BuildContext, component: Component, def: ArtifactDefinition) {
34
- const artifactContext = this.getArtifactContext(def);
35
- if (artifactContext === 'component') {
36
- const capsulePath = context.capsuleNetwork.graphCapsules.getCapsule(component.id)?.path;
37
- if (!capsulePath) throw new CapsuleNotFound(component.id);
38
- return capsulePath;
39
- }
40
-
41
- return context.capsuleNetwork.capsulesRootDir;
42
- }
43
-
44
- private getArtifactContext(def: ArtifactDefinition) {
45
- return def.context || DEFAULT_CONTEXT;
46
- }
47
-
48
- createFromComponent(
49
- context: BuildContext,
50
- component: Component,
51
- def: ArtifactDefinition,
52
- task: BuildTask
53
- ): Artifact | undefined {
54
- const storageResolver = this.getStorageResolver(def);
55
- const rootDir = this.getArtifactContextPath(context, component, def);
56
- const paths = this.resolvePaths(this.getRootDir(rootDir, def), def);
57
- if (!paths || !paths.length) {
58
- return undefined;
59
- }
60
- return new Artifact(def, storageResolver, new ArtifactFiles(paths), rootDir, task);
61
- }
62
-
63
- private getStorageResolver(def: ArtifactDefinition) {
64
- const storageResolvers = this.storageResolverSlot.values();
65
- return this.getResolver(storageResolvers, def.storageResolver);
66
- }
67
-
68
- private toComponentMap(context: BuildContext, artifactMap: [string, Artifact][]) {
69
- return ComponentMap.as<ArtifactList>(context.components, (component) => {
70
- const id = component.id.toString();
71
- const artifacts = artifactMap.filter(([targetId]) => targetId === id).map(([, artifact]) => artifact);
72
-
73
- return new ArtifactList(artifacts);
74
- });
75
- }
76
-
77
- private getRootDir(rootDir: string, def: ArtifactDefinition) {
78
- if (!def.rootDir) return rootDir;
79
- return join(rootDir, def.rootDir);
80
- }
81
-
82
- /**
83
- * generate artifacts from a build context according to the spec defined in the artifact definitions.
84
- */
85
- generate(context: BuildContext, defs: ArtifactDefinition[], task: BuildTask): ComponentMap<ArtifactList> {
86
- const tupleArr: [string, Artifact][] = [];
87
-
88
- defs.forEach((def) => {
89
- const artifactContext = this.getArtifactContext(def);
90
- if (artifactContext === 'env') {
91
- const capsuleDir = context.capsuleNetwork.capsulesRootDir;
92
- const rootDir = this.getRootDir(capsuleDir, def);
93
- const paths = this.resolvePaths(rootDir, def);
94
- if (paths && paths.length) {
95
- const artifact = new Artifact(
96
- def,
97
- this.getStorageResolver(def),
98
- new ArtifactFiles(this.resolvePaths(rootDir, def)),
99
- rootDir,
100
- task
101
- );
102
-
103
- return context.components.forEach((component) => {
104
- tupleArr.push([component.id.toString(), artifact]);
105
- });
106
- }
107
- }
108
-
109
- return context.components.forEach((component) => {
110
- const artifact = this.createFromComponent(context, component, def, task);
111
- if (artifact) {
112
- tupleArr.push([component.id.toString(), artifact]);
113
- }
114
- });
115
- });
116
-
117
- return this.toComponentMap(context, tupleArr);
118
- }
119
- }
@@ -1,64 +0,0 @@
1
- import { Component } from '@teambit/component';
2
- import type { ArtifactObject } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';
3
- import type { Artifact } from './artifact';
4
-
5
- export type ResolverMap = { [key: string]: Artifact[] };
6
-
7
- export class ArtifactList {
8
- constructor(readonly artifacts: Artifact[]) {}
9
-
10
- /**
11
- * return an array of artifact objects.
12
- */
13
- toArray() {
14
- return this.artifacts;
15
- }
16
-
17
- /**
18
- * group artifacts by the storage resolver.
19
- */
20
- groupByResolver(): ResolverMap {
21
- const resolverMap: ResolverMap = {};
22
- this.artifacts.forEach((artifact) => {
23
- const storageResolver = artifact.storageResolver;
24
- const resolverArray = resolverMap[storageResolver.name];
25
- if (!resolverArray) {
26
- resolverMap[storageResolver.name] = [artifact];
27
- return;
28
- }
29
- if (resolverArray.length) {
30
- resolverMap[storageResolver.name].push(artifact);
31
- }
32
- });
33
-
34
- return resolverMap;
35
- }
36
-
37
- toObject(): ArtifactObject[] {
38
- return this.artifacts.map((artifact) => artifact.toObject());
39
- }
40
-
41
- groupByTaskId() {
42
- return this.artifacts.reduce((acc: { [key: string]: Artifact }, artifact) => {
43
- const taskId = artifact.task.aspectId;
44
- acc[taskId] = artifact;
45
- return acc;
46
- }, {});
47
- }
48
-
49
- /**
50
- * store all artifacts using the configured storage resolvers.
51
- */
52
- async store(component: Component) {
53
- const byResolvers = this.groupByResolver();
54
- const promises = Object.keys(byResolvers).map(async (key) => {
55
- const artifacts = byResolvers[key];
56
- if (!artifacts.length) return;
57
- const storageResolver = artifacts[0].storageResolver;
58
- const artifactList = new ArtifactList(artifacts);
59
- await storageResolver.store(component, artifactList);
60
- });
61
-
62
- return Promise.all(promises);
63
- }
64
- }
@@ -1,81 +0,0 @@
1
- import type { ArtifactFiles, ArtifactObject } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';
2
- import type { BuildTask } from '../build-task';
3
- import type { StorageResolver } from '../storage';
4
- import type { ArtifactDefinition } from './artifact-definition';
5
-
6
- export class Artifact {
7
- constructor(
8
- /**
9
- * definition of the artifact.
10
- */
11
- readonly def: ArtifactDefinition,
12
-
13
- /**
14
- * storage resolver. can be used to replace where artifacts are stored.
15
- */
16
- readonly storageResolver: StorageResolver,
17
-
18
- readonly files: ArtifactFiles,
19
-
20
- /**
21
- * join this with `this.paths` to get the absolute paths
22
- */
23
- readonly rootDir: string,
24
-
25
- /**
26
- * the declaring task.
27
- * todo: change this to taskDescriptor that has only the metadata of the task, so it could be
28
- * saved into the model.
29
- */
30
- readonly task: BuildTask,
31
-
32
- /**
33
- * timestamp of the artifact creation.
34
- */
35
- readonly timestamp: number = Date.now()
36
- ) {}
37
-
38
- get storage() {
39
- return this.storageResolver;
40
- }
41
-
42
- /**
43
- * name of the artifact.
44
- */
45
- get name(): string {
46
- return this.def.name;
47
- }
48
-
49
- /**
50
- * description of the artifact.
51
- */
52
- get description() {
53
- return this.def.description;
54
- }
55
-
56
- /**
57
- * aspect id (string) that generated the artifact
58
- */
59
- get generatedBy(): string {
60
- return this.def.generatedBy || this.task.aspectId;
61
- }
62
-
63
- /**
64
- * archive all artifact files into a tar.
65
- */
66
- tar() {}
67
-
68
- toObject(): ArtifactObject {
69
- return {
70
- name: this.name,
71
- description: this.description,
72
- generatedBy: this.generatedBy,
73
- storage: this.storageResolver.name,
74
- task: {
75
- id: this.task.aspectId,
76
- name: this.task.name,
77
- },
78
- files: this.files,
79
- };
80
- }
81
- }