sproutboat 0.5.0 → 0.6.0

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.
package/src/dev.ts CHANGED
@@ -15,7 +15,7 @@ import { mkdir, readFile } from "node:fs/promises";
15
15
  import { dirname, resolve } from "node:path";
16
16
  import { buildArtifact } from "./build";
17
17
  import { createBroker, listen, type Bindings, type Broker } from "./broker";
18
- import { isString, jsonObject, parseJsonValue } from "./json";
18
+ import { jsonObject, parseJsonValue } from "./json";
19
19
  import { amber, dim, leaf, ok } from "./style";
20
20
  import type { SproutboatConfig } from "./config";
21
21
 
@@ -43,18 +43,21 @@ async function readDevVars(projectDir: string): Promise<Record<string, string>>
43
43
  const path = resolve(projectDir, ".dev.vars");
44
44
  if (!existsSync(path)) return {};
45
45
  const text = await readFile(path, "utf8");
46
- return Object.fromEntries(text.split("\n").flatMap((line): Array<[string, string]> => {
47
- const trimmed = line.trim();
48
- if (trimmed === "" || trimmed.startsWith("#")) return [];
49
- const eq = trimmed.indexOf("=");
50
- if (eq <= 0) return [];
51
- const value = trimmed.slice(eq + 1).trim();
52
- // Accept quoted values, since a secret can legitimately contain spaces.
53
- const unquoted = (value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))
54
- ? value.slice(1, -1)
55
- : value;
56
- return [[trimmed.slice(0, eq).trim(), unquoted]];
57
- }));
46
+ return Object.fromEntries(
47
+ text.split("\n").flatMap((line): Array<[string, string]> => {
48
+ const trimmed = line.trim();
49
+ if (trimmed === "" || trimmed.startsWith("#")) return [];
50
+ const eq = trimmed.indexOf("=");
51
+ if (eq <= 0) return [];
52
+ const value = trimmed.slice(eq + 1).trim();
53
+ // Accept quoted values, since a secret can legitimately contain spaces.
54
+ const unquoted =
55
+ (value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))
56
+ ? value.slice(1, -1)
57
+ : value;
58
+ return [[trimmed.slice(0, eq).trim(), unquoted]];
59
+ }),
60
+ );
58
61
  }
59
62
 
60
63
  /** `bindings.json` is written by the build whenever the project declares any. */
@@ -114,7 +117,15 @@ async function start(input: DevInput, source: string): Promise<Running> {
114
117
  stdout: "inherit",
115
118
  stderr: "inherit",
116
119
  });
117
- return { sprout, broker, stopBroker: () => { server.stop(); broker.close(); }, expected: false };
120
+ return {
121
+ sprout,
122
+ broker,
123
+ stopBroker: () => {
124
+ server.stop();
125
+ broker.close();
126
+ },
127
+ expected: false,
128
+ };
118
129
  }
119
130
 
120
131
  function stop(running: Running): void {
@@ -171,7 +182,11 @@ export async function runDev(input: DevInput): Promise<void> {
171
182
  } catch (cause) {
172
183
  // Keep the last good build serving; a typo should not take the
173
184
  // server down mid-edit.
174
- console.error(amber(` rebuild failed, still serving the previous build:\n ${cause instanceof Error ? cause.message : String(cause)}`));
185
+ console.error(
186
+ amber(
187
+ ` rebuild failed, still serving the previous build:\n ${cause instanceof Error ? cause.message : String(cause)}`,
188
+ ),
189
+ );
175
190
  } finally {
176
191
  rebuilding = false;
177
192
  }
@@ -188,7 +203,9 @@ export async function runDev(input: DevInput): Promise<void> {
188
203
  // and save, not a reason to tear the whole session down. Without a watcher
189
204
  // there is nothing to wait for but this one process.
190
205
  if (input.watch) {
191
- await new Promise<void>((resolve) => { resolveShutdown = resolve; });
206
+ await new Promise<void>((resolve) => {
207
+ resolveShutdown = resolve;
208
+ });
192
209
  } else {
193
210
  await running.sprout.exited;
194
211
  stop(running);
package/src/json.ts CHANGED
@@ -21,7 +21,15 @@ export function isBoolean(value: JsonValue | undefined): value is boolean {
21
21
 
22
22
  export function parseJsonValue(source: string): JsonValue {
23
23
  const value = JSON.parse(source);
24
- if (value === null || value === true || value === false || value === String(value) || Number.isFinite(value) || value instanceof Object) return value;
24
+ if (
25
+ value === null ||
26
+ value === true ||
27
+ value === false ||
28
+ value === String(value) ||
29
+ Number.isFinite(value) ||
30
+ value instanceof Object
31
+ )
32
+ return value;
25
33
  throw new Error("response was not valid JSON");
26
34
  }
27
35