Skip to content

Commit 8a9a6d1

Browse files
authored
refactor: replace deprecated tsconfck with get-tsconfig (#4367)
1 parent 57ad8fe commit 8a9a6d1

7 files changed

Lines changed: 35 additions & 87 deletions

File tree

docs/4.examples/vite-ssr-tss-react.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ icon: i-simple-icons-tanstack
3737
"@vitejs/plugin-react": "^6.0.1",
3838
"tailwindcss": "^4.2.2",
3939
"typescript": "^6.0.2",
40-
"vite": "latest",
41-
"vite-tsconfig-paths": "^6.1.1"
40+
"vite": "latest"
4241
}
4342
}
4443
```
@@ -71,17 +70,11 @@ import { defineConfig } from "vite";
7170
import { nitro } from "nitro/vite";
7271
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
7372
import viteReact from "@vitejs/plugin-react";
74-
import viteTsConfigPaths from "vite-tsconfig-paths";
7573
import tailwindcss from "@tailwindcss/vite";
7674

7775
export default defineConfig({
78-
plugins: [
79-
viteTsConfigPaths({ projects: ["./tsconfig.json"] }),
80-
tanstackStart(),
81-
viteReact(),
82-
tailwindcss(),
83-
nitro(),
84-
],
76+
plugins: [tanstackStart(), viteReact(), tailwindcss(), nitro()],
77+
resolve: { tsconfigPaths: true },
8578
environments: {
8679
ssr: { build: { rollupOptions: { input: "./server.ts" } } },
8780
},
@@ -315,24 +308,18 @@ import { defineConfig } from "vite";
315308
import { nitro } from "nitro/vite";
316309
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
317310
import viteReact from "@vitejs/plugin-react";
318-
import viteTsConfigPaths from "vite-tsconfig-paths";
319311
import tailwindcss from "@tailwindcss/vite";
320312

321313
export default defineConfig({
322-
plugins: [
323-
viteTsConfigPaths({ projects: ["./tsconfig.json"] }),
324-
tanstackStart(),
325-
viteReact(),
326-
tailwindcss(),
327-
nitro(),
328-
],
314+
plugins: [tanstackStart(), viteReact(), tailwindcss(), nitro()],
315+
resolve: { tsconfigPaths: true },
329316
environments: {
330317
ssr: { build: { rollupOptions: { input: "./server.ts" } } },
331318
},
332319
});
333320
```
334321

335-
The `tanstackStart()` plugin provides full SSR integration with automatic client entry handling. Use `viteTsConfigPaths()` to enable path aliases like `~/` from tsconfig. The `environments.ssr` option points to the server entry file.
322+
The `tanstackStart()` plugin provides full SSR integration with automatic client entry handling. The `environments.ssr` option points to the server entry file.
336323

337324
## 2. Create the Server Entry
338325

examples/vite-ssr-tss-react/README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,18 @@ import { defineConfig } from "vite";
1616
import { nitro } from "nitro/vite";
1717
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
1818
import viteReact from "@vitejs/plugin-react";
19-
import viteTsConfigPaths from "vite-tsconfig-paths";
2019
import tailwindcss from "@tailwindcss/vite";
2120

