1
- import type { TBabelCore , TBabelJest , TTypeScript , TEsBuild } from '../types'
1
+ import type { TBabelCore , TBabelJest , TEsBuild , TTypeScript } from '../types'
2
2
3
3
import { rootLogger } from './logger'
4
4
import { Memoize } from './memoize'
5
5
import { Errors , Helps , ImportReasons , interpolate } from './messages'
6
6
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- type ModulePatcher < T = any > = ( module : T ) => T
9
-
10
7
const logger = rootLogger . child ( { namespace : 'Importer' } )
11
8
12
9
// When adding an optional dependency which has another reason, add the reason in ImportReasons, and
@@ -26,14 +23,9 @@ export class Importer {
26
23
static get instance ( ) : Importer {
27
24
logger . debug ( 'creating Importer singleton' )
28
25
29
- // here we can define patches to apply to modules.
30
- // it could be fixes that are not deployed, or
31
- // abstractions so that multiple versions work the same
32
26
return new Importer ( )
33
27
}
34
28
35
- constructor ( protected _patches : { [ moduleName : string ] : ModulePatcher [ ] } = { } ) { }
36
-
37
29
babelJest ( why : ImportReasons ) : TBabelJest {
38
30
return this . _import ( why , 'babel-jest' )
39
31
}
@@ -66,13 +58,10 @@ export class Importer {
66
58
if ( req . exists ) {
67
59
// module exists
68
60
loaded = req as RequireResult < true >
69
- if ( loaded . error ) {
70
- // require-ing it failed
71
- logger . error ( { requireResult : contextReq } , `failed loading module '${ name } '` , loaded . error . message )
61
+ if ( req . error ) {
62
+ logger . error ( { requireResult : contextReq } , `failed loading module '${ name } '` , req . error . message )
72
63
} else {
73
- // it has been loaded, let's patch it
74
64
logger . debug ( { requireResult : contextReq } , 'loaded module' , name )
75
- loaded . exports = this . _patch ( name , loaded . exports )
76
65
}
77
66
break
78
67
} else {
@@ -99,17 +88,6 @@ export class Importer {
99
88
throw result . error
100
89
}
101
90
102
- @Memoize ( ( name ) => name )
103
- protected _patch < T > ( name : string , unpatched : T ) : T {
104
- if ( name in this . _patches ) {
105
- logger . debug ( 'patching' , name )
106
-
107
- return this . _patches [ name ] . reduce ( ( mod , patcher ) => patcher ( mod ) , unpatched )
108
- }
109
-
110
- return unpatched
111
- }
112
-
113
91
protected _import < T > (
114
92
why : string ,
115
93
moduleName : string ,
0 commit comments