feat(cli): Add --version option and warn against global tstest usage in the tstest project
This commit is contained in:
		| @@ -1,5 +1,12 @@ | |||||||
| # Changelog | # Changelog | ||||||
|  |  | ||||||
|  | ## 2025-05-26 - 2.3.0 - feat(cli) | ||||||
|  | Add '--version' option and warn against global tstest usage in the tstest project | ||||||
|  |  | ||||||
|  | - Introduced a new '--version' CLI flag that prints the version from package.json | ||||||
|  | - Added logic in ts/index.ts to detect if tstest is run globally within its own project and issue a warning | ||||||
|  | - Added .claude/settings.local.json to configure allowed permissions for various commands | ||||||
|  |  | ||||||
| ## 2025-05-26 - 2.2.6 - fix(tstest) | ## 2025-05-26 - 2.2.6 - fix(tstest) | ||||||
| Improve timeout warning timer management and summary output formatting in the test runner. | Improve timeout warning timer management and summary output formatting in the test runner. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,6 +3,6 @@ | |||||||
|  */ |  */ | ||||||
| export const commitinfo = { | export const commitinfo = { | ||||||
|   name: '@git.zone/tstest', |   name: '@git.zone/tstest', | ||||||
|   version: '2.2.6', |   version: '2.3.0', | ||||||
|   description: 'a test utility to run tests that match test/**/*.ts' |   description: 'a test utility to run tests that match test/**/*.ts' | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										47
									
								
								ts/index.ts
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								ts/index.ts
									
									
									
									
									
								
							| @@ -8,6 +8,40 @@ export enum TestExecutionMode { | |||||||
| } | } | ||||||
|  |  | ||||||
| export const runCli = async () => { | export const runCli = async () => { | ||||||
|  |   // Check if we're using global tstest in the tstest project itself | ||||||
|  |   try { | ||||||
|  |     const packageJsonPath = `${process.cwd()}/package.json`; | ||||||
|  |     const fs = await import('fs'); | ||||||
|  |     if (fs.existsSync(packageJsonPath)) { | ||||||
|  |       const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); | ||||||
|  |       if (packageJson.name === '@git.zone/tstest') { | ||||||
|  |         // Check if we're running from a global installation | ||||||
|  |         const execPath = process.argv[1]; | ||||||
|  |         // Debug: log the paths (uncomment for debugging) | ||||||
|  |         // console.log('DEBUG: Checking global tstest usage...'); | ||||||
|  |         // console.log('execPath:', execPath); | ||||||
|  |         // console.log('cwd:', process.cwd()); | ||||||
|  |         // console.log('process.argv:', process.argv); | ||||||
|  |          | ||||||
|  |         // Check if this is running from global installation | ||||||
|  |         const isLocalCli = execPath.includes(process.cwd()); | ||||||
|  |         const isGlobalPnpm = process.argv.some(arg => arg.includes('.pnpm') && !arg.includes(process.cwd())); | ||||||
|  |         const isGlobalNpm = process.argv.some(arg => arg.includes('npm/node_modules') && !arg.includes(process.cwd())); | ||||||
|  |          | ||||||
|  |         if (!isLocalCli && (isGlobalPnpm || isGlobalNpm || !execPath.includes('node_modules'))) { | ||||||
|  |           console.error('\n⚠️  WARNING: You are using a globally installed tstest in the tstest project itself!'); | ||||||
|  |           console.error('   This means you are NOT testing your local changes.'); | ||||||
|  |           console.error('   Please use one of these commands instead:'); | ||||||
|  |           console.error('     • node cli.js <test-path>'); | ||||||
|  |           console.error('     • pnpm test <test-path>'); | ||||||
|  |           console.error('     • ./cli.js <test-path> (if executable)\n'); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } catch (error) { | ||||||
|  |     // Silently ignore any errors in this check | ||||||
|  |   } | ||||||
|  |    | ||||||
|   // Parse command line arguments |   // Parse command line arguments | ||||||
|   const args = process.argv.slice(2); |   const args = process.argv.slice(2); | ||||||
|   const logOptions: LogOptions = {}; |   const logOptions: LogOptions = {}; | ||||||
| @@ -24,6 +58,18 @@ export const runCli = async () => { | |||||||
|     const arg = args[i]; |     const arg = args[i]; | ||||||
|      |      | ||||||
|     switch (arg) { |     switch (arg) { | ||||||
|  |       case '--version': | ||||||
|  |         // Get version from package.json | ||||||
|  |         try { | ||||||
|  |           const fs = await import('fs'); | ||||||
|  |           const packagePath = new URL('../package.json', import.meta.url).pathname; | ||||||
|  |           const packageData = JSON.parse(await fs.promises.readFile(packagePath, 'utf8')); | ||||||
|  |           console.log(`tstest version ${packageData.version}`); | ||||||
|  |         } catch (error) { | ||||||
|  |           console.log('tstest version unknown'); | ||||||
|  |         } | ||||||
|  |         process.exit(0); | ||||||
|  |         break; | ||||||
|       case '--quiet': |       case '--quiet': | ||||||
|       case '-q': |       case '-q': | ||||||
|         logOptions.quiet = true; |         logOptions.quiet = true; | ||||||
| @@ -115,6 +161,7 @@ export const runCli = async () => { | |||||||
|     console.error('You must specify a test directory/file/pattern as argument. Please try again.'); |     console.error('You must specify a test directory/file/pattern as argument. Please try again.'); | ||||||
|     console.error('\nUsage: tstest <path> [options]'); |     console.error('\nUsage: tstest <path> [options]'); | ||||||
|     console.error('\nOptions:'); |     console.error('\nOptions:'); | ||||||
|  |     console.error('  --version         Show version information'); | ||||||
|     console.error('  --quiet, -q       Minimal output'); |     console.error('  --quiet, -q       Minimal output'); | ||||||
|     console.error('  --verbose, -v     Verbose output'); |     console.error('  --verbose, -v     Verbose output'); | ||||||
|     console.error('  --no-color        Disable colored output'); |     console.error('  --no-color        Disable colored output'); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user