Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/@apphosting/adapter-angular/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ export async function validateOutputDirectory(
export const isMain = (meta: ImportMeta) => {
if (!meta) return false;
if (!process.argv[1]) return false;
return process.argv[1] === fileURLToPath(meta.url);
try {
return fsExtra.realpathSync(process.argv[1]) === fileURLToPath(meta.url);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
return fsExtra.realpathSync(process.argv[1]) === fileURLToPath(meta.url);
return fsExtra.realpathSync(process.argv[1]) === fsExtra.realpathSync(fileURLToPath(meta.url));

} catch {
return false;
}
};

export const metaFrameworkOutputBundleExists = () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/@apphosting/adapter-nextjs/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export async function writeRouteManifest(
export const isMain = (meta: ImportMeta): boolean => {
if (!meta) return false;
if (!process.argv[1]) return false;
return process.argv[1] === fileURLToPath(meta.url);
try {
return fsExtra.realpathSync(process.argv[1]) === fileURLToPath(meta.url);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
return fsExtra.realpathSync(process.argv[1]) === fileURLToPath(meta.url);
return fsExtra.realpathSync(process.argv[1]) === fsExtra.realpathSync(fileURLToPath(meta.url));

} catch {
return false;
}
};

/**
Expand Down
Loading