@@ -6,13 +6,24 @@ import * as interpret from 'interpret';
6
6
import { template } from 'lodash' ;
7
7
import * as rechoir from 'rechoir' ;
8
8
9
- // eslint-disable-next-line n/no-missing-import
10
- import { dynamicImportMaybe } from '../../helper/dynamic-import.js' ;
9
+ import { dynamicImportMaybe } from '../../helper/dynamic-import' ;
11
10
12
11
import { runMutatingHook } from './hook' ;
13
12
import PluginInterface from './plugin-interface' ;
14
13
import { readRawPackageJson } from './read-package-json' ;
15
14
15
+ /* eslint-disable @typescript-eslint/no-require-imports */
16
+ // TSX imports only work with Node16 resolution while we're still on CommonJS resolution in tsconfig.base.json
17
+ // However, all of Vite's entire TS types break when using CommonJS with Node16 resolution, it's more approachable
18
+ // to use `require` directly for the time being.
19
+ const tsxCJS = require ( 'tsx/cjs/api' ) ;
20
+ const tsxESM = require ( 'tsx/esm/api' ) ;
21
+ /* eslint-enable @typescript-eslint/no-require-imports */
22
+
23
+ // Register tsx enhancements
24
+ const unregisterCJS = tsxCJS . register ( ) ;
25
+ const unregisterESM = tsxESM . register ( ) ;
26
+
16
27
const underscoreCase = ( str : string ) =>
17
28
str
18
29
. replace ( / ( .) ( [ A - Z ] [ a - z ] + ) / g, '$1_$2' )
@@ -130,7 +141,7 @@ export default async (dir: string): Promise<ResolvedForgeConfig> => {
130
141
}
131
142
132
143
if ( ! forgeConfig || typeof forgeConfig === 'string' ) {
133
- for ( const extension of [ '.js' , ...Object . keys ( interpret . extensions ) ] ) {
144
+ for ( const extension of [ '.js' , ...Object . keys ( interpret . extensions ) . filter ( ( ext ) => ext !== '.ts' ) ] ) {
134
145
const pathToConfig = path . resolve ( dir , `forge.config${ extension } ` ) ;
135
146
if ( await fs . pathExists ( pathToConfig ) ) {
136
147
rechoir . prepare ( interpret . extensions , pathToConfig , dir ) ;
@@ -176,5 +187,8 @@ export default async (dir: string): Promise<ResolvedForgeConfig> => {
176
187
177
188
resolvedForgeConfig = await runMutatingHook ( resolvedForgeConfig , 'resolveForgeConfig' , resolvedForgeConfig ) ;
178
189
190
+ unregisterCJS ( ) ;
191
+ unregisterESM ( ) ;
192
+
179
193
return proxify < ResolvedForgeConfig > ( resolvedForgeConfig . buildIdentifier || '' , resolvedForgeConfig , 'ELECTRON_FORGE' ) ;
180
194
} ;
0 commit comments