Skip to content

Commit

Permalink
fix: resolve the project "realpath" on Windows to avoid drive letter …
Browse files Browse the repository at this point in the history
…mismatch in sourcemap (#227)
  • Loading branch information
byCedric authored Sep 4, 2023
1 parent 147fce5 commit f20d7b7
Showing 1 changed file with 39 additions and 0 deletions.
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);
}
});
});
}

0 comments on commit f20d7b7

Please sign in to comment.