@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.
- package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js +1 -11
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/get-api-docs.d.ts +3 -3
- package/dist/ai-service/agent/tools/apis/test-api.d.ts +13 -78
- package/dist/ai-service/agent/tools/apis/test-api.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/apis/test-api.js +50 -52
- package/dist/ai-service/agent/tools/apis/test-api.js.map +1 -1
- package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts +3 -11
- package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-capture-screenshot.js +8 -13
- package/dist/ai-service/agent/tools/build-capture-screenshot.js.map +1 -1
- package/dist/ai-service/agent/tools/build-navigate-preview.d.ts +0 -6
- package/dist/ai-service/agent/tools/build-navigate-preview.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-navigate-preview.js +4 -5
- package/dist/ai-service/agent/tools/build-navigate-preview.js.map +1 -1
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.d.ts +1 -4
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.js +3 -6
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.js.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts +4 -11
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.js +3 -21
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.js.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tools.js +5 -32
- package/dist/ai-service/agent/tools/databases/dev-database-tools.js.map +1 -1
- package/dist/ai-service/agent/tools/get-logs.d.ts +2 -5
- package/dist/ai-service/agent/tools/get-logs.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/get-logs.js +3 -6
- package/dist/ai-service/agent/tools/get-logs.js.map +1 -1
- package/dist/ai-service/agent/tools/get-runtime-errors.d.ts +0 -2
- package/dist/ai-service/agent/tools/get-runtime-errors.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/get-runtime-errors.js +2 -3
- package/dist/ai-service/agent/tools/get-runtime-errors.js.map +1 -1
- package/dist/ai-service/agent/tools/get-security-findings.js +1 -1
- package/dist/ai-service/agent/tools/integrations/execute-request.d.ts +5 -5
- package/dist/ai-service/agent/tools/integrations/metadata.d.ts +1 -1
- package/dist/ai-service/agent/tools/integrations/metadata.js.map +1 -1
- package/dist/ai-service/agent/tools/report-security-findings.d.ts +3 -3
- package/dist/ai-service/agent/tools.d.ts +5 -1
- package/dist/ai-service/agent/tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.js +42 -7
- package/dist/ai-service/agent/tools.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts +3 -4
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js +2 -4
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep.js +5 -27
- package/dist/ai-service/agent/tools2/tools/grep.js.map +1 -1
- package/dist/ai-service/app-interface/file-system-interface.d.ts +1 -1
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.d.ts +1 -2
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.d.ts.map +1 -1
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.js +2 -9
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.js.map +1 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.d.ts +0 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.d.ts.map +1 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.js +1 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.js.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.d.ts +0 -1
- package/dist/ai-service/app-interface/npm-registry.d.ts.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.js +6 -45
- package/dist/ai-service/app-interface/npm-registry.js.map +1 -1
- package/dist/ai-service/app-interface/shell.d.ts +1 -4
- package/dist/ai-service/app-interface/shell.d.ts.map +1 -1
- package/dist/ai-service/app-interface/shell.js +8 -26
- package/dist/ai-service/app-interface/shell.js.map +1 -1
- package/dist/ai-service/chat/chat-session-store.d.ts +1 -10
- package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
- package/dist/ai-service/chat/chat-session-store.js +1 -30
- package/dist/ai-service/chat/chat-session-store.js.map +1 -1
- package/dist/ai-service/dev-database-client.d.ts +0 -1
- package/dist/ai-service/dev-database-client.d.ts.map +1 -1
- package/dist/ai-service/dev-database-client.js +0 -1
- package/dist/ai-service/dev-database-client.js.map +1 -1
- package/dist/ai-service/dev-database-file-sync.d.ts +1 -3
- package/dist/ai-service/dev-database-file-sync.d.ts.map +1 -1
- package/dist/ai-service/dev-database-file-sync.js.map +1 -1
- package/dist/ai-service/features.d.ts +8 -15
- package/dist/ai-service/features.d.ts.map +1 -1
- package/dist/ai-service/features.js +8 -15
- package/dist/ai-service/features.js.map +1 -1
- package/dist/ai-service/index.d.ts +19 -34
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +738 -474
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/llm/context-v2/context-metrics.js +2 -2
- package/dist/ai-service/llm/context-v2/manager.d.ts +1 -3
- package/dist/ai-service/llm/context-v2/manager.d.ts.map +1 -1
- package/dist/ai-service/llm/context-v2/manager.js +0 -5
- package/dist/ai-service/llm/context-v2/manager.js.map +1 -1
- package/dist/ai-service/llm/context-v2/types.d.ts +1 -1
- package/dist/ai-service/llm/context-v2/types.d.ts.map +1 -1
- package/dist/ai-service/llm/context-v2/types.js.map +1 -1
- package/dist/ai-service/llm/stream/config.d.ts +1 -1
- package/dist/ai-service/llm/stream/config.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/config.js.map +1 -1
- package/dist/ai-service/llm/stream/errors.d.ts +1 -4
- package/dist/ai-service/llm/stream/errors.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/errors.js +2 -8
- package/dist/ai-service/llm/stream/errors.js.map +1 -1
- package/dist/ai-service/llm/stream/orchestrator.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/orchestrator.js +6 -3
- package/dist/ai-service/llm/stream/orchestrator.js.map +1 -1
- package/dist/ai-service/llmobs/tracer.d.ts.map +1 -1
- package/dist/ai-service/llmobs/tracer.js +21 -4
- package/dist/ai-service/llmobs/tracer.js.map +1 -1
- package/dist/ai-service/managed-native-db-availability.d.ts +1 -1
- package/dist/ai-service/managed-native-db-availability.d.ts.map +1 -1
- package/dist/ai-service/managed-native-db-availability.js +2 -4
- package/dist/ai-service/managed-native-db-availability.js.map +1 -1
- package/dist/ai-service/policy-gate-remediation-usage.d.ts +1 -2
- package/dist/ai-service/policy-gate-remediation-usage.d.ts.map +1 -1
- package/dist/ai-service/policy-gate-remediation-usage.js +1 -2
- package/dist/ai-service/policy-gate-remediation-usage.js.map +1 -1
- package/dist/ai-service/skills/system/materialized.d.ts +1 -3
- package/dist/ai-service/skills/system/materialized.d.ts.map +1 -1
- package/dist/ai-service/skills/system/materialized.js +3 -3
- package/dist/ai-service/skills/system/materialized.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +4 -6
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.d.ts +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.js +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/user-response-message.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/user-response-message.js +2 -4
- package/dist/ai-service/state-machine/helpers/user-response-message.js.map +1 -1
- package/dist/ai-service/types.d.ts +0 -3
- package/dist/ai-service/types.d.ts.map +1 -1
- package/dist/ai-service/types.js.map +1 -1
- package/dist/extract-api-integrations.d.ts +91 -52
- package/dist/extract-api-integrations.d.ts.map +1 -1
- package/dist/extract-api-integrations.js +487 -512
- package/dist/extract-api-integrations.js.map +1 -1
- package/dist/file-sync-vite-plugin.d.ts.map +1 -1
- package/dist/file-sync-vite-plugin.js +5 -53
- package/dist/file-sync-vite-plugin.js.map +1 -1
- package/dist/file-system-helpers.d.ts.map +1 -1
- package/dist/file-system-helpers.js +2 -3
- package/dist/file-system-helpers.js.map +1 -1
- package/dist/git-service/index.d.ts +0 -1
- package/dist/git-service/index.d.ts.map +1 -1
- package/dist/git-service/index.js +38 -6
- package/dist/git-service/index.js.map +1 -1
- package/dist/git-service/managed-excludes.d.ts.map +1 -1
- package/dist/git-service/managed-excludes.js +0 -2
- package/dist/git-service/managed-excludes.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/injected-index.d.ts +3 -1
- package/dist/injected-index.d.ts.map +1 -1
- package/dist/injected-index.js +8 -3
- package/dist/injected-index.js.map +1 -1
- package/dist/lock-service/index.d.ts +0 -3
- package/dist/lock-service/index.d.ts.map +1 -1
- package/dist/lock-service/index.js +0 -7
- package/dist/lock-service/index.js.map +1 -1
- package/dist/migration/get-fullstack-template-dir.d.ts +5 -2
- package/dist/migration/get-fullstack-template-dir.d.ts.map +1 -1
- package/dist/migration/get-fullstack-template-dir.js +8 -5
- package/dist/migration/get-fullstack-template-dir.js.map +1 -1
- package/dist/migration-templates/app-fullstack/.gitignore +50 -0
- package/dist/plugin-options.d.ts +1 -1
- package/dist/plugin-options.d.ts.map +1 -1
- package/dist/policy-gate-runner.d.ts +7 -32
- package/dist/policy-gate-runner.d.ts.map +1 -1
- package/dist/policy-gate-runner.js +6 -23
- package/dist/policy-gate-runner.js.map +1 -1
- package/dist/socket-manager.d.ts +2 -9
- package/dist/socket-manager.d.ts.map +1 -1
- package/dist/socket-manager.js +19 -160
- package/dist/socket-manager.js.map +1 -1
- package/dist/sync-service/draft-helpers.d.ts +0 -9
- package/dist/sync-service/draft-helpers.d.ts.map +1 -1
- package/dist/sync-service/draft-helpers.js +0 -135
- package/dist/sync-service/draft-helpers.js.map +1 -1
- package/dist/sync-service/index.d.ts +1 -24
- package/dist/sync-service/index.d.ts.map +1 -1
- package/dist/sync-service/index.js +9 -197
- package/dist/sync-service/index.js.map +1 -1
- package/dist/sync-service/list-dir.d.ts +1 -3
- package/dist/sync-service/list-dir.d.ts.map +1 -1
- package/dist/sync-service/list-dir.js +1 -7
- package/dist/sync-service/list-dir.js.map +1 -1
- package/dist/util/log-sanitizer.d.ts +0 -4
- package/dist/util/log-sanitizer.d.ts.map +1 -1
- package/dist/util/log-sanitizer.js +0 -7
- package/dist/util/log-sanitizer.js.map +1 -1
- package/package.json +52 -57
- package/dist/agent-tool-executor/codex-drafts.d.ts +0 -12
- package/dist/agent-tool-executor/codex-drafts.d.ts.map +0 -1
- package/dist/agent-tool-executor/codex-drafts.js +0 -48
- package/dist/agent-tool-executor/codex-drafts.js.map +0 -1
- package/dist/agent-tool-executor/codex-exec-server.d.ts +0 -42
- package/dist/agent-tool-executor/codex-exec-server.d.ts.map +0 -1
- package/dist/agent-tool-executor/codex-exec-server.js +0 -405
- package/dist/agent-tool-executor/codex-exec-server.js.map +0 -1
- package/dist/agent-tool-executor/codex-execution-policy.d.ts +0 -12
- package/dist/agent-tool-executor/codex-execution-policy.d.ts.map +0 -1
- package/dist/agent-tool-executor/codex-execution-policy.js +0 -201
- package/dist/agent-tool-executor/codex-execution-policy.js.map +0 -1
- package/dist/agent-tool-executor/native-dotenv-watch-scope.d.ts +0 -12
- package/dist/agent-tool-executor/native-dotenv-watch-scope.d.ts.map +0 -1
- package/dist/agent-tool-executor/native-dotenv-watch-scope.js +0 -74
- package/dist/agent-tool-executor/native-dotenv-watch-scope.js.map +0 -1
- package/dist/ai-service/agent/security-scan-tools.d.ts +0 -12
- package/dist/ai-service/agent/security-scan-tools.d.ts.map +0 -1
- package/dist/ai-service/agent/security-scan-tools.js +0 -44
- package/dist/ai-service/agent/security-scan-tools.js.map +0 -1
- package/dist/ai-service/builder-conversation.d.ts +0 -70
- package/dist/ai-service/builder-conversation.d.ts.map +0 -1
- package/dist/ai-service/builder-conversation.js +0 -660
- package/dist/ai-service/builder-conversation.js.map +0 -1
- package/dist/ai-service/builder-inference-auth.d.ts +0 -11
- package/dist/ai-service/builder-inference-auth.d.ts.map +0 -1
- package/dist/ai-service/builder-inference-auth.js +0 -48
- package/dist/ai-service/builder-inference-auth.js.map +0 -1
- package/dist/ai-service/builder-runtime.d.ts +0 -181
- package/dist/ai-service/builder-runtime.d.ts.map +0 -1
- package/dist/ai-service/builder-runtime.js +0 -337
- package/dist/ai-service/builder-runtime.js.map +0 -1
- package/dist/ai-service/builder-session-store.d.ts +0 -26
- package/dist/ai-service/builder-session-store.d.ts.map +0 -1
- package/dist/ai-service/builder-session-store.js +0 -66
- package/dist/ai-service/builder-session-store.js.map +0 -1
- package/dist/ai-service/builder-tool-callbacks.d.ts +0 -26
- package/dist/ai-service/builder-tool-callbacks.d.ts.map +0 -1
- package/dist/ai-service/builder-tool-callbacks.js +0 -114
- package/dist/ai-service/builder-tool-callbacks.js.map +0 -1
- package/dist/ai-service/builder-tools.d.ts +0 -46
- package/dist/ai-service/builder-tools.d.ts.map +0 -1
- package/dist/ai-service/builder-tools.js +0 -181
- package/dist/ai-service/builder-tools.js.map +0 -1
- package/dist/ai-service/chat/switch-chat-seed.d.ts +0 -8
- package/dist/ai-service/chat/switch-chat-seed.d.ts.map +0 -1
- package/dist/ai-service/chat/switch-chat-seed.js +0 -47
- package/dist/ai-service/chat/switch-chat-seed.js.map +0 -1
- package/dist/ai-service/llm/request-settings.d.ts +0 -6
- package/dist/ai-service/llm/request-settings.d.ts.map +0 -1
- package/dist/ai-service/llm/request-settings.js +0 -21
- package/dist/ai-service/llm/request-settings.js.map +0 -1
- package/dist/ai-service/native-callback-order.d.ts +0 -7
- package/dist/ai-service/native-callback-order.d.ts.map +0 -1
- package/dist/ai-service/native-callback-order.js +0 -39
- package/dist/ai-service/native-callback-order.js.map +0 -1
- package/dist/ai-service/native-secret-redactor.d.ts +0 -4
- package/dist/ai-service/native-secret-redactor.d.ts.map +0 -1
- package/dist/ai-service/native-secret-redactor.js +0 -34
- package/dist/ai-service/native-secret-redactor.js.map +0 -1
- package/dist/ai-service/policy-gate-review.d.ts +0 -42
- package/dist/ai-service/policy-gate-review.d.ts.map +0 -1
- package/dist/ai-service/policy-gate-review.js +0 -664
- package/dist/ai-service/policy-gate-review.js.map +0 -1
- package/dist/ai-service/skills/system/native.d.ts +0 -7
- package/dist/ai-service/skills/system/native.d.ts.map +0 -1
- package/dist/ai-service/skills/system/native.js +0 -25
- package/dist/ai-service/skills/system/native.js.map +0 -1
- package/dist/ai-service/skills/system/paths.d.ts +0 -2
- package/dist/ai-service/skills/system/paths.d.ts.map +0 -1
- package/dist/ai-service/skills/system/paths.js +0 -2
- package/dist/ai-service/skills/system/paths.js.map +0 -1
- package/dist/git-service/credential-scope.d.ts +0 -16
- package/dist/git-service/credential-scope.d.ts.map +0 -1
- package/dist/git-service/credential-scope.js +0 -91
- package/dist/git-service/credential-scope.js.map +0 -1
- package/dist/review-runner.d.ts +0 -25
- package/dist/review-runner.d.ts.map +0 -1
- package/dist/review-runner.js +0 -196
- package/dist/review-runner.js.map +0 -1
- package/dist/sync-service/draft-mutation.d.ts +0 -11
- package/dist/sync-service/draft-mutation.d.ts.map +0 -1
- package/dist/sync-service/draft-mutation.js +0 -121
- package/dist/sync-service/draft-mutation.js.map +0 -1
- package/dist/sync-service/native-draft-session.d.ts +0 -22
- package/dist/sync-service/native-draft-session.d.ts.map +0 -1
- package/dist/sync-service/native-draft-session.js +0 -229
- package/dist/sync-service/native-draft-session.js.map +0 -1
- package/dist/sync-service/safe-directory-reader.d.ts +0 -24
- package/dist/sync-service/safe-directory-reader.d.ts.map +0 -1
- package/dist/sync-service/safe-directory-reader.js +0 -124
- 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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
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
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
339
|
+
return { integrations, unresolvedKeys };
|
|
148
340
|
}
|
|
149
341
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
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
|
|
371
|
+
let ast;
|
|
160
372
|
try {
|
|
161
|
-
|
|
373
|
+
ast = parse(source, {
|
|
374
|
+
sourceType: "module",
|
|
375
|
+
plugins: ["typescript"],
|
|
376
|
+
});
|
|
162
377
|
}
|
|
163
378
|
catch {
|
|
164
379
|
return [];
|
|
165
380
|
}
|
|
166
|
-
|
|
167
|
-
|
|
381
|
+
return extractFromProgram(ast.program.body, new Map(), "any", "default")
|
|
382
|
+
.integrations;
|
|
168
383
|
}
|
|
169
|
-
/**
|
|
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
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* not
|
|
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
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* `export
|
|
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
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
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
|
-
* `
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* `
|
|
195
|
-
*
|
|
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
|
-
* -
|
|
199
|
-
* - `"(unknown)"` for
|
|
200
|
-
*
|
|
201
|
-
* - `"
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
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
|
|
453
|
+
let ast;
|
|
211
454
|
try {
|
|
212
|
-
|
|
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
|
|
218
|
-
const
|
|
219
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
311
|
-
|
|
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
|
-
|
|
377
|
-
return
|
|
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
|
-
|
|
386
|
-
return
|
|
510
|
+
try {
|
|
511
|
+
return {
|
|
512
|
+
exists: true,
|
|
513
|
+
body: parse(source, {
|
|
514
|
+
sourceType: "module",
|
|
515
|
+
plugins: ["typescript"],
|
|
516
|
+
}).program.body,
|
|
517
|
+
};
|
|
387
518
|
}
|
|
388
|
-
|
|
389
|
-
return
|
|
519
|
+
catch {
|
|
520
|
+
return { exists: true };
|
|
390
521
|
}
|
|
391
522
|
}
|
|
392
523
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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 (
|
|
420
|
-
|
|
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
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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
|
-
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
-
|
|
495
|
-
|
|
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
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
const
|
|
596
|
-
if (
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
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
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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
|