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

feat: add pathMapping to node.js #1015

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
merge some pathMapping options
connor4312 committed Jun 10, 2021

Verified

This commit was signed with the committer’s verified signature.
connor4312 Connor Peet
commit b141468e84d418e56564a22a52603660f79ea71f
12 changes: 8 additions & 4 deletions OPTIONS.md
Original file line number Diff line number Diff line change
@@ -20,7 +20,8 @@
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
]</pre></code><h4>outputCapture</h4><p>From where to capture output messages: the default debug API if set to <code>console</code>, or stdout/stderr streams if set to <code>std</code>.</p>
<h5>Default value:</h4><pre><code>"console"</pre></code><h4>pauseForSourceMap</h4><p>Whether to wait for source maps to load for each incoming script. This has a performance overhead, and might be safely disabled when running off of disk, so long as <code>rootPath</code> is not disabled.</p>
<h5>Default value:</h4><pre><code>"console"</pre></code><h4>pathMapping</h4><p>A mapping of folders from one path to another. To resolve scripts to their original locations. Typical use is to map scripts in <code>node_modules</code> to their sources that locate in another folder.</p>
<h5>Default value:</h4><pre><code>{}</pre></code><h4>pauseForSourceMap</h4><p>Whether to wait for source maps to load for each incoming script. This has a performance overhead, and might be safely disabled when running off of disk, so long as <code>rootPath</code> is not disabled.</p>
<h5>Default value:</h4><pre><code>false</pre></code><h4>port</h4><p>Debug port to attach to. Default is 9229.</p>
<h5>Default value:</h4><pre><code>9229</pre></code><h4>processId</h4><p>ID of process to attach to.</p>
<h5>Default value:</h4><pre><code>undefined</pre></code><h4>remoteRoot</h4><p>Absolute path to the remote directory containing the program.</p>
@@ -68,7 +69,8 @@
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
]</pre></code><h4>outputCapture</h4><p>From where to capture output messages: the default debug API if set to <code>console</code>, or stdout/stderr streams if set to <code>std</code>.</p>
<h5>Default value:</h4><pre><code>"console"</pre></code><h4>pauseForSourceMap</h4><p>Whether to wait for source maps to load for each incoming script. This has a performance overhead, and might be safely disabled when running off of disk, so long as <code>rootPath</code> is not disabled.</p>
<h5>Default value:</h4><pre><code>"console"</pre></code><h4>pathMapping</h4><p>A mapping of folders from one path to another. To resolve scripts to their original locations. Typical use is to map scripts in <code>node_modules</code> to their sources that locate in another folder.</p>
<h5>Default value:</h4><pre><code>{}</pre></code><h4>pauseForSourceMap</h4><p>Whether to wait for source maps to load for each incoming script. This has a performance overhead, and might be safely disabled when running off of disk, so long as <code>rootPath</code> is not disabled.</p>
<h5>Default value:</h4><pre><code>false</pre></code><h4>profileStartup</h4><p>If true, will start profiling as soon as the process launches</p>
<h5>Default value:</h4><pre><code>false</pre></code><h4>program</h4><p>Absolute path to the program. Generated value is guessed by looking at package.json and opened files. Edit this attribute.</p>
<h5>Default value:</h4><pre><code>""</pre></code><h4>remoteRoot</h4><p>Absolute path to the remote directory containing the program.</p>
@@ -116,7 +118,8 @@
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
]</pre></code><h4>outputCapture</h4><p>From where to capture output messages: the default debug API if set to <code>console</code>, or stdout/stderr streams if set to <code>std</code>.</p>
<h5>Default value:</h4><pre><code>"console"</pre></code><h4>pauseForSourceMap</h4><p>Whether to wait for source maps to load for each incoming script. This has a performance overhead, and might be safely disabled when running off of disk, so long as <code>rootPath</code> is not disabled.</p>
<h5>Default value:</h4><pre><code>"console"</pre></code><h4>pathMapping</h4><p>A mapping of folders from one path to another. To resolve scripts to their original locations. Typical use is to map scripts in <code>node_modules</code> to their sources that locate in another folder.</p>
<h5>Default value:</h4><pre><code>{}</pre></code><h4>pauseForSourceMap</h4><p>Whether to wait for source maps to load for each incoming script. This has a performance overhead, and might be safely disabled when running off of disk, so long as <code>rootPath</code> is not disabled.</p>
<h5>Default value:</h4><pre><code>false</pre></code><h4>remoteRoot</h4><p>Absolute path to the remote directory containing the program.</p>
<h5>Default value:</h4><pre><code>null</pre></code><h4>resolveSourceMapLocations</h4><p>A list of minimatch patterns for locations (folders and URLs) in which source maps can be used to resolve local files. This can be used to avoid incorrectly breaking in external source mapped code. Patterns can be prefixed with &quot;!&quot; to exclude them. May be set to an empty array or null to avoid restriction.</p>
<h5>Default value:</h4><pre><code>[
@@ -162,7 +165,8 @@
<h5>Default value:</h4><pre><code>[
"${workspaceFolder}/out/**/*.js"
]</pre></code><h4>outputCapture</h4><p>From where to capture output messages: the default debug API if set to <code>console</code>, or stdout/stderr streams if set to <code>std</code>.</p>
<h5>Default value:</h4><pre><code>"console"</pre></code><h4>pauseForSourceMap</h4><p>Whether to wait for source maps to load for each incoming script. This has a performance overhead, and might be safely disabled when running off of disk, so long as <code>rootPath</code> is not disabled.</p>
<h5>Default value:</h4><pre><code>"console"</pre></code><h4>pathMapping</h4><p>A mapping of folders from one path to another. To resolve scripts to their original locations. Typical use is to map scripts in <code>node_modules</code> to their sources that locate in another folder.</p>
<h5>Default value:</h4><pre><code>{}</pre></code><h4>pauseForSourceMap</h4><p>Whether to wait for source maps to load for each incoming script. This has a performance overhead, and might be safely disabled when running off of disk, so long as <code>rootPath</code> is not disabled.</p>
<h5>Default value:</h4><pre><code>false</pre></code><h4>remoteRoot</h4><p>Absolute path to the remote directory containing the program.</p>
<h5>Default value:</h4><pre><code>null</pre></code><h4>rendererDebugOptions</h4><p>Chrome launch options used when attaching to the renderer process, with <code>debugWebviews</code> or <code>debugWebWorkerHost</code>.</p>
<h5>Default value:</h4><pre><code>{}</pre></code><h4>resolveSourceMapLocations</h4><p>A list of minimatch patterns for locations (folders and URLs) in which source maps can be used to resolve local files. This can be used to avoid incorrectly breaking in external source mapped code. Patterns can be prefixed with &quot;!&quot; to exclude them. May be set to an empty array or null to avoid restriction.</p>
15 changes: 8 additions & 7 deletions src/build/generate-contributions.ts
Original file line number Diff line number Diff line change
@@ -298,6 +298,12 @@ const baseConfigurationAttributes: ConfigurationAttributes<IBaseConfiguration> =
default: [],
description: refString('base.cascadeTerminateToConfigurations.label'),
},
pathMapping: {
type: 'object',
additionalProperties: { type: 'string' },
description: refString('browser.pathMapping.description'),
default: {},
},
};

