Skip to content
Merged
Changes from all commits
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
63 changes: 63 additions & 0 deletions src/execution/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,69 @@ import type {Result} from '../error.js';

/**
* Execution for a {@link ServiceScriptConfig}.
*
* Note that this class represents a service _bound to one particular execution_
* of the script graph. In non-watch mode (`npm run ...`), there will be one
* instance of this class per service. In watch mode (`npm run --watch ...`),
* there will be one instance of this class per service _per watch iteration_,
* and the underlying child process will be transfered between instances of this
* class whenever possible to avoid restarts.
*
* ```
* ┌─────────┐
* ╭─◄─ abort ────┤ INITIAL │
* │ └────┬────┘
* │ │
* ▼ execute
* │ │
* │ ┌───────▼────────┐
* ├─◄─ abort ─┤ FINGERPRINTING ├──── depExecErr ────►───╮
* │ └───────┬────────┘ │
* │ │ │
* ▼ fingerprinted │
* │ │ │
* │ ┌─────▼─────┐ │
* ├─◄─ abort ───┤ UNSTARTED │ │
* │ └─────┬─────┘ ▼
* │ │ │
* │ start │
* │ │ ╭─╮ │
* │ │ │ start │
* │ ┌────▼──▼─┴┐ │
* │ ╭◄─ abort ┤ STARTING ├─── startErr or ────►──────┤
* │ │ └────┬────┬┘ depServiceStartErr │
* ▼ │ │ │ │
* │ │ │ ▼ │
* │ │ │ ╰─── depServiceExit ──►──╮ │
* │ │ started │ │
* │ ▼ │ ╭─╮ ▼ │
* │ │ │ │ start │ │
* │ │ ┌────▼─▼─┴┐ │ │
* │ ├◄─ abort ┤ STARTED ├── exit ─────────────►──│───┤
* │ │ └────┬─┬─┬┘ │ │
* │ │ │ │ ╰─── detach ──╮ │ │
* │ │ │ ▼ │ │ │
* │ │ │ ╰───── depServiceExit ───►──┤ │
* │ │ │ │ │ │
* │ │ allConsumersDone │ │ │
* │ ▼ (unless directly invoked) │ │ │
* │ │ │ ▼ ▼ ▼
* ▼ │ │ ╭─╮ │ │ │
* │ │ │ │ start │ │ │
* │ │ ┌────▼──▼─┴┐ │ │ │
* │ ╰─────────► STOPPING ◄─────────────◄─────────╯ │
* │ └┬─▲─┬─────┘ │ │
* │ abort │ │ │ │
* │ ╰─╯ │ │ │
* │ exit │ │
* │ │ ╭─╮ │ │ ╭─╮
* │ │ │ start │ │ │ start
Comment thread
justinfagnani marked this conversation as resolved.
* │ ┌────▼─▼─┴┐ ┌────▼─────┐ ┌───▼─▼─┴┐
* ╰──────────────► STOPPED │ │ DETACHED │ │ FAILED │
* └┬─▲──────┘ └┬─▲───────┘ └┬─▲─────┘
* abort │ *all* │ abort │
* ╰─╯ ╰─╯ ╰─╯
* ```
*/
export class ServiceScriptExecution extends BaseExecutionWithCommand<ServiceScriptConfig> {
private readonly _terminated = new Deferred<Result<void, Failure>>();
Expand Down