goatly 0.1.0 → 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/README.md +853 -1
- 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 +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 +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,220 @@
|
|
|
1
|
+
import { store } from "./redux/index.js";
|
|
2
|
+
import reporter from "./reporter.js";
|
|
3
|
+
import { generateHtmlPath, slash } from "./utils/paths.js";
|
|
4
|
+
import { ROOT_NOT_FOUND_PAGE, inNotFoundSection, isNotFoundPageIn, samePagePath } from "../runtime/not-found.js";
|
|
5
|
+
// src/node/not-found-pages.ts
|
|
6
|
+
/** 404 pages of site sections (gatsby-config `notFoundPages`), resolved against the pages. */
|
|
7
|
+
const PROD_404_PLUGIN = "prod-404-500";
|
|
8
|
+
/** the page prod-404-500 builds for a section: `/de` → `/de/404.html` (static hosts look for it) */
|
|
9
|
+
const notFoundHtmlPath = (prefix) => `${prefix}/404.html`;
|
|
10
|
+
const toggleSlash = (p) => p.endsWith("/") ? p.slice(0, -1) : `${p}/`;
|
|
11
|
+
const scopesOf = (state = store.getState()) => state.config?.notFoundPages ?? [];
|
|
12
|
+
/**
|
|
13
|
+
* The paths that name `page`: itself, without/with trailing slash, for `…/404.html` the page
|
|
14
|
+
* `…/404/` (Gatsby's /404/ ↔ /404.html, also for sections: i18n plugins create both) and, for a
|
|
15
|
+
* page prod-404-500 mirrors (`/404.html`, `/500.html`, `<section>/404.html`), the pages it mirrors.
|
|
16
|
+
*/
|
|
17
|
+
function pageAliases(page, scopes, seen = /* @__PURE__ */ new Set()) {
|
|
18
|
+
if (seen.has(page)) return [];
|
|
19
|
+
seen.add(page);
|
|
20
|
+
const out = [page, toggleSlash(page)];
|
|
21
|
+
const html = /^((?:\/[^/]+)*\/404|\/500)\.html$/.exec(page);
|
|
22
|
+
if (html) out.push(`${html[1]}/`, html[1]);
|
|
23
|
+
for (const s of scopes) if (notFoundHtmlPath(s.prefix) === page) out.push(...pageAliases(s.page, scopes, seen));
|
|
24
|
+
return [...new Set(out)];
|
|
25
|
+
}
|
|
26
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
function memoOf(scopes) {
|
|
28
|
+
let m = memo.get(scopes);
|
|
29
|
+
if (!m) memo.set(scopes, m = { aliases: /* @__PURE__ */ new Map() });
|
|
30
|
+
return m;
|
|
31
|
+
}
|
|
32
|
+
function scopeAliases(page, scopes) {
|
|
33
|
+
const { aliases } = memoOf(scopes);
|
|
34
|
+
let out = aliases.get(page);
|
|
35
|
+
if (!out) aliases.set(page, out = pageAliases(page, scopes));
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The pages a prod-404-500 mirror (`/404.html`, `/500.html`, `<section>/404.html`) is a copy of –
|
|
40
|
+
* it stays in develop while one of them does. [] for other pages.
|
|
41
|
+
*/
|
|
42
|
+
function notFoundMirrorSources(mirror, scopes = scopesOf()) {
|
|
43
|
+
const root = /^\/(404|500)\.html$/.exec(mirror);
|
|
44
|
+
if (root) return [`/${root[1]}/`, `/${root[1]}`];
|
|
45
|
+
const scope = scopes.find((s) => notFoundHtmlPath(s.prefix) === mirror);
|
|
46
|
+
if (!scope) return [];
|
|
47
|
+
return scopeAliases(scope.page, scopes).filter((p) => p !== mirror);
|
|
48
|
+
}
|
|
49
|
+
/** the `<section>/404.html` pages prod-404-500 creates as copies of the page `pagePath` */
|
|
50
|
+
function scopedMirrorTargets(pagePath, scopes) {
|
|
51
|
+
const m = memoOf(scopes);
|
|
52
|
+
if (!m.targets) {
|
|
53
|
+
const targets = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const s of scopes) {
|
|
55
|
+
const target = notFoundHtmlPath(s.prefix);
|
|
56
|
+
for (const alias of scopeAliases(s.page, scopes)) {
|
|
57
|
+
if (alias === target) continue;
|
|
58
|
+
const list = targets.get(alias);
|
|
59
|
+
if (list) list.push(target);
|
|
60
|
+
else targets.set(alias, [target]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
m.targets = targets;
|
|
64
|
+
}
|
|
65
|
+
return m.targets.get(pagePath) ?? [];
|
|
66
|
+
}
|
|
67
|
+
function prod404PluginId(state = store.getState()) {
|
|
68
|
+
return state.flattenedPlugins.find((p) => p.name === PROD_404_PLUGIN)?.id;
|
|
69
|
+
}
|
|
70
|
+
function resolve(state) {
|
|
71
|
+
const { pages } = state;
|
|
72
|
+
const scopes = scopesOf(state);
|
|
73
|
+
return scopes.map((scope) => {
|
|
74
|
+
const htmlPath = notFoundHtmlPath(scope.prefix);
|
|
75
|
+
let source;
|
|
76
|
+
for (const alias of scopeAliases(scope.page, scopes)) {
|
|
77
|
+
source = alias !== htmlPath ? pages.get(alias) : void 0;
|
|
78
|
+
if (source) break;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
scope,
|
|
82
|
+
htmlPath,
|
|
83
|
+
mirror: pages.get(htmlPath),
|
|
84
|
+
source
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function toEntry({ scope, mirror, source }) {
|
|
89
|
+
const page = mirror ?? source;
|
|
90
|
+
if (!page) return void 0;
|
|
91
|
+
return {
|
|
92
|
+
prefix: scope.prefix,
|
|
93
|
+
path: page.path,
|
|
94
|
+
...source && source.path !== page.path ? { source: source.path } : {},
|
|
95
|
+
file: slash(generateHtmlPath("", page.path))
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The 404 page of each section that has one (longest prefix first): its `<section>/404.html` page,
|
|
100
|
+
* or else the configured page. Cheap enough per request.
|
|
101
|
+
*/
|
|
102
|
+
function resolveNotFoundEntries(state = store.getState()) {
|
|
103
|
+
return resolve(state).map(toEntry).filter((e) => !!e);
|
|
104
|
+
}
|
|
105
|
+
/** the URLs a matchPath matches start with this (its static segments) */
|
|
106
|
+
const matchPathBase = (matchPath) => {
|
|
107
|
+
const segments = [];
|
|
108
|
+
for (const s of matchPath.split("/").filter(Boolean)) {
|
|
109
|
+
if (s.startsWith(":") || s.startsWith("*")) break;
|
|
110
|
+
segments.push(s);
|
|
111
|
+
}
|
|
112
|
+
return `/${segments.join("/")}`;
|
|
113
|
+
};
|
|
114
|
+
/** resolveNotFoundEntries, with `problems` (a section without its 404 page) and `notes` (warnings) */
|
|
115
|
+
function resolveNotFoundPages(state = store.getState()) {
|
|
116
|
+
const entries = [];
|
|
117
|
+
const problems = [];
|
|
118
|
+
const notes = [];
|
|
119
|
+
const resolved = resolve(state);
|
|
120
|
+
if (!resolved.length) return {
|
|
121
|
+
entries,
|
|
122
|
+
problems,
|
|
123
|
+
notes
|
|
124
|
+
};
|
|
125
|
+
const own = prod404PluginId(state);
|
|
126
|
+
const sectionsOf = /* @__PURE__ */ new Map();
|
|
127
|
+
for (const r of resolved) {
|
|
128
|
+
const entry = toEntry(r);
|
|
129
|
+
if (!entry) {
|
|
130
|
+
const { scope } = r;
|
|
131
|
+
const found = [...state.pages.keys()].filter((p) => /(^|\/)404(\/|\.html)?$/.test(p)).sort();
|
|
132
|
+
problems.push(`notFoundPages: the section "${scope.prefix}" uses the 404 page "${scope.page}", but no page has that path. Create src/pages${scope.page.replace(/\/$/, "")}.js (or createPage({ path: "${scope.page}" })) or fix the path.${found.length ? ` 404 pages found: ${found.map((p) => `"${p}"`).join(", ")}` : ""}`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
entries.push(entry);
|
|
136
|
+
const { scope, htmlPath, mirror, source } = r;
|
|
137
|
+
if (scope.explicit && mirror && source && mirror.pluginCreatorId !== own && !samePagePath(scope.page, htmlPath)) notes.push(`notFoundPages: the section "${scope.prefix}" is set to "${scope.page}", but the page "${htmlPath}" already exists (made by another plugin or the site) and is what static hosts serve for "${scope.prefix}/…"; goatly uses "${htmlPath}" too. Remove that page or set the section to it.`);
|
|
138
|
+
for (const p of /* @__PURE__ */ new Set([mirror ?? source, source])) if (p) sectionsOf.set(p, [...sectionsOf.get(p) ?? [], scope.prefix]);
|
|
139
|
+
}
|
|
140
|
+
for (const [page, sections] of sectionsOf) {
|
|
141
|
+
if (!page.matchPath) continue;
|
|
142
|
+
const base = matchPathBase(page.matchPath);
|
|
143
|
+
if (sections.some((prefix) => inNotFoundSection(prefix, base))) continue;
|
|
144
|
+
const list = sections.map((s) => `"${s}"`).join(", ");
|
|
145
|
+
notes.push(`notFoundPages: "${page.path}" is the 404 page of ${list}, so its matchPath "${page.matchPath}" is no client-only route: unknown URLs it matches outside ${list} get the 404 page of their section or ${ROOT_NOT_FOUND_PAGE} (status 404) instead of "${page.path}". Add their section to notFoundPages to give them "${page.path}".`);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
entries,
|
|
149
|
+
problems,
|
|
150
|
+
notes
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** what the browser runtime gets (virtual:goatly/not-found-pages) */
|
|
154
|
+
function runtimeNotFoundPages(state = store.getState()) {
|
|
155
|
+
return resolveNotFoundEntries(state).map(({ file: _file, ...entry }) => entry);
|
|
156
|
+
}
|
|
157
|
+
/** `.cache/not-found-pages.json`, read by `serve` (and hosting plugins) */
|
|
158
|
+
function notFoundPagesManifest(state = store.getState()) {
|
|
159
|
+
return {
|
|
160
|
+
version: 1,
|
|
161
|
+
pages: resolveNotFoundEntries(state)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/** pages of sections' 404 pages: no client-only routes, even with a matchPath (i18n plugins set one) */
|
|
165
|
+
function notFoundPagePaths(state = store.getState()) {
|
|
166
|
+
const paths = /* @__PURE__ */ new Set();
|
|
167
|
+
for (const e of resolveNotFoundEntries(state)) {
|
|
168
|
+
paths.add(e.path);
|
|
169
|
+
if (e.source) paths.add(e.source);
|
|
170
|
+
}
|
|
171
|
+
return paths;
|
|
172
|
+
}
|
|
173
|
+
/** whether the page is a 404 page: "/404.html" or a section's */
|
|
174
|
+
function isNotFoundPage(pagePath, state = store.getState()) {
|
|
175
|
+
return isNotFoundPageIn(runtimeNotFoundPages(state), pagePath);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* develop: whether an untouched page stays after createPages ran again – a copy prod-404-500 made
|
|
179
|
+
* of a page that is still there (it doesn't create an existing copy again). Gatsby exempts
|
|
180
|
+
* /404.html (and /500.html) whoever made them.
|
|
181
|
+
*/
|
|
182
|
+
function isKeptNotFoundMirror(page, kept, state = store.getState()) {
|
|
183
|
+
if (!/^\/(404|500)\.html$/.test(page.path) && page.pluginCreatorId !== prod404PluginId(state)) return false;
|
|
184
|
+
return notFoundMirrorSources(page.path, scopesOf(state)).some(kept);
|
|
185
|
+
}
|
|
186
|
+
const componentFile = (p) => (p.componentPath || p.component || "").split("?")[0];
|
|
187
|
+
/** the sections with a page that looks like their own 404 page (for the hint without the option) */
|
|
188
|
+
function sectionsWithNotFoundPages(state) {
|
|
189
|
+
const { pages } = state;
|
|
190
|
+
const rootComponents = new Set([
|
|
191
|
+
"/404/",
|
|
192
|
+
"/404",
|
|
193
|
+
ROOT_NOT_FOUND_PAGE
|
|
194
|
+
].map((p) => pages.get(p)).map((p) => p && componentFile(p)));
|
|
195
|
+
rootComponents.delete(void 0);
|
|
196
|
+
const sections = /* @__PURE__ */ new Set();
|
|
197
|
+
for (const page of pages.values()) {
|
|
198
|
+
const m = /^((?:\/[^/]+)+)\/404(?:\/|\.html)?$/.exec(page.path);
|
|
199
|
+
if (!m) continue;
|
|
200
|
+
const section = m[1];
|
|
201
|
+
const file = componentFile(page);
|
|
202
|
+
if (rootComponents.has(file) || /(^|[\\/])404(\.[^\\/.]+|[\\/]index\.[^\\/.]+)$/.test(file) || page.matchPath && /(^|\/)\*[^/]*$/.test(page.matchPath) && inNotFoundSection(section, matchPathBase(page.matchPath))) sections.add(section);
|
|
203
|
+
}
|
|
204
|
+
return [...sections].sort();
|
|
205
|
+
}
|
|
206
|
+
/** problems with the sections' 404 pages (fails `build`), warnings and hints – after createPages */
|
|
207
|
+
function reportNotFoundPages(state = store.getState()) {
|
|
208
|
+
const scopes = scopesOf(state);
|
|
209
|
+
if (state.config?.notFoundPages === void 0) {
|
|
210
|
+
const sections = sectionsWithNotFoundPages(state);
|
|
211
|
+
if (sections.length) reporter.info(`There are 404 pages of site sections (${sections.join(", ")}), but unknown URLs in them get /404.html (or a page with a catch-all matchPath like "${sections[0]}/*", with status 200), as in Gatsby. To give them their section's 404 page with status 404, add notFoundPages: ${JSON.stringify(sections)} to gatsby-config (README: "Multiple 404 pages"); notFoundPages: [] turns this hint off.`);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (!scopes.length) return;
|
|
215
|
+
const { problems, notes } = resolveNotFoundPages(state);
|
|
216
|
+
for (const note of notes) reporter.warn(note);
|
|
217
|
+
if (!state.pages.has("/404.html") && !state.pages.has("/404/") && !state.pages.has("/404")) reporter.warn(`notFoundPages: there is no 404 page for the rest of the site (src/pages/404.js). Unknown URLs outside ${scopes.map((s) => `"${s.prefix}"`).join(", ")} get the server's default 404, and hosts that only use /404.html (GitHub Pages, S3, Firebase) show none of the 404 pages.`);
|
|
218
|
+
if (problems.length) reporter.panicOnBuild(problems.join("\n"));
|
|
219
|
+
}
|
|
220
|
+
export { PROD_404_PLUGIN, isKeptNotFoundMirror, isNotFoundPage, notFoundHtmlPath, notFoundMirrorSources, notFoundPagePaths, notFoundPagesManifest, pageAliases, prod404PluginId, reportNotFoundPages, resolveNotFoundEntries, resolveNotFoundPages, runtimeNotFoundPages, scopedMirrorTargets };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { browser, features, node, ssr } from "../../compat-apis.json.js";
|
|
2
|
+
// src/node/plugins/api-list.ts
|
|
3
|
+
const NODE_APIS = Object.keys(node).concat([
|
|
4
|
+
"unstable_shouldOnCreateNode",
|
|
5
|
+
"unstable_onPluginInit",
|
|
6
|
+
"loadNodeContent",
|
|
7
|
+
"onCreateViteConfig"
|
|
8
|
+
]);
|
|
9
|
+
const BROWSER_APIS = Object.keys(browser);
|
|
10
|
+
const SSR_APIS = Object.keys(ssr);
|
|
11
|
+
const FEATURES = features;
|
|
12
|
+
export { BROWSER_APIS, FEATURES, NODE_APIS, SSR_APIS };
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { importModule, normalizeModuleExports, resolveApiFile } from "../loader/import-module.js";
|
|
2
|
+
import reporter from "../reporter.js";
|
|
3
|
+
import { BROWSER_APIS, NODE_APIS, SSR_APIS } from "./api-list.js";
|
|
4
|
+
import { createPluginId, resolvePlugin, resolvePluginModulePath } from "./resolve-plugin.js";
|
|
5
|
+
import { getStaticExports } from "./static-exports.js";
|
|
6
|
+
import { slash } from "../utils/paths.js";
|
|
7
|
+
import { loadConfigFile } from "../config/index.js";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import Joi from "joi";
|
|
11
|
+
// src/node/plugins/load-plugins.ts
|
|
12
|
+
/** What goatly takes from the gatsby-config of a theme */
|
|
13
|
+
const THEME_CONFIG_KEYS = /* @__PURE__ */ new Set(["plugins", "siteMetadata"]);
|
|
14
|
+
/** Gatsby plugins whose functionality is built into goatly. */
|
|
15
|
+
const BUILT_IN_REPLACEMENTS = /* @__PURE__ */ new Set(["gatsby-plugin-page-creator"]);
|
|
16
|
+
/** npm Gatsby plugins that cannot work with goatly, and what to do instead. */
|
|
17
|
+
const UNSUPPORTED_PLUGINS = /* @__PURE__ */ new Map([["gatsby-plugin-offline", `"gatsby-plugin-offline" is not supported by goatly: it generates its service worker from webpack's build output (public/webpack.stats.json), which goatly doesn't produce.
|
|
18
|
+
|
|
19
|
+
To migrate, remove it from your plugins:
|
|
20
|
+
- If the site was deployed with it, add "gatsby-plugin-remove-serviceworker" for a while. It replaces public/sw.js with a service worker that removes itself, so visitors' browsers stop serving the old cached site.
|
|
21
|
+
- To keep offline support, generate public/sw.js yourself after the build (e.g. with workbox-build in onPostBuild of your gatsby-node) and export \`registerServiceWorker = () => true\` from gatsby-browser.`]]);
|
|
22
|
+
function normalizeRef(ref) {
|
|
23
|
+
if (typeof ref === "string") return {
|
|
24
|
+
resolve: ref,
|
|
25
|
+
options: {}
|
|
26
|
+
};
|
|
27
|
+
if (!ref || typeof ref !== "object" || typeof ref.resolve !== "string") throw new Error(`Invalid plugin configuration: ${JSON.stringify(ref)}`);
|
|
28
|
+
if (ref.option && !ref.options) throw new Error(`Plugin "${ref.resolve}" has an "option" key in the configuration. Did you mean "options"?`);
|
|
29
|
+
return {
|
|
30
|
+
resolve: ref.resolve,
|
|
31
|
+
options: { ...ref.options },
|
|
32
|
+
parentDir: ref.parentDir
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The error for a shadowed theme, with the steps to turn it into a local plugin of the site. A theme
|
|
37
|
+
* outside node_modules (in plugins/, or a linked workspace package) is converted where it is.
|
|
38
|
+
*/
|
|
39
|
+
function shadowingNotSupported(info, rootDir, shadowDir) {
|
|
40
|
+
const { name } = info;
|
|
41
|
+
const installed = info.resolve.includes("/node_modules/");
|
|
42
|
+
const dir = installed ? `plugins/${name}` : slash(path.relative(rootDir, info.resolve));
|
|
43
|
+
return `"${name}" is a Gatsby theme, and ${shadowDir}/ shadows its files: goatly doesn't support component shadowing.
|
|
44
|
+
|
|
45
|
+
To migrate, make the theme a plain local plugin of your site:
|
|
46
|
+
${[
|
|
47
|
+
...installed ? [`Copy the theme's package to ${dir}/ (local plugins are found before node_modules) and keep "${name}" in your plugins. Add the theme's dependencies to your package.json and remove the theme itself.`] : [],
|
|
48
|
+
`Move the "plugins" and "siteMetadata" of its gatsby-config into your gatsby-config, then delete its gatsby-config. If it exports a function of the theme's options, move what it returns for your options. Paths in it that point into the theme (such as \`\${__dirname}/src/...\`) must point into ${dir}/ now, and a page creator for the theme's src/pages is replaced by the next step.`,
|
|
49
|
+
`If the theme has a src/pages directory, add { resolve: "gatsby-plugin-page-creator", options: { path: path.resolve("${dir}/src/pages") } } to your plugins.`,
|
|
50
|
+
...installed ? [`Point the imports of "${name}" and "${name}/..." in your site to the copy, e.g. with vite: { resolve: { alias: { "${name}": path.resolve("${dir}") } } } in your gatsby-config.`] : [],
|
|
51
|
+
`Apply the files you shadowed in ${shadowDir}/ to ${installed ? "the copy" : `${dir}/`}, then delete ${shadowDir}/.`
|
|
52
|
+
].map((step, i) => ` ${i + 1}. ${step}`).join("\n")}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Resolves the plugins listed in gatsby-config. A Gatsby theme (a plugin with its own
|
|
56
|
+
* gatsby-config) adds the plugins of its config, placed before it and resolved from the theme,
|
|
57
|
+
* and its siteMetadata, where the site's values win. Component shadowing is not supported
|
|
58
|
+
* (see `checkShadowing`).
|
|
59
|
+
*/
|
|
60
|
+
async function resolvePluginRefs(plugins, rootDir, siteMetadata, expanded = /* @__PURE__ */ new Set()) {
|
|
61
|
+
const out = [];
|
|
62
|
+
for (const raw of plugins) {
|
|
63
|
+
const ref = normalizeRef(raw);
|
|
64
|
+
const unsupported = UNSUPPORTED_PLUGINS.get(ref.resolve);
|
|
65
|
+
if (unsupported) reporter.panic(unsupported);
|
|
66
|
+
if (BUILT_IN_REPLACEMENTS.has(ref.resolve)) {
|
|
67
|
+
out.push({
|
|
68
|
+
...ref,
|
|
69
|
+
info: builtInInfo(ref.resolve)
|
|
70
|
+
});
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
let info;
|
|
74
|
+
try {
|
|
75
|
+
info = resolvePlugin(ref.resolve, ref.parentDir ?? rootDir);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
reporter.panic({
|
|
78
|
+
id: "11321",
|
|
79
|
+
context: { sourceMessage: e.message }
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const isTheme = !!resolveApiFile(info.resolve, "gatsby-config");
|
|
83
|
+
if (isTheme && !expanded.has(info.resolve)) {
|
|
84
|
+
expanded.add(info.resolve);
|
|
85
|
+
out.push(...await expandTheme(info, ref.options, rootDir, siteMetadata, expanded));
|
|
86
|
+
}
|
|
87
|
+
out.push({
|
|
88
|
+
resolve: ref.resolve,
|
|
89
|
+
options: ref.options,
|
|
90
|
+
info,
|
|
91
|
+
isTheme
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const dedup = /* @__PURE__ */ new Map();
|
|
95
|
+
for (const p of out) {
|
|
96
|
+
const key = `${p.info.resolve}::${JSON.stringify(p.options)}`;
|
|
97
|
+
dedup.delete(key);
|
|
98
|
+
dedup.set(key, p);
|
|
99
|
+
}
|
|
100
|
+
return [...dedup.values()];
|
|
101
|
+
}
|
|
102
|
+
async function expandTheme(info, options, rootDir, siteMetadata, expanded) {
|
|
103
|
+
let { config } = await loadConfigFile(info.resolve);
|
|
104
|
+
if (typeof config === "function") config = await config(options);
|
|
105
|
+
config ??= {};
|
|
106
|
+
const ignored = Object.keys(config).filter((key) => !THEME_CONFIG_KEYS.has(key));
|
|
107
|
+
if (ignored.length) reporter.warn(`The gatsby-config of the theme "${info.name}" sets ${ignored.map((k) => `"${k}"`).join(", ")}, which goatly ignores: it only takes "plugins" and "siteMetadata" from themes. Set the others in your gatsby-config if your site needs them.`);
|
|
108
|
+
for (const [key, value] of Object.entries(config.siteMetadata ?? {})) if (!(key in siteMetadata)) siteMetadata[key] = value;
|
|
109
|
+
return resolvePluginRefs((Array.isArray(config.plugins) ? config.plugins : []).map((p) => typeof p === "string" ? {
|
|
110
|
+
resolve: p,
|
|
111
|
+
parentDir: info.resolve
|
|
112
|
+
} : {
|
|
113
|
+
parentDir: info.resolve,
|
|
114
|
+
...p
|
|
115
|
+
}), rootDir, siteMetadata, expanded);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gatsby's component shadowing (files in `src/<theme name>/` of the site or of another theme replace
|
|
119
|
+
* the theme's files) is not supported. Rather than building the theme's own files instead, the
|
|
120
|
+
* build stops with the steps to make the theme a local plugin.
|
|
121
|
+
*/
|
|
122
|
+
function checkShadowing(refs, rootDir) {
|
|
123
|
+
const themes = refs.filter((r) => r.isTheme);
|
|
124
|
+
for (const theme of themes) for (const dir of [rootDir, ...themes.map((t) => t.info.resolve)]) {
|
|
125
|
+
if (dir === theme.info.resolve) continue;
|
|
126
|
+
const shadowDir = path.join(dir, "src", theme.info.name);
|
|
127
|
+
if (fs.existsSync(shadowDir) && fs.statSync(shadowDir).isDirectory()) reporter.panic(shadowingNotSupported(theme.info, rootDir, slash(path.relative(rootDir, shadowDir))));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function builtInInfo(name) {
|
|
131
|
+
return {
|
|
132
|
+
name,
|
|
133
|
+
resolve: name,
|
|
134
|
+
version: "built-in",
|
|
135
|
+
id: createPluginId(name),
|
|
136
|
+
packageJson: {}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async function loadGatsbyNode(file) {
|
|
140
|
+
if (!file) return {};
|
|
141
|
+
try {
|
|
142
|
+
return normalizeModuleExports(await importModule(file));
|
|
143
|
+
} catch (e) {
|
|
144
|
+
reporter.panic({
|
|
145
|
+
id: "11333",
|
|
146
|
+
context: { sourceMessage: `Error loading "${file}"` },
|
|
147
|
+
error: e
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The Joi instance passed to a plugin's `pluginOptionsSchema({ Joi })`: Joi plus `subPlugins()`
|
|
153
|
+
* (`Joi.subPlugins({ entry })`), which records where the plugin's sub-plugins are. As in Gatsby,
|
|
154
|
+
* whose `gatsby-plugin-utils` Joi has no `subPlugins()` at runtime, it is only defined here.
|
|
155
|
+
*/
|
|
156
|
+
function makeSubPluginJoi(subPluginPaths) {
|
|
157
|
+
return Joi.extend((joi) => ({
|
|
158
|
+
type: "subPlugins",
|
|
159
|
+
base: joi.array().items(joi.alternatives(joi.string(), joi.object({
|
|
160
|
+
resolve: joi.string(),
|
|
161
|
+
options: joi.object({}).unknown(true)
|
|
162
|
+
}).unknown(true))).custom((arrayValue, helpers) => {
|
|
163
|
+
const entry = helpers.schema.$_getFlag("entry");
|
|
164
|
+
const normalizedPath = helpers.state.path.map((key, index) => typeof key === "number" && Array.isArray(helpers.state.ancestors[helpers.state.path.length - index - 1]) ? "[]" : key).join(".");
|
|
165
|
+
subPluginPaths.add(normalizedPath);
|
|
166
|
+
return arrayValue.map((v) => {
|
|
167
|
+
const value = typeof v === "string" ? {
|
|
168
|
+
resolve: v,
|
|
169
|
+
options: {}
|
|
170
|
+
} : {
|
|
171
|
+
options: {},
|
|
172
|
+
...v
|
|
173
|
+
};
|
|
174
|
+
if (entry) value.__entry = entry;
|
|
175
|
+
return value;
|
|
176
|
+
});
|
|
177
|
+
}, "subplugin normalization").default([]),
|
|
178
|
+
args(schema, args) {
|
|
179
|
+
if (args?.entry && schema?.$_setFlag) return schema.$_setFlag("entry", args.entry, { clone: true });
|
|
180
|
+
return schema;
|
|
181
|
+
}
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
async function validateOptions(name, gatsbyNode, options) {
|
|
185
|
+
const subPluginPaths = /* @__PURE__ */ new Set();
|
|
186
|
+
if (typeof gatsbyNode.pluginOptionsSchema !== "function") {
|
|
187
|
+
if (Array.isArray(options.plugins) && options.plugins.length) subPluginPaths.add("plugins");
|
|
188
|
+
return {
|
|
189
|
+
options,
|
|
190
|
+
subPluginPaths: [...subPluginPaths]
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const J = makeSubPluginJoi(subPluginPaths);
|
|
194
|
+
let schema = gatsbyNode.pluginOptionsSchema({ Joi: J });
|
|
195
|
+
const SchemaJoi = J.isSchema(schema, { legacy: true }) ? schema.$_root : void 0;
|
|
196
|
+
if (!SchemaJoi?.isSchema || schema.type !== "object") {
|
|
197
|
+
reporter.warn(`Plugin "${name}" has an invalid options schema so we cannot verify your configuration for it.`);
|
|
198
|
+
return {
|
|
199
|
+
options,
|
|
200
|
+
subPluginPaths: []
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
if (!schema.describe().keys?.plugins) schema = schema.append({ plugins: SchemaJoi.array().length(0) });
|
|
204
|
+
try {
|
|
205
|
+
const { value, warning } = await schema.pattern(/.*/, SchemaJoi.any().warning("any.unknown")).validateAsync(options, {
|
|
206
|
+
abortEarly: false,
|
|
207
|
+
externals: true,
|
|
208
|
+
warnings: true
|
|
209
|
+
});
|
|
210
|
+
if (warning?.details?.length) reporter.warn(`Warning: there are unknown plugin options for "${name}": ${warning.details.map((d) => d.path.join(".")).join(", ")}`);
|
|
211
|
+
if (!subPluginPaths.has("plugins") && Array.isArray(value.plugins) && value.plugins.length) subPluginPaths.add("plugins");
|
|
212
|
+
return {
|
|
213
|
+
options: value,
|
|
214
|
+
subPluginPaths: [...subPluginPaths]
|
|
215
|
+
};
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (error?.isJoi || error?.name === "ValidationError") reporter.panic({
|
|
218
|
+
id: "11331",
|
|
219
|
+
context: { sourceMessage: `Invalid plugin options for "${name}":\n${(error.details ?? []).map((d) => ` - ${d.message}`).join("\n")}` }
|
|
220
|
+
});
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function getAtPath(obj, segments) {
|
|
225
|
+
let parent = obj;
|
|
226
|
+
const keys = segments.filter((s) => s !== "[]");
|
|
227
|
+
for (let i = 0; i < keys.length - 1; i++) parent = parent?.[keys[i]];
|
|
228
|
+
const last = keys[keys.length - 1];
|
|
229
|
+
return {
|
|
230
|
+
roots: [].concat(parent?.[last] ?? []).flat(),
|
|
231
|
+
set: (value) => {
|
|
232
|
+
if (parent) parent[last] = value;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
async function processSubPlugins(options, subPluginPaths, rootDir, flattened) {
|
|
237
|
+
for (const subPath of subPluginPaths) {
|
|
238
|
+
const { roots, set } = getAtPath(options, subPath.split("."));
|
|
239
|
+
const processed = [];
|
|
240
|
+
for (const root of roots) {
|
|
241
|
+
const ref = typeof root === "string" ? {
|
|
242
|
+
resolve: root,
|
|
243
|
+
options: {}
|
|
244
|
+
} : root;
|
|
245
|
+
if (ref && typeof ref === "object" && ref.pluginOptions && ref.name) {
|
|
246
|
+
processed.push(ref);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const plugin = await loadPlugin({
|
|
250
|
+
resolve: ref.resolve,
|
|
251
|
+
options: ref.options ?? {}
|
|
252
|
+
}, rootDir, flattened, {
|
|
253
|
+
isSubPlugin: true,
|
|
254
|
+
entry: ref.__entry
|
|
255
|
+
});
|
|
256
|
+
processed.push(plugin);
|
|
257
|
+
}
|
|
258
|
+
set(processed);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async function loadPlugin(ref, rootDir, flattened, extra = {}) {
|
|
262
|
+
const info = ref.info ?? resolvePlugin(ref.resolve, rootDir);
|
|
263
|
+
const gatsbyNodePath = resolveApiFile(info.resolve, "gatsby-node");
|
|
264
|
+
const gatsbyNode = await loadGatsbyNode(gatsbyNodePath);
|
|
265
|
+
const { options, subPluginPaths } = await validateOptions(info.name, gatsbyNode, {
|
|
266
|
+
plugins: [],
|
|
267
|
+
...ref.options
|
|
268
|
+
});
|
|
269
|
+
if (subPluginPaths.length) await processSubPlugins(options, subPluginPaths, rootDir, flattened);
|
|
270
|
+
const gatsbyBrowserPath = resolveApiFile(info.resolve, "gatsby-browser");
|
|
271
|
+
const gatsbySSRPath = resolveApiFile(info.resolve, "gatsby-ssr");
|
|
272
|
+
const gatsbyWorkerPath = resolveApiFile(info.resolve, "gatsby-worker");
|
|
273
|
+
const exportedNodeApis = Object.keys(gatsbyNode);
|
|
274
|
+
const nodeAPIs = exportedNodeApis.filter((k) => NODE_APIS.includes(k) && typeof gatsbyNode[k] === "function");
|
|
275
|
+
const unknown = exportedNodeApis.filter((k) => !NODE_APIS.includes(k) && k !== "default" && k !== "__esModule");
|
|
276
|
+
if (unknown.length && !extra.isSubPlugin) reporter.warn(`Plugin "${info.name}" exports unknown Node APIs from gatsby-node: ${unknown.join(", ")}`);
|
|
277
|
+
const plugin = {
|
|
278
|
+
id: createPluginId(info.name, ref),
|
|
279
|
+
name: info.name,
|
|
280
|
+
version: info.version,
|
|
281
|
+
resolve: info.resolve,
|
|
282
|
+
pluginOptions: options,
|
|
283
|
+
nodeAPIs,
|
|
284
|
+
browserAPIs: gatsbyBrowserPath ? getStaticExports(gatsbyBrowserPath).filter((k) => BROWSER_APIS.includes(k)) : [],
|
|
285
|
+
ssrAPIs: gatsbySSRPath ? getStaticExports(gatsbySSRPath).filter((k) => SSR_APIS.includes(k)) : [],
|
|
286
|
+
pluginFilepath: info.resolve,
|
|
287
|
+
gatsbyNodePath,
|
|
288
|
+
gatsbyBrowserPath,
|
|
289
|
+
gatsbySSRPath,
|
|
290
|
+
gatsbyWorkerPath,
|
|
291
|
+
subPluginPaths: subPluginPaths.length ? subPluginPaths : void 0,
|
|
292
|
+
module: gatsbyNode,
|
|
293
|
+
isSubPlugin: extra.isSubPlugin,
|
|
294
|
+
isTheme: ref.isTheme
|
|
295
|
+
};
|
|
296
|
+
if (extra.isSubPlugin) {
|
|
297
|
+
const modulePath = resolvePluginModulePath(info, extra.entry);
|
|
298
|
+
if (modulePath) {
|
|
299
|
+
plugin.modulePath = modulePath;
|
|
300
|
+
try {
|
|
301
|
+
const mod = await importModule(modulePath);
|
|
302
|
+
plugin.module = mod?.default ?? mod;
|
|
303
|
+
} catch (e) {
|
|
304
|
+
reporter.panic({
|
|
305
|
+
context: { sourceMessage: `Error loading sub-plugin "${info.name}"` },
|
|
306
|
+
error: e
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
plugin.gatsbyNodeModule = gatsbyNode;
|
|
311
|
+
flattened.push({
|
|
312
|
+
...plugin,
|
|
313
|
+
module: gatsbyNode
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
return plugin;
|
|
317
|
+
}
|
|
318
|
+
let uncomparableOptions = 0;
|
|
319
|
+
/** compares plugin options (functions and regexes by their source; circular ones never match) */
|
|
320
|
+
function safeOptionsKey(options) {
|
|
321
|
+
try {
|
|
322
|
+
return JSON.stringify(options, (_k, v) => typeof v === "function" || v instanceof RegExp ? String(v) : v);
|
|
323
|
+
} catch {
|
|
324
|
+
return `\0${uncomparableOptions++}`;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Resolves, validates and flattens the plugin list into execution order:
|
|
329
|
+
* internal plugins → user plugins (themes expanded, sub-plugins first) → page creators of
|
|
330
|
+
* the themes' and the site's src/pages → site.
|
|
331
|
+
*/
|
|
332
|
+
async function loadPlugins(opts) {
|
|
333
|
+
const { rootDir } = opts;
|
|
334
|
+
const flattened = [];
|
|
335
|
+
const pushInternal = async (def) => {
|
|
336
|
+
const { options } = await validateOptions(def.name, def.module, {
|
|
337
|
+
plugins: [],
|
|
338
|
+
...def.options
|
|
339
|
+
});
|
|
340
|
+
flattened.push({
|
|
341
|
+
id: createPluginId(def.name, def),
|
|
342
|
+
name: def.name,
|
|
343
|
+
version: "1.0.0",
|
|
344
|
+
resolve: def.resolve,
|
|
345
|
+
pluginOptions: options,
|
|
346
|
+
nodeAPIs: Object.keys(def.module).filter((k) => NODE_APIS.includes(k)),
|
|
347
|
+
browserAPIs: def.browserPath ? getStaticExports(def.browserPath).filter((k) => BROWSER_APIS.includes(k)) : [],
|
|
348
|
+
ssrAPIs: def.ssrPath ? getStaticExports(def.ssrPath).filter((k) => SSR_APIS.includes(k)) : [],
|
|
349
|
+
pluginFilepath: def.resolve,
|
|
350
|
+
gatsbyBrowserPath: def.browserPath,
|
|
351
|
+
gatsbySSRPath: def.ssrPath,
|
|
352
|
+
module: def.module
|
|
353
|
+
});
|
|
354
|
+
};
|
|
355
|
+
for (const def of opts.internalPluginsBefore) await pushInternal(def);
|
|
356
|
+
const refs = await resolvePluginRefs(opts.plugins, rootDir, opts.siteMetadata);
|
|
357
|
+
checkShadowing(refs, rootDir);
|
|
358
|
+
const isPageCreator = (ref) => ref.info.name === "gatsby-plugin-page-creator" && ref.info.version === "built-in";
|
|
359
|
+
const pagesDirKey = (dir) => {
|
|
360
|
+
const abs = path.resolve(rootDir, String(dir ?? "src/pages"));
|
|
361
|
+
try {
|
|
362
|
+
return fs.realpathSync(abs);
|
|
363
|
+
} catch {
|
|
364
|
+
return abs;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
const configuredPageCreators = /* @__PURE__ */ new Map();
|
|
368
|
+
for (const ref of refs) {
|
|
369
|
+
if (!isPageCreator(ref)) continue;
|
|
370
|
+
const dir = pagesDirKey(ref.options.path);
|
|
371
|
+
const byOptions = configuredPageCreators.get(dir) ?? /* @__PURE__ */ new Map();
|
|
372
|
+
configuredPageCreators.set(dir, byOptions);
|
|
373
|
+
const optionsKey = safeOptionsKey({
|
|
374
|
+
...ref.options,
|
|
375
|
+
path: void 0
|
|
376
|
+
});
|
|
377
|
+
if (!byOptions.has(optionsKey)) byOptions.set(optionsKey, ref.options);
|
|
378
|
+
}
|
|
379
|
+
const automaticPagesDirs = [...refs.filter((ref) => ref.isTheme).map((ref) => path.join(ref.info.resolve, "src/pages")).filter((dir) => fs.existsSync(dir)), path.join(rootDir, "src/pages")];
|
|
380
|
+
const automaticKeys = new Set(automaticPagesDirs.map(pagesDirKey));
|
|
381
|
+
const pushedDirs = /* @__PURE__ */ new Set();
|
|
382
|
+
/** the page creators of a pages directory: the configured ones, else `fallback` */
|
|
383
|
+
const pushPageCreators = async (dir, fallback) => {
|
|
384
|
+
if (pushedDirs.has(dir)) return;
|
|
385
|
+
pushedDirs.add(dir);
|
|
386
|
+
const configured = configuredPageCreators.get(dir);
|
|
387
|
+
for (const options of configured?.size ? configured.values() : fallback ? [fallback] : []) await pushInternal(opts.createPageCreator(options));
|
|
388
|
+
};
|
|
389
|
+
for (const ref of refs) {
|
|
390
|
+
if (BUILT_IN_REPLACEMENTS.has(ref.info.name) && ref.info.version === "built-in") {
|
|
391
|
+
if (isPageCreator(ref)) {
|
|
392
|
+
const dir = pagesDirKey(ref.options.path);
|
|
393
|
+
if (!automaticKeys.has(dir)) await pushPageCreators(dir);
|
|
394
|
+
}
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const plugin = await loadPlugin(ref, rootDir, flattened);
|
|
398
|
+
flattened.push(plugin);
|
|
399
|
+
}
|
|
400
|
+
for (const dir of automaticPagesDirs) await pushPageCreators(pagesDirKey(dir), {
|
|
401
|
+
path: dir,
|
|
402
|
+
pathCheck: false
|
|
403
|
+
});
|
|
404
|
+
const siteNodePath = resolveApiFile(rootDir, "gatsby-node");
|
|
405
|
+
const siteNode = await loadGatsbyNode(siteNodePath);
|
|
406
|
+
const siteBrowser = resolveApiFile(rootDir, "gatsby-browser");
|
|
407
|
+
const siteSSR = resolveApiFile(rootDir, "gatsby-ssr");
|
|
408
|
+
const unknown = Object.keys(siteNode).filter((k) => !NODE_APIS.includes(k) && k !== "default");
|
|
409
|
+
if (unknown.length) reporter.warn(`Your site's gatsby-node exports unknown APIs: ${unknown.join(", ")}`);
|
|
410
|
+
flattened.push({
|
|
411
|
+
id: createPluginId("default-site-plugin"),
|
|
412
|
+
name: "default-site-plugin",
|
|
413
|
+
version: "1.0.0",
|
|
414
|
+
resolve: rootDir,
|
|
415
|
+
pluginOptions: { plugins: [] },
|
|
416
|
+
nodeAPIs: Object.keys(siteNode).filter((k) => NODE_APIS.includes(k) && typeof siteNode[k] === "function"),
|
|
417
|
+
browserAPIs: siteBrowser ? getStaticExports(siteBrowser).filter((k) => BROWSER_APIS.includes(k)) : [],
|
|
418
|
+
ssrAPIs: siteSSR ? getStaticExports(siteSSR).filter((k) => SSR_APIS.includes(k)) : [],
|
|
419
|
+
pluginFilepath: rootDir,
|
|
420
|
+
gatsbyNodePath: siteNodePath,
|
|
421
|
+
gatsbyBrowserPath: siteBrowser,
|
|
422
|
+
gatsbySSRPath: siteSSR,
|
|
423
|
+
module: siteNode
|
|
424
|
+
});
|
|
425
|
+
return flattened;
|
|
426
|
+
}
|
|
427
|
+
export { loadPlugins, resolvePluginRefs };
|