@smoothbricks/nx-plugin 0.7.15 → 0.7.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +15 -0
  2. package/dist/.build-inputs.json +10 -7
  3. package/dist/compile-environment.d.ts +8 -0
  4. package/dist/compile-environment.d.ts.map +1 -0
  5. package/dist/compile-environment.js +80 -0
  6. package/dist/dependency-manifests.d.ts +13 -0
  7. package/dist/dependency-manifests.d.ts.map +1 -0
  8. package/dist/dependency-manifests.js +20 -0
  9. package/dist/executors/bounded-exec/child-exit-diagnostics.d.ts +45 -0
  10. package/dist/executors/bounded-exec/child-exit-diagnostics.d.ts.map +1 -0
  11. package/dist/executors/bounded-exec/child-exit-diagnostics.js +188 -0
  12. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  13. package/dist/executors/bounded-exec/executor.js +10 -1
  14. package/dist/executors/bounded-exec/host-memory.d.ts +11 -0
  15. package/dist/executors/bounded-exec/host-memory.d.ts.map +1 -1
  16. package/dist/executors/bounded-exec/host-memory.darwin.d.ts.map +1 -1
  17. package/dist/executors/bounded-exec/host-memory.darwin.js +1 -0
  18. package/dist/executors/bounded-exec/host-memory.linux.d.ts +3 -1
  19. package/dist/executors/bounded-exec/host-memory.linux.d.ts.map +1 -1
  20. package/dist/executors/bounded-exec/host-memory.linux.js +16 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +17 -8
  23. package/dist/managed-files/files.d.ts +3 -3
  24. package/dist/managed-files/files.js +3 -3
  25. package/dist/typecheck-route.d.ts +3 -4
  26. package/dist/typecheck-route.d.ts.map +1 -1
  27. package/dist/typecheck-route.js +4 -15
  28. package/managed/raw/patches/{ttsc@0.34.1.patch → ttsc@0.36.3.patch} +728 -71
  29. package/managed/raw/tooling/direnv/devenv.smoo.nix +1 -1
  30. package/package.json +9 -4
  31. package/src/compile-environment.ts +35 -0
  32. package/src/dependency-manifests.ts +30 -0
  33. package/src/executors/bounded-exec/child-exit-diagnostics.ts +87 -0
  34. package/src/executors/bounded-exec/executor.ts +10 -1
  35. package/src/executors/bounded-exec/host-memory.darwin.ts +1 -0
  36. package/src/executors/bounded-exec/host-memory.linux.ts +25 -2
  37. package/src/executors/bounded-exec/host-memory.ts +7 -0
  38. package/src/index.ts +17 -8
  39. package/src/managed-files/files.ts +3 -3
  40. package/src/typecheck-route.ts +5 -14
  41. package/test-timings.json +138 -137
@@ -348,7 +348,7 @@ in {
348
348
  # comment that rots.
349
349
  #
350
350
  # It needs its own input because the fleet's nixpkgs does not carry that patch:
351
- # devenv-nixpkgs rolling has no Go 1.27, while ttsc 0.34.1 vendors go1.27.3.
351
+ # devenv-nixpkgs rolling has no Go 1.27, while ttsc 0.36.3 vendors go1.27.3.
352
352
  # Same idiom, and same reason, for any single-package pin — one leaf package
353
353
  # from a nixpkgs that has it, lock-pinned, prebuilt, rather than a fleet-wide
354
354
  # bump that would move rustc, bun and node too. Not every pairing is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.7.15",
3
+ "version": "0.7.17",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -33,6 +33,11 @@
33
33
  "import": "./dist/bounded-test-policy.js",
34
34
  "default": "./dist/bounded-test-policy.js"
35
35
  },
36
+ "./bounded-exec-diagnostics": {
37
+ "types": "./dist/executors/bounded-exec/child-exit-diagnostics.d.ts",
38
+ "import": "./dist/executors/bounded-exec/child-exit-diagnostics.js",
39
+ "default": "./dist/executors/bounded-exec/child-exit-diagnostics.js"
40
+ },
36
41
  "./test-results": {
37
42
  "types": "./dist/executors/bounded-exec/test-results.d.ts",
38
43
  "import": "./dist/executors/bounded-exec/test-results.js",
@@ -656,7 +661,7 @@
656
661
  "@nx/js": "24.0.3",
657
662
  "@smoothbricks/build-inputs": "0.0.3",
658
663
  "@smoothbricks/cargo-retain": "0.0.2",
659
- "@smoothbricks/cowshed": "0.4.9",
664
+ "@smoothbricks/cowshed": "0.5.1",
660
665
  "@smoothbricks/nextest-extract": "0.0.2",
661
666
  "jsonc-parser": "^3.3.1",
662
667
  "minimatch": "10.2.5",
@@ -669,8 +674,8 @@
669
674
  "yaml": "^2.9.0"
670
675
  },
