@tramvai/cli 5.18.3 → 5.19.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 (61) hide show
  1. package/lib/api/start/utils/tips/tips.d.ts.map +1 -1
  2. package/lib/api/start/utils/tips/tips.js +8 -0
  3. package/lib/api/start/utils/tips/tips.js.map +1 -1
  4. package/lib/builder/webpack/tokens.d.ts +3 -0
  5. package/lib/builder/webpack/tokens.d.ts.map +1 -1
  6. package/lib/commands/analyze/command.d.ts.map +1 -1
  7. package/lib/commands/analyze/command.js +2 -0
  8. package/lib/commands/analyze/command.js.map +1 -1
  9. package/lib/commands/build/command.d.ts.map +1 -1
  10. package/lib/commands/build/command.js +2 -0
  11. package/lib/commands/build/command.js.map +1 -1
  12. package/lib/commands/start/command.d.ts.map +1 -1
  13. package/lib/commands/start/command.js +2 -0
  14. package/lib/commands/start/command.js.map +1 -1
  15. package/lib/commands/start-prod/command.d.ts.map +1 -1
  16. package/lib/commands/start-prod/command.js +2 -0
  17. package/lib/commands/start-prod/command.js.map +1 -1
  18. package/lib/di/tokens/config.d.ts +1 -0
  19. package/lib/di/tokens/config.d.ts.map +1 -1
  20. package/lib/library/babel/index.d.ts +11 -1
  21. package/lib/library/babel/index.d.ts.map +1 -1
  22. package/lib/library/babel/index.js +4 -1
  23. package/lib/library/babel/index.js.map +1 -1
  24. package/lib/library/babel/plugins/react-compiler.d.ts +13 -0
  25. package/lib/library/babel/plugins/react-compiler.d.ts.map +1 -0
  26. package/lib/library/babel/plugins/react-compiler.js +27 -0
  27. package/lib/library/babel/plugins/react-compiler.js.map +1 -0
  28. package/lib/library/typescript/index.d.ts +5 -0
  29. package/lib/library/typescript/index.d.ts.map +1 -1
  30. package/lib/library/webpack/utils/transpiler.d.ts +2 -1
  31. package/lib/library/webpack/utils/transpiler.d.ts.map +1 -1
  32. package/lib/library/webpack/utils/transpiler.js +3 -2
  33. package/lib/library/webpack/utils/transpiler.js.map +1 -1
  34. package/lib/schema/autogeneratedSchema.json +132 -15
  35. package/lib/typings/configEntry/cli.d.ts +15 -0
  36. package/lib/typings/configEntry/cli.d.ts.map +1 -1
  37. package/lib/utils/resolveReactVersion.d.ts +3 -0
  38. package/lib/utils/resolveReactVersion.d.ts.map +1 -0
  39. package/lib/utils/resolveReactVersion.js +11 -0
  40. package/lib/utils/resolveReactVersion.js.map +1 -0
  41. package/lib/validators/commands/checkReactCompilerDependencies.d.ts +3 -0
  42. package/lib/validators/commands/checkReactCompilerDependencies.d.ts.map +1 -0
  43. package/lib/validators/commands/checkReactCompilerDependencies.js +60 -0
  44. package/lib/validators/commands/checkReactCompilerDependencies.js.map +1 -0
  45. package/package.json +10 -2
  46. package/schema.json +132 -15
  47. package/src/api/start/utils/tips/tips.ts +9 -0
  48. package/src/commands/analyze/command.ts +2 -0
  49. package/src/commands/build/command.ts +2 -0
  50. package/src/commands/start/command.ts +2 -0
  51. package/src/commands/start-prod/command.ts +2 -0
  52. package/src/library/babel/index.ts +5 -0
  53. package/src/library/babel/plugins/react-compiler.ts +39 -0
  54. package/src/library/webpack/utils/transpiler.ts +5 -3
  55. package/src/models/config.spec.ts +4 -0
  56. package/src/schema/autogeneratedSchema.json +132 -15
  57. package/src/schema/tramvai.spec.ts +2 -0
  58. package/src/typings/configEntry/cli.ts +23 -0
  59. package/src/utils/resolveReactVersion.ts +8 -0
  60. package/src/validators/commands/checkReactCompilerDependencies.ts +82 -0
  61. package/src/validators/commands/checkSwcDependencies.ts +1 -1
