Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/providers/base/Provider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

/**
* Abstract Provider Base Class.
Expand Down Expand Up @@ -41,7 +43,8 @@ export class Provider {
*/
async _loadProviderPricing(providerName) {
try {
const pricingPath = new URL(`../../../config/${providerName}-pricing.json`, import.meta.url).pathname;
const currentDir = path.dirname(fileURLToPath(import.meta.url));
const pricingPath = path.resolve(currentDir, '..', '..', '..', 'config', `${providerName}-pricing.json`);
const pricingContent = fs.readFileSync(pricingPath, 'utf-8');

this.providerPricing = JSON.parse(pricingContent);
Expand Down
3 changes: 2 additions & 1 deletion src/utils/promptLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { encoding_for_model as encodingForModel } from 'tiktoken';
import { getApiTargetLanguage } from './languageMapping.js';
import { getPluralForms, extractPluralCount } from './poFileUtils.js';
Expand Down Expand Up @@ -49,7 +50,7 @@ function loadPromptTemplate(promptFilePath) {
*/
export function buildSystemPrompt(targetLang, sourceLang = 'English', promptFilePath = null) {
if (!promptFilePath) {
const currentDir = path.dirname(new URL(import.meta.url).pathname);
const currentDir = path.dirname(fileURLToPath(import.meta.url));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

LGTM: Improved file path resolution for cross-platform compatibility.

The change from new URL(import.meta.url).pathname to fileURLToPath(import.meta.url) is correct and addresses the file path resolution issues mentioned in the PR objectives. This is particularly important for Windows environments where URL pathname handling can be problematic.

However, ensure consistency across the codebase with similar patterns.


🏁 Script executed:

#!/bin/bash
# Description: Check for remaining usage of the old URL pattern that should be updated for consistency
# Expected: Find any remaining instances that might need similar updates

echo "Searching for remaining instances of 'new URL(import.meta.url).pathname' pattern:"
rg -n "new URL\(import\.meta\.url\)\.pathname" --type js

echo -e "\nSearching for any URL-based path resolution patterns:"
rg -n "import\.meta\.url.*pathname" --type js

Length of output: 604


Update remaining file path resolution for cross-platform consistency

The change to fileURLToPath(import.meta.url) correctly addresses Windows pathname issues and should be applied uniformly.

• In src/utils/costTracker.js (line 59), replace the old URL-based pattern:

- const currentDir = path.dirname(new URL(import.meta.url).pathname);
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/utils/costTracker.js at line 59, update the file path resolution to use
path.dirname(fileURLToPath(import.meta.url)) instead of the old URL-based
pattern to ensure cross-platform consistency, especially on Windows. Replace the
existing code with this new pattern to standardize path handling.


promptFilePath = path.resolve(currentDir, '../../config/prompt.md');
}
Expand Down