Skip to content

Commit 51db8f4

Browse files
authored
fix: warn when using both isolatedModules and emitDecoratorMetadata (#3029)
See angular/angular-cli@6a19c21
1 parent 9f2951e commit 51db8f4

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

Diff for: src/compiler/ng-jest-compiler.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'node:os';
22
import path from 'node:path';
33

44
import { type TsJestAstTransformer, TsCompiler, type ConfigSet } from 'ts-jest';
5-
import type ts from 'typescript';
5+
import ts from 'typescript';
66

77
import { angularJitApplicationTransform } from '../transformers/jit_transform';
88
import { replaceResources } from '../transformers/replace-resources';
@@ -24,22 +24,29 @@ export class NgJestCompiler extends TsCompiler {
2424
const compilerOptions = { ...this._compilerOptions };
2525
const options: ts.CompilerOptions = compilerOptions
2626
? // @ts-expect-error internal TypeScript API
27-
this._ts.fixupCompilerOptions(compilerOptions, diagnostics)
27+
ts.fixupCompilerOptions(compilerOptions, diagnostics)
2828
: {};
2929

3030
// mix in default options
31-
const defaultOptions = this._ts.getDefaultCompilerOptions();
31+
const defaultOptions = ts.getDefaultCompilerOptions();
3232
for (const key in defaultOptions) {
3333
if (Object.prototype.hasOwnProperty.call(defaultOptions, key) && options[key] === undefined) {
3434
options[key] = defaultOptions[key];
3535
}
3636
}
3737

3838
// @ts-expect-error internal TypeScript API
39-
for (const option of this._ts.transpileOptionValueCompilerOptions) {
39+
for (const option of ts.transpileOptionValueCompilerOptions) {
4040
options[option.name] = option.transpileOptionValue;
4141
}
4242

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+
4350
/**
4451
* transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between
4552
* input and output paths.
@@ -49,11 +56,7 @@ export class NgJestCompiler extends TsCompiler {
4956
// Filename can be non-ts file.
5057
options.allowNonTsExtensions = true;
5158

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);
5760

5861
let outputText: string | undefined;
5962
let sourceMapText: string | undefined;
@@ -82,7 +85,7 @@ export class NgJestCompiler extends TsCompiler {
8285
getDirectories: () => [],
8386
};
8487

85-
this.program = this._ts.createProgram([filePath], options, compilerHost);
88+
this.program = ts.createProgram([filePath], options, compilerHost);
8689
this.program.emit(
8790
undefined,
8891
undefined,
@@ -97,17 +100,16 @@ export class NgJestCompiler extends TsCompiler {
97100
protected _makeTransformers(customTransformers: TsJestAstTransformer): ts.CustomTransformers {
98101
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
99102
const program = this.program!;
103+
const transformerFactories = super._makeTransformers(customTransformers);
100104

101105
return {
102-
...super._makeTransformers(customTransformers).after,
103-
...super._makeTransformers(customTransformers).afterDeclarations,
106+
...transformerFactories.after,
107+
...transformerFactories.afterDeclarations,
104108
before: [
105-
...customTransformers.before.map((beforeTransformer) =>
106-
beforeTransformer.factory(this, beforeTransformer.options),
107-
),
109+
...(transformerFactories.before ?? []),
108110
replaceResources(program),
109111
angularJitApplicationTransform(program),
110-
] as Array<ts.TransformerFactory<ts.SourceFile> | ts.CustomTransformerFactory>,
112+
],
111113
};
112114
}
113115
}

0 commit comments

Comments
 (0)