@@ -4,6 +4,7 @@ import { checkConfigExists } from '../../validators/commands/checkConfigExists';
4
4
  import { checkPwaDependencies } from '../../validators/commands/checkPwaDependencies';
5
5
  import { runMigrationsAndCheckVersions } from '../../validators/commands/runMigrationsAndCheckVersions';
6
6
  import { checkSwcDependencies } from '../../validators/commands/checkSwcDependencies';
7
+ import { checkReactCompilerDependencies } from '../../validators/commands/checkReactCompilerDependencies';
7
8
 
8
9
  export type Params = {
9
10
  target: string;
@@ -51,6 +52,7 @@ class AnalyzeCommand extends CLICommand<Params> {
51
52
  runMigrationsAndCheckVersions,
52
53
  checkPwaDependencies,
53
54
  checkSwcDependencies,
55
+ checkReactCompilerDependencies,
54
56
  ];
55
57
 
56
58
  action(parameters: Params) {
@@ -6,6 +6,7 @@ import { runMigrationsAndCheckVersions } from '../../validators/commands/runMigr
6
6
  import type { BuildCommand as BuildCommandType } from '../../api/build';
7
7
  import { checkPwaDependencies } from '../../validators/commands/checkPwaDependencies';
8
8
  import { checkSwcDependencies } from '../../validators/commands/checkSwcDependencies';
9
+ import { checkReactCompilerDependencies } from '../../validators/commands/checkReactCompilerDependencies';
9
10
 
10
11
  export type Params = Parameters<BuildCommandType>[0] & {
11
12
  target: string;
@@ -85,6 +86,7 @@ class BuildCommand extends CLICommand<Params> {
85
86
  checkDependencies,
86
87
  checkPwaDependencies,
87
88
  checkSwcDependencies,
89
+ checkReactCompilerDependencies,
88
90
  ];
89
91
 
90
92
  action(parameters: Params) {
@@ -6,6 +6,7 @@ import { runMigrationsAndCheckVersions } from '../../validators/commands/runMigr
6
6
  import type { StartCommand as StartCommandType } from '../../api/start';
7
7
  import { checkPwaDependencies } from '../../validators/commands/checkPwaDependencies';
8
8
  import { checkSwcDependencies } from '../../validators/commands/checkSwcDependencies';
9
+ import { checkReactCompilerDependencies } from '../../validators/commands/checkReactCompilerDependencies';
9
10
 
10
11
  export type Params = Parameters<StartCommandType>[0] & {
11
12
  target: string;
@@ -138,6 +139,7 @@ export class StartCommand extends CLICommand<Params> {
138
139
  checkDependencies,
139
140
  checkPwaDependencies,
140
141
  checkSwcDependencies,
142
+ checkReactCompilerDependencies,
141
143
  ];
142
144
 
143
145
  action(parameters) {
@@ -4,6 +4,7 @@ import { checkApplication } from '../../validators/commands/checkBuild';
4
4
  import { runMigrationsAndCheckVersions } from '../../validators/commands/runMigrationsAndCheckVersions';
5
5
  import { checkPwaDependencies } from '../../validators/commands/checkPwaDependencies';
6
6
  import { checkSwcDependencies } from '../../validators/commands/checkSwcDependencies';
7
+ import { checkReactCompilerDependencies } from '../../validators/commands/checkReactCompilerDependencies';
7
8
 
8
9
  export interface Params {
9
10
  target: string;
@@ -111,6 +112,7 @@ export class StartProdCommand extends CLICommand<Params> {
111
112
  runMigrationsAndCheckVersions,
112
113
  checkPwaDependencies,
113
114
  checkSwcDependencies,
115
+ checkReactCompilerDependencies,
114
116
  ];
115
117
 
116
118
  action(parameters: Params) {
@@ -3,6 +3,8 @@ import browserslist from 'browserslist';
3
3
  import envTargets from '@tinkoff/browserslist-config';
4
4
  import { sync as resolve } from 'resolve';
5
5
  import type { TransformOptions } from '@babel/core';
6
+
7
+ import { getReactCompilerPlugin } from './plugins/react-compiler';
6
8
  import type { TranspilerConfig } from '../webpack/utils/transpiler';
7
9
 
8
10
  const envConfig = {
@@ -48,6 +50,7 @@ export const babelConfigFactory = ({
48
50
  hot = false,
49
51
  excludesPresetEnv,
50
52
  rootDir = process.cwd(),
53
+ reactCompiler = false,
51
54
  }: Partial<TranspilerConfig>) => {
52
55
  const cfg = envConfig[env] || {};
53
56
  let resultTarget = target;
@@ -118,6 +121,8 @@ export const babelConfigFactory = ({
118
121
  .filter(Boolean) as TransformOptions['presets'],
119
122
 
120
123
  plugins: [
124
+ // React compiler must be the first plugin in the chain
125
+ getReactCompilerPlugin({ isServer, options: reactCompiler }),
121
126
  // TODO: useESModules is deprecated and should work automatically - https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
122
127
  ['@babel/transform-runtime', { useESModules: !(isServer && env === 'development') }],
123
128
  path.resolve(__dirname, './plugins/lazy-component/legacy-universal-replace'), // TODO: удалить плагин после того как отпадёт необходимость поддерживать легаси
@@ -0,0 +1,39 @@
1
+ import { resolveReactVersion } from '../../../utils/resolveReactVersion';
2
+ import type { ReactCompilerOptions } from '../../../typings/configEntry/cli';
3
+
4
+ type ReactCompilerTarget = '17' | '18' | '19';
5
+
6
+ const resolveTarget = (): ReactCompilerTarget => {
7
+ const resolved = resolveReactVersion();
8
+ const major = resolved.major.toString() as ReactCompilerTarget;
9
+
10
+ if (['17', '18', '19'].includes(major)) {
11
+ return major;
12
+ }
13
+
14
+ throw new Error(
15
+ `Resolved React version is ${resolved.version} which is not supported. Supported versions are 17, 18 and 19.`
16
+ );
17
+ };
18
+
19
+ export const getReactCompilerPlugin = ({
20
+ options,
21
+ isServer,
22
+ }: {
23
+ options: boolean | ReactCompilerOptions;
24
+ isServer: boolean;
25
+ }) => {
26
+ if (!options || isServer) {
27
+ return undefined;
28
+ }
29
+
30
+ const compilerOptions = typeof options === 'boolean' ? {} : options;
31
+
32
+ return [
33
+ 'babel-plugin-react-compiler',
34
+ {
35
+ ...compilerOptions,
36
+ target: resolveTarget(),
37
+ },
38
+ ];
39
+ };
@@ -5,7 +5,7 @@ import { getSwcOptions } from '../../swc';
5
5
  import { babelConfigFactory } from '../../babel';
6
6
  import type { Env } from '../../../typings/Env';
7
7
  import type { Target } from '../../../typings/target';
8
- import type { CliConfigEntry } from '../../../typings/configEntry/cli';
8
+ import type { CliConfigEntry, ReactCompilerOptions } from '../../../typings/configEntry/cli';
9
9
 
10
10
  export type TranspilerConfig = {
11
11
  env: Env;
@@ -23,6 +23,7 @@ export type TranspilerConfig = {
23
23
  hot: boolean;
24
24
  excludesPresetEnv: string[];
25
25
  rootDir: string;
26
+ reactCompiler: boolean | ReactCompilerOptions;
26
27
  };
27
28
 
28
29
  export const addTranspilerLoader =
@@ -56,7 +57,7 @@ export const getTranspilerConfig = (
56
57
  alias,
57
58
  enableFillActionNamePlugin,
58
59
  excludesPresetEnv,
59
- experiments: { enableFillDeclareActionNamePlugin },
60
+ experiments: { enableFillDeclareActionNamePlugin, reactCompiler },
60
61
  } = configManager;
61
62
  const { env, modern } = configManager;
62
63
 
@@ -80,7 +81,8 @@ Just check or add configuration to your tsconfig file and remove alias from tram
80
81
  loader: true,
81
82
  modules: false,
82
83
  typescript: false,
83
- ...overrideOptions,
84
84
  enableFillDeclareActionNamePlugin,
85
+ reactCompiler,
86
+ ...overrideOptions,
85
87
  };
86
88
  };
@@ -71,6 +71,7 @@ it('should populate defaults for config', () => {
71
71
  "enabled": false,
72
72
  },
73
73
  },
74
+ "reactCompiler": false,
74
75
  "reactTransitions": false,
75
76
  "serverRunner": "thread",
76
77
  "transpilation": {
@@ -146,6 +147,7 @@ it('should populate defaults for config', () => {
146
147
  "useImportModule": true,
147
148
  },
148
149
  "minifier": "terser",
150
+ "reactCompiler": false,
149
151
  "transpilation": {
150
152
  "loader": "babel",
151
153
  },
@@ -314,6 +316,7 @@ it('should populate defaults for overridable options', () => {
314
316
  "enabled": false,
315
317
  },
316
318
  },
319
+ "reactCompiler": false,
317
320
  "reactTransitions": false,
318
321
  "serverRunner": "thread",
319
322
  "transpilation": {
@@ -407,6 +410,7 @@ it('should populate defaults for overridable options', () => {
407
410
  "useImportModule": true,
408
411
  },
409
412
  "minifier": "terser",
413
+ "reactCompiler": false,
410
414
  "transpilation": {
411
415
  "loader": {
412
416
  "development": "babel",
@@ -940,6 +940,45 @@
940
940
  "title": "Включает использование плагина fill-declare-action-name",
941
941
  "default": false,
942
942
  "type": "boolean"
943
+ },
944
+ "reactCompiler": {
945
+ "description": "https://github.com/facebook/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts",
946
+ "title": "Enable React Compiler. You can pass some options, or use it with meaningful defaults.",
947
+ "default": false,
948
+ "anyOf": [
949
+ {
950
+ "type": "object",
951
+ "properties": {
952
+ "sources": {
953
+ "type": "array",
954
+ "items": {
955
+ "type": "string"
956
+ }
957
+ },
958
+ "compilationMode": {
959
+ "enum": [
960
+ "all",
961
+ "annotation",
962
+ "infer"
963
+ ],
964
+ "type": "string"
965
+ },
966
+ "panicThreshold": {
967
+ "title": "Determines the point at which compiler should throw an error",
968
+ "enum": [
969
+ "ALL_ERRORS",
970
+ "CRITICAL_ERRORS",
971
+ "NONE"
972
+ ],
973
+ "type": "string"
974
+ }
975
+ },
976
+ "additionalProperties": false
977
+ },
978
+ {
979
+ "type": "boolean"
980
+ }
981
+ ]
943
982
  }
944
983
  },
945
984
  "additionalProperties": false
@@ -1188,23 +1227,23 @@
1188
1227
  "dotAll": {
1189
1228
  "type": "boolean"
1190
1229
  },
1191
- "__@match@7335": {
1230
+ "__@match@7341": {
1192
1231
  "type": "object",
1193
1232
  "additionalProperties": false
1194
1233
  },
1195
- "__@replace@7337": {
1234
+ "__@replace@7343": {
1196
1235
  "type": "object",
1197
1236
  "additionalProperties": false
1198
1237
  },
1199
- "__@search@7340": {
1238
+ "__@search@7346": {
1200
1239
  "type": "object",
1201
1240
  "additionalProperties": false
1202
1241
  },
1203
- "__@split@7342": {
1242
+ "__@split@7348": {
1204
1243
  "type": "object",
1205
1244
  "additionalProperties": false
1206
1245
  },
1207
- "__@matchAll@7344": {
1246
+ "__@matchAll@7350": {
1208
1247
  "type": "object",
1209
1248
  "additionalProperties": false
1210
1249
  }
@@ -1715,6 +1754,45 @@
1715
1754
  "title": "Включает использование плагина fill-declare-action-name",
1716
1755
  "default": false,
1717
1756
  "type": "boolean"
1757
+ },
1758
+ "reactCompiler": {
1759
+ "description": "https://github.com/facebook/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts",
1760
+ "title": "Enable React Compiler. You can pass some options, or use it with meaningful defaults.",
1761
+ "default": false,
1762
+ "anyOf": [
1763
+ {
1764
+ "type": "object",
1765
+ "properties": {
1766
+ "sources": {
1767
+ "type": "array",
1768
+ "items": {
1769
+ "type": "string"
1770
+ }
1771
+ },
1772
+ "compilationMode": {
1773
+ "enum": [
1774
+ "all",
1775
+ "annotation",
1776
+ "infer"
1777
+ ],
1778
+ "type": "string"
1779
+ },
1780
+ "panicThreshold": {
1781
+ "title": "Determines the point at which compiler should throw an error",
1782
+ "enum": [
1783
+ "ALL_ERRORS",
1784
+ "CRITICAL_ERRORS",
1785
+ "NONE"
1786
+ ],
1787
+ "type": "string"
1788
+ }
1789
+ },
1790
+ "additionalProperties": false
1791
+ },
1792
+ {
1793
+ "type": "boolean"
1794
+ }
1795
+ ]
1718
1796
  }
1719
1797
  },
1720
1798
  "additionalProperties": false
@@ -1901,23 +1979,23 @@
1901
1979
  "dotAll": {
1902
1980
  "type": "boolean"
1903
1981
  },
1904
- "__@match@7335": {
1982
+ "__@match@7341": {
1905
1983
  "type": "object",
1906
1984
  "additionalProperties": false
1907
1985
  },
1908
- "__@replace@7337": {
1986
+ "__@replace@7343": {
1909
1987
  "type": "object",
1910
1988
  "additionalProperties": false
1911
1989
  },
1912
- "__@search@7340": {
1990
+ "__@search@7346": {
1913
1991
  "type": "object",
1914
1992
  "additionalProperties": false
1915
1993
  },
1916
- "__@split@7342": {
1994
+ "__@split@7348": {
1917
1995
  "type": "object",
1918
1996
  "additionalProperties": false
1919
1997
  },
1920
- "__@matchAll@7344": {
1998
+ "__@matchAll@7350": {
1921
1999
  "type": "object",
1922
2000
  "additionalProperties": false
1923
2001
  }
@@ -2428,6 +2506,45 @@
2428
2506
  "title": "Включает использование плагина fill-declare-action-name",
2429
2507
  "default": false,
2430
2508
  "type": "boolean"
2509
+ },
2510
+ "reactCompiler": {
2511
+ "description": "https://github.com/facebook/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts",
2512
+ "title": "Enable React Compiler. You can pass some options, or use it with meaningful defaults.",
2513
+ "default": false,
2514
+ "anyOf": [
2515
+ {
2516
+ "type": "object",
2517
+ "properties": {
2518
+ "sources": {
2519
+ "type": "array",
2520
+ "items": {
2521
+ "type": "string"
2522
+ }
2523
+ },
2524
+ "compilationMode": {
2525
+ "enum": [
2526
+ "all",
2527
+ "annotation",
2528
+ "infer"
2529
+ ],
2530
+ "type": "string"
2531
+ },
2532
+ "panicThreshold": {
2533
+ "title": "Determines the point at which compiler should throw an error",
2534
+ "enum": [
2535
+ "ALL_ERRORS",
2536
+ "CRITICAL_ERRORS",
2537
+ "NONE"
2538
+ ],
2539
+ "type": "string"
2540
+ }
2541
+ },
2542
+ "additionalProperties": false
2543
+ },
2544
+ {
2545
+ "type": "boolean"
2546
+ }
2547
+ ]
2431
2548
  }
2432
2549
  },
2433
2550
  "additionalProperties": false
@@ -2614,23 +2731,23 @@
2614
2731
  "dotAll": {
2615
2732
  "type": "boolean"
2616
2733
  },
2617
- "__@match@7335": {
2734
+ "__@match@7341": {
2618
2735
  "type": "object",
2619
2736
  "additionalProperties": false
2620
2737
  },
2621
- "__@replace@7337": {
2738
+ "__@replace@7343": {
2622
2739
  "type": "object",
2623
2740
  "additionalProperties": false
2624
2741
  },
2625
- "__@search@7340": {
2742
+ "__@search@7346": {
2626
2743
  "type": "object",
2627
2744
  "additionalProperties": false
2628
2745
  },
2629
- "__@split@7342": {
2746
+ "__@split@7348": {
2630
2747
  "type": "object",
2631
2748
  "additionalProperties": false
2632
2749
  },
2633
- "__@matchAll@7344": {
2750
+ "__@matchAll@7350": {
2634
2751
  "type": "object",
2635
2752
  "additionalProperties": false
2636
2753
  }
@@ -100,6 +100,7 @@ describe('JSON schema для tramvai.json', () => {
100
100
  "enabled": false,
101
101
  },
102
102
  },
103
+ "reactCompiler": false,
103
104
  "reactTransitions": false,
104
105
  "serverRunner": "thread",
105
106
  "transpilation": {
@@ -175,6 +176,7 @@ describe('JSON schema для tramvai.json', () => {
175
176
  "useImportModule": true,
176
177
  },
177
178
  "minifier": "terser",
179
+ "reactCompiler": false,
178
180
  "transpilation": {
179
181
  "loader": "babel",
180
182
  },
@@ -21,6 +21,21 @@ type Notifications = {
21
21
  activateTerminalOnError?: boolean;
22
22
  };
23
23
 
24
+ export type ReactCompilerOptions = {
25
+ /*
26
+ * @title Array of paths which React compiler applies to. Ignore node_moduled by default
27
+ */
28
+ sources?: Array<string>;
29
+ /*
30
+ * @title Determines the strategy for determining which functions to compile
31
+ */
32
+ compilationMode?: 'infer' | 'annotation' | 'all';
33
+ /**
34
+ * @title Determines the point at which compiler should throw an error
35
+ */
36
+ panicThreshold?: 'ALL_ERRORS' | 'CRITICAL_ERRORS' | 'NONE';
37
+ };
38
+
24
39
  export type WebpackExperiments = Omit<
25
40
  Configuration['experiments'],
26
41
  'buildHttp' | 'lazyCompilation' | 'css'
@@ -85,6 +100,14 @@ export interface Experiments {
85
100
  * @default false
86
101
  */
87
102
  enableFillDeclareActionNamePlugin: boolean;
103
+
104
+ /**
105
+ * https://github.com/facebook/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts
106
+ *
107
+ * @title Enable React Compiler. You can pass some options, or use it with meaningful defaults.
108
+ * @default false
109
+ */
110
+ reactCompiler?: boolean | ReactCompilerOptions;
88
111
  }
89
112
 
90
113
  /**
@@ -0,0 +1,8 @@
1
+ import once from '@tinkoff/utils/function/once';
2
+ import semver from 'semver';
3
+
4
+ export const resolveReactVersion = once(() => {
5
+ const reactVersion = require('react').version;
6
+
7
+ return semver.parse(reactVersion);
8
+ });
@@ -0,0 +1,82 @@
1
+ import type { Validator } from './validator.h';
2
+ import type { TranspilationLoader } from '../../typings/configEntry/cli';
3
+ import type { ApplicationConfigEntry } from '../../typings/configEntry/application';
4
+ import { resolveReactVersion } from '../../utils/resolveReactVersion';
5
+
6
+ type ReactCompilerTarget = '17' | '18' | '19';
7
+
8
+ const VALIDATOR_NAME = 'checkReactCompilerDependencies';
9
+
10
+ const getLoaderFromConfig = (config: ApplicationConfigEntry): TranspilationLoader => {
11
+ const field = config.experiments?.transpilation?.loader;
12
+
13
+ if (field === undefined) {
14
+ return 'babel';
15
+ }
16
+
17
+ if (typeof field === 'string') {
18
+ return field as unknown as TranspilationLoader;
19
+ }
20
+
21
+ return field[process.env.NODE_ENV] ?? 'babel';
22
+ };
23
+
24
+ const resolveBabelPlugin = () => {
25
+ try {
26
+ require.resolve('babel-plugin-react-compiler');
27
+ } catch (error) {
28
+ if (error.code === 'MODULE_NOT_FOUND') {
29
+ throw new Error(
30
+ 'Can not resolve the `babel-plugin-react-compiler`. It is required to use the React Compiler. Please install it.'
31
+ );
32
+ }
33
+
34
+ throw error;
35
+ }
36
+ };
37
+
38
+ const resolveCompilerRuntime = (reactMajor: ReactCompilerTarget) => {
39
+ if (reactMajor === '19') {
40
+ return;
41
+ }
42
+
43
+ try {
44
+ require.resolve('react-compiler-runtime');
45
+ } catch (error) {
46
+ if (error.code === 'MODULE_NOT_FOUND') {
47
+ throw new Error(
48
+ 'React versions prior to 19 require the `react-compiler-runtime` package to be installed. Please install it.'
49
+ );
50
+ }
51
+
52
+ throw error;
53
+ }
54
+ };
55
+
56
+ export const checkReactCompilerDependencies: Validator = async ({ config }, params) => {
57
+ const configEntry = config.getProject(params.target) as ApplicationConfigEntry;
58
+
59
+ if (!configEntry.experiments?.reactCompiler) {
60
+ return { name: VALIDATOR_NAME, status: 'ok' };
61
+ }
62
+
63
+ const loader = getLoaderFromConfig(configEntry);
64
+
65
+ if (loader === 'swc') {
66
+ throw new Error(`React compiler is not supported when using SWC transpiler.`);
67
+ }
68
+
69
+ const reactVersion = resolveReactVersion();
70
+ const reactMajor = reactVersion.major.toString() as ReactCompilerTarget;
71
+
72
+ if (!['17', '18', '19'].includes(reactMajor)) {
73
+ throw new Error(
74
+ `Resolved React version is ${reactVersion.version} which is not supported. Supported versions are 17, 18 and 19.`
75
+ );
76
+ }
77
+
78
+ resolveBabelPlugin();
79
+ resolveCompilerRuntime(reactMajor);
80
+
81
+ return { name: VALIDATOR_NAME, status: 'ok' };
82
+ };
@@ -1,6 +1,6 @@
1
1
  import { sync as resolve } from 'resolve';
2
2
  import type { Validator } from './validator.h';
3
- import type { Experiments, TranspilationLoader, Minifier } from '../../typings/configEntry/cli';
3
+ import type { TranspilationLoader, Minifier } from '../../typings/configEntry/cli';
4
4
 
5
5
  const validator = 'checkSwcDependencies';
6
6