chore: fix --version weird error
This commit is contained in:
@@ -7,7 +7,6 @@ import https from 'https';
|
|||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import ora from 'ora';
|
import ora from 'ora';
|
||||||
import boxen from 'boxen';
|
import boxen from 'boxen';
|
||||||
import packageJson from '../../../../package.json' with { type: 'json' };
|
|
||||||
|
|
||||||
export interface UpdateInfo {
|
export interface UpdateInfo {
|
||||||
currentVersion: string;
|
currentVersion: string;
|
||||||
@@ -16,15 +15,18 @@ export interface UpdateInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current version from package.json
|
* Get current version from build-time injected environment variable
|
||||||
*/
|
*/
|
||||||
function getCurrentVersion(): string {
|
function getCurrentVersion(): string {
|
||||||
try {
|
// Version is injected at build time via TM_PUBLIC_VERSION
|
||||||
return packageJson.version;
|
const version = process.env.TM_PUBLIC_VERSION;
|
||||||
} catch (error) {
|
if (version && version !== 'unknown') {
|
||||||
console.warn('Could not read package.json for version info');
|
return version;
|
||||||
return '0.0.0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback for development or if injection failed
|
||||||
|
console.warn('Could not read version from TM_PUBLIC_VERSION, using fallback');
|
||||||
|
return '0.0.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5079,25 +5079,7 @@ function setupCLI() {
|
|||||||
const programInstance = new Command()
|
const programInstance = new Command()
|
||||||
.name('dev')
|
.name('dev')
|
||||||
.description('AI-driven development task management')
|
.description('AI-driven development task management')
|
||||||
.version(() => {
|
.version(process.env.TM_PUBLIC_VERSION || 'unknown')
|
||||||
// Read version directly from package.json ONLY
|
|
||||||
try {
|
|
||||||
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
||||||
if (fs.existsSync(packageJsonPath)) {
|
|
||||||
const packageJson = JSON.parse(
|
|
||||||
fs.readFileSync(packageJsonPath, 'utf8')
|
|
||||||
);
|
|
||||||
return packageJson.version;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Silently fall back to 'unknown'
|
|
||||||
log(
|
|
||||||
'warn',
|
|
||||||
'Could not read package.json for version info in .version()'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return 'unknown'; // Default fallback if package.json fails
|
|
||||||
})
|
|
||||||
.helpOption('-h, --help', 'Display help')
|
.helpOption('-h, --help', 'Display help')
|
||||||
.addHelpCommand(false); // Disable default help command
|
.addHelpCommand(false); // Disable default help command
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,16 @@ dotenvLoad();
|
|||||||
// Get all TM_PUBLIC_* env variables for build-time injection
|
// Get all TM_PUBLIC_* env variables for build-time injection
|
||||||
const getBuildTimeEnvs = () => {
|
const getBuildTimeEnvs = () => {
|
||||||
const envs: Record<string, string> = {};
|
const envs: Record<string, string> = {};
|
||||||
|
|
||||||
|
// Inject package.json version at build time
|
||||||
|
try {
|
||||||
|
const packageJson = JSON.parse(require('fs').readFileSync('package.json', 'utf8'));
|
||||||
|
envs['TM_PUBLIC_VERSION'] = packageJson.version || 'unknown';
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Could not read package.json version during build:', error);
|
||||||
|
envs['TM_PUBLIC_VERSION'] = 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(process.env)) {
|
for (const [key, value] of Object.entries(process.env)) {
|
||||||
if (key.startsWith('TM_PUBLIC_')) {
|
if (key.startsWith('TM_PUBLIC_')) {
|
||||||
// Return the actual value, not JSON.stringify'd
|
// Return the actual value, not JSON.stringify'd
|
||||||
|
|||||||
Reference in New Issue
Block a user