goatly 0.1.0 → 0.1.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.
- package/README.md +874 -1
- package/bin/goatly.js +99 -0
- package/dist/cli/index.js +234 -0
- package/dist/compat/gatsby-node-entry.js +16 -0
- package/dist/compat/gatsby-package.json +6 -0
- package/dist/compat/md5-file.js +47 -0
- package/dist/compat-apis.json +72 -0
- package/dist/compat-apis.json.js +62 -0
- package/dist/graphql.js +3 -0
- package/dist/node/actions/index.js +619 -0
- package/dist/node/actions/job-store.js +180 -0
- package/dist/node/actions/jobs.js +174 -0
- package/dist/node/api-runner.js +258 -0
- package/dist/node/bootstrap.js +569 -0
- package/dist/node/build/assets.js +110 -0
- package/dist/node/build/incremental.js +208 -0
- package/dist/node/build/index.js +763 -0
- package/dist/node/build/memory-governor.js +450 -0
- package/dist/node/build/output-dirs.js +70 -0
- package/dist/node/build/page-data.js +40 -0
- package/dist/node/build/page-files.js +186 -0
- package/dist/node/build/partitioned-state.js +258 -0
- package/dist/node/build/query-worker.js +626 -0
- package/dist/node/build/query-workers.js +863 -0
- package/dist/node/build/render-thread.js +103 -0
- package/dist/node/build/render-worker.js +162 -0
- package/dist/node/build/state.js +24 -0
- package/dist/node/build/timing-breakdown.js +216 -0
- package/dist/node/build/work-clock.js +75 -0
- package/dist/node/build/worker-pool.js +242 -0
- package/dist/node/cache-layout.js +99 -0
- package/dist/node/cache.js +1430 -0
- package/dist/node/compat/chokidar-shim.js +148 -0
- package/dist/node/compat/core-utils-lmdb.js +145 -0
- package/dist/node/compat/create-node-id-shim.js +1 -0
- package/dist/node/compat/module-hooks.js +245 -0
- package/dist/node/compat/redux-shim.js +1 -0
- package/dist/node/config/index.js +162 -0
- package/dist/node/config/not-found-pages.js +95 -0
- package/dist/node/datastore/codec.js +144 -0
- package/dist/node/datastore/index.js +127 -0
- package/dist/node/datastore/logfile/cache.js +89 -0
- package/dist/node/datastore/logfile/index.js +1329 -0
- package/dist/node/datastore/logfile/record.js +71 -0
- package/dist/node/datastore/types.js +1 -0
- package/dist/node/develop/express-compat.js +207 -0
- package/dist/node/develop/graphiql.js +22 -0
- package/dist/node/develop/hydration-report.js +41 -0
- package/dist/node/develop/index.js +618 -0
- package/dist/node/develop/local-url.js +10 -0
- package/dist/node/develop/ssr-runner.js +66 -0
- package/dist/node/gql.js +5 -0
- package/dist/node/index.js +15 -0
- package/dist/node/info.js +270 -0
- package/dist/node/internal-plugins/data-bridge.js +196 -0
- package/dist/node/internal-plugins/page-creator.js +318 -0
- package/dist/node/loader/import-module.js +160 -0
- package/dist/node/node-helpers.js +66 -0
- package/dist/node/not-found-pages.js +220 -0
- package/dist/node/plugins/api-list.js +12 -0
- package/dist/node/plugins/load-plugins.js +427 -0
- package/dist/node/plugins/resolve-plugin.js +79 -0
- package/dist/node/plugins/static-exports.js +64 -0
- package/dist/node/query/compile.js +326 -0
- package/dist/node/query/dependencies.js +45 -0
- package/dist/node/query/execute.js +417 -0
- package/dist/node/query/extract.js +372 -0
- package/dist/node/query/gql-tada-introspection.js +124 -0
- package/dist/node/query/graphql-env.js +231 -0
- package/dist/node/query/graphql-runner.js +79 -0
- package/dist/node/redux/actions.js +1 -0
- package/dist/node/redux/index.js +133 -0
- package/dist/node/redux/node-changes.js +128 -0
- package/dist/node/redux/reducers.js +193 -0
- package/dist/node/redux/state.js +71 -0
- package/dist/node/renderer.js +124 -0
- package/dist/node/reporter-transports.js +259 -0
- package/dist/node/reporter.js +497 -0
- package/dist/node/schema/date.js +539 -0
- package/dist/node/schema/extensions.js +315 -0
- package/dist/node/schema/index.js +542 -0
- package/dist/node/schema/infer.js +388 -0
- package/dist/node/schema/inline-objects.js +128 -0
- package/dist/node/schema/naming.js +20 -0
- package/dist/node/schema/node-model.js +207 -0
- package/dist/node/schema/query-engine.js +1808 -0
- package/dist/node/schema/resolver-kinds.js +7 -0
- package/dist/node/schema/resolvers.js +273 -0
- package/dist/node/schema/type-builders.js +45 -0
- package/dist/node/schema/types.js +241 -0
- package/dist/node/serve.js +90 -0
- package/dist/node/site-page-nodes.js +277 -0
- package/dist/node/types.js +1 -0
- package/dist/node/utils/content-digest.js +107 -0
- package/dist/node/utils/cpus.js +104 -0
- package/dist/node/utils/create-node-id.js +51 -0
- package/dist/node/utils/env.js +25 -0
- package/dist/node/utils/fs-retry.js +74 -0
- package/dist/node/utils/memory-signals.js +441 -0
- package/dist/node/utils/memory.js +657 -0
- package/dist/node/utils/murmurhash.js +32 -0
- package/dist/node/utils/parser.js +33 -0
- package/dist/node/utils/partition-hash.js +19 -0
- package/dist/node/utils/paths.js +122 -0
- package/dist/node/utils/resolver.js +48 -0
- package/dist/node/utils/runtime.js +5 -0
- package/dist/node/utils/serializable.js +41 -0
- package/dist/node/utils/strings.js +41 -0
- package/dist/node/vite/config.js +289 -0
- package/dist/node/vite/paths.js +12 -0
- package/dist/node/vite/plugin-deps.js +232 -0
- package/dist/node/vite/plugin.js +283 -0
- package/dist/node/vite/react-compiler.js +362 -0
- package/dist/node/vite/source-files.js +83 -0
- package/dist/node/vite/static-image.js +136 -0
- package/dist/node/vite/styled-components.js +73 -0
- package/dist/node/vite/transforms.js +330 -0
- package/dist/node/wasm-data/host.js +406 -0
- package/dist/node/wasm-data/lower.js +406 -0
- package/dist/node/wasm-data/runner.js +79 -0
- package/dist/node/wasm-data/worker.js +95 -0
- package/dist/reporter.js +5 -0
- package/dist/runtime/api-runner.js +81 -0
- package/dist/runtime/app.js +256 -0
- package/dist/runtime/client-entry.js +4 -0
- package/dist/runtime/client.js +383 -0
- package/dist/runtime/default-html.js +31 -0
- package/dist/runtime/head-markup.js +100 -0
- package/dist/runtime/head-sync.js +101 -0
- package/dist/runtime/head-tags.js +45 -0
- package/dist/runtime/hydration-report.js +111 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/link.js +293 -0
- package/dist/runtime/loader.js +449 -0
- package/dist/runtime/not-found.js +61 -0
- package/dist/runtime/page-renderer.js +35 -0
- package/dist/runtime/preamble.js +47 -0
- package/dist/runtime/react-compat.js +14 -0
- package/dist/runtime/renderer-shared.js +10 -0
- package/dist/runtime/renderers/react-client.js +14 -0
- package/dist/runtime/renderers/react-server.js +99 -0
- package/dist/runtime/renderers/react.js +17 -0
- package/dist/runtime/renderers/types.js +1 -0
- package/dist/runtime/root-error-handlers.js +29 -0
- package/dist/runtime/router/history.js +132 -0
- package/dist/runtime/router/index.js +240 -0
- package/dist/runtime/router/utils.js +118 -0
- package/dist/runtime/script.js +110 -0
- package/dist/runtime/scroll.js +40 -0
- package/dist/runtime/slice.js +11 -0
- package/dist/runtime/ssr.js +240 -0
- package/dist/runtime/static-query.js +47 -0
- package/dist/utils.js +4 -0
- package/package.json +105 -3
- package/types/graphql-tada.d.ts +223 -0
- package/types/graphql.d.ts +2 -0
- package/types/index.d.ts +2287 -0
- package/types/node.d.ts +389 -0
- package/types/reporter.d.ts +187 -0
- package/types/router.d.ts +102 -0
- package/types/vendor/gql-tada.d.ts +2529 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import { compatEnv } from "./utils/env.js";
|
|
2
|
+
import { activityEndText, consoleTransport, formatTimingBreakdown } from "./reporter-transports.js";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
import { performance } from "node:perf_hooks";
|
|
5
|
+
import { BroadcastChannel, isMainThread, threadId } from "node:worker_threads";
|
|
6
|
+
// src/node/reporter.ts
|
|
7
|
+
var Span = class {
|
|
8
|
+
tags = {};
|
|
9
|
+
setTag(key, value) {
|
|
10
|
+
this.tags[key] = value;
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
finish() {}
|
|
14
|
+
context() {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
log() {
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const noopTracer = { startSpan: () => new Span() };
|
|
22
|
+
function stripIndent(strings, ...values) {
|
|
23
|
+
const lines = (typeof strings === "string" ? strings : strings.reduce((acc, s, i) => acc + s + (i < values.length ? String(values[i]) : ""), "")).replace(/^\n/, "").split("\n");
|
|
24
|
+
const indents = lines.filter((l) => l.trim()).map((l) => l.match(/^\s*/)[0].length);
|
|
25
|
+
const min = indents.length ? Math.min(...indents) : 0;
|
|
26
|
+
return lines.map((l) => l.slice(min)).join("\n").trimEnd();
|
|
27
|
+
}
|
|
28
|
+
var PanicError = class extends Error {
|
|
29
|
+
isPanic = true;
|
|
30
|
+
};
|
|
31
|
+
/** worker threads send their output to the main thread (one channel per process) */
|
|
32
|
+
const BRIDGE_CHANNEL = "goatly:reporter";
|
|
33
|
+
/** set for goatly's own worker threads (query/render workers) */
|
|
34
|
+
const BRIDGED = !isMainThread && process.env.GOATLY_REPORTER_BRIDGE === "1";
|
|
35
|
+
/** env for worker threads whose output should go to the main thread's transports */
|
|
36
|
+
const REPORTER_BRIDGE_ENV = { GOATLY_REPORTER_BRIDGE: "1" };
|
|
37
|
+
/** transport used in worker threads: forwards everything to the main thread */
|
|
38
|
+
function workerBridgeTransport() {
|
|
39
|
+
let channel;
|
|
40
|
+
const post = (message) => {
|
|
41
|
+
if (!channel) {
|
|
42
|
+
channel = new BroadcastChannel(BRIDGE_CHANNEL);
|
|
43
|
+
channel.unref?.();
|
|
44
|
+
}
|
|
45
|
+
channel.postMessage(message);
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
log: (entry) => post({
|
|
49
|
+
kind: "log",
|
|
50
|
+
entry: {
|
|
51
|
+
...entry,
|
|
52
|
+
threadId
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
activityStart: (activity) => post({
|
|
56
|
+
kind: "activityStart",
|
|
57
|
+
activity
|
|
58
|
+
}),
|
|
59
|
+
activityUpdate: (activity) => post({
|
|
60
|
+
kind: "activityUpdate",
|
|
61
|
+
activity
|
|
62
|
+
}),
|
|
63
|
+
activityEnd: (activity) => post({
|
|
64
|
+
kind: "activityEnd",
|
|
65
|
+
activity
|
|
66
|
+
})
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const UPDATE_INTERVAL_MS = 200;
|
|
70
|
+
/** seconds: activities running this long are reported (then less often, at least once a minute) */
|
|
71
|
+
const PROGRESS_AFTER = 5;
|
|
72
|
+
/** "run page queries - running for 12s - 4200/8422 49% - 3 workers" */
|
|
73
|
+
function runningText(activity) {
|
|
74
|
+
let text = `${activity.text} - running for ${Math.floor(activity.elapsed)}s`;
|
|
75
|
+
if (activity.type === "progress") {
|
|
76
|
+
const { current = 0, total = 0 } = activity;
|
|
77
|
+
text += ` - ${current}/${total}`;
|
|
78
|
+
if (total > 0) text += ` ${Math.min(100, Math.floor(100 * current / total))}%`;
|
|
79
|
+
}
|
|
80
|
+
if (activity.status) text += ` - ${activity.status}`;
|
|
81
|
+
return text;
|
|
82
|
+
}
|
|
83
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
84
|
+
var Reporter = class {
|
|
85
|
+
errorMaps = {};
|
|
86
|
+
isVerbose = !!compatEnv("GOATLY_VERBOSE");
|
|
87
|
+
isBuild = false;
|
|
88
|
+
/** When set, panics throw instead of exiting the process (used by tests / programmatic API). */
|
|
89
|
+
throwOnPanic = false;
|
|
90
|
+
hasErrors = false;
|
|
91
|
+
/** only errors are reported (all transports) */
|
|
92
|
+
silent = !!process.env.GOATLY_SILENT;
|
|
93
|
+
stripIndent = stripIndent;
|
|
94
|
+
format = pc;
|
|
95
|
+
startTime = performance.now();
|
|
96
|
+
transports = BRIDGED ? [workerBridgeTransport()] : [consoleTransport()];
|
|
97
|
+
activityCounter = 0;
|
|
98
|
+
/** the activities behind trackers (parents of `activityParts()`, `endActivity()`) */
|
|
99
|
+
activities = /* @__PURE__ */ new WeakMap();
|
|
100
|
+
/** (an object: local reporters of plugins, `Object.create(reporter)`, share it) */
|
|
101
|
+
running = {
|
|
102
|
+
activities: /* @__PURE__ */ new Set(),
|
|
103
|
+
timer: void 0
|
|
104
|
+
};
|
|
105
|
+
bridge;
|
|
106
|
+
/**
|
|
107
|
+
* where the transports come from: transports set through the API (`build({ reporter })`,
|
|
108
|
+
* GOATLY_REPORTER, `reporter.setTransports()`) win over `reporter` in gatsby-config
|
|
109
|
+
*/
|
|
110
|
+
transportSource = "default";
|
|
111
|
+
/** Replaces the transports all output goes to (default: the console transport). */
|
|
112
|
+
setTransports(transports, source = "api") {
|
|
113
|
+
const list = Array.isArray(transports) ? transports : [transports];
|
|
114
|
+
for (const t of list) if (!t || typeof t.log !== "function") throw new TypeError("A reporter transport needs a log(entry) method");
|
|
115
|
+
this.transports = list;
|
|
116
|
+
this.transportSource = source;
|
|
117
|
+
}
|
|
118
|
+
addTransport(transport) {
|
|
119
|
+
this.setTransports([...this.transports, transport], this.transportSource === "config" ? "config" : "api");
|
|
120
|
+
}
|
|
121
|
+
getTransports() {
|
|
122
|
+
return [...this.transports];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Main thread: receive the output of worker threads started with `REPORTER_BRIDGE_ENV` (they
|
|
126
|
+
* forward it over a BroadcastChannel). Stays open for the process lifetime (unref'd), so output
|
|
127
|
+
* arriving after a worker finished is not lost.
|
|
128
|
+
*/
|
|
129
|
+
receiveWorkerOutput() {
|
|
130
|
+
if (!isMainThread || this.bridge) return;
|
|
131
|
+
const channel = new BroadcastChannel(BRIDGE_CHANNEL);
|
|
132
|
+
channel.unref?.();
|
|
133
|
+
channel.addEventListener("message", (event) => this.dispatchFromWorker(event.data));
|
|
134
|
+
this.bridge = channel;
|
|
135
|
+
}
|
|
136
|
+
dispatchFromWorker(message) {
|
|
137
|
+
if (!message || typeof message !== "object") return;
|
|
138
|
+
if (message.kind === "log") {
|
|
139
|
+
const { entry } = message;
|
|
140
|
+
if (entry.level === "error") this.hasErrors = true;
|
|
141
|
+
if (entry.level === "verbose" && !this.isVerbose) return;
|
|
142
|
+
this.write(entry);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const activity = {
|
|
146
|
+
...message.activity,
|
|
147
|
+
id: `${message.activity.id}`
|
|
148
|
+
};
|
|
149
|
+
if (message.kind === "activityEnd") this.writeActivityEnd(activity);
|
|
150
|
+
else this.each((t) => t[message.kind]?.(activity));
|
|
151
|
+
}
|
|
152
|
+
each(fn) {
|
|
153
|
+
for (const t of this.transports) try {
|
|
154
|
+
fn(t);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
process.stderr.write(`goatly: reporter transport failed: ${e?.stack ?? e}\n`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
write(entry) {
|
|
160
|
+
if (this.silent && entry.level !== "error") return;
|
|
161
|
+
this.each((t) => t.log(entry));
|
|
162
|
+
}
|
|
163
|
+
emit(level, text, extra) {
|
|
164
|
+
this.write({
|
|
165
|
+
level,
|
|
166
|
+
text: text.replace(ANSI, ""),
|
|
167
|
+
timestamp: Date.now(),
|
|
168
|
+
...extra
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
writeActivityEnd(activity) {
|
|
172
|
+
if (this.silent && activity.outcome !== "failed") return;
|
|
173
|
+
this.each((t) => {
|
|
174
|
+
if (t.activityEnd) t.activityEnd(activity);
|
|
175
|
+
else t.log({
|
|
176
|
+
level: activity.outcome === "failed" ? "error" : "success",
|
|
177
|
+
text: activityEndText(activity),
|
|
178
|
+
timestamp: Date.now(),
|
|
179
|
+
activity
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** flushes all transports; resolves when asynchronous transports are done (max. 3 s) */
|
|
184
|
+
flush() {
|
|
185
|
+
const pending = [];
|
|
186
|
+
this.each((t) => {
|
|
187
|
+
const result = t.flush?.();
|
|
188
|
+
if (result && typeof result.then === "function") pending.push(result);
|
|
189
|
+
});
|
|
190
|
+
if (!pending.length) return Promise.resolve();
|
|
191
|
+
return Promise.race([Promise.allSettled(pending).then(() => {}), new Promise((resolve) => setTimeout(resolve, 3e3).unref())]);
|
|
192
|
+
}
|
|
193
|
+
setVerbose(isVerbose = true) {
|
|
194
|
+
this.isVerbose = isVerbose;
|
|
195
|
+
}
|
|
196
|
+
setNoColor(noColor = true) {
|
|
197
|
+
if (noColor) this.format = pc.createColors(false);
|
|
198
|
+
}
|
|
199
|
+
setErrorMap(map) {
|
|
200
|
+
Object.assign(this.errorMaps, map);
|
|
201
|
+
}
|
|
202
|
+
_setStage() {}
|
|
203
|
+
_registerAdditionalDiagnosticOutputHandler() {}
|
|
204
|
+
log(text = "") {
|
|
205
|
+
this.emit("log", String(text));
|
|
206
|
+
}
|
|
207
|
+
info(text) {
|
|
208
|
+
this.emit("info", String(text));
|
|
209
|
+
}
|
|
210
|
+
success(text) {
|
|
211
|
+
this.emit("success", String(text));
|
|
212
|
+
}
|
|
213
|
+
warn(text) {
|
|
214
|
+
this.emit("warn", String(text));
|
|
215
|
+
}
|
|
216
|
+
verbose(text) {
|
|
217
|
+
if (this.isVerbose || BRIDGED) this.emit("verbose", String(text));
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* A line (`title`) with the breakdown of its time below it: a Gantt chart of the segments, one
|
|
221
|
+
* row each with its time, share and bar (e.g. the build's phases). Other transports get the
|
|
222
|
+
* `breakdown` field of the log entry.
|
|
223
|
+
*/
|
|
224
|
+
timingBreakdown(title, segments, level = "info") {
|
|
225
|
+
this.emit(level, formatTimingBreakdown(segments, { title }), { breakdown: {
|
|
226
|
+
title,
|
|
227
|
+
segments: segments.map((s) => ({ ...s }))
|
|
228
|
+
} });
|
|
229
|
+
}
|
|
230
|
+
uptime(prefix) {
|
|
231
|
+
this.verbose(`${prefix}: ${((performance.now() - this.startTime) / 1e3).toFixed(3)}s`);
|
|
232
|
+
}
|
|
233
|
+
/** Converts Gatsby structured error metadata to a message and structured details. */
|
|
234
|
+
describeError(errorMeta, error) {
|
|
235
|
+
let message = "";
|
|
236
|
+
let err = error;
|
|
237
|
+
const details = {};
|
|
238
|
+
if (typeof errorMeta === "string") message = errorMeta;
|
|
239
|
+
else if (errorMeta instanceof Error) {
|
|
240
|
+
err = errorMeta;
|
|
241
|
+
message = errorMeta.message;
|
|
242
|
+
} else if (Array.isArray(errorMeta)) {
|
|
243
|
+
const parts = errorMeta.map((e) => this.describeError(e));
|
|
244
|
+
return {
|
|
245
|
+
text: parts.map((p) => p.text).join("\n"),
|
|
246
|
+
error: parts[0]?.error
|
|
247
|
+
};
|
|
248
|
+
} else if (errorMeta && typeof errorMeta === "object") {
|
|
249
|
+
const meta = errorMeta;
|
|
250
|
+
const mapped = meta.id ? this.errorMaps[meta.id] : void 0;
|
|
251
|
+
if (meta.id !== void 0) details.id = String(meta.id);
|
|
252
|
+
if (meta.context && typeof meta.context === "object") details.context = meta.context;
|
|
253
|
+
details.category = meta.category ?? mapped?.category;
|
|
254
|
+
details.type = meta.type ?? mapped?.type;
|
|
255
|
+
details.level = meta.level ?? mapped?.level;
|
|
256
|
+
if (meta.filePath) details.filePath = meta.filePath;
|
|
257
|
+
if (meta.location) details.location = meta.location;
|
|
258
|
+
if (meta.pluginName ?? meta.context?.pluginName) details.pluginName = meta.pluginName ?? meta.context?.pluginName;
|
|
259
|
+
if (mapped) try {
|
|
260
|
+
message = mapped.text(meta.context ?? {});
|
|
261
|
+
} catch {
|
|
262
|
+
message = JSON.stringify(meta.context);
|
|
263
|
+
}
|
|
264
|
+
else message = meta.context?.sourceMessage ?? meta.context?.message ?? meta.text ?? meta.message ?? (meta.id ? `Error ${meta.id}: ${JSON.stringify(meta.context ?? {})}` : JSON.stringify(meta));
|
|
265
|
+
if (meta.context?.pluginName && meta.context?.api) message = `"${meta.context.pluginName}" threw an error while running the ${meta.context.api} lifecycle:\n\n${message}`;
|
|
266
|
+
if (meta.filePath) message += `\n\n File: ${meta.filePath}${meta.location?.start ? `:${meta.location.start.line}:${meta.location.start.column ?? 0}` : ""}`;
|
|
267
|
+
if (meta.context?.codeFrame) message += `\n\n${meta.context.codeFrame}`;
|
|
268
|
+
err = err ?? meta.error;
|
|
269
|
+
}
|
|
270
|
+
if (err && err instanceof Error) {
|
|
271
|
+
if (!message.includes(err.message)) message += `\n\n${err.message}`;
|
|
272
|
+
details.message = err.message;
|
|
273
|
+
details.name = err.name;
|
|
274
|
+
details.stack = err.stack;
|
|
275
|
+
}
|
|
276
|
+
for (const key of Object.keys(details)) if (details[key] === void 0) delete details[key];
|
|
277
|
+
return {
|
|
278
|
+
text: message,
|
|
279
|
+
error: Object.keys(details).length ? details : void 0
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/** The message of Gatsby structured error metadata (incl. the stack trace, colored). */
|
|
283
|
+
formatError(errorMeta, error) {
|
|
284
|
+
const { text, error: details } = this.describeError(errorMeta, error);
|
|
285
|
+
return details?.stack ? `${text}\n\n${pc.gray(details.stack.split("\n").slice(1, 12).join("\n"))}` : text;
|
|
286
|
+
}
|
|
287
|
+
error(errorMeta, error) {
|
|
288
|
+
this.hasErrors = true;
|
|
289
|
+
const { text, error: details } = this.describeError(errorMeta, error);
|
|
290
|
+
this.emit("error", text, details ? { error: details } : void 0);
|
|
291
|
+
}
|
|
292
|
+
panic(errorMeta, error) {
|
|
293
|
+
this.error(errorMeta, error);
|
|
294
|
+
if (this.throwOnPanic || !isMainThread) throw new PanicError(this.describeError(errorMeta, error).text);
|
|
295
|
+
const flushed = this.flush();
|
|
296
|
+
if (this.transports.some((t) => t.flush)) {
|
|
297
|
+
process.exitCode = 1;
|
|
298
|
+
flushed.finally(() => process.exit(1));
|
|
299
|
+
throw new PanicError(this.describeError(errorMeta, error).text);
|
|
300
|
+
}
|
|
301
|
+
process.exit(1);
|
|
302
|
+
}
|
|
303
|
+
panicOnBuild(errorMeta, error) {
|
|
304
|
+
if (this.isBuild) this.panic(errorMeta, error);
|
|
305
|
+
this.error(errorMeta, error);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Logs a line for each activity that has been running for 5 s, then again whenever a quarter of
|
|
309
|
+
* its running time (5 s to 60 s) has passed. Runs every second and on activity updates: timers
|
|
310
|
+
* do not run while page queries in the main thread keep the event loop busy.
|
|
311
|
+
*/
|
|
312
|
+
reportRunning() {
|
|
313
|
+
const now = performance.now();
|
|
314
|
+
for (const activity of this.running.activities) {
|
|
315
|
+
const info = activity.info();
|
|
316
|
+
if ((activity.reportedAt === void 0 ? info.elapsed : (now - activity.reportedAt) / 1e3) < (activity.reportedAt === void 0 ? PROGRESS_AFTER : Math.max(PROGRESS_AFTER, Math.min(60, info.elapsed / 4)))) continue;
|
|
317
|
+
activity.reportedAt = now;
|
|
318
|
+
this.info(runningText(info));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/** `hidden`: no progress lines (phantom activities) */
|
|
322
|
+
createActivity(text, type, total, startCount, hidden = false) {
|
|
323
|
+
const id = this.nextActivityId();
|
|
324
|
+
let start = 0;
|
|
325
|
+
let status;
|
|
326
|
+
let current = startCount ?? 0;
|
|
327
|
+
let ended = false;
|
|
328
|
+
let lastUpdate = 0;
|
|
329
|
+
let endElapsed;
|
|
330
|
+
const elapsed = () => endElapsed ?? (start ? (performance.now() - start) / 1e3 : 0);
|
|
331
|
+
const running = { info: () => info() };
|
|
332
|
+
const live = this.running.activities;
|
|
333
|
+
const info = (outcome) => ({
|
|
334
|
+
id,
|
|
335
|
+
text,
|
|
336
|
+
type,
|
|
337
|
+
status: status || void 0,
|
|
338
|
+
...type === "progress" ? {
|
|
339
|
+
current,
|
|
340
|
+
total: state.total
|
|
341
|
+
} : {},
|
|
342
|
+
elapsed: elapsed(),
|
|
343
|
+
...outcome ? { outcome } : {}
|
|
344
|
+
});
|
|
345
|
+
const state = {
|
|
346
|
+
id,
|
|
347
|
+
elapsed,
|
|
348
|
+
total: total ?? 0,
|
|
349
|
+
start: () => {
|
|
350
|
+
start = performance.now();
|
|
351
|
+
this.each((t) => t.activityStart?.(info()));
|
|
352
|
+
if (hidden || !isMainThread || ended) return;
|
|
353
|
+
live.add(running);
|
|
354
|
+
if (!this.running.timer) {
|
|
355
|
+
this.running.timer = setInterval(() => this.reportRunning(), 1e3);
|
|
356
|
+
this.running.timer.unref?.();
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
update: (force = false) => {
|
|
360
|
+
if (ended || !start) return;
|
|
361
|
+
const now = performance.now();
|
|
362
|
+
if (!force && now - lastUpdate < UPDATE_INTERVAL_MS) return;
|
|
363
|
+
lastUpdate = now;
|
|
364
|
+
this.each((t) => t.activityUpdate?.(info()));
|
|
365
|
+
this.reportRunning();
|
|
366
|
+
},
|
|
367
|
+
setStatus: (s) => {
|
|
368
|
+
status = s;
|
|
369
|
+
state.update(true);
|
|
370
|
+
},
|
|
371
|
+
add: (n) => {
|
|
372
|
+
current += n;
|
|
373
|
+
state.update();
|
|
374
|
+
},
|
|
375
|
+
set: (n) => {
|
|
376
|
+
current = n;
|
|
377
|
+
state.update();
|
|
378
|
+
},
|
|
379
|
+
end: (outcome = "success") => {
|
|
380
|
+
if (ended) return;
|
|
381
|
+
if (!start) start = performance.now();
|
|
382
|
+
ended = true;
|
|
383
|
+
endElapsed = elapsed();
|
|
384
|
+
if (live.delete(running) && !live.size) {
|
|
385
|
+
clearInterval(this.running.timer);
|
|
386
|
+
this.running.timer = void 0;
|
|
387
|
+
}
|
|
388
|
+
this.writeActivityEnd(info(outcome));
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
return state;
|
|
392
|
+
}
|
|
393
|
+
nextActivityId() {
|
|
394
|
+
return `${isMainThread ? "" : `t${threadId}-`}${++this.activityCounter}`;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Reports the parts of an ended activity whose times were measured elsewhere, e.g. the phases of
|
|
398
|
+
* a pipelined step in worker threads. Each part is an activity end event with `parentId`, its
|
|
399
|
+
* `share` of the parent's time, its `span` on the parent's timeline and `lastPart` set (the
|
|
400
|
+
* console transport prints the parts as a tree below their parent, each with its bar).
|
|
401
|
+
*/
|
|
402
|
+
activityParts(parent, parts) {
|
|
403
|
+
const activity = this.activities.get(parent);
|
|
404
|
+
const parentId = activity?.id;
|
|
405
|
+
const parentElapsed = activity?.elapsed() ?? 0;
|
|
406
|
+
let previousEnd = 0;
|
|
407
|
+
parts.forEach((part, i) => {
|
|
408
|
+
const start = part.offset ?? previousEnd;
|
|
409
|
+
previousEnd = start + part.elapsed;
|
|
410
|
+
const progress = part.current !== void 0 || part.total !== void 0;
|
|
411
|
+
this.writeActivityEnd({
|
|
412
|
+
id: this.nextActivityId(),
|
|
413
|
+
text: part.text,
|
|
414
|
+
type: progress ? "progress" : "spinner",
|
|
415
|
+
status: part.status || void 0,
|
|
416
|
+
...progress ? {
|
|
417
|
+
current: part.current ?? 0,
|
|
418
|
+
total: part.total ?? 0
|
|
419
|
+
} : {},
|
|
420
|
+
elapsed: part.elapsed,
|
|
421
|
+
outcome: "success",
|
|
422
|
+
...parentId ? { parentId } : {},
|
|
423
|
+
...parentElapsed > 0 ? {
|
|
424
|
+
share: Math.min(1, part.elapsed / parentElapsed),
|
|
425
|
+
span: [Math.min(1, start / parentElapsed), Math.min(1, previousEnd / parentElapsed)]
|
|
426
|
+
} : {},
|
|
427
|
+
...i === parts.length - 1 ? { lastPart: true } : {}
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
/** Ends an activity with the given outcome (trackers only end successfully, or with a panic). */
|
|
432
|
+
endActivity(tracker, outcome) {
|
|
433
|
+
this.activities.get(tracker)?.end(outcome);
|
|
434
|
+
}
|
|
435
|
+
activityTimer(text, _activityArgs = {}, _pluginName) {
|
|
436
|
+
return this.createTimer(text, false);
|
|
437
|
+
}
|
|
438
|
+
createTimer(text, hidden) {
|
|
439
|
+
const activity = this.createActivity(text, "spinner", void 0, void 0, hidden);
|
|
440
|
+
const tracker = {
|
|
441
|
+
span: new Span(),
|
|
442
|
+
start: () => activity.start(),
|
|
443
|
+
end: () => activity.end(),
|
|
444
|
+
done: () => activity.end(),
|
|
445
|
+
setStatus: (s) => activity.setStatus(s),
|
|
446
|
+
panic: (meta, err) => {
|
|
447
|
+
activity.end("failed");
|
|
448
|
+
return this.panic(meta, err);
|
|
449
|
+
},
|
|
450
|
+
panicOnBuild: (meta, err) => {
|
|
451
|
+
if (this.isBuild) activity.end("failed");
|
|
452
|
+
this.panicOnBuild(meta, err);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
this.activities.set(tracker, activity);
|
|
456
|
+
return tracker;
|
|
457
|
+
}
|
|
458
|
+
phantomActivity(text, _activityArgs = {}) {
|
|
459
|
+
return {
|
|
460
|
+
...this.createTimer(text, true),
|
|
461
|
+
end: () => {},
|
|
462
|
+
done: () => {}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
createProgress(text, total = 0, startCount = 0, _activityArgs = {}) {
|
|
466
|
+
const activity = this.createActivity(text, "progress", total, startCount);
|
|
467
|
+
const tracker = {
|
|
468
|
+
span: new Span(),
|
|
469
|
+
get total() {
|
|
470
|
+
return activity.total;
|
|
471
|
+
},
|
|
472
|
+
set total(value) {
|
|
473
|
+
activity.total = value;
|
|
474
|
+
},
|
|
475
|
+
start: () => activity.start(),
|
|
476
|
+
tick: (inc = 1) => activity.add(inc),
|
|
477
|
+
updateProgress: (v) => activity.set(v),
|
|
478
|
+
setStatus: (s) => activity.setStatus(s),
|
|
479
|
+
end: () => activity.end(),
|
|
480
|
+
done: () => activity.end(),
|
|
481
|
+
panic: (meta, err) => {
|
|
482
|
+
activity.end("failed");
|
|
483
|
+
return this.panic(meta, err);
|
|
484
|
+
},
|
|
485
|
+
panicOnBuild: (meta, err) => {
|
|
486
|
+
if (this.isBuild) activity.end("failed");
|
|
487
|
+
this.panicOnBuild(meta, err);
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
this.activities.set(tracker, activity);
|
|
491
|
+
return tracker;
|
|
492
|
+
}
|
|
493
|
+
pendingActivity() {}
|
|
494
|
+
completeActivity() {}
|
|
495
|
+
};
|
|
496
|
+
const reporter = new Reporter();
|
|
497
|
+
export { PanicError, REPORTER_BRIDGE_ENV, reporter as default, reporter, noopTracer };
|