671
676
  "devDependencies": {
672
- "@smoothbricks/lmao": "0.6.1",
673
- "@smoothbricks/validation": "0.1.13",
677
+ "@smoothbricks/lmao": "0.6.2",
678
+ "@smoothbricks/validation": "0.1.14",
674
679
  "fast-check": "^4.4.0"
675
680
  }
676
681
  }
@@ -0,0 +1,35 @@
1
+ import typia from 'typia';
2
+ import type { DependencyManifest } from './dependency-manifests.js';
3
+
4
+ /**
5
+ * What a package whose ttsc plugin lowers by environment variables declares in its manifest, as `smoo.compileEnv`:
6
+ * the variables the plugin's output depends on. `@smoothbricks/lmao-ttsc` declares `NODE_ENV`, which decides whether
7
+ * trace statements compile away (specs/lmao/01o_typescript_transformer.md §6.3). Every project that depends on such a
8
+ * package directly compiles through its plugin, so each target whose output is that compile hashes the variables.
9
+ */
10
+ interface DeclaringManifest {
11
+ readonly smoo?: { readonly compileEnv?: readonly string[] };
12
+ }
13
+
14
+ const validateManifest = typia.createValidate<DeclaringManifest>();
15
+
16
+ /**
17
+ * The environment variables a project's transformed output depends on, over its direct dependencies' manifests, once
18
+ * each in declaration order. A manifest that declares `smoo.compileEnv` in another shape refuses the inference by its
19
+ * path and the field it got wrong.
20
+ */
21
+ export function compileEnvironment(manifests: readonly DependencyManifest[]): string[] {
22
+ const names: string[] = [];
23
+ for (const manifest of manifests) {
24
+ const checked = validateManifest(manifest.json);
25
+ if (!checked.success) {
26
+ throw new Error(
27
+ `${manifest.path}: smoo.compileEnv must be ['<VARIABLE>', ...]: ${checked.errors
28
+ .map((error) => `${error.path} expected ${error.expected}`)
29
+ .join('; ')}`,
30
+ );
31
+ }
32
+ for (const name of checked.data.smoo?.compileEnv ?? []) if (!names.includes(name)) names.push(name);
33
+ }
34
+ return names;
35
+ }
@@ -0,0 +1,30 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { join } from 'node:path';
4
+
5
+ /** One installed direct dependency's manifest: its package name, where it is, and its parsed JSON. */
6
+ export interface DependencyManifest {
7
+ readonly name: string;
8
+ readonly path: string;
9
+ readonly json: unknown;
10
+ }
11
+
12
+ /**
13
+ * The manifests of a project's direct dependencies, the ones ttsc discovers plugins on (`dependencies` and
14
+ * `devDependencies`), once per name. Each is the manifest Node resolution reaches from the project, as ttsc reads it;
15
+ * a dependency that is not installed has none. Read once per project, for every declaration inference reads from them.
16
+ */
17
+ export function directDependencyManifests(
18
+ packageJsonPath: string,
19
+ dependencies: readonly string[],
20
+ ): DependencyManifest[] {
21
+ const lookup = createRequire(packageJsonPath);
22
+ const manifests: DependencyManifest[] = [];
23
+ for (const name of new Set(dependencies)) {
24
+ const path = (lookup.resolve.paths(name) ?? [])
25
+ .map((root) => join(root, ...name.split('/'), 'package.json'))
26
+ .find((candidate) => existsSync(candidate));
27
+ if (path !== undefined) manifests.push({ name, path, json: JSON.parse(readFileSync(path, 'utf-8')) });
28
+ }
29
+ return manifests;
30
+ }
@@ -0,0 +1,87 @@
1
+ import typia from 'typia';
2
+ import {
3
+ HOST_MEMORY,
4
+ type LiveUsageReading,
5
+ type ResidentUsageReading,
6
+ type RunMemoryReading,
7
+ readLiveUsage,
8
+ readRunMemory,
9
+ } from './host-memory.js';
10
+
11
+ /** Diagnostic facts, not configuration: neither value changes a grant or a runner's parallelism. */
12
+ export const DIAGNOSTIC_CONTEXT_ENV = 'BOUNDED_EXEC_MEMORY_DIAGNOSTICS';
13
+ export const DIAGNOSTIC_MODULE_ENV = 'BOUNDED_EXEC_DIAGNOSTICS_MODULE';
14
+
15
+ interface GrantMemoryContext {
16
+ readonly chargedBytes: number;
17
+ readonly bound: RunMemoryReading;
18
+ }
19
+ const parseContext = typia.json.createAssertParse<GrantMemoryContext>();
20
+
21
+ /** A sub-pool charges no memory: descendants retain the memory-bearing ancestor's facts. */
22
+ export async function grantMemoryEnvironment(
23
+ chargedBytes: number | null,
24
+ inherited: Readonly<NodeJS.ProcessEnv>,
25
+ readMemory: () => Promise<RunMemoryReading> = readRunMemory,
26
+ ): Promise<Record<string, string>> {
27
+ if (chargedBytes === null) {
28
+ return {
29
+ [DIAGNOSTIC_CONTEXT_ENV]: inherited[DIAGNOSTIC_CONTEXT_ENV] ?? '',
30
+ [DIAGNOSTIC_MODULE_ENV]: inherited[DIAGNOSTIC_MODULE_ENV] ?? '',
31
+ };
32
+ }
33
+ const context: GrantMemoryContext = { chargedBytes, bound: await readMemory() };
34
+ return { [DIAGNOSTIC_CONTEXT_ENV]: JSON.stringify(context), [DIAGNOSTIC_MODULE_ENV]: import.meta.url };
35
+ }
36
+
37
+ export interface ResidentSample {
38
+ readonly sampledAtMs: number;
39
+ readonly reading: ResidentUsageReading;
40
+ }
41
+
42
+ /** The original grant plus the bound's live reading at exit, never a new accounting ledger. */
43
+ export function childExitMemory(
44
+ contextText: string | undefined,
45
+ lastResident: ResidentSample,
46
+ readLive: (bound: string) => LiveUsageReading = readLiveUsage,
47
+ ) {
48
+ if (!contextText)
49
+ return { lastResident, pool: { ok: false as const, reason: 'no memory-bearing CPU grant was inherited' } };
50
+ let context: GrantMemoryContext;
51
+ try {
52
+ context = parseContext(contextText);
53
+ } catch (error) {
54
+ return {
55
+ lastResident,
56
+ pool: {
57
+ ok: false as const,
58
+ reason: `invalid inherited memory diagnostic: ${error instanceof Error ? error.message : String(error)}`,
59
+ },
60
+ };
61
+ }
62
+ const live: LiveUsageReading = context.bound.ok
63
+ ? readLive(context.bound.memory.source)
64
+ : { ok: false, reason: `${context.bound.error.subject}: ${context.bound.error.cause}` };
65
+ return { lastResident, pool: { ok: true as const, ...context, live } };
66
+ }
67
+
68
+ /** Retains the last readable sample through PID exit; stop is called by the child's exit event. */
69
+ export function observeChildMemory(pid: number, contextText: string | undefined) {
70
+ const sample = (): ResidentSample => ({
71
+ sampledAtMs: Date.now(),
72
+ reading: HOST_MEMORY?.residentUsage(pid) ?? {
73
+ ok: false,
74
+ reason: `${process.platform} has no per-process RSS reader`,
75
+ },
76
+ });
77
+ let lastResident = sample();
78
+ const timer = setInterval(() => {
79
+ const next = sample();
80
+ if (next.reading.ok || !lastResident.reading.ok) lastResident = next;
81
+ }, 250);
82
+ timer.unref();
83
+ return () => {
84
+ clearInterval(timer);
85
+ return childExitMemory(contextText, lastResident);
86
+ };
87
+ }
@@ -15,6 +15,7 @@ import {
15
15
  } from '../../process-group.js';
