@depup/ts-jest 29.4.6-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.lintstagedrc +4 -0
  2. package/.ts-jest-digest +1 -0
  3. package/CHANGELOG.md +2025 -0
  4. package/CONTRIBUTING.md +121 -0
  5. package/LICENSE.md +21 -0
  6. package/README.md +33 -0
  7. package/TROUBLESHOOTING.md +3 -0
  8. package/changes.json +18 -0
  9. package/cli.js +3 -0
  10. package/dist/cli/config/init.d.ts +6 -0
  11. package/dist/cli/config/init.js +139 -0
  12. package/dist/cli/config/migrate.d.ts +1 -0
  13. package/dist/cli/config/migrate.js +177 -0
  14. package/dist/cli/help.d.ts +1 -0
  15. package/dist/cli/help.js +25 -0
  16. package/dist/cli/helpers/presets.d.ts +1 -0
  17. package/dist/cli/helpers/presets.js +41 -0
  18. package/dist/cli/index.d.ts +1 -0
  19. package/dist/cli/index.js +63 -0
  20. package/dist/config/index.d.ts +2 -0
  21. package/dist/config/index.js +18 -0
  22. package/dist/config/paths-to-module-name-mapper.d.ts +9 -0
  23. package/dist/config/paths-to-module-name-mapper.js +52 -0
  24. package/dist/config/types.d.ts +2 -0
  25. package/dist/config/types.js +2 -0
  26. package/dist/constants.d.ts +13 -0
  27. package/dist/constants.js +22 -0
  28. package/dist/index.d.ts +15 -0
  29. package/dist/index.js +31 -0
  30. package/dist/legacy/compiler/compiler-utils.d.ts +8 -0
  31. package/dist/legacy/compiler/compiler-utils.js +32 -0
  32. package/dist/legacy/compiler/index.d.ts +2 -0
  33. package/dist/legacy/compiler/index.js +18 -0
  34. package/dist/legacy/compiler/ts-compiler.d.ts +27 -0
  35. package/dist/legacy/compiler/ts-compiler.js +434 -0
  36. package/dist/legacy/compiler/ts-jest-compiler.d.ts +8 -0
  37. package/dist/legacy/compiler/ts-jest-compiler.js +18 -0
  38. package/dist/legacy/config/config-set.d.ts +36 -0
  39. package/dist/legacy/config/config-set.js +622 -0
  40. package/dist/legacy/index.d.ts +6 -0
  41. package/dist/legacy/index.js +6 -0
  42. package/dist/legacy/ts-jest-transformer.d.ts +28 -0
  43. package/dist/legacy/ts-jest-transformer.js +293 -0
  44. package/dist/presets/all-presets.d.ts +15 -0
  45. package/dist/presets/all-presets.js +42 -0
  46. package/dist/presets/create-jest-preset.d.ts +18 -0
  47. package/dist/presets/create-jest-preset.js +180 -0
  48. package/dist/raw-compiler-options.d.ts +556 -0
  49. package/dist/raw-compiler-options.js +2 -0
  50. package/dist/transformers/hoist-jest.d.ts +9 -0
  51. package/dist/transformers/hoist-jest.js +111 -0
  52. package/dist/transpilers/typescript/transpile-module.d.ts +8 -0
  53. package/dist/transpilers/typescript/transpile-module.js +174 -0
  54. package/dist/types.d.ts +282 -0
  55. package/dist/types.js +3 -0
  56. package/dist/utils/backports.d.ts +1 -0
  57. package/dist/utils/backports.js +118 -0
  58. package/dist/utils/diagnostics.d.ts +5 -0
  59. package/dist/utils/diagnostics.js +8 -0
  60. package/dist/utils/get-package-version.d.ts +1 -0
  61. package/dist/utils/get-package-version.js +14 -0
  62. package/dist/utils/importer.d.ts +1 -0
  63. package/dist/utils/importer.js +146 -0
  64. package/dist/utils/index.d.ts +4 -0
  65. package/dist/utils/index.js +20 -0
  66. package/dist/utils/json.d.ts +2 -0
  67. package/dist/utils/json.js +16 -0
  68. package/dist/utils/jsonable-value.d.ts +10 -0
  69. package/dist/utils/jsonable-value.js +29 -0
  70. package/dist/utils/logger.d.ts +1 -0
  71. package/dist/utils/logger.js +20 -0
  72. package/dist/utils/memoize.d.ts +1 -0
  73. package/dist/utils/memoize.js +60 -0
  74. package/dist/utils/messages.d.ts +1 -0
  75. package/dist/utils/messages.js +21 -0
  76. package/dist/utils/normalize-slashes.d.ts +1 -0
  77. package/dist/utils/normalize-slashes.js +9 -0
  78. package/dist/utils/sha1.d.ts +1 -0
  79. package/dist/utils/sha1.js +38 -0
  80. package/dist/utils/ts-error.d.ts +1 -0
  81. package/dist/utils/ts-error.js +37 -0
  82. package/jest-preset.js +1 -0
  83. package/legacy.js +1 -0
  84. package/package.json +167 -0
  85. package/preprocessor.js +7 -0
  86. package/presets/default/jest-preset.js +1 -0
  87. package/presets/default-esm/jest-preset.js +1 -0
  88. package/presets/default-esm-legacy/jest-preset.js +1 -0
  89. package/presets/default-legacy/jest-preset.js +1 -0
  90. package/presets/index.d.ts +3 -0
  91. package/presets/index.js +3 -0
  92. package/presets/js-with-babel/jest-preset.js +1 -0
  93. package/presets/js-with-babel-esm/jest-preset.js +1 -0
  94. package/presets/js-with-babel-esm-legacy/jest-preset.js +1 -0
  95. package/presets/js-with-babel-legacy/jest-preset.js +1 -0
  96. package/presets/js-with-ts/jest-preset.js +1 -0
  97. package/presets/js-with-ts-esm/jest-preset.js +1 -0
  98. package/presets/js-with-ts-esm-legacy/jest-preset.js +1 -0
  99. package/presets/js-with-ts-legacy/jest-preset.js +1 -0
  100. package/tsconfig.base.json +20 -0
