@paleo/workspace 0.14.1 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/dev-server.js +25 -21
  2. package/package.json +1 -1
@@ -82,17 +82,7 @@ async function start(config, mainWorktree, options) {
82
82
  if (await runStartChecks(config, mainWorktree, ctx, options))
83
83
  return;
84
84
  const state = { spawnPids: {}, startedCallbacks: [] };
85
- try {
86
- await spawnAndAwait(config, ctx, state);
87
- }
88
- catch (err) {
89
- await rollbackStart(state.spawnPids, state.startedCallbacks, ctx);
90
- if (err instanceof StartupError) {
91
- handleStartupFailure(err);
92
- process.exit(1);
93
- }
94
- throw err;
95
- }
85
+ await spawnWithRollback(config, ctx, state);
96
86
  const slot = registerStartedServer(config, mainWorktree, state.spawnPids);
97
87
  printStartSummary(config, slot, state.spawnPids);
98
88
  }
@@ -121,16 +111,10 @@ async function runForeground(config, mainWorktree, options) {
121
111
  process.on("SIGTERM", onSignal);
122
112
  if (await runStartChecks(config, mainWorktree, ctx, options))
123
113
  process.exit(0);
124
- try {
125
- await spawnAndAwait(config, ctx, state);
126
- }
127
- catch (err) {
128
- await rollbackStart(state.spawnPids, state.startedCallbacks, ctx);
129
- if (err instanceof StartupError) {
130
- handleStartupFailure(err);
131
- process.exit(1);
132
- }
133
- throw err;
114
+ // A signal during startup hands teardown to onSignal (rollback + exit 130); block so we
115
+ // neither roll back twice nor register a server that is being torn down.
116
+ if (!(await spawnWithRollback(config, ctx, state, () => shuttingDown))) {
117
+ await new Promise(() => { });
134
118
  }
135
119
  const slot = registerStartedServer(config, mainWorktree, state.spawnPids);
136
120
  started = true;
@@ -160,6 +144,26 @@ async function runStartChecks(config, mainWorktree, ctx, { evict, restart }) {
160
144
  await checkPortsFree(config.servers, ctx.cwd);
161
145
  return false;
162
146
  }
147
+ /**
148
+ * Spawn and await readiness, rolling back on failure. Returns `false` when `isAborted` reports a
149
+ * concurrent shutdown — the caller must then yield teardown to whoever set it, not proceed.
150
+ */
151
+ async function spawnWithRollback(config, ctx, state, isAborted = () => false) {
152
+ try {
153
+ await spawnAndAwait(config, ctx, state);
154
+ }
155
+ catch (err) {
156
+ if (isAborted())
157
+ return false;
158
+ await rollbackStart(state.spawnPids, state.startedCallbacks, ctx);
159
+ if (err instanceof StartupError) {
160
+ handleStartupFailure(err);
161
+ process.exit(1);
162
+ }
163
+ throw err;
164
+ }
165
+ return !isAborted();
166
+ }
163
167
  async function spawnAndAwait(config, ctx, state) {
164
168
  for (const server of config.servers) {
165
169
  console.log(`Starting ${server.name} dev server...`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paleo/workspace",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "description": "Run multiple git-worktree dev environments side by side.",
5
5
  "keywords": [
6
6
  "workspace",