@rpc-dart/trpc-adapter 0.1.3 → 0.1.4

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/extract.js CHANGED
@@ -23,10 +23,8 @@ export async function extractContract(options) {
23
23
  });
24
24
  throw new ExtractionFailure(diagnostics);
25
25
  }
26
- // 2. Virtual harness over the public inference utilities, one alias pair per path.
27
- const harnessPath = path.join(tsconfigDir, harnessFileName());
28
- const harnessSource = buildHarness(entryImportPath(tsconfigDir, entryAbsolute), options.exportName, probePaths.map((p) => p.path));
29
- // 3. Program under the user's own tsconfig, harness overlaid in memory.
26
+ // 2. Program options from the user's own tsconfig (parsed before the harness
27
+ // is built so Node16/NodeNext resolution can shape the entry specifier).
30
28
  const configFile = ts.readConfigFile(options.tsconfigPath, ts.sys.readFile);
31
29
  if (configFile.error) {
32
30
  diagnostics.push({
@@ -39,11 +37,38 @@ export async function extractContract(options) {
39
37
  throw new ExtractionFailure(diagnostics);
40
38
  }
41
39
  const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, tsconfigDir);
42
- const baseHost = ts.createCompilerHost(parsed.options, true);
40
+ // 3. Virtual harness over the public inference utilities, one alias pair per path.
41
+ const resolution = parsed.options.moduleResolution === ts.ModuleResolutionKind.Node16
42
+ ? 'node16'
43
+ : parsed.options.moduleResolution === ts.ModuleResolutionKind.NodeNext
44
+ ? 'nodenext'
45
+ : undefined;
46
+ const harnessPath = path.join(tsconfigDir, harnessFileName());
47
+ const harnessSource = buildHarness(entryImportPath(tsconfigDir, entryAbsolute, resolution), options.exportName, probePaths.map((p) => p.path));
48
+ // 4. Program under the user's own tsconfig, harness overlaid in memory.
49
+ // Extraction-neutral overrides: the in-memory program exists only to
50
+ // answer type queries on the harness, so build/lint-only flags are
51
+ // neutralized regardless of the user's tsconfig — they would otherwise
52
+ // reject the synthetic harness (rootDir, composite emit rules) or surface
53
+ // lint-only semantic errors (noUnusedLocals/noUnusedParameters,
54
+ // isolatedDeclarations) that have nothing to do with contract extraction.
55
+ const extractionOptions = {
56
+ ...parsed.options,
57
+ noEmit: true,
58
+ declaration: false,
59
+ declarationMap: false,
60
+ composite: false,
61
+ incremental: false,
62
+ isolatedDeclarations: false,
63
+ noUnusedLocals: false,
64
+ noUnusedParameters: false,
65
+ rootDir: undefined,
66
+ };
67
+ const baseHost = ts.createCompilerHost(extractionOptions, true);
43
68
  const host = overlayHost(baseHost, harnessPath, harnessSource);
44
69
  const program = ts.createProgram({
45
70
  rootNames: [harnessPath, ...parsed.fileNames],
46
- options: parsed.options,
71
+ options: extractionOptions,
47
72
  host,
48
73
  });
49
74
  const harnessSf = program.getSourceFile(harnessPath);
package/dist/harness.d.ts CHANGED
@@ -8,5 +8,10 @@
8
8
  export declare function harnessFileName(): string;
9
9
  export declare function pathAlias(path: string, role: 'in' | 'out'): string;
10
10
  export declare function buildHarness(entryImportPath: string, exportName: string, paths: string[]): string;
11
- /** './router.ts' -> './router' (extensionless relative import for the harness). */
12
- export declare function entryImportPath(tsconfigDir: string, entryAbsolute: string): string;
11
+ /**
12
+ * './router.ts' -> './router' (bundler-style), or explicit extensions under
13
+ * node16/nodenext resolution, where extensionless relative imports are
14
+ * illegal (TS5097) and the TS-standard specifiers (.js/.mjs/.cjs) resolve to
15
+ * the .ts/.mts/.cts sources with or without allowImportingTsExtensions.
16
+ */
17
+ export declare function entryImportPath(tsconfigDir: string, entryAbsolute: string, resolution?: 'node16' | 'nodenext'): string;
package/dist/harness.js CHANGED
@@ -32,9 +32,21 @@ export type __rpc_dart_outputs = inferRouterOutputs<__rpc_dart_router>;
32
32
  ${aliases}
33
33
  `;
34
34
  }
35
- /** './router.ts' -> './router' (extensionless relative import for the harness). */
36
- export function entryImportPath(tsconfigDir, entryAbsolute) {
37
- const rel = relative(tsconfigDir, entryAbsolute).replace(/\.ts$/, '');
38
- return rel.startsWith('.') ? rel : `./${rel}`;
35
+ /**
36
+ * './router.ts' -> './router' (bundler-style), or explicit extensions under
37
+ * node16/nodenext resolution, where extensionless relative imports are
38
+ * illegal (TS5097) and the TS-standard specifiers (.js/.mjs/.cjs) resolve to
39
+ * the .ts/.mts/.cts sources with or without allowImportingTsExtensions.
40
+ */
41
+ export function entryImportPath(tsconfigDir, entryAbsolute, resolution) {
42
+ const rel = relative(tsconfigDir, entryAbsolute);
43
+ const specifier = resolution === undefined
44
+ ? rel.replace(/\.(mts|cts|tsx?)$/, '')
45
+ : rel
46
+ .replace(/\.tsx$/, '.js')
47
+ .replace(/\.mts$/, '.mjs')
48
+ .replace(/\.cts$/, '.cjs')
49
+ .replace(/\.ts$/, '.js');
50
+ return specifier.startsWith('.') ? specifier : `./${specifier}`;
39
51
  }
40
52
  import { relative } from 'node:path';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpc-dart/trpc-adapter",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "tRPC v11 extraction adapter: route probe, inference harness, and Contract IR normalizer.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,7 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "dependencies": {
12
- "@rpc-dart/core": "0.1.3",
12
+ "@rpc-dart/core": "0.1.4",
13
13
  "jiti": "^2.6.0",
14
14
  "typescript": "^5.9.0"
15
15
  },