1+ import { dirname } from "node:path" ;
12import { BuildExtension } from "@trigger.dev/core/v3/build" ;
23import { readFile } from "node:fs/promises" ;
34import typescriptPkg from "typescript" ;
45
5- const { transpileModule, ModuleKind } = typescriptPkg ;
6+ const { transpileModule, ModuleKind, findConfigFile , readConfigFile , parseJsonConfigFileContent , sys } = typescriptPkg ;
67
78const 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 : / \. t s $ / } , 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+
0 commit comments