@teambit/builder 0.0.881 → 0.0.882

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/artifact/artifact-extractor.js +6 -47
  2. package/dist/artifact/artifact-extractor.js.map +1 -1
  3. package/dist/artifact/artifact-factory.js +1 -52
  4. package/dist/artifact/artifact-factory.js.map +1 -1
  5. package/dist/artifact/artifact-list.js +6 -43
  6. package/dist/artifact/artifact-list.js.map +1 -1
  7. package/dist/artifact/artifact.js +4 -20
  8. package/dist/artifact/artifact.js.map +1 -1
  9. package/dist/artifact/artifacts.cmd.js +0 -29
  10. package/dist/artifact/artifacts.cmd.js.map +1 -1
  11. package/dist/artifact/extension-artifact.js +0 -4
  12. package/dist/artifact/extension-artifact.js.map +1 -1
  13. package/dist/artifact/fs-artifact.js +0 -6
  14. package/dist/artifact/fs-artifact.js.map +1 -1
  15. package/dist/artifact/index.js +0 -18
  16. package/dist/artifact/index.js.map +1 -1
  17. package/dist/build-pipe.js +2 -44
  18. package/dist/build-pipe.js.map +1 -1
  19. package/dist/build-pipeline-order.js +7 -44
  20. package/dist/build-pipeline-order.js.map +1 -1
  21. package/dist/build-pipeline-result-list.js +2 -35
  22. package/dist/build-pipeline-result-list.js.map +1 -1
  23. package/dist/build-task.js +1 -9
  24. package/dist/build-task.js.map +1 -1
  25. package/dist/build.cmd.js +0 -27
  26. package/dist/build.cmd.js.map +1 -1
  27. package/dist/builder.aspect.js +0 -5
  28. package/dist/builder.aspect.js.map +1 -1
  29. package/dist/builder.composition.js +0 -6
  30. package/dist/builder.composition.js.map +1 -1
  31. package/dist/builder.graphql.js +0 -19
  32. package/dist/builder.graphql.js.map +1 -1
  33. package/dist/builder.main.runtime.js +8 -137
  34. package/dist/builder.main.runtime.js.map +1 -1
  35. package/dist/builder.route.js +3 -27
  36. package/dist/builder.route.js.map +1 -1
  37. package/dist/builder.service.js +1 -37
  38. package/dist/builder.service.js.map +1 -1
  39. package/dist/exceptions/artifact-definition-no-glob.js +0 -3
  40. package/dist/exceptions/artifact-definition-no-glob.js.map +1 -1
  41. package/dist/exceptions/artifact-storage-error.js +0 -3
  42. package/dist/exceptions/artifact-storage-error.js.map +1 -1
  43. package/dist/exceptions/capsule-not-found.js +0 -3
  44. package/dist/exceptions/capsule-not-found.js.map +1 -1
  45. package/dist/exceptions/index.js +0 -9
  46. package/dist/exceptions/index.js.map +1 -1
  47. package/dist/exceptions/invalid-task.js +0 -6
  48. package/dist/exceptions/invalid-task.js.map +1 -1
  49. package/dist/index.js +0 -24
  50. package/dist/index.js.map +1 -1
  51. package/dist/pipeline/index.js +0 -3
  52. package/dist/pipeline/index.js.map +1 -1
  53. package/dist/pipeline/pipeline-results.js +0 -2
  54. package/dist/pipeline/pipeline-results.js.map +1 -1
  55. package/dist/storage/default-resolver.js +0 -9
  56. package/dist/storage/default-resolver.js.map +1 -1
  57. package/dist/storage/index.js +0 -6
  58. package/dist/storage/index.js.map +1 -1
  59. package/dist/storage/s3-resolver.js +4 -0
  60. package/dist/storage/s3-resolver.js.map +1 -1
  61. package/dist/task-results-list.js +1 -23
  62. package/dist/task-results-list.js.map +1 -1
  63. package/dist/tasks-queue.js +0 -14
  64. package/dist/tasks-queue.js.map +1 -1
  65. package/dist/templates/build-task/files/index-file.js +0 -1
  66. package/dist/templates/build-task/files/index-file.js.map +1 -1
  67. package/dist/templates/build-task/files/task-file.js +0 -1
  68. package/dist/templates/build-task/files/task-file.js.map +1 -1
  69. package/dist/templates/build-task/index.js +0 -7
  70. package/dist/templates/build-task/index.js.map +1 -1
  71. package/package-tar/teambit-builder-0.0.882.tgz +0 -0
  72. package/package.json +11 -11
  73. package/{preview-1666409808293.js → preview-1666496165706.js} +2 -2
  74. package/package-tar/teambit-builder-0.0.881.tgz +0 -0
