Skip to content

Commit

Permalink
fix: don't incorrectly scope sourcemap resolution to node_modules
Browse files Browse the repository at this point in the history
Fixes #1100
  • Loading branch information
connor4312 committed Sep 8, 2021
1 parent 427978f commit ad56015
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/test/extension/nodeConfigurationProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,26 @@ describe('NodeDebugConfigurationProvider', () => {
]);
});

it('does not resolve in node_modules', async () => {
createFileTree(testFixturesDir, {
'a/node_modules/c/hello.js': '',
'a/node_modules/c/package.json': '{}',
'a/package.json': '{}',
});

const result = await provider.resolveDebugConfiguration(folder, {
type: DebugType.Node,
name: '',
request: 'launch',
program: 'a/node_modules/c/hello.js',
});

expect(result?.outFiles).to.deep.equal([
'${workspaceFolder}/a/**/*.js',
'!**/node_modules/**',
]);
});

it('does not resolve outside the workspace folder', async () => {
createFileTree(testFixturesDir, {
'a/b/c/hello.js': '',
Expand Down
8 changes: 4 additions & 4 deletions src/ui/configuration/nodeDebugConfigurationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { EnvironmentVars } from '../../common/environmentVars';
import { findOpenPort } from '../../common/findOpenPort';
import { IFsUtils, LocalFsUtils } from '../../common/fsUtils';
import { forceForwardSlashes, isSubdirectoryOf } from '../../common/pathUtils';
import { nearestDirectoryContaining } from '../../common/urlUtils';
import { nearestDirectoryWhere } from '../../common/urlUtils';
import {
AnyNodeConfiguration,
applyNodeDefaults,
Expand Down Expand Up @@ -219,11 +219,11 @@ async function guessOutFiles(
return;
}

const root = await nearestDirectoryContaining(
fsUtils,
const root = await nearestDirectoryWhere(
path.dirname(programLocation),
'package.json',
async p => !p.includes('node_modules') && (await fsUtils.exists(path.join(p, 'package.json'))),
);

if (root && isSubdirectoryOf(folder.uri.fsPath, root)) {
const rel = forceForwardSlashes(path.relative(folder.uri.fsPath, root));
config.outFiles = resolveVariableInConfig(
Expand Down

0 comments on commit ad56015

Please sign in to comment.