mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 20:43:36 +00:00
refactor: Address PR review feedback for symlink and directory handling
- Use lstatSync with try/catch for robust broken symlink detection - Remove redundant existsSync check before mkdirSync with recursive: true Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -119,11 +119,19 @@ const nodeModulesAutomaker = join(BUNDLE_DIR, 'node_modules', '@automaker');
|
||||
for (const pkgName of LOCAL_PACKAGES) {
|
||||
const pkgDir = pkgName.replace('@automaker/', '');
|
||||
const nmPkgPath = join(nodeModulesAutomaker, pkgDir);
|
||||
if (existsSync(nmPkgPath) && lstatSync(nmPkgPath).isSymbolicLink()) {
|
||||
const realPath = resolve(BUNDLE_DIR, 'libs', pkgDir);
|
||||
rmSync(nmPkgPath);
|
||||
cpSync(realPath, nmPkgPath, { recursive: true });
|
||||
console.log(` ✓ Replaced symlink: ${pkgName}`);
|
||||
try {
|
||||
// lstatSync does not follow symlinks, allowing us to check for broken ones
|
||||
if (lstatSync(nmPkgPath).isSymbolicLink()) {
|
||||
const realPath = resolve(BUNDLE_DIR, 'libs', pkgDir);
|
||||
rmSync(nmPkgPath);
|
||||
cpSync(realPath, nmPkgPath, { recursive: true });
|
||||
console.log(` ✓ Replaced symlink: ${pkgName}`);
|
||||
}
|
||||
} catch (error) {
|
||||
// If the path doesn't exist, lstatSync throws ENOENT. We can safely ignore this.
|
||||
if (error.code !== 'ENOENT') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -752,9 +752,7 @@ export function electronUserDataWriteFileSync(
|
||||
const fullPath = path.join(electronUserDataPath, relativePath);
|
||||
// Ensure parent directory exists (may not exist on first launch)
|
||||
const dir = path.dirname(fullPath);
|
||||
if (!fsSync.existsSync(dir)) {
|
||||
fsSync.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
fsSync.mkdirSync(dir, { recursive: true });
|
||||
fsSync.writeFileSync(fullPath, data, options);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user