goatly 0.0.0-stage → 0.1.1
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/LICENSE +24 -0
- package/README.md +854 -2
- package/bin/goatly.js +91 -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 +539 -0
- package/dist/node/build/assets.js +110 -0
- package/dist/node/build/incremental.js +208 -0
- package/dist/node/build/index.js +752 -0
- package/dist/node/build/memory-governor.js +448 -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 +54 -0
- package/dist/node/build/partitioned-state.js +258 -0
- package/dist/node/build/query-worker.js +536 -0
- package/dist/node/build/query-workers.js +832 -0
- package/dist/node/build/render-worker.js +131 -0
- package/dist/node/build/state.js +24 -0
- package/dist/node/build/timing-breakdown.js +155 -0
- package/dist/node/build/worker-pool.js +236 -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/create-node-id.js +51 -0
- package/dist/node/utils/env.js +24 -0
- package/dist/node/utils/fs-retry.js +74 -0
- package/dist/node/utils/memory-signals.js +410 -0
- package/dist/node/utils/memory.js +400 -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 +281 -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 +299 -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 +110 -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 +380 -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,619 @@
|
|
|
1
|
+
import { getDataStore, getNode, nodeTypeOf } from "../datastore/index.js";
|
|
2
|
+
import { store } from "../redux/index.js";
|
|
3
|
+
import reporter from "../reporter.js";
|
|
4
|
+
import { recordPathDependency } from "../query/dependencies.js";
|
|
5
|
+
import { isSerializable, sanitize } from "../utils/serializable.js";
|
|
6
|
+
import { applyTrailingSlashOption, generateComponentChunkName, segmentLength, segmentLengthUnit, slash, tooLongSegmentsInPath, truncatePath } from "../utils/paths.js";
|
|
7
|
+
import { runOnCreateNode, runOnCreatePage } from "../api-runner.js";
|
|
8
|
+
import { createJobV2 } from "./jobs.js";
|
|
9
|
+
import { deleteSitePageNode, resetSitePageNodes, sitePageNodeActions } from "../site-page-nodes.js";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
// src/node/actions/index.ts
|
|
13
|
+
/**
|
|
14
|
+
* traceId of develop's createPagesStatefully runs (when page files are added or removed). Like the
|
|
15
|
+
* initial run's, its pages belong to the plugin that created them: develop's createPages refresh
|
|
16
|
+
* leaves them alone. (Gatsby's page-creator keeps its own watcher and creates them with the actions
|
|
17
|
+
* of the initial run instead.)
|
|
18
|
+
*/
|
|
19
|
+
const DEV_STATEFUL_TRACE_ID = "dev-createPagesStatefully";
|
|
20
|
+
const statefulTraceIds = /* @__PURE__ */ new Set(["initial-createPagesStatefully", DEV_STATEFUL_TRACE_ID]);
|
|
21
|
+
const typeOwners = /* @__PURE__ */ new Map();
|
|
22
|
+
const componentExistsCache = /* @__PURE__ */ new Map();
|
|
23
|
+
const reservedContextFields = [
|
|
24
|
+
"path",
|
|
25
|
+
"matchPath",
|
|
26
|
+
"component",
|
|
27
|
+
"componentChunkName",
|
|
28
|
+
"pluginCreator___NODE",
|
|
29
|
+
"pluginCreatorId"
|
|
30
|
+
];
|
|
31
|
+
function resetActionCaches() {
|
|
32
|
+
typeOwners.clear();
|
|
33
|
+
componentExistsCache.clear();
|
|
34
|
+
resetSitePageNodes();
|
|
35
|
+
}
|
|
36
|
+
function pluginDisplayName(plugin) {
|
|
37
|
+
if (!plugin) return "An unknown plugin";
|
|
38
|
+
return plugin.name === "default-site-plugin" ? `Your site's "gatsby-node"` : `The plugin "${plugin.name}"`;
|
|
39
|
+
}
|
|
40
|
+
function nextNodeCounter() {
|
|
41
|
+
return store.getState().status.LAST_NODE_COUNTER + 1;
|
|
42
|
+
}
|
|
43
|
+
function findDescendants(ids, acc = []) {
|
|
44
|
+
for (const id of ids) {
|
|
45
|
+
const child = getNode(id);
|
|
46
|
+
if (!child) continue;
|
|
47
|
+
acc.push(child);
|
|
48
|
+
if (child.children?.length) findDescendants(child.children, acc);
|
|
49
|
+
}
|
|
50
|
+
return acc;
|
|
51
|
+
}
|
|
52
|
+
const ALLOWED_INTERNAL = /* @__PURE__ */ new Set([
|
|
53
|
+
"type",
|
|
54
|
+
"contentDigest",
|
|
55
|
+
"mediaType",
|
|
56
|
+
"content",
|
|
57
|
+
"description",
|
|
58
|
+
"ignoreType",
|
|
59
|
+
"counter",
|
|
60
|
+
"contentFilePath",
|
|
61
|
+
"owner",
|
|
62
|
+
"fieldOwners"
|
|
63
|
+
]);
|
|
64
|
+
function validateNode(node) {
|
|
65
|
+
if (typeof node.id !== "string" || !node.id) return `"id" must be a non-empty string`;
|
|
66
|
+
if (!Array.isArray(node.children) || node.children.some((c) => typeof c !== "string")) return `"children" must be an array of node ids`;
|
|
67
|
+
if (node.parent !== null && typeof node.parent !== "string") return `"parent" must be a string or null`;
|
|
68
|
+
const i = node.internal;
|
|
69
|
+
if (!i || typeof i !== "object") return `"internal" is required`;
|
|
70
|
+
if (typeof i.type !== "string" || !i.type) return `"internal.type" must be a non-empty string`;
|
|
71
|
+
if (typeof i.contentDigest !== "string" || !i.contentDigest) return `"internal.contentDigest" must be a string`;
|
|
72
|
+
for (const key of Object.keys(i)) if (!ALLOWED_INTERNAL.has(key)) return `"internal.${key}" is not allowed`;
|
|
73
|
+
if (i.content !== void 0 && typeof i.content !== "string") return `"internal.content" must be a string`;
|
|
74
|
+
}
|
|
75
|
+
const reportedValidationErrors = /* @__PURE__ */ new Set();
|
|
76
|
+
function touchNodeActions(id, typeName, plugin, actionOptions) {
|
|
77
|
+
return { actions: [{
|
|
78
|
+
...actionOptions,
|
|
79
|
+
type: "TOUCH_NODE",
|
|
80
|
+
plugin,
|
|
81
|
+
payload: id,
|
|
82
|
+
typeName
|
|
83
|
+
}] };
|
|
84
|
+
}
|
|
85
|
+
function createNodeActions(nodeInput, plugin, actionOptions = {}) {
|
|
86
|
+
if (!nodeInput || typeof nodeInput !== "object") {
|
|
87
|
+
reporter.error(`The node passed to the "createNode" action creator must be an object`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
let node = nodeInput;
|
|
91
|
+
node.internal ??= {};
|
|
92
|
+
if (!Array.isArray(node.children)) node.children = [];
|
|
93
|
+
if (!node.parent) node.parent = null;
|
|
94
|
+
if (node.internal.owner) reporter.panic(`The node internal.owner field is set automatically by Gatsby and not by plugins`);
|
|
95
|
+
if (plugin) node.internal.owner = plugin.name;
|
|
96
|
+
const error = validateNode(node);
|
|
97
|
+
if (error) {
|
|
98
|
+
if (!reportedValidationErrors.has(error)) {
|
|
99
|
+
reportedValidationErrors.add(error);
|
|
100
|
+
reporter.error({
|
|
101
|
+
id: "11467",
|
|
102
|
+
context: { sourceMessage: `${pluginDisplayName(plugin)} created an invalid node: ${error}\n${JSON.stringify(node, null, 2).slice(0, 2e3)}` }
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (node.fields) throw new Error(`Plugins creating nodes can not set data on the reserved field "fields" as this is reserved for plugins which wish to extend your nodes.\n\nNode:\n${JSON.stringify(node, null, 4)}\n\nPlugin that created the node:\n${JSON.stringify(plugin?.name)}`);
|
|
108
|
+
const type = node.internal.type;
|
|
109
|
+
const owner = typeOwners.get(type);
|
|
110
|
+
if (plugin && owner && owner !== plugin.name && !node.internal.ignoreType) reporter.panic(`The plugin "${plugin.name}" created a node of a type owned by another plugin.\n\nThe node type "${type}" is owned by "${owner}".`);
|
|
111
|
+
else if (plugin && !owner) typeOwners.set(type, plugin.name);
|
|
112
|
+
const ds = getDataStore();
|
|
113
|
+
if (typeof ds.getNodeDigest === "function" && ds.getNodeDigest(node.id) === node.internal.contentDigest && nodeTypeOf(node.id) === type) return touchNodeActions(node.id, type, plugin, actionOptions);
|
|
114
|
+
const oldNode = getNode(node.id);
|
|
115
|
+
if (oldNode && oldNode.internal.contentDigest === node.internal.contentDigest && oldNode.internal.type === type) return touchNodeActions(node.id, type, plugin, actionOptions);
|
|
116
|
+
if (!isSerializable(node)) node = sanitize(node);
|
|
117
|
+
const actions = [];
|
|
118
|
+
if (oldNode) for (const child of findDescendants(oldNode.children)) actions.push({
|
|
119
|
+
...actionOptions,
|
|
120
|
+
type: "DELETE_NODE",
|
|
121
|
+
plugin,
|
|
122
|
+
payload: child,
|
|
123
|
+
isRecursiveChildrenDelete: true
|
|
124
|
+
});
|
|
125
|
+
node.internal.counter = nextNodeCounter();
|
|
126
|
+
actions.push({
|
|
127
|
+
...actionOptions,
|
|
128
|
+
type: "CREATE_NODE",
|
|
129
|
+
plugin,
|
|
130
|
+
oldNode,
|
|
131
|
+
payload: node
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
actions,
|
|
135
|
+
created: node
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function createNode(node, plugin, actionOptions = {}) {
|
|
139
|
+
const result = createNodeActions(node, plugin, actionOptions);
|
|
140
|
+
if (!result) return Promise.resolve(void 0);
|
|
141
|
+
store.dispatch(result.actions);
|
|
142
|
+
if (!result.created) return Promise.resolve(void 0);
|
|
143
|
+
return runOnCreateNode(result.created, actionOptions.traceId, actionOptions.parentSpan);
|
|
144
|
+
}
|
|
145
|
+
function deleteNode(nodeOrId, plugin) {
|
|
146
|
+
if (nodeOrId && typeof nodeOrId === "object" && !nodeOrId.id && nodeOrId.node) nodeOrId = nodeOrId.node;
|
|
147
|
+
const id = typeof nodeOrId === "string" ? nodeOrId : nodeOrId?.id;
|
|
148
|
+
const internalNode = getNode(id);
|
|
149
|
+
if (!internalNode) return;
|
|
150
|
+
if (plugin && internalNode.internal.owner && internalNode.internal.owner !== plugin.name && plugin.name !== "internal-data-bridge") reporter.warn(`${pluginDisplayName(plugin)} deleted node "${id}" which is owned by "${internalNode.internal.owner}"`);
|
|
151
|
+
const actions = findDescendants(internalNode.children).map((child) => ({
|
|
152
|
+
type: "DELETE_NODE",
|
|
153
|
+
plugin,
|
|
154
|
+
payload: child,
|
|
155
|
+
isRecursiveChildrenDelete: true
|
|
156
|
+
}));
|
|
157
|
+
actions.push({
|
|
158
|
+
type: "DELETE_NODE",
|
|
159
|
+
plugin,
|
|
160
|
+
payload: internalNode
|
|
161
|
+
});
|
|
162
|
+
store.dispatch(actions);
|
|
163
|
+
}
|
|
164
|
+
function touchNode(nodeOrId, plugin) {
|
|
165
|
+
const id = typeof nodeOrId === "string" ? nodeOrId : nodeOrId?.id ?? nodeOrId?.nodeId;
|
|
166
|
+
if (!id) return;
|
|
167
|
+
store.dispatch({
|
|
168
|
+
type: "TOUCH_NODE",
|
|
169
|
+
plugin,
|
|
170
|
+
payload: id,
|
|
171
|
+
typeName: nodeOrId?.internal?.type
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function createNodeField({ node, name, value }, plugin, actionOptions = {}) {
|
|
175
|
+
if (!node) throw new Error(`createNodeField requires a "node"`);
|
|
176
|
+
if (!name) throw new Error(`createNodeField requires a "name"`);
|
|
177
|
+
node.internal.fieldOwners ??= {};
|
|
178
|
+
node.fields ??= {};
|
|
179
|
+
const schemaFieldName = name.includes("___NODE") ? name.split("___")[0] : name;
|
|
180
|
+
const stored = getNode(node.id);
|
|
181
|
+
const fieldOwner = stored?.internal.fieldOwners?.[schemaFieldName] ?? node.internal.fieldOwners[schemaFieldName];
|
|
182
|
+
const pluginName = plugin?.name ?? "unknown";
|
|
183
|
+
if (fieldOwner && fieldOwner !== pluginName) throw new Error(`A plugin tried to update a node field that it doesn't own:\n\nNode id: ${node.id}\nPlugin: ${pluginName}\nname: ${name}\nvalue: ${String(value)}`);
|
|
184
|
+
node.fields[name] = value;
|
|
185
|
+
node.internal.fieldOwners[schemaFieldName] = pluginName;
|
|
186
|
+
let payload = stored && stored !== node ? {
|
|
187
|
+
...stored,
|
|
188
|
+
fields: {
|
|
189
|
+
...stored.fields,
|
|
190
|
+
[name]: value
|
|
191
|
+
},
|
|
192
|
+
internal: {
|
|
193
|
+
...stored.internal,
|
|
194
|
+
fieldOwners: {
|
|
195
|
+
...stored.internal.fieldOwners,
|
|
196
|
+
[schemaFieldName]: pluginName
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} : node;
|
|
200
|
+
if (!isSerializable(payload)) payload = sanitize(payload);
|
|
201
|
+
store.dispatch({
|
|
202
|
+
...actionOptions,
|
|
203
|
+
type: "ADD_FIELD_TO_NODE",
|
|
204
|
+
plugin,
|
|
205
|
+
payload,
|
|
206
|
+
addedField: name
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Whether createParentChildLink should add the child to the datastore's working copy of the parent
|
|
211
|
+
* (`DataStore.getNodeForUpdate`) instead of writing a changed copy of it: for parents linked again
|
|
212
|
+
* recently (e.g. a JSON or CSV file getting a child per record: each link copied and encoded the
|
|
213
|
+
* whole parent, quadratic in its children) and not read since (a node read since its last write is
|
|
214
|
+
* written as a copy of the object read, with any changes made to it, as before).
|
|
215
|
+
*/
|
|
216
|
+
function wantsWorkingCopy(node) {
|
|
217
|
+
const ds = getDataStore();
|
|
218
|
+
if (typeof ds.getNodeForUpdate !== "function" || typeof ds.peekNode !== "function") return false;
|
|
219
|
+
if (!recentlyChanged.has(node.id)) {
|
|
220
|
+
if (recentlyChanged.size >= 1e4) recentlyChanged.clear();
|
|
221
|
+
recentlyChanged.add(node.id);
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
return ds.peekNode(node.id) === void 0;
|
|
225
|
+
}
|
|
226
|
+
/** ids of parents linked to a child recently */
|
|
227
|
+
const recentlyChanged = /* @__PURE__ */ new Set();
|
|
228
|
+
/**
|
|
229
|
+
* Positions of the ids in long `children` arrays that are passed again (a plugin's parent object,
|
|
230
|
+
* the store's working copy). null: passed once (e.g. a parent read from the store for this link).
|
|
231
|
+
*/
|
|
232
|
+
const childIndexes = /* @__PURE__ */ new WeakMap();
|
|
233
|
+
const INDEX_CHILDREN = 32;
|
|
234
|
+
/**
|
|
235
|
+
* `children.includes(id)`, with an index of the positions of the ids for long arrays passed again:
|
|
236
|
+
* includes() on every link was quadratic (5 s for 20,000 children on Node). An array is indexed the
|
|
237
|
+
* second time it is passed (a parent read from the store for each link has a new array: one scan,
|
|
238
|
+
* like includes()). The index follows this action's pushes (`pushChild`) and adds ids pushed by
|
|
239
|
+
* others at the next call. It is built again when the array shrank, its last indexed id changed, or
|
|
240
|
+
* an indexed id is no longer at its position or shows up again further on (a plugin removed, moved,
|
|
241
|
+
* copied or replaced ids in its own array): ids that were in the array at the last call are always
|
|
242
|
+
* found. An id that is new to the array and that a plugin wrote over another id (directly, or by
|
|
243
|
+
* pushing it and moving it there before the next call) is not seen: linking it pushes it again.
|
|
244
|
+
*/
|
|
245
|
+
function hasChild(children, id) {
|
|
246
|
+
if (children.length < INDEX_CHILDREN) {
|
|
247
|
+
childIndexes.delete(children);
|
|
248
|
+
return children.includes(id);
|
|
249
|
+
}
|
|
250
|
+
let index = childIndexes.get(children);
|
|
251
|
+
if (index === void 0) {
|
|
252
|
+
childIndexes.set(children, null);
|
|
253
|
+
return children.includes(id);
|
|
254
|
+
}
|
|
255
|
+
if (index && (index.length > children.length || children[index.length - 1] !== index.last)) index = null;
|
|
256
|
+
let at = indexChildren(children, index).get(id);
|
|
257
|
+
if (at !== void 0 && children[at] !== id) at = indexChildren(children, null).get(id);
|
|
258
|
+
return at !== void 0;
|
|
259
|
+
}
|
|
260
|
+
/** the index of `children` (from scratch without `index`), with the ids added since */
|
|
261
|
+
function indexChildren(children, index) {
|
|
262
|
+
const added = index !== null;
|
|
263
|
+
if (!index) childIndexes.set(children, index = {
|
|
264
|
+
at: /* @__PURE__ */ new Map(),
|
|
265
|
+
length: 0,
|
|
266
|
+
last: ""
|
|
267
|
+
});
|
|
268
|
+
for (let i = index.length; i < children.length; i++) if (!index.at.has(children[i])) index.at.set(children[i], i);
|
|
269
|
+
else if (added) return indexChildren(children, null);
|
|
270
|
+
index.length = children.length;
|
|
271
|
+
index.last = children[children.length - 1];
|
|
272
|
+
return index.at;
|
|
273
|
+
}
|
|
274
|
+
/** `children.push(id)`, and the index of `children` with it */
|
|
275
|
+
function pushChild(children, id) {
|
|
276
|
+
children.push(id);
|
|
277
|
+
const index = childIndexes.get(children);
|
|
278
|
+
if (index && index.length === children.length - 1 && children[index.length - 1] === index.last) {
|
|
279
|
+
if (!index.at.has(id)) index.at.set(id, index.length);
|
|
280
|
+
index.length = children.length;
|
|
281
|
+
index.last = id;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function createParentChildLink({ parent, child }, plugin) {
|
|
285
|
+
if (!parent || !child) throw new Error(`createParentChildLink requires "parent" and "child"`);
|
|
286
|
+
if (!hasChild(parent.children, child.id)) pushChild(parent.children, child.id);
|
|
287
|
+
const work = typeof child.id === "string" && wantsWorkingCopy(parent) ? getDataStore().getNodeForUpdate(parent.id) : void 0;
|
|
288
|
+
if (work) {
|
|
289
|
+
if (!hasChild(work.children, child.id)) pushChild(work.children, child.id);
|
|
290
|
+
store.dispatch({
|
|
291
|
+
type: "ADD_CHILD_NODE_TO_PARENT_NODE",
|
|
292
|
+
plugin,
|
|
293
|
+
payload: work,
|
|
294
|
+
deferDigest: true
|
|
295
|
+
});
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const stored = getNode(parent.id);
|
|
299
|
+
const payload = stored && stored !== parent ? stored.children.includes(child.id) ? stored : {
|
|
300
|
+
...stored,
|
|
301
|
+
children: [...stored.children, child.id]
|
|
302
|
+
} : parent;
|
|
303
|
+
store.dispatch({
|
|
304
|
+
type: "ADD_CHILD_NODE_TO_PARENT_NODE",
|
|
305
|
+
plugin,
|
|
306
|
+
payload
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
function componentExists(file) {
|
|
310
|
+
let exists = componentExistsCache.get(file);
|
|
311
|
+
if (exists === void 0) {
|
|
312
|
+
exists = fs.existsSync(file);
|
|
313
|
+
componentExistsCache.set(file, exists);
|
|
314
|
+
}
|
|
315
|
+
return exists;
|
|
316
|
+
}
|
|
317
|
+
function createPage(page, plugin, actionOptions = {}) {
|
|
318
|
+
const name = pluginDisplayName(plugin);
|
|
319
|
+
if (!page?.path) reporter.panic({
|
|
320
|
+
id: "11323",
|
|
321
|
+
context: { sourceMessage: `${name} must set the page path when creating a page` }
|
|
322
|
+
});
|
|
323
|
+
if (page.context && typeof page.context === "object") {
|
|
324
|
+
const invalid = reservedContextFields.filter((f) => f in page.context && page.context[f] !== page[f]);
|
|
325
|
+
if (invalid.length) reporter.panic({
|
|
326
|
+
id: "11324",
|
|
327
|
+
context: { sourceMessage: `${name} used reserved field names in the context object when creating a page:\n${invalid.map((f) => ` * "${f}"`).join("\n")}` }
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
if (!page.component) reporter.panic({
|
|
331
|
+
id: "11322",
|
|
332
|
+
context: { sourceMessage: `${name} must set the absolute path to the page component when creating a page` }
|
|
333
|
+
});
|
|
334
|
+
const { config, program } = store.getState();
|
|
335
|
+
const [componentFile, contentFilePath] = String(page.component).split("?__contentFilePath=");
|
|
336
|
+
if (!path.isAbsolute(componentFile)) reporter.panic({
|
|
337
|
+
id: "11326",
|
|
338
|
+
context: { sourceMessage: `${name} must set the absolute path to the page component when creating a page.\n\nThe page component path you set was "${page.component}".` }
|
|
339
|
+
});
|
|
340
|
+
if (!componentExists(componentFile)) {
|
|
341
|
+
reporter.panicOnBuild({
|
|
342
|
+
id: "11325",
|
|
343
|
+
context: { sourceMessage: `${name} created a page with a component that doesn't exist.\n\nThe path to the missing component is "${componentFile}"` }
|
|
344
|
+
});
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
let component = slash(componentFile);
|
|
348
|
+
if (contentFilePath) component = `${component}?__contentFilePath=${slash(contentFilePath)}`;
|
|
349
|
+
let pagePath = page.path;
|
|
350
|
+
if (!pagePath.startsWith("/")) pagePath = `/${pagePath}`;
|
|
351
|
+
pagePath = applyTrailingSlashOption(pagePath, config.trailingSlash);
|
|
352
|
+
const tooLong = tooLongSegmentsInPath(pagePath);
|
|
353
|
+
if (tooLong.length > 0) {
|
|
354
|
+
const truncated = truncatePath(pagePath);
|
|
355
|
+
const lengths = tooLong.map(segmentLength).join(", ");
|
|
356
|
+
reporter.warn(`Page path too long for a file name (${tooLong.length === 1 ? "segment" : "segments"} of ${lengths} ${segmentLengthUnit}, max. 255): "${pagePath}" is shortened to "${truncated}"`);
|
|
357
|
+
pagePath = truncated;
|
|
358
|
+
}
|
|
359
|
+
const internalPage = {
|
|
360
|
+
internalComponentName: pagePath === "/" ? "ComponentIndex" : `Component${pagePath}`,
|
|
361
|
+
path: pagePath,
|
|
362
|
+
matchPath: page.matchPath,
|
|
363
|
+
component,
|
|
364
|
+
componentPath: component,
|
|
365
|
+
componentChunkName: generateComponentChunkName(component, program.directory),
|
|
366
|
+
isCreatedByStatefulCreatePages: statefulTraceIds.has(actionOptions.traceId),
|
|
367
|
+
context: page.context || {},
|
|
368
|
+
updatedAt: Date.now(),
|
|
369
|
+
pluginCreator___NODE: plugin?.id ?? "",
|
|
370
|
+
pluginCreatorId: plugin?.id ?? "",
|
|
371
|
+
mode: "SSG"
|
|
372
|
+
};
|
|
373
|
+
if (page.defer) internalPage.defer = true;
|
|
374
|
+
if (page.ownerNodeId) internalPage.ownerNodeId = page.ownerNodeId;
|
|
375
|
+
const oldPage = store.getState().pages.get(pagePath);
|
|
376
|
+
const alternate = pagePath.endsWith("/") ? pagePath.slice(0, -1) : `${pagePath}/`;
|
|
377
|
+
if (pagePath !== "/" && store.getState().pages.has(alternate)) reporter.warn(`Non-deterministic routing danger: Attempting to create page: "${pagePath}", but page "${alternate}" already exists`);
|
|
378
|
+
store.dispatch([{
|
|
379
|
+
...actionOptions,
|
|
380
|
+
type: "CREATE_PAGE",
|
|
381
|
+
contextModified: !!oldPage && JSON.stringify(oldPage.context) !== JSON.stringify(internalPage.context),
|
|
382
|
+
componentModified: !!oldPage && oldPage.component !== internalPage.component,
|
|
383
|
+
plugin,
|
|
384
|
+
payload: internalPage
|
|
385
|
+
}, ...sitePageNodeActions(internalPage, actionOptions, nextNodeCounter)]);
|
|
386
|
+
runOnCreatePage(internalPage, actionOptions.traceId, actionOptions.parentSpan, plugin?.name);
|
|
387
|
+
}
|
|
388
|
+
function deletePage(page) {
|
|
389
|
+
if (!page?.path) return;
|
|
390
|
+
if (tooLongSegmentsInPath(page.path).length > 0) page = {
|
|
391
|
+
...page,
|
|
392
|
+
path: truncatePath(page.path)
|
|
393
|
+
};
|
|
394
|
+
store.dispatch({
|
|
395
|
+
type: "DELETE_PAGE",
|
|
396
|
+
payload: page
|
|
397
|
+
});
|
|
398
|
+
deleteSitePageNode(page.path);
|
|
399
|
+
}
|
|
400
|
+
let warnedSlices = false;
|
|
401
|
+
/** Gatsby's `createSlice` – Slices are not supported by goatly (`<Slice>` fails the build). */
|
|
402
|
+
function createSlice(input, plugin) {
|
|
403
|
+
if (warnedSlices) return;
|
|
404
|
+
warnedSlices = true;
|
|
405
|
+
reporter.warn(`${pluginDisplayName(plugin)} created the slice "${input?.id}": Gatsby Slices are not supported by goatly. Render the slice component directly (its sliceContext as props, its query as useStaticQuery or part of the page query). Pages rendering <Slice> fail to build; <Slice allowEmpty> renders nothing.`);
|
|
406
|
+
}
|
|
407
|
+
function createRedirect(redirect, plugin) {
|
|
408
|
+
const { fromPath, toPath, isPermanent = false, redirectInBrowser = false, ...rest } = redirect;
|
|
409
|
+
if (!fromPath || !toPath) reporter.panic(`createRedirect requires "fromPath" and "toPath"`);
|
|
410
|
+
const { program, config } = store.getState();
|
|
411
|
+
const prefix = program.prefixPaths ? config.pathPrefix : "";
|
|
412
|
+
const applyPrefix = (p) => prefix && p.startsWith("/") && !p.startsWith(prefix) ? `${prefix}${p}` : p;
|
|
413
|
+
store.dispatch({
|
|
414
|
+
type: "CREATE_REDIRECT",
|
|
415
|
+
plugin,
|
|
416
|
+
payload: {
|
|
417
|
+
fromPath: applyPrefix(fromPath),
|
|
418
|
+
toPath: applyPrefix(toPath),
|
|
419
|
+
isPermanent,
|
|
420
|
+
redirectInBrowser,
|
|
421
|
+
...rest
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
/** an action plugins dispatch with just a payload (unchecked: it comes from a plugin) */
|
|
426
|
+
const simple = (type) => (payload, plugin) => store.dispatch({
|
|
427
|
+
type,
|
|
428
|
+
plugin,
|
|
429
|
+
payload
|
|
430
|
+
});
|
|
431
|
+
const babelStageWarned = /* @__PURE__ */ new Set();
|
|
432
|
+
const babelAction = (type) => (payload, plugin) => {
|
|
433
|
+
const key = `${plugin?.name}:${type}`;
|
|
434
|
+
if (!babelStageWarned.has(key)) {
|
|
435
|
+
babelStageWarned.add(key);
|
|
436
|
+
reporter.verbose(`${pluginDisplayName(plugin)} called ${type.toLowerCase()} – goatly does not use Babel, the setting is recorded but has no effect.`);
|
|
437
|
+
}
|
|
438
|
+
store.dispatch({
|
|
439
|
+
type,
|
|
440
|
+
plugin,
|
|
441
|
+
payload
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
const jobsV1Reported = /* @__PURE__ */ new Set();
|
|
445
|
+
/** Gatsby's Jobs API v1 (deprecated since Gatsby 2 for createJobV2) only reported progress: a no-op here */
|
|
446
|
+
const jobV1Action = (name) => (_job, plugin) => {
|
|
447
|
+
const key = plugin?.name ?? "";
|
|
448
|
+
if (jobsV1Reported.has(key)) return;
|
|
449
|
+
jobsV1Reported.add(key);
|
|
450
|
+
reporter.verbose(`${pluginDisplayName(plugin)} called ${name}: the deprecated Jobs API v1 has no effect in goatly (createJobV2 runs jobs).`);
|
|
451
|
+
};
|
|
452
|
+
const publicActions = {
|
|
453
|
+
createNode,
|
|
454
|
+
deleteNode,
|
|
455
|
+
touchNode,
|
|
456
|
+
createNodeField,
|
|
457
|
+
createParentChildLink,
|
|
458
|
+
createPage,
|
|
459
|
+
deletePage,
|
|
460
|
+
createRedirect,
|
|
461
|
+
createJobV2,
|
|
462
|
+
createJob: jobV1Action("createJob"),
|
|
463
|
+
setJob: jobV1Action("setJob"),
|
|
464
|
+
endJob: jobV1Action("endJob"),
|
|
465
|
+
setPluginStatus: simple("SET_PLUGIN_STATUS"),
|
|
466
|
+
setWebpackConfig: simple("SET_WEBPACK_CONFIG"),
|
|
467
|
+
replaceWebpackConfig: simple("REPLACE_WEBPACK_CONFIG"),
|
|
468
|
+
setBabelOptions: babelAction("SET_BABEL_OPTIONS"),
|
|
469
|
+
setBabelPlugin: babelAction("SET_BABEL_PLUGIN"),
|
|
470
|
+
setBabelPreset: babelAction("SET_BABEL_PRESET"),
|
|
471
|
+
setRequestHeaders: (payload, plugin) => store.dispatch({
|
|
472
|
+
type: "SET_REQUEST_HEADERS",
|
|
473
|
+
plugin,
|
|
474
|
+
payload
|
|
475
|
+
}),
|
|
476
|
+
addGatsbyImageSourceUrl: (_sourceUrl) => {},
|
|
477
|
+
createServerVisitedPage: (_chunkName) => {},
|
|
478
|
+
createPageDependency: (args) => recordPathDependency(args?.path, {
|
|
479
|
+
nodeId: args?.nodeId,
|
|
480
|
+
connection: args?.connection
|
|
481
|
+
}),
|
|
482
|
+
unstable_createNodeManifest: (_manifest) => {},
|
|
483
|
+
enableStatefulSourceNodes: (plugin) => store.dispatch({
|
|
484
|
+
type: "ENABLE_STATEFUL_SOURCE_PLUGIN",
|
|
485
|
+
plugin
|
|
486
|
+
})
|
|
487
|
+
};
|
|
488
|
+
const restrictedActions = {
|
|
489
|
+
createTypes: (types, plugin) => store.dispatch({
|
|
490
|
+
type: "CREATE_TYPES",
|
|
491
|
+
plugin,
|
|
492
|
+
payload: types
|
|
493
|
+
}),
|
|
494
|
+
createFieldExtension: (extension, plugin) => {
|
|
495
|
+
const name = extension?.name;
|
|
496
|
+
if (!name) {
|
|
497
|
+
reporter.error(`The provided field extension must have a "name" property.`);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if ([
|
|
501
|
+
"infer",
|
|
502
|
+
"dontInfer",
|
|
503
|
+
"mimeTypes",
|
|
504
|
+
"childOf",
|
|
505
|
+
"nodeInterface",
|
|
506
|
+
"deprecated"
|
|
507
|
+
].includes(name)) {
|
|
508
|
+
reporter.error(`The extension name "${name}" is reserved for internal use.`);
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
store.dispatch({
|
|
512
|
+
type: "CREATE_FIELD_EXTENSION",
|
|
513
|
+
plugin,
|
|
514
|
+
payload: {
|
|
515
|
+
name,
|
|
516
|
+
extension
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
},
|
|
520
|
+
addThirdPartySchema: ({ schema }, plugin) => store.dispatch({
|
|
521
|
+
type: "ADD_THIRD_PARTY_SCHEMA",
|
|
522
|
+
plugin,
|
|
523
|
+
payload: schema
|
|
524
|
+
}),
|
|
525
|
+
printTypeDefinitions: (options = {}, plugin) => store.dispatch({
|
|
526
|
+
type: "PRINT_SCHEMA_REQUESTED",
|
|
527
|
+
plugin,
|
|
528
|
+
payload: {
|
|
529
|
+
path: "schema.gql",
|
|
530
|
+
include: {},
|
|
531
|
+
exclude: {},
|
|
532
|
+
withFieldTypes: true,
|
|
533
|
+
...options
|
|
534
|
+
}
|
|
535
|
+
}),
|
|
536
|
+
createResolverContext: (context, plugin) => store.dispatch({
|
|
537
|
+
type: "CREATE_RESOLVER_CONTEXT",
|
|
538
|
+
plugin,
|
|
539
|
+
payload: context
|
|
540
|
+
}),
|
|
541
|
+
createSlice,
|
|
542
|
+
addRemoteFileAllowedUrl: (_url) => {}
|
|
543
|
+
};
|
|
544
|
+
const restrictions = {
|
|
545
|
+
createTypes: {
|
|
546
|
+
allowed: ["createSchemaCustomization"],
|
|
547
|
+
deprecated: [
|
|
548
|
+
"onPreInit",
|
|
549
|
+
"onPreBootstrap",
|
|
550
|
+
"sourceNodes"
|
|
551
|
+
]
|
|
552
|
+
},
|
|
553
|
+
createFieldExtension: {
|
|
554
|
+
allowed: ["createSchemaCustomization"],
|
|
555
|
+
deprecated: ["sourceNodes"]
|
|
556
|
+
},
|
|
557
|
+
addThirdPartySchema: {
|
|
558
|
+
allowed: ["createSchemaCustomization"],
|
|
559
|
+
deprecated: [
|
|
560
|
+
"onPreInit",
|
|
561
|
+
"onPreBootstrap",
|
|
562
|
+
"sourceNodes"
|
|
563
|
+
]
|
|
564
|
+
},
|
|
565
|
+
printTypeDefinitions: { allowed: ["createSchemaCustomization"] },
|
|
566
|
+
createResolverContext: { allowed: ["createSchemaCustomization"] },
|
|
567
|
+
createSlice: { allowed: ["createPages"] },
|
|
568
|
+
addRemoteFileAllowedUrl: { allowed: [
|
|
569
|
+
"onPreInit",
|
|
570
|
+
"onPreBootstrap",
|
|
571
|
+
"onPluginInit",
|
|
572
|
+
"createSchemaCustomization"
|
|
573
|
+
] }
|
|
574
|
+
};
|
|
575
|
+
function restrictedFor(api) {
|
|
576
|
+
const out = {};
|
|
577
|
+
for (const [name, action] of Object.entries(restrictedActions)) {
|
|
578
|
+
const r = restrictions[name];
|
|
579
|
+
if (r.allowed.includes(api)) out[name] = action;
|
|
580
|
+
else if (r.deprecated?.includes(api)) out[name] = (...args) => {
|
|
581
|
+
reporter.warn(`Calling "${name}" in the "${api}" API is deprecated. Please use: ${r.allowed.join(", ")}.`);
|
|
582
|
+
return action(...args);
|
|
583
|
+
};
|
|
584
|
+
else out[name] = () => reporter.panic(`"${name}" is only available in the following APIs: ${r.allowed.join(", ")}. It was called in "${api}".`);
|
|
585
|
+
}
|
|
586
|
+
return out;
|
|
587
|
+
}
|
|
588
|
+
const boundCache = /* @__PURE__ */ new Map();
|
|
589
|
+
/**
|
|
590
|
+
* Returns the action creators bound to the calling plugin, with Gatsby's
|
|
591
|
+
* "double binding" semantics (callers may override the plugin argument).
|
|
592
|
+
*/
|
|
593
|
+
function getActionsForApi(api, plugin, actionOptions = {}) {
|
|
594
|
+
const key = `${plugin.name}|${api}|${actionOptions.traceId ?? ""}`;
|
|
595
|
+
const cached = boundCache.get(key);
|
|
596
|
+
if (cached) return cached;
|
|
597
|
+
const all = {
|
|
598
|
+
...publicActions,
|
|
599
|
+
...restrictedFor(api)
|
|
600
|
+
};
|
|
601
|
+
const pluginRef = {
|
|
602
|
+
name: plugin.name,
|
|
603
|
+
id: plugin.id,
|
|
604
|
+
version: plugin.version
|
|
605
|
+
};
|
|
606
|
+
const bound = {};
|
|
607
|
+
for (const [name, action] of Object.entries(all)) bound[name] = (...args) => {
|
|
608
|
+
if (args.length === 0) return action(pluginRef, actionOptions);
|
|
609
|
+
if (args.length === 1) return action(args[0], pluginRef, actionOptions);
|
|
610
|
+
if (args.length === 2) return action(args[0], args[1] ?? pluginRef, actionOptions);
|
|
611
|
+
return action(args[0], args[1] ?? pluginRef, args[2] ?? actionOptions);
|
|
612
|
+
};
|
|
613
|
+
boundCache.set(key, bound);
|
|
614
|
+
return bound;
|
|
615
|
+
}
|
|
616
|
+
function clearBoundActionCache() {
|
|
617
|
+
boundCache.clear();
|
|
618
|
+
}
|
|
619
|
+
export { DEV_STATEFUL_TRACE_ID, clearBoundActionCache, createNode, createNodeField, createPage, createParentChildLink, createRedirect, createSlice, deleteNode, deletePage, getActionsForApi, publicActions, resetActionCaches, restrictedActions, touchNode };
|