Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve project "realpath" on windows to avoid drive mismatch when debugging #227

Merged
merged 1 commit into from
Sep 4, 2023
Merged
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
39 changes: 39 additions & 0 deletions src/expoDebuggers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs';
import vscode from 'vscode';

import {
Expand Down Expand Up @@ -166,6 +167,16 @@ export class ExpoDebuggersProvider implements vscode.DebugConfigurationProvider
config.bundlerHost = config.bundlerHost ?? '127.0.0.1';
config.bundlerPort = config.bundlerPort ?? undefined;

// Workaround for Window's drive letter case mismatch with source maps
if (process.platform === 'win32') {
const projectRoot = await resolveWindowsProjectRoot(config.projectRoot);

// Replace the project root for all source maps related paths.
config.cwd = projectRoot;
config.projectRoot = projectRoot;
config.rootPath = projectRoot;
}

// Resolve the target device config to inspect
const { platform, workflow, ...deviceConfig } = await resolveDeviceConfig(config, project);

Expand Down Expand Up @@ -237,3 +248,31 @@ async function pickDevice(config: ExpoDebugConfig) {

throw new Error('waiting for device to connect...');
}

/**
* Resolve the "real path" of the project root.
* This workaround is for Window's drive letter casing mismatch within the source maps.
* VS Code seems to prefer lower case drive letters, while Metro use upper case drive letters.
*/
async function resolveWindowsProjectRoot(projectRoot: string) {
if (process.platform !== 'win32') {
return projectRoot;
}

return await new Promise<string>((resolve) => {
fs.realpath.native(projectRoot, (error, realProjectRoot) => {
if (error) {
console.warn(
`Failed to resolve the real path of the project root, this may break the breakpoints functionality.`
);
console.warn(`Reason: ${error.message} (${error.code})`);
console.warn(
`If you run into this issue often, please report it at: https://github.com/expo/vscode-expo/issues/new/choose`
);
resolve(projectRoot);
} else {
resolve(realProjectRoot);
}
});
});
}