16
16
  import { AdmissionObservation, type QueueHost } from './admission-queue.js';
17
17
  import { type BoundEvent, type BoundKind, type Bounds, earliestBound, stepBounds, UNARMED } from './bounds.js';
18
+ import { DIAGNOSTIC_CONTEXT_ENV, DIAGNOSTIC_MODULE_ENV, grantMemoryEnvironment } from './child-exit-diagnostics.js';
18
19
  import { type CpuPool, createCpuPool } from './cpu-pool.js';
19
20
  import { GATEWAY_SOCKET } from './gateway-lease.js';
20
21
  import type { HangDiagnostics } from './hang-diagnostics.js';
@@ -94,7 +95,14 @@ const POOL_ENV = [CPU_TOKENS_ENV, CPU_POOL_ENV];
94
95
  * itself inherits, a parent make's or its cowshed job's, still reaches an ungranted command by Cargo's own rule; a
95
96
  * granted one's sub-pool names its own fifo over it.
96
97
  */
97
- const BUDGET_ENV = [...POOL_ENV, 'CARGO_MAKEFLAGS', 'MAKEFLAGS', 'MFLAGS'];
98
+ const BUDGET_ENV = [
99
+ ...POOL_ENV,
100
+ 'CARGO_MAKEFLAGS',
101
+ 'MAKEFLAGS',
102
+ 'MFLAGS',
103
+ DIAGNOSTIC_CONTEXT_ENV,
104
+ DIAGNOSTIC_MODULE_ENV,
105
+ ];
98
106
 
