carrick 0.3.147 → 0.3.149

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carrick",
3
- "version": "0.3.147",
3
+ "version": "0.3.149",
4
4
  "carrickCache": {
5
5
  "cache_version": 22,
6
6
  "intent_cache_version": 2
@@ -115,11 +115,11 @@
115
115
  "zod": "^3.23.0"
116
116
  },
117
117
  "optionalDependencies": {
118
- "@carrick-tools/cli-darwin-arm64": "0.3.147",
119
- "@carrick-tools/cli-darwin-x64": "0.3.147",
120
- "@carrick-tools/cli-linux-arm64": "0.3.147",
121
- "@carrick-tools/cli-linux-x64": "0.3.147",
122
- "@carrick-tools/cli-win32-x64": "0.3.147"
118
+ "@carrick-tools/cli-darwin-arm64": "0.3.149",
119
+ "@carrick-tools/cli-darwin-x64": "0.3.149",
120
+ "@carrick-tools/cli-linux-arm64": "0.3.149",
121
+ "@carrick-tools/cli-linux-x64": "0.3.149",
122
+ "@carrick-tools/cli-win32-x64": "0.3.149"
123
123
  },
124
124
  "devDependencies": {
125
125
  "@types/node": "^24.13.3"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "carrick",
3
3
  "description": "Claude Code plugin for Carrick, which indexes TypeScript codebases across service and repository boundaries. After each edit it adds the file's routes, calls, and cross-service type mismatches to the session, and it registers Carrick's language server. It pairs with the Carrick MCP server, which lets agents search functions by intent rather than name.",
4
- "version": "0.3.147",
4
+ "version": "0.3.149",
5
5
  "author": {
6
6
  "name": "Carrick",
7
7
  "email": "hello@carrick.tools"
@@ -38,6 +38,7 @@
38
38
  * caller's answers. An executor only one call reaches, or whose callers all
39
39
  * pass the same value, has no such mode.
40
40
  */
41
+ import { functionBodyOf, peelValueWrappers } from './function-body.js';
41
42
  import { Node, SyntaxKind } from 'ts-morph';
42
43
  import { stepsOnPath } from './failure-path.js';
43
44
  /** The function a call runs, when it has one body in the program. */
@@ -45,24 +46,7 @@ export function calledFunction(call) {
45
46
  let symbol = call.getExpression().getSymbol();
46
47
  if (symbol?.isAlias())
47
48
  symbol = symbol.getAliasedSymbol();
48
- const declarations = symbol?.getDeclarations() ?? [];
49
- if (declarations.length !== 1)
50
- return undefined;
51
- const [declaration] = declarations;
52
- if ((Node.isFunctionDeclaration(declaration) || Node.isMethodDeclaration(declaration)) &&
53
- declaration.getBody()) {
54
- return declaration;
55
- }
56
- if (Node.isVariableDeclaration(declaration) || Node.isPropertyAssignment(declaration)) {
57
- let initializer = declaration.getInitializer();
58
- while (initializer && (Node.isParenthesizedExpression(initializer) || Node.isAsExpression(initializer))) {
59
- initializer = initializer.getExpression();
60
- }
61
- if (initializer && (Node.isArrowFunction(initializer) || Node.isFunctionExpression(initializer))) {
62
- return initializer;
63
- }
64
- }
65
- return undefined;
49
+ return functionBodyOf(symbol?.getDeclarations() ?? []);
66
50
  }
67
51
  /** The one call in `caller` that runs `callee`, or `undefined` for none or several. */
68
52
  export function callInto(caller, callee) {
@@ -196,7 +180,7 @@ function bindArguments(callee, call) {
196
180
  const UNDEFINED = { kind: 'value', value: undefined };
197
181
  /** What one argument expression states. */
198
182
  function statedBy(arg) {
199
- const expression = peel(arg);
183
+ const expression = peelValueWrappers(arg);
200
184
  if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) {
201
185
  return { kind: 'value', value: expression.getLiteralValue() };
202
186
  }
@@ -220,7 +204,7 @@ function statedBy(arg) {
220
204
  }
221
205
  /** What an argument states about one of its members, when it is an object literal. */
222
206
  function statedMember(arg, member) {
223
- const literal = peel(arg);
207
+ const literal = peelValueWrappers(arg);
224
208
  if (!Node.isObjectLiteralExpression(literal))
225
209
  return undefined;
226
210
  let found;
@@ -309,25 +293,15 @@ function isWritten(node) {
309
293
  }
310
294
  return false;
311
295
  }
312
- function peel(node) {
313
- let current = node;
314
- while (Node.isParenthesizedExpression(current) ||
315
- Node.isAsExpression(current) ||
316
- Node.isNonNullExpression(current) ||
317
- Node.isSatisfiesExpression(current)) {
318
- current = current.getExpression();
319
- }
320
- return current;
321
- }
322
296
  /** The entry a test operand reads, when it reads a stated value. */
323
297
  function entryOf(node, binding) {
324
- const operand = peel(node);
298
+ const operand = peelValueWrappers(node);
325
299
  if (Node.isIdentifier(operand)) {
326
300
  const symbol = operand.getSymbol();
327
301
  return symbol ? binding.direct.get(symbol) : undefined;
328
302
  }
329
303
  if (Node.isPropertyAccessExpression(operand)) {
330
- const object = peel(operand.getExpression());
304
+ const object = peelValueWrappers(operand.getExpression());
331
305
  const symbol = Node.isIdentifier(object) ? object.getSymbol() : undefined;
332
306
  return symbol ? binding.members.get(symbol)?.get(operand.getName()) : undefined;
333
307
  }
@@ -338,7 +312,7 @@ function statedOperand(node, binding) {
338
312
  }
339
313
  /** The literal a test operand is, when it is one. */
340
314
  function literalOperand(node) {
341
- const operand = peel(node);
315
+ const operand = peelValueWrappers(node);
342
316
  if (Node.isVoidExpression(operand))
343
317
  return UNDEFINED;
344
318
  if (Node.isStringLiteral(operand) ||
@@ -367,7 +341,7 @@ function compare(stated, literal, loose) {
367
341
  }
368
342
  /** True, false, or `undefined` when the stated arguments do not decide `condition`. */
369
343
  function evaluate(condition, binding) {
370
- const test = peel(condition);
344
+ const test = peelValueWrappers(condition);
371
345
  if (Node.isPrefixUnaryExpression(test) && test.getOperatorToken() === SyntaxKind.ExclamationToken) {
372
346
  const inner = evaluate(test.getOperand(), binding);
373
347
  return inner === undefined ? undefined : !inner;
@@ -6,7 +6,7 @@ import { Node, ts, } from 'ts-morph';
6
6
  import * as path from 'node:path';
7
7
  import * as fs from 'node:fs';
8
8
  import { expandTypeStructural, } from './type-structural-expander.js';
9
- import { externalImportsOf, isExternalOrigin } from './origin.js';
9
+ import { expandOriginOf, isExternalOrigin } from './origin.js';
10
10
  import { statusTableBody } from './capture/index.js';
11
11
  /**
12
12
  * #248: upper bound on `SymbolRequest.array_depth`. SDL list nesting is
@@ -321,11 +321,7 @@ export class TypeBundler {
321
321
  * `ExpandOrigin`.
322
322
  */
323
323
  expandOrigin() {
324
- return {
325
- program: this.project.getProgram().compilerObject,
326
- repoRoot: this.repoRoot,
327
- imports: externalImportsOf(this.project),
328
- };
324
+ return expandOriginOf(this.project, this.repoRoot);
329
325
  }
330
326
  extractTypeDefinition(symbol) {
331
327
  const tableBody = symbol.consumer_response ? this.statusTableBodyText(symbol) : undefined;
@@ -35,10 +35,12 @@ export { sidecarCompilerOptions } from './compiler-options.js';
35
35
  export { isInsideCheckout, untrustedReadBound, UNTRUSTED_TREE_ENV, type ReadBound } from './checkout.js';
36
36
  export { serviceConfigPath } from './project-references.js';
37
37
  export { referenceRedirectOf } from './reference-redirect.js';
38
- export { findServiceTsconfig, fileConfigPath } from './service-config.js';
38
+ export { findServiceTsconfig, GoverningConfigs } from './service-config.js';
39
39
  export { WriteGuard } from './guarded-fs.js';
40
40
  export { installedPackageDirectory } from './installed-package-directory.js';
41
41
  export { isDeclarationFileName, packageNameOf } from './specifiers.js';
42
+ export { toPosix } from './installed-package.js';
43
+ export { constituentsOf } from './result-label.js';
42
44
  export { moduleExport } from './anchors.js';
43
45
  export { runCheck } from './check.js';
44
46
  export type { CheckProgress } from './check.js';
@@ -83,4 +85,4 @@ export declare function removeStaleSurfaceEntries(dir: string, guard: WriteGuard
83
85
  /** Same normalization intent as bundle_file_stems on the Rust side. */
84
86
  export declare function sanitizeServiceName(name: string): string;
85
87
  export declare function captureStub(opts: CaptureStubOptions): CaptureStubResult;
86
- export { classifyStatusCodes, constituents, httpStatus, statesNoBody, statesNoShape, statusKeyCode, statusTableBody, statusTableOf, successEntries, } from './status-table.js';
88
+ export { classifyStatusCodes, httpStatus, statesNoBody, statesNoShape, statusKeyCode, statusTableBody, statusTableOf, successEntries, } from './status-table.js';
@@ -54,12 +54,14 @@ export { sidecarCompilerOptions } from './compiler-options.js';
54
54
  export { isInsideCheckout, untrustedReadBound, UNTRUSTED_TREE_ENV } from './checkout.js';
55
55
  export { serviceConfigPath } from './project-references.js';
56
56
  export { referenceRedirectOf } from './reference-redirect.js';
57
- export { findServiceTsconfig, fileConfigPath } from './service-config.js';
57
+ export { findServiceTsconfig, GoverningConfigs } from './service-config.js';
58
58
  // carrick#2405: the per-position rows write through the guard, and name an
59
59
  // installed declaring file the way the capture's resolution walk does.
60
60
  export { WriteGuard } from './guarded-fs.js';
61
61
  export { installedPackageDirectory } from './installed-package-directory.js';
62
62
  export { isDeclarationFileName, packageNameOf } from './specifiers.js';
63
+ export { toPosix } from './installed-package.js';
64
+ export { constituentsOf } from './result-label.js';
63
65
  export { moduleExport } from './anchors.js';
64
66
  // v2 check core ("tsc as the judge"). Same bundle, same seam: the sidecar
65
67
  // reaches it only through this door (index.js).
@@ -1312,4 +1314,4 @@ function resolveAnchors(opts, parsed, ctx, deno, owner) {
1312
1314
  }
1313
1315
  // carrick#1841: the response-table reading the inferrer and the v1 bundle
1314
1316
  // share with the capture's symbol anchor.
1315
- export { classifyStatusCodes, constituents, httpStatus, statesNoBody, statesNoShape, statusKeyCode, statusTableBody, statusTableOf, successEntries, } from './status-table.js';
1317
+ export { classifyStatusCodes, httpStatus, statesNoBody, statesNoShape, statusKeyCode, statusTableBody, statusTableOf, successEntries, } from './status-table.js';
@@ -46,6 +46,7 @@ export interface InstalledPackageSpecifier {
46
46
  * deciding whether a runtime name is covered by a pinned types package.
47
47
  */
48
48
  export declare function typesPackageOf(name: string): string;
49
+ export declare function toPosix(p: string): string;
49
50
  /** A path or specifier without its script, source or declaration extension. */
50
51
  export declare function withoutExtension(subpath: string): string;
51
52
  /**
@@ -26,6 +26,7 @@ import * as fs from 'node:fs';
26
26
  import * as path from 'node:path';
27
27
  import { sidecarCompilerOptions } from './compiler-options.js';
28
28
  import { isPublishedSemver } from './lockfile.js';
29
+ import { packageNameOf } from './specifiers.js';
29
30
  const DECLARATION_SUFFIXES = ['', '.d.ts', '.d.mts', '.d.cts', '.ts', '.mts', '.cts', '/index.d.ts'];
30
31
  const RESOLUTION_OPTIONS = sidecarCompilerOptions({
31
32
  module: ts.ModuleKind.ESNext,
@@ -51,7 +52,7 @@ export function typesPackageOf(name) {
51
52
  const scoped = /^@([^/]+)\/(.+)$/.exec(name);
52
53
  return scoped ? `@types/${scoped[1]}__${scoped[2]}` : `@types/${name}`;
53
54
  }
54
- function toPosix(p) {
55
+ export function toPosix(p) {
55
56
  return p.split(path.sep).join('/');
56
57
  }
57
58
  function readManifest(dir) {
@@ -214,7 +215,7 @@ export function withInstalledPackages(options, installs, base = ts.createCompile
214
215
  : ts.resolveModuleName(name, containingFile, compilerOptions, base).resolvedModule;
215
216
  if (resolved || name.startsWith('.') || name.startsWith('/'))
216
217
  return resolved;
217
- const packageName = packageNameOfSpecifier(name);
218
+ const packageName = packageNameOf(name);
218
219
  for (const owner of [packageName, typesPackageOf(packageName)]) {
219
220
  const root = installs[owner];
220
221
  if (root) {
@@ -227,10 +228,6 @@ export function withInstalledPackages(options, installs, base = ts.createCompile
227
228
  });
228
229
  return base;
229
230
  }
230
- function packageNameOfSpecifier(spec) {
231
- const parts = spec.split('/');
232
- return spec.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
233
- }
234
231
  /** Entry subpaths of a package that a consumer can import. */
235
232
  function entrySubpaths(manifest) {
236
233
  const exportsField = manifest.exports;
@@ -15,7 +15,7 @@
15
15
  * A capture whose program stays inside rootDir is placed exactly as before.
16
16
  */
17
17
  import * as path from 'node:path';
18
- import { withoutExtension } from './installed-package.js';
18
+ import { toPosix, withoutExtension } from './installed-package.js';
19
19
  import { rewriteSpecifiers } from './specifiers.js';
20
20
  /** Tree directory holding declarations of sources outside rootDir. */
21
21
  export const OUTSIDE_DIR = '__outside__';
@@ -33,7 +33,7 @@ export function placeEmittedTree(args) {
33
33
  const outsideFiles = [];
34
34
  for (const fileName of args.emitted.keys()) {
35
35
  sourceSideOf.set(fileName, sourceSidePath(fileName, args.staging, args.entryDir));
36
- const rel = posix(path.relative(args.staging, fileName));
36
+ const rel = toPosix(path.relative(args.staging, fileName));
37
37
  if (escapes(rel)) {
38
38
  outsideFiles.push(fileName);
39
39
  continue;
@@ -45,7 +45,7 @@ export function placeEmittedTree(args) {
45
45
  return { relOf, textOf, outside, rewrites: 0 };
46
46
  const shared = commonDirectory([args.entryDir, ...outsideFiles.map((f) => path.dirname(path.resolve(f)))]);
47
47
  for (const fileName of outsideFiles) {
48
- const rel = path.posix.join(OUTSIDE_DIR, posix(path.relative(shared, path.resolve(fileName))));
48
+ const rel = path.posix.join(OUTSIDE_DIR, toPosix(path.relative(shared, path.resolve(fileName))));
49
49
  relOf.set(fileName, rel);
50
50
  outside.set(path.resolve(fileName).replace(DECLARATION_EXT, ''), rel);
51
51
  }
@@ -88,7 +88,7 @@ export function placeEmittedTree(args) {
88
88
  * source's own path.
89
89
  */
90
90
  function sourceSidePath(fileName, staging, entryDir) {
91
- const rel = posix(path.relative(staging, fileName));
91
+ const rel = toPosix(path.relative(staging, fileName));
92
92
  return escapes(rel) ? path.resolve(fileName) : path.join(entryDir, rel);
93
93
  }
94
94
  /**
@@ -119,9 +119,6 @@ export function surfaceModuleInTree(args) {
119
119
  return held.has(target) || held.has(path.join(target, 'index'));
120
120
  };
121
121
  }
122
- function posix(p) {
123
- return p.split(path.sep).join('/');
124
- }
125
122
  function escapes(rel) {
126
123
  return rel === '..' || rel.startsWith('../') || path.isAbsolute(rel);
127
124
  }
@@ -51,6 +51,12 @@ export declare class ProjectGraph {
51
51
  * reference closure lists it. The named config when none does.
52
52
  */
53
53
  ownerOf(file: string): ServiceProject;
54
+ /**
55
+ * `ownerOf` when some project in the graph lists `file`, the named config
56
+ * included; undefined when none does (carrick#3497: a config that lists a
57
+ * file nowhere is passed over for one further up).
58
+ */
59
+ listingOwnerOf(file: string): ServiceProject | undefined;
54
60
  /**
55
61
  * Every project `project` reaches through its references, transitively,
56
62
  * depth-first in declared order, without itself. Only projects this graph
@@ -68,9 +68,19 @@ export class ProjectGraph {
68
68
  ownerOf(file) {
69
69
  if (!this.hasReferences)
70
70
  return this.named;
71
+ return this.listingOwnerOf(file) ?? this.named;
72
+ }
73
+ /**
74
+ * `ownerOf` when some project in the graph lists `file`, the named config
75
+ * included; undefined when none does (carrick#3497: a config that lists a
76
+ * file nowhere is passed over for one further up).
77
+ */
78
+ listingOwnerOf(file) {
71
79
  const key = fileKey(file);
80
+ if (!this.hasReferences)
81
+ return this.namedFiles.has(key) ? this.named : undefined;
72
82
  const owner = this.projects().find((entry) => entry.files.has(key) && !this.closure(entry.project).some((reached) => reached.files.has(key)));
73
- return owner?.project ?? this.named;
83
+ return owner?.project;
74
84
  }
75
85
  /**
76
86
  * Every project `project` reaches through its references, transitively,
@@ -14,25 +14,55 @@
14
14
  * A service-root `jsconfig.json` ranks after those names and before an
15
15
  * ancestor `tsconfig.json` (carrick#3497): tsserver types a JavaScript file
16
16
  * under the jsconfig beside it, not under a config above. Where no ancestor
17
- * config exists the answer stays undefined, as before: the service is then
18
- * typed per file by `fileConfigPath`, which reads the same jsconfig.
17
+ * config exists the answer stays undefined, as before: each file is then
18
+ * typed by `GoverningConfigs` alone, which reads the same jsconfig.
19
19
  *
20
20
  * The walk stops at the scan root, inclusive: a config outside the scanned
21
21
  * tree is never read. With no scan root, or a service outside it, only the
22
22
  * service root is searched.
23
+ *
24
+ * The service config is the fallback of the per-file rule
25
+ * (`GoverningConfigs`, carrick#3497): a file a config inside the service
26
+ * lists is typed under that config.
23
27
  */
24
28
  /** Absolute path of the config that types the service, or undefined for none. */
25
29
  export declare function findServiceTsconfig(serviceRoot: string, scanRoot?: string): string | undefined;
26
30
  /** The path with every symlink resolved; the path as given when it does not exist. */
27
31
  export declare function realPath(p: string): string;
28
32
  /**
29
- * The config an editor types `file` under, for a service with none at its
30
- * root (carrick#1604): the nearest `tsconfig.json`, then `jsconfig.json`, in
31
- * each directory from the file's up to the service root, inclusive. The
32
- * climb stops after a directory named `node_modules`, as tsserver's does. A file
33
- * outside the service root, or with no config on its way up, has none.
33
+ * The config each file of one service is typed under (carrick#1604,
34
+ * carrick#3497 ruling R-N1): the one the TypeScript language service picks.
35
+ * From the file's directory up to the service root, inclusive, each directory's
36
+ * `tsconfig.json`, else `jsconfig.json`, is asked whether its program, or a
37
+ * project it references, lists the file; the first that does types it (a
38
+ * solution config hands the file to the reference that lists it). A config
39
+ * that lists the file nowhere is passed over. The climb stops after a
40
+ * directory named `node_modules`, as tsserver's does. A file no config inside
41
+ * the service lists falls back to the service config (`findServiceTsconfig`
42
+ * or the named one) and the project of its references that lists the file,
43
+ * else to that config itself; with no service config, to none.
34
44
  *
35
- * `known` caches the answer per directory; pass one map for one service so
36
- * its files share the climb.
45
+ * The scanner's `module_aliases::Governing` is the same rule, and
46
+ * `tests/module_resolution_parity_test.rs` holds both to the compiler's own
47
+ * answer.
37
48
  */
38
- export declare function fileConfigPath(file: string, serviceRoot: string, known?: Map<string, string | undefined>): string | undefined;
49
+ export declare class GoverningConfigs {
50
+ private readonly serviceConfig;
51
+ private readonly report;
52
+ private readonly root;
53
+ /** Directory -> the config in it, for every directory a climb visited. */
54
+ private readonly dirConfigs;
55
+ /** Config -> its projects; undefined for one that cannot be read. */
56
+ private readonly graphs;
57
+ /**
58
+ * @param serviceRoot the service directory
59
+ * @param serviceConfig the fallback config, absolute, or undefined for none
60
+ * @param report where a config or reference that cannot be read is named
61
+ */
62
+ constructor(serviceRoot: string, serviceConfig: string | undefined, report?: (diagnostic: string) => void);
63
+ /** Absolute path of the config that types `file`, or undefined for none. */
64
+ configFor(file: string): string | undefined;
65
+ private configIn;
66
+ /** The project reached from `config` that lists `file`, absolute. */
67
+ private listingOwner;
68
+ }
@@ -14,15 +14,20 @@
14
14
  * A service-root `jsconfig.json` ranks after those names and before an
15
15
  * ancestor `tsconfig.json` (carrick#3497): tsserver types a JavaScript file
16
16
  * under the jsconfig beside it, not under a config above. Where no ancestor
17
- * config exists the answer stays undefined, as before: the service is then
18
- * typed per file by `fileConfigPath`, which reads the same jsconfig.
17
+ * config exists the answer stays undefined, as before: each file is then
18
+ * typed by `GoverningConfigs` alone, which reads the same jsconfig.
19
19
  *
20
20
  * The walk stops at the scan root, inclusive: a config outside the scanned
21
21
  * tree is never read. With no scan root, or a service outside it, only the
22
22
  * service root is searched.
23
+ *
24
+ * The service config is the fallback of the per-file rule
25
+ * (`GoverningConfigs`, carrick#3497): a file a config inside the service
26
+ * lists is typed under that config.
23
27
  */
24
28
  import * as fs from 'node:fs';
25
29
  import * as path from 'node:path';
30
+ import { ProjectGraph } from './project-references.js';
26
31
  /** The names a service root is searched for, in order. */
27
32
  const SERVICE_ROOT_NAMES = ['tsconfig.json', 'tsconfig.build.json', 'tsconfig.app.json'];
28
33
  /** The root config tsserver types a JavaScript service under, after the names above. */
@@ -68,40 +73,85 @@ export function realPath(p) {
68
73
  /** The names an editor looks for in a file's directory, in order. */
69
74
  const FILE_CONFIG_NAMES = ['tsconfig.json', 'jsconfig.json'];
70
75
  /**
71
- * The config an editor types `file` under, for a service with none at its
72
- * root (carrick#1604): the nearest `tsconfig.json`, then `jsconfig.json`, in
73
- * each directory from the file's up to the service root, inclusive. The
74
- * climb stops after a directory named `node_modules`, as tsserver's does. A file
75
- * outside the service root, or with no config on its way up, has none.
76
+ * The config each file of one service is typed under (carrick#1604,
77
+ * carrick#3497 ruling R-N1): the one the TypeScript language service picks.
78
+ * From the file's directory up to the service root, inclusive, each directory's
79
+ * `tsconfig.json`, else `jsconfig.json`, is asked whether its program, or a
80
+ * project it references, lists the file; the first that does types it (a
81
+ * solution config hands the file to the reference that lists it). A config
82
+ * that lists the file nowhere is passed over. The climb stops after a
83
+ * directory named `node_modules`, as tsserver's does. A file no config inside
84
+ * the service lists falls back to the service config (`findServiceTsconfig`
85
+ * or the named one) and the project of its references that lists the file,
86
+ * else to that config itself; with no service config, to none.
76
87
  *
77
- * `known` caches the answer per directory; pass one map for one service so
78
- * its files share the climb.
88
+ * The scanner's `module_aliases::Governing` is the same rule, and
89
+ * `tests/module_resolution_parity_test.rs` holds both to the compiler's own
90
+ * answer.
79
91
  */
80
- export function fileConfigPath(file, serviceRoot, known = new Map()) {
81
- const root = path.resolve(serviceRoot);
82
- const climbed = [];
83
- let found;
84
- let dir = path.dirname(path.resolve(file));
85
- for (;;) {
86
- const from = path.relative(root, dir);
87
- if (from.startsWith('..') || path.isAbsolute(from))
88
- break;
89
- if (known.has(dir)) {
90
- found = known.get(dir);
91
- break;
92
+ export class GoverningConfigs {
93
+ serviceConfig;
94
+ report;
95
+ root;
96
+ /** Directory -> the config in it, for every directory a climb visited. */
97
+ dirConfigs = new Map();
98
+ /** Config -> its projects; undefined for one that cannot be read. */
99
+ graphs = new Map();
100
+ /**
101
+ * @param serviceRoot the service directory
102
+ * @param serviceConfig the fallback config, absolute, or undefined for none
103
+ * @param report where a config or reference that cannot be read is named
104
+ */
105
+ constructor(serviceRoot, serviceConfig, report = () => { }) {
106
+ this.serviceConfig = serviceConfig;
107
+ this.report = report;
108
+ this.root = path.resolve(serviceRoot);
109
+ }
110
+ /** Absolute path of the config that types `file`, or undefined for none. */
111
+ configFor(file) {
112
+ const absolute = path.resolve(file);
113
+ let dir = path.dirname(absolute);
114
+ for (;;) {
115
+ const from = path.relative(this.root, dir);
116
+ if (from.startsWith('..') || path.isAbsolute(from))
117
+ break;
118
+ const config = this.configIn(dir);
119
+ const owner = config === undefined ? undefined : this.listingOwner(config, absolute);
120
+ if (owner !== undefined)
121
+ return owner;
122
+ // tsserver looks in a `node_modules` directory itself, then stops.
123
+ if (dir === this.root || path.basename(dir) === 'node_modules')
124
+ break;
125
+ dir = path.dirname(dir);
92
126
  }
93
- climbed.push(dir);
94
- const name = FILE_CONFIG_NAMES.find((n) => fs.existsSync(path.join(dir, n)));
95
- if (name !== undefined) {
96
- found = path.join(dir, name);
97
- break;
127
+ if (this.serviceConfig === undefined)
128
+ return undefined;
129
+ return this.listingOwner(this.serviceConfig, absolute) ?? this.serviceConfig;
130
+ }
131
+ configIn(dir) {
132
+ if (!this.dirConfigs.has(dir)) {
133
+ const name = FILE_CONFIG_NAMES.find((n) => fs.existsSync(path.join(dir, n)));
134
+ this.dirConfigs.set(dir, name === undefined ? undefined : path.join(dir, name));
98
135
  }
99
- // tsserver looks in a `node_modules` directory itself, then stops.
100
- if (dir === root || path.basename(dir) === 'node_modules')
101
- break;
102
- dir = path.dirname(dir);
136
+ return this.dirConfigs.get(dir);
137
+ }
138
+ /** The project reached from `config` that lists `file`, absolute. */
139
+ listingOwner(config, file) {
140
+ if (!this.graphs.has(config)) {
141
+ try {
142
+ this.graphs.set(config, { graph: new ProjectGraph(config), reported: 0 });
143
+ }
144
+ catch (err) {
145
+ this.report(`tsconfig ${config} could not be read and was skipped: ${err instanceof Error ? err.message : String(err)}`);
146
+ this.graphs.set(config, undefined);
147
+ }
148
+ }
149
+ const entry = this.graphs.get(config);
150
+ if (entry === undefined)
151
+ return undefined;
152
+ const owner = entry.graph.listingOwnerOf(file);
153
+ entry.graph.diagnostics.slice(entry.reported).forEach(this.report);
154
+ entry.reported = entry.graph.diagnostics.length;
155
+ return owner?.configPath;
103
156
  }
104
- for (const d of climbed)
105
- known.set(d, found);
106
- return found;
107
157
  }
@@ -75,5 +75,3 @@ export declare function statusTableBody(checker: ts.TypeChecker, type: ts.Type,
75
75
  kind: 'no_body';
76
76
  entries: StatusTableEntry[];
77
77
  } | undefined;
78
- /** The members of a union, or the type itself: what a set comparison reads. */
79
- export declare function constituents(type: ts.Type): ts.Type[];
@@ -124,7 +124,3 @@ export function statusTableBody(checker, type, at) {
124
124
  }
125
125
  return { kind: 'body', entries: success, types };
126
126
  }
127
- /** The members of a union, or the type itself: what a set comparison reads. */
128
- export function constituents(type) {
129
- return type.isUnion() ? type.types : [type];
130
- }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The function body a call runs (carrick#3500). One answer for the helpers
3
+ * that ask it: a declaration that has a body is that body; an overloaded
4
+ * function is its one implementation (the signatures carry no body); a
5
+ * variable or property initialised with an arrow or function expression is
6
+ * that function, through the wrappers that leave a value as it is
7
+ * (parentheses, `as`, `<T>`, `!`, `satisfies`).
8
+ *
9
+ * A name with two bodies, or with none, has no one body and answers
10
+ * undefined.
11
+ */
12
+ import { Node, type ArrowFunction, type FunctionDeclaration, type FunctionExpression, type MethodDeclaration } from 'ts-morph';
13
+ export type PlainFunctionBody = FunctionDeclaration | ArrowFunction | FunctionExpression;
14
+ export type FunctionBody = PlainFunctionBody | MethodDeclaration;
15
+ /** An expression without the wrappers that leave its value as it is. */
16
+ export declare function peelValueWrappers(node: Node): Node;
17
+ /**
18
+ * The one function with a body among `declarations`, or undefined for none
19
+ * or several. `methods: false` leaves method declarations out.
20
+ */
21
+ export declare function functionBodyOf(declarations: readonly Node[], options: {
22
+ methods: false;
23
+ }): PlainFunctionBody | undefined;
24
+ export declare function functionBodyOf(declarations: readonly Node[], options?: {
25
+ methods?: boolean;
26
+ }): FunctionBody | undefined;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The function body a call runs (carrick#3500). One answer for the helpers
3
+ * that ask it: a declaration that has a body is that body; an overloaded
4
+ * function is its one implementation (the signatures carry no body); a
5
+ * variable or property initialised with an arrow or function expression is
6
+ * that function, through the wrappers that leave a value as it is
7
+ * (parentheses, `as`, `<T>`, `!`, `satisfies`).
8
+ *
9
+ * A name with two bodies, or with none, has no one body and answers
10
+ * undefined.
11
+ */
12
+ import { Node, } from 'ts-morph';
13
+ /** An expression without the wrappers that leave its value as it is. */
14
+ export function peelValueWrappers(node) {
15
+ let current = node;
16
+ while (Node.isParenthesizedExpression(current) ||
17
+ Node.isAsExpression(current) ||
18
+ Node.isTypeAssertion(current) ||
19
+ Node.isSatisfiesExpression(current) ||
20
+ Node.isNonNullExpression(current)) {
21
+ current = current.getExpression();
22
+ }
23
+ return current;
24
+ }
25
+ function bodyOfDeclaration(declaration, methods) {
26
+ if (Node.isFunctionDeclaration(declaration))
27
+ return declaration.getBody() ? declaration : undefined;
28
+ if (Node.isMethodDeclaration(declaration))
29
+ return methods && declaration.getBody() ? declaration : undefined;
30
+ if (Node.isArrowFunction(declaration) || Node.isFunctionExpression(declaration))
31
+ return declaration;
32
+ if (Node.isVariableDeclaration(declaration) || Node.isPropertyAssignment(declaration)) {
33
+ const initializer = declaration.getInitializer();
34
+ const value = initializer ? peelValueWrappers(initializer) : undefined;
35
+ if (value && (Node.isArrowFunction(value) || Node.isFunctionExpression(value)))
36
+ return value;
37
+ }
38
+ return undefined;
39
+ }
40
+ export function functionBodyOf(declarations, options = {}) {
41
+ const methods = options.methods ?? true;
42
+ const bodies = new Set();
43
+ for (const declaration of declarations) {
44
+ const body = bodyOfDeclaration(declaration, methods);
45
+ if (body)
46
+ bodies.add(body);
47
+ }
48
+ return bodies.size === 1 ? [...bodies][0] : undefined;
49
+ }
@@ -2487,10 +2487,12 @@ class DeclarationReader {
2487
2487
  */
2488
2488
  judgeOp(receiver, claim, rules) {
2489
2489
  // Amendment 7, part 3 (carrick#3047): the form says how the service
2490
- // writes the op, and the op kinds a form belongs to.
2490
+ // writes the op, and the op kinds a form belongs to. A `new` receive
2491
+ // subscribes when the export is constructed (carrick-cloud#3139).
2491
2492
  const form = claim.form ?? 'call';
2492
- if (form === 'new' && claim.op !== 'send' && claim.op !== 'request')
2493
+ if (form === 'new' && claim.op !== 'send' && claim.op !== 'request' && claim.op !== 'receive') {
2493
2494
  return unchecked('claim_invalid');
2495
+ }
2494
2496
  if (form === 'decorate' && claim.op !== 'receive')
2495
2497
  return unchecked('claim_invalid');
2496
2498
  // `returns` judges the handler a receive op registers.