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,449 @@
|
|
|
1
|
+
import { pick } from "./router/utils.js";
|
|
2
|
+
import { isNotFoundPageFor, isNotFoundPageIn, isNotFoundPageUrl, notFoundCandidates, notFoundLookupPath } from "./not-found.js";
|
|
3
|
+
import { components } from "virtual:goatly/async-requires";
|
|
4
|
+
import matchPaths from "virtual:goatly/match-paths";
|
|
5
|
+
import notFoundPages from "virtual:goatly/not-found-pages";
|
|
6
|
+
// src/runtime/loader.ts
|
|
7
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
8
|
+
let componentLoaders = components;
|
|
9
|
+
/** the 404 pages of site sections (gatsby-config `notFoundPages`), longest prefix first */
|
|
10
|
+
let notFoundEntries = notFoundPages;
|
|
11
|
+
const notFoundListeners = /* @__PURE__ */ new Set();
|
|
12
|
+
const hot = import.meta.hot;
|
|
13
|
+
if (hot) hot.accept([
|
|
14
|
+
"virtual:goatly/async-requires",
|
|
15
|
+
"virtual:goatly/match-paths",
|
|
16
|
+
"virtual:goatly/not-found-pages"
|
|
17
|
+
], ([asyncRequires, mp, nf]) => {
|
|
18
|
+
if (asyncRequires?.components) componentLoaders = asyncRequires.components;
|
|
19
|
+
if (mp?.default) {
|
|
20
|
+
rankedMatchPaths.length = 0;
|
|
21
|
+
rankedMatchPaths.push(...mp.default);
|
|
22
|
+
pathCache.clear();
|
|
23
|
+
}
|
|
24
|
+
if (nf?.default) {
|
|
25
|
+
notFoundEntries = nf.default;
|
|
26
|
+
loader.forgetNotFound();
|
|
27
|
+
for (const listener of notFoundListeners) listener();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
function stripPrefix(str, prefix = "") {
|
|
31
|
+
if (!prefix) return str;
|
|
32
|
+
if (str === prefix) return "/";
|
|
33
|
+
if (str.startsWith(`${prefix}/`)) return str.slice(prefix.length);
|
|
34
|
+
return str;
|
|
35
|
+
}
|
|
36
|
+
/** Gatsby's normalizePagePath: removes the trailing slash (except for `/`) */
|
|
37
|
+
function normalizePagePath(path) {
|
|
38
|
+
if (path === "/") return path;
|
|
39
|
+
return path.endsWith("/") ? path.slice(0, -1) : path;
|
|
40
|
+
}
|
|
41
|
+
function decode(path) {
|
|
42
|
+
try {
|
|
43
|
+
return decodeURIComponent(path);
|
|
44
|
+
} catch {
|
|
45
|
+
return path;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const rankedMatchPaths = [...matchPaths];
|
|
49
|
+
const pathCache = /* @__PURE__ */ new Map();
|
|
50
|
+
/** `pick` for a decoded pathname: it decodes params again, which throws for e.g. "/a/100%" */
|
|
51
|
+
function safePick(routes, uri) {
|
|
52
|
+
try {
|
|
53
|
+
return pick(routes, uri);
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Finds the page path for a browser pathname, considering matchPaths (client-only routes). */
|
|
59
|
+
function findPath(rawPathname) {
|
|
60
|
+
const pathname = decode(stripPrefix(rawPathname.split("?")[0].split("#")[0], __BASE_PATH__));
|
|
61
|
+
const cached = pathCache.get(pathname);
|
|
62
|
+
if (cached) return cached;
|
|
63
|
+
let found;
|
|
64
|
+
if (!isDev && rankedMatchPaths.length) {
|
|
65
|
+
const result = safePick(rankedMatchPaths.map((m) => ({
|
|
66
|
+
path: m.matchPath,
|
|
67
|
+
page: m.path
|
|
68
|
+
})), pathname);
|
|
69
|
+
if (result) found = result.route.page;
|
|
70
|
+
}
|
|
71
|
+
const resolved = found ?? normalizePagePath(pathname);
|
|
72
|
+
pathCache.set(pathname, resolved);
|
|
73
|
+
return resolved;
|
|
74
|
+
}
|
|
75
|
+
function findMatchPath(rawPathname) {
|
|
76
|
+
const pathname = decode(stripPrefix(rawPathname, __BASE_PATH__));
|
|
77
|
+
const result = safePick(rankedMatchPaths.map((m) => ({ path: m.matchPath })), pathname);
|
|
78
|
+
return result ? result.route.path : null;
|
|
79
|
+
}
|
|
80
|
+
/** Params of the current matchPath (Gatsby's grabMatchParams) */
|
|
81
|
+
function grabMatchParams(rawPathname, matchPath) {
|
|
82
|
+
if (!matchPath) return {};
|
|
83
|
+
const pathname = decode(stripPrefix(rawPathname, __BASE_PATH__));
|
|
84
|
+
const result = safePick([{ path: matchPath }], pathname);
|
|
85
|
+
return result ? result.params : {};
|
|
86
|
+
}
|
|
87
|
+
const lookupPath = (rawPath) => notFoundLookupPath(rawPath, __BASE_PATH__);
|
|
88
|
+
/** the 404 page unknown URLs like `rawPath` get: their section's (`notFoundPages`) or "/404.html" */
|
|
89
|
+
function findNotFoundPath(rawPath) {
|
|
90
|
+
return notFoundCandidates(notFoundEntries, lookupPath(rawPath))[0];
|
|
91
|
+
}
|
|
92
|
+
/** whether the page is a 404 page: "/404.html" or the 404 page of a site section */
|
|
93
|
+
function isNotFoundPagePath(pagePath) {
|
|
94
|
+
return !!pagePath && isNotFoundPageIn(notFoundEntries, pagePath);
|
|
95
|
+
}
|
|
96
|
+
/** whether the page is the 404 page unknown URLs like `rawPath` get */
|
|
97
|
+
function isNotFoundPageForUrl(pagePath, rawPath) {
|
|
98
|
+
return isNotFoundPageFor(notFoundEntries, pagePath, lookupPath(rawPath));
|
|
99
|
+
}
|
|
100
|
+
/** whether the URL's page `urlPage` is the 404 page `pagePath` itself (e.g. "/404/" of "/404.html") */
|
|
101
|
+
function isNotFoundPageOwnUrl(pagePath, urlPage) {
|
|
102
|
+
return isNotFoundPageUrl(notFoundEntries, pagePath, urlPage);
|
|
103
|
+
}
|
|
104
|
+
/** whether site sections have their own 404 pages (`notFoundPages`) */
|
|
105
|
+
function hasNotFoundSections() {
|
|
106
|
+
return notFoundEntries.length > 0;
|
|
107
|
+
}
|
|
108
|
+
/** develop: calls `listener` after the list of 404 pages changed (HMR) */
|
|
109
|
+
function onNotFoundPagesChange(listener) {
|
|
110
|
+
notFoundListeners.add(listener);
|
|
111
|
+
return () => notFoundListeners.delete(listener);
|
|
112
|
+
}
|
|
113
|
+
function createPageDataUrl(pagePath) {
|
|
114
|
+
const fixed = pagePath === "/" ? "index" : normalizePagePath(pagePath).replace(/^\//, "");
|
|
115
|
+
return `${__PATH_PREFIX__}/page-data/${fixed}/page-data.json`;
|
|
116
|
+
}
|
|
117
|
+
/** null when there is no such JSON file; rejects only when `signal` aborted the request */
|
|
118
|
+
async function fetchJson(url, signal) {
|
|
119
|
+
try {
|
|
120
|
+
const res = await fetch(url, {
|
|
121
|
+
cache: isDev ? "no-store" : "default",
|
|
122
|
+
signal
|
|
123
|
+
});
|
|
124
|
+
if (!res.ok) return null;
|
|
125
|
+
const text = await res.text();
|
|
126
|
+
if (!text || text.trimStart().startsWith("<")) return null;
|
|
127
|
+
return JSON.parse(text);
|
|
128
|
+
} catch (e) {
|
|
129
|
+
if (signal?.aborted) throw e;
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** like Gatsby: prefetch a few pages at a time, with a pause in between, when the browser is idle */
|
|
134
|
+
const PREFETCH_BATCH_SIZE = 4;
|
|
135
|
+
const PREFETCH_DELAY_MS = 3e3;
|
|
136
|
+
function whenIdle(cb) {
|
|
137
|
+
if (typeof requestIdleCallback === "function") requestIdleCallback(() => cb());
|
|
138
|
+
else setTimeout(cb, 0);
|
|
139
|
+
}
|
|
140
|
+
/** a low priority download the browser keeps in its cache, without running anything */
|
|
141
|
+
function prefetchUrl(url) {
|
|
142
|
+
if (typeof document === "undefined") return;
|
|
143
|
+
for (const existing of document.getElementsByTagName("link")) if (existing.getAttribute("href") === url) return;
|
|
144
|
+
const link = document.createElement("link");
|
|
145
|
+
link.rel = "prefetch";
|
|
146
|
+
link.href = url;
|
|
147
|
+
if (!url.endsWith(".css")) link.crossOrigin = "";
|
|
148
|
+
document.head.appendChild(link);
|
|
149
|
+
}
|
|
150
|
+
const loader = new class PageLoader {
|
|
151
|
+
resources = /* @__PURE__ */ new Map();
|
|
152
|
+
prefetched = /* @__PURE__ */ new Set();
|
|
153
|
+
/** page-data loaded by prefetching, by page path (until the page is loaded) */
|
|
154
|
+
prefetchedPageData = /* @__PURE__ */ new Map();
|
|
155
|
+
prefetchQueue = [];
|
|
156
|
+
/** queued and running prefetches by page path */
|
|
157
|
+
prefetchEntries = /* @__PURE__ */ new Map();
|
|
158
|
+
prefetchRunning = false;
|
|
159
|
+
prefetchDisabled;
|
|
160
|
+
/** chunk-map.json (build): the JS and CSS files of each page component */
|
|
161
|
+
chunkMap;
|
|
162
|
+
prefetchedUrls = /* @__PURE__ */ new Set();
|
|
163
|
+
componentPromises = /* @__PURE__ */ new Map();
|
|
164
|
+
/** page-data of 404 pages by page path (production) */
|
|
165
|
+
notFoundData = /* @__PURE__ */ new Map();
|
|
166
|
+
pageDb = /* @__PURE__ */ new Map();
|
|
167
|
+
buildHash = "";
|
|
168
|
+
constructor() {
|
|
169
|
+
for (const key of Object.getOwnPropertyNames(PageLoader.prototype)) {
|
|
170
|
+
const value = this[key];
|
|
171
|
+
if (key !== "constructor" && typeof value === "function") this[key] = value.bind(this);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
setBuildHash(hash) {
|
|
175
|
+
this.buildHash = hash;
|
|
176
|
+
}
|
|
177
|
+
loadComponent(chunkName) {
|
|
178
|
+
let p = this.componentPromises.get(chunkName);
|
|
179
|
+
if (!p) {
|
|
180
|
+
const loader = componentLoaders[chunkName];
|
|
181
|
+
if (!loader) return Promise.reject(/* @__PURE__ */ new Error(`Unknown page component "${chunkName}"`));
|
|
182
|
+
p = loader();
|
|
183
|
+
p.catch(() => this.componentPromises.delete(chunkName));
|
|
184
|
+
this.componentPromises.set(chunkName, p);
|
|
185
|
+
}
|
|
186
|
+
return p;
|
|
187
|
+
}
|
|
188
|
+
/** Builds page resources from page data that is already known (initial render / dev) */
|
|
189
|
+
async resourcesFromPageData(pageData, notFound = false) {
|
|
190
|
+
const mod = await this.loadComponent(pageData.componentChunkName);
|
|
191
|
+
return {
|
|
192
|
+
component: mod.default,
|
|
193
|
+
head: mod.Head,
|
|
194
|
+
json: pageData.result ?? {},
|
|
195
|
+
page: {
|
|
196
|
+
componentChunkName: pageData.componentChunkName,
|
|
197
|
+
path: pageData.path,
|
|
198
|
+
matchPath: pageData.matchPath,
|
|
199
|
+
webpackCompilationHash: this.buildHash
|
|
200
|
+
},
|
|
201
|
+
staticQueryHashes: pageData.staticQueryHashes ?? [],
|
|
202
|
+
notFound
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
async loadPageDataJson(rawPath, signal) {
|
|
206
|
+
const pagePath = findPath(rawPath);
|
|
207
|
+
const pageData = await fetchJson(createPageDataUrl(pagePath), signal);
|
|
208
|
+
if (pageData) return {
|
|
209
|
+
pageData,
|
|
210
|
+
notFound: false
|
|
211
|
+
};
|
|
212
|
+
signal?.throwIfAborted();
|
|
213
|
+
return {
|
|
214
|
+
pageData: await this.notFoundPageData(rawPath, pagePath),
|
|
215
|
+
notFound: true
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
fetchNotFoundPageData(pagePath) {
|
|
219
|
+
if (isDev) return fetchJson(createPageDataUrl(pagePath));
|
|
220
|
+
let data = this.notFoundData.get(pagePath);
|
|
221
|
+
if (!data) {
|
|
222
|
+
const fetched = fetchJson(createPageDataUrl(pagePath));
|
|
223
|
+
fetched.then((d) => {
|
|
224
|
+
if (!d && this.notFoundData.get(pagePath) === fetched) this.notFoundData.delete(pagePath);
|
|
225
|
+
});
|
|
226
|
+
this.notFoundData.set(pagePath, fetched);
|
|
227
|
+
data = fetched;
|
|
228
|
+
}
|
|
229
|
+
return data;
|
|
230
|
+
}
|
|
231
|
+
/** page-data of the 404 page for `rawPath`: its section's, else the site's – never `requested`'s */
|
|
232
|
+
async notFoundPageData(rawPath, requested) {
|
|
233
|
+
for (const candidate of notFoundCandidates(notFoundEntries, lookupPath(rawPath))) {
|
|
234
|
+
if (requested !== void 0 && normalizePagePath(candidate) === normalizePagePath(requested)) continue;
|
|
235
|
+
const pageData = await this.fetchNotFoundPageData(candidate);
|
|
236
|
+
if (pageData) return pageData;
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
loadPage(rawPath) {
|
|
241
|
+
return this.load(rawPath);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* loadPage for the loader itself (prefetching, hovering): `loadPage` is window.___loader.loadPage,
|
|
245
|
+
* which sites may override (gatsby-browser) – like Gatsby, only navigation goes through it
|
|
246
|
+
*/
|
|
247
|
+
load(rawPath) {
|
|
248
|
+
const pagePath = findPath(rawPath);
|
|
249
|
+
return this.loadOnce(pagePath, () => {
|
|
250
|
+
const prefetched = this.prefetchedPageData.get(pagePath);
|
|
251
|
+
this.prefetchedPageData.delete(pagePath);
|
|
252
|
+
return prefetched ?? this.loadPageDataJson(rawPath);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
/** the 404 page for `rawPath`, a URL known to have no page (the server answered it with a 404 page) */
|
|
256
|
+
loadNotFoundPage(rawPath) {
|
|
257
|
+
return this.loadOnce(findPath(rawPath), async () => ({
|
|
258
|
+
pageData: await this.notFoundPageData(rawPath),
|
|
259
|
+
notFound: true
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
loadOnce(pagePath, load) {
|
|
263
|
+
const existing = this.resources.get(pagePath);
|
|
264
|
+
if (existing) return existing.promise;
|
|
265
|
+
const status = { promise: Promise.resolve(null) };
|
|
266
|
+
status.promise = (async () => {
|
|
267
|
+
const { pageData, notFound } = await load();
|
|
268
|
+
if (!pageData) {
|
|
269
|
+
status.value = null;
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
const resources = await this.resourcesFromPageData(pageData, notFound);
|
|
273
|
+
status.value = resources;
|
|
274
|
+
this.pageDb.set(pagePath, resources);
|
|
275
|
+
return resources;
|
|
276
|
+
})();
|
|
277
|
+
status.promise.catch(() => this.resources.delete(pagePath));
|
|
278
|
+
this.resources.set(pagePath, status);
|
|
279
|
+
return status.promise;
|
|
280
|
+
}
|
|
281
|
+
loadPageSync(rawPath) {
|
|
282
|
+
return this.resources.get(findPath(rawPath))?.value ?? void 0;
|
|
283
|
+
}
|
|
284
|
+
/** Seeds the cache (initial page, dev updates) */
|
|
285
|
+
setPageResources(rawPath, resources) {
|
|
286
|
+
const pagePath = findPath(rawPath);
|
|
287
|
+
this.resources.set(pagePath, {
|
|
288
|
+
promise: Promise.resolve(resources),
|
|
289
|
+
value: resources
|
|
290
|
+
});
|
|
291
|
+
this.pageDb.set(pagePath, resources);
|
|
292
|
+
}
|
|
293
|
+
invalidate(rawPath) {
|
|
294
|
+
if (!rawPath) {
|
|
295
|
+
this.resources.clear();
|
|
296
|
+
this.prefetchedPageData.clear();
|
|
297
|
+
this.notFoundData.clear();
|
|
298
|
+
pathCache.clear();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this.resources.delete(findPath(rawPath));
|
|
302
|
+
this.prefetchedPageData.delete(findPath(rawPath));
|
|
303
|
+
}
|
|
304
|
+
/** drops what was loaded for unknown URLs (develop: the list of 404 pages changed) */
|
|
305
|
+
forgetNotFound() {
|
|
306
|
+
this.notFoundData.clear();
|
|
307
|
+
this.prefetchedPageData.clear();
|
|
308
|
+
for (const [pagePath, status] of this.resources) if (status.value === null || status.value?.notFound) {
|
|
309
|
+
this.resources.delete(pagePath);
|
|
310
|
+
this.pageDb.delete(pagePath);
|
|
311
|
+
this.prefetched.delete(pagePath);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
isPageNotFound(rawPath) {
|
|
315
|
+
return !!this.loadPageSync(rawPath)?.notFound;
|
|
316
|
+
}
|
|
317
|
+
shouldPrefetch() {
|
|
318
|
+
if (typeof navigator === "undefined") return false;
|
|
319
|
+
const connection = navigator.connection;
|
|
320
|
+
if (connection && (connection.effectiveType || "").includes("2g")) return false;
|
|
321
|
+
if (connection?.saveData) return false;
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Queues prefetching a page (like Gatsby): its page-data is fetched and its component's JS and CSS
|
|
326
|
+
* are prefetched with `<link rel=prefetch>`, a few pages at a time when the browser is idle. No page
|
|
327
|
+
* code runs before the page is needed.
|
|
328
|
+
*/
|
|
329
|
+
prefetch(rawPath) {
|
|
330
|
+
const queued = this.queuePrefetch(rawPath);
|
|
331
|
+
if (queued) queued.pinned = true;
|
|
332
|
+
return queued !== void 0;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* gatsby-link API: prefetch when a link becomes visible. `abort()` once it is hidden again: when no
|
|
336
|
+
* other visible link wants the page, it is taken out of the queue, or its page-data request is
|
|
337
|
+
* cancelled if it is running (unless the page is being loaded meanwhile, e.g. hovered).
|
|
338
|
+
*/
|
|
339
|
+
enqueue(rawPath) {
|
|
340
|
+
const queued = this.queuePrefetch(rawPath);
|
|
341
|
+
if (queued) queued.watchers++;
|
|
342
|
+
let released = false;
|
|
343
|
+
return { abort: () => {
|
|
344
|
+
if (!queued || released) return;
|
|
345
|
+
released = true;
|
|
346
|
+
queued.watchers--;
|
|
347
|
+
if (queued.watchers > 0 || queued.pinned) return;
|
|
348
|
+
if (queued.controller) {
|
|
349
|
+
if (this.resources.has(queued.pagePath)) return;
|
|
350
|
+
this.prefetchedPageData.delete(queued.pagePath);
|
|
351
|
+
queued.controller.abort();
|
|
352
|
+
} else if (this.prefetchEntries.get(queued.pagePath) === queued) this.prefetchEntries.delete(queued.pagePath);
|
|
353
|
+
} };
|
|
354
|
+
}
|
|
355
|
+
/** gatsby-link API: user hovers a link – load the page right away */
|
|
356
|
+
hovering(rawPath) {
|
|
357
|
+
this.load(rawPath).catch(() => {});
|
|
358
|
+
}
|
|
359
|
+
/** the queued or running prefetch of the page; null when it is prefetched or loaded already */
|
|
360
|
+
queuePrefetch(rawPath) {
|
|
361
|
+
if (!this.shouldPrefetch()) return void 0;
|
|
362
|
+
const pagePath = findPath(rawPath);
|
|
363
|
+
const existing = this.prefetchEntries.get(pagePath);
|
|
364
|
+
if (existing) return existing;
|
|
365
|
+
if (this.prefetched.has(pagePath) || this.resources.has(pagePath)) return null;
|
|
366
|
+
const queued = {
|
|
367
|
+
rawPath,
|
|
368
|
+
pagePath,
|
|
369
|
+
watchers: 0,
|
|
370
|
+
pinned: false
|
|
371
|
+
};
|
|
372
|
+
this.prefetchEntries.set(pagePath, queued);
|
|
373
|
+
this.prefetchQueue.push(queued);
|
|
374
|
+
if (!this.prefetchRunning) {
|
|
375
|
+
this.prefetchRunning = true;
|
|
376
|
+
setTimeout(() => this.prefetchNextBatch(), PREFETCH_DELAY_MS);
|
|
377
|
+
}
|
|
378
|
+
return queued;
|
|
379
|
+
}
|
|
380
|
+
prefetchNextBatch() {
|
|
381
|
+
whenIdle(() => {
|
|
382
|
+
this.prefetchQueue = this.prefetchQueue.filter((q) => this.prefetchEntries.get(q.pagePath) === q);
|
|
383
|
+
const batch = this.prefetchQueue.splice(0, 4);
|
|
384
|
+
Promise.all(batch.map((q) => this.runPrefetch(q))).then(() => {
|
|
385
|
+
if (this.prefetchQueue.length) setTimeout(() => this.prefetchNextBatch(), PREFETCH_DELAY_MS);
|
|
386
|
+
else this.prefetchRunning = false;
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
async runPrefetch(queued) {
|
|
391
|
+
const { rawPath, pagePath } = queued;
|
|
392
|
+
if (this.prefetched.has(pagePath)) {
|
|
393
|
+
this.prefetchEntries.delete(pagePath);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
this.prefetched.add(pagePath);
|
|
397
|
+
const plugins = globalThis.___goatlyBrowserApiRunner;
|
|
398
|
+
const prefetchArgs = { pathname: rawPath };
|
|
399
|
+
plugins?.apiRunner("onPrefetchPathname", prefetchArgs);
|
|
400
|
+
this.prefetchDisabled ??= !!plugins?.apiRunner("disableCorePrefetching").some(Boolean);
|
|
401
|
+
if (this.prefetchDisabled) {
|
|
402
|
+
this.prefetchEntries.delete(pagePath);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const controller = new AbortController();
|
|
406
|
+
queued.controller = controller;
|
|
407
|
+
try {
|
|
408
|
+
await this.prefetchResources(queued, controller.signal);
|
|
409
|
+
plugins?.apiRunner("onPostPrefetchPathname", prefetchArgs);
|
|
410
|
+
} catch {
|
|
411
|
+
if (controller.signal.aborted) this.prefetched.delete(pagePath);
|
|
412
|
+
} finally {
|
|
413
|
+
if (this.prefetchEntries.get(pagePath) === queued) this.prefetchEntries.delete(pagePath);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
async prefetchResources(queued, signal) {
|
|
417
|
+
const { rawPath, pagePath } = queued;
|
|
418
|
+
if (this.resources.has(pagePath)) return;
|
|
419
|
+
let pageData = this.prefetchedPageData.get(pagePath);
|
|
420
|
+
if (!pageData) {
|
|
421
|
+
pageData = this.loadPageDataJson(rawPath, signal);
|
|
422
|
+
this.prefetchedPageData.set(pagePath, pageData);
|
|
423
|
+
pageData.catch(() => {
|
|
424
|
+
if (this.prefetchedPageData.get(pagePath) === pageData) this.prefetchedPageData.delete(pagePath);
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
const loaded = (await pageData).pageData;
|
|
428
|
+
queued.controller = void 0;
|
|
429
|
+
if (!loaded || this.componentPromises.has(loaded.componentChunkName)) return;
|
|
430
|
+
for (const url of (await this.loadChunkMap())?.[loaded.componentChunkName] ?? []) {
|
|
431
|
+
if (this.prefetchedUrls.has(url)) continue;
|
|
432
|
+
this.prefetchedUrls.add(url);
|
|
433
|
+
prefetchUrl(url);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
loadChunkMap() {
|
|
437
|
+
if (isDev) return Promise.resolve(null);
|
|
438
|
+
this.chunkMap ??= fetchJson(`${__PATH_PREFIX__}/chunk-map.json`);
|
|
439
|
+
return this.chunkMap;
|
|
440
|
+
}
|
|
441
|
+
getResourceURLsForPathname(rawPath) {
|
|
442
|
+
const pagePath = findPath(rawPath);
|
|
443
|
+
const urls = [createPageDataUrl(pagePath)];
|
|
444
|
+
const loaded = this.resources.get(pagePath)?.value;
|
|
445
|
+
if (loaded?.notFound) urls.push(createPageDataUrl(loaded.page.path));
|
|
446
|
+
return urls;
|
|
447
|
+
}
|
|
448
|
+
}();
|
|
449
|
+
export { PREFETCH_BATCH_SIZE, PREFETCH_DELAY_MS, createPageDataUrl, findMatchPath, findNotFoundPath, findPath, grabMatchParams, hasNotFoundSections, isNotFoundPageForUrl, isNotFoundPageOwnUrl, isNotFoundPagePath, loader, normalizePagePath, onNotFoundPagesChange, stripPrefix };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/runtime/not-found.ts
|
|
2
|
+
/** the 404 page of every other URL (Gatsby's) */
|
|
3
|
+
const ROOT_NOT_FOUND_PAGE = "/404.html";
|
|
4
|
+
function decodePathname(pathname) {
|
|
5
|
+
try {
|
|
6
|
+
return decodeURIComponent(pathname);
|
|
7
|
+
} catch {
|
|
8
|
+
return pathname;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** pathname to match: without query, hash and base path (pathPrefix), decoded once */
|
|
12
|
+
function notFoundLookupPath(raw, basePath = "") {
|
|
13
|
+
let pathname = raw.split("?")[0].split("#")[0];
|
|
14
|
+
if (basePath) {
|
|
15
|
+
if (pathname === basePath) pathname = "/";
|
|
16
|
+
else if (pathname.startsWith(`${basePath}/`)) pathname = pathname.slice(basePath.length);
|
|
17
|
+
}
|
|
18
|
+
return decodePathname(pathname);
|
|
19
|
+
}
|
|
20
|
+
const trimSlash = (p) => p.length > 1 && p.endsWith("/") ? p.slice(0, -1) : p;
|
|
21
|
+
/** the same page path, apart from a trailing slash */
|
|
22
|
+
function samePagePath(a, b) {
|
|
23
|
+
return a !== void 0 && b !== void 0 && trimSlash(a) === trimSlash(b);
|
|
24
|
+
}
|
|
25
|
+
/** whether `pathname` is in the section `prefix`: whole segments, case-sensitive */
|
|
26
|
+
function inNotFoundSection(prefix, pathname) {
|
|
27
|
+
return pathname === prefix || pathname.startsWith(`${prefix}/`);
|
|
28
|
+
}
|
|
29
|
+
/** longest prefix first, then alphabetical */
|
|
30
|
+
function compareNotFoundEntries(a, b) {
|
|
31
|
+
return b.prefix.length - a.prefix.length || (a.prefix < b.prefix ? -1 : a.prefix > b.prefix ? 1 : 0);
|
|
32
|
+
}
|
|
33
|
+
/** the sections containing `pathname`, most specific first (`entries` sorted by compareNotFoundEntries) */
|
|
34
|
+
function matchNotFoundEntries(entries, pathname) {
|
|
35
|
+
return entries.filter((e) => inNotFoundSection(e.prefix, pathname));
|
|
36
|
+
}
|
|
37
|
+
/** the 404 pages to try for `pathname`, most specific first, ending with "/404.html" */
|
|
38
|
+
function notFoundCandidates(entries, pathname) {
|
|
39
|
+
const paths = matchNotFoundEntries(entries, pathname).map((e) => e.path);
|
|
40
|
+
return [.../* @__PURE__ */ new Set([...paths, ROOT_NOT_FOUND_PAGE])];
|
|
41
|
+
}
|
|
42
|
+
const isEntryPage = (e, pagePath) => samePagePath(e.path, pagePath) || samePagePath(e.source, pagePath);
|
|
43
|
+
/** whether `pagePath` is a 404 page: "/404.html" or the page of a section */
|
|
44
|
+
function isNotFoundPageIn(entries, pagePath) {
|
|
45
|
+
return pagePath === "/404.html" || entries.some((e) => isEntryPage(e, pagePath));
|
|
46
|
+
}
|
|
47
|
+
/** whether `pagePath` is the 404 page unknown URLs like `pathname` get */
|
|
48
|
+
function isNotFoundPageFor(entries, pagePath, pathname) {
|
|
49
|
+
const entry = matchNotFoundEntries(entries, pathname)[0];
|
|
50
|
+
return entry ? isEntryPage(entry, pagePath) : pagePath === ROOT_NOT_FOUND_PAGE;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* whether `urlPath` names the 404 page `pagePath` itself (a visit of the page, not an unknown URL):
|
|
54
|
+
* its path, "…/404/" of "…/404.html" (Gatsby's /404/ ↔ /404.html), a section's configured page
|
|
55
|
+
*/
|
|
56
|
+
function isNotFoundPageUrl(entries, pagePath, urlPath) {
|
|
57
|
+
if (samePagePath(pagePath, urlPath)) return true;
|
|
58
|
+
if (pagePath.endsWith("/404.html") && samePagePath(pagePath.slice(0, -5), urlPath)) return true;
|
|
59
|
+
return entries.some((e) => samePagePath(e.path, pagePath) && samePagePath(e.source, urlPath) || samePagePath(e.source, pagePath) && samePagePath(e.path, urlPath));
|
|
60
|
+
}
|
|
61
|
+
export { ROOT_NOT_FOUND_PAGE, compareNotFoundEntries, decodePathname, inNotFoundSection, isNotFoundPageFor, isNotFoundPageIn, isNotFoundPageUrl, matchNotFoundEntries, notFoundCandidates, notFoundLookupPath, samePagePath };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ApiRunnerContext, wrapElement } from "./api-runner.js";
|
|
2
|
+
import { grabMatchParams, loader } from "./loader.js";
|
|
3
|
+
import { LocationContext, navigate } from "./router/index.js";
|
|
4
|
+
import { createElement, useContext } from "react";
|
|
5
|
+
// src/runtime/page-renderer.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Gatsby's public `PageRenderer`: renders the page for a given location (e.g. behind a modal).
|
|
8
|
+
* The page must already be loaded (it usually is: it is the current or previous page).
|
|
9
|
+
*/
|
|
10
|
+
function PageRenderer(props) {
|
|
11
|
+
const ctx = useContext(LocationContext);
|
|
12
|
+
const runner = useContext(ApiRunnerContext);
|
|
13
|
+
const location = props.location ?? ctx.location;
|
|
14
|
+
const resources = loader.loadPageSync(location.pathname + (location.search ?? ""));
|
|
15
|
+
if (!resources) return null;
|
|
16
|
+
const params = {
|
|
17
|
+
...grabMatchParams(location.pathname, resources.page.matchPath),
|
|
18
|
+
...resources.json.pageContext?.__params
|
|
19
|
+
};
|
|
20
|
+
const pageProps = {
|
|
21
|
+
...props,
|
|
22
|
+
location,
|
|
23
|
+
navigate,
|
|
24
|
+
pageResources: resources,
|
|
25
|
+
...resources.json,
|
|
26
|
+
params,
|
|
27
|
+
path: resources.page.matchPath || resources.page.path
|
|
28
|
+
};
|
|
29
|
+
const element = createElement(resources.component, {
|
|
30
|
+
...pageProps,
|
|
31
|
+
key: pageProps.path
|
|
32
|
+
});
|
|
33
|
+
return runner ? wrapElement(runner, "wrapPageElement", element, { props: pageProps }) : element;
|
|
34
|
+
}
|
|
35
|
+
export { PageRenderer };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/runtime/preamble.ts
|
|
2
|
+
/**
|
|
3
|
+
* Renderers that hoist (react-dom 19; TanStack Redact with @goatly/redact) write what they
|
|
4
|
+
* hoist at the very start of the output when rendering a non-document root: the `<title>`, `<meta>`
|
|
5
|
+
* and `<link>` elements of components, stylesheets and styles with a precedence, async scripts and
|
|
6
|
+
* resource hints (`preload()`, `preinit()`, …). Split them off so they can be put in `<head>`, where
|
|
7
|
+
* the browser runtime expects them.
|
|
8
|
+
*
|
|
9
|
+
* Nothing else is split off. Like react-dom 19, these are rendered in place: metadata and scripts
|
|
10
|
+
* with `itemProp`, `<base>`, a `<link>` without a `rel` attribute or with an empty `href`, a
|
|
11
|
+
* stylesheet (`rel="stylesheet"`) without a precedence, a script without `src` or `async`, a style
|
|
12
|
+
* without a precedence.
|
|
13
|
+
*/
|
|
14
|
+
function splitPreamble(html) {
|
|
15
|
+
let pos = 0;
|
|
16
|
+
while (pos < html.length && html[pos] === "<") {
|
|
17
|
+
const m = /^<(link|meta|script|style|title)[\s/>]/.exec(html.slice(pos, pos + 8));
|
|
18
|
+
if (!m) break;
|
|
19
|
+
const tag = m[1];
|
|
20
|
+
const openEnd = html.indexOf(">", pos);
|
|
21
|
+
if (openEnd === -1) break;
|
|
22
|
+
const openTag = html.slice(pos, openEnd + 1);
|
|
23
|
+
const names = openTag.replace(/="[^"]*"/g, "");
|
|
24
|
+
const has = (name) => new RegExp(`\\s${name}(?=[\\s=/>])`, "i").test(names);
|
|
25
|
+
if (tag !== "style" && has("itemprop")) break;
|
|
26
|
+
if (tag === "link" || tag === "meta") {
|
|
27
|
+
if (tag === "link") {
|
|
28
|
+
const rel = /\srel="([^"]*)"/.exec(openTag)?.[1];
|
|
29
|
+
const href = /\shref="([^"]*)"/.exec(openTag)?.[1];
|
|
30
|
+
if (rel === void 0 || !href || rel === "stylesheet" && !has("data-precedence")) break;
|
|
31
|
+
}
|
|
32
|
+
pos = openEnd + 1;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (tag === "script" && !(has("async") && /\ssrc="[^"]/.test(openTag))) break;
|
|
36
|
+
if (tag === "style" && !has("data-precedence")) break;
|
|
37
|
+
const close = `</${tag}>`;
|
|
38
|
+
const end = html.indexOf(close, openEnd);
|
|
39
|
+
if (end === -1) break;
|
|
40
|
+
pos = end + close.length;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
preamble: html.slice(0, pos),
|
|
44
|
+
body: html.slice(pos)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export { splitPreamble };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/runtime/react-compat.ts
|
|
2
|
+
/** Gatsby 5's marker of elements owned by the `Head` export (portal head mode). */
|
|
3
|
+
const HEAD_ATTRIBUTE = "data-gatsby-head";
|
|
4
|
+
/** Elements a `Head` export may render (Gatsby 5 `VALID_NODE_NAMES` without html/body). */
|
|
5
|
+
const VALID_HEAD_TAGS = /* @__PURE__ */ new Set([
|
|
6
|
+
"link",
|
|
7
|
+
"meta",
|
|
8
|
+
"style",
|
|
9
|
+
"title",
|
|
10
|
+
"base",
|
|
11
|
+
"noscript",
|
|
12
|
+
"script"
|
|
13
|
+
]);
|
|
14
|
+
export { HEAD_ATTRIBUTE, VALID_HEAD_TAGS };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as exports from "virtual:goatly/renderer";
|
|
2
|
+
// src/runtime/renderer-shared.ts
|
|
3
|
+
/**
|
|
4
|
+
* The exports of the renderer's shared module. A copy of the module namespace: its optional exports
|
|
5
|
+
* (`escapeRawText`) may be missing, which Rolldown would warn about for a direct import.
|
|
6
|
+
*/
|
|
7
|
+
const shared = { ...exports };
|
|
8
|
+
const headMode = shared.headMode;
|
|
9
|
+
const escapeRawText = shared.escapeRawText;
|
|
10
|
+
export { escapeRawText, headMode };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
2
|
+
// src/runtime/renderers/react-client.ts
|
|
3
|
+
const mount = (element, container, { onRecoverableError, onCaughtError, onUncaughtError }) => {
|
|
4
|
+
if (container.hasChildNodes()) hydrateRoot(container, element, {
|
|
5
|
+
onRecoverableError,
|
|
6
|
+
onCaughtError,
|
|
7
|
+
onUncaughtError
|
|
8
|
+
});
|
|
9
|
+
else createRoot(container, {
|
|
10
|
+
onCaughtError,
|
|
11
|
+
onUncaughtError
|
|
12
|
+
}).render(element);
|
|
13
|
+
};
|
|
14
|
+
export { mount };
|