@@ -2,7 +2,7 @@ import os from 'node:os';
2
2
import path from 'node:path' ;
3
3
4
4
import { type TsJestAstTransformer , TsCompiler , type ConfigSet } from 'ts-jest' ;
5
- import type ts from 'typescript' ;
5
+ import ts from 'typescript' ;
6
6
7
7
import { angularJitApplicationTransform } from '../transformers/jit_transform' ;
8
8
import { replaceResources } from '../transformers/replace-resources' ;
@@ -24,22 +24,29 @@ export class NgJestCompiler extends TsCompiler {
24
24
const compilerOptions = { ...this . _compilerOptions } ;
25
25
const options : ts . CompilerOptions = compilerOptions
26
26
? // @ts -expect-error internal TypeScript API
27
- this . _ts . fixupCompilerOptions ( compilerOptions , diagnostics )
27
+ ts . fixupCompilerOptions ( compilerOptions , diagnostics )
28
28
: { } ;
29
29
30
30
// mix in default options
31
- const defaultOptions = this . _ts . getDefaultCompilerOptions ( ) ;
31
+ const defaultOptions = ts . getDefaultCompilerOptions ( ) ;
32
32
for ( const key in defaultOptions ) {
33
33
if ( Object . prototype . hasOwnProperty . call ( defaultOptions , key ) && options [ key ] === undefined ) {
34
34
options [ key ] = defaultOptions [ key ] ;
35
35
}
36
36
}
37
37
38
38
// @ts -expect-error internal TypeScript API
39
- for ( const option of this . _ts . transpileOptionValueCompilerOptions ) {
39
+ for ( const option of ts . transpileOptionValueCompilerOptions ) {
40
40
options [ option . name ] = option . transpileOptionValue ;
41
41
}
42
42
43
+ if ( options . isolatedModules && options . emitDecoratorMetadata ) {
44
+ this . _logger . warn ( `
45
+ TypeScript compiler option 'isolatedModules' may prevent the 'emitDecoratorMetadata' option from emitting all metadata.
46
+ The 'emitDecoratorMetadata' option is not required by Angular and can be removed if not explicitly required by the project.'
47
+ ` ) ;
48
+ }
49
+
43
50
/**
44
51
* transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between
45
52
* input and output paths.
@@ -49,11 +56,7 @@ export class NgJestCompiler extends TsCompiler {
49
56
// Filename can be non-ts file.
50
57
options . allowNonTsExtensions = true ;
51
58
52
- const sourceFile = this . _ts . createSourceFile (
53
- filePath ,
54
- fileContent ,
55
- options . target ?? this . _ts . ScriptTarget . Latest ,
56
- ) ;
59
+ const sourceFile = ts . createSourceFile ( filePath , fileContent , options . target ?? ts . ScriptTarget . Latest ) ;
57
60
58
61
let outputText : string | undefined ;
59
62
let sourceMapText : string | undefined ;
@@ -82,7 +85,7 @@ export class NgJestCompiler extends TsCompiler {
82
85
getDirectories : ( ) => [ ] ,
83
86
} ;
84
87
85
- this . program = this . _ts . createProgram ( [ filePath ] , options , compilerHost ) ;
88
+ this . program = ts . createProgram ( [ filePath ] , options , compilerHost ) ;
86
89
this . program . emit (
87
90
undefined ,
88
91
undefined ,
@@ -97,17 +100,16 @@ export class NgJestCompiler extends TsCompiler {
97
100
protected _makeTransformers ( customTransformers : TsJestAstTransformer ) : ts . CustomTransformers {
98
101
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
99
102
const program = this . program ! ;
103
+ const transformerFactories = super . _makeTransformers ( customTransformers ) ;
100
104
101
105
return {
102
- ...super . _makeTransformers ( customTransformers ) . after ,
103
- ...super . _makeTransformers ( customTransformers ) . afterDeclarations ,
106
+ ...transformerFactories . after ,
107
+ ...transformerFactories . afterDeclarations ,
104
108
before : [
105
- ...customTransformers . before . map ( ( beforeTransformer ) =>
106
- beforeTransformer . factory ( this , beforeTransformer . options ) ,
107
- ) ,
109
+ ...( transformerFactories . before ?? [ ] ) ,
108
110
replaceResources ( program ) ,
109
111
angularJitApplicationTransform ( program ) ,
110
- ] as Array < ts . TransformerFactory < ts . SourceFile > | ts . CustomTransformerFactory > ,
112
+ ] ,
111
113
} ;
112
114
}
113
115
}
0 commit comments