| 26 | } |
| 27 | |
| 28 | export class NodeTarget implements ITarget { |
| 29 | private _cdp: Cdp.Api; |
| 30 | private _targetName: string; |
| 31 | private _serialize: Promise<Cdp.Api | undefined> = Promise.resolve(undefined); |
| 32 | private _attached = false; |
| 33 | private _waitingForDebugger: boolean; |
| 34 | private _onNameChangedEmitter = new EventEmitter<void>(); |
| 35 | private _onDisconnectEmitter = new EventEmitter<void>(); |
| 36 | |
| 37 | public entryBreakpoint: IBreakpointPathAndId | undefined = undefined; |
| 38 | |
| 39 | public readonly onDisconnect = this._onDisconnectEmitter.event; |
| 40 | public readonly onNameChanged = this._onNameChangedEmitter.event; |
| 41 | |
| 42 | constructor( |
| 43 | public readonly launchConfig: AnyNodeConfiguration, |
| 44 | private readonly targetOriginValue: ITargetOrigin, |
| 45 | public readonly connection: Connection, |
| 46 | cdp: Cdp.Api, |
| 47 | public readonly targetInfo: WatchdogTarget, |
| 48 | public readonly logger: ILogger, |
| 49 | private readonly lifecycle: INodeTargetLifecycleHooks = {}, |
| 50 | private readonly _parent: ITarget | undefined, |
| 51 | ) { |
| 52 | this.connection = connection; |
| 53 | this._cdp = cdp; |
| 54 | cdp.pause(); |
| 55 | this._waitingForDebugger = targetInfo.type === 'waitingForDebugger'; |
| 56 | if (targetInfo.title) { |
| 57 | this._targetName = `${basename(targetInfo.title)} [${targetInfo.processId}]`; |
| 58 | } else this._targetName = `[${targetInfo.processId}]`; |
| 59 | |
| 60 | cdp.Target.on('targetDestroyed', () => this.connection.close()); |
| 61 | connection.onDisconnected(() => this._disconnected()); |
| 62 | } |
| 63 | |
| 64 | id(): string { |
| 65 | return this.targetInfo.targetId; |
| 66 | } |
| 67 | |
| 68 | processId() { |
| 69 | return this.targetInfo.processId; |
| 70 | } |
| 71 | |
| 72 | name(): string { |
| 73 | return this._targetName; |
| 74 | } |
| 75 | |
| 76 | fileName(): string | undefined { |
| 77 | return this.targetInfo.title; |
| 78 | } |
| 79 | |
| 80 | type(): string { |
| 81 | return 'node'; |
| 82 | } |
| 83 | |
| 84 | targetOrigin(): ITargetOrigin { |
| 85 | return this.targetOriginValue; |