@@ -1,96 +1,68 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.array.iterator.js");
6
-
7
5
  require("core-js/modules/es.promise.js");
8
-
9
6
  Object.defineProperty(exports, "__esModule", {
10
7
  value: true
11
8
  });
12
9
  exports.ArtifactExtractor = void 0;
13
-
14
10
  function _path() {
15
11
  const data = _interopRequireDefault(require("path"));
16
-
17
12
  _path = function () {
18
13
  return data;
19
14
  };
20
-
21
15
  return data;
22
16
  }
23
-
24
17
  function _filenamify() {
25
18
  const data = _interopRequireDefault(require("filenamify"));
26
-
27
19
  _filenamify = function () {
28
20
  return data;
29
21
  };
30
-
31
22
  return data;
32
23
  }
33
-
34
24
  function _fsExtra() {
35
25
  const data = _interopRequireDefault(require("fs-extra"));
36
-
37
26
  _fsExtra = function () {
38
27
  return data;
39
28
  };
40
-
41
29
  return data;
42
30
  }
43
-
44
31
  function _pMapSeries() {
45
32
  const data = _interopRequireDefault(require("p-map-series"));
46
-
47
33
  _pMapSeries = function () {
48
34
  return data;
49
35
  };
50
-
51
36
  return data;
52
37
  }
53
-
54
38
  function _minimatch() {
55
39
  const data = _interopRequireDefault(require("minimatch"));
56
-
57
40
  _minimatch = function () {
58
41
  return data;
59
42
  };
60
-
61
43
  return data;
62
44
  }
63
-
64
45
  function _artifactFiles() {
65
46
  const data = require("@teambit/legacy/dist/consumer/component/sources/artifact-files");
66
-
67
47
  _artifactFiles = function () {
68
48
  return data;
69
49
  };
70
-
71
50
  return data;
72
51
  }
73
-
74
52
  function _artifactList() {
75
53
  const data = require("./artifact-list");
76
-
77
54
  _artifactList = function () {
78
55
  return data;
79
56
  };
80
-
81
57
  return data;
82
58
  }
83
-
84
59
  function _artifact() {
85
60
  const data = require("./artifact");
86
-
87
61
  _artifact = function () {
88
62
  return data;
89
63
  };
90
-
91
64
  return data;
92
65
  }
