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/README.md +67 -78
- package/SURFACE.md +1 -1
- package/package.json +25 -20
- package/src/assets.ts +29 -9
- package/src/broker.ts +143 -65
- package/src/build.ts +23 -5
- package/src/bundle.ts +2 -1
- package/src/compile.ts +9 -4
- package/src/config.ts +71 -29
- package/src/dev.ts +33 -16
- package/src/json.ts +9 -1
- package/src/main.ts +274 -77
- package/src/manifest.ts +63 -14
- package/src/native-fetch-prelude.js +256 -127
- package/src/patch-porffor.ts +5 -2
- package/src/report.ts +37 -17
- package/src/source.ts +4 -1
- package/src/style.ts +9 -6
- package/src/surface.ts +150 -42
- package/src/toolchain.ts +15 -4
- package/src/update-check.ts +20 -5
- package/src/wrap.ts +32 -8
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 {
|
|
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(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 {
|
|
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(
|
|
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) => {
|
|
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 (
|
|
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
|
|