carrick 0.3.155 → 0.3.157
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/contract.d.ts +22 -23
- package/dist/contract.js.map +1 -1
- package/dist/facts/enabled.d.ts +28 -0
- package/dist/facts/enabled.js +36 -0
- package/dist/facts/enabled.js.map +1 -1
- package/dist/facts/fetch.js +20 -8
- package/dist/facts/fetch.js.map +1 -1
- package/dist/facts/lines.d.ts +75 -2
- package/dist/facts/lines.js +302 -46
- package/dist/facts/lines.js.map +1 -1
- package/dist/facts/match.d.ts +2 -0
- package/dist/facts/match.js +189 -28
- package/dist/facts/match.js.map +1 -1
- package/dist/facts/peers.d.ts +2 -0
- package/dist/facts/peers.js +7 -2
- package/dist/facts/peers.js.map +1 -1
- package/dist/facts/store.d.ts +98 -2
- package/dist/facts/store.js +110 -12
- package/dist/facts/store.js.map +1 -1
- package/dist/held/client.d.ts +34 -0
- package/dist/held/client.js +85 -0
- package/dist/held/client.js.map +1 -0
- package/dist/held/daemon.d.ts +106 -0
- package/dist/held/daemon.js +307 -0
- package/dist/held/daemon.js.map +1 -0
- package/dist/held/engine.d.ts +50 -0
- package/dist/held/engine.js +166 -0
- package/dist/held/engine.js.map +1 -0
- package/dist/held/paths.d.ts +9 -0
- package/dist/held/paths.js +27 -0
- package/dist/held/paths.js.map +1 -0
- package/dist/held/place.d.ts +84 -0
- package/dist/held/place.js +198 -0
- package/dist/held/place.js.map +1 -0
- package/dist/held/registry.d.ts +22 -0
- package/dist/held/registry.js +72 -0
- package/dist/held/registry.js.map +1 -0
- package/dist/held/run.d.ts +2 -0
- package/dist/held/run.js +60 -0
- package/dist/held/run.js.map +1 -0
- package/dist/hook/bash-targets.d.ts +7 -2
- package/dist/hook/bash-targets.js +82 -27
- package/dist/hook/bash-targets.js.map +1 -1
- package/dist/hook/edit-flow.js +11 -7
- package/dist/hook/edit-flow.js.map +1 -1
- package/dist/hook/late.d.ts +1 -1
- package/dist/hook/late.js +3 -3
- package/dist/hook/late.js.map +1 -1
- package/dist/hook/lock.d.ts +26 -0
- package/dist/hook/lock.js +122 -0
- package/dist/hook/lock.js.map +1 -0
- package/dist/hook/post-bash.js +22 -7
- package/dist/hook/post-bash.js.map +1 -1
- package/dist/hook/post-read.js +9 -4
- package/dist/hook/post-read.js.map +1 -1
- package/dist/hook/probe.js +4 -2
- package/dist/hook/probe.js.map +1 -1
- package/dist/hook/read-answer.d.ts +23 -4
- package/dist/hook/read-answer.js +74 -19
- package/dist/hook/read-answer.js.map +1 -1
- package/dist/hook/rechecks.d.ts +2 -5
- package/dist/hook/rechecks.js +23 -130
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/similar.d.ts +13 -0
- package/dist/hook/similar.js +60 -0
- package/dist/hook/similar.js.map +1 -0
- package/dist/hook/stop-wait.d.ts +1 -0
- package/dist/hook/stop-wait.js +19 -24
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/timings.d.ts +17 -3
- package/dist/hook/timings.js +10 -2
- package/dist/hook/timings.js.map +1 -1
- package/dist/lsp-frame.d.ts +20 -0
- package/dist/lsp-frame.js +47 -0
- package/dist/lsp-frame.js.map +1 -0
- package/dist/render.js +9 -3
- package/dist/render.js.map +1 -1
- package/dist/scan.d.ts +9 -0
- package/dist/scan.js +39 -8
- package/dist/scan.js.map +1 -1
- package/dist/server.js +4 -28
- package/dist/server.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/bundler.d.ts +5 -0
- package/sidecar/dist/src/bundler.js +20 -0
- package/sidecar/dist/src/capture/anchors.js +19 -4
- package/sidecar/dist/src/capture/api.d.ts +52 -4
- package/sidecar/dist/src/capture/check-probe.d.ts +17 -1
- package/sidecar/dist/src/capture/check-probe.js +39 -2
- package/sidecar/dist/src/capture/index.d.ts +12 -4
- package/sidecar/dist/src/capture/index.js +19 -3
- package/sidecar/dist/src/capture/result-label.js +3 -1
- package/sidecar/dist/src/capture/self-check.js +12 -31
- package/sidecar/dist/src/capture/serialised-arms.d.ts +27 -0
- package/sidecar/dist/src/capture/serialised-arms.js +76 -0
- package/sidecar/dist/src/capture/site-node.d.ts +17 -0
- package/sidecar/dist/src/capture/site-node.js +36 -0
- package/sidecar/dist/src/capture/stub-resolution.d.ts +63 -0
- package/sidecar/dist/src/capture/stub-resolution.js +102 -0
- package/sidecar/dist/src/capture/type-reasons.json +78 -0
- package/sidecar/dist/src/capture/unresolved.js +8 -1
- package/sidecar/dist/src/definition-resolver.d.ts +18 -9
- package/sidecar/dist/src/definition-resolver.js +66 -42
- package/sidecar/dist/src/engine-stamp.json +1 -0
- package/sidecar/dist/src/held-shadow.d.ts +60 -0
- package/sidecar/dist/src/held-shadow.js +222 -0
- package/sidecar/dist/src/index.js +47 -1
- package/sidecar/dist/src/library-claims.d.ts +3 -1
- package/sidecar/dist/src/library-claims.js +79 -3
- package/sidecar/dist/src/retype.js +1 -61
- package/sidecar/dist/src/type-home.d.ts +42 -0
- package/sidecar/dist/src/type-home.js +94 -0
- package/sidecar/dist/src/type-inferrer.d.ts +245 -28
- package/sidecar/dist/src/type-inferrer.js +938 -192
- package/sidecar/dist/src/type-parameters.d.ts +41 -0
- package/sidecar/dist/src/type-parameters.js +126 -0
- package/sidecar/dist/src/type-structural-expander.d.ts +1 -11
- package/sidecar/dist/src/type-structural-expander.js +9 -1
- package/sidecar/dist/src/types.d.ts +132 -20
- package/sidecar/dist/src/validators.d.ts +450 -244
- package/sidecar/dist/src/validators.js +27 -1
- package/dist/hook/lead.d.ts +0 -13
- package/dist/hook/lead.js +0 -39
- package/dist/hook/lead.js.map +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a stub's module specifiers resolve: one answer for the capture's
|
|
3
|
+
* self-check and for the definition resolver that reads the stub after it
|
|
4
|
+
* (carrick#3995 T5).
|
|
5
|
+
*
|
|
6
|
+
* The stub is written outside the checkout, so a bare specifier in it
|
|
7
|
+
* (`import("pkg").Thing`) reaches nothing by itself. The self-check reaches the
|
|
8
|
+
* producer's installed packages three ways: a `node_modules` link inside the
|
|
9
|
+
* stub to the producer's own, the capture's compiler host (installed-package
|
|
10
|
+
* rewrites, a Deno graph, the untrusted-tree read bound), and, for a
|
|
11
|
+
* declaration emitted from a source outside the service's rootDir, that
|
|
12
|
+
* source's own place in the checkout. The resolver used to read the stub with
|
|
13
|
+
* none of them, so an alias the self-check called clean answered `any`.
|
|
14
|
+
*
|
|
15
|
+
* The capture remembers each stub's resolution in this process; the resolver
|
|
16
|
+
* asks for it by stub directory. The compiler engine runs a capture in a
|
|
17
|
+
* process of its own and resolves its stub in the same process, right after.
|
|
18
|
+
* A stub this process did not capture reads with nothing installed, as before.
|
|
19
|
+
*/
|
|
20
|
+
import ts from 'typescript';
|
|
21
|
+
import * as fs from 'node:fs';
|
|
22
|
+
import * as path from 'node:path';
|
|
23
|
+
/**
|
|
24
|
+
* Point the stub at the producer's installed packages: a `node_modules` link
|
|
25
|
+
* in the stub to the producer's own, unless the checkout is bare or the stub
|
|
26
|
+
* already has one. Returns what removes the link again.
|
|
27
|
+
*/
|
|
28
|
+
export function linkInstalledPackages(resolution) {
|
|
29
|
+
const repoNodeModules = path.join(resolution.repoRoot, 'node_modules');
|
|
30
|
+
const linkPath = path.join(resolution.stubDir, 'node_modules');
|
|
31
|
+
if (resolution.bareCheckout || !fs.existsSync(repoNodeModules) || fs.existsSync(linkPath))
|
|
32
|
+
return () => { };
|
|
33
|
+
resolution.guard.symlink(repoNodeModules, linkPath, 'dir');
|
|
34
|
+
// unlinkSync, not rmSync: the link target is a directory and rmSync
|
|
35
|
+
// refuses symlinks-to-directories with EISDIR.
|
|
36
|
+
return () => resolution.guard.unlink(linkPath);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The compiler host of a program over the stub: the capture's, with outside
|
|
40
|
+
* declarations resolving from their source. `undefined` means the compiler's
|
|
41
|
+
* default host.
|
|
42
|
+
*/
|
|
43
|
+
export function stubResolutionHost(resolution, options) {
|
|
44
|
+
const outside = resolution.outsideSources;
|
|
45
|
+
if (!outside || Object.keys(outside).length === 0)
|
|
46
|
+
return resolution.compilerHost?.(options);
|
|
47
|
+
const host = resolution.compilerHost?.(options) ?? ts.createCompilerHost(options);
|
|
48
|
+
const fallback = host.resolveModuleNames?.bind(host);
|
|
49
|
+
host.resolveModuleNames = (names, containingFile, reused, redirected, compilerOptions, containingSourceFile) => names.map((name, index) => {
|
|
50
|
+
const resolved = fallback
|
|
51
|
+
? fallback([name], containingFile, reused?.slice(index, index + 1), redirected, compilerOptions, containingSourceFile)[0]
|
|
52
|
+
: ts.resolveModuleName(name, containingFile, compilerOptions, host).resolvedModule;
|
|
53
|
+
const source = outside[path.resolve(containingFile)];
|
|
54
|
+
if (resolved || !source || name.startsWith('.') || path.isAbsolute(name))
|
|
55
|
+
return resolved;
|
|
56
|
+
return ts.resolveModuleName(name, source, compilerOptions, host).resolvedModule;
|
|
57
|
+
});
|
|
58
|
+
return host;
|
|
59
|
+
}
|
|
60
|
+
/** Each stub this process captured, by absolute stub directory. */
|
|
61
|
+
const captured = new Map();
|
|
62
|
+
/** Forget every stub of an earlier capture: only the latest is resolved. */
|
|
63
|
+
export function forgetStubResolutions() {
|
|
64
|
+
captured.clear();
|
|
65
|
+
}
|
|
66
|
+
/** Remember how a captured stub resolves, for the resolver that reads it next. */
|
|
67
|
+
export function rememberStubResolution(resolution) {
|
|
68
|
+
captured.set(path.resolve(resolution.stubDir), resolution);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Run `use` with the stub resolving as its self-check did: the installed
|
|
72
|
+
* packages linked in, and module names resolved through the self-check's host.
|
|
73
|
+
* `use` gets `undefined` when this process did not capture the stub; the stub
|
|
74
|
+
* then reads with nothing installed.
|
|
75
|
+
*/
|
|
76
|
+
export function withStubResolution(stubDir, use) {
|
|
77
|
+
const resolution = captured.get(path.resolve(stubDir));
|
|
78
|
+
if (!resolution)
|
|
79
|
+
return use(undefined);
|
|
80
|
+
const unlink = linkInstalledPackages(resolution);
|
|
81
|
+
try {
|
|
82
|
+
const hosts = new Map();
|
|
83
|
+
const hostOf = (options) => {
|
|
84
|
+
let host = hosts.get(options);
|
|
85
|
+
if (!host) {
|
|
86
|
+
host = stubResolutionHost(resolution, options) ?? ts.createCompilerHost(options);
|
|
87
|
+
hosts.set(options, host);
|
|
88
|
+
}
|
|
89
|
+
return host;
|
|
90
|
+
};
|
|
91
|
+
return use((moduleNames, containingFile, options) => {
|
|
92
|
+
const host = hostOf(options);
|
|
93
|
+
if (host.resolveModuleNames) {
|
|
94
|
+
return host.resolveModuleNames(moduleNames, containingFile, undefined, undefined, options);
|
|
95
|
+
}
|
|
96
|
+
return moduleNames.map((name) => ts.resolveModuleName(name, containingFile, options, host).resolvedModule);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
unlink();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"declared": {
|
|
3
|
+
"sentence": "declared that way in the code or in a library it calls",
|
|
4
|
+
"decided": "never"
|
|
5
|
+
},
|
|
6
|
+
"unresolved_import": {
|
|
7
|
+
"sentence": "a dependency or generated module could not be resolved on the scanned checkout",
|
|
8
|
+
"decided": "never"
|
|
9
|
+
},
|
|
10
|
+
"budget_exhausted": {
|
|
11
|
+
"sentence": "the type walk hit its budget before resolving this",
|
|
12
|
+
"decided": "never"
|
|
13
|
+
},
|
|
14
|
+
"no_payload_evidence": {
|
|
15
|
+
"sentence": "nothing in the handler states what it returns",
|
|
16
|
+
"decided": "never"
|
|
17
|
+
},
|
|
18
|
+
"machinery_envelope": {
|
|
19
|
+
"sentence": "the value sits inside framework machinery the walk does not read through",
|
|
20
|
+
"decided": "at_call_result"
|
|
21
|
+
},
|
|
22
|
+
"coerced_input": {
|
|
23
|
+
"sentence": "the request schema takes this position untyped and coerces it to the type printed here, so the finding is what a caller may send rather than the printed member",
|
|
24
|
+
"decided": "never"
|
|
25
|
+
},
|
|
26
|
+
"no_success_payload": {
|
|
27
|
+
"sentence": "every response the route sends is an error or a redirect, so the scan found no success body and compared nothing at this site",
|
|
28
|
+
"decided": "always"
|
|
29
|
+
},
|
|
30
|
+
"no_request_body": {
|
|
31
|
+
"sentence": "the request read located here is a path parameter or a query the route validates rather than a body, so the scan compared nothing at this site",
|
|
32
|
+
"decided": "always"
|
|
33
|
+
},
|
|
34
|
+
"projected_value_only": {
|
|
35
|
+
"sentence": "every read of the call's result takes a member out of it, so the site states part of a payload rather than a whole one and the scan compared nothing here",
|
|
36
|
+
"decided": "always"
|
|
37
|
+
},
|
|
38
|
+
"serialised_body_unread": {
|
|
39
|
+
"sentence": "the handler returns a status and a body it serialised to a string, and the scan could not see what it serialised, so nothing was compared at this site. Read the handler for the body's shape rather than this type",
|
|
40
|
+
"decided": "always"
|
|
41
|
+
},
|
|
42
|
+
"body_built_by_callee": {
|
|
43
|
+
"sentence": "the call hands its argument to a function that builds the request body from it in a way the scan could not type, so the argument is not the body and nothing was compared at this site. Read the called function for the body's shape",
|
|
44
|
+
"decided": "always"
|
|
45
|
+
},
|
|
46
|
+
"bound_by_callers": {
|
|
47
|
+
"sentence": "the type here is still an open type parameter of a generic function, which only that function's callers set, so this site states no type of its own and nothing was compared here. Read the callers of the function that declares the parameter (the detail names it) for the type",
|
|
48
|
+
"decided": "always"
|
|
49
|
+
},
|
|
50
|
+
"body_member_undecided": {
|
|
51
|
+
"sentence": "the call's result is an object that holds the transport response beside other members, and the called function's code does not settle which member holds the parsed body, so the site states no contract and nothing was compared here. Read the called function's returns for the member that holds the body",
|
|
52
|
+
"decided": "always"
|
|
53
|
+
},
|
|
54
|
+
"result_member_missing": {
|
|
55
|
+
"sentence": "the library this call uses says which part of its result holds the response body, and the type at this call has no such part, so the site states no contract and nothing was compared here",
|
|
56
|
+
"decided": "always"
|
|
57
|
+
},
|
|
58
|
+
"reshaped_by_callback": {
|
|
59
|
+
"sentence": "the call's result is handed unread to a callback in its chain that builds a new value from it, and nothing in the chain states the body, so the site states no contract and nothing was compared here",
|
|
60
|
+
"decided": "always"
|
|
61
|
+
},
|
|
62
|
+
"not_located": {
|
|
63
|
+
"sentence": "the scan found no value in the code for this payload, so no type was read at this site",
|
|
64
|
+
"decided": "never"
|
|
65
|
+
},
|
|
66
|
+
"site_unreadable": {
|
|
67
|
+
"sentence": "the scan located the site and the compiler engine could not read a type there",
|
|
68
|
+
"decided": "never"
|
|
69
|
+
},
|
|
70
|
+
"unplaced_top_type": {
|
|
71
|
+
"sentence": "at a member the scan could not identify",
|
|
72
|
+
"decided": "never"
|
|
73
|
+
},
|
|
74
|
+
"not_recorded": {
|
|
75
|
+
"sentence": "the layer that produced it recorded no cause",
|
|
76
|
+
"decided": "never"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* self-check labels the matching findings. Seam: node builtins + `typescript`.
|
|
17
17
|
*/
|
|
18
18
|
import ts from 'typescript';
|
|
19
|
-
import { findUncarriedPositions, findUnresolvedPlaceholders } from './deep-walk.js';
|
|
19
|
+
import { findUncarriedPositions, findUnresolvedPlaceholders, isErrorPlaceholder, } from './deep-walk.js';
|
|
20
20
|
/** Files the specifier walk visits from one anchor before it stops. */
|
|
21
21
|
const MAX_REACHABLE_FILES = 256;
|
|
22
22
|
/** Per-program memo: source file name -> unresolved specifiers it reaches. */
|
|
@@ -47,6 +47,13 @@ export function unresolvedAtAnchor(program, sourceFile, type, location, pathPref
|
|
|
47
47
|
const found = findUnresolvedPlaceholders(type, program, checker, location);
|
|
48
48
|
if (uncarried)
|
|
49
49
|
found.push(...findUncarriedPositions(type, program, checker, location, uncarried));
|
|
50
|
+
// The member walk leaves the root to its callers (carrick#3995). A call,
|
|
51
|
+
// `.then`, member read or binding through a value that did not resolve
|
|
52
|
+
// keeps the placeholder, while the emitted stub prints it as a plain `any`
|
|
53
|
+
// the self-check would read as declared. The root is the alias's own type
|
|
54
|
+
// only when no prefix maps it under a member.
|
|
55
|
+
if (pathPrefix === '' && isErrorPlaceholder(type))
|
|
56
|
+
found.unshift('');
|
|
50
57
|
const paths = [...new Set(found)].map((path) => prefixPath(pathPrefix, path));
|
|
51
58
|
if (paths.length === 0)
|
|
52
59
|
return undefined;
|
|
@@ -10,11 +10,16 @@
|
|
|
10
10
|
* anonymous (inline object types, node-builder prints) the surface alias
|
|
11
11
|
* line itself is the as-written form.
|
|
12
12
|
* - `expanded`: the fully *structural* form, with every named member type
|
|
13
|
-
* inlined to its member structure, recursively.
|
|
13
|
+
* inlined to its member structure, recursively. The sending side of an
|
|
14
|
+
* `http` payload and a GraphQL producer response print in JSON wire form
|
|
15
|
+
* (a `Date` as `string`), by the rule the judge compares them under
|
|
16
|
+
* (`wireFormFor`, carrick-cloud#3503, carrick#4275): the stored text says
|
|
17
|
+
* what travels. `definition` stays as written.
|
|
14
18
|
*
|
|
15
19
|
* An alias whose own type did not resolve produces neither: the tree is read
|
|
16
|
-
*
|
|
17
|
-
*
|
|
20
|
+
* as its self-check read it, so a reference that leaves it and that the
|
|
21
|
+
* self-check could not follow either lands on TypeScript's unresolved-reference
|
|
22
|
+
* placeholder, which the compiler prints as the reference
|
|
18
23
|
* text rather than as `any` (see `isUnresolvedReference`). Both forms are then
|
|
19
24
|
* the top type, which is what every downstream rule about an empty answer is
|
|
20
25
|
* written to refuse.
|
|
@@ -26,12 +31,16 @@
|
|
|
26
31
|
* inference path in `type-inferrer.ts`), which walks the resolved `Type` and
|
|
27
32
|
* rebuilds the inlined text.
|
|
28
33
|
*
|
|
29
|
-
* Each resolve call builds its own throwaway project over the stub tree
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
+
* Each resolve call builds its own throwaway project over the stub tree: not
|
|
35
|
+
* the service's project, and not whether the sidecar was ever initialised. So
|
|
36
|
+
* the request costs what the stub costs, in a process that has built nothing as
|
|
37
|
+
* in one that has (carrick#1927), and the sidecar's long-lived project never
|
|
38
|
+
* sees stub files. Its module specifiers resolve as the capture's self-check
|
|
39
|
+
* resolved them (`withStubResolution`), so a bare package import the
|
|
40
|
+
* self-check called clean reads the installed package's type here too
|
|
41
|
+
* (carrick#3995 T5).
|
|
34
42
|
*/
|
|
43
|
+
import type { DefinitionAlias } from './types.js';
|
|
35
44
|
export interface ResolvedDefinition {
|
|
36
45
|
type_alias: string;
|
|
37
46
|
/** Original declaration text as written (preserves named types) */
|
|
@@ -51,7 +60,7 @@ export declare class DefinitionResolver {
|
|
|
51
60
|
* both extensionless and `.js`-suffixed specifiers — the same policy the
|
|
52
61
|
* check-phase workspace uses.
|
|
53
62
|
*/
|
|
54
|
-
resolveFromStub(stubDir: string, aliases:
|
|
63
|
+
resolveFromStub(stubDir: string, aliases: DefinitionAlias[]): ResolvedDefinition[];
|
|
55
64
|
/**
|
|
56
65
|
* Resolve a single alias: the original text and the structural form.
|
|
57
66
|
*/
|
|
@@ -10,11 +10,16 @@
|
|
|
10
10
|
* anonymous (inline object types, node-builder prints) the surface alias
|
|
11
11
|
* line itself is the as-written form.
|
|
12
12
|
* - `expanded`: the fully *structural* form, with every named member type
|
|
13
|
-
* inlined to its member structure, recursively.
|
|
13
|
+
* inlined to its member structure, recursively. The sending side of an
|
|
14
|
+
* `http` payload and a GraphQL producer response print in JSON wire form
|
|
15
|
+
* (a `Date` as `string`), by the rule the judge compares them under
|
|
16
|
+
* (`wireFormFor`, carrick-cloud#3503, carrick#4275): the stored text says
|
|
17
|
+
* what travels. `definition` stays as written.
|
|
14
18
|
*
|
|
15
19
|
* An alias whose own type did not resolve produces neither: the tree is read
|
|
16
|
-
*
|
|
17
|
-
*
|
|
20
|
+
* as its self-check read it, so a reference that leaves it and that the
|
|
21
|
+
* self-check could not follow either lands on TypeScript's unresolved-reference
|
|
22
|
+
* placeholder, which the compiler prints as the reference
|
|
18
23
|
* text rather than as `any` (see `isUnresolvedReference`). Both forms are then
|
|
19
24
|
* the top type, which is what every downstream rule about an empty answer is
|
|
20
25
|
* written to refuse.
|
|
@@ -26,16 +31,19 @@
|
|
|
26
31
|
* inference path in `type-inferrer.ts`), which walks the resolved `Type` and
|
|
27
32
|
* rebuilds the inlined text.
|
|
28
33
|
*
|
|
29
|
-
* Each resolve call builds its own throwaway project over the stub tree
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
+
* Each resolve call builds its own throwaway project over the stub tree: not
|
|
35
|
+
* the service's project, and not whether the sidecar was ever initialised. So
|
|
36
|
+
* the request costs what the stub costs, in a process that has built nothing as
|
|
37
|
+
* in one that has (carrick#1927), and the sidecar's long-lived project never
|
|
38
|
+
* sees stub files. Its module specifiers resolve as the capture's self-check
|
|
39
|
+
* resolved them (`withStubResolution`), so a bare package import the
|
|
40
|
+
* self-check called clean reads the installed package's type here too
|
|
41
|
+
* (carrick#3995 T5).
|
|
34
42
|
*/
|
|
35
43
|
import * as path from 'node:path';
|
|
36
44
|
import * as fs from 'node:fs';
|
|
37
45
|
import { Project, Node } from 'ts-morph';
|
|
38
|
-
import { sidecarCompilerOptions } from './capture/index.js';
|
|
46
|
+
import { wireFormFor, sidecarCompilerOptions, withStubResolution } from './capture/index.js';
|
|
39
47
|
import { defaultLibraryOptions } from './default-library.js';
|
|
40
48
|
import { expandTypeStructural, } from './type-structural-expander.js';
|
|
41
49
|
export class DefinitionResolver {
|
|
@@ -58,39 +66,48 @@ export class DefinitionResolver {
|
|
|
58
66
|
return [];
|
|
59
67
|
}
|
|
60
68
|
try {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
const results = [];
|
|
81
|
-
for (const alias of aliases) {
|
|
82
|
-
const result = this.resolveAlias(surface, alias, {
|
|
83
|
-
program: stubProject.getProgram().compilerObject,
|
|
84
|
-
repoRoot: stubDir,
|
|
69
|
+
return withStubResolution(stubDir, (resolveModules) => {
|
|
70
|
+
if (!resolveModules)
|
|
71
|
+
this.log(`${stubDir} was not captured in this process; reading it with nothing installed`);
|
|
72
|
+
const stubProject = new Project({
|
|
73
|
+
...defaultLibraryOptions(),
|
|
74
|
+
compilerOptions: sidecarCompilerOptions({
|
|
75
|
+
target: 99, // ESNext
|
|
76
|
+
module: 99, // ESNext
|
|
77
|
+
moduleResolution: 100, // Bundler
|
|
78
|
+
strict: true,
|
|
79
|
+
skipLibCheck: true,
|
|
80
|
+
}),
|
|
81
|
+
skipAddingFilesFromTsConfig: true,
|
|
82
|
+
...(resolveModules && {
|
|
83
|
+
resolutionHost: (_host, getOptions) => ({
|
|
84
|
+
resolveModuleNames: (moduleNames, containingFile) => resolveModules(moduleNames, containingFile, getOptions()),
|
|
85
|
+
}),
|
|
86
|
+
}),
|
|
85
87
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
for (const filePath of walkDtsFiles(typesDir)) {
|
|
89
|
+
stubProject.addSourceFileAtPath(filePath);
|
|
88
90
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
const surface = stubProject.getSourceFile(surfacePath);
|
|
92
|
+
if (!surface) {
|
|
93
|
+
this.logError(`Failed to load ${surfacePath}`);
|
|
94
|
+
return [];
|
|
91
95
|
}
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
const results = [];
|
|
97
|
+
for (const alias of aliases) {
|
|
98
|
+
const result = this.resolveAlias(surface, alias, {
|
|
99
|
+
program: stubProject.getProgram().compilerObject,
|
|
100
|
+
repoRoot: stubDir,
|
|
101
|
+
});
|
|
102
|
+
if (result) {
|
|
103
|
+
results.push(result);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
this.log(`Could not resolve alias: ${alias.alias}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return results;
|
|
110
|
+
});
|
|
94
111
|
}
|
|
95
112
|
catch (err) {
|
|
96
113
|
this.logError(`Resolution failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -100,7 +117,8 @@ export class DefinitionResolver {
|
|
|
100
117
|
/**
|
|
101
118
|
* Resolve a single alias: the original text and the structural form.
|
|
102
119
|
*/
|
|
103
|
-
resolveAlias(sourceFile,
|
|
120
|
+
resolveAlias(sourceFile, payload, origin) {
|
|
121
|
+
const alias = payload.alias;
|
|
104
122
|
const decl = sourceFile.getTypeAlias(alias) ??
|
|
105
123
|
sourceFile.getInterface(alias) ??
|
|
106
124
|
sourceFile.getClass(alias) ??
|
|
@@ -134,8 +152,14 @@ export class DefinitionResolver {
|
|
|
134
152
|
break;
|
|
135
153
|
}
|
|
136
154
|
}
|
|
137
|
-
// Structural form — every named member inlined to its shape
|
|
138
|
-
|
|
155
|
+
// Structural form — every named member inlined to its shape, in the
|
|
156
|
+
// form the payload travels in where the judge compares that form. An
|
|
157
|
+
// RPC procedure fails closed to the declared form: its router's
|
|
158
|
+
// transformer, not JSON, decides what travels (carrick#4275).
|
|
159
|
+
const wire = payload.procedure
|
|
160
|
+
? 'declared'
|
|
161
|
+
: wireFormFor(payload.protocol, payload.type_kind, payload.side);
|
|
162
|
+
const expanded = expandTypeStructural(type, origin, { wire });
|
|
139
163
|
return { type_alias: alias, definition, expanded };
|
|
140
164
|
}
|
|
141
165
|
catch (err) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs_sha256":"c1246197a0eb92ca60d59fba5847424f2654dcf52c08307d5badee9f3e8b3314"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shadow tree a held-open compiler reads: a copy of one service's program
|
|
3
|
+
* that lives outside the checkout and loads on TypeScript 7.
|
|
4
|
+
*
|
|
5
|
+
* The scan's loader builds the program on TypeScript 6 (repo tsconfig, Deno
|
|
6
|
+
* graph, workspace links). TypeScript 7's command line refuses options the
|
|
7
|
+
* repo may set (`baseUrl`, `moduleResolution: node`, `target: es5`,
|
|
8
|
+
* `esModuleInterop: false`), and a config outside the repo cannot govern files
|
|
9
|
+
* inside it, so the held compiler never reads the repo's own config or files.
|
|
10
|
+
* It reads this tree instead:
|
|
11
|
+
*
|
|
12
|
+
* - `w/<repo-relative path>`: byte copies of the service's own files;
|
|
13
|
+
* - `v/<absolute path>`: every other program file (installed packages,
|
|
14
|
+
* runtime types), with each import, export, import type, augmentation and
|
|
15
|
+
* `types` reference pinned to the copy of the file TypeScript 6 resolved it
|
|
16
|
+
* to, so one package name that resolves to two versions stays two files;
|
|
17
|
+
* - `w/tsconfig.json`: generated, `moduleResolution: bundler`, exact `paths`
|
|
18
|
+
* for the bare specifiers the own files use, every non-library program file
|
|
19
|
+
* named in `files` (so `@types` the loader included on its own are
|
|
20
|
+
* explicit), and the library files TypeScript 6 loaded named in `lib`.
|
|
21
|
+
*
|
|
22
|
+
* Own = under the scanned repo, not under a `node_modules` segment, not under
|
|
23
|
+
* `.carrick/`. A bare import added later is not in `paths` (it needs a new
|
|
24
|
+
* shadow).
|
|
25
|
+
*/
|
|
26
|
+
import type { ProjectLoader } from './project-loader.js';
|
|
27
|
+
/** What `write_shadow` answers. */
|
|
28
|
+
export interface ShadowResult {
|
|
29
|
+
/** Absolute path of the generated `w/tsconfig.json`. */
|
|
30
|
+
tsconfig: string;
|
|
31
|
+
/** The service's own files, repo-relative (to the scan root), sorted. */
|
|
32
|
+
own_files: string[];
|
|
33
|
+
/** Program files copied to `v/`. */
|
|
34
|
+
vendored: number;
|
|
35
|
+
/** Specifiers and references rewritten inside those copies. */
|
|
36
|
+
rewritten: number;
|
|
37
|
+
/** Specifiers TypeScript 6 left unresolved or resolved outside the program. */
|
|
38
|
+
unresolved: number;
|
|
39
|
+
/** A bare specifier two own files resolve to different files: reported, not solved. */
|
|
40
|
+
path_conflicts: Array<{
|
|
41
|
+
spec: string;
|
|
42
|
+
a: string;
|
|
43
|
+
b: string;
|
|
44
|
+
from: string;
|
|
45
|
+
}>;
|
|
46
|
+
/** The bare specifiers the own files use, as written to `paths`. */
|
|
47
|
+
bare_specifiers: string[];
|
|
48
|
+
/** Some own file imports a package named `hono` that resolved into the program. */
|
|
49
|
+
hono: boolean;
|
|
50
|
+
/** The native TypeScript 7 executable, or null when only TypeScript 6's tsc is installed. */
|
|
51
|
+
native_tsc: string | null;
|
|
52
|
+
}
|
|
53
|
+
/** `judgeTscPath()` when it is the native executable, else null (no held compiler). */
|
|
54
|
+
export declare function nativeTscPath(tscPath?: string): string | null;
|
|
55
|
+
/**
|
|
56
|
+
* Write the shadow tree of the loader's default program under `outDir` (which
|
|
57
|
+
* must be outside the scan root). Reads the program; changes nothing in the
|
|
58
|
+
* checkout.
|
|
59
|
+
*/
|
|
60
|
+
export declare function writeShadow(loader: ProjectLoader, outDir: string): ShadowResult;
|