93
-
94
66
  class ArtifactExtractor {
95
67
  constructor(scope, builder, pattern, options) {
96
68
  this.scope = scope;
@@ -98,7 +70,6 @@ class ArtifactExtractor {
98
70
  this.pattern = pattern;
99
71
  this.options = options;
100
72
  }
101
-
102
73
  async list() {
103
74
  const ids = await this.scope.idsByPattern(this.pattern);
104
75
  const components = await this.scope.loadMany(ids);
@@ -112,12 +83,10 @@ class ArtifactExtractor {
112
83
  await this.saveFilesInFileSystemIfAsked(artifactListPerId);
113
84
  return this.artifactsObjectsToExtractorResults(artifactListPerId);
114
85
  }
115
-
116
86
  groupResultsByAspect(extractorResult) {
117
87
  return extractorResult.map(result => {
118
88
  const artifacts = result.artifacts.reduce((acc, current) => {
119
89
  var _current$aspectId;
120
-
121
90
  (acc[_current$aspectId = current.aspectId] || (acc[_current$aspectId] = [])).push(current);
122
91
  return acc;
123
92
  }, {});
@@ -127,31 +96,25 @@ class ArtifactExtractor {
127
96
  };
128
97
  });
129
98
  }
130
-
131
99
  async saveFilesInFileSystemIfAsked(artifactListPerId) {
132
100
  const outDir = this.options.outDir;
133
-
134
101
  if (!outDir) {
135
102
  return;
136
- } // @todo: optimize this to first import all missing hashes.
137
-
138
-
103
+ }
104
+ // @todo: optimize this to first import all missing hashes.
139
105
  await (0, _pMapSeries().default)(artifactListPerId, async ({
140
106
  id,
141
107
  artifacts
142
108
  }) => {
143
- const vinyls = await artifacts.getVinylsAndImportIfMissing(id._legacy, this.scope.legacyScope); // make sure the component-dir is just one dir. without this, every slash in the component-id will create a new dir.
144
-
109
+ const vinyls = await artifacts.getVinylsAndImportIfMissing(id._legacy, this.scope.legacyScope);
110
+ // make sure the component-dir is just one dir. without this, every slash in the component-id will create a new dir.
145
111
  const idAsFilename = (0, _filenamify().default)(id.toStringWithoutVersion(), {
146
112
  replacement: '_'
147
113
  });
148
-
149
114
  const compPath = _path().default.join(outDir, idAsFilename);
150
-
151
115
  await Promise.all(vinyls.map(vinyl => _fsExtra().default.outputFile(_path().default.join(compPath, vinyl.path), vinyl.contents)));
152
116
  });
153
117
  }
154
-
155
118
  artifactsObjectsToExtractorResults(artifactListPerId) {
156
119
  return artifactListPerId.map(({
157
120
  id,
@@ -171,7 +134,6 @@ class ArtifactExtractor {
171
134
  };
172
135
  });
173
136
  }
174
-
175
137
  filterByOptions(artifactListPerId) {
176
138
  const {
177
139
  aspect,
@@ -185,21 +147,18 @@ class ArtifactExtractor {
185
147
  if (task && task !== artifact.task.name) return false;
186
148
  return true;
187
149
  });
188
-
189
150
  if (files) {
190
151
  filteredArtifacts = item.artifacts.map(artifact => {
191
152
  const refs = artifact.files.refs.filter(ref => (0, _minimatch().default)(ref.relativePath, files));
192
153
  return new (_artifact().Artifact)(artifact.def, new (_artifactFiles().ArtifactFiles)([], [], refs), artifact.task);
193
- }) // remove artifacts with no files
154
+ })
155
+ // remove artifacts with no files
194
156
  .filter(artifact => !artifact.isEmpty());
195
157
  }
196
-
197
158
  item.artifacts = _artifactList().ArtifactList.fromArray(filteredArtifacts);
198
159
  });
199
160
  }
200
-
201
161
  }
202
-
203
162
  exports.ArtifactExtractor = ArtifactExtractor;
204
163
 
205
164
  //# sourceMappingURL=artifact-extractor.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ArtifactExtractor","constructor","scope","builder","pattern","options","list","ids","idsByPattern","components","loadMany","artifactListPerId","map","component","id","artifacts","getArtifacts","filterByOptions","saveFilesInFileSystemIfAsked","artifactsObjectsToExtractorResults","groupResultsByAspect","extractorResult","result","reduce","acc","current","aspectId","push","outDir","pMapSeries","vinyls","getVinylsAndImportIfMissing","_legacy","legacyScope","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","fromArray"],"sources":["artifact-extractor.ts"],"sourcesContent":["import path from 'path';\nimport filenamify from 'filenamify';\nimport fs from 'fs-extra';\nimport { ScopeMain } from '@teambit/scope';\nimport { ComponentID } 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 scope: ScopeMain,\n private builder: BuilderMain,\n private pattern: string,\n private options: ArtifactsOpts\n ) {}\n\n async list(): Promise<ExtractorResult[]> {\n const ids = await this.scope.idsByPattern(this.pattern);\n const components = await this.scope.loadMany(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 // @todo: optimize this to first import all missing hashes.\n await pMapSeries(artifactListPerId, async ({ id, artifacts }) => {\n const vinyls = await artifacts.getVinylsAndImportIfMissing(id._legacy, this.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;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAwBO,MAAMA,iBAAN,CAAwB;EAC7BC,WAAW,CACDC,KADC,EAEDC,OAFC,EAGDC,OAHC,EAID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jB;IACD,CAhBD;EAiBD;;AAtF4B"}
