Skip to content

Commit

Permalink
fix: avoid generating extra rebased paths in relative `rebaseLocalToR…
Browse files Browse the repository at this point in the history
…emote`

Refs #2091
  • Loading branch information
connor4312 committed Oct 3, 2024
1 parent 0000bd9 commit d398452
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/targets/sourcePathResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export abstract class SourcePathResolverBase<T extends ISourcePathResolverOption
*/
public rebaseRemoteToLocal(remotePath: string) {
if (!this.options.remoteRoot || !this.options.localRoot || !this.canMapPath(remotePath)) {
return path.resolve(remotePath);
// path.resolve in a relative path will put the path in VS Code's source folder which is never right
return path.isAbsolute(remotePath) ? path.resolve(remotePath) : remotePath;
}

const relativePath = properRelative(this.options.remoteRoot, remotePath);
Expand Down
40 changes: 31 additions & 9 deletions src/test/node/node-source-path-resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('node source path resolver', () => {
fsUtils,
undefined,
defaultOptions,
await Logger.test(),
Logger.null,
);
expect(await r.urlToAbsolutePath({ url: 'file:///src/index.js' })).to.equal(
resolve('/src/index.js'),
Expand All @@ -51,7 +51,7 @@ describe('node source path resolver', () => {
'C:\\some\\workspa*ce\\folder/../foo/**',
],
},
await Logger.test(),
Logger.null,
);
expect((r as unknown as Record<string, string[]>).resolvePatterns).to.deep.equal([
'C:/some/workspa\\*ce/folder/**',
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('node source path resolver', () => {
'!**/node_modules/**',
],
},
await Logger.test(),
Logger.null,
);
expect(
r.shouldResolveSourceMap({
Expand All @@ -90,6 +90,28 @@ describe('node source path resolver', () => {
}
});

it('avoids bad matches in relative rebasd #2091', async () => {
const r = new NodeSourcePathResolver(
fsUtils,
undefined,
{
...defaultOptions,
workspaceFolder: 'C:\\some\\workspa*ce\\folder',
basePath: 'C:\\some\\workspa*ce\\folder',
resolveSourceMapLocations: [
'**/*o*/**',
],
},
Logger.null,
);
expect(
r.shouldResolveSourceMap({
compiledPath: 'external:///app.js',
sourceMapUrl: 'external:///app.js.map',
}),
).to.be.false;
});

it('resolves unc paths', async () => {
if (process.platform !== 'win32') {
return;
Expand All @@ -99,7 +121,7 @@ describe('node source path resolver', () => {
fsUtils,
undefined,
defaultOptions,
await Logger.test(),
Logger.null,
);
expect(
await r.urlToAbsolutePath({
Expand All @@ -117,7 +139,7 @@ describe('node source path resolver', () => {
remoteRoot: 'C:\\Source',
localRoot: '/dev/src',
},
await Logger.test(),
Logger.null,
);

expect(await r.urlToAbsolutePath({ url: 'file:///c:/source/foo/bar.js' })).to.equal(
Expand All @@ -134,7 +156,7 @@ describe('node source path resolver', () => {
remoteRoot: '/dev/src',
localRoot: 'C:\\Source',
},
await Logger.test(),
Logger.null,
);

expect(await r.urlToAbsolutePath({ url: 'file:///dev/src/foo/bar.js' })).to.equal(
Expand All @@ -147,7 +169,7 @@ describe('node source path resolver', () => {
fsUtils,
undefined,
defaultOptions,
await Logger.test(),
Logger.null,
);

expect(
Expand All @@ -162,7 +184,7 @@ describe('node source path resolver', () => {
fsUtils,
undefined,
defaultOptions,
await Logger.test(),
Logger.null,
);

expect(
Expand Down Expand Up @@ -242,7 +264,7 @@ describe('node source path resolver', () => {
...defaultOptions,
resolveSourceMapLocations: locs,
},
await Logger.test(),
Logger.null,
);

const result = await resolver.urlToAbsolutePath({
Expand Down

0 comments on commit d398452

Please sign in to comment.