@nx/jest 21.6.1-beta.0 → 21.6.1-beta.2

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.
package/migrations.json CHANGED
@@ -19,9 +19,6 @@
19
19
  },
20
20
  "rename-test-path-pattern": {
21
21
  "version": "21.3.0-beta.3",
22
- "requires": {
23
- "jest": ">=30.0.0"
24
- },
25
22
  "description": "Rename the CLI option `testPathPattern` to `testPathPatterns`.",
26
23
  "implementation": "./src/migrations/update-21-3-0/rename-test-path-pattern"
27
24
  },
@@ -80,6 +77,9 @@
80
77
  "21.3.0": {
81
78
  "version": "21.3.0-beta.3",
82
79
  "x-prompt": "Do you want to update the Jest version to v30?",
80
+ "incompatibleWith": {
81
+ "@angular-devkit/build-angular": "*"
82
+ },
83
83
  "packages": {
84
84
  "jest": {
85
85
  "version": "~30.0.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/jest",
3
- "version": "21.6.1-beta.0",
3
+ "version": "21.6.1-beta.2",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Jest contains executors and generators allowing your workspace to use the powerful Jest testing capabilities.",
6
6
  "repository": {
@@ -37,8 +37,8 @@
37
37
  "dependencies": {
38
38
  "@jest/reporters": "^30.0.2",
39
39
  "@jest/test-result": "^30.0.2",
40
- "@nx/devkit": "21.6.1-beta.0",
41
- "@nx/js": "21.6.1-beta.0",
40
+ "@nx/devkit": "21.6.1-beta.2",
41
+ "@nx/js": "21.6.1-beta.2",
42
42
  "@phenomnomnominal/tsquery": "~5.0.1",
43
43
  "identity-obj-proxy": "3.0.0",
44
44
  "jest-config": "^30.0.2",
@@ -52,7 +52,7 @@
52
52
  "yargs-parser": "21.1.1"
53
53
  },
54
54
  "devDependencies": {
55
- "nx": "21.6.1-beta.0"
55
+ "nx": "21.6.1-beta.2"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path_1 = require("path");
4
4
  const resolve_exports_1 = require("resolve.exports");
5
5
  const jest_1 = require("jest");
6
+ const semver_1 = require("semver");
6
7
  let compilerSetup;
7
8
  let ts;
8
- const jestMajorVersion = Number((0, jest_1.getVersion)().split('.')[0]);
9
+ const jestMajorVersion = (0, semver_1.major)((0, jest_1.getVersion)());
9
10
  function getCompilerSetup(rootDir) {
10
11
  const tsConfigPath = ts.findConfigFile(rootDir, ts.sys.fileExists, 'tsconfig.spec.json') ||
11
12
  ts.findConfigFile(rootDir, ts.sys.fileExists, 'tsconfig.test.json') ||
@@ -1,3 +1,3 @@
1
- import type { Config } from 'jest';
1
+ import { Config } from 'jest';
2
2
  export declare const nxPreset: Config;
3
3
  //# sourceMappingURL=jest-preset.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../packages/jest/preset/jest-preset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,eAAO,MAAM,QAAQ,EAAE,MA6BtB,CAAC"}
1
+ {"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../packages/jest/preset/jest-preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAK1C,eAAO,MAAM,QAAQ,EAAE,MAsCtB,CAAC"}
@@ -1,14 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nxPreset = void 0;
4
+ const jest_1 = require("jest");
5
+ const semver_1 = require("semver");
6
+ const jestMajorVersion = (0, semver_1.major)((0, jest_1.getVersion)());
4
7
  exports.nxPreset = {
5
8
  // This is one of the patterns that jest finds by default https://jestjs.io/docs/configuration#testmatch-arraystring
6
- testMatch: ['**/?(*.)+(spec|test).?([mc])[jt]s?(x)'],
9
+ testMatch: [
10
+ jestMajorVersion >= 30
11
+ ? '**/?(*.)+(spec|test).?([mc])[jt]s?(x)'
12
+ : '**/?(*.)+(spec|test).[jt]s?(x)',
13
+ ],
7
14
  resolver: '@nx/jest/plugins/resolver',
8
- moduleFileExtensions: ['ts', 'js', 'mts', 'mjs', 'cts', 'cjs', 'html'],
15
+ moduleFileExtensions: jestMajorVersion >= 30
16
+ ? ['ts', 'js', 'mts', 'mjs', 'cts', 'cjs', 'html']
17
+ : ['ts', 'js', 'mjs', 'html'],
9
18
  coverageReporters: ['html'],
10
19
  transform: {
11
- '^.+\\.(ts|js|mts|mjs|cts|cjs|html)$': [
20
+ [jestMajorVersion >= 30
21
+ ? '^.+\\.(ts|js|mts|mjs|cts|cjs|html)$'
22
+ : '^.+\\.(ts|js|html)$']: [
12
23
  'ts-jest',
13
24
  { tsconfig: '<rootDir>/tsconfig.spec.json' },
14
25
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"ensure-dependencies.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jest/src/generators/configuration/lib/ensure-dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAYrE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAE7D,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,CAAC,2BAA2B,CAAC,0CAuC9C"}
1
+ {"version":3,"file":"ensure-dependencies.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jest/src/generators/configuration/lib/ensure-dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAE7D,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,CAAC,2BAA2B,CAAC,0CAmD9C"}
@@ -4,32 +4,33 @@ exports.ensureDependencies = ensureDependencies;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const versions_1 = require("../../../utils/versions");
6
6
  function ensureDependencies(tree, options) {
7
+ const { babelJestVersion, jestTypesVersion, jestVersion, nxVersion, swcJestVersion, tsJestVersion, tslibVersion, tsNodeVersion, typesNodeVersion, } = (0, versions_1.versions)(tree);
7
8
  const dependencies = {
8
- tslib: versions_1.tslibVersion,
9
+ tslib: tslibVersion,
9
10
  };
10
11
  const devDeps = {
11
12
  // because the default jest-preset uses ts-jest,
12
13
  // jest will throw an error if it's not installed
13
14
  // even if not using it in overriding transformers
14
- 'ts-jest': versions_1.tsJestVersion,
15
+ 'ts-jest': tsJestVersion,
15
16
  // peer dependency of ts-jest
16
- 'jest-util': versions_1.jestVersion,
17
+ 'jest-util': jestVersion,
17
18
  };
18
19
  if (options.testEnvironment !== 'none') {
19
- devDeps[`jest-environment-${options.testEnvironment}`] = versions_1.jestVersion;
20
+ devDeps[`jest-environment-${options.testEnvironment}`] = jestVersion;
20
21
  }
21
22
  if (!options.js) {
22
- devDeps['ts-node'] = versions_1.tsNodeVersion;
23
- devDeps['@types/jest'] = versions_1.jestTypesVersion;
24
- devDeps['@types/node'] = versions_1.typesNodeVersion;
23
+ devDeps['ts-node'] = tsNodeVersion;
24
+ devDeps['@types/jest'] = jestTypesVersion;
25
+ devDeps['@types/node'] = typesNodeVersion;
25
26
  }
26
27
  if (options.compiler === 'babel' || options.babelJest) {
27
- devDeps['babel-jest'] = versions_1.babelJestVersion;
28
+ devDeps['babel-jest'] = babelJestVersion;
28
29
  // in some cases @nx/js will not already be present i.e. node only projects
29
- devDeps['@nx/js'] = versions_1.nxVersion;
30
+ devDeps['@nx/js'] = nxVersion;
30
31
  }
31
32
  else if (options.compiler === 'swc') {
32
- devDeps['@swc/jest'] = versions_1.swcJestVersion;
33
+ devDeps['@swc/jest'] = swcJestVersion;
33
34
  }
34
35
  return (0, devkit_1.addDependenciesToPackageJson)(tree, dependencies, devDeps, undefined, options.keepExistingVersions);
35
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"convert-to-inferred.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/generators/convert-to-inferred/convert-to-inferred.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAepB,UAAU,MAAM;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,iBA0BlE;AA4DD,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"convert-to-inferred.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/generators/convert-to-inferred/convert-to-inferred.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAepB,UAAU,MAAM;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,iBA0BlE;AA8DD,eAAe,iBAAiB,CAAC"}
@@ -8,7 +8,7 @@ const jest_config_1 = require("jest-config");
8
8
  const node_path_1 = require("node:path");
9
9
  const plugin_1 = require("../../plugins/plugin");
10
10
  const config_file_1 = require("../../utils/config/config-file");
11
- const version_utils_1 = require("../../utils/version-utils");
11
+ const versions_1 = require("../../utils/versions");
12
12
  async function convertToInferred(tree, options) {
13
13
  const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
14
14
  const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/jest/plugin', plugin_1.createNodesV2, { targetName: 'test' }, [
@@ -30,11 +30,11 @@ async function postTargetTransformer(target, tree, projectDetails, inferredTarge
30
30
  .map((ext) => `jest.config.${ext}`)
31
31
  .find((configFileName) => tree.exists(node_path_1.posix.join(projectDetails.root, configFileName)));
32
32
  if (target.options) {
33
- await updateOptionsObject(target.options, projectDetails.root, tree.root, jestConfigPath);
33
+ await updateOptionsObject(tree, target.options, projectDetails.root, tree.root, jestConfigPath);
34
34
  }
35
35
  if (target.configurations) {
36
36
  for (const [configName, config] of Object.entries(target.configurations)) {
37
- await updateConfigurationObject(config, projectDetails.root, tree.root, jestConfigPath);
37
+ await updateConfigurationObject(tree, config, projectDetails.root, tree.root, jestConfigPath);
38
38
  if (!Object.keys(config).length) {
39
39
  delete target.configurations[configName];
40
40
  }
@@ -57,15 +57,15 @@ async function postTargetTransformer(target, tree, projectDetails, inferredTarge
57
57
  return target;
58
58
  }
59
59
  exports.default = convertToInferred;
60
- async function updateOptionsObject(targetOptions, projectRoot, workspaceRoot, defaultJestConfigPath) {
60
+ async function updateOptionsObject(tree, targetOptions, projectRoot, workspaceRoot, defaultJestConfigPath) {
61
61
  const jestConfigPath = targetOptions.jestConfig ?? defaultJestConfigPath;
62
62
  // inferred targets are only identified after known files that Jest would
63
63
  // pick up, so we can safely remove the config options
64
64
  delete targetOptions.jestConfig;
65
65
  delete targetOptions.config;
66
- await updateOptions(targetOptions, projectRoot, workspaceRoot, jestConfigPath);
66
+ await updateOptions(tree, targetOptions, projectRoot, workspaceRoot, jestConfigPath);
67
67
  }
68
- async function updateConfigurationObject(targetOptions, projectRoot, workspaceRoot, defaultJestConfigPath) {
68
+ async function updateConfigurationObject(tree, targetOptions, projectRoot, workspaceRoot, defaultJestConfigPath) {
69
69
  const jestConfigPath = targetOptions.jestConfig ?? defaultJestConfigPath;
70
70
  if (targetOptions.jestConfig) {
71
71
  targetOptions.config = (0, plugin_migration_utils_1.toProjectRelativePath)(targetOptions.jestConfig, projectRoot);
@@ -74,9 +74,9 @@ async function updateConfigurationObject(targetOptions, projectRoot, workspaceRo
74
74
  else if (targetOptions.config) {
75
75
  targetOptions.config = (0, plugin_migration_utils_1.toProjectRelativePath)(targetOptions.config, projectRoot);
76
76
  }
77
- await updateOptions(targetOptions, projectRoot, workspaceRoot, jestConfigPath);
77
+ await updateOptions(tree, targetOptions, projectRoot, workspaceRoot, jestConfigPath);
78
78
  }
79
- async function updateOptions(targetOptions, projectRoot, workspaceRoot, jestConfigPath) {
79
+ async function updateOptions(tree, targetOptions, projectRoot, workspaceRoot, jestConfigPath) {
80
80
  // deprecated and unused
81
81
  delete targetOptions.tsConfig;
82
82
  if ('codeCoverage' in targetOptions) {
@@ -98,7 +98,7 @@ async function updateOptions(targetOptions, projectRoot, workspaceRoot, jestConf
98
98
  testPathPatterns.push(...targetOptions.testPathPatterns.map((pattern) => toProjectRelativeRegexPath(pattern, projectRoot)));
99
99
  }
100
100
  else {
101
- const jestMajorVersion = (0, version_utils_1.getInstalledJestMajorVersion)();
101
+ const jestMajorVersion = (0, versions_1.getInstalledJestMajorVersion)(tree);
102
102
  testPathPatternsOptionName =
103
103
  jestMajorVersion >= 30 ? 'testPathPatterns' : 'testPathPattern';
104
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/generators/init/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,iBAAiB,EACtB,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAQpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAqE/C,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,8BAEpE;AAED,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,iBAAiB,CAAC,CAsC5B;AAED,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/generators/init/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,iBAAiB,EACtB,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAYpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAuE/C,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,8BAEpE;AAED,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,iBAAiB,CAAC,CA2C5B;AAED,eAAe,iBAAiB,CAAC"}
@@ -51,15 +51,20 @@ function addJestTargetDefaults(tree, presetExt) {
51
51
  (0, devkit_1.updateNxJson)(tree, nxJson);
52
52
  }
53
53
  function updateDependencies(tree, options) {
54
+ const { jestVersion, nxVersion } = (0, versions_1.versions)(tree);
54
55
  return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
55
- '@nx/jest': versions_1.nxVersion,
56
- jest: versions_1.jestVersion,
56
+ '@nx/jest': nxVersion,
57
+ jest: jestVersion,
57
58
  }, undefined, options.keepExistingVersions);
58
59
  }
59
60
  function jestInitGenerator(tree, options) {
60
61
  return jestInitGeneratorInternal(tree, { addPlugin: false, ...options });
61
62
  }
62
63
  async function jestInitGeneratorInternal(tree, options) {
64
+ const installedJestVersion = (0, versions_1.getInstalledJestVersion)(tree);
65
+ if (installedJestVersion) {
66
+ (0, versions_1.validateInstalledJestVersion)(tree);
67
+ }
63
68
  const nxJson = (0, devkit_1.readNxJson)(tree);
64
69
  const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
65
70
  nxJson.useInferencePlugins !== false;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/jest/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAIX,aAAa,EAUd,MAAM,YAAY,CAAC;AAqBpB,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAmBD,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,iBAAiB,CAiF1D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,iBAAiB,CA4CtD,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/jest/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAIX,aAAa,EAUd,MAAM,YAAY,CAAC;AAsBpB,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAmBD,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,iBAAiB,CAiF1D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,iBAAiB,CA4CtD,CAAC"}
@@ -16,6 +16,7 @@ const workspace_context_1 = require("nx/src/utils/workspace-context");
16
16
  const node_path_1 = require("node:path");
17
17
  const installation_directory_1 = require("nx/src/utils/installation-directory");
18
18
  const semver_1 = require("semver");
19
+ const versions_1 = require("../utils/versions");
19
20
  const pmc = (0, devkit_1.getPackageManagerCommand)();
20
21
  function readTargetsCache(cachePath) {
21
22
  return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0, fs_1.existsSync)(cachePath)
@@ -289,7 +290,11 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
289
290
  });
290
291
  const jest = require(resolveJestPath(projectRoot, context.workspaceRoot));
291
292
  const source = new jest.SearchSource(jestContext);
292
- const specs = await source.getTestPaths(config.globalConfig, config.projectConfig);
293
+ const jestVersion = (0, versions_1.getInstalledJestMajorVersion)();
294
+ const specs = jestVersion >= 30
295
+ ? await source.getTestPaths(config.globalConfig, config.projectConfig)
296
+ : // @ts-expect-error Jest v29 doesn't have the projectConfig parameter
297
+ await source.getTestPaths(config.globalConfig);
293
298
  const testPaths = new Set(specs.tests.map(({ path }) => path));
294
299
  if (testPaths.size > 0) {
295
300
  const targetGroup = [];
@@ -1,10 +1,29 @@
1
- export declare const nxVersion: any;
2
- export declare const jestVersion = "^30.0.2";
3
- export declare const babelJestVersion = "^30.0.2";
4
- export declare const jestTypesVersion = "^30.0.0";
5
- export declare const tsJestVersion = "^29.4.0";
6
- export declare const tslibVersion = "^2.3.0";
7
- export declare const swcJestVersion = "~0.2.38";
8
- export declare const typesNodeVersion = "20.19.9";
9
- export declare const tsNodeVersion = "10.9.1";
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare const latestVersions: {
3
+ nxVersion: any;
4
+ jestVersion: string;
5
+ babelJestVersion: string;
6
+ jestTypesVersion: string;
7
+ tsJestVersion: string;
8
+ tslibVersion: string;
9
+ swcJestVersion: string;
10
+ typesNodeVersion: string;
11
+ tsNodeVersion: string;
12
+ };
13
+ declare const supportedMajorVersions: readonly [29, 30];
14
+ type SupportedVersions = (typeof supportedMajorVersions)[number];
15
+ type PackageVersionNames = keyof typeof latestVersions;
16
+ export type VersionMap = {
17
+ [key in SupportedVersions]: Record<PackageVersionNames, string>;
18
+ };
19
+ export declare const versionMap: VersionMap;
20
+ export declare function versions(tree: Tree): any;
21
+ export declare function getInstalledJestVersion(tree?: Tree): string | null;
22
+ export declare function getInstalledJestVersionInfo(tree?: Tree): {
23
+ version: string | null;
24
+ major: number | null;
25
+ };
26
+ export declare function getInstalledJestMajorVersion(tree?: Tree): number | null;
27
+ export declare function validateInstalledJestVersion(tree?: Tree): void;
28
+ export {};
10
29
  //# sourceMappingURL=versions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../../../../../packages/jest/src/utils/versions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,KAAwC,CAAC;AAC/D,eAAO,MAAM,WAAW,YAAY,CAAC;AACrC,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,YAAY,WAAW,CAAC;AACrC,eAAO,MAAM,cAAc,YAAY,CAAC;AACxC,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C,eAAO,MAAM,aAAa,WAAW,CAAC"}
1
+ {"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../../../../../packages/jest/src/utils/versions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAKjD,eAAO,MAAM,cAAc;;;;;;;;;;CAU1B,CAAC;AAEF,QAAA,MAAM,sBAAsB,mBAAoB,CAAC;AAIjD,KAAK,iBAAiB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AACjE,KAAK,mBAAmB,GAAG,MAAM,OAAO,cAAc,CAAC;AACvD,MAAM,MAAM,UAAU,GAAG;KACtB,GAAG,IAAI,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC;CAChE,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,UAaxB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,OAiBlC;AAED,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAclE;AAED,wBAAgB,2BAA2B,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG;IACxD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAMA;AAED,wBAAgB,4BAA4B,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAIvE;AAED,wBAAgB,4BAA4B,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAc9D"}
@@ -1,12 +1,106 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tsNodeVersion = exports.typesNodeVersion = exports.swcJestVersion = exports.tslibVersion = exports.tsJestVersion = exports.jestTypesVersion = exports.babelJestVersion = exports.jestVersion = exports.nxVersion = void 0;
4
- exports.nxVersion = require('../../package.json').version;
5
- exports.jestVersion = '^30.0.2';
6
- exports.babelJestVersion = '^30.0.2';
7
- exports.jestTypesVersion = '^30.0.0';
8
- exports.tsJestVersion = '^29.4.0';
9
- exports.tslibVersion = '^2.3.0';
10
- exports.swcJestVersion = '~0.2.38';
11
- exports.typesNodeVersion = '20.19.9';
12
- exports.tsNodeVersion = '10.9.1';
3
+ exports.versionMap = exports.latestVersions = void 0;
4
+ exports.versions = versions;
5
+ exports.getInstalledJestVersion = getInstalledJestVersion;
6
+ exports.getInstalledJestVersionInfo = getInstalledJestVersionInfo;
7
+ exports.getInstalledJestMajorVersion = getInstalledJestMajorVersion;
8
+ exports.validateInstalledJestVersion = validateInstalledJestVersion;
9
+ const devkit_1 = require("@nx/devkit");
10
+ const semver_1 = require("semver");
11
+ const nxVersion = require('../../package.json').version;
12
+ exports.latestVersions = {
13
+ nxVersion,
14
+ jestVersion: '^30.0.2',
15
+ babelJestVersion: '^30.0.2',
16
+ jestTypesVersion: '^30.0.0',
17
+ tsJestVersion: '^29.4.0',
18
+ tslibVersion: '^2.3.0',
19
+ swcJestVersion: '~0.2.38',
20
+ typesNodeVersion: '20.19.9',
21
+ tsNodeVersion: '10.9.1',
22
+ };
23
+ const supportedMajorVersions = [29, 30];
24
+ const minSupportedMajorVersion = Math.min(...supportedMajorVersions);
25
+ const currentMajorVersion = Math.max(...supportedMajorVersions);
26
+ exports.versionMap = {
27
+ 29: {
28
+ nxVersion,
29
+ jestVersion: '^29.7.0',
30
+ babelJestVersion: '^29.7.0',
31
+ jestTypesVersion: '^29.5.12',
32
+ tsJestVersion: '^29.1.0',
33
+ tslibVersion: '^2.3.0',
34
+ swcJestVersion: '~0.2.36',
35
+ typesNodeVersion: '18.16.9',
36
+ tsNodeVersion: '10.9.1',
37
+ },
38
+ 30: exports.latestVersions,
39
+ };
40
+ function versions(tree) {
41
+ const installedJestVersion = getInstalledJestVersion(tree);
42
+ if (!installedJestVersion) {
43
+ return exports.latestVersions;
44
+ }
45
+ const jestMajorVersion = (0, semver_1.major)(installedJestVersion);
46
+ if (exports.versionMap[jestMajorVersion]) {
47
+ return exports.versionMap[jestMajorVersion];
48
+ }
49
+ const backwardCompatibleVersions = supportedMajorVersions.slice(0, -1);
50
+ throw new Error(`You're currently using an unsupported Jest version: ${installedJestVersion}. Supported major versions are ${backwardCompatibleVersions.join(', ')} and ${currentMajorVersion}.`);
51
+ }
52
+ function getInstalledJestVersion(tree) {
53
+ try {
54
+ let version;
55
+ if (tree) {
56
+ version = getJestVersionFromTree(tree);
57
+ }
58
+ else {
59
+ version = getJestVersionFromFileSystem();
60
+ }
61
+ return version;
62
+ }
63
+ catch {
64
+ return null;
65
+ }
66
+ }
67
+ function getInstalledJestVersionInfo(tree) {
68
+ const version = getInstalledJestVersion(tree);
69
+ return version
70
+ ? { version, major: (0, semver_1.major)(version) }
71
+ : { version: null, major: null };
72
+ }
73
+ function getInstalledJestMajorVersion(tree) {
74
+ const installedJestVersion = getInstalledJestVersion(tree);
75
+ return installedJestVersion ? (0, semver_1.major)(installedJestVersion) : null;
76
+ }
77
+ function validateInstalledJestVersion(tree) {
78
+ const { version, major } = getInstalledJestVersionInfo(tree);
79
+ if (!version) {
80
+ return;
81
+ }
82
+ if (major < minSupportedMajorVersion || major > currentMajorVersion) {
83
+ const backwardCompatibleVersions = supportedMajorVersions.slice(0, -1);
84
+ throw new Error(`You're currently using an unsupported Jest version: ${version}. Supported major versions are ${backwardCompatibleVersions.join(', ')} and ${currentMajorVersion}.`);
85
+ }
86
+ }
87
+ function getJestVersionFromTree(tree) {
88
+ const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
89
+ const installedVersion = packageJson.devDependencies?.jest ?? packageJson.dependencies?.jest;
90
+ if (!installedVersion) {
91
+ return null;
92
+ }
93
+ if (installedVersion === 'latest' || installedVersion === 'next') {
94
+ return ((0, semver_1.clean)(exports.latestVersions.jestVersion) ??
95
+ (0, semver_1.coerce)(exports.latestVersions.jestVersion)?.version);
96
+ }
97
+ return (0, semver_1.clean)(installedVersion) ?? (0, semver_1.coerce)(installedVersion)?.version;
98
+ }
99
+ function getJestVersionFromFileSystem() {
100
+ try {
101
+ const { getVersion } = require('jest');
102
+ return getVersion();
103
+ }
104
+ catch { }
105
+ return null;
106
+ }