Skip to content

Commit f0a875e

Browse files
author
Rahul Chaudhary
committed
fix: replace tsconfck with native typescript config parsing
1 parent df964ea commit f0a875e

4 files changed

Lines changed: 35 additions & 31 deletions

File tree

.changeset/afraid-bags-pretend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/build": patch
3+
---
4+
5+
Remove deprecated tsconfck dependency and replace with native typescript compiler api to resolve typescript 6 peer dependency installation issues

packages/build/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@
8282
"mlly": "^1.7.1",
8383
"pkg-types": "^1.1.3",
8484
"resolve": "^1.22.8",
85-
"tinyglobby": "^0.2.2",
86-
"tsconfck": "3.1.3"
85+
"tinyglobby": "^0.2.2"
8786
},
8887
"devDependencies": {
8988
"@arethetypeswrong/cli": "^0.15.4",

packages/build/src/extensions/typescript.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { dirname } from "node:path";
12
import { BuildExtension } from "@trigger.dev/core/v3/build";
23
import { readFile } from "node:fs/promises";
34
import typescriptPkg from "typescript";
45

5-
const { transpileModule, ModuleKind } = typescriptPkg;
6+
const { transpileModule, ModuleKind, findConfigFile, readConfigFile, parseJsonConfigFileContent, sys } = typescriptPkg;
67

78
const decoratorMatcher = new RegExp(/((?<![(\s]\s*['"])@\w[.[\]\w\d]*\s*(?![;])[((?=\s)])/);
89

@@ -13,27 +14,42 @@ export function emitDecoratorMetadata(): BuildExtension {
1314
context.registerPlugin({
1415
name: "emitDecoratorMetadata",
1516
async setup(build) {
16-
const { parseNative, TSConfckCache } = await import("tsconfck");
17-
const cache = new TSConfckCache<any>();
17+
const configCache = new Map<string, any>();
1818

1919
build.onLoad({ filter: /\.ts$/ }, async (args) => {
2020
context.logger.debug("emitDecoratorMetadata onLoad", { args });
2121

22-
const { tsconfigFile, tsconfig } = await parseNative(args.path, {
23-
ignoreNodeModules: true,
24-
cache,
25-
});
22+
const searchPath = dirname(args.path);
23+
const tsconfigFile = findConfigFile(searchPath, sys.fileExists, "tsconfig.json");
2624

27-
context.logger.debug("emitDecoratorMetadata parsed native tsconfig", {
28-
tsconfig,
25+
context.logger.debug("emitDecoratorMetadata resolved tsconfig file", {
2926
tsconfigFile,
3027
args,
3128
});
3229

33-
if (tsconfig.compilerOptions?.emitDecoratorMetadata !== true) {
30+
let compilerOptions: any = {};
31+
32+
if (tsconfigFile) {
33+
if (configCache.has(tsconfigFile)) {
34+
compilerOptions = configCache.get(tsconfigFile);
35+
} else {
36+
const configFile = readConfigFile(tsconfigFile, sys.readFile);
37+
if (configFile.config) {
38+
const parsedConfig = parseJsonConfigFileContent(
39+
configFile.config,
40+
sys,
41+
dirname(tsconfigFile)
42+
);
43+
compilerOptions = parsedConfig.options || {};
44+
}
45+
configCache.set(tsconfigFile, compilerOptions);
46+
}
47+
}
48+
49+
if (compilerOptions.emitDecoratorMetadata !== true) {
3450
context.logger.debug("emitDecoratorMetadata skipping", {
3551
args,
36-
tsconfig,
52+
compilerOptions,
3753
});
3854

3955
return undefined;
@@ -55,7 +71,7 @@ export function emitDecoratorMetadata(): BuildExtension {
5571
const program = transpileModule(ts, {
5672
fileName: args.path,
5773
compilerOptions: {
58-
...tsconfig.compilerOptions,
74+
...compilerOptions,
5975
module: ModuleKind.ES2022,
6076
},
6177
});
@@ -67,3 +83,4 @@ export function emitDecoratorMetadata(): BuildExtension {
6783
},
6884
};
6985
}
86+

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)