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.
Files changed (161) hide show
  1. package/README.md +874 -1
  2. package/bin/goatly.js +99 -0
  3. package/dist/cli/index.js +234 -0
  4. package/dist/compat/gatsby-node-entry.js +16 -0
  5. package/dist/compat/gatsby-package.json +6 -0
  6. package/dist/compat/md5-file.js +47 -0
  7. package/dist/compat-apis.json +72 -0
  8. package/dist/compat-apis.json.js +62 -0
  9. package/dist/graphql.js +3 -0
  10. package/dist/node/actions/index.js +619 -0
  11. package/dist/node/actions/job-store.js +180 -0
  12. package/dist/node/actions/jobs.js +174 -0
  13. package/dist/node/api-runner.js +258 -0
  14. package/dist/node/bootstrap.js +569 -0
  15. package/dist/node/build/assets.js +110 -0
  16. package/dist/node/build/incremental.js +208 -0
  17. package/dist/node/build/index.js +763 -0
  18. package/dist/node/build/memory-governor.js +450 -0
  19. package/dist/node/build/output-dirs.js +70 -0
  20. package/dist/node/build/page-data.js +40 -0
  21. package/dist/node/build/page-files.js +186 -0
  22. package/dist/node/build/partitioned-state.js +258 -0
  23. package/dist/node/build/query-worker.js +626 -0
  24. package/dist/node/build/query-workers.js +863 -0
  25. package/dist/node/build/render-thread.js +103 -0
  26. package/dist/node/build/render-worker.js +162 -0
  27. package/dist/node/build/state.js +24 -0
  28. package/dist/node/build/timing-breakdown.js +216 -0
  29. package/dist/node/build/work-clock.js +75 -0
  30. package/dist/node/build/worker-pool.js +242 -0
  31. package/dist/node/cache-layout.js +99 -0
  32. package/dist/node/cache.js +1430 -0
  33. package/dist/node/compat/chokidar-shim.js +148 -0
  34. package/dist/node/compat/core-utils-lmdb.js +145 -0
  35. package/dist/node/compat/create-node-id-shim.js +1 -0
  36. package/dist/node/compat/module-hooks.js +245 -0
  37. package/dist/node/compat/redux-shim.js +1 -0
  38. package/dist/node/config/index.js +162 -0
  39. package/dist/node/config/not-found-pages.js +95 -0
  40. package/dist/node/datastore/codec.js +144 -0
  41. package/dist/node/datastore/index.js +127 -0
  42. package/dist/node/datastore/logfile/cache.js +89 -0
  43. package/dist/node/datastore/logfile/index.js +1329 -0
  44. package/dist/node/datastore/logfile/record.js +71 -0
  45. package/dist/node/datastore/types.js +1 -0
  46. package/dist/node/develop/express-compat.js +207 -0
  47. package/dist/node/develop/graphiql.js +22 -0
  48. package/dist/node/develop/hydration-report.js +41 -0
  49. package/dist/node/develop/index.js +618 -0
  50. package/dist/node/develop/local-url.js +10 -0
  51. package/dist/node/develop/ssr-runner.js +66 -0
  52. package/dist/node/gql.js +5 -0
  53. package/dist/node/index.js +15 -0
  54. package/dist/node/info.js +270 -0
  55. package/dist/node/internal-plugins/data-bridge.js +196 -0
  56. package/dist/node/internal-plugins/page-creator.js +318 -0
  57. package/dist/node/loader/import-module.js +160 -0
  58. package/dist/node/node-helpers.js +66 -0
  59. package/dist/node/not-found-pages.js +220 -0
  60. package/dist/node/plugins/api-list.js +12 -0
  61. package/dist/node/plugins/load-plugins.js +427 -0
  62. package/dist/node/plugins/resolve-plugin.js +79 -0
  63. package/dist/node/plugins/static-exports.js +64 -0
  64. package/dist/node/query/compile.js +326 -0
  65. package/dist/node/query/dependencies.js +45 -0
  66. package/dist/node/query/execute.js +417 -0
  67. package/dist/node/query/extract.js +372 -0
  68. package/dist/node/query/gql-tada-introspection.js +124 -0
  69. package/dist/node/query/graphql-env.js +231 -0
  70. package/dist/node/query/graphql-runner.js +79 -0
  71. package/dist/node/redux/actions.js +1 -0
  72. package/dist/node/redux/index.js +133 -0
  73. package/dist/node/redux/node-changes.js +128 -0
  74. package/dist/node/redux/reducers.js +193 -0
  75. package/dist/node/redux/state.js +71 -0
  76. package/dist/node/renderer.js +124 -0
  77. package/dist/node/reporter-transports.js +259 -0
  78. package/dist/node/reporter.js +497 -0
  79. package/dist/node/schema/date.js +539 -0
  80. package/dist/node/schema/extensions.js +315 -0
  81. package/dist/node/schema/index.js +542 -0
  82. package/dist/node/schema/infer.js +388 -0
  83. package/dist/node/schema/inline-objects.js +128 -0
  84. package/dist/node/schema/naming.js +20 -0
  85. package/dist/node/schema/node-model.js +207 -0
  86. package/dist/node/schema/query-engine.js +1808 -0
  87. package/dist/node/schema/resolver-kinds.js +7 -0
  88. package/dist/node/schema/resolvers.js +273 -0
  89. package/dist/node/schema/type-builders.js +45 -0
  90. package/dist/node/schema/types.js +241 -0
  91. package/dist/node/serve.js +90 -0
  92. package/dist/node/site-page-nodes.js +277 -0
  93. package/dist/node/types.js +1 -0
  94. package/dist/node/utils/content-digest.js +107 -0
  95. package/dist/node/utils/cpus.js +104 -0
  96. package/dist/node/utils/create-node-id.js +51 -0
  97. package/dist/node/utils/env.js +25 -0
  98. package/dist/node/utils/fs-retry.js +74 -0
  99. package/dist/node/utils/memory-signals.js +441 -0
  100. package/dist/node/utils/memory.js +657 -0
  101. package/dist/node/utils/murmurhash.js +32 -0
  102. package/dist/node/utils/parser.js +33 -0
  103. package/dist/node/utils/partition-hash.js +19 -0
  104. package/dist/node/utils/paths.js +122 -0
  105. package/dist/node/utils/resolver.js +48 -0
  106. package/dist/node/utils/runtime.js +5 -0
  107. package/dist/node/utils/serializable.js +41 -0
  108. package/dist/node/utils/strings.js +41 -0
  109. package/dist/node/vite/config.js +289 -0
  110. package/dist/node/vite/paths.js +12 -0
  111. package/dist/node/vite/plugin-deps.js +232 -0
  112. package/dist/node/vite/plugin.js +283 -0
  113. package/dist/node/vite/react-compiler.js +362 -0
  114. package/dist/node/vite/source-files.js +83 -0
  115. package/dist/node/vite/static-image.js +136 -0
  116. package/dist/node/vite/styled-components.js +73 -0
  117. package/dist/node/vite/transforms.js +330 -0
  118. package/dist/node/wasm-data/host.js +406 -0
  119. package/dist/node/wasm-data/lower.js +406 -0
  120. package/dist/node/wasm-data/runner.js +79 -0
  121. package/dist/node/wasm-data/worker.js +95 -0
  122. package/dist/reporter.js +5 -0
  123. package/dist/runtime/api-runner.js +81 -0
  124. package/dist/runtime/app.js +256 -0
  125. package/dist/runtime/client-entry.js +4 -0
  126. package/dist/runtime/client.js +383 -0
  127. package/dist/runtime/default-html.js +31 -0
  128. package/dist/runtime/head-markup.js +100 -0
  129. package/dist/runtime/head-sync.js +101 -0
  130. package/dist/runtime/head-tags.js +45 -0
  131. package/dist/runtime/hydration-report.js +111 -0
  132. package/dist/runtime/index.js +12 -0
  133. package/dist/runtime/link.js +293 -0
  134. package/dist/runtime/loader.js +449 -0
  135. package/dist/runtime/not-found.js +61 -0
  136. package/dist/runtime/page-renderer.js +35 -0
  137. package/dist/runtime/preamble.js +47 -0
  138. package/dist/runtime/react-compat.js +14 -0
  139. package/dist/runtime/renderer-shared.js +10 -0
  140. package/dist/runtime/renderers/react-client.js +14 -0
  141. package/dist/runtime/renderers/react-server.js +99 -0
  142. package/dist/runtime/renderers/react.js +17 -0
  143. package/dist/runtime/renderers/types.js +1 -0
  144. package/dist/runtime/root-error-handlers.js +29 -0
  145. package/dist/runtime/router/history.js +132 -0
  146. package/dist/runtime/router/index.js +240 -0
  147. package/dist/runtime/router/utils.js +118 -0
  148. package/dist/runtime/script.js +110 -0
  149. package/dist/runtime/scroll.js +40 -0
  150. package/dist/runtime/slice.js +11 -0
  151. package/dist/runtime/ssr.js +240 -0
  152. package/dist/runtime/static-query.js +47 -0
  153. package/dist/utils.js +4 -0
  154. package/package.json +105 -3
  155. package/types/graphql-tada.d.ts +223 -0
  156. package/types/graphql.d.ts +2 -0
  157. package/types/index.d.ts +2287 -0
  158. package/types/node.d.ts +389 -0
  159. package/types/reporter.d.ts +187 -0
  160. package/types/router.d.ts +102 -0
  161. package/types/vendor/gql-tada.d.ts +2529 -0
