Skip to content

Commit

Permalink
fix(artifacts): support using full-component-id for staged components (
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfirst authored May 18, 2023
1 parent 8f534da commit d3b19cf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
3 changes: 3 additions & 0 deletions e2e/harmony/artifacts.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ describe('bit artifacts command', function () {
it('should not throw an error about missing scope', () => {
expect(() => helper.command.artifacts('comp1')).to.not.throw();
});
it('should be able to work when using the full component-id', () => {
expect(() => helper.command.artifacts('my-scope/comp1')).to.not.throw();
});
});
describe('running the command on a snap', () => {
before(() => {
Expand Down
13 changes: 8 additions & 5 deletions scopes/pipelines/builder/artifact/artifact-extractor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'path';
import filenamify from 'filenamify';
import fs from 'fs-extra';
import { ScopeMain } from '@teambit/scope';
import { ComponentMain } from '@teambit/component';
import ScopeAspect, { ScopeMain } from '@teambit/scope';
import { ComponentID } from '@teambit/component-id';
import pMapSeries from 'p-map-series';
import minimatch from 'minimatch';
Expand Down Expand Up @@ -35,15 +36,16 @@ type ArtifactListPerId = {

export class ArtifactExtractor {
constructor(
private scope: ScopeMain,
private componentMain: ComponentMain,
private builder: BuilderMain,
private pattern: string,
private options: ArtifactsOpts
) {}

async list(): Promise<ExtractorResult[]> {
const ids = await this.scope.idsByPattern(this.pattern);
const components = await this.scope.getMany(ids);
const host = this.componentMain.getHost();
const ids = await host.idsByPattern(this.pattern);
const components = await host.getMany(ids);
const artifactListPerId: ArtifactListPerId[] = components.map((component) => {
return {
id: component.id,
Expand Down Expand Up @@ -71,9 +73,10 @@ export class ArtifactExtractor {
if (!outDir) {
return;
}
const scope = this.componentMain.getHost(ScopeAspect.id) as ScopeMain;
// @todo: optimize this to first import all missing hashes.
await pMapSeries(artifactListPerId, async ({ id, artifacts }) => {
const vinyls = await artifacts.getVinylsAndImportIfMissing(id._legacy, this.scope.legacyScope);
const vinyls = await artifacts.getVinylsAndImportIfMissing(id._legacy, scope.legacyScope);
// make sure the component-dir is just one dir. without this, every slash in the component-id will create a new dir.
const idAsFilename = filenamify(id.toStringWithoutVersion(), { replacement: '_' });
const compPath = path.join(outDir, idAsFilename);
Expand Down
8 changes: 3 additions & 5 deletions scopes/pipelines/builder/artifact/artifacts.cmd.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Command, CommandOptions } from '@teambit/cli';
import chalk from 'chalk';
import { COMPONENT_PATTERN_HELP } from '@teambit/legacy/dist/constants';
import { BitError } from '@teambit/bit-error';
import { ScopeMain } from '@teambit/scope';
import { ComponentMain } from '@teambit/component';
import { BuilderMain } from '../builder.main.runtime';
import { ArtifactExtractor, ExtractorArtifactResult, ExtractorResultGrouped } from './artifact-extractor';

Expand Down Expand Up @@ -44,11 +43,10 @@ and a package.tgz file generated by pkg aspect.
['', 'out-dir <string>', 'download the files to the specified dir'],
] as CommandOptions;

constructor(private builder: BuilderMain, private scope: ScopeMain) {}
constructor(private builder: BuilderMain, private componentMain: ComponentMain) {}

async report([componentPattern]: [string], artifactsOpts: ArtifactsOpts): Promise<string> {
if (!this.scope) throw new BitError(`unable to run "bit artifacts" outside of a workspace or a scope`);
const artifactExtractor = new ArtifactExtractor(this.scope, this.builder, componentPattern, artifactsOpts);
const artifactExtractor = new ArtifactExtractor(this.componentMain, this.builder, componentPattern, artifactsOpts);
const list = await artifactExtractor.list();
const grouped = artifactExtractor.groupResultsByAspect(list);
const outputArtifacts = (aspectId: string, artifactData: ExtractorArtifactResult[]) => {
Expand Down
2 changes: 1 addition & 1 deletion scopes/pipelines/builder/builder.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export class BuilderMain {
component.registerRoute([new BuilderRoute(builder, scope, logger)]);
graphql.register(builderSchema(builder, logger));
if (generator) generator.registerComponentTemplate([buildTaskTemplate]);
const commands = [new BuilderCmd(builder, workspace, logger), new ArtifactsCmd(builder, scope)];
const commands = [new BuilderCmd(builder, workspace, logger), new ArtifactsCmd(builder, component)];
cli.register(...commands);

return builder;
Expand Down

0 comments on commit d3b19cf

Please sign in to comment.