Skip to content

feat: read bit version from workspace.jsonc if no version is specified #105

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
101 changes: 96 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion teambit.bvm/commands/install/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class InstallCmd implements CommandModule {
builder(yargs: Argv) {
yargs.positional('bit-version', {
describe: 'version to install',
default: 'latest',
type: 'string'
})
.option({
Expand Down
13 changes: 13 additions & 0 deletions teambit.bvm/install/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { BvmError } from '@teambit/bvm.error';
import {linkOne, PathExtenderReport} from '@teambit/bvm.link';
import { GcpListOptions, getOsType, listRemote } from '@teambit/bvm.list';
import { FsTarVersion } from '@teambit/bvm.fs-tar-version';
import { parse as parseCommentJson } from 'comment-json';
import { installWithPnpm } from './installWithPnpm';

export type InstallOpts = GcpListOptions & {
Expand Down Expand Up @@ -62,12 +63,15 @@ export async function installVersion(version: string, opts: InstallOpts = defaul

let resolvedVersion = version;
if (!version || version === 'latest') {
let versionFromWorkspaceManifest: string | undefined;
if (opts.file) {
const versionFromFileName = getBitVersionFromFilePath(opts.file);
if (!versionFromFileName) {
throw new BvmError(`Could not detect bit version from file name "${opts.file}"`);
}
resolvedVersion = versionFromFileName;
} else if (!version && (versionFromWorkspaceManifest = getVersionFromWorkspaceJsonc())) {
resolvedVersion = versionFromWorkspaceManifest;
} else {
const remoteVersionList = await listRemote({os: opts.os, arch: opts.arch});
resolvedVersion = remoteVersionList.latest().version;
Expand Down Expand Up @@ -179,6 +183,15 @@ export async function installVersion(version: string, opts: InstallOpts = defaul
}
}

function getVersionFromWorkspaceJsonc(): string | undefined {
try {
const workspaceManifest = parseCommentJson(fs.readFileSync('workspace.jsonc', 'utf8'));
return workspaceManifest?.['teambit.harmony/bit']?.engine;
} catch {
return undefined;
}
}

async function installFromRegistry(
opts: {
resolvedVersion: string;
Expand Down
1 change: 1 addition & 0 deletions workspace.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"bin-links": "2.2.1",
"chalk": "4.1.0",
"cli-progress": "3.10.0",
"comment-json": "^4.2.5",
"date-fns": "2.19.0",
"execa": "5.1.1",
"fs-extra": "9.1.0",
Expand Down