Fix: Correct version resolution for banner and update check (#511)

* Fix: Correct version resolution for banner and update check

Resolves issues where the tool's version was displayed as 'unknown'.

- Modified 'displayBanner' in 'ui.js' and 'checkForUpdate' in 'commands.js' to read package.json relative to their own script locations using import.meta.url.
- This ensures the correct local version is identified for both the main banner display and the update notification mechanism.
- Restored a missing closing brace in 'ui.js' to fix a SyntaxError.

* fix: refactor and cleanup

* fix: chores and cleanup and testing

* chore: cleanup

* fix: add changeset

---------

Co-authored-by: Christer Soederlund <christer.soderlund@gmail.com>
This commit is contained in:
Ralph Khreish
2025-05-15 22:41:16 +02:00
committed by GitHub
parent a96215a359
commit 17294ff259
7 changed files with 52 additions and 56 deletions

View File

@@ -0,0 +1,5 @@
---
'task-master-ai': patch
---
Task Master no longer tells you to update when you're already up to date

View File

@@ -1,8 +1,8 @@
{ {
"mode": "pre", "mode": "exit",
"tag": "rc", "tag": "rc",
"initialVersions": { "initialVersions": {
"task-master-ai": "0.13.1" "task-master-ai": "0.13.2"
}, },
"changesets": [ "changesets": [
"beige-doodles-type", "beige-doodles-type",

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "task-master-ai", "name": "task-master-ai",
"version": "0.13.2-rc.1", "version": "0.12",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "task-master-ai", "name": "task-master-ai",
"version": "0.13.2-rc.1", "version": "0.12",
"license": "MIT WITH Commons-Clause", "license": "MIT WITH Commons-Clause",
"dependencies": { "dependencies": {
"@ai-sdk/anthropic": "^1.2.10", "@ai-sdk/anthropic": "^1.2.10",

View File

@@ -1,6 +1,6 @@
{ {
"name": "task-master-ai", "name": "task-master-ai",
"version": "0.13.2-rc.1", "version": "0.13.2",
"description": "A task management system for ambitious AI-driven development that doesn't overwhelm and confuse Cursor.", "description": "A task management system for ambitious AI-driven development that doesn't overwhelm and confuse Cursor.",
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",

View File

@@ -73,7 +73,7 @@ import {
getApiKeyStatusReport getApiKeyStatusReport
} from './task-manager/models.js'; } from './task-manager/models.js';
import { findProjectRoot } from './utils.js'; import { findProjectRoot } from './utils.js';
import { getTaskMasterVersion } from '../../src/utils/getVersion.js';
/** /**
* Runs the interactive setup process for model configuration. * Runs the interactive setup process for model configuration.
* @param {string|null} projectRoot - The resolved project root directory. * @param {string|null} projectRoot - The resolved project root directory.
@@ -1273,10 +1273,6 @@ function registerCommands(programInstance) {
'--details <details>', '--details <details>',
'Implementation details (for manual task creation)' 'Implementation details (for manual task creation)'
) )
.option(
'--test-strategy <testStrategy>',
'Test strategy (for manual task creation)'
)
.option( .option(
'--dependencies <dependencies>', '--dependencies <dependencies>',
'Comma-separated list of task IDs this task depends on' 'Comma-separated list of task IDs this task depends on'
@@ -1658,6 +1654,7 @@ function registerCommands(programInstance) {
} }
} catch (error) { } catch (error) {
console.error(chalk.red(`Error: ${error.message}`)); console.error(chalk.red(`Error: ${error.message}`));
showAddSubtaskHelp();
process.exit(1); process.exit(1);
} }
}) })
@@ -2381,28 +2378,7 @@ function setupCLI() {
*/ */
async function checkForUpdate() { async function checkForUpdate() {
// Get current version from package.json ONLY // Get current version from package.json ONLY
let currentVersion = 'unknown'; // Initialize with a default const currentVersion = getTaskMasterVersion();
try {
// Try to get the version from the installed package (if applicable) or current dir
let packageJsonPath = path.join(
process.cwd(),
'node_modules',
'task-master-ai',
'package.json'
);
// Fallback to current directory package.json if not found in node_modules
if (!fs.existsSync(packageJsonPath)) {
packageJsonPath = path.join(process.cwd(), 'package.json');
}
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
currentVersion = packageJson.version;
}
} catch (error) {
// Silently fail and use default
log('debug', `Error reading current package version: ${error.message}`);
}
return new Promise((resolve) => { return new Promise((resolve) => {
// Get the latest version from npm registry // Get the latest version from npm registry

View File

@@ -16,10 +16,10 @@ import {
truncate, truncate,
isSilentMode isSilentMode
} from './utils.js'; } from './utils.js';
import path from 'path';
import fs from 'fs'; import fs from 'fs';
import { findNextTask, analyzeTaskComplexity } from './task-manager.js'; import { findNextTask, analyzeTaskComplexity } from './task-manager.js';
import { getProjectName, getDefaultSubtasks } from './config-manager.js'; import { getProjectName, getDefaultSubtasks } from './config-manager.js';
import { getTaskMasterVersion } from '../../src/utils/getVersion.js';
// Create a color gradient for the banner // Create a color gradient for the banner
const coolGradient = gradient(['#00b4d8', '#0077b6', '#03045e']); const coolGradient = gradient(['#00b4d8', '#0077b6', '#03045e']);
@@ -46,17 +46,7 @@ function displayBanner() {
); );
// Read version directly from package.json // Read version directly from package.json
let version = 'unknown'; // Initialize with a default const version = getTaskMasterVersion();
try {
const packageJsonPath = path.join(process.cwd(), 'package.json');
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
version = packageJson.version;
}
} catch (error) {
// Silently fall back to default version
log('warn', 'Could not read package.json for version info.');
}
console.log( console.log(
boxen( boxen(
@@ -809,12 +799,7 @@ async function displayNextTask(tasksPath) {
'padding-bottom': 0, 'padding-bottom': 0,
compact: true compact: true
}, },
chars: { chars: { mid: '', 'left-mid': '', 'mid-mid': '', 'right-mid': '' },
mid: '',
'left-mid': '',
'mid-mid': '',
'right-mid': ''
},
colWidths: [15, Math.min(75, process.stdout.columns - 20 || 60)], colWidths: [15, Math.min(75, process.stdout.columns - 20 || 60)],
wordWrap: true wordWrap: true
}); });
@@ -902,12 +887,7 @@ async function displayNextTask(tasksPath) {
'padding-bottom': 0, 'padding-bottom': 0,
compact: true compact: true
}, },
chars: { chars: { mid: '', 'left-mid': '', 'mid-mid': '', 'right-mid': '' },
mid: '',
'left-mid': '',
'mid-mid': '',
'right-mid': ''
},
wordWrap: true wordWrap: true
}); });

35
src/utils/getVersion.js Normal file
View File

@@ -0,0 +1,35 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { log } from '../../scripts/modules/utils.js';
/**
* Reads the version from the nearest package.json relative to this file.
* Returns 'unknown' if not found or on error.
* @returns {string} The version string or 'unknown'.
*/
export function getTaskMasterVersion() {
let version = 'unknown';
try {
// Get the directory of the current module (getPackageVersion.js)
const currentModuleFilename = fileURLToPath(import.meta.url);
const currentModuleDirname = path.dirname(currentModuleFilename);
// Construct the path to package.json relative to this file (../../package.json)
const packageJsonPath = path.join(
currentModuleDirname,
'..',
'..',
'package.json'
);
if (fs.existsSync(packageJsonPath)) {
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
const packageJson = JSON.parse(packageJsonContent);
version = packageJson.version;
}
} catch (error) {
// Silently fall back to default version
log('warn', 'Could not read own package.json for version info.', error);
}
return version;
}