Skip to content

Commit

Permalink
fix: -v incorrectly using previous version
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekyEggo committed Jun 28, 2024
1 parent 84613bf commit b81675b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"watch:exports": "tsup --watch",
"lint": "eslint . --ext .ts --max-warnings 0",
"lint:fix": "prettier \"./src/**/*.ts\" --write",
"preversion": "npm run build && npm run lint"
"preversion": "npm run lint",
"version": "npm run build"
},
"prettier": "@elgato/prettier-config",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { program } from "commander";
import { config, create, link, pack, restart, setDeveloperMode, stop, validate } from "./commands";
import { packageManager } from "./package-manager";

program.version(packageManager.getVersion(), "-v", "display CLI version");
program.version(packageManager.getVersion({ checkEnvironment: true }), "-v", "display CLI version");

program
.command("create")
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { homedir, platform } from "node:os";
import { dirname, join } from "node:path";

import { relative } from "./system/path";
import { packageManager } from "./package-manager";

let __config: Config | undefined = undefined;

Expand All @@ -17,7 +17,7 @@ export const defaultConfig: Config = Object.freeze({
npm: {
cli: {
mode: "prod" as const,
version: `^${JSON.parse(readFileSync(relative("../package.json"), { encoding: "utf-8" })).version}`,
version: `^${packageManager.getVersion()}`,
},
streamDeck: {
mode: "prod" as const,
Expand Down
23 changes: 19 additions & 4 deletions src/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ class PackageManager {
}

/**
* Gets the version of the current package; when installed as part of a development environment, the version is suffixed appropriately.
* @returns Version.
* Gets the current version of the CLI from the package JSON file.
* @param opts Version format options.
* @returns The version, for example `0.3.0`.
*/
public getVersion(): string {
return existsSync(relative("../src")) ? `${version} (dev)` : version;
public getVersion(opts: GetVersionOptions = {}): string {
if (opts.checkEnvironment && existsSync(relative("../src"))) {
return `${version} (dev)`;
}

return version;
}

/**
Expand Down Expand Up @@ -251,3 +256,13 @@ export type PackageMetadataVersion = {
tarball: string;
};
};

/**
* Options for {@link PackageManager.getVersion}.
*/
type GetVersionOptions = {
/**
* Determines whether to check the if the CLI is in development mode; when `true` the version will include a suffix of `(dev)`.
*/
checkEnvironment?: boolean;
};

0 comments on commit b81675b

Please sign in to comment.