diff --git a/e2e/harmony/artifacts.e2e.ts b/e2e/harmony/artifacts.e2e.ts index 6313b9704959..69d5365313e1 100644 --- a/e2e/harmony/artifacts.e2e.ts +++ b/e2e/harmony/artifacts.e2e.ts @@ -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(() => { diff --git a/scopes/pipelines/builder/artifact/artifact-extractor.ts b/scopes/pipelines/builder/artifact/artifact-extractor.ts index 77d997c16649..506afffc690e 100644 --- a/scopes/pipelines/builder/artifact/artifact-extractor.ts +++ b/scopes/pipelines/builder/artifact/artifact-extractor.ts @@ -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'; @@ -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 { - 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, @@ -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); diff --git a/scopes/pipelines/builder/artifact/artifacts.cmd.ts b/scopes/pipelines/builder/artifact/artifacts.cmd.ts index 97e2fa897120..37fc0778a344 100644 --- a/scopes/pipelines/builder/artifact/artifacts.cmd.ts +++ b/scopes/pipelines/builder/artifact/artifacts.cmd.ts @@ -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'; @@ -44,11 +43,10 @@ and a package.tgz file generated by pkg aspect. ['', 'out-dir ', '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 { - 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[]) => { diff --git a/scopes/pipelines/builder/builder.main.runtime.ts b/scopes/pipelines/builder/builder.main.runtime.ts index 906a047894c1..583f95ae9754 100644 --- a/scopes/pipelines/builder/builder.main.runtime.ts +++ b/scopes/pipelines/builder/builder.main.runtime.ts @@ -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;