Refactor: Use String.prototype.replaceAll() and update TS lib
- Replaces the custom `replaceAll` implementation in `packages/server/src/tools/edit.ts` with the standard `String.prototype.replaceAll()`. - Updates `packages/server/tsconfig.json` to include `ES2021` in the `lib` compiler options to ensure TypeScript recognizes this method. This aligns with the project's Node.js version requirements \(Node.js 16.x+\). Fixes https://github.com/google-gemini/gemini-cli/issues/7
This commit is contained in:
parent
e486d84d6a
commit
58e0224061
|
@ -205,8 +205,7 @@ Expectation for parameters:
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// Successful edit calculation
|
// Successful edit calculation
|
||||||
newContent = this.replaceAll(
|
newContent = currentContent.replaceAll(
|
||||||
currentContent,
|
|
||||||
params.old_string,
|
params.old_string,
|
||||||
params.new_string,
|
params.new_string,
|
||||||
);
|
);
|
||||||
|
@ -274,8 +273,7 @@ Expectation for parameters:
|
||||||
if (correctedOccurrences === 0 || correctedOccurrences !== 1) {
|
if (correctedOccurrences === 0 || correctedOccurrences !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
newContent = this.replaceAll(
|
newContent = currentContent.replaceAll(
|
||||||
currentContent,
|
|
||||||
params.old_string,
|
params.old_string,
|
||||||
params.new_string,
|
params.new_string,
|
||||||
);
|
);
|
||||||
|
@ -392,19 +390,6 @@ Expectation for parameters:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces all occurrences of a substring in a string
|
|
||||||
*/
|
|
||||||
private replaceAll(str: string, find: string, replace: string): string {
|
|
||||||
if (find === '') {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
// Use RegExp with global flag for true replacement of all instances
|
|
||||||
// Escape special regex characters in the find string
|
|
||||||
const escapedFind = find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
||||||
return str.replace(new RegExp(escapedFind, 'g'), replace);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates parent directories if they don't exist
|
* Creates parent directories if they don't exist
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"extends": "../../tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"lib": ["DOM", "DOM.Iterable", "ES2020"],
|
"lib": ["DOM", "DOM.Iterable", "ES2021"],
|
||||||
"composite": true
|
"composite": true
|
||||||
},
|
},
|
||||||
"include": ["index.ts", "src/**/*.ts", "src/**/*.json"],
|
"include": ["index.ts", "src/**/*.ts", "src/**/*.json"],
|
||||||
|
|
Loading…
Reference in New Issue