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,110 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
// src/runtime/script.tsx
|
|
3
|
+
let ScriptStrategy = /* @__PURE__ */ function(ScriptStrategy) {
|
|
4
|
+
ScriptStrategy["postHydrate"] = "post-hydrate";
|
|
5
|
+
ScriptStrategy["idle"] = "idle";
|
|
6
|
+
/** Partytown in Gatsby – not supported: the script runs on the main thread like `idle` */
|
|
7
|
+
ScriptStrategy["offMainThread"] = "off-main-thread";
|
|
8
|
+
return ScriptStrategy;
|
|
9
|
+
}({});
|
|
10
|
+
const scriptCache = /* @__PURE__ */ new Set();
|
|
11
|
+
const scriptCallbackCache = /* @__PURE__ */ new Map();
|
|
12
|
+
/** Gatsby collects off-main-thread scripts here for Partytown (always empty in goatly) */
|
|
13
|
+
const collectedScriptsByPage = /* @__PURE__ */ new Map();
|
|
14
|
+
/**
|
|
15
|
+
* Injects a script like gatsby-script: scripts with an `id` or `src` run once per session (later
|
|
16
|
+
* mounts get the cached load/error event), inline scripts without an `id` run on every mount.
|
|
17
|
+
*/
|
|
18
|
+
function injectScript(props, strategy) {
|
|
19
|
+
const { id, src, strategy: _s, onLoad, onError, children, dangerouslySetInnerHTML, forward: _f, ...attributes } = props;
|
|
20
|
+
const inline = children ?? dangerouslySetInnerHTML?.__html;
|
|
21
|
+
const key = id || src;
|
|
22
|
+
if (!key && !inline) return {};
|
|
23
|
+
if (key && scriptCache.has(key)) {
|
|
24
|
+
const cached = scriptCallbackCache.get(key);
|
|
25
|
+
if (cached?.load?.event && onLoad) onLoad(cached.load.event);
|
|
26
|
+
else if (onLoad) cached?.load?.callbacks.push(onLoad);
|
|
27
|
+
if (cached?.error?.event && onError) onError(cached.error.event);
|
|
28
|
+
else if (onError) cached?.error?.callbacks.push(onError);
|
|
29
|
+
return {
|
|
30
|
+
key,
|
|
31
|
+
onLoad,
|
|
32
|
+
onError
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const script = document.createElement("script");
|
|
36
|
+
if (id) script.id = id;
|
|
37
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
38
|
+
if (value === void 0 || value === null || value === false) continue;
|
|
39
|
+
script.setAttribute(name === "className" ? "class" : name === "crossOrigin" ? "crossorigin" : name, value === true ? "" : String(value));
|
|
40
|
+
}
|
|
41
|
+
script.dataset.strategy = strategy;
|
|
42
|
+
const entry = {
|
|
43
|
+
load: {
|
|
44
|
+
callbacks: onLoad ? [onLoad] : [],
|
|
45
|
+
event: void 0
|
|
46
|
+
},
|
|
47
|
+
error: {
|
|
48
|
+
callbacks: onError ? [onError] : [],
|
|
49
|
+
event: void 0
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
if (key) scriptCallbackCache.set(key, entry);
|
|
53
|
+
script.addEventListener("load", (e) => {
|
|
54
|
+
entry.load.event = e;
|
|
55
|
+
for (const cb of entry.load.callbacks.slice()) cb(e);
|
|
56
|
+
});
|
|
57
|
+
script.addEventListener("error", (e) => {
|
|
58
|
+
entry.error.event = e;
|
|
59
|
+
for (const cb of entry.error.callbacks.slice()) cb(e);
|
|
60
|
+
});
|
|
61
|
+
if (src) script.src = src;
|
|
62
|
+
else if (inline) script.textContent = inline;
|
|
63
|
+
if (key) scriptCache.add(key);
|
|
64
|
+
document.body.appendChild(script);
|
|
65
|
+
return {
|
|
66
|
+
script,
|
|
67
|
+
key,
|
|
68
|
+
onLoad,
|
|
69
|
+
onError
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** unmount: the element goes away and this mount's callbacks are not called any more (Gatsby) */
|
|
73
|
+
function removeInjected(injected) {
|
|
74
|
+
if (!injected) return;
|
|
75
|
+
const entry = injected.key ? scriptCallbackCache.get(injected.key) : void 0;
|
|
76
|
+
const drop = (list, cb) => {
|
|
77
|
+
const index = list && cb ? list.indexOf(cb) : -1;
|
|
78
|
+
if (index !== -1) list.splice(index, 1);
|
|
79
|
+
};
|
|
80
|
+
drop(entry?.load?.callbacks, injected.onLoad);
|
|
81
|
+
drop(entry?.error?.callbacks, injected.onError);
|
|
82
|
+
injected.script?.remove();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Gatsby's `<Script>` component. `post-hydrate` scripts are injected after hydration,
|
|
86
|
+
* `idle` scripts when the browser is idle. `off-main-thread` (Partytown in Gatsby) is not
|
|
87
|
+
* supported: those scripts run on the main thread when the browser is idle.
|
|
88
|
+
*/
|
|
89
|
+
function Script(props) {
|
|
90
|
+
const strategy = props.strategy ?? "post-hydrate";
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
let injected;
|
|
93
|
+
if (strategy === "post-hydrate") injected = injectScript(props, strategy);
|
|
94
|
+
else {
|
|
95
|
+
if (strategy === "off-main-thread") warnOffMainThread(props);
|
|
96
|
+
(window.requestIdleCallback ?? ((cb) => setTimeout(cb, 1)))(() => {
|
|
97
|
+
injected = injectScript(props, strategy);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return () => removeInjected(injected);
|
|
101
|
+
}, []);
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
let warnedOffMainThread = false;
|
|
105
|
+
function warnOffMainThread(props) {
|
|
106
|
+
if (warnedOffMainThread || process.env.NODE_ENV === "production") return;
|
|
107
|
+
warnedOffMainThread = true;
|
|
108
|
+
console.warn(`<Script strategy="off-main-thread"> (Partytown) is not supported by goatly: "${props.id || props.src || "inline script"}" runs on the main thread when the browser is idle.`);
|
|
109
|
+
}
|
|
110
|
+
export { Script, ScriptStrategy, collectedScriptsByPage, scriptCache, scriptCallbackCache };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useLocation } from "./router/index.js";
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
3
|
+
// src/runtime/scroll.ts
|
|
4
|
+
const STATE_KEY_PREFIX = "@@scroll|";
|
|
5
|
+
const useIsoLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
6
|
+
function storageKey(pathname, key, identifier) {
|
|
7
|
+
return `${STATE_KEY_PREFIX}${pathname}|${key || "initial"}${identifier ? `|${identifier}` : ""}`;
|
|
8
|
+
}
|
|
9
|
+
const sessionStorageScroll = {
|
|
10
|
+
read(pathname, key, identifier) {
|
|
11
|
+
try {
|
|
12
|
+
const value = window.sessionStorage.getItem(storageKey(pathname, key, identifier));
|
|
13
|
+
return value ? JSON.parse(value) : void 0;
|
|
14
|
+
} catch {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
save(pathname, key, value, identifier) {
|
|
19
|
+
try {
|
|
20
|
+
window.sessionStorage.setItem(storageKey(pathname, key, identifier), JSON.stringify(value));
|
|
21
|
+
} catch {}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/** Gatsby's `useScrollRestoration(identifier)` for scroll containers. */
|
|
25
|
+
function useScrollRestoration(identifier) {
|
|
26
|
+
const location = useLocation();
|
|
27
|
+
const ref = useRef(void 0);
|
|
28
|
+
useIsoLayoutEffect(() => {
|
|
29
|
+
if (!ref.current) return;
|
|
30
|
+
const position = sessionStorageScroll.read(location.pathname, location.key, identifier);
|
|
31
|
+
ref.current.scrollTo(0, typeof position === "number" ? position : 0);
|
|
32
|
+
}, [location.key]);
|
|
33
|
+
return {
|
|
34
|
+
ref,
|
|
35
|
+
onScroll() {
|
|
36
|
+
if (ref.current) sessionStorageScroll.save(location.pathname, location.key, ref.current.scrollTop, identifier);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export { sessionStorageScroll, useScrollRestoration };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/runtime/slice.tsx
|
|
2
|
+
/**
|
|
3
|
+
* Gatsby's `<Slice>` – Slices are not supported by goatly. With `allowEmpty` it renders
|
|
4
|
+
* nothing (as Gatsby does when no slice exists for the alias); otherwise rendering it fails (the
|
|
5
|
+
* build reports the page), so a missing part of a page never goes unnoticed.
|
|
6
|
+
*/
|
|
7
|
+
function Slice({ alias, allowEmpty }) {
|
|
8
|
+
if (allowEmpty) return null;
|
|
9
|
+
throw new Error(`<Slice alias="${alias}"> – Gatsby Slices are not supported by goatly. Render the slice component directly instead: pass its sliceContext as props, and turn its \`export const query\` into useStaticQuery or part of the page query.`);
|
|
10
|
+
}
|
|
11
|
+
export { Slice };
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { escapeRawText, headMode } from "./renderer-shared.js";
|
|
2
|
+
import { createApiRunner } from "./api-runner.js";
|
|
3
|
+
import { HeadRoot, Root } from "./app.js";
|
|
4
|
+
import { isRedirect } from "./router/index.js";
|
|
5
|
+
import { createHtmlAttributeCollector } from "./head-tags.js";
|
|
6
|
+
import { headMarkupParts } from "./head-markup.js";
|
|
7
|
+
import { cloneElement, createElement, isValidElement } from "react";
|
|
8
|
+
import { components } from "virtual:goatly/async-requires";
|
|
9
|
+
import { renderBody, renderDocument, renderHead, splitBody } from "virtual:goatly/renderer-server";
|
|
10
|
+
import ssrPlugins from "virtual:goatly/ssr-plugins";
|
|
11
|
+
import Html from "virtual:goatly/html";
|
|
12
|
+
// src/runtime/ssr.tsx
|
|
13
|
+
const runner = createApiRunner(ssrPlugins);
|
|
14
|
+
const PREAMBLE_PLACEHOLDER = "__goatly_head__";
|
|
15
|
+
/** `"portal"` head mode: where the Head export's non-meta elements go (after stylesheets, like Gatsby 5) */
|
|
16
|
+
const HEAD_REST_PLACEHOLDER = "__goatly_head_rest__";
|
|
17
|
+
const flatten = (components) => [].concat(components).flat(1e400).filter(Boolean);
|
|
18
|
+
function deepMerge(a, b) {
|
|
19
|
+
const out = { ...a };
|
|
20
|
+
for (const [k, v] of Object.entries(b ?? {})) out[k] = v && typeof v === "object" && !Array.isArray(v) && typeof out[k] === "object" ? deepMerge(out[k], v) : v;
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
/** Moves meta tags to the top of head so they are not pushed down by large inline styles. */
|
|
24
|
+
function reorderHeadComponents(headComponents) {
|
|
25
|
+
return [...headComponents].sort((a, b) => {
|
|
26
|
+
const aMeta = a?.type === "meta";
|
|
27
|
+
const bMeta = b?.type === "meta";
|
|
28
|
+
if (aMeta && !bMeta) return -1;
|
|
29
|
+
return 0;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function withKeys(list, prefix) {
|
|
33
|
+
return list.map((el, i) => isValidElement(el) && el.key == null ? cloneElement(el, { key: `${prefix}-${i}` }) : el);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Renders a page to a complete HTML document – the equivalent of Gatsby's `static-entry`.
|
|
37
|
+
* Implements `replaceRenderer`, `onRenderBody`, `onPreRenderHTML`, `wrapRootElement`,
|
|
38
|
+
* `wrapPageElement` and the `Head` export.
|
|
39
|
+
*/
|
|
40
|
+
async function renderPage(input) {
|
|
41
|
+
const { pagePath, pageData } = input;
|
|
42
|
+
const loadComponent = components[pageData.componentChunkName];
|
|
43
|
+
if (!loadComponent) throw new Error(`Page component "${pageData.componentChunkName}" not found for page "${pagePath}"`);
|
|
44
|
+
const pageModule = await loadComponent();
|
|
45
|
+
if (!pageModule.default) throw new Error(`The page component for "${pagePath}" has no default export`);
|
|
46
|
+
const pageResources = {
|
|
47
|
+
component: pageModule.default,
|
|
48
|
+
head: pageModule.Head,
|
|
49
|
+
json: pageData.result ?? {},
|
|
50
|
+
page: {
|
|
51
|
+
componentChunkName: pageData.componentChunkName,
|
|
52
|
+
path: pageData.path,
|
|
53
|
+
matchPath: pageData.matchPath,
|
|
54
|
+
webpackCompilationHash: input.buildHash ?? ""
|
|
55
|
+
},
|
|
56
|
+
staticQueryHashes: pageData.staticQueryHashes ?? [],
|
|
57
|
+
...input.notFound ? { notFound: true } : {}
|
|
58
|
+
};
|
|
59
|
+
let headComponents = [createElement("meta", {
|
|
60
|
+
name: "generator",
|
|
61
|
+
content: input.generator ?? "goatly",
|
|
62
|
+
key: "generator"
|
|
63
|
+
})];
|
|
64
|
+
let htmlAttributes = {};
|
|
65
|
+
let bodyAttributes = {};
|
|
66
|
+
let preBodyComponents = [];
|
|
67
|
+
let postBodyComponents = [];
|
|
68
|
+
let bodyProps = {};
|
|
69
|
+
let bodyHtml = "";
|
|
70
|
+
const setHeadComponents = (c) => headComponents = headComponents.concat(flatten(c));
|
|
71
|
+
const setHtmlAttributes = (a) => htmlAttributes = deepMerge(htmlAttributes, a);
|
|
72
|
+
const setBodyAttributes = (a) => bodyAttributes = deepMerge(bodyAttributes, a);
|
|
73
|
+
const setPreBodyComponents = (c) => preBodyComponents = preBodyComponents.concat(flatten(c));
|
|
74
|
+
const setPostBodyComponents = (c) => postBodyComponents = postBodyComponents.concat(flatten(c));
|
|
75
|
+
const setBodyProps = (p) => bodyProps = deepMerge(bodyProps, p);
|
|
76
|
+
const replaceBodyHTMLString = (s) => bodyHtml = s;
|
|
77
|
+
const basePath = typeof __BASE_PATH__ !== "undefined" ? __BASE_PATH__ : "";
|
|
78
|
+
const url = input.url ?? `${basePath}${pagePath}`;
|
|
79
|
+
const location = {
|
|
80
|
+
pathname: url,
|
|
81
|
+
search: "",
|
|
82
|
+
hash: "",
|
|
83
|
+
href: url,
|
|
84
|
+
origin: "",
|
|
85
|
+
protocol: "",
|
|
86
|
+
host: "",
|
|
87
|
+
hostname: "",
|
|
88
|
+
port: "",
|
|
89
|
+
state: null,
|
|
90
|
+
key: "initial"
|
|
91
|
+
};
|
|
92
|
+
const ssr = {
|
|
93
|
+
staticQueryUsage: new Set(pageData.staticQueryHashes ?? []),
|
|
94
|
+
htmlAttributes: createHtmlAttributeCollector()
|
|
95
|
+
};
|
|
96
|
+
const bodyComponent = createElement(Root, {
|
|
97
|
+
initial: {
|
|
98
|
+
location,
|
|
99
|
+
pageResources
|
|
100
|
+
},
|
|
101
|
+
runner,
|
|
102
|
+
ssr,
|
|
103
|
+
wrapRootPathname: pagePath
|
|
104
|
+
});
|
|
105
|
+
await runner.apiRunnerAsync("replaceRenderer", {
|
|
106
|
+
bodyComponent,
|
|
107
|
+
replaceBodyHTMLString,
|
|
108
|
+
setHeadComponents,
|
|
109
|
+
setHtmlAttributes,
|
|
110
|
+
setBodyAttributes,
|
|
111
|
+
setPreBodyComponents,
|
|
112
|
+
setPostBodyComponents,
|
|
113
|
+
setBodyProps,
|
|
114
|
+
pathname: pagePath,
|
|
115
|
+
pathPrefix: __PATH_PREFIX__
|
|
116
|
+
});
|
|
117
|
+
let preamble = "";
|
|
118
|
+
let body = "";
|
|
119
|
+
if (bodyHtml) ({html: body, head: preamble} = splitBody(bodyHtml));
|
|
120
|
+
else try {
|
|
121
|
+
({html: body, head: preamble} = await renderBody(bodyComponent, { ignoreError: isRedirect }));
|
|
122
|
+
} catch (e) {
|
|
123
|
+
if (!isRedirect(e)) throw e;
|
|
124
|
+
}
|
|
125
|
+
runner.apiRunner("onRenderBody", {
|
|
126
|
+
setHeadComponents,
|
|
127
|
+
setHtmlAttributes,
|
|
128
|
+
setBodyAttributes,
|
|
129
|
+
setPreBodyComponents,
|
|
130
|
+
setPostBodyComponents,
|
|
131
|
+
setBodyProps,
|
|
132
|
+
pathname: pagePath,
|
|
133
|
+
loadPageDataSync: (p) => p === pagePath ? pageData : null,
|
|
134
|
+
bodyHtml: body,
|
|
135
|
+
scripts: input.scripts.map((name) => ({
|
|
136
|
+
name,
|
|
137
|
+
rel: "preload"
|
|
138
|
+
})),
|
|
139
|
+
styles: (input.stylesheets ?? []).map((name) => ({
|
|
140
|
+
name,
|
|
141
|
+
rel: "preload"
|
|
142
|
+
})),
|
|
143
|
+
pathPrefix: __PATH_PREFIX__
|
|
144
|
+
});
|
|
145
|
+
let head = {
|
|
146
|
+
meta: "",
|
|
147
|
+
rest: ""
|
|
148
|
+
};
|
|
149
|
+
if (headMode === "portal" && typeof pageResources.head === "function") {
|
|
150
|
+
const rendered = renderHead(createElement(HeadRoot, {
|
|
151
|
+
location,
|
|
152
|
+
pageResources,
|
|
153
|
+
runner,
|
|
154
|
+
ssr,
|
|
155
|
+
wrapRootPathname: null
|
|
156
|
+
}));
|
|
157
|
+
head = headMarkupParts(rendered.html, escapeRawText);
|
|
158
|
+
preamble += rendered.head;
|
|
159
|
+
}
|
|
160
|
+
setHtmlAttributes(ssr.htmlAttributes.html);
|
|
161
|
+
setBodyAttributes(ssr.htmlAttributes.body);
|
|
162
|
+
headComponents.push(createElement("meta", {
|
|
163
|
+
name: PREAMBLE_PLACEHOLDER,
|
|
164
|
+
key: PREAMBLE_PLACEHOLDER
|
|
165
|
+
}));
|
|
166
|
+
if (head.rest) headComponents.push(createElement("noscript", {
|
|
167
|
+
id: HEAD_REST_PLACEHOLDER,
|
|
168
|
+
key: HEAD_REST_PLACEHOLDER
|
|
169
|
+
}));
|
|
170
|
+
const styleElements = [];
|
|
171
|
+
for (const href of input.stylesheets ?? []) styleElements.push(createElement("link", {
|
|
172
|
+
rel: "stylesheet",
|
|
173
|
+
href,
|
|
174
|
+
key: `css-${href}`
|
|
175
|
+
}));
|
|
176
|
+
for (const { href, content } of input.inlineStyles ?? []) styleElements.push(createElement("style", {
|
|
177
|
+
"data-href": href,
|
|
178
|
+
"data-identity": "gatsby-global-css",
|
|
179
|
+
key: `style-${href}`,
|
|
180
|
+
dangerouslySetInnerHTML: { __html: content }
|
|
181
|
+
}));
|
|
182
|
+
headComponents = [...styleElements, ...headComponents];
|
|
183
|
+
for (const href of input.modulePreloads ?? []) headComponents.push(createElement("link", {
|
|
184
|
+
rel: "modulepreload",
|
|
185
|
+
href,
|
|
186
|
+
crossOrigin: "",
|
|
187
|
+
key: `mp-${href}`
|
|
188
|
+
}));
|
|
189
|
+
if (input.pageDataUrl && !input.inlinePageData) headComponents.push(createElement("link", {
|
|
190
|
+
rel: "preload",
|
|
191
|
+
href: input.pageDataUrl,
|
|
192
|
+
as: "fetch",
|
|
193
|
+
crossOrigin: "anonymous",
|
|
194
|
+
key: "page-data"
|
|
195
|
+
}));
|
|
196
|
+
const windowData = `/*<![CDATA[*/window.pagePath=${JSON.stringify(pagePath)};window.___renderedPath=${JSON.stringify(url)};window.___buildHash=${JSON.stringify(input.buildHash ?? "")};${input.inlinePageData ? `window.___pageData=${JSON.stringify(pageData).replace(/</g, "\\u003c")};` : ""}/*]]>*/`;
|
|
197
|
+
postBodyComponents.push(createElement("script", {
|
|
198
|
+
key: "script-loader",
|
|
199
|
+
id: "gatsby-script-loader",
|
|
200
|
+
dangerouslySetInnerHTML: { __html: windowData }
|
|
201
|
+
}));
|
|
202
|
+
for (const src of input.scripts) postBodyComponents.push(createElement("script", {
|
|
203
|
+
key: `script-${src}`,
|
|
204
|
+
type: "module",
|
|
205
|
+
src,
|
|
206
|
+
crossOrigin: ""
|
|
207
|
+
}));
|
|
208
|
+
headComponents = reorderHeadComponents(headComponents);
|
|
209
|
+
runner.apiRunner("onPreRenderHTML", {
|
|
210
|
+
getHeadComponents: () => headComponents,
|
|
211
|
+
replaceHeadComponents: (c) => headComponents = flatten(c),
|
|
212
|
+
getPreBodyComponents: () => preBodyComponents,
|
|
213
|
+
replacePreBodyComponents: (c) => preBodyComponents = flatten(c),
|
|
214
|
+
getPostBodyComponents: () => postBodyComponents,
|
|
215
|
+
replacePostBodyComponents: (c) => postBodyComponents = flatten(c),
|
|
216
|
+
pathname: pagePath,
|
|
217
|
+
pathPrefix: __PATH_PREFIX__
|
|
218
|
+
});
|
|
219
|
+
const HtmlComponent = Html?.default ?? Html;
|
|
220
|
+
const markup = renderDocument(createElement(HtmlComponent, {
|
|
221
|
+
...bodyProps,
|
|
222
|
+
headComponents: withKeys(headComponents, "head"),
|
|
223
|
+
htmlAttributes,
|
|
224
|
+
bodyAttributes,
|
|
225
|
+
preBodyComponents: withKeys(preBodyComponents, "pre"),
|
|
226
|
+
postBodyComponents: withKeys(postBodyComponents, "post"),
|
|
227
|
+
body,
|
|
228
|
+
path: pagePath
|
|
229
|
+
}));
|
|
230
|
+
const placeholder = `<meta name="${PREAMBLE_PLACEHOLDER}"/>`;
|
|
231
|
+
const restPlaceholder = `<noscript id="${HEAD_REST_PLACEHOLDER}"></noscript>`;
|
|
232
|
+
const insert = (html, marker, content) => html.includes(marker) ? html.replace(marker, () => content) : html.replace("</head>", () => `${content}</head>`);
|
|
233
|
+
let out = insert(markup, placeholder, preamble + head.meta + (input.headHtml ?? ""));
|
|
234
|
+
if (head.rest) out = insert(out, restPlaceholder, head.rest);
|
|
235
|
+
return {
|
|
236
|
+
html: /^<!doctype /i.test(out) ? out : `<!DOCTYPE html>${out}`,
|
|
237
|
+
staticQueryHashes: [...ssr.staticQueryUsage].sort()
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
export { components, renderPage, reorderHeadComponents, runner as ssrApiRunner };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/runtime/static-query.tsx
|
|
4
|
+
const NO_RESULTS = Object.freeze({});
|
|
5
|
+
/**
|
|
6
|
+
* Results of uncompiled (string/number id) static queries, Gatsby compatible – e.g. provided by
|
|
7
|
+
* tests or mocks. Not provided by the runtime: compiled queries carry their data (see
|
|
8
|
+
* `useStaticQuery`), and the stable default keeps `React.memo` consumers from re-rendering.
|
|
9
|
+
*/
|
|
10
|
+
const StaticQueryContext = createContext(NO_RESULTS);
|
|
11
|
+
StaticQueryContext.displayName = "StaticQueryContext";
|
|
12
|
+
/** SSR only: collects the static query hashes used while rendering a page (null in the browser) */
|
|
13
|
+
const StaticQueryUsageContext = createContext(null);
|
|
14
|
+
StaticQueryUsageContext.displayName = "StaticQueryUsageContext";
|
|
15
|
+
function isDataModule(q) {
|
|
16
|
+
return !!q && typeof q === "object" && "data" in q && "hash" in q;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `graphql` tag. goatly compiles all `graphql` tags at build time, so calling it at runtime
|
|
20
|
+
* means the query was not processed (e.g. the file was not transformed).
|
|
21
|
+
*/
|
|
22
|
+
function graphql(..._args) {
|
|
23
|
+
throw new Error("It appears like Gatsby is misconfigured. Gatsby related `graphql` calls are supposed to only be evaluated at compile time, and then compiled away. Unfortunately, something went wrong and the query was left in the compiled code.");
|
|
24
|
+
}
|
|
25
|
+
function useStaticQuery(query) {
|
|
26
|
+
const usage = useContext(StaticQueryUsageContext);
|
|
27
|
+
const context = useContext(StaticQueryContext);
|
|
28
|
+
if (isDataModule(query)) {
|
|
29
|
+
usage?.add(query.hash);
|
|
30
|
+
return query.data;
|
|
31
|
+
}
|
|
32
|
+
if (typeof query === "string" || typeof query === "number") {
|
|
33
|
+
const entry = context[String(query)];
|
|
34
|
+
if (entry) {
|
|
35
|
+
usage?.add(String(query));
|
|
36
|
+
return entry.data;
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`The result of this StaticQuery could not be fetched.\n\nThis is likely a bug in goatly and if refreshing the page does not fix it, please open an issue.`);
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`useStaticQuery was called without a compiled query. Make sure the \`graphql\` tag is imported from "gatsby" and used inline: useStaticQuery(graphql\`...\`)`);
|
|
41
|
+
}
|
|
42
|
+
function StaticQuery(props) {
|
|
43
|
+
const data = useStaticQuery(props.query);
|
|
44
|
+
const render = props.render ?? props.children;
|
|
45
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: render ? render(data) : null });
|
|
46
|
+
}
|
|
47
|
+
export { StaticQuery, StaticQueryContext, StaticQueryUsageContext, graphql, useStaticQuery };
|
package/dist/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,113 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goatly",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "A Gatsby-compatible static site generator built on Vite, Rolldown and React 18/19 – drop-in replacement for Gatsby's Node, SSR and Browser APIs.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"gatsby",
|
|
7
|
+
"goatly",
|
|
8
|
+
"react",
|
|
9
|
+
"ssg",
|
|
10
|
+
"static-site-generator",
|
|
11
|
+
"vite"
|
|
12
|
+
],
|
|
5
13
|
"license": "MIT",
|
|
6
14
|
"repository": {
|
|
7
15
|
"type": "git",
|
|
8
16
|
"url": "git+https://github.com/goatly-org/goatly.git",
|
|
9
17
|
"directory": "packages/goatly"
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"gatsby": "./bin/goatly.js",
|
|
21
|
+
"goatly": "./bin/goatly.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bin",
|
|
25
|
+
"dist",
|
|
26
|
+
"types"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "./dist/runtime/index.js",
|
|
30
|
+
"types": "./types/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./types/index.d.ts",
|
|
34
|
+
"default": "./dist/runtime/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./graphql": {
|
|
37
|
+
"types": "./types/graphql.d.ts",
|
|
38
|
+
"default": "./dist/graphql.js"
|
|
39
|
+
},
|
|
40
|
+
"./node": {
|
|
41
|
+
"types": "./types/node.d.ts",
|
|
42
|
+
"default": "./dist/node/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./reporter": {
|
|
45
|
+
"types": "./types/reporter.d.ts",
|
|
46
|
+
"default": "./dist/reporter.js"
|
|
47
|
+
},
|
|
48
|
+
"./utils": {
|
|
49
|
+
"default": "./dist/utils.js"
|
|
50
|
+
},
|
|
51
|
+
"./router": {
|
|
52
|
+
"types": "./types/router.d.ts",
|
|
53
|
+
"default": "./dist/runtime/router/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./runtime/*": "./dist/runtime/*.js",
|
|
56
|
+
"./compat/*": "./dist/compat/*",
|
|
57
|
+
"./package.json": "./package.json"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@sindresorhus/slugify": "^1.1.2",
|
|
61
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
62
|
+
"dayjs": "^1.11.23",
|
|
63
|
+
"graphql": "^16.15.0",
|
|
64
|
+
"graphql-compose": "^9.3.0",
|
|
65
|
+
"joi": "^18.3.1",
|
|
66
|
+
"magic-string": "^1.4.5",
|
|
67
|
+
"mrmime": "^2.0.1",
|
|
68
|
+
"msgpackr": "^2.1.4",
|
|
69
|
+
"node-object-hash": "^2.3.10",
|
|
70
|
+
"picocolors": "^1.1.1",
|
|
71
|
+
"picomatch": "^4.0.7",
|
|
72
|
+
"sirv": "^3.0.2",
|
|
73
|
+
"tinyglobby": "^0.2.17",
|
|
74
|
+
"vite": "^8.3.8",
|
|
75
|
+
"@goatly/wasm": "0.1.2"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@gql.tada/internal": "1.3.0",
|
|
79
|
+
"@types/picomatch": "^4.0.2",
|
|
80
|
+
"@types/react": "^19.2.0",
|
|
81
|
+
"@types/react-dom": "^19.2.0",
|
|
82
|
+
"joi-17": "npm:joi@^17.13.9",
|
|
83
|
+
"oxc-transform-react": "0.158.0",
|
|
84
|
+
"pino": "^10.4.0",
|
|
85
|
+
"react": "^19.3.1",
|
|
86
|
+
"react-dom": "^19.3.1",
|
|
87
|
+
"tsdown": "^0.23.7",
|
|
88
|
+
"typescript": "^6.0.3",
|
|
89
|
+
"winston": "^3.19.0"
|
|
90
|
+
},
|
|
91
|
+
"peerDependencies": {
|
|
92
|
+
"oxc-transform-react": ">=0.158.0 <1",
|
|
93
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
94
|
+
"react-compiler-runtime": "*",
|
|
95
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
96
|
+
},
|
|
97
|
+
"peerDependenciesMeta": {
|
|
98
|
+
"oxc-transform-react": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"react-compiler-runtime": {
|
|
102
|
+
"optional": true
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"engines": {
|
|
106
|
+
"node": "^22.22.3 || ^24.11.1 || >=25.1.0"
|
|
107
|
+
},
|
|
108
|
+
"scripts": {
|
|
109
|
+
"build": "tsdown",
|
|
110
|
+
"dev": "tsdown --watch",
|
|
111
|
+
"typecheck": "tsrs --noEmit -p ."
|
|
10
112
|
}
|
|
11
|
-
}
|
|
113
|
+
}
|