/**
@@ -358,12 +364,8 @@ const nodeBaseConfigurationAttributes: ConfigurationAttributes<INodeBaseConfigur
default: 12,
},
pathMapping: {
type: 'object',
items: {
type: 'string',
},
...baseConfigurationAttributes.pathMapping,
markdownDescription: refString('node.pathMapping.description'),
default: {},
},
};

@@ -687,9 +689,8 @@ const chromiumBaseConfigurationAttributes: ConfigurationAttributes<IChromiumBase
default: true,
},
pathMapping: {
type: 'object',
...baseConfigurationAttributes.pathMapping,
description: refString('browser.pathMapping.description'),
default: {},
},
webRoot: {
type: 'string',
29 changes: 13 additions & 16 deletions src/configuration.ts
Original file line number Diff line number Diff line change
@@ -207,6 +207,14 @@ export interface IBaseConfiguration extends IMandatedConfiguration {
* e.g.: "function () { return {...this, extraProperty: 'otherProperty' } }"
*/
customPropertiesGenerator?: string;

/**
* A mapping of folder paths. In the context of Chrome, these are "path"
* portions of the URL to absolute paths on disk. In the context of
* Node.js, they are mappings from absolute paths to other absolute paths,
* which is useful when debugging hard linked files.
*/
pathMapping: PathMapping;
}

export interface IExtensionHostBaseConfiguration extends INodeBaseConfiguration {
@@ -322,13 +330,6 @@ export interface INodeBaseConfiguration extends IBaseConfiguration, IConfigurati
* with `--inpect-brk`.
*/
continueOnAttach?: boolean;

/**
* A mapping of folders from one path to another. To resolve scripts to their
* original locations. Typical use is to map scripts in `node_modules` to their
* sources that locate in another folder.
*/
pathMapping: PathMapping;
}

