( args: string[], options: ReactDevtoolsCommandOptions, action: () => Promise<T>, )
| 111 | } |
| 112 | |
| 113 | async function withRemoteDevtoolsCompanion<T>( |
| 114 | args: string[], |
| 115 | options: ReactDevtoolsCommandOptions, |
| 116 | action: () => Promise<T>, |
| 117 | ): Promise<T> { |
| 118 | const { flags } = options; |
| 119 | const bridgeConfig = resolveRemoteBridgeConfig(flags); |
| 120 | if (!bridgeConfig) return action(); |
| 121 | |
| 122 | const stateDir = options.stateDir ?? process.cwd(); |
| 123 | const session = options.session ?? flags?.session ?? 'default'; |
| 124 | const profileKey = |
| 125 | flags?.remoteConfig ?? `${bridgeConfig.tenantId}:${bridgeConfig.runId}:${bridgeConfig.leaseId}`; |
| 126 | |
| 127 | if (args[0] === 'stop') { |
| 128 | try { |
| 129 | return await action(); |
| 130 | } finally { |
| 131 | await stopReactDevtoolsCompanion({ |
| 132 | projectRoot: options.cwd ?? process.cwd(), |
| 133 | stateDir, |
| 134 | profileKey, |
| 135 | consumerKey: session, |
| 136 | }); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | await ensureReactDevtoolsCompanion({ |
| 141 | projectRoot: options.cwd ?? process.cwd(), |
| 142 | stateDir, |
| 143 | serverBaseUrl: bridgeConfig.serverBaseUrl, |
| 144 | bearerToken: bridgeConfig.bearerToken, |
| 145 | bridgeScope: { |
| 146 | tenantId: bridgeConfig.tenantId, |
| 147 | runId: bridgeConfig.runId, |
| 148 | leaseId: bridgeConfig.leaseId, |
| 149 | }, |
| 150 | session, |
| 151 | profileKey, |
| 152 | consumerKey: session, |
| 153 | env: options.env ?? process.env, |
| 154 | }); |
| 155 | return await action(); |
| 156 | } |
| 157 | |
| 158 | export async function runReactDevtoolsCommand( |
| 159 | args: string[], |
no test coverage detected