@superblocksteam/vite-plugin-file-sync 2.0.175-next.0 → 2.0.176

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 (286) hide show
  1. package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
  2. package/dist/ai-service/agent/prompts/build-base-system-prompt.js +1 -11
  3. package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
  4. package/dist/ai-service/agent/tools/apis/get-api-docs.d.ts +3 -3
  5. package/dist/ai-service/agent/tools/apis/test-api.d.ts +13 -78
  6. package/dist/ai-service/agent/tools/apis/test-api.d.ts.map +1 -1
  7. package/dist/ai-service/agent/tools/apis/test-api.js +50 -52
  8. package/dist/ai-service/agent/tools/apis/test-api.js.map +1 -1
  9. package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts +3 -11
  10. package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts.map +1 -1
  11. package/dist/ai-service/agent/tools/build-capture-screenshot.js +8 -13
  12. package/dist/ai-service/agent/tools/build-capture-screenshot.js.map +1 -1
  13. package/dist/ai-service/agent/tools/build-navigate-preview.d.ts +0 -6
  14. package/dist/ai-service/agent/tools/build-navigate-preview.d.ts.map +1 -1
  15. package/dist/ai-service/agent/tools/build-navigate-preview.js +4 -5
  16. package/dist/ai-service/agent/tools/build-navigate-preview.js.map +1 -1
  17. package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.d.ts +1 -4
  18. package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.d.ts.map +1 -1
  19. package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.js +3 -6
  20. package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.js.map +1 -1
  21. package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts +4 -11
  22. package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts.map +1 -1
  23. package/dist/ai-service/agent/tools/databases/dev-database-tasks.js +3 -21
  24. package/dist/ai-service/agent/tools/databases/dev-database-tasks.js.map +1 -1
  25. package/dist/ai-service/agent/tools/databases/dev-database-tools.d.ts.map +1 -1
  26. package/dist/ai-service/agent/tools/databases/dev-database-tools.js +5 -32
  27. package/dist/ai-service/agent/tools/databases/dev-database-tools.js.map +1 -1
  28. package/dist/ai-service/agent/tools/get-logs.d.ts +2 -5
  29. package/dist/ai-service/agent/tools/get-logs.d.ts.map +1 -1
  30. package/dist/ai-service/agent/tools/get-logs.js +3 -6
  31. package/dist/ai-service/agent/tools/get-logs.js.map +1 -1
  32. package/dist/ai-service/agent/tools/get-runtime-errors.d.ts +0 -2
  33. package/dist/ai-service/agent/tools/get-runtime-errors.d.ts.map +1 -1
  34. package/dist/ai-service/agent/tools/get-runtime-errors.js +2 -3
  35. package/dist/ai-service/agent/tools/get-runtime-errors.js.map +1 -1
  36. package/dist/ai-service/agent/tools/get-security-findings.js +1 -1
  37. package/dist/ai-service/agent/tools/integrations/execute-request.d.ts +5 -5
  38. package/dist/ai-service/agent/tools/integrations/metadata.d.ts +1 -1
  39. package/dist/ai-service/agent/tools/integrations/metadata.js.map +1 -1
  40. package/dist/ai-service/agent/tools/report-security-findings.d.ts +3 -3
  41. package/dist/ai-service/agent/tools.d.ts +5 -1
  42. package/dist/ai-service/agent/tools.d.ts.map +1 -1
  43. package/dist/ai-service/agent/tools.js +42 -7
  44. package/dist/ai-service/agent/tools.js.map +1 -1
  45. package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts +3 -4
  46. package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts.map +1 -1
  47. package/dist/ai-service/agent/tools2/tools/grep-metadata.js +2 -4
  48. package/dist/ai-service/agent/tools2/tools/grep-metadata.js.map +1 -1
  49. package/dist/ai-service/agent/tools2/tools/grep.d.ts.map +1 -1
  50. package/dist/ai-service/agent/tools2/tools/grep.js +5 -27
  51. package/dist/ai-service/agent/tools2/tools/grep.js.map +1 -1
  52. package/dist/ai-service/app-interface/file-system-interface.d.ts +1 -1
  53. package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.d.ts +1 -2
  54. package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.d.ts.map +1 -1
  55. package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.js +2 -9
  56. package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.js.map +1 -1
  57. package/dist/ai-service/app-interface/filesystem/virtual-file-system.d.ts +0 -1
  58. package/dist/ai-service/app-interface/filesystem/virtual-file-system.d.ts.map +1 -1
  59. package/dist/ai-service/app-interface/filesystem/virtual-file-system.js +1 -1
  60. package/dist/ai-service/app-interface/filesystem/virtual-file-system.js.map +1 -1
  61. package/dist/ai-service/app-interface/npm-registry.d.ts +0 -1
  62. package/dist/ai-service/app-interface/npm-registry.d.ts.map +1 -1
  63. package/dist/ai-service/app-interface/npm-registry.js +6 -45
  64. package/dist/ai-service/app-interface/npm-registry.js.map +1 -1
  65. package/dist/ai-service/app-interface/shell.d.ts +1 -4
  66. package/dist/ai-service/app-interface/shell.d.ts.map +1 -1
  67. package/dist/ai-service/app-interface/shell.js +8 -26
  68. package/dist/ai-service/app-interface/shell.js.map +1 -1
  69. package/dist/ai-service/chat/chat-session-store.d.ts +1 -10
  70. package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
  71. package/dist/ai-service/chat/chat-session-store.js +1 -30
  72. package/dist/ai-service/chat/chat-session-store.js.map +1 -1
  73. package/dist/ai-service/dev-database-client.d.ts +0 -1
  74. package/dist/ai-service/dev-database-client.d.ts.map +1 -1
  75. package/dist/ai-service/dev-database-client.js +0 -1
  76. package/dist/ai-service/dev-database-client.js.map +1 -1
  77. package/dist/ai-service/dev-database-file-sync.d.ts +1 -3
  78. package/dist/ai-service/dev-database-file-sync.d.ts.map +1 -1
  79. package/dist/ai-service/dev-database-file-sync.js.map +1 -1
  80. package/dist/ai-service/features.d.ts +8 -15
  81. package/dist/ai-service/features.d.ts.map +1 -1
  82. package/dist/ai-service/features.js +8 -15
  83. package/dist/ai-service/features.js.map +1 -1
  84. package/dist/ai-service/index.d.ts +19 -34
  85. package/dist/ai-service/index.d.ts.map +1 -1
  86. package/dist/ai-service/index.js +738 -474
  87. package/dist/ai-service/index.js.map +1 -1
  88. package/dist/ai-service/llm/context-v2/context-metrics.js +2 -2
  89. package/dist/ai-service/llm/context-v2/manager.d.ts +1 -3
  90. package/dist/ai-service/llm/context-v2/manager.d.ts.map +1 -1
  91. package/dist/ai-service/llm/context-v2/manager.js +0 -5
  92. package/dist/ai-service/llm/context-v2/manager.js.map +1 -1
  93. package/dist/ai-service/llm/context-v2/types.d.ts +1 -1
  94. package/dist/ai-service/llm/context-v2/types.d.ts.map +1 -1
  95. package/dist/ai-service/llm/context-v2/types.js.map +1 -1
  96. package/dist/ai-service/llm/stream/config.d.ts +1 -1
  97. package/dist/ai-service/llm/stream/config.d.ts.map +1 -1
  98. package/dist/ai-service/llm/stream/config.js.map +1 -1
  99. package/dist/ai-service/llm/stream/errors.d.ts +1 -4
  100. package/dist/ai-service/llm/stream/errors.d.ts.map +1 -1
  101. package/dist/ai-service/llm/stream/errors.js +2 -8
  102. package/dist/ai-service/llm/stream/errors.js.map +1 -1
  103. package/dist/ai-service/llm/stream/orchestrator.d.ts.map +1 -1
  104. package/dist/ai-service/llm/stream/orchestrator.js +6 -3
  105. package/dist/ai-service/llm/stream/orchestrator.js.map +1 -1
  106. package/dist/ai-service/llmobs/tracer.d.ts.map +1 -1
  107. package/dist/ai-service/llmobs/tracer.js +21 -4
  108. package/dist/ai-service/llmobs/tracer.js.map +1 -1
  109. package/dist/ai-service/managed-native-db-availability.d.ts +1 -1
  110. package/dist/ai-service/managed-native-db-availability.d.ts.map +1 -1
  111. package/dist/ai-service/managed-native-db-availability.js +2 -4
  112. package/dist/ai-service/managed-native-db-availability.js.map +1 -1
  113. package/dist/ai-service/policy-gate-remediation-usage.d.ts +1 -2
  114. package/dist/ai-service/policy-gate-remediation-usage.d.ts.map +1 -1
  115. package/dist/ai-service/policy-gate-remediation-usage.js +1 -2
  116. package/dist/ai-service/policy-gate-remediation-usage.js.map +1 -1
  117. package/dist/ai-service/skills/system/materialized.d.ts +1 -3
  118. package/dist/ai-service/skills/system/materialized.d.ts.map +1 -1
  119. package/dist/ai-service/skills/system/materialized.js +3 -3
  120. package/dist/ai-service/skills/system/materialized.js.map +1 -1
  121. package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
  122. package/dist/ai-service/state-machine/handlers/llm-generating.js +4 -6
  123. package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
  124. package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.d.ts +1 -1
  125. package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.d.ts.map +1 -1
  126. package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.js +1 -1
  127. package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.js.map +1 -1
  128. package/dist/ai-service/state-machine/helpers/user-response-message.d.ts.map +1 -1
  129. package/dist/ai-service/state-machine/helpers/user-response-message.js +2 -4
  130. package/dist/ai-service/state-machine/helpers/user-response-message.js.map +1 -1
  131. package/dist/ai-service/types.d.ts +0 -3
  132. package/dist/ai-service/types.d.ts.map +1 -1
  133. package/dist/ai-service/types.js.map +1 -1
  134. package/dist/extract-api-integrations.d.ts +91 -52
  135. package/dist/extract-api-integrations.d.ts.map +1 -1
  136. package/dist/extract-api-integrations.js +487 -512
  137. package/dist/extract-api-integrations.js.map +1 -1
  138. package/dist/file-sync-vite-plugin.d.ts.map +1 -1
  139. package/dist/file-sync-vite-plugin.js +5 -53
  140. package/dist/file-sync-vite-plugin.js.map +1 -1
  141. package/dist/file-system-helpers.d.ts.map +1 -1
  142. package/dist/file-system-helpers.js +2 -3
  143. package/dist/file-system-helpers.js.map +1 -1
  144. package/dist/git-service/index.d.ts +0 -1
  145. package/dist/git-service/index.d.ts.map +1 -1
  146. package/dist/git-service/index.js +38 -6
  147. package/dist/git-service/index.js.map +1 -1
  148. package/dist/git-service/managed-excludes.d.ts.map +1 -1
  149. package/dist/git-service/managed-excludes.js +0 -2
  150. package/dist/git-service/managed-excludes.js.map +1 -1
  151. package/dist/index.d.ts +0 -1
  152. package/dist/index.d.ts.map +1 -1
  153. package/dist/index.js +0 -1
  154. package/dist/index.js.map +1 -1
  155. package/dist/injected-index.d.ts +3 -1
  156. package/dist/injected-index.d.ts.map +1 -1
  157. package/dist/injected-index.js +8 -3
  158. package/dist/injected-index.js.map +1 -1
  159. package/dist/lock-service/index.d.ts +0 -3
  160. package/dist/lock-service/index.d.ts.map +1 -1
  161. package/dist/lock-service/index.js +0 -7
  162. package/dist/lock-service/index.js.map +1 -1
  163. package/dist/migration/get-fullstack-template-dir.d.ts +5 -2
  164. package/dist/migration/get-fullstack-template-dir.d.ts.map +1 -1
  165. package/dist/migration/get-fullstack-template-dir.js +8 -5
  166. package/dist/migration/get-fullstack-template-dir.js.map +1 -1
  167. package/dist/migration-templates/app-fullstack/.gitignore +50 -0
  168. package/dist/plugin-options.d.ts +1 -1
  169. package/dist/plugin-options.d.ts.map +1 -1
  170. package/dist/policy-gate-runner.d.ts +7 -32
  171. package/dist/policy-gate-runner.d.ts.map +1 -1
  172. package/dist/policy-gate-runner.js +6 -23
  173. package/dist/policy-gate-runner.js.map +1 -1
  174. package/dist/socket-manager.d.ts +2 -9
  175. package/dist/socket-manager.d.ts.map +1 -1
  176. package/dist/socket-manager.js +19 -160
  177. package/dist/socket-manager.js.map +1 -1
  178. package/dist/sync-service/draft-helpers.d.ts +0 -9
  179. package/dist/sync-service/draft-helpers.d.ts.map +1 -1
  180. package/dist/sync-service/draft-helpers.js +0 -135
  181. package/dist/sync-service/draft-helpers.js.map +1 -1
  182. package/dist/sync-service/index.d.ts +1 -24
  183. package/dist/sync-service/index.d.ts.map +1 -1
  184. package/dist/sync-service/index.js +9 -197
  185. package/dist/sync-service/index.js.map +1 -1
  186. package/dist/sync-service/list-dir.d.ts +1 -3
  187. package/dist/sync-service/list-dir.d.ts.map +1 -1
  188. package/dist/sync-service/list-dir.js +1 -7
  189. package/dist/sync-service/list-dir.js.map +1 -1
  190. package/dist/util/log-sanitizer.d.ts +0 -4
  191. package/dist/util/log-sanitizer.d.ts.map +1 -1
  192. package/dist/util/log-sanitizer.js +0 -7
  193. package/dist/util/log-sanitizer.js.map +1 -1
  194. package/package.json +52 -57
  195. package/dist/agent-tool-executor/codex-drafts.d.ts +0 -12
  196. package/dist/agent-tool-executor/codex-drafts.d.ts.map +0 -1
  197. package/dist/agent-tool-executor/codex-drafts.js +0 -48
  198. package/dist/agent-tool-executor/codex-drafts.js.map +0 -1
  199. package/dist/agent-tool-executor/codex-exec-server.d.ts +0 -42
  200. package/dist/agent-tool-executor/codex-exec-server.d.ts.map +0 -1
  201. package/dist/agent-tool-executor/codex-exec-server.js +0 -405
  202. package/dist/agent-tool-executor/codex-exec-server.js.map +0 -1
  203. package/dist/agent-tool-executor/codex-execution-policy.d.ts +0 -12
  204. package/dist/agent-tool-executor/codex-execution-policy.d.ts.map +0 -1
  205. package/dist/agent-tool-executor/codex-execution-policy.js +0 -201
  206. package/dist/agent-tool-executor/codex-execution-policy.js.map +0 -1
  207. package/dist/agent-tool-executor/native-dotenv-watch-scope.d.ts +0 -12
  208. package/dist/agent-tool-executor/native-dotenv-watch-scope.d.ts.map +0 -1
  209. package/dist/agent-tool-executor/native-dotenv-watch-scope.js +0 -74
  210. package/dist/agent-tool-executor/native-dotenv-watch-scope.js.map +0 -1
  211. package/dist/ai-service/agent/security-scan-tools.d.ts +0 -12
  212. package/dist/ai-service/agent/security-scan-tools.d.ts.map +0 -1
  213. package/dist/ai-service/agent/security-scan-tools.js +0 -44
  214. package/dist/ai-service/agent/security-scan-tools.js.map +0 -1
  215. package/dist/ai-service/builder-conversation.d.ts +0 -70
  216. package/dist/ai-service/builder-conversation.d.ts.map +0 -1
  217. package/dist/ai-service/builder-conversation.js +0 -660
  218. package/dist/ai-service/builder-conversation.js.map +0 -1
  219. package/dist/ai-service/builder-inference-auth.d.ts +0 -11
  220. package/dist/ai-service/builder-inference-auth.d.ts.map +0 -1
  221. package/dist/ai-service/builder-inference-auth.js +0 -48
  222. package/dist/ai-service/builder-inference-auth.js.map +0 -1
  223. package/dist/ai-service/builder-runtime.d.ts +0 -181
  224. package/dist/ai-service/builder-runtime.d.ts.map +0 -1
  225. package/dist/ai-service/builder-runtime.js +0 -337
  226. package/dist/ai-service/builder-runtime.js.map +0 -1
  227. package/dist/ai-service/builder-session-store.d.ts +0 -26
  228. package/dist/ai-service/builder-session-store.d.ts.map +0 -1
  229. package/dist/ai-service/builder-session-store.js +0 -66
  230. package/dist/ai-service/builder-session-store.js.map +0 -1
  231. package/dist/ai-service/builder-tool-callbacks.d.ts +0 -26
  232. package/dist/ai-service/builder-tool-callbacks.d.ts.map +0 -1
  233. package/dist/ai-service/builder-tool-callbacks.js +0 -114
  234. package/dist/ai-service/builder-tool-callbacks.js.map +0 -1
  235. package/dist/ai-service/builder-tools.d.ts +0 -46
  236. package/dist/ai-service/builder-tools.d.ts.map +0 -1
  237. package/dist/ai-service/builder-tools.js +0 -181
  238. package/dist/ai-service/builder-tools.js.map +0 -1
  239. package/dist/ai-service/chat/switch-chat-seed.d.ts +0 -8
  240. package/dist/ai-service/chat/switch-chat-seed.d.ts.map +0 -1
  241. package/dist/ai-service/chat/switch-chat-seed.js +0 -47
  242. package/dist/ai-service/chat/switch-chat-seed.js.map +0 -1
  243. package/dist/ai-service/llm/request-settings.d.ts +0 -6
  244. package/dist/ai-service/llm/request-settings.d.ts.map +0 -1
  245. package/dist/ai-service/llm/request-settings.js +0 -21
  246. package/dist/ai-service/llm/request-settings.js.map +0 -1
  247. package/dist/ai-service/native-callback-order.d.ts +0 -7
  248. package/dist/ai-service/native-callback-order.d.ts.map +0 -1
  249. package/dist/ai-service/native-callback-order.js +0 -39
  250. package/dist/ai-service/native-callback-order.js.map +0 -1
  251. package/dist/ai-service/native-secret-redactor.d.ts +0 -4
  252. package/dist/ai-service/native-secret-redactor.d.ts.map +0 -1
  253. package/dist/ai-service/native-secret-redactor.js +0 -34
  254. package/dist/ai-service/native-secret-redactor.js.map +0 -1
  255. package/dist/ai-service/policy-gate-review.d.ts +0 -42
  256. package/dist/ai-service/policy-gate-review.d.ts.map +0 -1
  257. package/dist/ai-service/policy-gate-review.js +0 -664
  258. package/dist/ai-service/policy-gate-review.js.map +0 -1
  259. package/dist/ai-service/skills/system/native.d.ts +0 -7
  260. package/dist/ai-service/skills/system/native.d.ts.map +0 -1
  261. package/dist/ai-service/skills/system/native.js +0 -25
  262. package/dist/ai-service/skills/system/native.js.map +0 -1
  263. package/dist/ai-service/skills/system/paths.d.ts +0 -2
  264. package/dist/ai-service/skills/system/paths.d.ts.map +0 -1
  265. package/dist/ai-service/skills/system/paths.js +0 -2
  266. package/dist/ai-service/skills/system/paths.js.map +0 -1
  267. package/dist/git-service/credential-scope.d.ts +0 -16
  268. package/dist/git-service/credential-scope.d.ts.map +0 -1
  269. package/dist/git-service/credential-scope.js +0 -91
  270. package/dist/git-service/credential-scope.js.map +0 -1
  271. package/dist/review-runner.d.ts +0 -25
  272. package/dist/review-runner.d.ts.map +0 -1
  273. package/dist/review-runner.js +0 -196
  274. package/dist/review-runner.js.map +0 -1
  275. package/dist/sync-service/draft-mutation.d.ts +0 -11
  276. package/dist/sync-service/draft-mutation.d.ts.map +0 -1
  277. package/dist/sync-service/draft-mutation.js +0 -121
  278. package/dist/sync-service/draft-mutation.js.map +0 -1
  279. package/dist/sync-service/native-draft-session.d.ts +0 -22
  280. package/dist/sync-service/native-draft-session.d.ts.map +0 -1
  281. package/dist/sync-service/native-draft-session.js +0 -229
  282. package/dist/sync-service/native-draft-session.js.map +0 -1
  283. package/dist/sync-service/safe-directory-reader.d.ts +0 -24
  284. package/dist/sync-service/safe-directory-reader.d.ts.map +0 -1
  285. package/dist/sync-service/safe-directory-reader.js +0 -124
  286. package/dist/sync-service/safe-directory-reader.js.map +0 -1
