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,208 @@
|
|
|
1
|
+
import "../query/dependencies.js";
|
|
2
|
+
import { generatePageDataPath } from "../utils/paths.js";
|
|
3
|
+
import { readPageDataResult } from "./page-data.js";
|
|
4
|
+
import crypto from "node:crypto";
|
|
5
|
+
// src/node/build/incremental.ts
|
|
6
|
+
/**
|
|
7
|
+
* Incremental query running (like Gatsby's page dependency tracking): every page query records
|
|
8
|
+
* the nodes and node types it read. The next build only re-runs queries whose query/context
|
|
9
|
+
* changed or whose dependencies changed – the results of all other pages are taken from their
|
|
10
|
+
* existing `page-data.json` (needed only when their HTML has to be rendered again).
|
|
11
|
+
*/
|
|
12
|
+
const QUERY_STATE_VERSION = 1;
|
|
13
|
+
/** above this many node dependencies a page depends on the nodes' types instead (bounded state) */
|
|
14
|
+
const MAX_NODE_DEPENDENCIES = 200;
|
|
15
|
+
const sha1Hex = typeof crypto.hash === "function" ? (s) => crypto.hash("sha1", s) : (s) => crypto.createHash("sha1").update(s).digest("hex");
|
|
16
|
+
const hexCodes = Array.from({ length: 16 }, () => 0);
|
|
17
|
+
/** first 16 hex chars of the SHA-1 */
|
|
18
|
+
function hashString(s) {
|
|
19
|
+
const hex = sha1Hex(s);
|
|
20
|
+
for (let i = 0; i < 16; i++) hexCodes[i] = hex.charCodeAt(i);
|
|
21
|
+
return String.fromCharCode(...hexCodes);
|
|
22
|
+
}
|
|
23
|
+
function createQueryState(schemaHash, nodes, nodeCount) {
|
|
24
|
+
return {
|
|
25
|
+
version: 1,
|
|
26
|
+
schemaHash,
|
|
27
|
+
nodes,
|
|
28
|
+
nodeCount,
|
|
29
|
+
pages: {}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What a query can observe of a node: its content (contentDigest), fields added with
|
|
34
|
+
* `createNodeField` and the parent/children relations (which do not change the digest).
|
|
35
|
+
*/
|
|
36
|
+
function nodeDigest(node) {
|
|
37
|
+
return hashString(`${node.internal.contentDigest}|${node.parent ?? ""}|${(node.children ?? []).join(",")}|${node.fields === void 0 ? "" : JSON.stringify(node.fields)}`);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Applies the node changes of this run to the previous node digests (deleted nodes removed) – in
|
|
41
|
+
* place: for large sites copying the previous state cost more than the rest of this step. Returns
|
|
42
|
+
* the number of nodes afterwards (`count`: before). With `changed`, collects the nodes and types
|
|
43
|
+
* whose state differs from the previous one, exactly what comparing all nodes would find.
|
|
44
|
+
*/
|
|
45
|
+
function applyNodeChanges(states, count, changes, changed) {
|
|
46
|
+
for (const [id, state] of changes) {
|
|
47
|
+
const before = states[id];
|
|
48
|
+
if (state) {
|
|
49
|
+
if (!before) count++;
|
|
50
|
+
else if (before[0] === state[0] && before[1] === state[1]) continue;
|
|
51
|
+
else changed?.types.add(before[1]);
|
|
52
|
+
changed?.nodes.add(id);
|
|
53
|
+
changed?.types.add(state[1]);
|
|
54
|
+
states[id] = state;
|
|
55
|
+
} else if (before) {
|
|
56
|
+
count--;
|
|
57
|
+
changed?.nodes.add(id);
|
|
58
|
+
changed?.types.add(before[1]);
|
|
59
|
+
delete states[id];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return count;
|
|
63
|
+
}
|
|
64
|
+
function computeNodeStates(nodes) {
|
|
65
|
+
const states = Object.create(null);
|
|
66
|
+
for (const node of nodes) states[node.id] = [nodeDigest(node), node.internal.type];
|
|
67
|
+
return states;
|
|
68
|
+
}
|
|
69
|
+
/** adds the nodes (and their types before and after) whose state differs to `changed` */
|
|
70
|
+
function diffNodeStates(nodes, previous, changed) {
|
|
71
|
+
for (const id in nodes) {
|
|
72
|
+
const [digest, type] = nodes[id];
|
|
73
|
+
const before = previous[id];
|
|
74
|
+
if (before && before[0] === digest && before[1] === type) continue;
|
|
75
|
+
changed.nodes.add(id);
|
|
76
|
+
changed.types.add(type);
|
|
77
|
+
if (before) changed.types.add(before[1]);
|
|
78
|
+
}
|
|
79
|
+
for (const id in previous) {
|
|
80
|
+
if (nodes[id]) continue;
|
|
81
|
+
changed.nodes.add(id);
|
|
82
|
+
changed.types.add(previous[id][1]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The node digests of this build: the previous build's with the changes of this run applied (no
|
|
87
|
+
* pass over all nodes – for lazy datastores that would mean deserializing all of them). All nodes
|
|
88
|
+
* are read when there is nothing to start from or the result does not match the store's count.
|
|
89
|
+
*/
|
|
90
|
+
function currentNodeStates(options) {
|
|
91
|
+
const { base, restored, changes, store } = options;
|
|
92
|
+
let changed;
|
|
93
|
+
if (base) {
|
|
94
|
+
changed = {
|
|
95
|
+
nodes: /* @__PURE__ */ new Set(),
|
|
96
|
+
types: /* @__PURE__ */ new Set()
|
|
97
|
+
};
|
|
98
|
+
const before = base.nodeCount ?? Object.keys(base.nodes).length;
|
|
99
|
+
const count = applyNodeChanges(base.nodes, before, changes, changed);
|
|
100
|
+
if (count === store.countNodes()) return {
|
|
101
|
+
states: base.nodes,
|
|
102
|
+
count,
|
|
103
|
+
changed
|
|
104
|
+
};
|
|
105
|
+
} else if (!restored) {
|
|
106
|
+
const states = Object.create(null);
|
|
107
|
+
const count = applyNodeChanges(states, 0, changes);
|
|
108
|
+
if (count === store.countNodes()) return {
|
|
109
|
+
states,
|
|
110
|
+
count
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const states = computeNodeStates(store.iterateNodes());
|
|
114
|
+
if (base) diffNodeStates(states, base.nodes, changed);
|
|
115
|
+
return {
|
|
116
|
+
states,
|
|
117
|
+
count: Object.keys(states).length,
|
|
118
|
+
changed
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** JSON with the contents of Set/Map (GraphQL turns a Set variable into a list) */
|
|
122
|
+
function contextJson(context) {
|
|
123
|
+
return JSON.stringify(context ?? {}, (_key, value) => {
|
|
124
|
+
if (value instanceof Set) return { __set: [...value] };
|
|
125
|
+
if (value instanceof Map) return { __map: [...value.entries()] };
|
|
126
|
+
if (typeof value === "bigint") return `${value}n`;
|
|
127
|
+
return value;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/** Hash of everything besides data that determines a page's query result. */
|
|
131
|
+
function pageQueryHash(page, query) {
|
|
132
|
+
return hashString(`${query ?? ""}\0${page.path}\0${page.matchPath ?? ""}\0${page.componentPath}\0${contextJson(page.context)}`);
|
|
133
|
+
}
|
|
134
|
+
/** Page dependencies as stored in the query state (many node ids collapse to their types). */
|
|
135
|
+
function serializeDependencies(deps, typeOf) {
|
|
136
|
+
if (deps.nodes.size <= MAX_NODE_DEPENDENCIES) return {
|
|
137
|
+
n: [...deps.nodes].sort(),
|
|
138
|
+
c: [...deps.connections].sort()
|
|
139
|
+
};
|
|
140
|
+
const connections = new Set(deps.connections);
|
|
141
|
+
const missing = [];
|
|
142
|
+
for (const id of deps.nodes) {
|
|
143
|
+
const type = typeOf(id);
|
|
144
|
+
if (type) connections.add(type);
|
|
145
|
+
else missing.push(id);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
n: missing.sort(),
|
|
149
|
+
c: [...connections].sort()
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** Decides which page queries have to run again. */
|
|
153
|
+
function classifyPages(options) {
|
|
154
|
+
const { pages, componentQueries, previous, nodes, schemaHash } = options;
|
|
155
|
+
const queryHashes = /* @__PURE__ */ new Map();
|
|
156
|
+
for (const page of pages) queryHashes.set(page.path, pageQueryHash(page, componentQueries[page.componentPath]));
|
|
157
|
+
if (!previous) return {
|
|
158
|
+
dirty: pages,
|
|
159
|
+
clean: [],
|
|
160
|
+
queryHashes,
|
|
161
|
+
reason: "no cached query results"
|
|
162
|
+
};
|
|
163
|
+
if (previous.schemaHash !== schemaHash) return {
|
|
164
|
+
dirty: pages,
|
|
165
|
+
clean: [],
|
|
166
|
+
queryHashes,
|
|
167
|
+
reason: "the GraphQL schema changed"
|
|
168
|
+
};
|
|
169
|
+
let changed = options.changed;
|
|
170
|
+
if (!changed) {
|
|
171
|
+
changed = {
|
|
172
|
+
nodes: /* @__PURE__ */ new Set(),
|
|
173
|
+
types: /* @__PURE__ */ new Set()
|
|
174
|
+
};
|
|
175
|
+
diffNodeStates(nodes, previous.nodes, changed);
|
|
176
|
+
}
|
|
177
|
+
const { nodes: changedNodes, types: changedTypes } = changed;
|
|
178
|
+
const dirty = [];
|
|
179
|
+
const clean = [];
|
|
180
|
+
for (const page of pages) {
|
|
181
|
+
const before = previous.pages[page.path];
|
|
182
|
+
(!before || before.q !== queryHashes.get(page.path) || before.n.some((id) => changedNodes.has(id)) || before.c.some((type) => type === "*" ? changedNodes.size > 0 : changedTypes.has(type)) ? dirty : clean).push(page);
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
dirty,
|
|
186
|
+
clean,
|
|
187
|
+
queryHashes
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Whether the HTML of a page lies in public/assets/, which every build deletes before bundling:
|
|
192
|
+
* the HTML state cannot vouch for it (it is rendered on every build).
|
|
193
|
+
*/
|
|
194
|
+
function htmlRemovedEachBuild(pagePath) {
|
|
195
|
+
return pagePath === "/assets" || pagePath.startsWith("/assets/");
|
|
196
|
+
}
|
|
197
|
+
/** Digest of everything the HTML/page-data of a page depends on (besides the renderer). */
|
|
198
|
+
function htmlDigest(page, resultHash) {
|
|
199
|
+
return hashString(`${page.componentChunkName}|${page.matchPath ?? ""}|${resultHash}`);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The query result (`{ data, pageContext }` JSON) of a page from its existing page-data.json (see
|
|
203
|
+
* `readPageDataResult`).
|
|
204
|
+
*/
|
|
205
|
+
function readCachedResult(publicDir, page) {
|
|
206
|
+
return readPageDataResult(generatePageDataPath(publicDir, page.path), page.componentChunkName, page.path, page.matchPath);
|
|
207
|
+
}
|
|
208
|
+
export { QUERY_STATE_VERSION, applyNodeChanges, classifyPages, computeNodeStates, createQueryState, currentNodeStates, diffNodeStates, hashString, htmlDigest, htmlRemovedEachBuild, nodeDigest, pageQueryHash, readCachedResult, serializeDependencies };
|