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.
Files changed (161) hide show
  1. package/README.md +874 -1
  2. package/bin/goatly.js +99 -0
  3. package/dist/cli/index.js +234 -0
  4. package/dist/compat/gatsby-node-entry.js +16 -0
  5. package/dist/compat/gatsby-package.json +6 -0
  6. package/dist/compat/md5-file.js +47 -0
  7. package/dist/compat-apis.json +72 -0
  8. package/dist/compat-apis.json.js +62 -0
  9. package/dist/graphql.js +3 -0
  10. package/dist/node/actions/index.js +619 -0
  11. package/dist/node/actions/job-store.js +180 -0
  12. package/dist/node/actions/jobs.js +174 -0
  13. package/dist/node/api-runner.js +258 -0
  14. package/dist/node/bootstrap.js +569 -0
  15. package/dist/node/build/assets.js +110 -0
  16. package/dist/node/build/incremental.js +208 -0
  17. package/dist/node/build/index.js +763 -0
  18. package/dist/node/build/memory-governor.js +450 -0
  19. package/dist/node/build/output-dirs.js +70 -0
  20. package/dist/node/build/page-data.js +40 -0
  21. package/dist/node/build/page-files.js +186 -0
  22. package/dist/node/build/partitioned-state.js +258 -0
  23. package/dist/node/build/query-worker.js +626 -0
  24. package/dist/node/build/query-workers.js +863 -0
  25. package/dist/node/build/render-thread.js +103 -0
  26. package/dist/node/build/render-worker.js +162 -0
  27. package/dist/node/build/state.js +24 -0
  28. package/dist/node/build/timing-breakdown.js +216 -0
  29. package/dist/node/build/work-clock.js +75 -0
  30. package/dist/node/build/worker-pool.js +242 -0
  31. package/dist/node/cache-layout.js +99 -0
  32. package/dist/node/cache.js +1430 -0
  33. package/dist/node/compat/chokidar-shim.js +148 -0
  34. package/dist/node/compat/core-utils-lmdb.js +145 -0
  35. package/dist/node/compat/create-node-id-shim.js +1 -0
  36. package/dist/node/compat/module-hooks.js +245 -0
  37. package/dist/node/compat/redux-shim.js +1 -0
  38. package/dist/node/config/index.js +162 -0
  39. package/dist/node/config/not-found-pages.js +95 -0
  40. package/dist/node/datastore/codec.js +144 -0
  41. package/dist/node/datastore/index.js +127 -0
  42. package/dist/node/datastore/logfile/cache.js +89 -0
  43. package/dist/node/datastore/logfile/index.js +1329 -0
  44. package/dist/node/datastore/logfile/record.js +71 -0
  45. package/dist/node/datastore/types.js +1 -0
  46. package/dist/node/develop/express-compat.js +207 -0
  47. package/dist/node/develop/graphiql.js +22 -0
  48. package/dist/node/develop/hydration-report.js +41 -0
  49. package/dist/node/develop/index.js +618 -0
  50. package/dist/node/develop/local-url.js +10 -0
  51. package/dist/node/develop/ssr-runner.js +66 -0
  52. package/dist/node/gql.js +5 -0
  53. package/dist/node/index.js +15 -0
  54. package/dist/node/info.js +270 -0
  55. package/dist/node/internal-plugins/data-bridge.js +196 -0
  56. package/dist/node/internal-plugins/page-creator.js +318 -0
  57. package/dist/node/loader/import-module.js +160 -0
  58. package/dist/node/node-helpers.js +66 -0
  59. package/dist/node/not-found-pages.js +220 -0
  60. package/dist/node/plugins/api-list.js +12 -0
  61. package/dist/node/plugins/load-plugins.js +427 -0
  62. package/dist/node/plugins/resolve-plugin.js +79 -0
  63. package/dist/node/plugins/static-exports.js +64 -0
  64. package/dist/node/query/compile.js +326 -0
  65. package/dist/node/query/dependencies.js +45 -0
  66. package/dist/node/query/execute.js +417 -0
  67. package/dist/node/query/extract.js +372 -0
  68. package/dist/node/query/gql-tada-introspection.js +124 -0
  69. package/dist/node/query/graphql-env.js +231 -0
  70. package/dist/node/query/graphql-runner.js +79 -0
  71. package/dist/node/redux/actions.js +1 -0
  72. package/dist/node/redux/index.js +133 -0
  73. package/dist/node/redux/node-changes.js +128 -0
  74. package/dist/node/redux/reducers.js +193 -0
  75. package/dist/node/redux/state.js +71 -0
  76. package/dist/node/renderer.js +124 -0
  77. package/dist/node/reporter-transports.js +259 -0
  78. package/dist/node/reporter.js +497 -0
  79. package/dist/node/schema/date.js +539 -0
  80. package/dist/node/schema/extensions.js +315 -0
  81. package/dist/node/schema/index.js +542 -0
  82. package/dist/node/schema/infer.js +388 -0
  83. package/dist/node/schema/inline-objects.js +128 -0
  84. package/dist/node/schema/naming.js +20 -0
  85. package/dist/node/schema/node-model.js +207 -0
  86. package/dist/node/schema/query-engine.js +1808 -0
  87. package/dist/node/schema/resolver-kinds.js +7 -0
  88. package/dist/node/schema/resolvers.js +273 -0
  89. package/dist/node/schema/type-builders.js +45 -0
  90. package/dist/node/schema/types.js +241 -0
  91. package/dist/node/serve.js +90 -0
  92. package/dist/node/site-page-nodes.js +277 -0
  93. package/dist/node/types.js +1 -0
  94. package/dist/node/utils/content-digest.js +107 -0
  95. package/dist/node/utils/cpus.js +104 -0
  96. package/dist/node/utils/create-node-id.js +51 -0
  97. package/dist/node/utils/env.js +25 -0
  98. package/dist/node/utils/fs-retry.js +74 -0
  99. package/dist/node/utils/memory-signals.js +441 -0
  100. package/dist/node/utils/memory.js +657 -0
  101. package/dist/node/utils/murmurhash.js +32 -0
  102. package/dist/node/utils/parser.js +33 -0
  103. package/dist/node/utils/partition-hash.js +19 -0
  104. package/dist/node/utils/paths.js +122 -0
  105. package/dist/node/utils/resolver.js +48 -0
  106. package/dist/node/utils/runtime.js +5 -0
  107. package/dist/node/utils/serializable.js +41 -0
  108. package/dist/node/utils/strings.js +41 -0
  109. package/dist/node/vite/config.js +289 -0
  110. package/dist/node/vite/paths.js +12 -0
  111. package/dist/node/vite/plugin-deps.js +232 -0
  112. package/dist/node/vite/plugin.js +283 -0
  113. package/dist/node/vite/react-compiler.js +362 -0
  114. package/dist/node/vite/source-files.js +83 -0
  115. package/dist/node/vite/static-image.js +136 -0
  116. package/dist/node/vite/styled-components.js +73 -0
  117. package/dist/node/vite/transforms.js +330 -0
  118. package/dist/node/wasm-data/host.js +406 -0
  119. package/dist/node/wasm-data/lower.js +406 -0
  120. package/dist/node/wasm-data/runner.js +79 -0
  121. package/dist/node/wasm-data/worker.js +95 -0
  122. package/dist/reporter.js +5 -0
  123. package/dist/runtime/api-runner.js +81 -0
  124. package/dist/runtime/app.js +256 -0
  125. package/dist/runtime/client-entry.js +4 -0
  126. package/dist/runtime/client.js +383 -0
  127. package/dist/runtime/default-html.js +31 -0
  128. package/dist/runtime/head-markup.js +100 -0
  129. package/dist/runtime/head-sync.js +101 -0
  130. package/dist/runtime/head-tags.js +45 -0
  131. package/dist/runtime/hydration-report.js +111 -0
  132. package/dist/runtime/index.js +12 -0
  133. package/dist/runtime/link.js +293 -0
  134. package/dist/runtime/loader.js +449 -0
  135. package/dist/runtime/not-found.js +61 -0
  136. package/dist/runtime/page-renderer.js +35 -0
  137. package/dist/runtime/preamble.js +47 -0
  138. package/dist/runtime/react-compat.js +14 -0
  139. package/dist/runtime/renderer-shared.js +10 -0
  140. package/dist/runtime/renderers/react-client.js +14 -0
  141. package/dist/runtime/renderers/react-server.js +99 -0
  142. package/dist/runtime/renderers/react.js +17 -0
  143. package/dist/runtime/renderers/types.js +1 -0
  144. package/dist/runtime/root-error-handlers.js +29 -0
  145. package/dist/runtime/router/history.js +132 -0
  146. package/dist/runtime/router/index.js +240 -0
  147. package/dist/runtime/router/utils.js +118 -0
  148. package/dist/runtime/script.js +110 -0
  149. package/dist/runtime/scroll.js +40 -0
  150. package/dist/runtime/slice.js +11 -0
  151. package/dist/runtime/ssr.js +240 -0
  152. package/dist/runtime/static-query.js +47 -0
  153. package/dist/utils.js +4 -0
  154. package/package.json +105 -3
  155. package/types/graphql-tada.d.ts +223 -0
  156. package/types/graphql.d.ts +2 -0
  157. package/types/index.d.ts +2287 -0
  158. package/types/node.d.ts +389 -0
  159. package/types/reporter.d.ts +187 -0
  160. package/types/router.d.ts +102 -0
  161. package/types/vendor/gql-tada.d.ts +2529 -0
