fix: resolve symlinks when checking entrypoint in isMain#666
Conversation
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension. |
There was a problem hiding this comment.
Code Review
This pull request updates the isMain utility function in both the Angular and Next.js adapters to resolve process.argv[1] to its real path using fsExtra.realpathSync inside a try-catch block. The reviewer suggested also resolving the second path (fileURLToPath(meta.url)) to its real path to ensure robust comparison when modules are loaded via symlinks, which is common in monorepos.
| if (!process.argv[1]) return false; | ||
| return process.argv[1] === fileURLToPath(meta.url); | ||
| try { | ||
| return fsExtra.realpathSync(process.argv[1]) === fileURLToPath(meta.url); |
There was a problem hiding this comment.
To ensure maximum robustness, both paths should be resolved to their real paths. If the module itself is loaded via a symlink (which is common in monorepos or when running with --preserve-symlinks), fileURLToPath(meta.url) might return the symlinked path rather than the real path, causing the comparison to fail. Resolving both sides with fsExtra.realpathSync guarantees a correct comparison of the actual physical files on disk.
| return fsExtra.realpathSync(process.argv[1]) === fileURLToPath(meta.url); | |
| return fsExtra.realpathSync(process.argv[1]) === fsExtra.realpathSync(fileURLToPath(meta.url)); |
| if (!process.argv[1]) return false; | ||
| return process.argv[1] === fileURLToPath(meta.url); | ||
| try { | ||
| return fsExtra.realpathSync(process.argv[1]) === fileURLToPath(meta.url); |
There was a problem hiding this comment.
To ensure maximum robustness, both paths should be resolved to their real paths. If the module itself is loaded via a symlink (which is common in monorepos or when running with --preserve-symlinks), fileURLToPath(meta.url) might return the symlinked path rather than the real path, causing the comparison to fail. Resolving both sides with fsExtra.realpathSync guarantees a correct comparison of the actual physical files on disk.
| return fsExtra.realpathSync(process.argv[1]) === fileURLToPath(meta.url); | |
| return fsExtra.realpathSync(process.argv[1]) === fsExtra.realpathSync(fileURLToPath(meta.url)); |
Fixes a bug where symlinked binaries in
node_modules/.binevaluate to false in isMain checks (becauseprocess.argv[1]is a symlink path), preventing the build script from executing.