@@ -1,6 +1,5 @@
1
1
  import { posix as posixPath } from "node:path";
2
2
  import { parse } from "@babel/parser";
3
- import * as t from "@babel/types";
4
3
  function isNode(value) {
5
4
  return !!value && typeof value === "object";
6
5
  }
@@ -77,48 +76,164 @@ function unwrapExpression(node) {
77
76
  }
78
77
  return node;
79
78
  }
80
- function specifiersOf(statement) {
81
- return Array.isArray(statement.specifiers)
82
- ? statement.specifiers.filter(isNode)
83
- : [];
84
- }
85
79
  function isTypeOnly(node) {
86
80
  return (node.importKind === "type" ||
87
81
  node.importKind === "typeof" ||
88
82
  node.exportKind === "type");
89
83
  }
90
84
  function valueSpecifiersOf(statement) {
91
- return isTypeOnly(statement)
92
- ? []
93
- : specifiersOf(statement).filter((specifier) => !isTypeOnly(specifier));
85
+ if (isTypeOnly(statement) || !Array.isArray(statement.specifiers)) {
86
+ return [];
87
+ }
88
+ return statement.specifiers.filter((specifier) => isNode(specifier) && !isTypeOnly(specifier));
94
89
  }
95
90
  /**
96
- * The declarators of a top-level `const`, `let`, or `var` statement,
97
- * including an exported one, and none for a `declare` statement, which has
98
- * no runtime value.
91
+ * Walks top-level variable declarations in a program body, calling `visitor`
92
+ * for each individual declarator of a binding `bindings` trusts. Unwraps
93
+ * `export const x = ...` (`ExportNamedDeclaration` whose `.declaration` is
94
+ * a `VariableDeclaration`) to its inner `VariableDeclaration` so exported
95
+ * declarations are visited the same as bare ones. A `declare` statement has
96
+ * no runtime value, so it is never visited.
99
97
  */
