Skip to content

Commit b6d9dc1

Browse files
authored
feat, support publishing to an external registry during snap (#9606)
1 parent 5c5d8a3 commit b6d9dc1

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

e2e/harmony/build-cmd.e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ describe('build command', function () {
5252
helper.scopeHelper.setNewLocalAndRemoteScopes();
5353
helper.fixtures.populateComponents(1);
5454
});
55-
it('should list the publish task in the tagPipeline but not in the snapPipeline', async () => {
55+
it('should list the publish task in the tagPipeline and in the snapPipeline', async () => {
5656
const harmony = await loadBit(helper.scopes.localPath);
5757
const workspace = harmony.get<Workspace>(WorkspaceAspect.id);
5858
const compId = await workspace.resolveComponentId('comp1');
5959
const component = await workspace.get(compId);
6060
const builder = harmony.get<BuilderMain>(BuilderAspect.id);
6161
const tasks = builder.listTasks(component);
62-
expect(tasks.snapTasks).to.not.include('teambit.pkg/pkg:PublishComponents');
62+
expect(tasks.snapTasks).to.include('teambit.pkg/pkg:PublishComponents');
6363
expect(tasks.tagTasks).to.include('teambit.pkg/pkg:PublishComponents');
6464
});
6565
});

e2e/harmony/publish.e2e.4.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,32 @@ describe('publish functionality', function () {
6060
expect(output.trim()).to.be.equal(appOutput.trim());
6161
});
6262
});
63+
describe('automatically by snap pipeline', () => {
64+
before(() => {
65+
helper.scopeHelper.getClonedLocalScope(scopeBeforeTag);
66+
helper.command.tagIncludeUnmodified('1.0.5');
67+
helper.command.snapAllComponents('--unmodified');
68+
});
69+
it('should publish them successfully using the 0.0.0-snap version and not changing the "latest" tag', () => {
70+
const headSnap = helper.command.getHead('comp1');
71+
const comp1Pkg = `@${DEFAULT_OWNER}/${scopeWithoutOwner}.comp1`;
72+
const npmTag = helper.command.runCmd(`npm dist-tags ls ${comp1Pkg}`);
73+
expect(npmTag).to.have.string('latest: 1.0.5');
74+
expect(npmTag).to.have.string(`snap: 0.0.0-${headSnap}`);
75+
});
76+
it('should publish them successfully and be able to consume them by installing the packages', () => {
77+
const headSnap = helper.command.getHead('comp1');
78+
helper.scopeHelper.reInitLocalScope();
79+
helper.npm.initNpm();
80+
helper.npm.installNpmPackage(`@${DEFAULT_OWNER}/${scopeWithoutOwner}.comp1`, `0.0.0-${headSnap}`);
81+
helper.fs.outputFile(
82+
'app.js',
83+
`const comp1 = require('@${DEFAULT_OWNER}/${scopeWithoutOwner}.comp1').default;\nconsole.log(comp1())`
84+
);
85+
const output = helper.command.runCmd('node app.js');
86+
expect(output.trim()).to.be.equal(appOutput.trim());
87+
});
88+
});
6389
describe('using "bit publish"', () => {
6490
before(async () => {
6591
helper.scopeHelper.getClonedLocalScope(scopeBeforeTag);

scopes/pkg/pkg/pkg.main.runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class PkgMain {
168168
// dryRunTask.dependencies = [BuildTaskHelper.serializeId(preparePackagesTask)];
169169
builder.registerBuildTasks([preparePackagesTask]);
170170
builder.registerTagTasks([preparePackagesTask, packTask, publishTask]);
171-
builder.registerSnapTasks([preparePackagesTask, packTask]);
171+
builder.registerSnapTasks([preparePackagesTask, packTask, publishTask]);
172172

173173
const calcPkgOnLoad = async (component: Component) => {
174174
const data = await pkg.mergePackageJsonProps(component);

scopes/pkg/pkg/publisher.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComponentResult, TaskMetadata } from '@teambit/builder';
22
import { Component, ComponentID } from '@teambit/component';
3+
import { isSnap } from '@teambit/component-version';
34
import { Capsule, IsolatorMain } from '@teambit/isolator';
45
import { Logger } from '@teambit/logger';
56
import { Workspace } from '@teambit/workspace';
@@ -63,6 +64,7 @@ export class Publisher {
6364
}
6465
if (this.options.dryRun) publishParams.push('--dry-run');
6566
publishParams.push(...this.getTagFlagForPreRelease(capsule.component.id));
67+
publishParams.push(...this.getTagFlagForSnap(capsule.component.id));
6668
const extraArgs = this.getExtraArgsFromConfig(capsule.component);
6769
if (extraArgs && Array.isArray(extraArgs) && extraArgs?.length) {
6870
const extraArgsSplit = extraArgs.map((arg) => arg.split(' ')).flat();
@@ -129,6 +131,14 @@ export class Publisher {
129131
return ['--tag', maybeIdentifier];
130132
}
131133

134+
private getTagFlagForSnap(id: ComponentID): string[] {
135+
if (isSnap(id.version)) {
136+
const snapTag = 'snap';
137+
return ['--tag', snapTag];
138+
}
139+
return [];
140+
}
141+
132142
private async getComponentCapsules(componentIds: ComponentID[]): Promise<Capsule[]> {
133143
const idsToPublish = await this.getIdsToPublish(componentIds);
134144
this.logger.debug(`total ${idsToPublish.length} to publish out of ${componentIds.length}`);

0 commit comments

Comments
 (0)