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,569 @@
|
|
|
1
|
+
import { compatEnv } from "./utils/env.js";
|
|
2
|
+
import { apiRunnerNode, waitForCascade } from "./api-runner.js";
|
|
3
|
+
import { closeCaches, commitCacheRun, getCache, mergeCacheRuns, openPluginCache, setCacheRoot, setCacheRun, startCacheRun } from "./cache.js";
|
|
4
|
+
import { releaseCoreUtilsMutexes } from "./compat/core-utils-lmdb.js";
|
|
5
|
+
import { LogFileDataStore } from "./datastore/logfile/index.js";
|
|
6
|
+
import { PLUGIN_CACHE_DIR, writeFileIfChanged } from "./cache-layout.js";
|
|
7
|
+
import { getChangedNodeTypes } from "./redux/node-changes.js";
|
|
8
|
+
import { loadConfigFile, normalizeConfig, readSitePackageJson, reportIgnoredConfig } from "./config/index.js";
|
|
9
|
+
import { getDataStore, getNode, setDataStore } from "./datastore/index.js";
|
|
10
|
+
import { createDataBridgePlugin, createProd404Plugin } from "./internal-plugins/data-bridge.js";
|
|
11
|
+
import { createPageCreatorPlugin } from "./internal-plugins/page-creator.js";
|
|
12
|
+
import { reportNotFoundPages } from "./not-found-pages.js";
|
|
13
|
+
import { loadPlugins } from "./plugins/load-plugins.js";
|
|
14
|
+
import { extractAndCompileQueries } from "./query/compile.js";
|
|
15
|
+
import { graphqlForApis } from "./query/graphql-runner.js";
|
|
16
|
+
import { emitter, store } from "./redux/index.js";
|
|
17
|
+
import reporter from "./reporter.js";
|
|
18
|
+
import { buildSchema, getInferenceMetadata, setInferenceBaseline, setInferenceSnapshot } from "./schema/index.js";
|
|
19
|
+
import { clearQueryEngineCaches } from "./schema/query-engine.js";
|
|
20
|
+
import { deleteNode } from "./actions/index.js";
|
|
21
|
+
import { pruneCompletedJobs } from "./actions/job-store.js";
|
|
22
|
+
import { sitePageNodesCreated, startSitePageNodes, startWorkerSitePageNodes, withoutSitePageReads, writeSitePageRecord } from "./site-page-nodes.js";
|
|
23
|
+
import { registerGatsbyModuleHooks } from "./compat/module-hooks.js";
|
|
24
|
+
import { useRenderer } from "./renderer.js";
|
|
25
|
+
import { createContentDigest } from "./utils/content-digest.js";
|
|
26
|
+
import { TEMP_MODULE, resolveApiFile } from "./loader/import-module.js";
|
|
27
|
+
import { runtimeName } from "./utils/runtime.js";
|
|
28
|
+
import { performance } from "node:perf_hooks";
|
|
29
|
+
import { isMainThread } from "node:worker_threads";
|
|
30
|
+
import path from "node:path";
|
|
31
|
+
import fs from "node:fs";
|
|
32
|
+
import v8 from "node:v8";
|
|
33
|
+
// src/node/bootstrap.ts
|
|
34
|
+
/** the phases of the bootstrap, in order (see `BootstrapResult.phases`) */
|
|
35
|
+
const BOOTSTRAP_PHASES = [
|
|
36
|
+
"config",
|
|
37
|
+
"cache",
|
|
38
|
+
"preBootstrap",
|
|
39
|
+
"schemaCustomization",
|
|
40
|
+
"sourcing",
|
|
41
|
+
"schema",
|
|
42
|
+
"createPages",
|
|
43
|
+
"extractQueries",
|
|
44
|
+
"postBootstrap"
|
|
45
|
+
];
|
|
46
|
+
const GOATLY_VERSION = "0.1.2";
|
|
47
|
+
const DEFAULT_EXTENSIONS = [
|
|
48
|
+
".mjs",
|
|
49
|
+
".js",
|
|
50
|
+
".jsx",
|
|
51
|
+
".wasm",
|
|
52
|
+
".json",
|
|
53
|
+
".tsx",
|
|
54
|
+
".ts"
|
|
55
|
+
];
|
|
56
|
+
async function loadEnvFiles(directory, command) {
|
|
57
|
+
const mode = compatEnv("GOATLY_ACTIVE_ENV") || process.env.NODE_ENV || (command === "build" ? "production" : "development");
|
|
58
|
+
const { loadEnv } = await import("vite");
|
|
59
|
+
const env = loadEnv(mode, directory, "");
|
|
60
|
+
for (const [key, value] of Object.entries(env)) if (process.env[key] === void 0) process.env[key] = value;
|
|
61
|
+
}
|
|
62
|
+
/** whether the nodes of the previous build were restored from the cache (main thread) */
|
|
63
|
+
let datastoreRestored = false;
|
|
64
|
+
/**
|
|
65
|
+
* Marker of the restored nodes: written after a completed build persisted them (and stored in its
|
|
66
|
+
* query state), removed as soon as a process may change them – incremental builds only trust
|
|
67
|
+
* node changes recorded relative to nodes they know (develop or a failed build may have changed
|
|
68
|
+
* the store, e.g. the sqlite store writes in place).
|
|
69
|
+
*/
|
|
70
|
+
let restoredGeneration;
|
|
71
|
+
/**
|
|
72
|
+
* Whether public/ was missing or empty when the run started (main thread): the build state then
|
|
73
|
+
* does not describe what is in public/, whatever is left of it in .cache.
|
|
74
|
+
*/
|
|
75
|
+
let publicDirWasMissing = false;
|
|
76
|
+
const generationFile = (cacheDir) => path.join(cacheDir, "data", "nodes-generation");
|
|
77
|
+
/** inference results of the persisted nodes (types are only scanned again when they changed) */
|
|
78
|
+
const inferenceStateFile = (cacheDir) => path.join(cacheDir, "data", "inference-state.v8");
|
|
79
|
+
const INFERENCE_STATE_VERSION = 1;
|
|
80
|
+
function computeCacheKey(directory, pluginKeys) {
|
|
81
|
+
const { flattenedPlugins, config } = store.getState();
|
|
82
|
+
const files = [];
|
|
83
|
+
for (const base of ["gatsby-config", "gatsby-node"]) {
|
|
84
|
+
const f = resolveApiFile(directory, base);
|
|
85
|
+
if (f) files.push(fs.readFileSync(f, "utf8"));
|
|
86
|
+
}
|
|
87
|
+
for (const name of [
|
|
88
|
+
"package.json",
|
|
89
|
+
"pnpm-lock.yaml",
|
|
90
|
+
"package-lock.json",
|
|
91
|
+
"yarn.lock",
|
|
92
|
+
"bun.lock"
|
|
93
|
+
]) try {
|
|
94
|
+
files.push(fs.readFileSync(path.join(directory, name), "utf8"));
|
|
95
|
+
} catch {}
|
|
96
|
+
for (const p of flattenedPlugins) {
|
|
97
|
+
if (!p.resolve || p.resolve.includes("node_modules") || !path.isAbsolute(p.resolve)) continue;
|
|
98
|
+
if (p.name === "default-site-plugin" || path.resolve(p.resolve) === path.resolve(directory)) continue;
|
|
99
|
+
files.push(...readPluginFiles(p.resolve));
|
|
100
|
+
}
|
|
101
|
+
return createContentDigest({
|
|
102
|
+
version: GOATLY_VERSION,
|
|
103
|
+
runtime: runtimeName.split(".")[0],
|
|
104
|
+
plugins: pluginKeys,
|
|
105
|
+
trailingSlash: config.trailingSlash,
|
|
106
|
+
files
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** contents of a local plugin's source files (bounded: 2,000 files of up to 2 MB) */
|
|
110
|
+
function readPluginFiles(dir) {
|
|
111
|
+
const out = [];
|
|
112
|
+
const walk = (current) => {
|
|
113
|
+
let entries;
|
|
114
|
+
try {
|
|
115
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
116
|
+
} catch {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
if (out.length >= 2e3) return;
|
|
122
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules" || TEMP_MODULE.test(entry.name)) continue;
|
|
123
|
+
const full = path.join(current, entry.name);
|
|
124
|
+
if (entry.isDirectory()) walk(full);
|
|
125
|
+
else if (entry.isFile()) try {
|
|
126
|
+
if (fs.statSync(full).size <= 2097152) out.push(`${path.relative(dir, full)}\0${fs.readFileSync(full, "utf8")}`);
|
|
127
|
+
} catch {}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) walk(dir);
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
function safeJson(v) {
|
|
134
|
+
try {
|
|
135
|
+
return JSON.stringify(v, (_k, val) => typeof val === "function" ? String(val) : val instanceof RegExp ? String(val) : val);
|
|
136
|
+
} catch {
|
|
137
|
+
return "";
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function findRootAncestor(node) {
|
|
141
|
+
let current = node;
|
|
142
|
+
const seen = /* @__PURE__ */ new Set();
|
|
143
|
+
while (current.parent && !seen.has(current.id)) {
|
|
144
|
+
seen.add(current.id);
|
|
145
|
+
const parent = getNode(current.parent);
|
|
146
|
+
if (!parent) break;
|
|
147
|
+
current = parent;
|
|
148
|
+
}
|
|
149
|
+
return current;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Deletes nodes whose root ancestor was not created/touched during sourcing (Gatsby semantics).
|
|
153
|
+
* Stores with type and parent indexes (lazy stores) are checked without loading every node, and
|
|
154
|
+
* stores that know the nodes' owners skip the nodes of stateful source plugins without loading
|
|
155
|
+
* them.
|
|
156
|
+
*/
|
|
157
|
+
function deleteStaleNodes() {
|
|
158
|
+
const { nodesTouched, statefulSourcePlugins } = store.getState();
|
|
159
|
+
const ds = getDataStore();
|
|
160
|
+
const stale = [];
|
|
161
|
+
const isStateful = (node) => !!node && statefulSourcePlugins.has(node.internal.owner ?? "");
|
|
162
|
+
/** true when the store knows the node's owner and it is stateful (nothing is read) */
|
|
163
|
+
const ownerIsStateful = (id) => {
|
|
164
|
+
const owner = statefulSourcePlugins.size ? ds.getNodeOwner?.(id) : void 0;
|
|
165
|
+
return owner !== void 0 && statefulSourcePlugins.has(owner);
|
|
166
|
+
};
|
|
167
|
+
if (typeof ds.getNodeIdsByType === "function" && typeof ds.getNodeParent === "function") {
|
|
168
|
+
const rootIdOf = (id) => {
|
|
169
|
+
const seen = /* @__PURE__ */ new Set();
|
|
170
|
+
let current = id;
|
|
171
|
+
for (;;) {
|
|
172
|
+
seen.add(current);
|
|
173
|
+
const parent = ds.getNodeParent(current);
|
|
174
|
+
if (!parent || seen.has(parent) || ds.getNodeType?.(parent) === void 0) return current;
|
|
175
|
+
current = parent;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
for (const type of ds.getTypes()) {
|
|
179
|
+
if (type === "SitePage") continue;
|
|
180
|
+
for (const id of ds.getNodeIdsByType(type)) {
|
|
181
|
+
const rootId = rootIdOf(id);
|
|
182
|
+
if (nodesTouched.has(rootId)) continue;
|
|
183
|
+
if (ownerIsStateful(id) || rootId !== id && ownerIsStateful(rootId)) continue;
|
|
184
|
+
const node = getNode(id);
|
|
185
|
+
if (!node || isStateful(node) || isStateful(getNode(rootId))) continue;
|
|
186
|
+
stale.push(node);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} else for (const node of ds.iterateNodes()) {
|
|
190
|
+
if (node.internal.type === "SitePage" || isStateful(node)) continue;
|
|
191
|
+
const root = findRootAncestor(node);
|
|
192
|
+
if (!nodesTouched.has(root.id) && !isStateful(root)) stale.push(node);
|
|
193
|
+
}
|
|
194
|
+
for (const node of stale) if (getNode(node.id)) deleteNode(node, { name: node.internal.owner ?? "internal" });
|
|
195
|
+
if (stale.length) reporter.verbose(`Deleted ${stale.length} stale nodes`);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* SitePage nodes of pages that were not created again (unchanged pages keep their node) – all of
|
|
199
|
+
* them while SitePage nodes aren't created (the persisted nodes of a build that read them).
|
|
200
|
+
*/
|
|
201
|
+
function deleteOrphanSitePages() {
|
|
202
|
+
const { pages } = store.getState();
|
|
203
|
+
const ds = getDataStore();
|
|
204
|
+
const ids = typeof ds.getNodeIdsByType === "function" ? ds.getNodeIdsByType("SitePage") : [...ds.iterateNodesByType("SitePage")].map((n) => n.id);
|
|
205
|
+
const created = sitePageNodesCreated();
|
|
206
|
+
let deleted = 0;
|
|
207
|
+
withoutSitePageReads(() => {
|
|
208
|
+
for (const id of ids) {
|
|
209
|
+
if (created && id.startsWith("SitePage ") && pages.has(id.slice(9))) continue;
|
|
210
|
+
deleteNode(id, { name: "internal-data-bridge" });
|
|
211
|
+
deleted++;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
if (deleted) reporter.verbose(created ? `Deleted ${deleted} SitePage nodes of removed pages` : `Deleted ${deleted} SitePage nodes: the previous build did not read them`);
|
|
215
|
+
}
|
|
216
|
+
/** Deletes the plugin caches (`cache`, `getCache`) and the given other entries of `.cache`. */
|
|
217
|
+
function deleteCaches(cacheDir, other = []) {
|
|
218
|
+
closeCaches();
|
|
219
|
+
for (const sub of [
|
|
220
|
+
...other,
|
|
221
|
+
"caches",
|
|
222
|
+
PLUGIN_CACHE_DIR
|
|
223
|
+
]) fs.rmSync(path.join(cacheDir, sub), {
|
|
224
|
+
recursive: true,
|
|
225
|
+
force: true
|
|
226
|
+
});
|
|
227
|
+
setCacheRoot(cacheDir);
|
|
228
|
+
startCacheRun();
|
|
229
|
+
}
|
|
230
|
+
/** Whether `dir` has no entries; also when it is missing or not a readable directory. */
|
|
231
|
+
function isMissingOrEmpty(dir) {
|
|
232
|
+
let handle;
|
|
233
|
+
try {
|
|
234
|
+
handle = fs.opendirSync(dir);
|
|
235
|
+
return handle.readSync() === null;
|
|
236
|
+
} catch {
|
|
237
|
+
return true;
|
|
238
|
+
} finally {
|
|
239
|
+
handle?.closeSync();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async function initDataStore(config, cacheDir) {
|
|
243
|
+
let ds;
|
|
244
|
+
if (typeof config.datastore === "function") ds = await config.datastore({ cacheDir });
|
|
245
|
+
else if (config.datastore) ds = config.datastore;
|
|
246
|
+
else ds = new LogFileDataStore({ cacheDir });
|
|
247
|
+
setDataStore(ds);
|
|
248
|
+
return ds;
|
|
249
|
+
}
|
|
250
|
+
async function loadSiteAndPlugins(directory, options, dirs, renderer) {
|
|
251
|
+
const { cacheDir, publicDir } = dirs;
|
|
252
|
+
let activity = reporter.activityTimer("load gatsby config");
|
|
253
|
+
activity.start();
|
|
254
|
+
const { config: rawConfig } = await loadConfigFile(directory);
|
|
255
|
+
const config = normalizeConfig(typeof rawConfig === "function" ? await rawConfig({}) : rawConfig);
|
|
256
|
+
try {
|
|
257
|
+
await useRenderer(renderer === void 0 ? config.renderer : renderer ?? void 0, directory);
|
|
258
|
+
} catch (e) {
|
|
259
|
+
reporter.panic(e.message, e);
|
|
260
|
+
}
|
|
261
|
+
if (config.reporter && isMainThread && reporter.transportSource !== "api") reporter.setTransports(config.reporter, "config");
|
|
262
|
+
reportIgnoredConfig(config);
|
|
263
|
+
const sitePackageJson = readSitePackageJson(directory);
|
|
264
|
+
store.dispatch({
|
|
265
|
+
type: "SET_PROGRAM",
|
|
266
|
+
payload: {
|
|
267
|
+
directory,
|
|
268
|
+
command: options.command,
|
|
269
|
+
sitePackageJson,
|
|
270
|
+
prefixPaths: options.command !== "develop" && (!!options.prefixPaths || process.env.PREFIX_PATHS === "true"),
|
|
271
|
+
host: options.host ?? "localhost",
|
|
272
|
+
port: options.port ?? 8e3,
|
|
273
|
+
verbose: !!options.verbose,
|
|
274
|
+
extensions: DEFAULT_EXTENSIONS,
|
|
275
|
+
browserslist: [],
|
|
276
|
+
publicDir,
|
|
277
|
+
cacheDir
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
activity.end();
|
|
281
|
+
activity = reporter.activityTimer("load plugins");
|
|
282
|
+
activity.start();
|
|
283
|
+
const flattenedPlugins = await loadPlugins({
|
|
284
|
+
rootDir: directory,
|
|
285
|
+
plugins: config.plugins,
|
|
286
|
+
siteMetadata: config.siteMetadata,
|
|
287
|
+
internalPluginsBefore: [createDataBridgePlugin(), createProd404Plugin()],
|
|
288
|
+
createPageCreator: (opts) => createPageCreatorPlugin(opts)
|
|
289
|
+
});
|
|
290
|
+
store.dispatch({
|
|
291
|
+
type: "SET_SITE_CONFIG",
|
|
292
|
+
payload: { ...config }
|
|
293
|
+
});
|
|
294
|
+
store.dispatch({
|
|
295
|
+
type: "SET_SITE_FLATTENED_PLUGINS",
|
|
296
|
+
payload: flattenedPlugins
|
|
297
|
+
});
|
|
298
|
+
activity.end();
|
|
299
|
+
const extraExtensions = (await apiRunnerNode("resolvableExtensions", { traceId: "initial-resolvableExtensions" })).flat();
|
|
300
|
+
store.dispatch({
|
|
301
|
+
type: "SET_PROGRAM",
|
|
302
|
+
payload: { extensions: [.../* @__PURE__ */ new Set([...DEFAULT_EXTENSIONS, ...extraExtensions.filter((e) => typeof e === "string")])] }
|
|
303
|
+
});
|
|
304
|
+
return { config };
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Runs Gatsby's bootstrap sequence:
|
|
308
|
+
* config → plugins → onPreInit → cache → onPluginInit → onPreBootstrap →
|
|
309
|
+
* createSchemaCustomization → sourceNodes → schema (setFieldsOnGraphQLNodeType, createResolvers) →
|
|
310
|
+
* createPages → createPagesStatefully → query extraction → onPostBootstrap.
|
|
311
|
+
*/
|
|
312
|
+
async function bootstrap(options) {
|
|
313
|
+
const phases = {};
|
|
314
|
+
let phaseStart = performance.now();
|
|
315
|
+
const phaseDone = (phase) => {
|
|
316
|
+
const end = performance.now();
|
|
317
|
+
phases[phase] = [phaseStart, end];
|
|
318
|
+
phaseStart = end;
|
|
319
|
+
};
|
|
320
|
+
const directory = path.resolve(options.directory);
|
|
321
|
+
const cacheDir = path.join(directory, ".cache");
|
|
322
|
+
const publicDir = path.join(directory, "public");
|
|
323
|
+
const metaFile = path.join(cacheDir, "goatly-cache.json");
|
|
324
|
+
const publicDirMissing = isMissingOrEmpty(publicDir);
|
|
325
|
+
publicDirWasMissing = publicDirMissing;
|
|
326
|
+
const pluginCacheExisted = ["caches", PLUGIN_CACHE_DIR].some((sub) => fs.existsSync(path.join(cacheDir, sub)));
|
|
327
|
+
const cacheIncomplete = publicDirMissing && (pluginCacheExisted || fs.existsSync(metaFile));
|
|
328
|
+
if (process.cwd() !== directory) process.chdir(directory);
|
|
329
|
+
if (options.verbose) reporter.setVerbose(true);
|
|
330
|
+
reporter.isBuild = options.command === "build";
|
|
331
|
+
await loadEnvFiles(directory, options.command);
|
|
332
|
+
registerGatsbyModuleHooks({ build: options.command === "build" });
|
|
333
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
334
|
+
setCacheRoot(cacheDir);
|
|
335
|
+
releaseCoreUtilsMutexes(cacheDir);
|
|
336
|
+
const reverted = startCacheRun();
|
|
337
|
+
let activity;
|
|
338
|
+
const { config } = await loadSiteAndPlugins(directory, options, {
|
|
339
|
+
cacheDir,
|
|
340
|
+
publicDir
|
|
341
|
+
});
|
|
342
|
+
if (reverted) {
|
|
343
|
+
const entries = reverted === 1 ? "entry" : "entries";
|
|
344
|
+
reporter.info(`Reverted ${reverted} plugin cache ${entries} written after the last run that saved its nodes`);
|
|
345
|
+
}
|
|
346
|
+
const pluginKeys = store.getState().flattenedPlugins.map((p) => `${p.name}@${p.version}:${safeJson(p.pluginOptions)}`);
|
|
347
|
+
await apiRunnerNode("onPreInit", {});
|
|
348
|
+
phaseDone("config");
|
|
349
|
+
activity = reporter.activityTimer("initialize cache");
|
|
350
|
+
activity.start();
|
|
351
|
+
const cacheKey = computeCacheKey(directory, pluginKeys);
|
|
352
|
+
let previousKey;
|
|
353
|
+
try {
|
|
354
|
+
previousKey = JSON.parse(fs.readFileSync(metaFile, "utf8")).cacheKey;
|
|
355
|
+
} catch {}
|
|
356
|
+
const keyChanged = !!previousKey && previousKey !== cacheKey;
|
|
357
|
+
if (keyChanged) reporter.info("We've detected changes to plugins, config or gatsby-node – deleting the cache");
|
|
358
|
+
if (cacheIncomplete) reporter.info("We've detected an incomplete cache (public is missing or empty) – deleting the cache");
|
|
359
|
+
if (keyChanged || cacheIncomplete) deleteCaches(cacheDir, ["data"]);
|
|
360
|
+
const cacheDeleted = keyChanged || cacheIncomplete;
|
|
361
|
+
fs.mkdirSync(path.join(publicDir, "static"), { recursive: true });
|
|
362
|
+
const ds = await initDataStore(config, cacheDir);
|
|
363
|
+
if (!ds.load && pluginCacheExisted && !cacheDeleted) reporter.warn(`The datastore${ds.name ? ` "${ds.name}"` : ""} does not restore nodes (no load()), but the plugin caches of an earlier run are kept: source plugins that keep a sync token in their cache can miss content in this run. Use a datastore that restores its nodes (the default logfile store or SQLite) or run \`gatsby clean\` before each run.`);
|
|
364
|
+
const cacheRestored = previousKey === cacheKey && !cacheDeleted && ds.load ? await ds.load() : false;
|
|
365
|
+
if (!cacheRestored && ds.load && pluginCacheExisted && !cacheDeleted) {
|
|
366
|
+
reporter.info("No nodes were restored from the cache – deleting the plugin caches");
|
|
367
|
+
deleteCaches(cacheDir);
|
|
368
|
+
}
|
|
369
|
+
clearQueryEngineCaches();
|
|
370
|
+
datastoreRestored = cacheRestored;
|
|
371
|
+
restoredGeneration = void 0;
|
|
372
|
+
if (cacheRestored) {
|
|
373
|
+
try {
|
|
374
|
+
restoredGeneration = fs.readFileSync(generationFile(cacheDir), "utf8").trim() || void 0;
|
|
375
|
+
} catch {}
|
|
376
|
+
let max = 0;
|
|
377
|
+
if (typeof ds.getMaxNodeCounter === "function") max = ds.getMaxNodeCounter();
|
|
378
|
+
else for (const n of ds.iterateNodes()) if ((n.internal.counter ?? 0) > max) max = n.internal.counter ?? 0;
|
|
379
|
+
store.getState().status.LAST_NODE_COUNTER = max;
|
|
380
|
+
reporter.verbose(`Restored ${ds.countNodes()} nodes from cache`);
|
|
381
|
+
}
|
|
382
|
+
startSitePageNodes({
|
|
383
|
+
cacheDir,
|
|
384
|
+
restored: cacheRestored
|
|
385
|
+
});
|
|
386
|
+
fs.rmSync(generationFile(cacheDir), { force: true });
|
|
387
|
+
setInferenceBaseline(restoredGeneration ? readInferenceState(cacheDir) : void 0);
|
|
388
|
+
writeFileIfChanged(metaFile, JSON.stringify({
|
|
389
|
+
cacheKey,
|
|
390
|
+
version: GOATLY_VERSION
|
|
391
|
+
}));
|
|
392
|
+
fs.rmSync(path.join(cacheDir, "fragments"), {
|
|
393
|
+
recursive: true,
|
|
394
|
+
force: true
|
|
395
|
+
});
|
|
396
|
+
fs.mkdirSync(path.join(cacheDir, "fragments"), { recursive: true });
|
|
397
|
+
const prunedJobs = await pruneCompletedJobs();
|
|
398
|
+
if (prunedJobs) reporter.verbose(`Deleted ${prunedJobs} completed job(s) whose files are gone`);
|
|
399
|
+
activity.end();
|
|
400
|
+
phaseDone("cache");
|
|
401
|
+
await apiRunnerNode("onPluginInit", {});
|
|
402
|
+
await apiRunnerNode("onPreBootstrap", {});
|
|
403
|
+
phaseDone("preBootstrap");
|
|
404
|
+
store.getState().nodesTouched.clear();
|
|
405
|
+
activity = reporter.activityTimer("createSchemaCustomization");
|
|
406
|
+
activity.start();
|
|
407
|
+
await apiRunnerNode("createSchemaCustomization", { traceId: "initial-createSchemaCustomization" });
|
|
408
|
+
activity.end();
|
|
409
|
+
phaseDone("schemaCustomization");
|
|
410
|
+
activity = reporter.activityTimer("source and transform nodes");
|
|
411
|
+
activity.start();
|
|
412
|
+
await apiRunnerNode("sourceNodes", {
|
|
413
|
+
traceId: "initial-sourceNodes",
|
|
414
|
+
waitForCascadingActions: true,
|
|
415
|
+
webhookBody: {}
|
|
416
|
+
});
|
|
417
|
+
await waitForCascade("initial-sourceNodes");
|
|
418
|
+
deleteStaleNodes();
|
|
419
|
+
activity.setStatus(`${ds.countNodes()} nodes`);
|
|
420
|
+
activity.end();
|
|
421
|
+
phaseDone("sourcing");
|
|
422
|
+
activity = reporter.activityTimer("building schema");
|
|
423
|
+
activity.start();
|
|
424
|
+
await buildSchema();
|
|
425
|
+
activity.end();
|
|
426
|
+
phaseDone("schema");
|
|
427
|
+
let queries = {
|
|
428
|
+
pageQueries: /* @__PURE__ */ new Map(),
|
|
429
|
+
staticQueries: /* @__PURE__ */ new Map(),
|
|
430
|
+
staticQueriesByFile: /* @__PURE__ */ new Map(),
|
|
431
|
+
fragments: /* @__PURE__ */ new Map(),
|
|
432
|
+
queries: /* @__PURE__ */ new Map(),
|
|
433
|
+
usesGraphqlTypes: false,
|
|
434
|
+
errors: 0
|
|
435
|
+
};
|
|
436
|
+
if (!options.skipPages) {
|
|
437
|
+
activity = reporter.activityTimer("createPages");
|
|
438
|
+
activity.start();
|
|
439
|
+
await apiRunnerNode("createPages", {
|
|
440
|
+
graphql: graphqlForApis,
|
|
441
|
+
traceId: "initial-createPages",
|
|
442
|
+
waitForCascadingActions: true
|
|
443
|
+
});
|
|
444
|
+
await waitForCascade("initial-createPages");
|
|
445
|
+
activity.end();
|
|
446
|
+
activity = reporter.activityTimer("createPagesStatefully");
|
|
447
|
+
activity.start();
|
|
448
|
+
await apiRunnerNode("createPagesStatefully", {
|
|
449
|
+
graphql: graphqlForApis,
|
|
450
|
+
traceId: "initial-createPagesStatefully",
|
|
451
|
+
waitForCascadingActions: true
|
|
452
|
+
});
|
|
453
|
+
await waitForCascade("initial-createPagesStatefully");
|
|
454
|
+
await waitForCascade();
|
|
455
|
+
deleteOrphanSitePages();
|
|
456
|
+
activity.setStatus(`${store.getState().pages.size} pages`);
|
|
457
|
+
activity.end();
|
|
458
|
+
phaseDone("createPages");
|
|
459
|
+
reportNotFoundPages();
|
|
460
|
+
activity = reporter.activityTimer("extract queries from components");
|
|
461
|
+
activity.start();
|
|
462
|
+
queries = await extractAndCompileQueries();
|
|
463
|
+
activity.end();
|
|
464
|
+
phaseDone("extractQueries");
|
|
465
|
+
}
|
|
466
|
+
await apiRunnerNode("onPostBootstrap", {});
|
|
467
|
+
store.dispatch({
|
|
468
|
+
type: "BOOTSTRAP_FINISHED",
|
|
469
|
+
payload: {}
|
|
470
|
+
});
|
|
471
|
+
reporter.info(`bootstrap finished - ${runtimeName}`);
|
|
472
|
+
phaseDone("postBootstrap");
|
|
473
|
+
return {
|
|
474
|
+
queries,
|
|
475
|
+
cacheRestored,
|
|
476
|
+
phases
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Bootstrap for query workers (parallel query running): loads config & plugins, restores nodes
|
|
481
|
+
* from the datastore snapshot written by the main process, runs `onPluginInit` and rebuilds the
|
|
482
|
+
* schema (createSchemaCustomization, setFieldsOnGraphQLNodeType, createResolvers).
|
|
483
|
+
*/
|
|
484
|
+
async function bootstrapWorker(options) {
|
|
485
|
+
const directory = path.resolve(options.directory);
|
|
486
|
+
reporter.isBuild = true;
|
|
487
|
+
registerGatsbyModuleHooks({ build: true });
|
|
488
|
+
const cacheDir = path.join(directory, ".cache");
|
|
489
|
+
const publicDir = path.join(directory, "public");
|
|
490
|
+
setCacheRoot(cacheDir);
|
|
491
|
+
const pluginCache = openPluginCache();
|
|
492
|
+
if (!pluginCache.shared) throw new Error(`query worker: could not open the plugin cache: ${pluginCache.error}`);
|
|
493
|
+
setCacheRun(options.cacheRun);
|
|
494
|
+
const quiet = reporter.silent;
|
|
495
|
+
reporter.silent = true;
|
|
496
|
+
try {
|
|
497
|
+
const { config } = await loadSiteAndPlugins(directory, {
|
|
498
|
+
command: "build",
|
|
499
|
+
prefixPaths: options.prefixPaths
|
|
500
|
+
}, {
|
|
501
|
+
cacheDir,
|
|
502
|
+
publicDir
|
|
503
|
+
}, options.renderer);
|
|
504
|
+
const ds = await initDataStore(config, cacheDir);
|
|
505
|
+
if (!ds.load || !await ds.load()) throw new Error("query worker: could not load the node snapshot");
|
|
506
|
+
startWorkerSitePageNodes({ available: options.sitePageNodes !== false });
|
|
507
|
+
clearQueryEngineCaches();
|
|
508
|
+
await apiRunnerNode("onPluginInit", {});
|
|
509
|
+
await apiRunnerNode("createSchemaCustomization", { traceId: "initial-createSchemaCustomization" });
|
|
510
|
+
let snapshot;
|
|
511
|
+
try {
|
|
512
|
+
if (options.inferenceFile) snapshot = v8.deserialize(fs.readFileSync(options.inferenceFile));
|
|
513
|
+
} catch {}
|
|
514
|
+
setInferenceSnapshot(snapshot);
|
|
515
|
+
try {
|
|
516
|
+
await buildSchema();
|
|
517
|
+
} finally {
|
|
518
|
+
setInferenceSnapshot(void 0);
|
|
519
|
+
}
|
|
520
|
+
} finally {
|
|
521
|
+
reporter.silent = quiet;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Persists plugin caches and nodes, and makes the run's plugin cache writes permanent with the
|
|
526
|
+
* nodes. `generation`: the marker of a completed build (see `restoredGeneration`), written once the
|
|
527
|
+
* nodes are on disk.
|
|
528
|
+
*/
|
|
529
|
+
async function persistState(generation) {
|
|
530
|
+
const { cacheDir } = store.getState().program;
|
|
531
|
+
if (!generation && cacheDir) {
|
|
532
|
+
fs.rmSync(generationFile(cacheDir), { force: true });
|
|
533
|
+
fs.rmSync(inferenceStateFile(cacheDir), { force: true });
|
|
534
|
+
}
|
|
535
|
+
await commitCacheRun(() => getDataStore().persist?.());
|
|
536
|
+
mergeCacheRuns();
|
|
537
|
+
if (cacheDir) writeSitePageRecord(cacheDir);
|
|
538
|
+
if (generation) {
|
|
539
|
+
fs.mkdirSync(path.join(cacheDir, "data"), { recursive: true });
|
|
540
|
+
writeInferenceState(cacheDir);
|
|
541
|
+
fs.writeFileSync(generationFile(cacheDir), generation);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Read only with a restored marker. Written before the marker and removed with it (the marker is
|
|
546
|
+
* removed when a run starts): it belongs to the nodes the marker vouches for. (Without the
|
|
547
|
+
* generation, which would change the file with every build.)
|
|
548
|
+
*/
|
|
549
|
+
function readInferenceState(cacheDir) {
|
|
550
|
+
try {
|
|
551
|
+
const state = v8.deserialize(fs.readFileSync(inferenceStateFile(cacheDir)));
|
|
552
|
+
if (state?.version === INFERENCE_STATE_VERSION) return state.metadata;
|
|
553
|
+
} catch {}
|
|
554
|
+
}
|
|
555
|
+
function writeInferenceState(cacheDir) {
|
|
556
|
+
const file = inferenceStateFile(cacheDir);
|
|
557
|
+
const metadata = getInferenceMetadata();
|
|
558
|
+
if (!metadata) {
|
|
559
|
+
fs.rmSync(file, { force: true });
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const changed = getChangedNodeTypes();
|
|
563
|
+
const valid = new Map([...metadata].filter(([type]) => !changed.has(type)));
|
|
564
|
+
writeFileIfChanged(file, v8.serialize({
|
|
565
|
+
version: INFERENCE_STATE_VERSION,
|
|
566
|
+
metadata: valid
|
|
567
|
+
}));
|
|
568
|
+
}
|
|
569
|
+
export { BOOTSTRAP_PHASES, bootstrap, bootstrapWorker, datastoreRestored, deleteStaleNodes, emitter, getCache, persistState, publicDirWasMissing, restoredGeneration };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { slash } from "../utils/paths.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
// src/node/build/assets.ts
|
|
5
|
+
function readManifest(publicDir) {
|
|
6
|
+
const file = path.join(publicDir, ".vite", "manifest.json");
|
|
7
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The manifest without its keys (source paths, relative to the project root, so for modules
|
|
11
|
+
* outside it, like goatly's client entry, they depend on where the project is): its chunks
|
|
12
|
+
* by output file (content-hashed), with what they import as output files too. What the build hash
|
|
13
|
+
* is computed from, so that the same output gives the same hash wherever the site is built (on
|
|
14
|
+
* Windows the paths across drives differ even more, e.g. a temp dir on C: and the package on D:).
|
|
15
|
+
*/
|
|
16
|
+
function manifestFingerprint(manifest) {
|
|
17
|
+
const file = (key) => manifest[key]?.file ?? key;
|
|
18
|
+
return `[${Object.values(manifest).map((c) => JSON.stringify({
|
|
19
|
+
file: c.file,
|
|
20
|
+
name: c.name,
|
|
21
|
+
isEntry: c.isEntry,
|
|
22
|
+
isDynamicEntry: c.isDynamicEntry,
|
|
23
|
+
imports: c.imports?.map(file),
|
|
24
|
+
dynamicImports: c.dynamicImports?.map(file),
|
|
25
|
+
css: c.css,
|
|
26
|
+
assets: c.assets
|
|
27
|
+
})).sort().join(",")}]`;
|
|
28
|
+
}
|
|
29
|
+
/** entries of AssetResolver's cache (MDX pages have a component path each: bounded) */
|
|
30
|
+
const CACHE_ENTRIES = 1e3;
|
|
31
|
+
/** Resolves script/modulepreload/stylesheet URLs for page component chunks from the Vite manifest. */
|
|
32
|
+
var AssetResolver = class {
|
|
33
|
+
manifest;
|
|
34
|
+
root;
|
|
35
|
+
base;
|
|
36
|
+
cache = /* @__PURE__ */ new Map();
|
|
37
|
+
entryKey;
|
|
38
|
+
constructor(manifest, root, base) {
|
|
39
|
+
this.manifest = manifest;
|
|
40
|
+
this.root = root;
|
|
41
|
+
this.base = base;
|
|
42
|
+
this.entryKey = Object.keys(manifest).find((k) => manifest[k].isEntry) ?? "";
|
|
43
|
+
if (!this.entryKey) throw new Error("Client entry not found in the Vite manifest");
|
|
44
|
+
}
|
|
45
|
+
url(file) {
|
|
46
|
+
return `${this.base}${file}`;
|
|
47
|
+
}
|
|
48
|
+
collect(key, js, css, seen) {
|
|
49
|
+
if (seen.has(key)) return;
|
|
50
|
+
seen.add(key);
|
|
51
|
+
const chunk = this.manifest[key];
|
|
52
|
+
if (!chunk) return;
|
|
53
|
+
js.add(chunk.file);
|
|
54
|
+
for (const c of chunk.css ?? []) css.add(c);
|
|
55
|
+
for (const k of chunk.imports ?? []) this.collect(k, js, css, seen);
|
|
56
|
+
}
|
|
57
|
+
keyFor(componentPath) {
|
|
58
|
+
const rel = slash(path.relative(this.root, componentPath));
|
|
59
|
+
if (this.manifest[rel]) return rel;
|
|
60
|
+
const base = rel.split("?")[0];
|
|
61
|
+
if (this.manifest[base]) return base;
|
|
62
|
+
return Object.keys(this.manifest).find((k) => this.manifest[k].src === rel || this.manifest[k].src === base);
|
|
63
|
+
}
|
|
64
|
+
forComponents(componentPaths) {
|
|
65
|
+
const cacheKey = componentPaths.join("|");
|
|
66
|
+
const cached = this.cache.get(cacheKey);
|
|
67
|
+
if (cached) return cached;
|
|
68
|
+
const entryJs = /* @__PURE__ */ new Set();
|
|
69
|
+
const css = /* @__PURE__ */ new Set();
|
|
70
|
+
const seen = /* @__PURE__ */ new Set();
|
|
71
|
+
this.collect(this.entryKey, entryJs, css, seen);
|
|
72
|
+
const pageJs = /* @__PURE__ */ new Set();
|
|
73
|
+
for (const c of componentPaths) {
|
|
74
|
+
const key = this.keyFor(c);
|
|
75
|
+
if (key) this.collect(key, pageJs, css, seen);
|
|
76
|
+
}
|
|
77
|
+
const entryFile = this.manifest[this.entryKey].file;
|
|
78
|
+
const preloads = [...entryJs, ...pageJs].filter((f) => f !== entryFile);
|
|
79
|
+
const assets = {
|
|
80
|
+
scripts: [this.url(entryFile)],
|
|
81
|
+
modulePreloads: preloads.map((f) => this.url(f)),
|
|
82
|
+
stylesheets: [...css].map((f) => this.url(f))
|
|
83
|
+
};
|
|
84
|
+
if (this.cache.size >= CACHE_ENTRIES) this.cache.clear();
|
|
85
|
+
this.cache.set(cacheKey, assets);
|
|
86
|
+
return assets;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gatsby's chunk-map.json: the JS and CSS files each page component needs beyond the client entry,
|
|
90
|
+
* by component chunk name. The client prefetches them (`<link rel=prefetch>`) for visible links,
|
|
91
|
+
* without running page code.
|
|
92
|
+
*/
|
|
93
|
+
chunkMap(components) {
|
|
94
|
+
const entryJs = /* @__PURE__ */ new Set();
|
|
95
|
+
const entryCss = /* @__PURE__ */ new Set();
|
|
96
|
+
const seen = /* @__PURE__ */ new Set();
|
|
97
|
+
this.collect(this.entryKey, entryJs, entryCss, seen);
|
|
98
|
+
const map = {};
|
|
99
|
+
for (const [chunkName, componentPath] of components) {
|
|
100
|
+
const key = this.keyFor(componentPath);
|
|
101
|
+
if (!key) continue;
|
|
102
|
+
const js = /* @__PURE__ */ new Set();
|
|
103
|
+
const css = /* @__PURE__ */ new Set();
|
|
104
|
+
this.collect(key, js, css, new Set(seen));
|
|
105
|
+
map[chunkName] = [...js, ...[...css].filter((c) => !entryCss.has(c))].map((f) => this.url(f));
|
|
106
|
+
}
|
|
107
|
+
return map;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
export { AssetResolver, manifestFingerprint, readManifest };
|