Skip to content

Commit

Permalink
Merge pull request #216 from firefox-devtools/cra-workaround
Browse files Browse the repository at this point in the history
add enableCRAWorkaround configuration property
  • Loading branch information
hbenl authored Aug 21, 2020
2 parents 6d1628c + c9fb7d2 commit 27dc007
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ popup auto-hide" (`extension.firefox.enablePopupAutohide` / `disablePopupAutohid
breakpoint in an unmapped source during a debug session. You may want to turn this off if some
of the sources in your project are loaded on-demand (e.g. if you create multiple bundles with
webpack and some of these bundles are only loaded as needed).
* `enableCRAWorkaround`: Enable a workaround for facebook/create-react-app#6074: Adding/removing
breakpoints doesn't work for sources that were changed after the dev-server was started

### Overriding configuration properties in your settings
You can override some of the `launch.json` configuration properties in your user, workspace or
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,11 @@
"description": "Suggest using the Path Mapping Wizard when the user tries to set a breakpoint in an unmapped source during a debug session",
"default": true
},
"enableCRAWorkaround": {
"type": "boolean",
"description": "Enable a workaround for breakpoints not working in projects created using create-react-app",
"default": true
},
"log": {
"type": "object",
"description": "Configuration for diagnostic logging of the debug adapter",
Expand Down Expand Up @@ -836,6 +841,11 @@
"description": "Suggest using the Path Mapping Wizard when the user tries to set a breakpoint in an unmapped source during a debug session",
"default": true
},
"enableCRAWorkaround": {
"type": "boolean",
"description": "Enable a workaround for breakpoints not working in projects created using create-react-app",
"default": true
},
"log": {
"type": "object",
"description": "Configuration for diagnostic logging of the debug adapter",
Expand Down
3 changes: 2 additions & 1 deletion src/adapter/adapter/addonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class AddonManager {
private addonActor: TabActorProxy | undefined = undefined;

constructor(
private readonly enableCRAWorkaround: boolean,
private readonly debugSession: FirefoxDebugSession
) {
this.config = debugSession.config.addon!;
Expand Down Expand Up @@ -73,7 +74,7 @@ export class AddonManager {

let consoleActor: ConsoleActorProxy;
let webExtensionActor = new WebExtensionActorProxy(
addon, this.debugSession.pathMapper,
addon, this.enableCRAWorkaround, this.debugSession.pathMapper,
this.debugSession.firefoxDebugConnection);

if (useConnect) {
Expand Down
7 changes: 5 additions & 2 deletions src/adapter/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface ParsedConfiguration {
liftAccessorsFromPrototypes: number;
suggestPathMappingWizard: boolean;
terminate: boolean;
enableCRAWorkaround: boolean;
}

export interface ParsedAttachConfiguration {
Expand Down Expand Up @@ -207,11 +208,13 @@ export async function parseConfiguration(
suggestPathMappingWizard = true;
}
const terminate = (config.request === 'launch') && !config.reAttach;
const enableCRAWorkaround = !!config.enableCRAWorkaround;

return {
attach, launch, addon, pathMappings, filesToSkip, reloadOnChange, tabFilter, clearConsoleOnReload,
showConsoleCallLocation, liftAccessorsFromPrototypes, suggestPathMappingWizard, terminate
}
showConsoleCallLocation, liftAccessorsFromPrototypes, suggestPathMappingWizard, terminate,
enableCRAWorkaround
};
}

function harmonizeTrailingSlashes(pathMapping: PathMapping): PathMapping {
Expand Down
9 changes: 5 additions & 4 deletions src/adapter/firefox/actorProxy/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class RootActorProxy extends EventEmitter implements ActorProxy {
private pendingAddonsRequests = new PendingRequests<FirefoxDebugProtocol.Addon[]>();

constructor(
private readonly enableCRAWorkaround: boolean,
private readonly pathMapper: PathMapper,
private readonly connection: DebugConnection
) {
Expand Down Expand Up @@ -131,15 +132,15 @@ export class RootActorProxy extends EventEmitter implements ActorProxy {

const _tab = tab as FirefoxDebugProtocol.Tab;
actorsForTab = [
new TabActorProxy(
tab.actor, _tab.title, _tab.url, this.pathMapper, this.connection),
new TabActorProxy(tab.actor, _tab.title, _tab.url,
this.enableCRAWorkaround, this.pathMapper, this.connection),
new ConsoleActorProxy(_tab.consoleActor, this.connection)
];

} else {

const tabDescriptorActor = new TabDescriptorActorProxy(
tab.actor, this.pathMapper, this.connection);
tab.actor, this.enableCRAWorkaround, this.pathMapper, this.connection);
actorsForTab = await tabDescriptorActor.getTarget();

}
Expand Down Expand Up @@ -220,7 +221,7 @@ export class RootActorProxy extends EventEmitter implements ActorProxy {
this.pendingProcessRequests.resolveOne([
new TabActorProxy(
processResponse.form.actor, 'Browser', processResponse.form.url,
this.pathMapper, this.connection),
this.enableCRAWorkaround, this.pathMapper, this.connection),
new ConsoleActorProxy(processResponse.form.consoleActor, this.connection)
]);

Expand Down
5 changes: 3 additions & 2 deletions src/adapter/firefox/actorProxy/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class TabActorProxy extends EventEmitter implements ActorProxy {
public readonly name: string,
private _title: string,
private _url: string,
private readonly enableCRAWorkaround: boolean,
private readonly pathMapper: PathMapper,
private readonly connection: DebugConnection
) {
Expand Down Expand Up @@ -94,7 +95,7 @@ export class TabActorProxy extends EventEmitter implements ActorProxy {

let threadActor: IThreadActorProxy = this.connection.getOrCreate(
tabAttachedResponse.threadActor,
() => new ThreadActorProxy(tabAttachedResponse.threadActor, this.connection));
() => new ThreadActorProxy(tabAttachedResponse.threadActor, this.enableCRAWorkaround, this.connection));

threadActor = new SourceMappingThreadActorProxy(threadActor, this.pathMapper, this.connection);

Expand Down Expand Up @@ -172,7 +173,7 @@ export class TabActorProxy extends EventEmitter implements ActorProxy {
log.debug(`Worker ${worker.actor} started`);

workerActor = new WorkerActorProxy(
worker.actor, worker.url, this.pathMapper, this.connection);
worker.actor, worker.url, this.enableCRAWorkaround, this.pathMapper, this.connection);
this.emit('workerStarted', workerActor);

}
Expand Down
3 changes: 2 additions & 1 deletion src/adapter/firefox/actorProxy/tabDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class TabDescriptorActorProxy implements ActorProxy {

constructor(
public readonly name: string,
private readonly enableCRAWorkaround: boolean,
private readonly pathMapper: PathMapper,
private readonly connection: DebugConnection
) {
Expand Down Expand Up @@ -52,7 +53,7 @@ export class TabDescriptorActorProxy implements ActorProxy {
this.pendingGetTargetRequest.resolve([
new TabActorProxy(
getTargetResponse.frame.actor, getTargetResponse.frame.title, getTargetResponse.frame.url,
this.pathMapper, this.connection),
this.enableCRAWorkaround, this.pathMapper, this.connection),
new ConsoleActorProxy(getTargetResponse.frame.consoleActor, this.connection)
]);

Expand Down
17 changes: 15 additions & 2 deletions src/adapter/firefox/actorProxy/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ThreadActorProxy extends EventEmitter implements ActorProxy, IThrea

constructor(
public readonly name: string,
private readonly enableCRAWorkaround: boolean,
private connection: DebugConnection
) {
super();
Expand Down Expand Up @@ -340,7 +341,13 @@ export class ThreadActorProxy extends EventEmitter implements ActorProxy, IThrea
this.pendingSourcesRequests.resolveOne(sources);

for (let source of sources) {
if (!this.connection.has(source.actor)) {

if (this.enableCRAWorkaround && source.url?.endsWith('hot-update.js')) {

log.debug('Ignoring this source because the CRA workaround is enabled');

} else if (!this.connection.has(source.actor)) {

const sourceActor = new SourceActorProxy(source, this.connection);
this.emit('newSource', sourceActor);
}
Expand All @@ -350,7 +357,13 @@ export class ThreadActorProxy extends EventEmitter implements ActorProxy, IThrea

let source = <FirefoxDebugProtocol.Source>(response['source']);
log.debug(`New source ${source.url} on thread ${this.name}`);
if (!this.connection.has(source.actor)) {

if (this.enableCRAWorkaround && source.url?.endsWith('hot-update.js')) {

log.debug('Ignoring this source because the CRA workaround is enabled');

} else if (!this.connection.has(source.actor)) {

const sourceActor = new SourceActorProxy(source, this.connection);
this.emit('newSource', sourceActor);
}
Expand Down
3 changes: 2 additions & 1 deletion src/adapter/firefox/actorProxy/webExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class WebExtensionActorProxy extends EventEmitter implements ActorProxy {

constructor(
private readonly webExtensionInfo: FirefoxDebugProtocol.Addon,
private readonly enableCRAWorkaround: boolean,
private readonly pathMapper: PathMapper,
private readonly connection: DebugConnection
) {
Expand Down Expand Up @@ -59,7 +60,7 @@ export class WebExtensionActorProxy extends EventEmitter implements ActorProxy {
this.pendingConnectRequests.resolveOne([
new TabActorProxy(
connectResponse.form.actor, this.webExtensionInfo.name, connectResponse.form.url,
this.pathMapper, this.connection),
this.enableCRAWorkaround, this.pathMapper, this.connection),
new ConsoleActorProxy(connectResponse.form.consoleActor, this.connection)
]);

Expand Down
3 changes: 2 additions & 1 deletion src/adapter/firefox/actorProxy/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class WorkerActorProxy extends EventEmitter implements ActorProxy {
constructor(
public readonly name: string,
public readonly url: string,
private readonly enableCRAWorkaround: boolean,
private readonly pathMapper: PathMapper,
private readonly connection: DebugConnection
) {
Expand Down Expand Up @@ -94,7 +95,7 @@ export class WorkerActorProxy extends EventEmitter implements ActorProxy {

let threadActor: IThreadActorProxy = this.connection.getOrCreate(
connectedResponse.threadActor,
() => new ThreadActorProxy(connectedResponse.threadActor, this.connection));
() => new ThreadActorProxy(connectedResponse.threadActor, this.enableCRAWorkaround, this.connection));

threadActor = new SourceMappingThreadActorProxy(threadActor, this.pathMapper, this.connection);

Expand Down
3 changes: 2 additions & 1 deletion src/adapter/firefox/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export class DebugConnection {
public readonly rootActor: RootActorProxy;

constructor(
enableCRAWorkaround: boolean,
pathMapper: PathMapper,
socket: Socket
) {

this.actors = new Map<string, ActorProxy>();
this.rootActor = new RootActorProxy(pathMapper, this);
this.rootActor = new RootActorProxy(enableCRAWorkaround, pathMapper, this);
this.transport = new DebugProtocolTransport(socket);

this.transport.on('message', (response: FirefoxDebugProtocol.Response) => {
Expand Down
4 changes: 2 additions & 2 deletions src/adapter/firefoxDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class FirefoxDebugSession {
this.threads, this.config.suggestPathMappingWizard, this.sendEvent);
this.skipFilesManager = new SkipFilesManager(this.config.filesToSkip, this.threads);
if (this.config.addon) {
this.addonManager = new AddonManager(this);
this.addonManager = new AddonManager(config.enableCRAWorkaround, this);
}
}

Expand All @@ -106,7 +106,7 @@ export class FirefoxDebugSession {
return;
}

this.firefoxDebugConnection = new DebugConnection(this.pathMapper, socket);
this.firefoxDebugConnection = new DebugConnection(this.config.enableCRAWorkaround, this.pathMapper, socket);
let rootActor = this.firefoxDebugConnection.rootActor;

// attach to all tabs, register the corresponding threads and inform VSCode about them
Expand Down
1 change: 1 addition & 0 deletions src/common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface CommonConfiguration {
popupAutohideButton?: boolean;
liftAccessorsFromPrototypes?: number;
suggestPathMappingWizard?: boolean;
enableCRAWorkaround?: boolean;
}

export type ReloadConfiguration = string | string[] | DetailedReloadConfiguration;
Expand Down

0 comments on commit 27dc007

Please sign in to comment.