99
107
  export interface BoundedExecContext {
100
108
  root: string;
@@ -730,6 +738,7 @@ async function runCommand(
730
738
  ...sized.env,
731
739
  ...native.env,
732
740
  ...(pool?.environment ?? {}),
741
+ ...(await grantMemoryEnvironment(grant?.charged ?? null, process.env)),
733
742
  ...(leaf?.kind === 'cargo' ? { MBX_GRANT_FD: String(MBX_GRANT_FD) } : {}),
734
743
  };
735
744
  // A fixture rides as segment 0 of the lifecycle. Without the channel (Windows) it is plain shell text ahead
@@ -136,6 +136,7 @@ export const darwinMemory: HostMemory = {
136
136
  readRunMemory,
137
137
  peakBytes: (maxRss) => maxRss,
138
138
  treeResidentBytes,
139
+ residentUsage: () => ({ ok: false, reason: 'Node has no macOS per-process RSS reader' }),
139
140
  // macOS has no cgroup, and its anonymous and shared pages are not read from a file the pool may open.
140
141
  liveUsage: () => ({ ok: false, reason: 'macOS keeps no anonymous and shared memory of a run to read' }),
141
142
  };
@@ -2,7 +2,14 @@ import { readFileSync } from 'node:fs';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { posix } from 'node:path';
4
4
  import { childPids } from '../../process-children.linux.js';
5
- import type { HostMemory, LiveUsageReading, RunMemory, RunMemoryError, RunMemoryReading } from './host-memory.js';
5
+ import type {
6
+ HostMemory,
7
+ LiveUsageReading,
8
+ ResidentUsageReading,
9
+ RunMemory,
10
+ RunMemoryError,
11
+ RunMemoryReading,
12
+ } from './host-memory.js';
6
13
 
7
14
  /**
8
15
  * Linux's memory mechanisms. The run's memory is the least of the host's `MemTotal` and every finite `memory.max` of
@@ -175,13 +182,29 @@ async function residentBytes(pid: number): Promise<number> {
175
182
  if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ESRCH')) return 0;
176
183
  throw error;
177
184
  }
178
- const kib = /^VmRSS:\s+(\d+) kB$/m.exec(status)?.[1];
185
+ const kib = residentKib(status);
179
186
  return kib === undefined ? 0 : Number(kib) * 1024;
180
187
  }
181
188
 
189
+ function residentKib(status: string): string | undefined {
190
+ return /^VmRSS:\s+(\d+) kB$/m.exec(status)?.[1];
191
+ }
192
+
193
+ /** The same VmRSS field the peak waiter reads, without turning an unreadable or exited PID into zero. */
194
+ export function linuxResidentUsage(read: (path: string) => FileRead, pid: number): ResidentUsageReading {
195
+ const source = `/proc/${pid}/status`;
196
+ const status = read(source);
197
+ if (!status.ok) return { ok: false, reason: `${source}: ${status.code}: ${status.message}` };
198
+ const kib = residentKib(status.text);
199
+ return kib === undefined
200
+ ? { ok: false, reason: `${source} names no VmRSS in kB` }
201
+ : { ok: true, bytes: Number(kib) * 1024, source };
202
+ }
203
+
182
204
  export const linuxMemory: HostMemory = {
183
205
  readRunMemory: () => linuxRunMemory(readText),
184
206
  peakBytes,
185
207
  treeResidentBytes,
208
+ residentUsage: (pid) => linuxResidentUsage(readTextSync, pid),
186
209
  liveUsage: (bound) => linuxLiveUsage(readTextSync, bound),
187
210
  };
@@ -9,6 +9,8 @@ import { linuxMemory } from './host-memory.linux.js';
9
9
  export interface HostMemory {
10
10
  /** The memory the run's pool charges its leaves' peaks against. */
11
11
  readRunMemory(): Promise<RunMemoryReading>;
12
+ /** One process's resident set for an exit diagnostic; unavailable is never a zero RSS sample. */
13
+ residentUsage(pid: number): ResidentUsageReading;
12
14
  /**
13
15
  * A leaf's peak in bytes, from the `maxRSS` that Bun's `Subprocess.resourceUsage()` on `bunVersion` reports for
14
16
  * it: the exited leaf's `ru_maxrss`.
@@ -41,6 +43,11 @@ export type LiveUsageReading =
41
43
  | { readonly ok: true; readonly usage: LiveUsage }
42
44
  | { readonly ok: false; readonly reason: string };
43
45
 
46
+ /** A process's resident bytes and source, or why no sample could be read. */
47
+ export type ResidentUsageReading =
48
+ | { readonly ok: true; readonly bytes: number; readonly source: string }
49
+ | { readonly ok: false; readonly reason: string };
50
+
44
51
  /** The run's memory in bytes, and where it was read: the file or sysctl that holds it. */
45
52
  export interface RunMemory {
46
53
  readonly bytes: number;
package/src/index.ts CHANGED
@@ -63,6 +63,7 @@ import {
63
63
  type SerialTestGroup,
64
64
  serialTestGroups,
65
65
  } from './cargo-workspace.js';
66
+ import { compileEnvironment } from './compile-environment.js';
66
67
  import {
67
68
  CARGO_CROSS_LINT_COMMAND,
68
69
  CARGO_CROSS_LINT_TARGET,
@@ -75,6 +76,7 @@ import {
75
76
  cargoFrozen,
76
77
  runsFrozenCargo,
77
78
  } from './cross-check-policy.js';
79
+ import { type DependencyManifest, directDependencyManifests } from './dependency-manifests.js';
78
80
  import { eslintConfigClosure } from './eslint-config-closure.js';
79
81
  import type { EslintFileSet } from './eslint-file-set.js';
80
82
  import { ESLINT_SOURCES_GLOB, eslintSources } from './eslint-sources.js';
@@ -160,11 +162,8 @@ interface TypecheckTargets {
160
162
  * which bun.lock and the patches in its check inputs already key, and it waits for the targets the declaring package
161
163
  * names to prepare the plugin binaries ttsc loads. Every other project runs the pinned native compiler.
162
164
  */
163
- function typecheckTargets(packageJsonPath: string, packageJson: PackageJson): TypecheckTargets {
164
- const route = typecheckRoute(packageJsonPath, [
165
- ...Object.keys(packageJson.dependencies ?? {}),
166
- ...Object.keys(packageJson.devDependencies ?? {}),
167
- ]);
165
+ function typecheckTargets(manifests: readonly DependencyManifest[]): TypecheckTargets {
166
+ const route = typecheckRoute(manifests);
168
167
  return route.declaredBy.length === 0
169
168
  ? { command: typecheckCommand, inputs: [TYPECHECK_COMPILER_INPUT], dependsOn: [] }
170
169
  : { command: (args) => `ttsc ${args}`, inputs: [], dependsOn: route.dependsOn };
@@ -1625,7 +1624,14 @@ async function createProjectTargets(
1625
1624
  const projectRoot = dirname(packageJsonPath);
1626
1625
  const absoluteProjectRoot = join(workspaceRoot, projectRoot);
1627
1626
  const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
1628
- const typecheck = typecheckTargets(join(workspaceRoot, packageJsonPath), packageJson);
1627
+ const dependencyManifests = directDependencyManifests(join(workspaceRoot, packageJsonPath), [
1628
+ ...Object.keys(packageJson.dependencies ?? {}),
1629
+ ...Object.keys(packageJson.devDependencies ?? {}),
1630
+ ]);
1631
+ const typecheck = typecheckTargets(dependencyManifests);
1632
+ // The environment a direct dependency's ttsc plugin lowers by (compile-environment.ts): the emitted JavaScript is a
1633
+ // function of it, so every target whose output is the transformed compile hashes it. A check never is.
1634
+ const compileEnvInputs = compileEnvironment(dependencyManifests).map((name) => ({ env: name }));
1629
1635
  const projectName = packageJson.nx?.name ?? packageJson.name;
1630
1636
  if (typeof projectName !== 'string' || projectName.length === 0) {
1631
1637
  throw new Error(`${packageJsonPath} must declare a non-empty package or nx project name`);
@@ -1726,7 +1732,7 @@ async function createProjectTargets(
1726
1732
  targets['tsc-js'] = {
1727
1733
  executor: '@smoothbricks/nx-plugin:typescript-emit',
1728
1734
  cache: true,
1729
- inputs: ['production', '^production', ...toolchainInputs, '{projectRoot}/tsconfig.lib.json'],
1735
+ inputs: ['production', '^production', ...toolchainInputs, ...compileEnvInputs, '{projectRoot}/tsconfig.lib.json'],
1730
1736
  outputs: inferTypescriptOutputs(libOutDir),
1731
1737
  dependsOn: ['^*-js', ...(cargoWasmConfig ? ['cargo-wasm'] : [])],
1732
1738
  options: {
@@ -1754,7 +1760,10 @@ async function createProjectTargets(
1754
1760
  };
1755
1761
  Object.assign(
1756
1762
  targets,
1757
- scriptcPlatformTargets(packageJson, packageJsonPath, projectRoot, libTsconfigPath, toolchainInputs),
1763
+ scriptcPlatformTargets(packageJson, packageJsonPath, projectRoot, libTsconfigPath, [
1764
+ ...toolchainInputs,
1765
+ ...compileEnvInputs,
1766
+ ]),
1758
1767
  );
1759
1768
  }
1760
1769
 
@@ -72,9 +72,9 @@ export interface ManagedFileContext {
72
72
 
73
73
  /** Temporary upstream compiler repairs distributed to smoo-managed Bun workspaces. */
74
74
  export const managedTtscPatch = {
75
- version: '0.34.1',
76
- key: 'ttsc@0.34.1',
77
- path: 'patches/ttsc@0.34.1.patch',
75
+ version: '0.36.3',
76
+ key: 'ttsc@0.36.3',
77
+ path: 'patches/ttsc@0.36.3.patch',
78
78
  } as const;
79
79
 
80
80
  /** Maintained Nx 24.0.3 repairs, applied as an ordinary Bun patchedDependency over the registry release. */
@@ -1,7 +1,5 @@
1
- import { existsSync, readFileSync } from 'node:fs';
2
- import { createRequire } from 'node:module';
3
- import { join } from 'node:path';
4
1
  import typia from 'typia';
2
+ import type { DependencyManifest } from './dependency-manifests.js';
5
3
 
6
4
  /**
7
5
  * What a package whose ttsc plugin lowers a dialect declares in its manifest, as `smoo.typecheck`: every project that
@@ -33,21 +31,14 @@ export interface TypecheckRoute {
33
31
  }
34
32
 
35
33
  /**
36
- * The typecheck route of the project whose manifest is `packageJsonPath`, over its direct dependencies (the ones ttsc
37
- * discovers plugins on: `dependencies` and `devDependencies`). Each dependency's manifest is the one Node resolution
38
- * reaches from the project, as ttsc reads it; a dependency that is not installed declares nothing. A manifest that
34
+ * The typecheck route of a project over its direct dependencies' manifests (dependency-manifests.ts). A manifest that
39
35
  * declares `smoo.typecheck` in another shape refuses the inference by its path and the field it got wrong.
40
36
  */
41
- export function typecheckRoute(packageJsonPath: string, dependencies: readonly string[]): TypecheckRoute {
37
+ export function typecheckRoute(manifests: readonly DependencyManifest[]): TypecheckRoute {
42
38
  const declaredBy: string[] = [];
43
39
  const dependsOn: string[] = [];
44
- const lookup = createRequire(packageJsonPath);
45
- for (const name of new Set(dependencies)) {
46
- const manifest = (lookup.resolve.paths(name) ?? [])
47
- .map((root) => join(root, ...name.split('/'), 'package.json'))
48
- .find((candidate) => existsSync(candidate));
49
- if (manifest === undefined) continue;
50
- const checked = validateManifest(JSON.parse(readFileSync(manifest, 'utf-8')));
40
+ for (const { name, path: manifest, json } of manifests) {
41
+ const checked = validateManifest(json);
51
42
  if (!checked.success) {
52
43
  throw new Error(
53
44
  `${manifest}: smoo.typecheck must be { compiler: 'ttsc', dependsOn: ['<project>:<target>', ...] }: ${checked.errors