2221
export default defineConfig({
23-
plugins: [
24-
viteTsConfigPaths({ projects: ["./tsconfig.json"] }),
25-
tanstackStart(),
26-
viteReact(),
27-
tailwindcss(),
28-
nitro(),
29-
],
22+
plugins: [tanstackStart(), viteReact(), tailwindcss(), nitro()],
23+
resolve: { tsconfigPaths: true },
3024
environments: {
3125
ssr: { build: { rollupOptions: { input: "./server.ts" } } },
3226
},
3327
});
3428
```
3529

36-
The `tanstackStart()` plugin provides full SSR integration with automatic client entry handling. Use `viteTsConfigPaths()` to enable path aliases like `~/` from tsconfig. The `environments.ssr` option points to the server entry file.
30+
The `tanstackStart()` plugin provides full SSR integration with automatic client entry handling. The `environments.ssr` option points to the server entry file.
3731

3832
## 2. Create the Server Entry
3933

examples/vite-ssr-tss-react/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"@vitejs/plugin-react": "^6.0.1",
2424
"tailwindcss": "^4.2.2",
2525
"typescript": "^6.0.2",
26-
"vite": "latest",
27-
"vite-tsconfig-paths": "^6.1.1"
26+
"vite": "latest"
2827
}
2928
}

examples/vite-ssr-tss-react/vite.config.mjs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ import { defineConfig } from "vite";
22
import { nitro } from "nitro/vite";
33
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
44
import viteReact from "@vitejs/plugin-react";
5-
import viteTsConfigPaths from "vite-tsconfig-paths";
65
import tailwindcss from "@tailwindcss/vite";
76

87
export default defineConfig({
9-
plugins: [
10-
viteTsConfigPaths({ projects: ["./tsconfig.json"] }),
11-
tanstackStart(),
12-
viteReact(),
13-
tailwindcss(),
14-
nitro(),
15-
],
8+
plugins: [tanstackStart(), viteReact(), tailwindcss(), nitro()],
9+
resolve: { tsconfigPaths: true },
1610
environments: {
1711
ssr: { build: { rollupOptions: { input: "./server.ts" } } },
1812
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"expect-type": "^1.3.0",
131131
"exsolve": "^1.0.8",
132132
"get-port-please": "^3.2.0",
133+
"get-tsconfig": "^4.14.0",
133134
"giget": "^3.3.0",
134135
"gzip-size": "^7.0.0",
135136
"httpxy": "^0.5.3",
@@ -159,7 +160,6 @@
159160
"source-map": "^0.7.6",
160161
"std-env": "^4.1.0",
161162
"tinyglobby": "^0.2.17",
162-
"tsconfck": "^3.1.6",
163163
"typescript": "^6.0.3",
164164
"ufo": "^1.6.4",
165165
"ultrahtml": "^1.6.0",

pnpm-lock.yaml

Lines changed: 10 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/resolvers/tsconfig.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import type { NitroOptions } from "nitro/types";
22
import type { TSConfig } from "pkg-types";
33
import { join, resolve } from "pathe";
4-
import * as tsco from "tsconfck";
4+
import { parseTsconfig } from "get-tsconfig";
5+
6+
const tsconfigCache = new Map<string, any>();
57

68
export async function resolveTsconfig(options: NitroOptions) {
79
const root = resolve(options.rootDir || ".") + "/";
810
if (!options.typescript.tsConfig) {
9-
options.typescript.tsConfig = await loadTsconfig(root);
11+
options.typescript.tsConfig = loadTsconfig(root);
1012
}
1113
}
1214

13-
async function loadTsconfig(root: string): Promise<TSConfig> {
14-
const opts: tsco.TSConfckParseOptions = {
15-
root,
16-
cache: ((loadTsconfig as any)["__cache"] ??= new tsco.TSConfckCache()),
17-
ignoreNodeModules: true,
18-
};
15+
function loadTsconfig(root: string): TSConfig {
1916
const tsConfigPath = join(root, "tsconfig.json");
20-
const parsed = await tsco.parse(tsConfigPath, opts).catch(() => undefined);
21-
if (!parsed) return {} as TSConfig;
22-
const { tsconfig, tsconfigFile } = parsed;
17+
let tsconfig: TSConfig;
18+
try {
19+
tsconfig = parseTsconfig(tsConfigPath, tsconfigCache) as TSConfig;
20+
} catch {
21+
return {} as TSConfig;
22+
}
2323
tsconfig.compilerOptions ??= {};
2424
if (!tsconfig.compilerOptions.baseUrl) {
25-
tsconfig.compilerOptions.baseUrl = resolve(tsconfigFile, "..");
25+
tsconfig.compilerOptions.baseUrl = resolve(tsConfigPath, "..");
2626
}
2727
return tsconfig;
2828
}

0 commit comments

Comments
 (0)