@@ -0,0 +1,389 @@
1
+ import type { DataStore, GatsbyConfig, Node, Page } from "./index.js"
2
+ export type { DataStore, Node }
3
+
4
+ export interface BuildOptions {
5
+ directory: string
6
+ prefixPaths?: boolean
7
+ verbose?: boolean
8
+ /** reporter transports (override `reporter` in gatsby-config) */
9
+ reporter?:
10
+ | import("./reporter.js").ReporterTransport
11
+ | Array<import("./reporter.js").ReporterTransport>
12
+ }
13
+ export interface BuildResult {
14
+ pages: number
15
+ /** page queries that ran (the others were unchanged – incremental query running) */
16
+ queries: number
17
+ rendered: number
18
+ skipped: number
19
+ parallelQueries: boolean
20
+ timings: Record<string, number>
21
+ /**
22
+ * wall-clock milliseconds of the predefined build segments (they add up to `timings.total`):
23
+ * the bootstrap's phases (config, cache, preBootstrap, schemaCustomization, sourcing, schema,
24
+ * createPages, extractQueries, postBootstrap), staticQueries, queryWorkers, pageQueries, bundle (time waited for it), render,
25
+ * postBuild, finalize
26
+ */
27
+ breakdown: Record<
28
+ | "config"
29
+ | "cache"
30
+ | "preBootstrap"
31
+ | "schemaCustomization"
32
+ | "sourcing"
33
+ | "schema"
34
+ | "createPages"
35
+ | "extractQueries"
36
+ | "postBootstrap"
37
+ | "staticQueries"
38
+ | "queryWorkers"
39
+ | "pageQueries"
40
+ | "bundle"
41
+ | "render"
42
+ | "postBuild"
43
+ | "finalize",
44
+ number
45
+ >
46
+ }
47
+ export declare function build(options: BuildOptions): Promise<BuildResult>
48
+
49
+ export interface DevelopOptions {
50
+ directory: string
51
+ host?: string
52
+ port?: number
53
+ verbose?: boolean
54
+ open?: boolean
55
+ prefixPaths?: boolean
56
+ /** reporter transports (override `reporter` in gatsby-config) */
57
+ reporter?:
58
+ | import("./reporter.js").ReporterTransport
59
+ | Array<import("./reporter.js").ReporterTransport>
60
+ }
61
+ export declare function develop(
62
+ options: DevelopOptions,
63
+ ): Promise<{ port: number; close(): Promise<void> }>
64
+ export declare function serve(options: {
65
+ directory: string
66
+ host: string
67
+ port: number
68
+ prefixPaths?: boolean
69
+ open?: boolean
70
+ }): Promise<unknown>
71
+
72
+ export interface LogFileDataStoreOptions {
73
+ /** directory of the segment and index files (default: `<cacheDir>/data/logfile`) */
74
+ dir?: string
75
+ /** decoded nodes kept in memory per thread (default: 10,000; 2,000 in query workers) */
76
+ cacheSize?: number
77
+ /**
78
+ * about the most bytes of nodes kept decoded per thread, counted as their encoded size (default:
79
+ * 256 MB; 64 MB in query workers): with large nodes (e.g. rich text) `cacheSize` nodes could take
80
+ * gigabytes per thread
81
+ */
82
+ cacheBytes?: number
83
+ }
84
+ /**
85
+ * The default datastore: nodes are msgpack-encoded and appended to segment files in `.cache`, read
86
+ * back with positional reads (through the OS page cache, outside the process's memory), with a
87
+ * compact index per thread. Query workers read the same files. Each run writes new segment files
88
+ * and index log files; files of earlier builds are never modified, so a layer diff of `.cache`
89
+ * holds only what changed.
90
+ */
91
+ export declare class LogFileDataStore implements DataStore {
92
+ constructor(
93
+ options?: LogFileDataStoreOptions & {
94
+ cacheDir?: string
95
+ /**
96
+ * Open the store without changing its files (inspection tools): load() restores the persisted
97
+ * state without removing unread index log files or unlisted segments, writes throw, persist()
98
+ * and close() write nothing, and a missing directory is not created. Query workers are always
99
+ * read-only. Experimental (not covered by semver).
100
+ */
101
+ readonly?: boolean
102
+ },
103
+ )
104
+ readonly name: "logfile"
105
+ readonly sharedAcrossThreads: true
106
+ readonly lazy: true
107
+ getNode(id: string): Node | undefined
108
+ getNodesByIds(ids: readonly string[], options?: { cache?: boolean }): Array<Node | undefined>
109
+ getNodeIdsByType(typeName: string): string[]
110
+ getNodeType(id: string): string | undefined
111
+ getNodeParent(id: string): string | null | undefined
112
+ getMaxNodeCounter(): number
113
+ getNodeDigest(id: string): string | undefined
114
+ getTypes(): string[]
115
+ countNodes(typeName?: string): number
116
+ getNodes(): Node[]
117
+ getNodesByType(typeName: string): Node[]
118
+ iterateNodes(): Iterable<Node>
119
+ iterateNodesByType(typeName: string): Iterable<Node>
120
+ setNode(node: Node, oldNode?: Node): void
121
+ deleteNode(node: Node): void
122
+ ready(): Promise<void>
123
+ trimCache(): void
124
+ clear(): void
125
+ load(): Promise<boolean>
126
+ persist(): Promise<void>
127
+ close(): void
128
+ /**
129
+ * A read-only view of the store's internal state, for inspection tools (e.g. a devtools panel).
130
+ * Experimental: not covered by semver. Reading it changes nothing: it does not flush, encode or
131
+ * use the node cache (`value()` reads a node without keeping it).
132
+ */
133
+ inspect(): LogFileInspection
134
+ }
135
+ /** A record header in the logfile store's segment files (see `LogFileDataStore.inspect()`) */
136
+ export interface LogFileRecordHeader {
137
+ dataLength: number
138
+ typeIndex: number
139
+ idLength: number
140
+ parentLength: number
141
+ digestLength: number
142
+ }
143
+ /** see `LogFileDataStore.inspect()` */
144
+ export interface LogFileRecordInfo {
145
+ /**
146
+ * offset of the node's latest record (in the virtual address space of the segments); null: not
147
+ * written yet (pending)
148
+ */
149
+ offset: number | null
150
+ /** index into `types` of the record (or of the pending write) */
151
+ typeIndex: number | null
152
+ /**
153
+ * the file that holds the record (`segment-<id>`) and where in it; null: not written, or outside
154
+ * the files the index lists
155
+ */
156
+ file: string | null
157
+ fileOffset: number | null
158
+ /** record size in bytes, header included; null: not written, or not readable */
159
+ size: number | null
160
+ header: LogFileRecordHeader | null
161
+ /** a newer version of the node waits in memory (not in a segment yet) */
162
+ pending: boolean
163
+ }
164
+ /** see `LogFileDataStore.inspect()`: a segment file */
165
+ export interface LogFileSegmentInfo {
166
+ /** the file is `segment-<id>` */
167
+ id: string
168
+ /** its first offset in the virtual address space */
169
+ base: number
170
+ /** bytes of it the persisted index covers (the segment this run appends to: bytes written) */
171
+ length: number
172
+ /** bytes of the file (a run that did not persist may have written more than `length`) */
173
+ size: number
174
+ /** bytes of live records */
175
+ live: number
176
+ /** this run appends to it */
177
+ current: boolean
178
+ }
179
+ /** Experimental (not covered by semver): see `LogFileDataStore.inspect()` */
180
+ export interface LogFileInspection {
181
+ dir: string
182
+ readonly: boolean
183
+ /** the on-disk format version this store reads (an index of another version is not restored) */
184
+ formatVersion: number
185
+ /**
186
+ * changes whenever the store's data or files change (writes, flushes, persist, load, compaction,
187
+ * new record structures); not when reads fill or use the node cache
188
+ */
189
+ version: number
190
+ /** the persisted index snapshot */
191
+ snapshotId: string | null
192
+ /** bytes of the segment files */
193
+ fileEnd: number
194
+ /**
195
+ * bytes of superseded and deleted records in the segments, and the bytes of segments past what
196
+ * the index covers
197
+ */
198
+ garbage: number
199
+ /** the segments by base */
200
+ segments: LogFileSegmentInfo[]
201
+ /** writes buffered in memory, not in a segment yet */
202
+ pendingWrites: number
203
+ /** ids set or deleted since the last persist() */
204
+ changed: number
205
+ /** changed since the last persist() or load() */
206
+ dirty: boolean
207
+ /** entries in the index log files after the last snapshot */
208
+ logEntries: number
209
+ /**
210
+ * the index log files of the snapshot that were replayed or written
211
+ * (`index-log-000001-<snapshotId>` up to this number; later ones are not read)
212
+ */
213
+ logFiles: number
214
+ /** msgpackr shared record structures */
215
+ structures: number
216
+ /** the type table: `typeIndex` of records and addresses indexes it */
217
+ types: string[]
218
+ /** the node cache when inspect() was called (reads change `size` without changing `version`) */
219
+ cache: { size: number; max: number }
220
+ /** all node ids in insertion order (a live iterator: consume it before the store changes) */
221
+ ids(): IterableIterator<string>
222
+ record(id: string): LogFileRecordInfo | undefined
223
+ /**
224
+ * The node's latest value, read without changing the store: no encode, no cache fill, nothing
225
+ * kept. Can be the store's own objects: a cached or pending node, or the working copy of
226
+ * `getNodeForUpdate()` (what the next flush encodes): read only, do not modify.
227
+ */
228
+ value(id: string): Node | undefined
229
+ }
230
+ /**
231
+ * `api` of the `goatly` Vite plugin (in develop and build): other Vite plugins of the same
232
+ * server reach the running instance through it, e.g.
233
+ * `config.plugins.find((p) => p.name === "goatly")?.api`.
234
+ */
235
+ export interface GoatlyVitePluginApi {
236
+ /** increases when a member is added */
237
+ apiVersion: 1
238
+ /** the datastore of this process (the configured one once bootstrap ran) */
239
+ getDataStore(): DataStore
240
+ }
241
+ /** The logfile datastore (the default) with options: `datastore: logFileDataStore({ cacheSize })` */
242
+ export declare function logFileDataStore(
243
+ options?: LogFileDataStoreOptions,
244
+ ): (ctx: { cacheDir: string }) => LogFileDataStore
245
+ export declare function createContentDigest(input: string | object): string
246
+ export declare function createNodeId(id: string, namespace?: string): string
247
+ /** Identity helper for typed gatsby-config files */
248
+ export declare function defineConfig<T extends GatsbyConfig>(config: T): T
249
+ export type { Page }
250
+
251
+ // ---- renderers (gatsby-config `renderer`) – experimental, the interface may change ------------
252
+
253
+ export type { RendererDescriptor } from "./index.js"
254
+
255
+ /** The default export of a renderer module (`RendererDescriptor.module`). */
256
+ export type RendererFactory = (
257
+ options: any,
258
+ context: RendererContext,
259
+ ) => Renderer | Promise<Renderer>
260
+
261
+ export interface RendererContext {
262
+ /** the site directory */
263
+ root: string
264
+ /** goatly's reporter; the methods can be called detached */
265
+ reporter: {
266
+ info(message: string): void
267
+ warn(message: string): void
268
+ error(message: string, error?: unknown): void
269
+ verbose(message: string): void
270
+ }
271
+ }
272
+
273
+ export interface Renderer {
274
+ name: string
275
+ /** Absolute paths of the runtime modules: `RendererShared`, `RendererServer`, `RendererClient`. */
276
+ runtime: { shared: string; server: string; client: string }
277
+ /** Additions to the Vite config of every stage. */
278
+ vite?(context: RendererViteContext): RendererViteConfig | Promise<RendererViteConfig>
279
+ /** For modules Node (or Bun) loads itself: gatsby-node files, externals of the SSR bundle. */
280
+ nodeHooks?: RendererNodeHooks
281
+ /** Changes whenever the HTML can change while the bundles stay the same (part of the HTML cache key). */
282
+ cacheKey?: string
283
+ }
284
+
285
+ export interface RendererViteContext {
286
+ stage: "develop" | "develop-html" | "build-javascript" | "build-html"
287
+ isBuild: boolean
288
+ root: string
289
+ }
290
+
291
+ export interface RendererViteConfig {
292
+ /** Added after goatly's own plugins. */
293
+ plugins?: any[]
294
+ /** Packages that must resolve to one copy (`resolve.dedupe`). */
295
+ dedupe?: string[]
296
+ /** Specifiers the SSR bundle of a build leaves to the runtime (`ssr.external`). */
297
+ ssrExternal?: string[]
298
+ /** Bare specifiers the renderer provides: `onCreateWebpackConfig` aliases for them are ignored. */
299
+ ownedSpecifiers?: string[]
300
+ }
301
+
302
+ export interface RendererNodeHooks {
303
+ /** Maps a bare specifier to an absolute file, or returns undefined to leave it alone. */
304
+ resolve?(specifier: string): string | undefined
305
+ /** The bare specifiers `resolve` maps (needed on Bun, which has no resolve hook for ESM imports). */
306
+ specifiers?: string[]
307
+ /**
308
+ * Rewrites the source of the files matching `filter` (on Node tested against the absolute path
309
+ * with forward slashes, on Bun it is the `onLoad` filter). `undefined` leaves a file unchanged.
310
+ */
311
+ load?: { filter: RegExp; transform(file: string, code: string): string | undefined }
312
+ }
313
+
314
+ /** How the page's `Head` export gets into `<head>` (see the built-in renderer). */
315
+ export type HeadMode = "hoist" | "portal"
316
+
317
+ /**
318
+ * The runtime modules (`runtime.shared`, `runtime.server`, `runtime.client`) are bundled by Vite.
319
+ * They can import core's runtime as `goatly/runtime/<module>` or `gatsby/runtime/<module>`
320
+ * (an alias, whatever name the site installed goatly under).
321
+ */
322
+
323
+ /** Exports of `runtime.shared` (bundled into the browser and the SSR bundle). */
324
+ export interface RendererShared {
325
+ headMode: HeadMode
326
+ /**
327
+ * Portal head mode: the text of a `<script>`/`<style>` of the `Head` export as the renderer's
328
+ * server writes it; the browser head sync compares the client's text in this form. Default:
329
+ * `</script` / `</style` escaped.
330
+ */
331
+ escapeRawText?: (text: string, tag: "script" | "style") => string
332
+ }
333
+
334
+ export interface RenderedMarkup {
335
+ html: string
336
+ /**
337
+ * Markup the renderer hoisted out of `html`, for `<head>`. Written as it is, without
338
+ * `data-gatsby-head` markers: the browser head sync never touches it.
339
+ */
340
+ head: string
341
+ }
342
+
343
+ /** Exports of `runtime.server`. */
344
+ export interface RendererServer {
345
+ renderBody(
346
+ element: import("react").ReactNode,
347
+ options: { ignoreError(error: unknown): boolean },
348
+ ): Promise<RenderedMarkup>
349
+ splitBody(html: string): RenderedMarkup
350
+ /**
351
+ * Portal head mode: the `Head` export. Core marks the head elements of `html` with
352
+ * `data-gatsby-head` (the head sync replaces them on navigation); `head` is for what the renderer
353
+ * keeps in `<head>` itself, e.g. stylesheets with a precedence.
354
+ */
355
+ renderHead(element: import("react").ReactElement): RenderedMarkup
356
+ /**
357
+ * The document (`html.js`) as static markup. `element.props.body` is the page markup, which must
358
+ * appear in the output unchanged; the head placeholders core puts into `headComponents` must keep
359
+ * their exact markup. The result may start with a doctype.
360
+ */
361
+ renderDocument(element: import("react").ReactElement): string
362
+ }
363
+
364
+ /** React 19's `onCaughtError` / `onUncaughtError` root option (`errorBoundary`: caught errors only). */
365
+ export type RootErrorHandler = (
366
+ error: unknown,
367
+ errorInfo: { componentStack?: string | null; errorBoundary?: unknown },
368
+ ) => void
369
+
370
+ /** Exports of `runtime.client`. */
371
+ export interface RendererClient {
372
+ mount(
373
+ element: import("react").ReactElement,
374
+ container: Element,
375
+ options: {
376
+ /** `kind: "warning"` shows the issue as a warning in the develop hydration report */
377
+ onRecoverableError(
378
+ error: unknown,
379
+ info?: { componentStack?: string; kind?: "error" | "warning" },
380
+ ): void
381
+ /**
382
+ * Root options for the `onCaughtError` / `onUncaughtError` browser APIs (hydration and an
383
+ * empty container). `undefined` when no plugin implements the API: keep the default reporting.
384
+ */
385
+ onCaughtError?: RootErrorHandler
386
+ onUncaughtError?: RootErrorHandler
387
+ },
388
+ ): void
389
+ }
@@ -0,0 +1,187 @@
1
+ export interface ActivityTracker {
2
+ start(): void
3
+ end(): void
4
+ done(): void
5
+ span: Record<string, unknown>
6
+ setStatus(status: string): void
7
+ panic(errorMeta: string | object, error?: object): never
8
+ panicOnBuild(errorMeta: string | object, error?: object): void
9
+ }
10
+
11
+ export interface ProgressActivityTracker extends ActivityTracker {
12
+ tick(increment?: number): void
13
+ total: number
14
+ }
15
+
16
+ export interface ActivityArgs {
17
+ parentSpan?: object
18
+ id?: string
19
+ tags?: Record<string, unknown>
20
+ }
21
+
22
+ export interface Reporter {
23
+ stripIndent(strings: TemplateStringsArray | string, ...values: unknown[]): string
24
+ format: Record<string, (text: string) => string>
25
+ setVerbose(isVerbose?: boolean): void
26
+ setNoColor(noColor?: boolean): void
27
+ setErrorMap(
28
+ map: Record<
29
+ string,
30
+ { text: (context: any) => string; level?: string; type?: string; category?: string }
31
+ >,
32
+ ): void
33
+ panic(errorMeta: unknown, error?: unknown): never
34
+ panicOnBuild(errorMeta: unknown, error?: unknown): void
35
+ error(errorMeta: unknown, error?: unknown): void
36
+ uptime(prefix: string): void
37
+ verbose(text: string): void
38
+ success(text: string): void
39
+ info(text: string): void
40
+ warn(text: string): void
41
+ log(text?: string): void
42
+ /** a line with the breakdown of its time below it: a Gantt chart of the segments */
43
+ timingBreakdown(title: string, segments: TimingSegment[], level?: "info" | "success"): void
44
+ activityTimer(text: string, activityArgs?: ActivityArgs, pluginName?: string): ActivityTracker
45
+ phantomActivity(text: string, activityArgs?: ActivityArgs): ActivityTracker
46
+ createProgress(
47
+ text: string,
48
+ total?: number,
49
+ start?: number,
50
+ activityArgs?: ActivityArgs,
51
+ ): ProgressActivityTracker
52
+ }
53
+
54
+ export type LogLevel = "error" | "warn" | "info" | "success" | "verbose" | "log"
55
+
56
+ /** Gatsby structured error details (see `reporter.error(errorMeta, error)`) */
57
+ export interface LogEntryError {
58
+ id?: string
59
+ category?: string
60
+ type?: string
61
+ level?: string
62
+ context?: Record<string, unknown>
63
+ filePath?: string
64
+ location?: unknown
65
+ pluginName?: string
66
+ message?: string
67
+ stack?: string
68
+ name?: string
69
+ }
70
+
71
+ export interface ActivityInfo {
72
+ id: string
73
+ text: string
74
+ type: "spinner" | "progress"
75
+ status?: string
76
+ current?: number
77
+ total?: number
78
+ /** seconds since the activity started */
79
+ elapsed: number
80
+ outcome?: "success" | "failed"
81
+ /**
82
+ * the activity this one is a part of: a breakdown of the parent's time, reported after the parent
83
+ * ended (e.g. page queries and HTML rendering of the pipelined worker step)
84
+ */
85
+ parentId?: string
86
+ /** parts: the fraction of the parent's time (0–1) */
87
+ share?: number
88
+ /** parts: the last part of the parent */
89
+ lastPart?: boolean
90
+ }
91
+
92
+ export interface LogEntry {
93
+ level: LogLevel
94
+ /** the message without ANSI colors */
95
+ text: string
96
+ /** milliseconds since the epoch */
97
+ timestamp: number
98
+ error?: LogEntryError
99
+ /** success lines of finished activities */
100
+ activity?: ActivityInfo
101
+ /** worker thread id for entries logged in a worker thread */
102
+ threadId?: number
103
+ /** timing breakdowns (e.g. at the end of a build): the segments of the total time, in order */
104
+ breakdown?: { title: string; segments: TimingSegment[] }
105
+ }
106
+
107
+ /** a segment of a timing breakdown */
108
+ export interface TimingSegment {
109
+ key: string
110
+ label: string
111
+ /** milliseconds */
112
+ ms: number
113
+ }
114
+
115
+ export interface TimingBreakdownFormatOptions {
116
+ /** characters of the timeline (default: 40) */
117
+ width?: number
118
+ /** default: no colors */
119
+ colors?: boolean
120
+ /** the line the breakdown belongs to (default: "timing breakdown") */
121
+ title?: string
122
+ }
123
+
124
+ /** Where reporter output goes. All methods but `log` are optional. */
125
+ export interface ReporterTransport {
126
+ log(entry: LogEntry): void
127
+ activityStart?(activity: ActivityInfo): void
128
+ activityUpdate?(activity: ActivityInfo): void
129
+ /** transports without it receive a `success` log entry with `activity` set */
130
+ activityEnd?(activity: ActivityInfo): void
131
+ flush?(): void | Promise<void>
132
+ }
133
+
134
+ export interface ConsoleTransportOptions {
135
+ stdout?: NodeJS.WritableStream
136
+ stderr?: NodeJS.WritableStream
137
+ colors?: boolean
138
+ silent?: boolean
139
+ }
140
+ export interface JsonTransportOptions {
141
+ stream?: NodeJS.WritableStream
142
+ activityEvents?: boolean
143
+ }
144
+ export interface LoggerLike {
145
+ error: (...args: any[]) => unknown
146
+ warn: (...args: any[]) => unknown
147
+ info: (...args: any[]) => unknown
148
+ debug?: (...args: any[]) => unknown
149
+ verbose?: (...args: any[]) => unknown
150
+ [key: string]: unknown
151
+ }
152
+ export interface LoggerTransportOptions {
153
+ /** `logger.info(message, meta)` (winston, consola, console) or `logger.info(meta, message)` (pino, bunyan); detected by default */
154
+ style?: "message-first" | "object-first"
155
+ verboseLevel?: string
156
+ successLevel?: string
157
+ activityStarts?: boolean
158
+ }
159
+
160
+ /** Gatsby style console output (the default) */
161
+ export declare function consoleTransport(options?: ConsoleTransportOptions): ReporterTransport
162
+ /** one JSON object per line */
163
+ export declare function jsonTransport(options?: JsonTransportOptions): ReporterTransport
164
+ /** all output to an existing logger: winston, pino, bunyan, consola, console, … */
165
+ export declare function loggerTransport(
166
+ logger: LoggerLike,
167
+ options?: LoggerTransportOptions,
168
+ ): ReporterTransport
169
+ export declare function activityEndText(activity: ActivityInfo): string
170
+ /** the segments as a Gantt chart: a row per segment with its time, share and bar on a timeline */
171
+ export declare function formatTimingBreakdown(
172
+ segments: TimingSegment[],
173
+ options?: TimingBreakdownFormatOptions,
174
+ ): string
175
+
176
+ export interface ReporterControl {
177
+ /** replaces the transports (overrides `reporter` in gatsby-config) */
178
+ setTransports(transports: ReporterTransport | ReporterTransport[]): void
179
+ addTransport(transport: ReporterTransport): void
180
+ getTransports(): ReporterTransport[]
181
+ /** resolves when asynchronous transports wrote their output */
182
+ flush(): Promise<void>
183
+ isVerbose: boolean
184
+ }
185
+
186
+ export declare const reporter: Reporter & ReporterControl
187
+ export default reporter
@@ -0,0 +1,102 @@
1
+ import type * as React from "react"
2
+
3
+ export interface HistoryLocation {
4
+ pathname: string
5
+ search: string
6
+ hash: string
7
+ href: string
8
+ origin: string
9
+ protocol: string
10
+ host: string
11
+ hostname: string
12
+ port: string
13
+ state: unknown
14
+ key: string
15
+ }
16
+ export type WindowLocation<S = unknown> = HistoryLocation & { state: S }
17
+ export interface NavigateOptions<TState = unknown> {
18
+ state?: TState
19
+ replace?: boolean
20
+ }
21
+ export type NavigateFn = (to: string | number, options?: NavigateOptions) => Promise<void>
22
+
23
+ export interface RouteComponentProps<TParams = {}> {
24
+ path?: string
25
+ default?: boolean
26
+ location?: WindowLocation
27
+ navigate?: NavigateFn
28
+ uri?: string
29
+ }
30
+
31
+ export declare function Router(
32
+ props: React.PropsWithChildren<{
33
+ basepath?: string
34
+ primary?: boolean
35
+ location?: WindowLocation
36
+ component?: any
37
+ [key: string]: unknown
38
+ }>,
39
+ ): React.ReactElement | null
40
+ export declare function Link<TState = unknown>(
41
+ props: React.AnchorHTMLAttributes<HTMLAnchorElement> & {
42
+ to: string
43
+ state?: TState
44
+ replace?: boolean
45
+ getProps?: (props: {
46
+ isCurrent: boolean
47
+ isPartiallyCurrent: boolean
48
+ href: string
49
+ location: WindowLocation
50
+ }) => object | undefined
51
+ innerRef?: React.Ref<HTMLAnchorElement>
52
+ },
53
+ ): React.ReactElement
54
+ export declare function Location(props: {
55
+ children: (ctx: { location: WindowLocation; navigate: NavigateFn }) => React.ReactNode
56
+ }): React.ReactElement
57
+ export declare function LocationProvider(
58
+ props: React.PropsWithChildren<{ history?: unknown }>,
59
+ ): React.ReactElement
60
+ export declare function ServerLocation(
61
+ props: React.PropsWithChildren<{ url: string }>,
62
+ ): React.ReactElement
63
+ export declare function Redirect(props: {
64
+ from?: string
65
+ to: string
66
+ noThrow?: boolean
67
+ state?: unknown
68
+ replace?: boolean
69
+ }): null
70
+ export declare function Match(props: {
71
+ path: string
72
+ children: (props: {
73
+ navigate: NavigateFn
74
+ location: WindowLocation
75
+ match: (Record<string, string> & { uri: string; path: string }) | null
76
+ }) => React.ReactNode
77
+ }): React.ReactElement
78
+ export declare const navigate: NavigateFn
79
+ export declare function useLocation(): WindowLocation
80
+ export declare function useNavigate(): NavigateFn
81
+ export declare function useParams(): Record<string, string> | null
82
+ export declare function useMatch(
83
+ path: string,
84
+ ): (Record<string, string> & { uri: string; path: string }) | null
85
+ export declare function isRedirect(o: unknown): boolean
86
+ export declare function redirectTo(to: string): never
87
+ export declare const globalHistory: {
88
+ location: WindowLocation
89
+ navigate: NavigateFn
90
+ listen(listener: (e: { location: WindowLocation; action: string }) => void): () => void
91
+ }
92
+ export declare function createHistory(source: unknown): typeof globalHistory
93
+ export declare function createMemorySource(initialPath?: string): unknown
94
+ export declare function match(
95
+ path: string,
96
+ uri: string,
97
+ ): { route: { path: string }; params: Record<string, string>; uri: string } | null
98
+ export declare const LocationContext: React.Context<{
99
+ location: WindowLocation
100
+ navigate: NavigateFn
101
+ }>
102
+ export declare const BaseContext: React.Context<{ baseuri: string; basepath: string }>