export interface IConfigurationWithEnv {
@@ -450,12 +451,6 @@ export interface IChromiumBaseConfiguration extends IBaseConfiguration {
*/
disableNetworkCache: boolean;

/**
* A mapping of URLs/paths to local folders, to resolve scripts
* in Chrome to scripts on disk
*/
pathMapping: PathMapping;

/**
* This specifies the workspace absolute path to the webserver root. Used to
* resolve paths like `/app.js` to files on disk. Shorthand for a pathMapping for "/".
@@ -819,6 +814,7 @@ export const baseDefaults: IBaseConfiguration = {
sourceMapPathOverrides: defaultSourceMapPathOverrides('${workspaceFolder}'),
enableContentValidation: true,
cascadeTerminateToConfigurations: [],
pathMapping: {},
// Should always be determined upstream;
__workspaceFolder: '',
__autoExpandGetters: false,
@@ -840,7 +836,6 @@ const nodeBaseDefaults: INodeBaseConfiguration = {
resolveSourceMapLocations: ['**', '!**/node_modules/**'],
autoAttachChildProcesses: true,
runtimeSourcemapPausePatterns: [],
pathMapping: {},
};

export const terminalBaseDefaults: ITerminalLaunchConfiguration = {
@@ -892,7 +887,6 @@ export const nodeLaunchConfigDefaults: INodeLaunchConfiguration = {
profileStartup: false,
attachSimplePort: null,
killBehavior: KillBehavior.Forceful,
pathMapping: {},
};

export const chromeAttachConfigDefaults: IChromeAttachConfiguration = {
@@ -902,7 +896,6 @@ export const chromeAttachConfigDefaults: IChromeAttachConfiguration = {
address: 'localhost',
port: 0,
disableNetworkCache: true,
pathMapping: {},
url: null,
restart: false,
urlFilter: '',
@@ -1077,6 +1070,10 @@ export function removeOptionalWorkspaceFolderUsages<T extends AnyLaunchConfigura
cast.resolveSourceMapLocations?.filter(o => !o.includes(token)) ?? null;
}

if ('pathMapping' in cast) {
cast.pathMapping = filterValues(cast.pathMapping, v => v.includes(token));
}

if ('cwd' in cast && cast.cwd?.includes(token)) {
cast.cwd = undefined;
}
2 changes: 0 additions & 2 deletions src/targets/browser/browserPathResolver.ts
Original file line number Diff line number Diff line change
@@ -23,12 +23,10 @@ import {
import { IUrlResolution } from '../../common/sourcePathResolver';
import * as utils from '../../common/urlUtils';
import { urlToRegex } from '../../common/urlUtils';
import { PathMapping } from '../../configuration';
import { ISourcePathResolverOptions, SourcePathResolverBase } from '../sourcePathResolver';

export interface IOptions extends ISourcePathResolverOptions {
baseUrl?: string;
pathMapping: PathMapping;
clientID: string | undefined;
remoteFilePrefix: string | undefined;
}
3 changes: 1 addition & 2 deletions src/targets/node/nodeSourcePathResolver.ts
Original file line number Diff line number Diff line change
@@ -16,13 +16,12 @@ import {
} from '../../common/sourceMaps/sourceMapResolutionUtils';
import { IUrlResolution } from '../../common/sourcePathResolver';
import * as urlUtils from '../../common/urlUtils';
import { AnyLaunchConfiguration, AnyNodeConfiguration, PathMapping } from '../../configuration';
import { AnyLaunchConfiguration, AnyNodeConfiguration } from '../../configuration';
import { ILinkedBreakpointLocation } from '../../ui/linkedBreakpointLocation';
import { ISourcePathResolverOptions, SourcePathResolverBase } from '../sourcePathResolver';

interface IOptions extends ISourcePathResolverOptions {
basePath?: string;
pathMapping: PathMapping;
}

const localNodeInternalsPrefix = 'node:';
2 changes: 2 additions & 0 deletions src/targets/sourcePathResolver.ts
Original file line number Diff line number Diff line change
@@ -25,9 +25,11 @@ import {
urlToRegex,
} from '../common/urlUtils';
import { SourceMapOverrides } from './sourceMapOverrides';
import { PathMapping } from '../configuration';

export interface ISourcePathResolverOptions {
resolveSourceMapLocations: ReadonlyArray<string> | null;
pathMapping: PathMapping;
sourceMapOverrides: { [key: string]: string };
localRoot: string | null;
remoteRoot: string | null;