Skip to content

Commit 8d5df4f

Browse files
committed
refactor(typescript): wire the testmu provider into the reference graph
Rebase overlap with #3118: provider-testmu entered the workspace as the 26th package after this branch's lists were derived. It gets the same treatment as every other package - manifest-derived references and a per-project tsBuildInfoFile - plus entries in the root and examples/sdk reference lists, which the guard test now proves complete again. Its dependency on the root agent-device package is the first edge that has no composite project to point at: the root tsconfig is a noEmit entry point and TS6310 forbids referencing it, so that import type-resolves through the package's own paths mapping. The guard test encodes exactly that: root-named workspace deps drop out of the references equality and must instead have a paths mapping, or the test fails.
1 parent 21556a2 commit 8d5df4f

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎examples/sdk/tsconfig.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
{ "path": "../../packages/platform-vega" },
5151
{ "path": "../../packages/platform-web" },
5252
{ "path": "../../packages/provider-limrun" },
53+
{ "path": "../../packages/provider-testmu" },
5354
{ "path": "../../packages/provider-webdriver" },
5455
{ "path": "../../packages/provision-kit" },
5556
{ "path": "../../packages/proxy" },

‎packages/provider-testmu/tsconfig.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
"emitDeclarationOnly": true,
77
"declaration": true,
88
"declarationDir": "./dist-types",
9+
"tsBuildInfoFile": "./dist-types/.tsbuildinfo",
910
"rootDir": "./src",
1011
"paths": {
1112
"agent-device/plugins": ["./node_modules/agent-device/src/sdk/plugins.ts"],
1213
"agent-device/plugins/webdriver": ["./node_modules/agent-device/src/sdk/plugin-webdriver.ts"]
1314
}
1415
},
15-
"include": ["src"]
16+
"include": ["src"],
17+
"references": [
18+
{ "path": "../contracts" },
19+
{ "path": "../kernel" },
20+
{ "path": "../provider-webdriver" }
21+
]
1622
}

‎scripts/layering/project-references.test.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,24 @@ import { readWorkspacePackages } from './package-boundaries.ts';
1515
const repoRoot = path.resolve(import.meta.dirname, '../..');
1616

1717
/** tsconfig JSONC minus line comments; both comment-bearing files use `//` only. */
18-
function readTsconfig(relativePath: string): { references?: { path: string }[] } {
18+
function readTsconfig(relativePath: string): {
19+
references?: { path: string }[];
20+
extends?: string;
21+
compilerOptions?: Record<string, unknown>;
22+
} {
1923
const source = fs.readFileSync(path.join(repoRoot, relativePath), 'utf8');
2024
return JSON.parse(source.replaceAll(/^\s*\/\/.*$/gm, ''));
2125
}
2226

27+
/**
28+
* The published root package name. It names no composite project: the root tsconfig is a
29+
* noEmit entry point TS6310 forbids referencing, so a workspace dependency on it is
30+
* type-resolved through tsconfig `paths`, never through a reference edge.
31+
*/
32+
const rootPackageName = (
33+
JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8')) as { name: string }
34+
).name;
35+
2336
/** Repo-relative package dir for one `references[].path` entry, resolved from its project. */
2437
function referencedPackageDirs(tsconfigFile: string, projectDir: string): string[] {
2538
const config = readTsconfig(tsconfigFile);
@@ -86,6 +99,10 @@ test('every package tsconfig references exactly its manifest workspace dependenc
8699
// references are DERIVED from the manifest DAG, so an import a manifest gains must add the
87100
// matching reference (edge freshness, which tsc -b never asks for) and a removed one must
88101
// drop it (an extra reference hides a stale edge that tsc -b tolerates silently).
102+
// The one expressible-edge exception: a workspace dependency on the ROOT package
103+
// (`agent-device`) has no composite project to point at (TS6310). Those imports are
104+
// type-resolved through tsconfig `paths`, so the dependency is asserted present in
105+
// paths instead of references.
89106
const packages = readWorkspacePackages(repoRoot);
90107
const nameByDir = new Map(packages.map((pkg) => [pkg.dir, pkg.name]));
91108
for (const pkg of packages) {
@@ -98,8 +115,17 @@ test('every package tsconfig references exactly its manifest workspace dependenc
98115
}
99116
assert.deepEqual(
100117
referencedDirs.map((dir) => nameByDir.get(dir)),
101-
[...pkg.workspaceDependencies].sort(),
118+
[...pkg.workspaceDependencies].filter((name) => name !== rootPackageName).sort(),
102119
`${pkg.dir}/tsconfig.json references must equal its manifest workspace:* dependencies`,
103120
);
121+
if (pkg.workspaceDependencies.has(rootPackageName)) {
122+
const config = readTsconfig(`${pkg.dir}/tsconfig.json`);
123+
const paths = (config.compilerOptions?.paths ?? {}) as Record<string, unknown>;
124+
assert.ok(
125+
Object.keys(paths).some((key) => key.startsWith(`${rootPackageName}/`)),
126+
`${pkg.dir} depends on the root package without a paths mapping; tsc cannot ` +
127+
'resolve it (the root project cannot be referenced)',
128+
);
129+
}
104130
}
105131
});

0 commit comments

Comments
 (0)