1
+ {"version":3,"names":["ArtifactExtractor","constructor","scope","builder","pattern","options","list","ids","idsByPattern","components","loadMany","artifactListPerId","map","component","id","artifacts","getArtifacts","filterByOptions","saveFilesInFileSystemIfAsked","artifactsObjectsToExtractorResults","groupResultsByAspect","extractorResult","result","reduce","acc","current","aspectId","push","outDir","pMapSeries","vinyls","getVinylsAndImportIfMissing","_legacy","legacyScope","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","fromArray"],"sources":["artifact-extractor.ts"],"sourcesContent":["import path from 'path';\nimport filenamify from 'filenamify';\nimport fs from 'fs-extra';\nimport { ScopeMain } from '@teambit/scope';\nimport { ComponentID } 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 scope: ScopeMain,\n private builder: BuilderMain,\n private pattern: string,\n private options: ArtifactsOpts\n ) {}\n\n async list(): Promise<ExtractorResult[]> {\n const ids = await this.scope.idsByPattern(this.pattern);\n const components = await this.scope.loadMany(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 // @todo: optimize this to first import all missing hashes.\n await pMapSeries(artifactListPerId, async ({ id, artifacts }) => {\n const vinyls = await artifacts.getVinylsAndImportIfMissing(id._legacy, this.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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAwBO,MAAMA,iBAAiB,CAAC;EAC7BC,WAAW,CACDC,KAAgB,EAChBC,OAAoB,EACpBC,OAAe,EACfC,OAAsB,EAC9B;IAAA,KAJQH,KAAgB,GAAhBA,KAAgB;IAAA,KAChBC,OAAoB,GAApBA,OAAoB;IAAA,KACpBC,OAAe,GAAfA,OAAe;IAAA,KACfC,OAAsB,GAAtBA,OAAsB;EAC7B;EAEH,MAAMC,IAAI,GAA+B;IACvC,MAAMC,GAAG,GAAG,MAAM,IAAI,CAACL,KAAK,CAACM,YAAY,CAAC,IAAI,CAACJ,OAAO,CAAC;IACvD,MAAMK,UAAU,GAAG,MAAM,IAAI,CAACP,KAAK,CAACQ,QAAQ,CAACH,GAAG,CAAC;IACjD,MAAMI,iBAAsC,GAAGF,UAAU,CAACG,GAAG,CAAEC,SAAS,IAAK;MAC3E,OAAO;QACLC,EAAE,EAAED,SAAS,CAACC,EAAE;QAChBC,SAAS,EAAE,IAAI,CAACZ,OAAO,CAACa,YAAY,CAACH,SAAS;MAChD,CAAC;IACH,CAAC,CAAC;IACF,IAAI,CAAC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AAK;QACrD,OAAO,IAAI;MACb,CAAC,CAAC;MACF,IAAII,KAAK,EAAE;QACTK,iBAAiB,GAAGE,IAAI,CAAC9C,SAAS,CAC/BH,GAAG,CAAEoC,QAAQ,IAAK;UACjB,MAAMO,IAAI,GAAGP,QAAQ,CAACM,KAAK,CAACC,IAAI,CAACO,MAAM,CAAEN,GAAG,IAAK,IAAAO,oBAAS,EAACP,GAAG,CAACC,YAAY,EAAEH,KAAK,CAAC,CAAC;UACpF,OAAO,KAAIU,oBAAQ,EAAChB,QAAQ,CAACiB,GAAG,EAAE,KAAIC,8BAAa,EAAC,EAAE,EAAE,EAAE,EAAEX,IAAI,CAAC,EAAEP,QAAQ,CAACG,IAAI,CAAC;QACnF,CAAC;QACD;QAAA,CACCW,MAAM,CAAEd,QAAQ,IAAK,CAACA,QAAQ,CAACmB,OAAO,EAAE,CAAC;MAC9C;MACAN,IAAI,CAAC9C,SAAS,GAAGqD,4BAAY,CAACC,SAAS,CAACV,iBAAiB,CAAC;IAC5D,CAAC,CAAC;EACJ;AACF;AAAC"}
@@ -1,152 +1,109 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.array.iterator.js");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.DEFAULT_CONTEXT = exports.ArtifactFactory = void 0;
11
-
12
9
  function _path() {
13
10
  const data = require("path");
14
-
15
11
  _path = function () {
16
12
  return data;
17
13
  };
18
-
19
14
  return data;
20
15
  }
21
-
22
16
  function _globby() {
23
17
  const data = _interopRequireDefault(require("globby"));
24
-
25
18
  _globby = function () {
26
19
  return data;
27
20
  };
28
-
29
21
  return data;
30
22
  }
31
-
32
23
  function _lodash() {
33
24
  const data = require("lodash");
34
-
35
25
  _lodash = function () {
36
26
  return data;
37
27
  };
38
-
39
28
  return data;
40
29
  }
41
-
42
30
  function _artifactFiles() {
43
31
  const data = require("@teambit/legacy/dist/consumer/component/sources/artifact-files");
44
-
45
32
  _artifactFiles = function () {
46
33
  return data;
47
34
  };
48
-
49
35
  return data;
50
36
  }
51
-
52
37
  function _component() {
53
38
  const data = require("@teambit/component");
54
-
55
39
  _component = function () {
56
40
  return data;
57
41
  };
58
-
59
42
  return data;
60
43
  }
61
-
62
44
  function _storage() {
63
45
  const data = require("../storage");
64
-
65
46
  _storage = function () {
66
47
  return data;
67
48
  };
68
-
69
49
  return data;
70
50
  }
71
-
72
51
  function _artifactList() {
73
52
  const data = require("./artifact-list");
74
-
75
53
  _artifactList = function () {
76
54
  return data;
77
55
  };
78
-
79
56
  return data;
80
57
  }
81
-
82
58
  function _exceptions() {
83
59
  const data = require("../exceptions");
84
-
85
60
  _exceptions = function () {
86
61
  return data;
87
62
  };
88
-
89
63
  return data;
90
64
  }
91
-
92
65
  function _fsArtifact() {
93
66
  const data = require("./fs-artifact");
94
-
95
67
  _fsArtifact = function () {
96
68
  return data;
97
69
  };
98
-
99
70
  return data;
100
71
  }
101
-
102
72
  const DEFAULT_CONTEXT = 'component';
103
73
  exports.DEFAULT_CONTEXT = DEFAULT_CONTEXT;
104
-
105
74
  class ArtifactFactory {
106
75
  resolvePaths(root, def) {
107
76
  const patternsFlattened = (0, _lodash().flatten)(def.globPatterns);
108
-
109
77
  const paths = _globby().default.sync(patternsFlattened, {
110
78
  cwd: root
111
79
  });
112
-
113
80
  return paths;
114
81
  }
115
-
116
82
  getArtifactContextPath(context, component, def) {
117
83
  const artifactContext = this.getArtifactContext(def);
118
-
119
84
  if (artifactContext === 'component') {
120
85
  var _context$capsuleNetwo;
121
-
122
86
  const capsulePath = (_context$capsuleNetwo = context.capsuleNetwork.graphCapsules.getCapsule(component.id)) === null || _context$capsuleNetwo === void 0 ? void 0 : _context$capsuleNetwo.path;
123
87
  if (!capsulePath) throw new (_exceptions().CapsuleNotFound)(component.id);
124
88
  return capsulePath;
125
89
  }
126
-
127
90
  return context.capsuleNetwork.capsulesRootDir;
128
91
  }
129
-
130
92
  getArtifactContext(def) {
131
93
  return def.context || DEFAULT_CONTEXT;
132
94
  }
133
-
134
95
  createFromComponent(context, component, def, task) {
135
96
  const contextPath = this.getArtifactContextPath(context, component, def);
136
97
  const rootDir = this.getRootDir(contextPath, def);
137
98
  const paths = this.resolvePaths(rootDir, def);
138
-
139
99
  if (!paths || !paths.length) {
140
100
  return undefined;
141
101
  }
142
-
143
102
  return new (_fsArtifact().FsArtifact)(def, new (_artifactFiles().ArtifactFiles)(paths), task, rootDir);
144
103
  }
145
-
146
104
  getStorageResolver(def) {
147
105
  return def.storageResolver || new (_storage().DefaultResolver)();
148
106
  }
149
-
150
107
  toComponentMap(context, artifactMap) {
151
108
  return _component().ComponentMap.as(context.components, component => {
152
109
  const id = component.id.toString();
@@ -154,26 +111,22 @@ class ArtifactFactory {
154
111
  return _artifactList().ArtifactList.fromArray(artifacts);
155
112
  });
156
113
  }
157
-
158
114
  getRootDir(rootDir, def) {
159
115
  if (!def.rootDir) return rootDir;
160
116
  return (0, _path().join)(rootDir, def.rootDir);
161
117
  }
118
+
162
119
  /**
163
120
  * generate artifacts from a build context according to the spec defined in the artifact definitions.
164
121
  */
165
-
166
-
167
122
  generate(context, defs, task) {
168
123
  const tupleArr = [];
169
124
  defs.forEach(def => {
170
125
  const artifactContext = this.getArtifactContext(def);
171
-
172
126
  if (artifactContext === 'env') {
173
127
  const capsuleDir = context.capsuleNetwork.capsulesRootDir;
174
128
  const rootDir = this.getRootDir(capsuleDir, def);
175
129
  const paths = this.resolvePaths(rootDir, def);
176
-
177
130
  if (paths && paths.length) {
178
131
  const artifact = new (_fsArtifact().FsArtifact)(def, new (_artifactFiles().ArtifactFiles)(this.resolvePaths(rootDir, def)), task, rootDir);
179
132
  return context.components.forEach(component => {
@@ -181,10 +134,8 @@ class ArtifactFactory {
181
134
  });
182
135
  }
183
136
  }
184
-
185
137
  return context.components.forEach(component => {
186
138
  const artifact = this.createFromComponent(context, component, def, task);
187
-
188
139
  if (artifact) {
189
140
  tupleArr.push([component.id.toString(), artifact]);
190
141
  }
@@ -192,9 +143,7 @@ class ArtifactFactory {
192
143
  });
193
144
  return this.toComponentMap(context, tupleArr);
194
145
  }
195
-
196
146
  }
197
-
198
147
  exports.ArtifactFactory = ArtifactFactory;
199
148
 
200
149
  //# sourceMappingURL=artifact-factory.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["DEFAULT_CONTEXT","ArtifactFactory","resolvePaths","root","def","patternsFlattened","flatten","globPatterns","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","map","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 { 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 paths = globby.sync(patternsFlattened, { 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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Ae;QAC/C,MAAMiC,QAAQ,GAAG,KAAKtB,mBAAL,CAAyBZ,OAAzB,EAAkCC,SAAlC,EAA6CV,GAA7C,EAAkDsB,IAAlD,CAAjB;;QACA,IAAIqB,QAAJ,EAAc;UACZM,QAAQ,CAACG,IAAT,CAAc,CAAC1C,SAAS,CAACO,EAAV,CAAaqB,QAAb,EAAD,EAA0BK,QAA1B,CAAd;QACD;MACF,CALM,CAAP;IAMD,CArBD;IAuBA,OAAO,KAAKV,cAAL,CAAoBxB,OAApB,EAA6BwC,QAA7B,CAAP;EACD;;AArF0B"}
1
+ {"version":3,"names":["DEFAULT_CONTEXT","ArtifactFactory","resolvePaths","root","def","patternsFlattened","flatten","globPatterns","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","map","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 { 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 paths = globby.sync(patternsFlattened, { 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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,eAAe,GAAG,WAAW;AAAC;AAIpC,MAAMC,eAAe,CAAC;EAC3BC,YAAY,CAACC,IAAY,EAAEC,GAAuB,EAAY;IAC5D,MAAMC,iBAAiB,GAAG,IAAAC,iBAAO,EAACF,GAAG,CAACG,YAAY,CAAC;IACnD,MAAMC,KAAK,GAAGC,iBAAM,CAACC,IAAI,CAACL,iBAAiB,EAAE;MAAEM,GAAG,EAAER;IAAK,CAAC,CAAC;IAC3D,OAAOK,KAAK;EACd;EAEQI,sBAAsB,CAACC,OAAqB,EAAEC,SAAoB,EAAEV,GAAuB,EAAE;IACnG,MAAMW,eAAe,GAAG,IAAI,CAACC,kBAAkB,CAACZ,GAAG,CAAC;IACpD,IAAIW,eAAe,KAAK,WAAW,EAAE;MAAA;MACnC,MAAME,WAAW,4BAAGJ,OAAO,CAACK,cAAc,CAACC,aAAa,CAACC,UAAU,CAACN,SAAS,CAACO,EAAE,CAAC,0DAA7D,sBAA+DC,IAAI;MACvF,IAAI,CAACL,WAAW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