Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ComponentUI): Package version for snaps on main #7141

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions scopes/component/component/component.ui.runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import flatten from 'lodash.flatten';
import copy from 'copy-to-clipboard';
import type { RouteProps } from 'react-router-dom';

import * as semver from 'semver';
import type { LinkProps } from '@teambit/base-react.navigation.link';
import CommandBarAspect, { CommandBarUI, CommandEntry } from '@teambit/command-bar';
import { DeprecationIcon } from '@teambit/component.ui.deprecation-icon';
Expand Down Expand Up @@ -79,11 +79,16 @@ export class ComponentUI {
*/
private activeComponent?: ComponentModel;

formatToInstallableVersion(version: string) {
if (semver.valid(version)) return version;
luvkapur marked this conversation as resolved.
Show resolved Hide resolved
return `0.0.0-${version}`;
}

private copyNpmId = () => {
const packageName = this.activeComponent?.packageName;
if (packageName) {
const version = this.activeComponent?.id.version;
const versionString = version ? `@${version}` : '';
const versionString = version ? `@${this.formatToInstallableVersion(version)}` : '';
copy(`${packageName}${versionString}`);
}
};
Expand Down Expand Up @@ -136,7 +141,7 @@ export class ComponentUI {
];

private bitMethod: ConsumePlugin = (comp, options) => {
const version = comp.version === comp.latest ? '' : `@${comp.version}`;
const version = comp.version === comp.latest ? '' : `@${this.formatToInstallableVersion(comp.version)}`;
return {
Title: <img style={{ width: '20px' }} src="https://static.bit.dev/brands/bit-logo-text.svg" />,
Component: (
Expand Down
8 changes: 6 additions & 2 deletions scopes/dependencies/pnpm/pnpm.ui.runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ export class PnpmUI {
static dependencies = [ComponentAspect];

static async provider([componentUI]: [ComponentUI]) {
const pnpm = new PnpmUI();
const pnpm = new PnpmUI(componentUI);
componentUI.registerConsumeMethod(pnpm.consumeMethod);
return pnpm;
}

constructor(private compUI: ComponentUI) {}

private consumeMethod: ConsumePlugin = (comp, options) => {
if (options?.currentLane) return undefined;

const registry = comp.packageName.split('/')[0];
const packageVersion = comp.version === comp.latest ? '' : `@${comp.version}`;
const packageVersion =
comp.version === comp.latest ? '' : `@${this.compUI.formatToInstallableVersion(comp.version)}`;

return {
Title: <img style={{ height: '16px', marginTop: '-2px' }} src="https://static.bit.dev/brands/pnpm.svg" />,
Component: (
Expand Down
8 changes: 6 additions & 2 deletions scopes/dependencies/yarn/yarn.ui.runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ export class YarnUI {
static dependencies = [ComponentAspect];

static async provider([componentUI]: [ComponentUI]) {
const yarn = new YarnUI();
const yarn = new YarnUI(componentUI);
componentUI.registerConsumeMethod(yarn.consumeMethod);
return yarn;
}

constructor(private compUI: ComponentUI) {}

private consumeMethod: ConsumePlugin = (comp, options) => {
if (options?.currentLane) return undefined;

const registry = comp.packageName.split('/')[0];
const packageVersion = comp.version === comp.latest ? '' : `@${comp.version}`;
const packageVersion =
comp.version === comp.latest ? '' : `@${this.compUI.formatToInstallableVersion(comp.version)}`;

return {
Title: (
<img style={{ height: '17px', paddingTop: '4px' }} src="https://static.bit.dev/brands/logo-yarn-text.svg" />
Expand Down
9 changes: 7 additions & 2 deletions scopes/pkg/pkg/pkg.ui.runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ export class PkgUI {
static dependencies = [ComponentAspect];

static async provider([componentUI]: [ComponentUI]) {
const pkg = new PkgUI();
const pkg = new PkgUI(componentUI);
componentUI.registerConsumeMethod(pkg.npmConsumeMethod);
return pkg;
}

constructor(private compUI: ComponentUI) {}

private npmConsumeMethod: ConsumePlugin = (comp, options) => {
if (options?.currentLane) return undefined;

const registry = comp.packageName.split('/')[0];
const packageVersion = comp.version === comp.latest ? '' : `@${comp.version}`;

const packageVersion =
comp.version === comp.latest ? '' : `@${this.compUI.formatToInstallableVersion(comp.version)}`;

return {
Title: <img style={{ width: '30px' }} src="https://static.bit.dev/brands/logo-npm-new.svg" />,
Component: (
Expand Down