100
- function variableDeclaratorsOf(statement) {
101
- const declaration = statement.type === "ExportNamedDeclaration" && isNode(statement.declaration)
102
- ? statement.declaration
103
- : statement;
104
- if (declaration.type !== "VariableDeclaration" ||
105
- declaration.declare === true ||
106
- !Array.isArray(declaration.declarations)) {
107
- return [];
98
+ function visitVariableDeclarations(programBody, bindings, visitor) {
99
+ for (const statement of programBody) {
100
+ if (!isNode(statement)) {
101
+ continue;
102
+ }
103
+ const declarationNode = statement.type === "ExportNamedDeclaration" &&
104
+ isNode(statement.declaration)
105
+ ? statement.declaration
106
+ : statement;
107
+ if (declarationNode.type !== "VariableDeclaration" ||
108
+ declarationNode.declare === true ||
109
+ (bindings === "const-only" && declarationNode.kind !== "const") ||
110
+ !Array.isArray(declarationNode.declarations)) {
111
+ continue;
112
+ }
113
+ for (const declaration of declarationNode.declarations) {
114
+ if (isNode(declaration)) {
115
+ visitor(declaration);
116
+ }
117
+ }
108
118
  }
109
- return declaration.declarations
110
- .filter(isNode)
111
- .map((declarator) => ({ kind: declaration.kind, declarator }));
112
119
  }
113
- function declaredNames(declaration) {
114
- if (!t.isNode(declaration)) {
115
- return [];
120
+ function buildVariableInitializerMap(programBody, bindings) {
121
+ const initializers = new Map();
122
+ visitVariableDeclarations(programBody, bindings, (declaration) => {
123
+ const identifier = declaration.id;
124
+ if (!isNode(identifier) ||
125
+ identifier.type !== "Identifier" ||
126
+ typeof identifier.name !== "string") {
127
+ return;
128
+ }
129
+ initializers.set(identifier.name, declaration.init);
130
+ });
131
+ return initializers;
132
+ }
133
+ function resolveApiConfigObject(expression, variableInitializers) {
134
+ const resolvedExpression = unwrapExpression(expression);
135
+ if (!resolvedExpression) {
136
+ return undefined;
137
+ }
138
+ if (resolvedExpression.type === "Identifier" &&
139
+ typeof resolvedExpression.name === "string") {
140
+ return resolveApiConfigObject(variableInitializers.get(resolvedExpression.name), variableInitializers);
141
+ }
142
+ if (resolvedExpression.type !== "CallExpression" ||
143
+ getCalleeName(resolvedExpression.callee) !== "api" ||
144
+ !Array.isArray(resolvedExpression.arguments)) {
145
+ return undefined;
146
+ }
147
+ const config = unwrapExpression(resolvedExpression.arguments[0]);
148
+ if (!config || config.type !== "ObjectExpression") {
149
+ return undefined;
150
+ }
151
+ return config;
152
+ }
153
+ function findExportedApiConfigObject(programBody, bindings, exportName) {
154
+ const variableInitializers = buildVariableInitializerMap(programBody, bindings);
155
+ for (const statement of programBody) {
156
+ if (!isNode(statement)) {
157
+ continue;
158
+ }
159
+ if (exportName === "default" &&
160
+ statement.type === "ExportDefaultDeclaration") {
161
+ return resolveApiConfigObject(statement.declaration, variableInitializers);
162
+ }
163
+ if (statement.type === "ExportNamedDeclaration" &&
164
+ !isNode(statement.source)) {
165
+ if (exportName !== "default" &&
166
+ isNode(statement.declaration) &&
167
+ statement.declaration.type === "VariableDeclaration" &&
168
+ statement.declaration.declare !== true &&
169
+ Array.isArray(statement.declaration.declarations) &&
170
+ statement.declaration.declarations.some((declaration) => isNode(declaration) &&
171
+ getPropertyName(declaration.id) === exportName)) {
172
+ return resolveApiConfigObject(variableInitializers.get(exportName), variableInitializers);
173
+ }
174
+ for (const specifier of valueSpecifiersOf(statement)) {
175
+ if (specifier.type !== "ExportSpecifier" ||
176
+ getPropertyName(specifier.exported) !== exportName) {
177
+ continue;
178
+ }
179
+ return resolveApiConfigObject(specifier.local, variableInitializers);
180
+ }
181
+ }
116
182
  }
117
- const names = Object.keys(t.getOuterBindingIdentifiers(declaration));
118
- const declaredName = "id" in declaration ? getPropertyName(declaration.id) : undefined;
119
- return declaredName ? [...names, declaredName] : names;
183
+ return undefined;
184
+ }
185
+ function buildVariableReferenceMap(programBody, stringLiterals, bindings) {
186
+ const refs = new Map();
187
+ visitVariableDeclarations(programBody, bindings, (declaration) => {
188
+ const identifier = declaration.id;
189
+ const init = declaration.init;
190
+ if (!isNode(identifier) ||
191
+ identifier.type !== "Identifier" ||
192
+ typeof identifier.name !== "string") {
193
+ return;
194
+ }
195
+ if (!isNode(init) ||
196
+ init.type !== "CallExpression" ||
197
+ !Array.isArray(init.arguments)) {
198
+ return;
199
+ }
200
+ const pluginId = getCalleeName(init.callee);
201
+ const id = resolveStringArgument(init.arguments[0], stringLiterals);
202
+ if (!pluginId || !id) {
203
+ return;
204
+ }
205
+ refs.set(identifier.name, { pluginId, id });
206
+ });
207
+ return refs;
208
+ }
209
+ function buildStringLiteralMap(programBody, bindings) {
210
+ const literals = new Map();
211
+ visitVariableDeclarations(programBody, bindings, (declaration) => {
212
+ const identifier = declaration.id;
213
+ if (!isNode(identifier) ||
214
+ identifier.type !== "Identifier" ||
215
+ typeof identifier.name !== "string") {
216
+ return;
217
+ }
218
+ const value = getLiteralString(declaration.init);
219
+ if (value !== undefined) {
220
+ literals.set(identifier.name, value);
221
+ }
222
+ });
223
+ return literals;
224
+ }
225
+ function resolveStringArgument(node, stringLiterals) {
226
+ const literal = getLiteralString(node);
227
+ if (literal !== undefined) {
228
+ return literal;
229
+ }
230
+ if (isNode(node) &&
231
+ node.type === "Identifier" &&
232
+ typeof node.name === "string") {
233
+ return stringLiterals.get(node.name);
234
+ }
235
+ return undefined;
120
236
  }
121
- const UNRESOLVED_EXPORT = { kind: "unresolved" };
122
237
  /**
123
238
  * The object literals an `api()` config declares its integrations in, and
124
239
  * whether they are all it declares. A spread, a computed key, an
@@ -140,97 +255,220 @@ function readIntegrationsObjects(apiConfig) {
140
255
  members.every((member) => getMemberKeyName(member) !== undefined),
141
256
  };
142
257
  }
143
- function unresolvedKeyOf(member) {
144
- if (member.type !== "ObjectProperty") {
145
- return "(dynamic)";
258
+ function extractFromProgram(programBody, importedRefs, bindings, exportName) {
259
+ const stringLiterals = buildStringLiteralMap(programBody, bindings);
260
+ // Seed with imported id constants (e.g. `import { SHEETS_ID } from
261
+ // "../lib/constants.js"`) so a same-file declaration like
262
+ // `const sheets = restApiIntegration(SHEETS_ID)` can resolve them. Only
263
+ // fill in names the same-file scan didn't already find, so a same-file
264
+ // literal always wins over an imported one of the same name. In practice
265
+ // this `!stringLiterals.has(name)` check is defensive and unreachable for
266
+ // valid input: a same-file `const X` and an `import { X }` of the same
267
+ // name is a duplicate lexical binding, which is a parse/type error in
268
+ // real TS/ESM and can't occur in a file that actually compiles.
269
+ for (const [name, ref] of importedRefs) {
270
+ if (ref.kind === "id" && !stringLiterals.has(name)) {
271
+ stringLiterals.set(name, ref.id);
272
+ }
273
+ }
274
+ const variableRefs = buildVariableReferenceMap(programBody, stringLiterals, bindings);
275
+ const apiConfig = findExportedApiConfigObject(programBody, bindings, exportName);
276
+ if (!apiConfig) {
277
+ return { integrations: [], unresolvedKeys: [] };
278
+ }
279
+ const { objects, isDefinitive } = readIntegrationsObjects(apiConfig);
280
+ const integrations = [];
281
+ const unresolvedKeys = isDefinitive ? [] : ["*"];
282
+ for (const property of objects.flatMap(membersOf)) {
283
+ if (property.type !== "ObjectProperty") {
284
+ // Not a key/value property at all (e.g. a spread element or a method),
285
+ // so there is no key to report as unresolved.
286
+ unresolvedKeys.push("(dynamic)");
287
+ continue;
288
+ }
289
+ const key = getMemberKeyName(property);
290
+ if (!key) {
291
+ unresolvedKeys.push("(unknown)");
292
+ continue;
293
+ }
294
+ if (isNode(property.value) &&
295
+ property.value.type === "CallExpression" &&
296
+ Array.isArray(property.value.arguments)) {
297
+ const pluginId = getCalleeName(property.value.callee);
298
+ const arg = property.value.arguments[0];
299
+ let id = resolveStringArgument(arg, stringLiterals);
300
+ if (!id &&
301
+ isNode(arg) &&
302
+ arg.type === "Identifier" &&
303
+ typeof arg.name === "string") {
304
+ const imported = importedRefs.get(arg.name);
305
+ if (imported?.kind === "id") {
306
+ id = imported.id;
307
+ }
308
+ }
309
+ if (pluginId && id) {
310
+ integrations.push({ key, pluginId, id });
311
+ }
312
+ else {
313
+ unresolvedKeys.push(key);
314
+ }
315
+ continue;
316
+ }
317
+ if (isNode(property.value) &&
318
+ property.value.type === "Identifier" &&
319
+ typeof property.value.name === "string") {
320
+ const resolved = variableRefs.get(property.value.name);
321
+ if (resolved) {
322
+ integrations.push({ key, ...resolved });
323
+ continue;
324
+ }
325
+ const imported = importedRefs.get(property.value.name);
326
+ if (imported?.kind === "declaration") {
327
+ integrations.push({
328
+ key,
329
+ pluginId: imported.pluginId,
330
+ id: imported.id,
331
+ });
332
+ continue;
333
+ }
334
+ unresolvedKeys.push(key);
335
+ continue;
336
+ }
337
+ unresolvedKeys.push(key);
146
338
  }
147
- return getMemberKeyName(member) ?? "(unknown)";
339
+ return { integrations, unresolvedKeys };
148
340
  }
149
341
  /**
150
- * Extracts the integrations a file's default `api()` export declares from the
151
- * file alone. A `let` or `var` reads as its initializer, since callers use
152
- * the result to list every integration an API may touch, such as the
153
- * migration write policy, which must not drop one. A declaration whose ID
154
- * comes from an import is left out without a trace;
155
- * {@link extractApiIntegrations} follows imports and reports the keys it
156
- * cannot resolve.
342
+ * Extract integration declarations from an SDK API source file.
343
+ *
344
+ * Anchors on the exported `api({ ... })` config object and extracts
345
+ * integrations from its `integrations` property.
346
+ *
347
+ * Supports inline declarations:
348
+ * `integrations: { db: postgres("uuid") }`
349
+ *
350
+ * Top-level variable references:
351
+ * `const DB = postgres("uuid"); integrations: { db: DB }`
352
+ *
353
+ * And string variable indirection:
354
+ * `const ID = "uuid"; integrations: { db: postgres(ID) }`
355
+ *
356
+ * Also resolves top-level `export const` declarations and `as const`
357
+ * literals in the same file (e.g. `export const ID = "uuid" as const;`) —
358
+ * a deliberate, additive improvement over the previous bare-declaration-only
359
+ * behavior. This is still single-file scope: only same-file declarations
360
+ * (exported or not) are considered, imports are never followed.
361
+ *
362
+ * Single-file only: does not follow imports, so an integration declared via
363
+ * an imported constant or an imported `integrations` object cannot be
364
+ * resolved here — it is silently dropped (its key is simply absent from the
365
+ * returned array, with no signal that it was seen but unresolved). Callers
366
+ * that need imported declarations resolved, or that need to know about
367
+ * unresolved keys instead of silently losing them, must use
368
+ * {@link extractApiIntegrations} instead.
157
369
  */
158
370
  export function extractIntegrationsFromSource(source) {
159
- let body;
371
+ let ast;
160
372
  try {
161
- body = parseProgramBody(source, "");
373
+ ast = parse(source, {
374
+ sourceType: "module",
375
+ plugins: ["typescript"],
376
+ });
162
377
  }
163
378
  catch {
164
379
  return [];
165
380
  }
166
- const module = new SourceModule("", body);
167
- return new ApiModule(module, new ModuleScope(module, new Map(), "any")).integrationsOf("default").integrations;
381
+ return extractFromProgram(ast.program.body, new Map(), "any", "default")
382
+ .integrations;
168
383
  }
169
- /** The IDs {@link extractIntegrationsFromSource} finds, in declaration order. */
384
+ /**
385
+ * Single-file only: does not follow imports, so an integration declared via
386
+ * an imported constant or an imported `integrations` object cannot be
387
+ * resolved here — it is silently dropped (its `id` is simply absent from the
388
+ * returned array, with no signal that it was seen but unresolved). Callers
389
+ * that need imported declarations resolved, or that need to know about
390
+ * unresolved keys instead of silently losing them, must use
391
+ * {@link extractApiIntegrations} instead.
392
+ */
170
393
  export function extractIntegrationIdsFromSource(source) {
171
394
  return extractIntegrationsFromSource(source).map((integration) => integration.id);
172
395
  }
173
396
  /**
174
- * Extracts the integrations an SDK API module's `api()` export declares,
175
- * following relative imports, and reports the `integrations` keys it could
176
- * not resolve.
397
+ * Async variant of {@link extractIntegrationsFromSource} that also resolves
398
+ * integrations declared via imports from other files, and reports which
399
+ * `integrations` object keys could not be resolved to a complete
400
+ * `{ key, pluginId, id }` triple.
401
+ *
402
+ * Import resolution supports one-hop relative imports (e.g., `../lib/integrations.js`).
403
+ * For each imported name, resolves it in the imported module via:
404
+ * 1. Imported string-literal constants: `export const SHEETS_ID = "sheets-uuid"`
405
+ * (including `as const`/type-assertion wrapping and re-exports via
406
+ * `export { name }` specifiers).
407
+ * 2. Imported integration declarations: `export const jira = restApiIntegration("jira-uuid")`
408
+ * including string-literal indirection within the imported module, and
409
+ * the same `export { name }` specifier form.
177
410
  *
178
- * `exportName` selects the default export when omitted or `"default"`,
179
- * otherwise a named one: `export const <name> = api({...})`,
180
- * `export const <name> = someApi`, or `export { someApi as <name> }`.
411
+ * Non-relative imports (package imports), type-only imports and exports,
412
+ * `declare` bindings, re-exports from another module
413
+ * (`export { name } from "..."`), and imports that more than one candidate
414
+ * file could satisfy are not followed.
181
415
  *
182
- * A declaration resolves when its ID is a string literal, or a binding,
183
- * alias, or integration declaration that leads to one, in the entry file or
184
- * in a module it reaches within {@link MAX_IMPORT_HOPS} imports or
185
- * re-exports. Package imports, type-only imports and exports, `declare`
186
- * bindings, and imports that more than one candidate file could satisfy are
187
- * not followed. `bindings` defaults to `"any"`; a caller that skips an
188
- * approval based on the result passes `"const-only"`.
416
+ * `bindings` defaults to `"any"`, which reads `let` and `var` bindings as
417
+ * their initializer. A caller that skips an approval based on the result
418
+ * passes `"const-only"`, since a `let` or `var` can be reassigned before
419
+ * `api()` reads it.
189
420
  *
190
- * `entryPoint` must be an app-root-relative posix path such as
191
- * `server/apis/get-rows.ts`; imports of an absolute or backslashed one are
192
- * not followed. Candidates above the app root are skipped without being
193
- * read, but containment is enforced by `readSource`, as
194
- * `createContainedSourceReader` does for testApi and
195
- * `resolveContainedRealPath` does for the CLI build manifest.
421
+ * `params.exportName` picks which exported `api()` to read: `"default"` (the
422
+ * default), or the name of an `export const X = api(...)` or `export { X }`.
423
+ *
424
+ * `params.entryPoint` MUST be an app-root-relative posix path (e.g.
425
+ * `server/apis/get-rows.ts`), never an absolute path or one containing a
426
+ * backslash — an entry point that violates this contract skips import
427
+ * resolution entirely (see the guard at the top of
428
+ * `buildImportedIntegrationRefs`). Within that contract, resolved relative
429
+ * import candidates that would escape the app root (e.g. `../../../secrets.ts`)
430
+ * are skipped without reading them, but that `..`-prefix skip is only a
431
+ * best-effort guard against traversal *relative to entryPoint's own
432
+ * directory* — it is not a substitute for real containment enforcement.
433
+ * Authoritative containment against the actual filesystem root lives in the
434
+ * caller's `readSource` implementation (see `resolveContainedPath` in
435
+ * `collect-sdk-apis.mts`), which re-resolves every candidate against the app
436
+ * root before touching disk.
196
437
  *
197
438
  * `unresolvedKeys` entries are one of:
198
- * - an `integrations` key whose declaration could not be resolved
199
- * - `"(unknown)"` for a declaration whose key is not static
200
- * - `"(dynamic)"` for a spread or method inside `integrations`
201
- * - `"*"` when the export may declare integrations other than the ones read:
202
- * the entry file has no local export by that name, which includes one it
203
- * re-exports from another module, its value is not an `api({...})` call,
204
- * its config has a spread, a computed key, an `integrations` accessor or
205
- * method, a second or non-literal `integrations` property, or the entry
206
- * file does not parse. `integrations` then lists only the declarations
207
- * that could be read.
439
+ * - a specific `integrations` object key that could not be resolved
440
+ * - `"(unknown)"` for an `ObjectProperty` whose key itself couldn't be read
441
+ * (e.g. a computed key)
442
+ * - `"(dynamic)"` for a non-`ObjectProperty` member of the integrations
443
+ * object (spread elements, methods)
444
+ * - `"*"` as a sentinel meaning the config may declare integrations other
445
+ * than the ones read: `api({ integrations })` shorthand,
446
+ * `api({ integrations: sharedObject })` referencing a non-literal value, a
447
+ * spread or computed key in the config, an `integrations` accessor or
448
+ * method, a second `integrations` property, or the entry file itself
449
+ * failing to parse. `integrations` then lists only the declarations that
450
+ * could be read.
208
451
  */
209
452
  export async function extractApiIntegrations(params) {
210
- let body;
453
+ let ast;
211
454
  try {
212
- body = parseProgramBody(params.source, params.entryPoint);
455
+ ast = parse(params.source, {
456
+ sourceType: "module",
457
+ plugins: ["typescript"],
458
+ });
213
459
  }
214
460
  catch {
461
+ // The entry file itself failed to parse (e.g. parser-config drift: a
462
+ // real build compiles syntax our @babel/parser config rejects, such as
463
+ // decorators or import attributes). Report the "*" sentinel instead of
464
+ // silently returning an empty result — this is maximal uncertainty
465
+ // about the whole integrations surface, exactly what "*" means below.
215
466
  return { integrations: [], unresolvedKeys: ["*"] };
216
467
  }
217
- const exportName = params.exportName ?? "default";
218
- const entry = new SourceModule(params.entryPoint, body);
219
- const scope = await new ImportedIntegrationResolver(params.readSource, params.bindings ?? "any").entryScope(entry, (probe) => new ApiModule(entry, probe).integrationsOf(exportName));
220
- return new ApiModule(entry, scope).integrationsOf(exportName);
221
- }
222
- /**
223
- * Parses a module as TypeScript, and as JSX too when its path is a `.tsx` or
224
- * `.jsx` file. A `.ts` file cannot also be read as JSX, since `<T>value` is a
225
- * type assertion there.
226
- */
227
- function parseProgramBody(source, path) {
228
- const plugins = JSX_EXTENSIONS.includes(posixPath.extname(path))
229
- ? ["typescript", "jsx"]
230
- : ["typescript"];
231
- return parse(source, { sourceType: "module", plugins }).program.body;
468
+ const bindings = params.bindings ?? "any";
469
+ const importedRefs = await buildImportedIntegrationRefs(ast.program.body, params.entryPoint, params.readSource, bindings);
470
+ return extractFromProgram(ast.program.body, importedRefs, bindings, params.exportName ?? "default");
232
471
  }
233
- const JSX_EXTENSIONS = [".tsx", ".jsx"];
234
472
  const TS_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts"];
235
473
  const SCRIPT_EXTENSIONS = [...TS_EXTENSIONS, ".js", ".jsx", ".mjs", ".cjs"];
236
474
  const JS_TO_TS_EXTENSIONS = {
@@ -257,448 +495,185 @@ export function resolveRelativeImportPath(fromPath, importPath) {
257
495
  }
258
496
  return SCRIPT_EXTENSIONS.map((ext) => resolved + ext);
259
497
  }
260
- /**
261
- * One parsed module, addressed by its app-root-relative posix path, and the
262
- * statements that matter for resolving integrations. Type-only and `declare`
263
- * statements have no runtime value, so only `explicitExportNames` sees them.
264
- */
265
- class SourceModule {
266
- path;
267
- body;
268
- constructor(path, body) {
269
- this.path = path;
270
- this.body = body;
271
- }
272
- /**
273
- * The app-root-relative paths an import or re-export source of this module
274
- * may name, or none when it must not be followed: package imports, and any
275
- * specifier containing a backslash, which `posixPath.join` would treat as
276
- * a filename character so the `..`-prefix skip could not catch a traversal
277
- * spelled with it. Candidates above the app root are dropped unread.
278
- */
279
- candidatePathsFor(sourceNode) {
280
- const specifier = isNode(sourceNode) ? sourceNode.value : undefined;
281
- if (typeof specifier !== "string" ||
282
- !specifier.startsWith(".") ||
283
- specifier.includes("\\")) {
284
- return [];
285
- }
286
- return resolveRelativeImportPath(this.path, specifier).filter((candidate) => !candidate.startsWith(".."));
287
- }
288
- variableDeclarators() {
289
- return this.statements().flatMap(variableDeclaratorsOf);
290
- }
291
- /** `import { a, b as c } from "..."` statements. */
292
- namedImports() {
293
- return this.references("ImportDeclaration", "ImportSpecifier");
294
- }
295
- /**
296
- * The source and source-side name of an `export { a as name } from "..."`
297
- * that exports `name`.
298
- */
299
- namedReExportOf(name) {
300
- for (const { source, specifiers } of this.references("ExportNamedDeclaration", "ExportSpecifier")) {
301
- for (const specifier of specifiers) {
302
- const localName = getPropertyName(specifier.local);
303
- if (localName && getPropertyName(specifier.exported) === name) {
304
- return { source, localName };
305
- }
306
- }
307
- }
308
- return undefined;
498
+ /** A file whose read throws counts as existing, since the bundler may load it. */
499
+ async function readCandidate(path, readSource) {
500
+ let source;
501
+ try {
502
+ source = await readSource(path);
309
503
  }
310
- /** The sources of `export * from "..."` statements. */
311
- starReExportSources() {
312
- return this.statementsOfType("ExportAllDeclaration")
313
- .filter((statement) => !isTypeOnly(statement))
314
- .map((statement) => statement.source);
315
- }
316
- /**
317
- * The expression behind each value the module exports from its own scope:
318
- * `export default <expr>`, the binding of `export const <name>`, and the
319
- * local of `export { <local> as <name> }`.
320
- */
321
- localExports() {
322
- const exports = new Map();
323
- for (const statement of this.statementsOfType("ExportDefaultDeclaration")) {
324
- if (isNode(statement.declaration)) {
325
- exports.set("default", statement.declaration);
326
- }
327
- }
328
- for (const statement of this.statementsOfType("ExportNamedDeclaration")) {
329
- if (isNode(statement.source)) {
330
- continue;
331
- }
332
- for (const { declarator } of variableDeclaratorsOf(statement)) {
333
- const name = getPropertyName(declarator.id);
334
- if (name && isNode(declarator.id)) {
335
- exports.set(name, declarator.id);
336
- }
337
- }
338
- for (const specifier of valueSpecifiersOf(statement)) {
339
- const exportedName = getPropertyName(specifier.exported);
340
- if (exportedName && isNode(specifier.local)) {
341
- exports.set(exportedName, specifier.local);
342
- }
343
- }
344
- }
345
- return exports;
346
- }
347
- /**
348
- * Every name the module exports other than through `export *`, which ESM
349
- * shadows with them and which never provides `default`. Type-only and
350
- * `declare` exports count: TypeScript resolves the name to them while the
351
- * runtime would take a star source's value, so the name stays unresolved.
352
- */
353
- explicitExportNames() {
354
- const names = new Set(["default"]);
355
- for (const statement of this.statementsOfType("TSImportEqualsDeclaration")) {
356
- const name = statement.isExport
357
- ? getPropertyName(statement.id)
358
- : undefined;
359
- if (name) {
360
- names.add(name);
361
- }
362
- }
363
- for (const statement of this.statementsOfType("ExportNamedDeclaration")) {
364
- for (const name of declaredNames(statement.declaration)) {
365
- names.add(name);
366
- }
367
- for (const specifier of specifiersOf(statement)) {
368
- const exportedName = getPropertyName(specifier.exported);
369
- if (exportedName) {
370
- names.add(exportedName);
371
- }
372
- }
373
- }
374
- return names;
504
+ catch {
505
+ return { exists: true };
375
506
  }
376
- references(statementType, specifierType) {
377
- return this.statementsOfType(statementType)
378
- .filter((statement) => isNode(statement.source))
379
- .map((statement) => ({
380
- source: statement.source,
381
- specifiers: valueSpecifiersOf(statement).filter((specifier) => specifier.type === specifierType),
382
- }))
383
- .filter(({ specifiers }) => specifiers.length > 0);
507
+ if (source === undefined) {
508
+ return { exists: false };
384
509
  }
385
- statementsOfType(type) {
386
- return this.statements().filter((statement) => statement.type === type);
510
+ try {
511
+ return {
512
+ exists: true,
513
+ body: parse(source, {
514
+ sourceType: "module",
515
+ plugins: ["typescript"],
516
+ }).program.body,
517
+ };
387
518
  }
388
- statements() {
389
- return this.body.filter(isNode);
519
+ catch {
520
+ return { exists: true };
390
521
  }
391
522
  }
392
523
  /**
393
- * What the top-level bindings of one module and the names it imports refer
394
- * to: string IDs, integration declarations, aliases of either, and `api()`
395
- * configs.
524
+ * The program body of the file an import loads when exactly one of its
525
+ * candidate files exists. With more than one, which the bundler loads depends
526
+ * on its resolution order, so the import is left unresolved.
396
527
  */
397
- class ModuleScope {
398
- importedRefs;
399
- initializers = new Map();
400
- constructor(module, importedRefs, bindings) {
401
- this.importedRefs = importedRefs;
402
- for (const { kind, declarator } of module.variableDeclarators()) {
403
- const name = getPropertyName(declarator.id);
404
- if (name && (bindings === "any" || kind === "const")) {
405
- this.initializers.set(name, declarator.init);
406
- }
407
- }
408
- }
409
- resolveExpression(node, followedNames = new Set()) {
410
- const literal = getLiteralString(node);
411
- if (literal !== undefined) {
412
- return { kind: "id", id: literal };
413
- }
414
- const expression = unwrapExpression(node);
415
- if (expression?.type === "Identifier" &&
416
- typeof expression.name === "string") {
417
- return this.resolveName(expression.name, followedNames);
528
+ async function readUnambiguous(candidatePaths, readSource, cache) {
529
+ const existing = [];
530
+ for (const candidate of candidatePaths) {
531
+ let file = cache.get(candidate);
532
+ if (!file) {
533
+ file = await readCandidate(candidate, readSource);
534
+ cache.set(candidate, file);
418
535
  }
419
- if (expression?.type === "CallExpression" &&
420
- Array.isArray(expression.arguments)) {
421
- const pluginId = getCalleeName(expression.callee);
422
- const argument = this.resolveExpression(expression.arguments[0], followedNames);
423
- return pluginId && argument?.kind === "id"
424
- ? { kind: "declaration", pluginId, id: argument.id }
425
- : undefined;
536
+ if (file.exists) {
537
+ existing.push(file);
426
538
  }
427
- return undefined;
428
- }
429
- resolveDeclaration(node) {
430
- const ref = this.resolveExpression(node);
431
- return ref?.kind === "declaration"
432
- ? { pluginId: ref.pluginId, id: ref.id }
433
- : undefined;
434
- }
435
- /** The config object of the `api({...})` call an expression evaluates to. */
436
- resolveApiConfig(node, followedNames = new Set()) {
437
- const expression = unwrapExpression(node);
438
- if (expression?.type === "Identifier" &&
439
- typeof expression.name === "string") {
440
- const name = expression.name;
441
- if (followedNames.has(name) || !this.initializers.has(name)) {
442
- return undefined;
443
- }
444
- followedNames.add(name);
445
- return this.resolveApiConfig(this.initializers.get(name), followedNames);
446
- }
447
- if (expression?.type !== "CallExpression" ||
448
- getCalleeName(expression.callee) !== "api" ||
449
- !Array.isArray(expression.arguments)) {
450
- return undefined;
451
- }
452
- const config = unwrapExpression(expression.arguments[0]);
453
- return config?.type === "ObjectExpression" ? config : undefined;
454
- }
455
- resolveName(name, followedNames) {
456
- if (!this.initializers.has(name)) {
457
- return this.importedRefs.get(name);
458
- }
459
- if (followedNames.has(name)) {
460
- return undefined;
461
- }
462
- followedNames.add(name);
463
- return this.resolveExpression(this.initializers.get(name), followedNames);
464
539
  }
540
+ return existing.length === 1 ? existing[0]?.body : undefined;
465
541
  }
466
- /** An API module's `api()` export and the integrations its config declares. */
467
- class ApiModule {
468
- module;
469
- scope;
470
- constructor(module, scope) {
471
- this.module = module;
472
- this.scope = scope;
473
- }
474
- integrationsOf(exportName) {
475
- const exported = this.module.localExports().get(exportName);
476
- const apiConfig = exported && this.scope.resolveApiConfig(exported);
477
- if (!apiConfig) {
478
- return { integrations: [], unresolvedKeys: ["*"] };
542
+ function buildExportedIntegrationRefMap(programBody, bindings) {
543
+ const refs = new Map();
544
+ const stringLiterals = buildStringLiteralMap(programBody, bindings);
545
+ // Resolves specifier-based exports (`const jira = ...; export { jira };`)
546
+ // against the module's bare top-level variable declarations.
547
+ const variableRefs = buildVariableReferenceMap(programBody, stringLiterals, bindings);
548
+ // Resolve `export const x = ...` declarations directly. Filtering to only
549
+ // `ExportNamedDeclaration` statements before delegating to the shared
550
+ // walker means bare (non-exported) top-level consts are correctly excluded
551
+ // here, even though they're visible for same-file indirection above.
552
+ const exportedDeclarationStatements = programBody.filter((statement) => isNode(statement) && statement.type === "ExportNamedDeclaration");
553
+ visitVariableDeclarations(exportedDeclarationStatements, bindings, (declaration) => {
554
+ const identifier = declaration.id;
555
+ if (!isNode(identifier) ||
556
+ identifier.type !== "Identifier" ||
557
+ typeof identifier.name !== "string") {
558
+ return;
559
+ }
560
+ const literal = getLiteralString(declaration.init);
561
+ if (literal !== undefined) {
562
+ refs.set(identifier.name, { kind: "id", id: literal });
563
+ return;
564
+ }
565
+ const init = declaration.init;
566
+ if (isNode(init) &&
567
+ init.type === "CallExpression" &&
568
+ Array.isArray(init.arguments)) {
569
+ const pluginId = getCalleeName(init.callee);
570
+ const id = resolveStringArgument(init.arguments[0], stringLiterals);
571
+ if (pluginId && id) {
572
+ refs.set(identifier.name, { kind: "declaration", pluginId, id });
573
+ }
479
574
  }
480
- return this.readDeclarations(apiConfig);
481
- }
482
- readDeclarations(apiConfig) {
483
- const { objects, isDefinitive } = readIntegrationsObjects(apiConfig);
484
- const integrations = [];
485
- const unresolvedKeys = isDefinitive ? [] : ["*"];
486
- for (const member of objects.flatMap(membersOf)) {
487
- const key = member.type === "ObjectProperty" ? getMemberKeyName(member) : undefined;
488
- const declaration = key === undefined
489
- ? undefined
490
- : this.scope.resolveDeclaration(member.value);
491
- if (key !== undefined && declaration) {
492
- integrations.push({ key, ...declaration });
575
+ });
576
+ // A specifier of `export { name } from "..."` names a binding of that
577
+ // other module, which is not followed, never a same-named local one.
578
+ for (const statement of programBody) {
579
+ if (!isNode(statement) ||
580
+ statement.type !== "ExportNamedDeclaration" ||
581
+ isNode(statement.source)) {
582
+ continue;
583
+ }
584
+ for (const specifier of valueSpecifiersOf(statement)) {
585
+ if (specifier.type !== "ExportSpecifier") {
586
+ continue;
493
587
  }
494
- else {
495
- unresolvedKeys.push(unresolvedKeyOf(member));
588
+ const localName = getPropertyName(specifier.local);
589
+ const exportedName = getPropertyName(specifier.exported);
590
+ if (!localName || !exportedName) {
591
+ continue;
592
+ }
593
+ const literal = stringLiterals.get(localName);
594
+ if (literal !== undefined) {
595
+ refs.set(exportedName, { kind: "id", id: literal });
596
+ continue;
597
+ }
598
+ const varRef = variableRefs.get(localName);
599
+ if (varRef) {
600
+ refs.set(exportedName, {
601
+ kind: "declaration",
602
+ pluginId: varRef.pluginId,
603
+ id: varRef.id,
604
+ });
496
605
  }
497
606
  }
498
- return { integrations, unresolvedKeys };
499
607
  }
608
+ return refs;
500
609
  }
501
- function isSameRef(left, right) {
502
- const pluginIdOf = (ref) => ref.kind === "declaration" ? ref.pluginId : undefined;
503
- return (left.kind === right.kind &&
504
- left.id === right.id &&
505
- pluginIdOf(left) === pluginIdOf(right));
506
- }
507
- /**
508
- * The most modules an imported name is followed through, counting the module
509
- * the entry point imports it from as the first.
510
- */
511
- const MAX_IMPORT_HOPS = 5;
512
- /**
513
- * The most candidate files one call reads, so an app whose modules import
514
- * widely cannot make one lookup read it whole. Every candidate of an import
515
- * counts, whether or not it exists. An import that needs more is left
516
- * unresolved.
517
- */
518
- export const MAX_SOURCE_READS = 256;
519
- /**
520
- * Resolves the names an API entry point imports, following relative imports
521
- * and re-exports through at most {@link MAX_IMPORT_HOPS} modules. It follows
522
- * only the names a lookup reaches: one export of a module at a time, and of
523
- * that export only the imports its value refers to. One instance serves one
524
- * entry point: it reads and parses each file at most once, and cuts an
525
- * import cycle where it closes, leaving the names that depend on the cycle
526
- * unresolved.
527
- */
528
- class ImportedIntegrationResolver {
529
- readSource;
530
- bindings;
531
- files = new Map();
532
- exportRefs = new Map();
533
- exportsInProgress = new Set();
534
- sourceReadsLeft = MAX_SOURCE_READS;
535
- constructor(readSource, bindings) {
536
- this.readSource = readSource;
537
- this.bindings = bindings;
538
- }
539
- /** A scope of the entry point with the imports `use` looks up resolved. */
540
- async entryScope(entry, use) {
541
- // The `..`-prefix skip only guards against traversal relative to the
542
- // entry point's own directory, so an absolute or backslashed entry point
543
- // could still resolve candidates outside the app root.
544
- if (entry.path.startsWith("/") || entry.path.includes("\\")) {
545
- return new ModuleScope(entry, new Map(), this.bindings);
546
- }
547
- this.files.set(entry.path, { exists: true, module: entry });
548
- return this.scopeFor(entry, 1, use);
549
- }
550
- /**
551
- * Run `use` once with no imports to find which imported names it reads,
552
- * then resolve only those. An imported name resolves to an ID or a
553
- * declaration, never to another name, so the second run reads the same
554
- * names.
555
- */
556
- async scopeFor(module, hop, use) {
557
- const lookedUp = new Set();
558
- use(new ModuleScope(module, {
559
- get: (name) => {
560
- lookedUp.add(name);
561
- return undefined;
562
- },
563
- }, this.bindings));
564
- return new ModuleScope(module, await this.resolveImports(module, lookedUp, hop), this.bindings);
565
- }
566
- async resolveImports(importer, localNames, hop) {
567
- const refs = new Map();
568
- for (const { source, specifiers } of importer.namedImports()) {
569
- for (const specifier of specifiers) {
570
- const importedName = getPropertyName(specifier.imported);
571
- const localName = getPropertyName(specifier.local);
572
- if (!importedName || !localName || !localNames.has(localName)) {
573
- continue;
574
- }
575
- const ref = await this.exportOfImport(importer, source, importedName, hop);
576
- if (ref && ref.kind !== "unresolved") {
577
- refs.set(localName, ref);
578
- }
579
- }
580
- }
610
+ async function buildImportedIntegrationRefs(programBody, entryPoint, readSource, bindings) {
611
+ const refs = new Map();
612
+ // entryPoint is contractually an app-root-relative posix path (see the
613
+ // JSDoc on extractApiIntegrations). An absolute path or one containing a
614
+ // backslash is out-of-contract input: resolveRelativeImportPath's
615
+ // `..`-prefix skip only guards against traversal relative to entryPoint's
616
+ // own directory, so a malformed entryPoint (e.g. an absolute path) could
617
+ // still let a resolved candidate land outside the app root even though it
618
+ // doesn't start with "..". Refuse to resolve any imports at all for such
619
+ // input rather than rely on that guard holding — callers that violate the
620
+ // contract get unresolved keys instead of a potential traversal.
621
+ if (entryPoint.startsWith("/") || entryPoint.includes("\\")) {
581
622
  return refs;
582
623
  }
583
- async exportOfImport(importer, sourceNode, name, hop) {
584
- if (hop > MAX_IMPORT_HOPS) {
585
- return UNRESOLVED_EXPORT;
586
- }
587
- const imported = await this.readUnambiguous(importer.candidatePathsFor(sourceNode));
588
- return imported ? this.exportOf(imported, name, hop) : UNRESOLVED_EXPORT;
589
- }
590
- async exportOf(module, name, hop) {
591
- const exportKey = JSON.stringify([module.path, name]);
592
- if (this.exportsInProgress.has(exportKey)) {
593
- return UNRESOLVED_EXPORT;
594
- }
595
- const cacheKey = JSON.stringify([hop, module.path, name]);
596
- if (this.exportRefs.has(cacheKey)) {
597
- return this.exportRefs.get(cacheKey);
598
- }
599
- this.exportsInProgress.add(exportKey);
600
- try {
601
- const ref = await this.resolveExport(module, name, hop);
602
- if (ref?.kind !== "unresolved") {
603
- this.exportRefs.set(cacheKey, ref);
604
- }
605
- return ref;
606
- }
607
- finally {
608
- this.exportsInProgress.delete(exportKey);
609
- }
610
- }
611
- /**
612
- * What `module` exports as `name`. A name the module exports explicitly,
613
- * even as a type, a `declare`, or a namespace, shadows `export *`.
614
- */
615
- async resolveExport(module, name, hop) {
616
- const local = module.localExports().get(name);
617
- if (local) {
618
- const scope = await this.scopeFor(module, hop + 1, (probe) => probe.resolveExpression(local));
619
- return scope.resolveExpression(local) ?? UNRESOLVED_EXPORT;
620
- }
621
- const reExport = module.namedReExportOf(name);
622
- if (reExport) {
623
- return ((await this.exportOfImport(module, reExport.source, reExport.localName, hop + 1)) ?? UNRESOLVED_EXPORT);
624
- }
625
- return module.explicitExportNames().has(name)
626
- ? UNRESOLVED_EXPORT
627
- : this.starExportOf(module, name, hop);
628
- }
629
- /**
630
- * What the `export *` sources of `module` provide as `name`, when they
631
- * agree. A name two sources disagree on is ambiguous in ESM.
632
- */
633
- async starExportOf(module, name, hop) {
634
- const refs = [];
635
- for (const sourceNode of module.starReExportSources()) {
636
- const ref = await this.exportOfImport(module, sourceNode, name, hop + 1);
637
- if (ref?.kind === "unresolved") {
638
- return UNRESOLVED_EXPORT;
639
- }
640
- if (ref) {
641
- refs.push(ref);
624
+ // Deliberately scoped to this call (one per entry point), not shared/module
625
+ // -level: each call to extractApiIntegrations gets its own cache, so
626
+ // repeated imports of the same relative path within a single entry point's
627
+ // import graph are only read and parsed once, without leaking parsed
628
+ // bodies across unrelated entry points or app roots.
629
+ const candidateFiles = new Map();
630
+ for (const statement of programBody) {
631
+ if (!isNode(statement) || statement.type !== "ImportDeclaration") {
632
+ continue;
633
+ }
634
+ const importSource = statement.source;
635
+ const importPath = isNode(importSource) ? importSource.value : undefined;
636
+ const specifiers = valueSpecifiersOf(statement);
637
+ if (typeof importPath !== "string" ||
638
+ !importPath.startsWith(".") ||
639
+ specifiers.length === 0) {
640
+ continue;
641
+ }
642
+ // Real ESM/TS import specifiers always use forward slashes, and no
643
+ // bundler resolves a backslash as a path separator either — a backslash
644
+ // here only ever comes from hostile or broken input (e.g.
645
+ // `..\\..\\..\\secret.js`). `posixPath.join` treats `\` as an ordinary
646
+ // filename character rather than a separator, so the `..`-prefix guard
647
+ // below cannot catch a traversal spelled with backslashes. Treat the
648
+ // specifier as unresolvable, the same as a bare package import, and
649
+ // never attempt to read it.
650
+ if (importPath.includes("\\")) {
651
+ continue;
652
+ }
653
+ // Skip candidates that resolve outside the app root (e.g.
654
+ // `../../../secrets.ts` escaping above the entry point's directory) —
655
+ // never read files outside the app being built.
656
+ const candidatePaths = resolveRelativeImportPath(entryPoint, importPath).filter((candidate) => !candidate.startsWith(".."));
657
+ if (candidatePaths.length === 0) {
658
+ continue;
659
+ }
660
+ const importedBody = await readUnambiguous(candidatePaths, readSource, candidateFiles);
661
+ if (!importedBody) {
662
+ continue;
663
+ }
664
+ const exportedRefs = buildExportedIntegrationRefMap(importedBody, bindings);
665
+ for (const specifier of specifiers) {
666
+ if (specifier.type !== "ImportSpecifier") {
667
+ continue;
642
668
  }
643
- }
644
- const [first] = refs;
645
- if (first && refs.some((ref) => !isSameRef(ref, first))) {
646
- return UNRESOLVED_EXPORT;
647
- }
648
- return first;
649
- }
650
- /**
651
- * The module a specifier loads when exactly one of its candidate files
652
- * exists. With more than one, which the bundler loads depends on its
653
- * resolution order, so the import is left unresolved.
654
- */
655
- async readUnambiguous(candidatePaths) {
656
- const existing = [];
657
- for (const path of candidatePaths) {
658
- const file = await this.read(path);
659
- if (file.exists) {
660
- existing.push(file);
669
+ const importedName = getPropertyName(specifier.imported);
670
+ const localName = getPropertyName(specifier.local);
671
+ const ref = importedName ? exportedRefs.get(importedName) : undefined;
672
+ if (localName && ref) {
673
+ refs.set(localName, ref);
661
674
  }
662
675
  }
663
- return existing.length === 1 ? existing[0]?.module : undefined;
664
- }
665
- async read(path) {
666
- const cached = this.files.get(path);
667
- if (cached) {
668
- return cached;
669
- }
670
- const file = await this.readAndParse(path);
671
- this.files.set(path, file);
672
- return file;
673
- }
674
- /**
675
- * A file whose read throws counts as existing, since the bundler may load
676
- * it, and so does one past {@link MAX_SOURCE_READS}, which is not read.
677
- */
678
- async readAndParse(path) {
679
- if (this.sourceReadsLeft === 0) {
680
- return { exists: true };
681
- }
682
- this.sourceReadsLeft -= 1;
683
- let source;
684
- try {
685
- source = await this.readSource(path);
686
- }
687
- catch {
688
- return { exists: true };
689
- }
690
- if (source === undefined) {
691
- return { exists: false };
692
- }
693
- try {
694
- return {
695
- exists: true,
696
- module: new SourceModule(path, parseProgramBody(source, path)),
697
- };
698
- }
699
- catch {
700
- return { exists: true };
701
- }
702
676
  }
677
+ return refs;
703
678
  }
704
679
  //# sourceMappingURL=extract-api-integrations.js.map