@@ -0,0 +1,8 @@
1
+ import ts from 'typescript';
2
+ type ExtendedTranspileOptions = Omit<ts.TranspileOptions, 'transformers'> & {
3
+ transformers?: (program: ts.Program) => ts.CustomTransformers;
4
+ };
5
+ type ExtendedTsTranspileModuleFn = (fileContent: string, transpileOptions: ExtendedTranspileOptions) => ts.TranspileOutput;
6
+ export declare const isModernNodeModuleKind: (module: ts.ModuleKind | undefined) => boolean;
7
+ export declare const tsTranspileModule: ExtendedTsTranspileModuleFn;
8
+ export {};
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.tsTranspileModule = exports.isModernNodeModuleKind = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const typescript_1 = __importDefault(require("typescript"));
9
+ const utils_1 = require("../../utils");
10
+ const barebonesLibContent = `/// <reference no-default-lib="true"/>
11
+ interface Boolean {}
12
+ interface Function {}
13
+ interface CallableFunction {}
14
+ interface NewableFunction {}
15
+ interface IArguments {}
16
+ interface Number {}
17
+ interface Object {}
18
+ interface RegExp {}
19
+ interface String {}
20
+ interface Array<T> { length: number; [n: number]: T; }
21
+ interface SymbolConstructor {
22
+ (desc?: string | number): symbol;
23
+ for(name: string): symbol;
24
+ readonly toStringTag: symbol;
25
+ }
26
+ declare var Symbol: SymbolConstructor;
27
+ interface Symbol {
28
+ readonly [Symbol.toStringTag]: string;
29
+ }`;
30
+ const barebonesLibName = 'lib.d.ts';
31
+ let barebonesLibSourceFile;
32
+ const carriageReturnLineFeed = '\r\n';
33
+ const lineFeed = '\n';
34
+ function getNewLineCharacter(options) {
35
+ switch (options.newLine) {
36
+ case typescript_1.default.NewLineKind.CarriageReturnLineFeed:
37
+ return carriageReturnLineFeed;
38
+ case typescript_1.default.NewLineKind.LineFeed:
39
+ default:
40
+ return lineFeed;
41
+ }
42
+ }
43
+ const isModernNodeModuleKind = (module) => {
44
+ return module
45
+ ? [typescript_1.default.ModuleKind.Node16, /* ModuleKind.Node18 */ 101, /* ModuleKind.Node20 */ 102, typescript_1.default.ModuleKind.NodeNext].includes(module)
46
+ : false;
47
+ };
48
+ exports.isModernNodeModuleKind = isModernNodeModuleKind;
49
+ const shouldCheckProjectPkgJsonContent = (fileName, moduleKind) => {
50
+ return fileName.endsWith('package.json') && (0, exports.isModernNodeModuleKind)(moduleKind);
51
+ };
52
+ /**
53
+ * Copy source code of {@link ts.transpileModule} from {@link https://github.com/microsoft/TypeScript/blob/main/src/services/transpile.ts}
54
+ * with extra modifications:
55
+ * - Remove generation of declaration files
56
+ * - Allow using custom AST transformers with the internal created {@link Program}
57
+ */
58
+ const transpileWorker = (input, transpileOptions) => {
59
+ if (!barebonesLibSourceFile) {
60
+ barebonesLibSourceFile = typescript_1.default.createSourceFile(barebonesLibName, barebonesLibContent, {
61
+ languageVersion: typescript_1.default.ScriptTarget.Latest,
62
+ });
63
+ }
64
+ const diagnostics = [];
65
+ const options = transpileOptions.compilerOptions
66
+ ? // @ts-expect-error internal TypeScript API
67
+ typescript_1.default.fixupCompilerOptions(transpileOptions.compilerOptions, diagnostics)
68
+ : {};
69
+ // mix in default options
70
+ const defaultOptions = typescript_1.default.getDefaultCompilerOptions();
71
+ for (const key in defaultOptions) {
72
+ if (Object.hasOwn(defaultOptions, key) && options[key] === undefined) {
73
+ options[key] = defaultOptions[key];
74
+ }
75
+ }
76
+ // @ts-expect-error internal TypeScript API
77
+ for (const option of typescript_1.default.transpileOptionValueCompilerOptions) {
78
+ // Do not set redundant config options if `verbatimModuleSyntax` was supplied.
79
+ if (options.verbatimModuleSyntax && new Set(['isolatedModules']).has(option.name)) {
80
+ continue;
81
+ }
82
+ options[option.name] = option.transpileOptionValue;
83
+ }
84
+ // transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths.
85
+ options.suppressOutputPathCheck = true;
86
+ // Filename can be non-ts file.
87
+ options.allowNonTsExtensions = true;
88
+ options.declaration = false;
89
+ options.declarationMap = false;
90
+ const newLine = getNewLineCharacter(options);
91
+ // if jsx is specified then treat file as .tsx
92
+ const inputFileName = transpileOptions.fileName ?? (transpileOptions.compilerOptions?.jsx ? 'module.tsx' : 'module.ts');
93
+ // Create a compilerHost object to allow the compiler to read and write files
94
+ const compilerHost = {
95
+ getSourceFile: (fileName) => {
96
+ // @ts-expect-error internal TypeScript API
97
+ if (fileName === typescript_1.default.normalizePath(inputFileName)) {
98
+ return sourceFile;
99
+ }
100
+ // @ts-expect-error internal TypeScript API
101
+ return fileName === typescript_1.default.normalizePath(barebonesLibName) ? barebonesLibSourceFile : undefined;
102
+ },
103
+ writeFile: (name, text) => {
104
+ if (node_path_1.default.extname(name) === '.map') {
105
+ sourceMapText = text;
106
+ }
107
+ else {
108
+ outputText = text;
109
+ }
110
+ },
111
+ getDefaultLibFileName: () => barebonesLibName,
112
+ useCaseSensitiveFileNames: () => false,
113
+ getCanonicalFileName: (fileName) => fileName,
114
+ getCurrentDirectory: () => '',
115
+ getNewLine: () => newLine,
116
+ fileExists: (fileName) => {
117
+ if (shouldCheckProjectPkgJsonContent(fileName, options.module)) {
118
+ return typescript_1.default.sys.fileExists(fileName);
119
+ }
120
+ return fileName === inputFileName;
121
+ },
122
+ readFile: (fileName) => {
123
+ if (shouldCheckProjectPkgJsonContent(fileName, options.module)) {
124
+ return typescript_1.default.sys.readFile(fileName);
125
+ }
126
+ return '';
127
+ },
128
+ directoryExists: () => true,
129
+ getDirectories: () => [],
130
+ };
131
+ const sourceFile = typescript_1.default.createSourceFile(inputFileName, input, {
132
+ languageVersion: options.target ?? typescript_1.default.ScriptTarget.ESNext,
133
+ impliedNodeFormat: typescript_1.default.getImpliedNodeFormatForFile(inputFileName,
134
+ /*packageJsonInfoCache*/ undefined, compilerHost, options),
135
+ // @ts-expect-error internal TypeScript API
136
+ setExternalModuleIndicator: typescript_1.default.getSetExternalModuleIndicator(options),
137
+ jsDocParsingMode: transpileOptions.jsDocParsingMode ?? typescript_1.default.JSDocParsingMode.ParseAll,
138
+ });
139
+ if (transpileOptions.moduleName) {
140
+ sourceFile.moduleName = transpileOptions.moduleName;
141
+ }
142
+ if (transpileOptions.renamedDependencies) {
143
+ // @ts-expect-error internal TypeScript API
144
+ sourceFile.renamedDependencies = new Map(Object.entries(transpileOptions.renamedDependencies));
145
+ }
146
+ // Output
147
+ let outputText;
148
+ let sourceMapText;
149
+ const inputs = [inputFileName];
150
+ const program = typescript_1.default.createProgram(inputs, options, compilerHost);
151
+ if (transpileOptions.reportDiagnostics) {
152
+ diagnostics.push(...program.getSyntacticDiagnostics(sourceFile));
153
+ }
154
+ diagnostics.push(...program.getOptionsDiagnostics());
155
+ // Emit
156
+ const result = program.emit(
157
+ /*targetSourceFile*/ undefined,
158
+ /*writeFile*/ undefined,
159
+ /*cancellationToken*/ undefined,
160
+ /*emitOnlyDtsFiles*/ undefined, transpileOptions.transformers?.(program));
161
+ diagnostics.push(...result.diagnostics);
162
+ if (outputText === undefined) {
163
+ diagnostics.push({
164
+ category: typescript_1.default.DiagnosticCategory.Error,
165
+ code: utils_1.TsJestDiagnosticCodes.Generic,
166
+ messageText: 'No output generated',
167
+ file: sourceFile,
168
+ start: 0,
169
+ length: 0,
170
+ });
171
+ }
172
+ return { outputText: outputText ?? '', diagnostics, sourceMapText };
173
+ };
174
+ exports.tsTranspileModule = transpileWorker;
@@ -0,0 +1,282 @@
1
+ import type { TransformedSource, TransformOptions } from '@jest/transform';
2
+ import type { Config } from '@jest/types';
3
+ import type * as _babel from 'babel__core';
4
+ import type * as _ts from 'typescript';
5
+ import type { TsConfigCompilerOptionsJson } from './config/types';
6
+ import { ESM_JS_TRANSFORM_PATTERN, ESM_TS_JS_TRANSFORM_PATTERN, ESM_TS_TRANSFORM_PATTERN, JS_TRANSFORM_PATTERN, TS_JS_TRANSFORM_PATTERN, TS_TRANSFORM_PATTERN } from './constants';
7
+ import type { ConfigSet } from './legacy/config/config-set';
8
+ import type { RawCompilerOptions } from './raw-compiler-options';
9
+ export type TTypeScript = typeof _ts;
10
+ /**
11
+ * Don't mark as internal because it is used in TsJestGlobalOptions which is an exposed type
12
+ */
13
+ export type BabelConfig = _babel.TransformOptions;
14
+ export interface AstTransformer<T = Record<string, unknown>> {
15
+ path: string;
16
+ options?: T;
17
+ }
18
+ export interface ConfigCustomTransformer {
19
+ before?: Array<string | AstTransformer>;
20
+ after?: Array<string | AstTransformer>;
21
+ afterDeclarations?: Array<string | AstTransformer>;
22
+ }
23
+ /**
24
+ * @deprecated use {@link TsJestTransformerOptions} instead
25
+ */
26
+ export type TsJestGlobalOptions = Config.TransformerConfig[1] & {
27
+ /**
28
+ * Compiler options. It can be:
29
+ * - `true` (or `undefined`, it's the default): use default tsconfig file
30
+ * - `false`: do NOT use default config file
31
+ * - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
32
+ * - `{...}`: an object with inline compiler options
33
+ *
34
+ * @default `undefined` (the default config file will be used if it exists)
35
+ *
36
+ * @remarks
37
+ *
38
+ * {@link RawCompilerOptions} will be replaced with {@link TsConfigCompilerOptionsJson} in the next major release
39
+ */
40
+ tsconfig?: boolean | string | RawCompilerOptions | TsConfigCompilerOptionsJson;
41
+ /**
42
+ * @deprecated use {@link TsConfigCompilerOptionsJson.isolatedModules} instead
43
+ *
44
+ * Compiles files as isolated modules (disables some features)
45
+ *
46
+ * @default `undefined` (disables transpiling files with {@link _ts.transpileModule})
47
+ */
48
+ isolatedModules?: boolean;
49
+ /**
50
+ * Compiler to use
51
+ *
52
+ * @default `typescript`
53
+ */
54
+ compiler?: 'typescript' | 'ttypescript' | string;
55
+ /**
56
+ * Custom transformers (mostly used by jest presets)
57
+ */
58
+ astTransformers?: ConfigCustomTransformer;
59
+ /**
60
+ * TS diagnostics - less to be reported if `isolatedModules` is `true`. It can be:
61
+ * - `true` (or `undefined`, it's the default): show all diagnostics
62
+ * - `false`: hide diagnostics of all files (kind of useless)
63
+ * - `{...}`: an inline object with fine grained settings
64
+ *
65
+ * @default `undefined`
66
+ */
67
+ diagnostics?: boolean | {
68
+ /**
69
+ * Enables colorful and pretty output of errors
70
+ *
71
+ * @default `undefined` (enables formatting errors)
72
+ */
73
+ pretty?: boolean;
74
+ /**
75
+ * List of TypeScript diagnostic error codes to ignore
76
+ * [here](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json).
77
+ *
78
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
79
+ * @default `[6059,18002,18003]`
80
+ */
81
+ ignoreCodes?: number | string | Array<number | string>;
82
+ /**
83
+ * If specified, diagnostics of source files which path **matches** will be ignored
84
+ */
85
+ exclude?: string[];
86
+ /**
87
+ * Logs TypeScript errors to stderr instead of throwing exceptions
88
+ *
89
+ * @default `undefined` (TypeScript errors will be thrown as exceptions)
90
+ */
91
+ warnOnly?: boolean;
92
+ };
93
+ /**
94
+ * Babel config. It can be:
95
+ * - `false` (or `undefined`, it's the default): do NOT use babel
96
+ * - `true`: use babel using default babelrc file
97
+ * - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
98
+ * - `{...}`: an object with inline babel options
99
+ *
100
+ * @default `undefined` (not using `Babel`)
101
+ */
102
+ babelConfig?: boolean | string | BabelConfig;
103
+ /**
104
+ * Kept for backward compatibility to handle __TRANSFORM_HTML__
105
+ * Any file which will match this regex will be transpiled as a module
106
+ * exporting the content of the file as a string
107
+ */
108
+ stringifyContentPathRegex?: string | RegExp;
109
+ /**
110
+ * Tell `ts-jest` to transform codes to ESM format. This only works in combination with `jest-runtime` ESM option
111
+ * `supportsStaticESM` true which is passed into Jest transformer
112
+ */
113
+ useESM?: boolean;
114
+ };
115
+ /**
116
+ * For transformers which extends `ts-jest`
117
+ * @deprecated use `JestConfigWithTsJest` instead
118
+ */
119
+ export interface ProjectConfigTsJest extends Config.ProjectConfig {
120
+ globals: GlobalConfigTsJest;
121
+ }
122
+ /**
123
+ * @deprecated use `JestConfigWithTsJest` instead
124
+ */
125
+ export interface TransformOptionsTsJest<TransformerConfig = unknown> extends TransformOptions<TransformerConfig> {
126
+ config: Config.ProjectConfig;
127
+ }
128
+ /**
129
+ * For typings in `jest.config.ts`
130
+ * @deprecated use `JestConfigWithTsJest` instead
131
+ */
132
+ export interface GlobalConfigTsJest extends Config.ConfigGlobals {
133
+ 'ts-jest'?: TsJestGlobalOptions;
134
+ }
135
+ /**
136
+ * @deprecated use `JestConfigWithTsJest` instead
137
+ */
138
+ export interface InitialOptionsTsJest extends Config.InitialOptions {
139
+ globals?: GlobalConfigTsJest;
140
+ }
141
+ export type TsJestTransformerOptions = TsJestGlobalOptions;
142
+ export type TsJestTransformOptions = TransformOptions<TsJestTransformerOptions>;
143
+ export interface JestConfigWithTsJest extends Omit<Config.InitialOptions, 'transform'> {
144
+ transform?: {
145
+ [regex: string]: 'ts-jest' | 'ts-jest/legacy' | ['ts-jest', TsJestTransformerOptions] | ['ts-jest/legacy', TsJestTransformerOptions];
146
+ } | Config.InitialOptions['transform'];
147
+ }
148
+ export type StringMap = Map<string, string>;
149
+ export interface DepGraphInfo {
150
+ fileContent: string;
151
+ resolvedModuleNames: string[];
152
+ }
153
+ export interface TsJestCompileOptions {
154
+ depGraphs: Map<string, DepGraphInfo>;
155
+ watchMode: boolean;
156
+ supportsStaticESM: boolean;
157
+ }
158
+ export interface CompiledOutput extends TransformedSource {
159
+ diagnostics?: _ts.Diagnostic[];
160
+ }
161
+ export interface CompilerInstance {
162
+ getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
163
+ getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput;
164
+ }
165
+ export interface TsCompilerInstance extends CompilerInstance {
166
+ configSet: ConfigSet;
167
+ program: _ts.Program | undefined;
168
+ }
169
+ export interface AstTransformerDesc<T = Record<string, unknown>> {
170
+ name: string;
171
+ version: number;
172
+ factory(tsCompiler: TsCompilerInstance, opts?: T): _ts.TransformerFactory<_ts.SourceFile> | _ts.TransformerFactory<_ts.Bundle | _ts.SourceFile>;
173
+ options?: T;
174
+ }
175
+ export interface TsJestAstTransformer {
176
+ before: AstTransformerDesc[];
177
+ after: AstTransformerDesc[];
178
+ afterDeclarations: AstTransformerDesc[];
179
+ }
180
+ /**
181
+ * @deprecated use other preset types below instead
182
+ */
183
+ export type TsJestPresets = Pick<JestConfigWithTsJest, 'extensionsToTreatAsEsm' | 'moduleFileExtensions' | 'transform' | 'testMatch'>;
184
+ export type DefaultTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
185
+ export type DefaultPreset = {
186
+ transform: {
187
+ [TS_TRANSFORM_PATTERN]: ['ts-jest', DefaultTransformOptions];
188
+ };
189
+ };
190
+ export type DefaultLegacyPreset = {
191
+ transform: {
192
+ [TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', DefaultTransformOptions];
193
+ };
194
+ };
195
+ export type DefaultEsmTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
196
+ export type DefaultEsmPreset = {
197
+ extensionsToTreatAsEsm: string[];
198
+ transform: {
199
+ [ESM_TS_TRANSFORM_PATTERN]: ['ts-jest', {
200
+ useESM: true;
201
+ } & DefaultEsmTransformOptions];
202
+ };
203
+ };
204
+ export type DefaultEsmLegacyPreset = {
205
+ extensionsToTreatAsEsm: string[];
206
+ transform: {
207
+ [ESM_TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', {
208
+ useESM: true;
209
+ } & DefaultEsmTransformOptions];
210
+ };
211
+ };
212
+ export type JsWithTsTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
213
+ export type JsWithTsPreset = {
214
+ transform: {
215
+ [TS_JS_TRANSFORM_PATTERN]: ['ts-jest', JsWithTsTransformOptions];
216
+ };
217
+ };
218
+ export type JsWithTsLegacyPreset = {
219
+ transform: {
220
+ [TS_JS_TRANSFORM_PATTERN]: ['ts-jest/legacy', JsWithTsTransformOptions];
221
+ };
222
+ };
223
+ export type JsWithTsEsmTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
224
+ export type JsWithTsEsmPreset = {
225
+ extensionsToTreatAsEsm: string[];
226
+ transform: {
227
+ [ESM_TS_JS_TRANSFORM_PATTERN]: ['ts-jest', {
228
+ useESM: true;
229
+ } & JsWithTsEsmTransformOptions];
230
+ };
231
+ };
232
+ export type JsWithTsEsmLegacyPreset = {
233
+ extensionsToTreatAsEsm: string[];
234
+ transform: {
235
+ [ESM_TS_JS_TRANSFORM_PATTERN]: ['ts-jest/legacy', {
236
+ useESM: true;
237
+ } & JsWithTsEsmTransformOptions];
238
+ };
239
+ };
240
+ export type JsWithBabelTransformerOptions = Omit<TsJestTransformerOptions, 'useESM'>;
241
+ export type JsWithBabelPreset = {
242
+ transform: {
243
+ [JS_TRANSFORM_PATTERN]: 'babel-jest';
244
+ [TS_TRANSFORM_PATTERN]: ['ts-jest', JsWithBabelTransformerOptions];
245
+ };
246
+ };
247
+ export type JsWithBabelLegacyPreset = {
248
+ transform: {
249
+ [JS_TRANSFORM_PATTERN]: 'babel-jest';
250
+ [TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', JsWithBabelTransformerOptions];
251
+ };
252
+ };
253
+ export type JsWithBabelEsmTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
254
+ export type JsWithBabelEsmPreset = {
255
+ extensionsToTreatAsEsm: string[];
256
+ transform: {
257
+ [ESM_JS_TRANSFORM_PATTERN]: 'babel-jest';
258
+ [ESM_TS_TRANSFORM_PATTERN]: ['ts-jest', {
259
+ useESM: true;
260
+ } & JsWithBabelEsmTransformOptions];
261
+ };
262
+ };
263
+ export type JsWithBabelEsmLegacyPreset = {
264
+ extensionsToTreatAsEsm: string[];
265
+ transform: {
266
+ [ESM_JS_TRANSFORM_PATTERN]: 'babel-jest';
267
+ [ESM_TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', {
268
+ useESM: true;
269
+ } & JsWithBabelEsmTransformOptions];
270
+ };
271
+ };
272
+ declare module '@jest/types' {
273
+ namespace Config {
274
+ interface ConfigGlobals {
275
+ /**
276
+ * strangely `@ts-expect-error` doesn't work in this case when running
277
+ * `npm run build` vs `npm run pretest`
278
+ */
279
+ 'ts-jest'?: TsJestTransformerOptions;
280
+ }
281
+ }
282
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("./constants");
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.backportTsJestDebugEnvVar = exports.backportJestConfig = void 0;
4
+ const bs_logger_1 = require("bs-logger");
5
+ const messages_1 = require("./messages");
6
+ const context = { [bs_logger_1.LogContexts.namespace]: 'backports' };
7
+ /**
8
+ * @internal
9
+ */
10
+ const backportJestConfig = (logger, config) => {
11
+ logger.debug({ ...context, config }, 'backporting config');
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ const { globals = {} } = (config || {});
14
+ const { 'ts-jest': tsJest = {} } = globals;
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ const mergeTsJest = {};
17
+ let hadWarnings = false;
18
+ const warnConfig = (oldPath, newPath, note) => {
19
+ hadWarnings = true;
20
+ logger.warn(context, (0, messages_1.interpolate)(note ? "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead.\n \u21B3 {{note}}" /* Deprecations.ConfigOptionWithNote */ : "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead." /* Deprecations.ConfigOption */, {
21
+ oldPath,
22
+ newPath,
23
+ note,
24
+ }));
25
+ };
26
+ if ('__TS_CONFIG__' in globals) {
27
+ warnConfig('globals.__TS_CONFIG__', 'globals.ts-jest.tsconfig');
28
+ if (typeof globals.__TS_CONFIG__ === 'object') {
29
+ mergeTsJest.tsconfig = globals.__TS_CONFIG__;
30
+ }
31
+ delete globals.__TS_CONFIG__;
32
+ }
33
+ if ('__TRANSFORM_HTML__' in globals) {
34
+ warnConfig('globals.__TRANSFORM_HTML__', 'globals.ts-jest.stringifyContentPathRegex');
35
+ if (globals.__TRANSFORM_HTML__) {
36
+ mergeTsJest.stringifyContentPathRegex = '\\.html?$';
37
+ }
38
+ delete globals.__TRANSFORM_HTML__;
39
+ }
40
+ if ('typeCheck' in tsJest) {
41
+ warnConfig('globals.ts-jest.typeCheck', 'globals.ts-jest.isolatedModules');
42
+ mergeTsJest.isolatedModules = !tsJest.typeCheck;
43
+ delete tsJest.typeCheck;
44
+ }
45
+ if ('tsConfigFile' in tsJest) {
46
+ warnConfig('globals.ts-jest.tsConfigFile', 'globals.ts-jest.tsconfig');
47
+ if (tsJest.tsConfigFile) {
48
+ mergeTsJest.tsconfig = tsJest.tsConfigFile;
49
+ }
50
+ delete tsJest.tsConfigFile;
51
+ }
52
+ if ('tsConfig' in tsJest) {
53
+ warnConfig('globals.ts-jest.tsConfig', 'globals.ts-jest.tsconfig');
54
+ if (tsJest.tsConfig) {
55
+ mergeTsJest.tsconfig = tsJest.tsConfig;
56
+ }
57
+ delete tsJest.tsConfig;
58
+ }
59
+ if ('enableTsDiagnostics' in tsJest) {
60
+ warnConfig('globals.ts-jest.enableTsDiagnostics', 'globals.ts-jest.diagnostics');
61
+ if (tsJest.enableTsDiagnostics) {
62
+ mergeTsJest.diagnostics = { warnOnly: true };
63
+ if (typeof tsJest.enableTsDiagnostics === 'string')
64
+ mergeTsJest.diagnostics.exclude = [tsJest.enableTsDiagnostics];
65
+ }
66
+ else {
67
+ mergeTsJest.diagnostics = false;
68
+ }
69
+ delete tsJest.enableTsDiagnostics;
70
+ }
71
+ if ('useBabelrc' in tsJest) {
72
+ warnConfig('globals.ts-jest.useBabelrc', 'globals.ts-jest.babelConfig', "See `babel-jest` related issue: https://github.com/facebook/jest/issues/3845" /* Deprecations.ConfigOptionUseBabelRcNote */);
73
+ if (tsJest.useBabelrc != null) {
74
+ mergeTsJest.babelConfig = tsJest.useBabelrc ? true : {};
75
+ }
76
+ delete tsJest.useBabelrc;
77
+ }
78
+ if ('skipBabel' in tsJest) {
79
+ warnConfig('globals.ts-jest.skipBabel', 'globals.ts-jest.babelConfig');
80
+ if (tsJest.skipBabel === false && !mergeTsJest.babelConfig) {
81
+ mergeTsJest.babelConfig = true;
82
+ }
83
+ delete tsJest.skipBabel;
84
+ }
85
+ // if we had some warnings we can inform the user about the CLI tool
86
+ if (hadWarnings) {
87
+ logger.warn(context, messages_1.Helps.MigrateConfigUsingCLI);
88
+ }
89
+ return {
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
+ ...config,
92
+ globals: {
93
+ ...globals,
94
+ 'ts-jest': {
95
+ ...mergeTsJest,
96
+ ...tsJest,
97
+ },
98
+ },
99
+ };
100
+ };
101
+ exports.backportJestConfig = backportJestConfig;
102
+ /**
103
+ * @internal
104
+ */
105
+ const backportTsJestDebugEnvVar = (logger) => {
106
+ if ('TS_JEST_DEBUG' in process.env) {
107
+ const shouldLog = !/^\s*(?:0|f(?:alse)?|no?|disabled?|off|)\s*$/i.test(process.env.TS_JEST_DEBUG || '');
108
+ delete process.env.TS_JEST_DEBUG;
109
+ if (shouldLog) {
110
+ process.env.TS_JEST_LOG = 'ts-jest.log,stderr:warn';
111
+ }
112
+ logger.warn(context, (0, messages_1.interpolate)("Using env. var \"{{old}}\" is deprecated, use \"{{new}}\" instead." /* Deprecations.EnvVar */, {
113
+ old: 'TS_JEST_DEBUG',
114
+ new: 'TS_JEST_LOG',
115
+ }));
116
+ }
117
+ };
118
+ exports.backportTsJestDebugEnvVar = backportTsJestDebugEnvVar;
@@ -0,0 +1,5 @@
1
+ export declare const TsJestDiagnosticCodes: {
2
+ readonly Generic: 151000;
3
+ readonly ConfigModuleOption: 151001;
4
+ readonly ModernNodeModule: 151002;
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TsJestDiagnosticCodes = void 0;
4
+ exports.TsJestDiagnosticCodes = {
5
+ Generic: 151000,
6
+ ConfigModuleOption: 151001,
7
+ ModernNodeModule: 151002,
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageVersion = getPackageVersion;
4
+ /**
5
+ * @internal
6
+ */
7
+ function getPackageVersion(moduleName) {
8
+ try {
9
+ return require(`${moduleName}/package.json`).version;
10
+ }
11
+ catch {
12
+ return undefined;
13
+ }
14
+ }
@@ -0,0 +1 @@
1
+ export {};