workspace-update-adapters.mjs 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. /** Replace only update delivery/installation and inspector allocation for the compiled main-entry scenario. */
  2. import { DesktopUpdateCoordinator as Coordinator } from '../../lib/types/update-coordinator.js'
  3. import { DesktopHostProcess as Host } from '../../lib/types/host-process.js'
  4. export { DesktopHostUncleanExitError } from '../../lib/types/host-process.js'
  5. export { DesktopUpdatePreparationError } from '../../lib/types/update-error.js'
  6. export const fixture = { updater: undefined, coordinator: undefined, host: undefined, ready: Promise.withResolvers(), readyHosts: new WeakSet(), states: [], installations: [], taskQueries: [] }
  7. export class DesktopUpdateCoordinator extends Coordinator {
  8. constructor(publish, beforeRestart) {
  9. super(state => { fixture.states.push(state); return publish(state) }, beforeRestart, fixture.updater, () => true, () => '0.1.5-rc.1')
  10. fixture.coordinator = this
  11. }
  12. }
  13. export class DesktopHostProcess extends Host {
  14. async updateTasks(action) {
  15. const result = await super.updateTasks(action)
  16. fixture.taskQueries.push({ at: Date.now(), action, active: result })
  17. return result
  18. }
  19. constructor(node, runtime, project, _inspectPort, environment, onFailure) {
  20. // Port zero lets the OS allocate the development inspector; no fixed listener is acquired.
  21. super(node, runtime, project, 0, environment, onFailure)
  22. fixture.host = this
  23. }
  24. async start() {
  25. try {
  26. const result = await super.start()
  27. fixture.readyHosts.add(this)
  28. fixture.ready.resolve(result.url)
  29. return result
  30. } catch (error) { fixture.ready.reject(error); throw error }
  31. }
  32. }