@teambit/builder 1.0.978 → 1.0.979
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/artifact/artifact-extractor.ts +27 -6
- package/artifact/artifacts.cmd.ts +6 -2
- package/dist/artifact/artifact-extractor.d.ts +1 -0
- package/dist/artifact/artifact-extractor.js +30 -5
- package/dist/artifact/artifact-extractor.js.map +1 -1
- package/dist/artifact/artifacts.cmd.js +5 -1
- package/dist/artifact/artifacts.cmd.js.map +1 -1
- package/dist/{preview-1778532898627.js → preview-1778537634251.js} +2 -2
- package/package.json +12 -12
|
@@ -9,6 +9,7 @@ import { ComponentIdList } from '@teambit/component-id';
|
|
|
9
9
|
import pMapSeries from 'p-map-series';
|
|
10
10
|
import minimatch from 'minimatch';
|
|
11
11
|
import { ArtifactFiles } from '@teambit/component.sources';
|
|
12
|
+
import { isValidPath } from '@teambit/legacy.utils';
|
|
12
13
|
import type { BuilderMain } from '../builder.main.runtime';
|
|
13
14
|
import type { ArtifactsOpts } from './artifacts.cmd';
|
|
14
15
|
import { ArtifactList } from './artifact-list';
|
|
@@ -37,6 +38,8 @@ type ArtifactListPerId = {
|
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
export class ArtifactExtractor {
|
|
41
|
+
savedFilesCount = 0;
|
|
42
|
+
|
|
40
43
|
constructor(
|
|
41
44
|
private componentMain: ComponentMain,
|
|
42
45
|
private builder: BuilderMain,
|
|
@@ -48,8 +51,16 @@ export class ArtifactExtractor {
|
|
|
48
51
|
const host = this.componentMain.getHost();
|
|
49
52
|
const ids = await host.idsByPattern(this.pattern);
|
|
50
53
|
const scope = this.componentMain.getHost(ScopeAspect.id) as ScopeMain;
|
|
51
|
-
// import
|
|
52
|
-
|
|
54
|
+
// re-import the version objects so we pick up any builder data added by the remote build
|
|
55
|
+
// pipeline after the local snap was created (the local Version may have been stored with
|
|
56
|
+
// empty BuilderAspect data — the Version hash excludes extension data, so it isn't replaced
|
|
57
|
+
// on a normal cached import). passing the current lane routes the fetch to the lane's scope
|
|
58
|
+
// where snaps actually live, and the lane-aware fetcher writes back any updated Version.
|
|
59
|
+
const currentLane = await scope.legacyScope.getCurrentLaneObject();
|
|
60
|
+
await scope.legacyScope.scopeImporter.importWithoutDeps(ComponentIdList.fromArray(ids), {
|
|
61
|
+
lane: currentLane,
|
|
62
|
+
reason: 'to refresh build artifacts',
|
|
63
|
+
});
|
|
53
64
|
const components = await host.getMany(ids);
|
|
54
65
|
const artifactListPerId: ArtifactListPerId[] = components.map((component) => {
|
|
55
66
|
return {
|
|
@@ -58,7 +69,7 @@ export class ArtifactExtractor {
|
|
|
58
69
|
};
|
|
59
70
|
});
|
|
60
71
|
this.filterByOptions(artifactListPerId);
|
|
61
|
-
await this.saveFilesInFileSystemIfAsked(artifactListPerId);
|
|
72
|
+
this.savedFilesCount = await this.saveFilesInFileSystemIfAsked(artifactListPerId);
|
|
62
73
|
|
|
63
74
|
return this.artifactsObjectsToExtractorResults(artifactListPerId);
|
|
64
75
|
}
|
|
@@ -73,20 +84,30 @@ export class ArtifactExtractor {
|
|
|
73
84
|
});
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
private async saveFilesInFileSystemIfAsked(artifactListPerId: ArtifactListPerId[]) {
|
|
87
|
+
private async saveFilesInFileSystemIfAsked(artifactListPerId: ArtifactListPerId[]): Promise<number> {
|
|
77
88
|
const outDir = this.options.outDir;
|
|
78
89
|
if (!outDir) {
|
|
79
|
-
return;
|
|
90
|
+
return 0;
|
|
80
91
|
}
|
|
81
92
|
const scope = this.componentMain.getHost(ScopeAspect.id) as ScopeMain;
|
|
93
|
+
let totalSaved = 0;
|
|
82
94
|
// @todo: optimize this to first import all missing hashes.
|
|
83
95
|
await pMapSeries(artifactListPerId, async ({ id, artifacts }) => {
|
|
84
96
|
const vinyls = await artifacts.getVinylsAndImportIfMissing(id, scope.legacyScope);
|
|
85
97
|
// make sure the component-dir is just one dir. without this, every slash in the component-id will create a new dir.
|
|
86
98
|
const idAsFilename = filenamify(id.toStringWithoutVersion(), { replacement: '_' });
|
|
87
99
|
const compPath = path.join(outDir, idAsFilename);
|
|
88
|
-
await Promise.all(
|
|
100
|
+
await Promise.all(
|
|
101
|
+
vinyls.map((vinyl) => {
|
|
102
|
+
if (!isValidPath(vinyl.path)) {
|
|
103
|
+
throw new Error(`refusing to write artifact "${vinyl.path}" for ${id.toString()}: unsafe path`);
|
|
104
|
+
}
|
|
105
|
+
return fs.outputFile(path.join(compPath, vinyl.path), vinyl.contents);
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
totalSaved += vinyls.length;
|
|
89
109
|
});
|
|
110
|
+
return totalSaved;
|
|
90
111
|
}
|
|
91
112
|
|
|
92
113
|
private artifactsObjectsToExtractorResults(artifactListPerId: ArtifactListPerId[]): ExtractorResult[] {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
-
import { formatTitle, formatSuccessSummary } from '@teambit/cli';
|
|
2
|
+
import { formatTitle, formatSuccessSummary, formatWarningSummary } from '@teambit/cli';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { COMPONENT_PATTERN_HELP } from '@teambit/legacy.constants';
|
|
5
5
|
import type { ComponentMain } from '@teambit/component';
|
|
@@ -52,6 +52,10 @@ use --out-dir to download artifacts locally for inspection or deployment purpose
|
|
|
52
52
|
async report([componentPattern]: [string], artifactsOpts: ArtifactsOpts): Promise<string> {
|
|
53
53
|
const artifactExtractor = new ArtifactExtractor(this.componentMain, this.builder, componentPattern, artifactsOpts);
|
|
54
54
|
const list = await artifactExtractor.list();
|
|
55
|
+
const totalArtifacts = list.reduce((sum, r) => sum + r.artifacts.length, 0);
|
|
56
|
+
if (totalArtifacts === 0) {
|
|
57
|
+
return formatWarningSummary(`no artifacts found for "${componentPattern}"`);
|
|
58
|
+
}
|
|
55
59
|
const grouped = artifactExtractor.groupResultsByAspect(list);
|
|
56
60
|
const outputArtifacts = (aspectId: string, artifactData: ExtractorArtifactResult[]) => {
|
|
57
61
|
const title = formatTitle(aspectId);
|
|
@@ -72,7 +76,7 @@ use --out-dir to download artifacts locally for inspection or deployment purpose
|
|
|
72
76
|
return `${idStr}\n${artifacts}`;
|
|
73
77
|
};
|
|
74
78
|
const footer = artifactsOpts.outDir
|
|
75
|
-
? `\n\n${formatSuccessSummary(
|
|
79
|
+
? `\n\n${formatSuccessSummary(`${artifactExtractor.savedFilesCount} file(s) saved to "${artifactsOpts.outDir}"`)}`
|
|
76
80
|
: '';
|
|
77
81
|
return grouped.map(outputResult).join('\n\n') + footer;
|
|
78
82
|
}
|
|
@@ -23,6 +23,7 @@ export declare class ArtifactExtractor {
|
|
|
23
23
|
private builder;
|
|
24
24
|
private pattern;
|
|
25
25
|
private options;
|
|
26
|
+
savedFilesCount: number;
|
|
26
27
|
constructor(componentMain: ComponentMain, builder: BuilderMain, pattern: string, options: ArtifactsOpts);
|
|
27
28
|
list(): Promise<ExtractorResult[]>;
|
|
28
29
|
groupResultsByAspect(extractorResult: ExtractorResult[]): {
|
|
@@ -60,6 +60,13 @@ function _component() {
|
|
|
60
60
|
};
|
|
61
61
|
return data;
|
|
62
62
|
}
|
|
63
|
+
function _legacy() {
|
|
64
|
+
const data = require("@teambit/legacy.utils");
|
|
65
|
+
_legacy = function () {
|
|
66
|
+
return data;
|
|
67
|
+
};
|
|
68
|
+
return data;
|
|
69
|
+
}
|
|
63
70
|
function _artifactList() {
|
|
64
71
|
const data = require("./artifact-list");
|
|
65
72
|
_artifactList = function () {
|
|
@@ -75,20 +82,30 @@ function _artifact() {
|
|
|
75
82
|
return data;
|
|
76
83
|
}
|
|
77
84
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
85
|
+
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; }
|
|
86
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
87
|
+
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); }
|
|
78
88
|
class ArtifactExtractor {
|
|
79
89
|
constructor(componentMain, builder, pattern, options) {
|
|
80
90
|
this.componentMain = componentMain;
|
|
81
91
|
this.builder = builder;
|
|
82
92
|
this.pattern = pattern;
|
|
83
93
|
this.options = options;
|
|
94
|
+
_defineProperty(this, "savedFilesCount", 0);
|
|
84
95
|
}
|
|
85
96
|
async list() {
|
|
86
97
|
const host = this.componentMain.getHost();
|
|
87
98
|
const ids = await host.idsByPattern(this.pattern);
|
|
88
99
|
const scope = this.componentMain.getHost(_scope().ScopeAspect.id);
|
|
89
|
-
// import
|
|
100
|
+
// re-import the version objects so we pick up any builder data added by the remote build
|
|
101
|
+
// pipeline after the local snap was created (the local Version may have been stored with
|
|
102
|
+
// empty BuilderAspect data — the Version hash excludes extension data, so it isn't replaced
|
|
103
|
+
// on a normal cached import). passing the current lane routes the fetch to the lane's scope
|
|
104
|
+
// where snaps actually live, and the lane-aware fetcher writes back any updated Version.
|
|
105
|
+
const currentLane = await scope.legacyScope.getCurrentLaneObject();
|
|
90
106
|
await scope.legacyScope.scopeImporter.importWithoutDeps(_componentId().ComponentIdList.fromArray(ids), {
|
|
91
|
-
|
|
107
|
+
lane: currentLane,
|
|
108
|
+
reason: 'to refresh build artifacts'
|
|
92
109
|
});
|
|
93
110
|
const components = await host.getMany(ids);
|
|
94
111
|
const artifactListPerId = components.map(component => {
|
|
@@ -98,7 +115,7 @@ class ArtifactExtractor {
|
|
|
98
115
|
};
|
|
99
116
|
});
|
|
100
117
|
this.filterByOptions(artifactListPerId);
|
|
101
|
-
await this.saveFilesInFileSystemIfAsked(artifactListPerId);
|
|
118
|
+
this.savedFilesCount = await this.saveFilesInFileSystemIfAsked(artifactListPerId);
|
|
102
119
|
return this.artifactsObjectsToExtractorResults(artifactListPerId);
|
|
103
120
|
}
|
|
104
121
|
groupResultsByAspect(extractorResult) {
|
|
@@ -116,9 +133,10 @@ class ArtifactExtractor {
|
|
|
116
133
|
async saveFilesInFileSystemIfAsked(artifactListPerId) {
|
|
117
134
|
const outDir = this.options.outDir;
|
|
118
135
|
if (!outDir) {
|
|
119
|
-
return;
|
|
136
|
+
return 0;
|
|
120
137
|
}
|
|
121
138
|
const scope = this.componentMain.getHost(_scope().ScopeAspect.id);
|
|
139
|
+
let totalSaved = 0;
|
|
122
140
|
// @todo: optimize this to first import all missing hashes.
|
|
123
141
|
await (0, _pMapSeries().default)(artifactListPerId, async ({
|
|
124
142
|
id,
|
|
@@ -130,8 +148,15 @@ class ArtifactExtractor {
|
|
|
130
148
|
replacement: '_'
|
|
131
149
|
});
|
|
132
150
|
const compPath = _path().default.join(outDir, idAsFilename);
|
|
133
|
-
await Promise.all(vinyls.map(vinyl =>
|
|
151
|
+
await Promise.all(vinyls.map(vinyl => {
|
|
152
|
+
if (!(0, _legacy().isValidPath)(vinyl.path)) {
|
|
153
|
+
throw new Error(`refusing to write artifact "${vinyl.path}" for ${id.toString()}: unsafe path`);
|
|
154
|
+
}
|
|
155
|
+
return _fsExtra().default.outputFile(_path().default.join(compPath, vinyl.path), vinyl.contents);
|
|
156
|
+
}));
|
|
157
|
+
totalSaved += vinyls.length;
|
|
134
158
|
});
|
|
159
|
+
return totalSaved;
|
|
135
160
|
}
|
|
136
161
|
artifactsObjectsToExtractorResults(artifactListPerId) {
|
|
137
162
|
return artifactListPerId.map(({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_path","data","_interopRequireDefault","require","_filenamify","_fsExtra","_scope","_componentId","_pMapSeries","_minimatch","_component","_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 type { ComponentMain } from '@teambit/component';\nimport type { ScopeMain } from '@teambit/scope';\nimport { ScopeAspect } from '@teambit/scope';\nimport type { ComponentID } from '@teambit/component-id';\nimport { ComponentIdList } from '@teambit/component-id';\nimport pMapSeries from 'p-map-series';\nimport minimatch from 'minimatch';\nimport { ArtifactFiles } from '@teambit/component.sources';\nimport type { BuilderMain } from '../builder.main.runtime';\nimport type { 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;AAGA,SAAAK,OAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,MAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAM,aAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,YAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,YAAA;EAAA,MAAAP,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAK,WAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAA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;IAC9D,MAAM;MAAE4C,MAAM;MAAEP,IAAI;MAAEG;IAAM,CAAC,GAAG,IAAI,CAACzD,OAAO;IAC5C,IAAI8D,iBAA6B,GAAG,EAAE;IAEtC7C,iBAAiB,CAAC8C,OAAO,CAAEC,IAAI,IAAK;MAClCF,iBAAiB,GAAGE,IAAI,CAAC5C,SAAS,CAAC6C,MAAM,CAAEd,QAAQ,IAAK;QACtD,IAAIU,MAAM,IAAIA,MAAM,KAAKV,QAAQ,CAACG,IAAI,CAACvB,QAAQ,EAAE,OAAO,KAAK;QAC7D,IAAIuB,IAAI,IAAIA,IAAI,KAAKH,QAAQ,CAACG,IAAI,CAACD,IAAI,EAAE,OAAO,KAAK;QACrD,OAAO,IAAI;MACb,CAAC,CAAC;MACF,IAAII,KAAK,EAAE;QACTK,iBAAiB,GAAGE,IAAI,CAAC5C,SAAS,CAC/BF,GAAG,CAAEiC,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,0BAAa,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,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","_component","_legacy","_artifactList","_artifact","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ArtifactExtractor","constructor","componentMain","builder","pattern","options","list","host","getHost","ids","idsByPattern","scope","ScopeAspect","id","currentLane","legacyScope","getCurrentLaneObject","scopeImporter","importWithoutDeps","ComponentIdList","fromArray","lane","reason","components","getMany","artifactListPerId","map","component","artifacts","getArtifacts","filterByOptions","savedFilesCount","saveFilesInFileSystemIfAsked","artifactsObjectsToExtractorResults","groupResultsByAspect","extractorResult","result","reduce","acc","current","aspectId","push","outDir","totalSaved","pMapSeries","vinyls","getVinylsAndImportIfMissing","idAsFilename","filenamify","toStringWithoutVersion","replacement","compPath","path","join","Promise","all","vinyl","isValidPath","Error","toString","fs","outputFile","contents","length","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 type { ComponentMain } from '@teambit/component';\nimport type { ScopeMain } from '@teambit/scope';\nimport { ScopeAspect } from '@teambit/scope';\nimport type { ComponentID } from '@teambit/component-id';\nimport { ComponentIdList } from '@teambit/component-id';\nimport pMapSeries from 'p-map-series';\nimport minimatch from 'minimatch';\nimport { ArtifactFiles } from '@teambit/component.sources';\nimport { isValidPath } from '@teambit/legacy.utils';\nimport type { BuilderMain } from '../builder.main.runtime';\nimport type { 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 savedFilesCount = 0;\n\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 // re-import the version objects so we pick up any builder data added by the remote build\n // pipeline after the local snap was created (the local Version may have been stored with\n // empty BuilderAspect data — the Version hash excludes extension data, so it isn't replaced\n // on a normal cached import). passing the current lane routes the fetch to the lane's scope\n // where snaps actually live, and the lane-aware fetcher writes back any updated Version.\n const currentLane = await scope.legacyScope.getCurrentLaneObject();\n await scope.legacyScope.scopeImporter.importWithoutDeps(ComponentIdList.fromArray(ids), {\n lane: currentLane,\n reason: 'to refresh build artifacts',\n });\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 this.savedFilesCount = 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[]): Promise<number> {\n const outDir = this.options.outDir;\n if (!outDir) {\n return 0;\n }\n const scope = this.componentMain.getHost(ScopeAspect.id) as ScopeMain;\n let totalSaved = 0;\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(\n vinyls.map((vinyl) => {\n if (!isValidPath(vinyl.path)) {\n throw new Error(`refusing to write artifact \"${vinyl.path}\" for ${id.toString()}: unsafe path`);\n }\n return fs.outputFile(path.join(compPath, vinyl.path), vinyl.contents);\n })\n );\n totalSaved += vinyls.length;\n });\n return totalSaved;\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,Y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,KAAK,EAAE;QACTK,iBAAiB,GAAGE,IAAI,CAAClD,SAAS,CAC/BF,GAAG,CAAEuC,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,0BAAa,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,CAAC,CAAC,CAAC;MAC9C;MACAN,IAAI,CAAClD,SAAS,GAAGyD,4BAAY,CAACjE,SAAS,CAACwD,iBAAiB,CAAC;IAC5D,CAAC,CAAC;EACJ;AACF;AAACU,OAAA,CAAAtF,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -60,6 +60,10 @@ use --out-dir to download artifacts locally for inspection or deployment purpose
|
|
|
60
60
|
async report([componentPattern], artifactsOpts) {
|
|
61
61
|
const artifactExtractor = new (_artifactExtractor().ArtifactExtractor)(this.componentMain, this.builder, componentPattern, artifactsOpts);
|
|
62
62
|
const list = await artifactExtractor.list();
|
|
63
|
+
const totalArtifacts = list.reduce((sum, r) => sum + r.artifacts.length, 0);
|
|
64
|
+
if (totalArtifacts === 0) {
|
|
65
|
+
return (0, _cli().formatWarningSummary)(`no artifacts found for "${componentPattern}"`);
|
|
66
|
+
}
|
|
63
67
|
const grouped = artifactExtractor.groupResultsByAspect(list);
|
|
64
68
|
const outputArtifacts = (aspectId, artifactData) => {
|
|
65
69
|
const title = (0, _cli().formatTitle)(aspectId);
|
|
@@ -75,7 +79,7 @@ use --out-dir to download artifacts locally for inspection or deployment purpose
|
|
|
75
79
|
const artifacts = Object.keys(result.artifacts).map(aspectId => outputArtifacts(aspectId, result.artifacts[aspectId])).join('\n\n');
|
|
76
80
|
return `${idStr}\n${artifacts}`;
|
|
77
81
|
};
|
|
78
|
-
const footer = artifactsOpts.outDir ? `\n\n${(0, _cli().formatSuccessSummary)(
|
|
82
|
+
const footer = artifactsOpts.outDir ? `\n\n${(0, _cli().formatSuccessSummary)(`${artifactExtractor.savedFilesCount} file(s) saved to "${artifactsOpts.outDir}"`)}` : '';
|
|
79
83
|
return grouped.map(outputResult).join('\n\n') + footer;
|
|
80
84
|
}
|
|
81
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_cli","data","require","_chalk","_interopRequireDefault","_legacy","_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","formatTitle","artifactDataStr","map","artifact","subTitle","chalk","white","taskName","artifactName","files","f","dim","join","outputResult","result","idStr","cyan","id","toString","
|
|
1
|
+
{"version":3,"names":["_cli","data","require","_chalk","_interopRequireDefault","_legacy","_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","totalArtifacts","reduce","sum","artifacts","length","formatWarningSummary","grouped","groupResultsByAspect","outputArtifacts","aspectId","artifactData","title","formatTitle","artifactDataStr","map","artifact","subTitle","chalk","white","taskName","artifactName","files","f","dim","join","outputResult","result","idStr","cyan","id","toString","keys","footer","outDir","formatSuccessSummary","savedFilesCount","exports"],"sources":["artifacts.cmd.ts"],"sourcesContent":["import type { Command, CommandOptions } from '@teambit/cli';\nimport { formatTitle, formatSuccessSummary, formatWarningSummary } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { COMPONENT_PATTERN_HELP } from '@teambit/legacy.constants';\nimport type { ComponentMain } from '@teambit/component';\nimport type { BuilderMain } from '../builder.main.runtime';\nimport type { ExtractorArtifactResult, ExtractorResultGrouped } from './artifact-extractor';\nimport { ArtifactExtractor } 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 = 'view and download build artifacts';\n extendedDescription = `displays artifacts created during the build pipeline in isolated capsules during tag or snap operations.\nartifacts include compiled files, test reports, package files, and other build outputs generated by various tasks.\nuse --out-dir to download artifacts locally for inspection or deployment purposes.`;\n arguments = [\n {\n name: 'component-pattern',\n description: COMPONENT_PATTERN_HELP,\n },\n ];\n alias = '';\n group = 'testing';\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(\n private builder: BuilderMain,\n private componentMain: ComponentMain\n ) {}\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 totalArtifacts = list.reduce((sum, r) => sum + r.artifacts.length, 0);\n if (totalArtifacts === 0) {\n return formatWarningSummary(`no artifacts found for \"${componentPattern}\"`);\n }\n const grouped = artifactExtractor.groupResultsByAspect(list);\n const outputArtifacts = (aspectId: string, artifactData: ExtractorArtifactResult[]) => {\n const title = formatTitle(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 ? `\\n\\n${formatSuccessSummary(`${artifactExtractor.savedFilesCount} file(s) saved to \"${artifactsOpts.outDir}\"`)}`\n : '';\n return grouped.map(outputResult).join('\\n\\n') + footer;\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,KAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,IAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,OAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,MAAA,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;EAAA;EAAA,OAAAA,IAAA;AAAA;AAIA,SAAAK,mBAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,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jD,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.pipelines_builder@1.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.pipelines_builder@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.pipelines_builder@1.0.979/dist/builder.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.pipelines_builder@1.0.979/dist/builder.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/builder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.979",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/pipelines/builder",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.pipelines",
|
|
8
8
|
"name": "builder",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.979"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chalk": "4.1.2",
|
|
@@ -40,16 +40,16 @@
|
|
|
40
40
|
"@teambit/component-id": "1.2.4",
|
|
41
41
|
"@teambit/legacy.utils": "0.0.35",
|
|
42
42
|
"@teambit/legacy.scope": "0.0.112",
|
|
43
|
-
"@teambit/component": "1.0.
|
|
44
|
-
"@teambit/envs": "1.0.
|
|
45
|
-
"@teambit/isolator": "1.0.
|
|
46
|
-
"@teambit/workspace": "1.0.
|
|
47
|
-
"@teambit/aspect-loader": "1.0.
|
|
48
|
-
"@teambit/generator": "1.0.
|
|
49
|
-
"@teambit/graphql": "1.0.
|
|
50
|
-
"@teambit/issues": "1.0.
|
|
51
|
-
"@teambit/scope": "1.0.
|
|
52
|
-
"@teambit/ui": "1.0.
|
|
43
|
+
"@teambit/component": "1.0.979",
|
|
44
|
+
"@teambit/envs": "1.0.979",
|
|
45
|
+
"@teambit/isolator": "1.0.979",
|
|
46
|
+
"@teambit/workspace": "1.0.979",
|
|
47
|
+
"@teambit/aspect-loader": "1.0.979",
|
|
48
|
+
"@teambit/generator": "1.0.980",
|
|
49
|
+
"@teambit/graphql": "1.0.979",
|
|
50
|
+
"@teambit/issues": "1.0.979",
|
|
51
|
+
"@teambit/scope": "1.0.979",
|
|
52
|
+
"@teambit/ui": "1.0.979"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/pretty-time": "^1.1.5",
|