Skip to content

Commit 65b43e8

Browse files
jyash97CompuIves
authored andcommitted
fix(embed): parse csb package version number (codesandbox#3010)
1 parent b1590c0 commit 65b43e8

File tree

3 files changed

+14
-13
lines changed
  • packages
    • app/src
      • app/pages/Sandbox/Editor/Workspace/Dependencies/VersionEntry
      • embed/components/Sidebar/Dependencies
    • common/src/utils

3 files changed

+14
-13
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies/VersionEntry/index.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ArrowDropUp from 'react-icons/lib/md/keyboard-arrow-up';
66
import algoliasearch from 'algoliasearch/lite';
77
import compareVersions from 'compare-versions';
88
import Tooltip from '@codesandbox/common/lib/components/Tooltip';
9-
import { CSB_PKG_PROTOCOL } from '@codesandbox/common/lib/utils/ci';
9+
import { formatVersion } from '@codesandbox/common/lib/utils/ci';
1010

1111
import { EntryContainer, IconArea, Icon } from '../../elements';
1212
import { Link } from '../elements';
@@ -27,17 +27,6 @@ interface State {
2727
versions: string[];
2828
}
2929

30-
function formatVersion(version: string) {
31-
if (CSB_PKG_PROTOCOL.test(version)) {
32-
const commitSha = version.match(/commit\/([\w\d]*)\//);
33-
if (commitSha && commitSha[1]) {
34-
return `csb:${commitSha[1]}`;
35-
}
36-
}
37-
38-
return version;
39-
}
40-
4130
export class VersionEntry extends React.PureComponent<Props, State> {
4231
state: State = {
4332
hovering: false,

packages/app/src/embed/components/Sidebar/Dependencies/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { formatVersion } from '@codesandbox/common/lib/utils/ci';
23
import { Container, Row } from './elements';
34

45
function Dependencies({ sandbox }) {
@@ -23,7 +24,7 @@ function Dependencies({ sandbox }) {
2324
{Object.keys(npmDependencies).map(dep => (
2425
<Row key={dep}>
2526
<span>{dep}</span>
26-
<span>{npmDependencies[dep]}</span>
27+
<span>{formatVersion(npmDependencies[dep])}</span>
2728
</Row>
2829
))}
2930
</Container>

packages/common/src/utils/ci.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
export const CSB_PKG_PROTOCOL = /https:\/\/pkg(-staging)?\.csb.dev/;
2+
3+
export const formatVersion = (version: string) => {
4+
if (CSB_PKG_PROTOCOL.test(version)) {
5+
const commitSha = version.match(/commit\/([\w\d]*)\//);
6+
if (commitSha && commitSha[1]) {
7+
return `csb:${commitSha[1]}`;
8+
}
9+
}
10+
11+
return version;
12+
};

0 commit comments

Comments
 (0)