mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +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) {
|
for (const pkgName of LOCAL_PACKAGES) {
|
||||||
const pkgDir = pkgName.replace('@automaker/', '');
|
const pkgDir = pkgName.replace('@automaker/', '');
|
||||||
const nmPkgPath = join(nodeModulesAutomaker, pkgDir);
|
const nmPkgPath = join(nodeModulesAutomaker, pkgDir);
|
||||||
if (existsSync(nmPkgPath) && lstatSync(nmPkgPath).isSymbolicLink()) {
|
try {
|
||||||
const realPath = resolve(BUNDLE_DIR, 'libs', pkgDir);
|
// lstatSync does not follow symlinks, allowing us to check for broken ones
|
||||||
rmSync(nmPkgPath);
|
if (lstatSync(nmPkgPath).isSymbolicLink()) {
|
||||||
cpSync(realPath, nmPkgPath, { recursive: true });
|
const realPath = resolve(BUNDLE_DIR, 'libs', pkgDir);
|
||||||
console.log(` ✓ Replaced symlink: ${pkgName}`);
|
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);
|
const fullPath = path.join(electronUserDataPath, relativePath);
|
||||||
// Ensure parent directory exists (may not exist on first launch)
|
// Ensure parent directory exists (may not exist on first launch)
|
||||||
const dir = path.dirname(fullPath);
|
const dir = path.dirname(fullPath);
|
||||||
if (!fsSync.existsSync(dir)) {
|
fsSync.mkdirSync(dir, { recursive: true });
|
||||||
fsSync.mkdirSync(dir, { recursive: true });
|
|
||||||
}
|
|
||||||
fsSync.writeFileSync(fullPath, data, options);
|
fsSync.writeFileSync(fullPath, data, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user