Consolidate versions and AWS configuration in a single file#32
Consolidate versions and AWS configuration in a single file#32talha-sofyrus wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code Review
This pull request replaces hardcoded download URLs and version numbers in the installation documentation with dynamic placeholders loaded from a new download-config.json file. In lib/markdown.ts, logic was added to read this configuration, cache it, and replace placeholders in the MDX content. The feedback suggests caching the configuration promise instead of the resolved object to prevent concurrent file reads during simultaneous requests, and replacing the in operator check with a safer type check to avoid matching built-in prototype properties.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| let cachedConfig: Record<string, string> | null = null; | ||
|
|
||
| async function loadDownloadConfig(): Promise<Record<string, string>> { | ||
| if (cachedConfig) return cachedConfig; | ||
| try { | ||
| const configPath = path.join(process.cwd(), "download-config.json"); | ||
| const content = await fs.readFile(configPath, "utf-8"); | ||
| cachedConfig = JSON.parse(content); | ||
| return cachedConfig || {}; | ||
| } catch (err) { | ||
| console.error("Failed to load download-config.json", err); | ||
| return {}; | ||
| } | ||
| } |
There was a problem hiding this comment.
When multiple documentation pages are requested concurrently, loadDownloadConfig can trigger multiple concurrent fs.readFile operations because cachedConfig is only assigned after the file read and JSON parsing complete. Caching the promise instead of the resolved configuration object avoids this race condition and ensures the file is read at most once.
let cachedConfigPromise: Promise<Record<string, string>> | null = null;
function loadDownloadConfig(): Promise<Record<string, string>> {
if (!cachedConfigPromise) {
cachedConfigPromise = (async () => {
try {
const configPath = path.join(process.cwd(), "download-config.json");
const content = await fs.readFile(configPath, "utf-8");
return JSON.parse(content) || {};
} catch (err) {
console.error("Failed to load download-config.json", err);
return {};
}
})();
}
return cachedConfigPromise;
}| function replacePlaceholders(content: string, config: Record<string, string>): string { | ||
| return content.replace(/\{\{([^}]+)\}\}/g, (match, key) => { | ||
| const trimmedKey = key.trim(); | ||
| return trimmedKey in config ? config[trimmedKey] : match; | ||
| }); | ||
| } |
There was a problem hiding this comment.
Using the in operator (trimmedKey in config) checks the entire prototype chain of the object. If a placeholder matches a built-in property name (such as toString, valueOf, or constructor), it will evaluate to true and attempt to replace the placeholder with a function or prototype property, leading to unexpected output or runtime errors. Checking typeof config[trimmedKey] === "string" is safer and ensures only explicitly defined string properties from the JSON configuration are replaced.
| function replacePlaceholders(content: string, config: Record<string, string>): string { | |
| return content.replace(/\{\{([^}]+)\}\}/g, (match, key) => { | |
| const trimmedKey = key.trim(); | |
| return trimmedKey in config ? config[trimmedKey] : match; | |
| }); | |
| } | |
| function replacePlaceholders(content: string, config: Record<string, string>): string { | |
| return content.replace(/\{\{([^}]+)\}\}/g, (match, key) => { | |
| const trimmedKey = key.trim(); | |
| return typeof config[trimmedKey] === "string" ? config[trimmedKey] : match; | |
| }); | |
| } |
No description provided.