@@ -0,0 +1,5 @@
1
+ import { createRequire } from "node:module";
2
+ // src/node/gql.ts
3
+ const g = createRequire(import.meta.url)("graphql");
4
+ const { BREAK, BreakingChangeType, DEFAULT_DEPRECATION_REASON, DangerousChangeType, DirectiveLocation, ExecutableDefinitionsRule, FieldsOnCorrectTypeRule, FragmentsOnCompositeTypesRule, GRAPHQL_MAX_INT, GRAPHQL_MIN_INT, GraphQLBoolean, GraphQLDeprecatedDirective, GraphQLDirective, GraphQLEnumType, GraphQLError, GraphQLFloat, GraphQLID, GraphQLIncludeDirective, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLOneOfDirective, GraphQLScalarType, GraphQLSchema, GraphQLSkipDirective, GraphQLSpecifiedByDirective, GraphQLString, GraphQLUnionType, Kind, KnownArgumentNamesRule, KnownDirectivesRule, KnownFragmentNamesRule, KnownTypeNamesRule, Lexer, Location, LoneAnonymousOperationRule, LoneSchemaDefinitionRule, MaxIntrospectionDepthRule, NoDeprecatedCustomRule, NoFragmentCyclesRule, NoSchemaIntrospectionCustomRule, NoUndefinedVariablesRule, NoUnusedFragmentsRule, NoUnusedVariablesRule, OperationTypeNode, OverlappingFieldsCanBeMergedRule, PossibleFragmentSpreadsRule, PossibleTypeExtensionsRule, ProvidedRequiredArgumentsRule, ScalarLeafsRule, SchemaMetaFieldDef, SingleFieldSubscriptionsRule, Source, Token, TokenKind, TypeInfo, TypeKind, TypeMetaFieldDef, TypeNameMetaFieldDef, UniqueArgumentDefinitionNamesRule, UniqueArgumentNamesRule, UniqueDirectiveNamesRule, UniqueDirectivesPerLocationRule, UniqueEnumValueNamesRule, UniqueFieldDefinitionNamesRule, UniqueFragmentNamesRule, UniqueInputFieldNamesRule, UniqueOperationNamesRule, UniqueOperationTypesRule, UniqueTypeNamesRule, UniqueVariableNamesRule, ValidationContext, ValuesOfCorrectTypeRule, VariablesAreInputTypesRule, VariablesInAllowedPositionRule, __Directive, __DirectiveLocation, __EnumValue, __Field, __InputValue, __Schema, __Type, __TypeKind, assertAbstractType, assertCompositeType, assertDirective, assertEnumType, assertEnumValueName, assertInputObjectType, assertInputType, assertInterfaceType, assertLeafType, assertListType, assertName, assertNamedType, assertNonNullType, assertNullableType, assertObjectType, assertOutputType, assertScalarType, assertSchema, assertType, assertUnionType, assertValidName, assertValidSchema, assertWrappingType, astFromValue, buildASTSchema, buildClientSchema, buildSchema, coerceInputValue, concatAST, createSourceEventStream, defaultFieldResolver, defaultTypeResolver, doTypesOverlap, execute, executeSync, extendSchema, findBreakingChanges, findDangerousChanges, formatError, getArgumentValues, getDirectiveValues, getEnterLeaveForKind, getIntrospectionQuery, getLocation, getNamedType, getNullableType, getOperationAST, getOperationRootType, getVariableValues, getVisitFn, graphql, graphqlSync, introspectionFromSchema, introspectionTypes, isAbstractType, isCompositeType, isConstValueNode, isDefinitionNode, isDirective, isEnumType, isEqualType, isExecutableDefinitionNode, isInputObjectType, isInputType, isInterfaceType, isIntrospectionType, isLeafType, isListType, isNamedType, isNonNullType, isNullableType, isObjectType, isOutputType, isRequiredArgument, isRequiredInputField, isScalarType, isSchema, isSchemaCoordinateNode, isSelectionNode, isSpecifiedDirective, isSpecifiedScalarType, isType, isTypeDefinitionNode, isTypeExtensionNode, isTypeNode, isTypeSubTypeOf, isTypeSystemDefinitionNode, isTypeSystemExtensionNode, isUnionType, isValidNameError, isValueNode, isWrappingType, lexicographicSortSchema, locatedError, parse, parseConstValue, parseSchemaCoordinate, parseType, parseValue, print, printError, printIntrospectionSchema, printLocation, printSchema, printSourceLocation, printType, recommendedRules, resolveASTSchemaCoordinate, resolveObjMapThunk, resolveReadonlyArrayThunk, resolveSchemaCoordinate, responsePathAsArray, separateOperations, specifiedDirectives, specifiedRules, specifiedScalarTypes, stripIgnoredCharacters, subscribe, syntaxError, typeFromAST, validate, validateSchema, valueFromAST, valueFromASTUntyped, version, versionInfo, visit, visitInParallel, visitWithTypeInfo } = g;
5
+ export { BREAK, BreakingChangeType, DEFAULT_DEPRECATION_REASON, DangerousChangeType, DirectiveLocation, ExecutableDefinitionsRule, FieldsOnCorrectTypeRule, FragmentsOnCompositeTypesRule, GRAPHQL_MAX_INT, GRAPHQL_MIN_INT, GraphQLBoolean, GraphQLDeprecatedDirective, GraphQLDirective, GraphQLEnumType, GraphQLError, GraphQLFloat, GraphQLID, GraphQLIncludeDirective, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLOneOfDirective, GraphQLScalarType, GraphQLSchema, GraphQLSkipDirective, GraphQLSpecifiedByDirective, GraphQLString, GraphQLUnionType, Kind, KnownArgumentNamesRule, KnownDirectivesRule, KnownFragmentNamesRule, KnownTypeNamesRule, Lexer, Location, LoneAnonymousOperationRule, LoneSchemaDefinitionRule, MaxIntrospectionDepthRule, NoDeprecatedCustomRule, NoFragmentCyclesRule, NoSchemaIntrospectionCustomRule, NoUndefinedVariablesRule, NoUnusedFragmentsRule, NoUnusedVariablesRule, OperationTypeNode, OverlappingFieldsCanBeMergedRule, PossibleFragmentSpreadsRule, PossibleTypeExtensionsRule, ProvidedRequiredArgumentsRule, ScalarLeafsRule, SchemaMetaFieldDef, SingleFieldSubscriptionsRule, Source, Token, TokenKind, TypeInfo, TypeKind, TypeMetaFieldDef, TypeNameMetaFieldDef, UniqueArgumentDefinitionNamesRule, UniqueArgumentNamesRule, UniqueDirectiveNamesRule, UniqueDirectivesPerLocationRule, UniqueEnumValueNamesRule, UniqueFieldDefinitionNamesRule, UniqueFragmentNamesRule, UniqueInputFieldNamesRule, UniqueOperationNamesRule, UniqueOperationTypesRule, UniqueTypeNamesRule, UniqueVariableNamesRule, ValidationContext, ValuesOfCorrectTypeRule, VariablesAreInputTypesRule, VariablesInAllowedPositionRule, __Directive, __DirectiveLocation, __EnumValue, __Field, __InputValue, __Schema, __Type, __TypeKind, assertAbstractType, assertCompositeType, assertDirective, assertEnumType, assertEnumValueName, assertInputObjectType, assertInputType, assertInterfaceType, assertLeafType, assertListType, assertName, assertNamedType, assertNonNullType, assertNullableType, assertObjectType, assertOutputType, assertScalarType, assertSchema, assertType, assertUnionType, assertValidName, assertValidSchema, assertWrappingType, astFromValue, buildASTSchema, buildClientSchema, buildSchema, coerceInputValue, concatAST, createSourceEventStream, g as default, defaultFieldResolver, defaultTypeResolver, doTypesOverlap, execute, executeSync, extendSchema, findBreakingChanges, findDangerousChanges, formatError, getArgumentValues, getDirectiveValues, getEnterLeaveForKind, getIntrospectionQuery, getLocation, getNamedType, getNullableType, getOperationAST, getOperationRootType, getVariableValues, getVisitFn, graphql, graphqlSync, introspectionFromSchema, introspectionTypes, isAbstractType, isCompositeType, isConstValueNode, isDefinitionNode, isDirective, isEnumType, isEqualType, isExecutableDefinitionNode, isInputObjectType, isInputType, isInterfaceType, isIntrospectionType, isLeafType, isListType, isNamedType, isNonNullType, isNullableType, isObjectType, isOutputType, isRequiredArgument, isRequiredInputField, isScalarType, isSchema, isSchemaCoordinateNode, isSelectionNode, isSpecifiedDirective, isSpecifiedScalarType, isType, isTypeDefinitionNode, isTypeExtensionNode, isTypeNode, isTypeSubTypeOf, isTypeSystemDefinitionNode, isTypeSystemExtensionNode, isUnionType, isValidNameError, isValueNode, isWrappingType, lexicographicSortSchema, locatedError, parse, parseConstValue, parseSchemaCoordinate, parseType, parseValue, print, printError, printIntrospectionSchema, printLocation, printSchema, printSourceLocation, printType, recommendedRules, resolveASTSchemaCoordinate, resolveObjMapThunk, resolveReadonlyArrayThunk, resolveSchemaCoordinate, responsePathAsArray, separateOperations, specifiedDirectives, specifiedRules, specifiedScalarTypes, stripIgnoredCharacters, subscribe, syntaxError, typeFromAST, validate, validateSchema, valueFromAST, valueFromASTUntyped, version, versionInfo, visit, visitInParallel, visitWithTypeInfo };
@@ -0,0 +1,15 @@
1
+ import { build } from "./build/index.js";
2
+ import { develop } from "./develop/index.js";
3
+ import { serve } from "./serve.js";
4
+ import { LogFileDataStore, logFileDataStore } from "./datastore/logfile/index.js";
5
+ import { bootstrap } from "./bootstrap.js";
6
+ import "./datastore/index.js";
7
+ import reporter from "./reporter.js";
8
+ import { createContentDigest } from "./utils/content-digest.js";
9
+ import { createNodeId } from "./utils/create-node-id.js";
10
+ // src/node/index.ts
11
+ /** Identity helper giving type inference for gatsby-config.ts */
12
+ function defineConfig(config) {
13
+ return config;
14
+ }
15
+ export { LogFileDataStore, bootstrap, build, createContentDigest, createNodeId, defineConfig, develop, logFileDataStore, reporter, serve };
@@ -0,0 +1,270 @@
1
+ import { resolveApiFile } from "./loader/import-module.js";
2
+ import { GATSBY_ENV_ALIASES } from "./utils/env.js";
3
+ import { availableMemoryMb, totalMemoryMb, userHeapLimit } from "./utils/memory.js";
4
+ import path from "node:path";
5
+ import fs from "node:fs";
6
+ import os from "node:os";
7
+ import { fileURLToPath } from "node:url";
8
+ import v8 from "node:v8";
9
+ // src/node/info.ts
10
+ /**
11
+ * `goatly info`: a report of the environment (system, runtime, memory, site files and the
12
+ * installed versions of the packages that matter), meant to be pasted into bug reports. It reads
13
+ * files only – gatsby-config and gatsby-node are not loaded – and never throws: what it cannot find
14
+ * is reported as missing.
15
+ */
16
+ const MB = 1048576;
17
+ /** a cap on directory walks, so `info` stays fast on .cache/public of very large sites */
18
+ const MAX_WALK_ENTRIES = 25e4;
19
+ const API_FILES = [
20
+ "gatsby-config",
21
+ "gatsby-node",
22
+ "gatsby-browser",
23
+ "gatsby-ssr"
24
+ ];
25
+ /** packages always reported, listed in the site's package.json or not */
26
+ const CORE_PACKAGES = [
27
+ "gatsby",
28
+ "goatly",
29
+ "react",
30
+ "react-dom",
31
+ "vite",
32
+ "typescript"
33
+ ];
34
+ /**
35
+ * environment variables that are safe to print and affect builds (not GATSBY_*: may hold keys,
36
+ * except the Gatsby options that goatly reads, see utils/env)
37
+ */
38
+ const ENV_NAMES = [
39
+ "NODE_ENV",
40
+ "NODE_OPTIONS",
41
+ "BUN_OPTIONS",
42
+ "CI",
43
+ ...Object.keys(GATSBY_ENV_ALIASES),
44
+ ...Object.values(GATSBY_ENV_ALIASES)
45
+ ];
46
+ function readJson(file) {
47
+ try {
48
+ return JSON.parse(fs.readFileSync(file, "utf8"));
49
+ } catch {
50
+ return;
51
+ }
52
+ }
53
+ /** the package.json of `name` as Node would resolve it from `directory` (exports maps ignored) */
54
+ function findInstalledPackage(directory, name) {
55
+ let dir = path.resolve(directory);
56
+ for (;;) {
57
+ const candidate = path.join(dir, "node_modules", name, "package.json");
58
+ const pkg = readJson(candidate);
59
+ if (pkg) return {
60
+ version: pkg.version,
61
+ name: pkg.name,
62
+ dir: path.dirname(candidate)
63
+ };
64
+ const parent = path.dirname(dir);
65
+ if (parent === dir) return void 0;
66
+ dir = parent;
67
+ }
68
+ }
69
+ /** plugins and themes by naming convention (gatsby-plugin-*, gatsby-source-*, @scope/gatsby-*) */
70
+ function isGatsbyPackage(name) {
71
+ return /^(@[^/]+\/)?gatsby-/.test(name);
72
+ }
73
+ /** files and bytes below `dir`, capped at `limit` entries */
74
+ function directorySize(dir, limit = MAX_WALK_ENTRIES) {
75
+ let stat;
76
+ try {
77
+ stat = fs.statSync(dir);
78
+ } catch {
79
+ return {
80
+ path: dir,
81
+ exists: false
82
+ };
83
+ }
84
+ let files = 0;
85
+ let bytes = 0;
86
+ let entries = 0;
87
+ let truncated = false;
88
+ const stack = [dir];
89
+ while (stack.length && !truncated) {
90
+ const current = stack.pop();
91
+ let dirents;
92
+ try {
93
+ dirents = fs.readdirSync(current, { withFileTypes: true });
94
+ } catch {
95
+ continue;
96
+ }
97
+ for (const dirent of dirents) {
98
+ if (++entries > limit) {
99
+ truncated = true;
100
+ break;
101
+ }
102
+ const full = path.join(current, dirent.name);
103
+ if (dirent.isDirectory()) stack.push(full);
104
+ else if (dirent.isFile()) {
105
+ files++;
106
+ try {
107
+ bytes += fs.statSync(full).size;
108
+ } catch {}
109
+ }
110
+ }
111
+ }
112
+ return {
113
+ path: dir,
114
+ exists: true,
115
+ files,
116
+ bytes,
117
+ ...truncated ? { truncated } : {},
118
+ modified: stat.mtime.toISOString()
119
+ };
120
+ }
121
+ /** `pnpm 10.34.9` from npm_config_user_agent (set by npm, pnpm, yarn and bun when they run scripts) */
122
+ function packageManagerFromUserAgent(userAgent) {
123
+ const match = /^([\w-]+)\/(\S+)/.exec(userAgent ?? "");
124
+ return match ? `${match[1]} ${match[2]}` : void 0;
125
+ }
126
+ function heapLimitSource(env) {
127
+ const chosen = userHeapLimit(env);
128
+ if (chosen) return chosen.source;
129
+ if (env.GOATLY_RESPAWNED) return "goatly (75% of the memory)";
130
+ return "Node.js default";
131
+ }
132
+ function isContainer() {
133
+ if (fs.existsSync("/.dockerenv") || fs.existsSync("/run/.containerenv")) return true;
134
+ try {
135
+ return /docker|containerd|kubepods|lxc/.test(fs.readFileSync("/proc/1/cgroup", "utf8"));
136
+ } catch {
137
+ return false;
138
+ }
139
+ }
140
+ function goatlyPackage() {
141
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
142
+ return {
143
+ version: readJson(path.join(root, "package.json"))?.version,
144
+ path: root
145
+ };
146
+ }
147
+ function collectInfo(directory, env = process.env) {
148
+ const sitePackage = readJson(path.join(directory, "package.json"));
149
+ const declared = {
150
+ ...sitePackage?.devDependencies,
151
+ ...sitePackage?.peerDependencies,
152
+ ...sitePackage?.dependencies
153
+ };
154
+ const names = [...CORE_PACKAGES, ...Object.keys(declared).filter((name) => isGatsbyPackage(name)).sort()];
155
+ const packages = [];
156
+ for (const name of new Set(names)) {
157
+ const installed = findInstalledPackage(directory, name);
158
+ const wanted = declared[name];
159
+ if (!installed && !wanted) continue;
160
+ packages.push({
161
+ name,
162
+ ...wanted ? { wanted } : {},
163
+ ...installed?.version ? { installed: installed.version } : {},
164
+ ...installed?.name && installed.name !== name ? { installedAs: installed.name } : {}
165
+ });
166
+ }
167
+ const bun = process.versions.bun;
168
+ const cpus = os.cpus();
169
+ const reported = {};
170
+ for (const [name, value] of Object.entries(env)) {
171
+ if (value === void 0) continue;
172
+ if (name.startsWith("GOATLY_") || name.startsWith("BUN_JSC_") || ENV_NAMES.includes(name)) reported[name] = value;
173
+ }
174
+ return {
175
+ goatly: goatlyPackage(),
176
+ system: {
177
+ os: `${os.type()} ${os.release()}`,
178
+ arch: process.arch,
179
+ cpus: typeof os.availableParallelism === "function" ? os.availableParallelism() : cpus.length,
180
+ ...cpus[0]?.model ? { cpuModel: cpus[0].model.trim() } : {},
181
+ ...process.platform === "linux" ? { container: isContainer() } : {}
182
+ },
183
+ runtime: {
184
+ name: bun ? "Bun" : "Node.js",
185
+ version: bun ?? process.versions.node,
186
+ ...packageManagerFromUserAgent(env.npm_config_user_agent) ? { packageManager: packageManagerFromUserAgent(env.npm_config_user_agent) } : {}
187
+ },
188
+ memory: {
189
+ totalMb: totalMemoryMb(),
190
+ availableMb: availableMemoryMb(),
191
+ ...bun ? {} : { heapLimitMb: Math.round(v8.getHeapStatistics().heap_size_limit / MB) },
192
+ heapLimitSource: bun ? "none on Bun (worker threads have budgets)" : heapLimitSource(env)
193
+ },
194
+ site: {
195
+ directory,
196
+ packageJson: !!sitePackage,
197
+ apiFiles: Object.fromEntries(API_FILES.map((base) => {
198
+ const file = resolveApiFile(directory, base);
199
+ return [base, file && path.basename(file)];
200
+ })),
201
+ cache: directorySize(path.join(directory, ".cache")),
202
+ public: directorySize(path.join(directory, "public"))
203
+ },
204
+ packages,
205
+ env: reported
206
+ };
207
+ }
208
+ function formatBytes(bytes) {
209
+ if (bytes < 1024) return `${bytes} B`;
210
+ const units = [
211
+ "KB",
212
+ "MB",
213
+ "GB",
214
+ "TB"
215
+ ];
216
+ let value = bytes / 1024;
217
+ let unit = 0;
218
+ while (value >= 1024 && unit < units.length - 1) {
219
+ value /= 1024;
220
+ unit++;
221
+ }
222
+ return `${value.toFixed(value < 10 ? 1 : 0)} ${units[unit]}`;
223
+ }
224
+ /** replaces the home directory with ~, so reports can be shared without the user name */
225
+ function tildify(p) {
226
+ const home = os.homedir();
227
+ return home && (p === home || p.startsWith(home + path.sep)) ? "~" + p.slice(home.length) : p;
228
+ }
229
+ function formatDirectory(info) {
230
+ if (!info.exists) return "missing";
231
+ const more = info.truncated ? "≥ " : "";
232
+ return `${more}${info.files} files, ${more}${formatBytes(info.bytes ?? 0)}, modified ${info.modified}`;
233
+ }
234
+ /** the report as Markdown-friendly text */
235
+ function formatInfo(info) {
236
+ const lines = [];
237
+ const section = (title, rows) => {
238
+ const shown = rows.filter((row) => row[1] !== void 0);
239
+ if (!shown.length) return;
240
+ lines.push("", ` ${title}:`);
241
+ const width = Math.max(...shown.map(([key]) => key.length)) + 1;
242
+ for (const [key, value] of shown) lines.push(` ${(key + ":").padEnd(width + 1)}${value}`);
243
+ };
244
+ const { system, runtime, memory, site } = info;
245
+ section("goatly", [["Version", info.goatly.version ?? "unknown"], ["Path", tildify(info.goatly.path)]]);
246
+ section("System", [
247
+ ["OS", `${system.os} (${system.arch})${system.container ? ", in a container" : ""}`],
248
+ ["CPU", `${system.cpus} × ${system.cpuModel ?? "unknown"}`],
249
+ ["Memory", `${formatBytes(memory.totalMb * MB)} total, ${formatBytes(memory.availableMb * MB)} available`]
250
+ ]);
251
+ section("Runtime", [
252
+ [runtime.name, runtime.version],
253
+ ["Heap limit", memory.heapLimitMb === void 0 ? memory.heapLimitSource : `${formatBytes(memory.heapLimitMb * MB)} (${memory.heapLimitSource})`],
254
+ ["Package manager", runtime.packageManager]
255
+ ]);
256
+ section("Site", [
257
+ ["Directory", tildify(site.directory)],
258
+ ["package.json", site.packageJson ? "found" : "missing"],
259
+ ...Object.entries(site.apiFiles).map(([base, file]) => [base, file ?? "none"]),
260
+ [".cache", formatDirectory(site.cache)],
261
+ ["public", formatDirectory(site.public)]
262
+ ]);
263
+ section("Packages", info.packages.map((pkg) => {
264
+ const installed = pkg.installed ? `${pkg.installedAs ? `${pkg.installedAs} ` : ""}${pkg.installed}` : "not installed";
265
+ return [pkg.name, pkg.wanted ? `${installed} (wanted ${pkg.wanted})` : installed];
266
+ }));
267
+ section("Environment", Object.entries(info.env).sort(([a], [b]) => a.localeCompare(b)));
268
+ return lines.join("\n").slice(1) + "\n";
269
+ }
270
+ export { MAX_WALK_ENTRIES, collectInfo, directorySize, findInstalledPackage, formatBytes, formatInfo, isGatsbyPackage, packageManagerFromUserAgent };
@@ -0,0 +1,196 @@
1
+ import { createContentDigest } from "../utils/content-digest.js";
2
+ import { store } from "../redux/index.js";
3
+ import { rootFree } from "../schema/inline-objects.js";
4
+ import { PROD_404_PLUGIN, scopedMirrorTargets } from "../not-found-pages.js";
5
+ import { ON_CREATE_PAGE_FILTER } from "../api-runner.js";
6
+ // src/node/internal-plugins/data-bridge.ts
7
+ /** the pages prod-404-500 mirrors to `/404.html` and `/500.html` */
8
+ const ERROR_PAGE = /^\/?(404|500)\/?$/;
9
+ /**
10
+ * `internal-data-bridge`: creates Site, SiteBuildMetadata and SitePlugin nodes
11
+ * and defines their types (the SitePage nodes of the pages are created once they are read, see
12
+ * site-page-nodes.ts).
13
+ */
14
+ function createDataBridgePlugin() {
15
+ return {
16
+ name: "internal-data-bridge",
17
+ resolve: "internal-data-bridge",
18
+ module: {
19
+ createSchemaCustomization({ actions }) {
20
+ actions.createTypes(`
21
+ type SitePage implements Node @dontInfer {
22
+ path: String!
23
+ component: String!
24
+ internalComponentName: String!
25
+ componentChunkName: String!
26
+ matchPath: String
27
+ pageContext: JSON
28
+ pluginCreator: SitePlugin @link(from: "pluginCreatorId")
29
+ }
30
+ type SitePlugin implements Node @infer {
31
+ resolve: String
32
+ name: String
33
+ version: String
34
+ nodeAPIs: [String]
35
+ browserAPIs: [String]
36
+ ssrAPIs: [String]
37
+ pluginFilepath: String
38
+ pluginOptions: JSON
39
+ packageJson: JSON
40
+ }
41
+ type Site implements Node @infer {
42
+ buildTime: Date @dateformat
43
+ siteMetadata: SiteSiteMetadata
44
+ }
45
+ type SiteSiteMetadata {
46
+ title: String
47
+ description: String
48
+ siteUrl: String
49
+ }
50
+ type SiteBuildMetadata implements Node @infer {
51
+ buildTime: Date @dateformat
52
+ }
53
+ `);
54
+ },
55
+ createResolvers({ createResolvers }) {
56
+ createResolvers({ Site: { buildTime: {
57
+ type: "Date",
58
+ resolve: rootFree((source, args, context, info) => {
59
+ const meta = context.nodeModel.getNodeById({
60
+ id: "SiteBuildMetadata",
61
+ type: "SiteBuildMetadata"
62
+ });
63
+ return info.originalResolver({
64
+ ...source,
65
+ buildTime: meta?.buildTime
66
+ }, args, context, info);
67
+ })
68
+ } } });
69
+ },
70
+ sourceNodes({ actions }) {
71
+ const { createNode } = actions;
72
+ const { config, program, flattenedPlugins } = store.getState();
73
+ for (const plugin of flattenedPlugins) {
74
+ const data = {
75
+ resolve: plugin.resolve,
76
+ name: plugin.name,
77
+ version: plugin.version,
78
+ nodeAPIs: plugin.nodeAPIs,
79
+ browserAPIs: plugin.browserAPIs,
80
+ ssrAPIs: plugin.ssrAPIs,
81
+ pluginFilepath: plugin.pluginFilepath,
82
+ pluginOptions: serializable(plugin.pluginOptions),
83
+ packageJson: {}
84
+ };
85
+ createNode({
86
+ ...data,
87
+ id: plugin.id,
88
+ parent: null,
89
+ children: [],
90
+ internal: {
91
+ type: "SitePlugin",
92
+ contentDigest: createContentDigest(data)
93
+ }
94
+ });
95
+ }
96
+ const buildTime = (/* @__PURE__ */ new Date()).toJSON();
97
+ createNode({
98
+ id: "SiteBuildMetadata",
99
+ parent: null,
100
+ children: [],
101
+ buildTime,
102
+ internal: {
103
+ type: "SiteBuildMetadata",
104
+ contentDigest: createContentDigest(buildTime)
105
+ }
106
+ });
107
+ const site = {
108
+ siteMetadata: { ...config.siteMetadata },
109
+ port: program.port,
110
+ host: program.host,
111
+ pathPrefix: config.pathPrefix,
112
+ polyfill: config.polyfill,
113
+ jsxRuntime: config.jsxRuntime,
114
+ trailingSlash: config.trailingSlash,
115
+ graphqlTypegen: !!config.graphqlTypegen
116
+ };
117
+ createNode({
118
+ ...site,
119
+ id: "Site",
120
+ parent: null,
121
+ children: [],
122
+ internal: {
123
+ type: "Site",
124
+ contentDigest: createContentDigest(site)
125
+ }
126
+ });
127
+ }
128
+ }
129
+ };
130
+ }
131
+ function serializable(value) {
132
+ return JSON.parse(JSON.stringify(value, (_k, v) => {
133
+ if (typeof v === "function") return void 0;
134
+ if (v instanceof RegExp) return v.toString();
135
+ if (v && typeof v === "object" && v.module && v.resolve && v.name) {
136
+ const { module: _m, gatsbyNodeModule: _g, ...rest } = v;
137
+ return rest;
138
+ }
139
+ return v;
140
+ }) ?? "null");
141
+ }
142
+ /**
143
+ * The context of a section's copy of its 404 page: `path` / `matchPath` in the context (allowed
144
+ * when they equal the page's) follow the copy's, or createPage would reject the copy.
145
+ */
146
+ function mirrorContext(page, htmlPath) {
147
+ const context = page.context;
148
+ if (!context || typeof context !== "object" || !("path" in context || "matchPath" in context)) return context;
149
+ const { matchPath: _matchPath, ...rest } = context;
150
+ return "path" in context ? {
151
+ ...rest,
152
+ path: htmlPath
153
+ } : rest;
154
+ }
155
+ /**
156
+ * Gatsby's `prod-404-500` internal plugin: mirrors /404/ to /404.html and /500/ to /500.html. With
157
+ * `notFoundPages`, also the 404 page of each site section to `<section>/404.html`.
158
+ */
159
+ function createProd404Plugin() {
160
+ return {
161
+ name: PROD_404_PLUGIN,
162
+ resolve: PROD_404_PLUGIN,
163
+ module: {
164
+ [ON_CREATE_PAGE_FILTER]: ((page) => {
165
+ if (ERROR_PAGE.test(page.path)) return true;
166
+ const scopes = store.getState().config.notFoundPages ?? [];
167
+ return scopes.length > 0 && scopedMirrorTargets(page.path, scopes).length > 0;
168
+ }),
169
+ onCreatePage({ page, actions }) {
170
+ const { pages, config, flattenedPlugins } = store.getState();
171
+ const m = ERROR_PAGE.exec(page.path);
172
+ if (m && !pages.has(`/${m[1]}.html`)) actions.createPage({
173
+ ...page,
174
+ path: `/${m[1]}.html`,
175
+ context: page.context
176
+ });
177
+ const scopes = config.notFoundPages ?? [];
178
+ if (!scopes.length) return;
179
+ const targets = scopedMirrorTargets(page.path, scopes);
180
+ if (!targets.length) return;
181
+ const own = flattenedPlugins.find((p) => p.name === PROD_404_PLUGIN)?.id;
182
+ for (const htmlPath of targets) {
183
+ const existing = store.getState().pages.get(htmlPath);
184
+ if (existing && existing.pluginCreatorId !== own) continue;
185
+ actions.createPage({
186
+ ...page,
187
+ path: htmlPath,
188
+ matchPath: void 0,
189
+ context: mirrorContext(page, htmlPath)
190
+ });
191
+ }
192
+ }
193
+ }
194
+ };
195
+ }
196
+ export { createDataBridgePlugin, createProd404Plugin };