@nx/vite 17.0.2 → 17.0.4

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 (116) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -4
  3. package/generators.json +3 -3
  4. package/migrations.json +90 -0
  5. package/package.json +9 -7
  6. package/plugin.d.ts +1 -0
  7. package/plugin.js +21 -0
  8. package/plugin.js.map +1 -0
  9. package/plugins/nx-tsconfig-paths.plugin.js +9 -5
  10. package/plugins/nx-tsconfig-paths.plugin.js.map +1 -1
  11. package/plugins/rollup-replace-files.plugin.d.ts +3 -3
  12. package/plugins/rollup-replace-files.plugin.js +2 -2
  13. package/plugins/rollup-replace-files.plugin.js.map +1 -1
  14. package/src/executors/build/build.impl.d.ts +5 -1
  15. package/src/executors/build/build.impl.js +90 -21
  16. package/src/executors/build/build.impl.js.map +1 -1
  17. package/src/executors/build/schema.d.ts +5 -18
  18. package/src/executors/build/schema.json +4 -106
  19. package/src/executors/dev-server/dev-server.impl.js +74 -9
  20. package/src/executors/dev-server/dev-server.impl.js.map +1 -1
  21. package/src/executors/dev-server/schema.d.ts +0 -10
  22. package/src/executors/dev-server/schema.json +0 -63
  23. package/src/executors/preview-server/preview-server.impl.d.ts +1 -1
  24. package/src/executors/preview-server/preview-server.impl.js +79 -15
  25. package/src/executors/preview-server/preview-server.impl.js.map +1 -1
  26. package/src/executors/preview-server/schema.d.ts +0 -7
  27. package/src/executors/preview-server/schema.json +1 -51
  28. package/src/executors/test/lib/nx-reporter.d.ts +14 -0
  29. package/src/executors/test/lib/nx-reporter.js +40 -0
  30. package/src/executors/test/lib/nx-reporter.js.map +1 -0
  31. package/src/executors/test/lib/utils.d.ts +4 -0
  32. package/src/executors/test/lib/utils.js +77 -0
  33. package/src/executors/test/lib/utils.js.map +1 -0
  34. package/src/executors/test/schema.d.ts +3 -8
  35. package/src/executors/test/schema.json +11 -43
  36. package/src/executors/test/vitest.impl.js +20 -112
  37. package/src/executors/test/vitest.impl.js.map +1 -1
  38. package/src/generators/configuration/configuration.d.ts +2 -1
  39. package/src/generators/configuration/configuration.js +49 -87
  40. package/src/generators/configuration/configuration.js.map +1 -1
  41. package/src/generators/configuration/lib/convert-non-vite.d.ts +5 -0
  42. package/src/generators/configuration/lib/convert-non-vite.js +62 -0
  43. package/src/generators/configuration/lib/convert-non-vite.js.map +1 -0
  44. package/src/generators/configuration/schema.d.ts +1 -3
  45. package/src/generators/configuration/schema.json +0 -12
  46. package/src/generators/init/init.d.ts +4 -3
  47. package/src/generators/init/init.js +50 -67
  48. package/src/generators/init/init.js.map +1 -1
  49. package/src/generators/init/lib/utils.d.ts +6 -0
  50. package/src/generators/init/lib/utils.js +80 -0
  51. package/src/generators/init/lib/utils.js.map +1 -0
  52. package/src/generators/init/schema.d.ts +5 -5
  53. package/src/generators/init/schema.json +17 -20
  54. package/src/generators/vitest/files/tsconfig.spec.json__tmpl__ +2 -1
  55. package/src/generators/vitest/schema.d.ts +2 -1
  56. package/src/generators/vitest/schema.json +2 -2
  57. package/src/generators/vitest/vitest-generator.d.ts +2 -1
  58. package/src/generators/vitest/vitest-generator.js +34 -10
  59. package/src/generators/vitest/vitest-generator.js.map +1 -1
  60. package/src/migrations/update-15-3-1/update-vite-tsconfig-paths.js.map +1 -1
  61. package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js +3 -17
  62. package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js.map +1 -1
  63. package/src/migrations/update-17-1-0/move-target-defaults.d.ts +2 -0
  64. package/src/migrations/update-17-1-0/move-target-defaults.js +77 -0
  65. package/src/migrations/update-17-1-0/move-target-defaults.js.map +1 -0
  66. package/src/migrations/update-17-2-0/lib/add-file-replacements.d.ts +2 -0
  67. package/src/migrations/update-17-2-0/lib/add-file-replacements.js +67 -0
  68. package/src/migrations/update-17-2-0/lib/add-file-replacements.js.map +1 -0
  69. package/src/migrations/update-17-2-0/lib/edit-build-config.d.ts +2 -0
  70. package/src/migrations/update-17-2-0/lib/edit-build-config.js +121 -0
  71. package/src/migrations/update-17-2-0/lib/edit-build-config.js.map +1 -0
  72. package/src/migrations/update-17-2-0/lib/edit-test-config.d.ts +2 -0
  73. package/src/migrations/update-17-2-0/lib/edit-test-config.js +83 -0
  74. package/src/migrations/update-17-2-0/lib/edit-test-config.js.map +1 -0
  75. package/src/migrations/update-17-2-0/update-vite-config.d.ts +5 -0
  76. package/src/migrations/update-17-2-0/update-vite-config.js +68 -0
  77. package/src/migrations/update-17-2-0/update-vite-config.js.map +1 -0
  78. package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.d.ts +3 -0
  79. package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.js +117 -0
  80. package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.js.map +1 -0
  81. package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.d.ts +2 -0
  82. package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.js +45 -0
  83. package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.js.map +1 -0
  84. package/src/plugins/plugin.d.ts +10 -0
  85. package/src/plugins/plugin.js +226 -0
  86. package/src/plugins/plugin.js.map +1 -0
  87. package/src/utils/ensure-dependencies.d.ts +8 -0
  88. package/src/utils/ensure-dependencies.js +34 -0
  89. package/src/utils/ensure-dependencies.js.map +1 -0
  90. package/src/utils/executor-utils.d.ts +2 -0
  91. package/src/utils/executor-utils.js +22 -7
  92. package/src/utils/executor-utils.js.map +1 -1
  93. package/src/utils/find-vite-config.d.ts +3 -0
  94. package/src/utils/find-vite-config.js +46 -0
  95. package/src/utils/find-vite-config.js.map +1 -0
  96. package/src/utils/generator-utils.d.ts +10 -12
  97. package/src/utils/generator-utils.js +135 -213
  98. package/src/utils/generator-utils.js.map +1 -1
  99. package/src/utils/options-utils.d.ts +3 -19
  100. package/src/utils/options-utils.js +25 -68
  101. package/src/utils/options-utils.js.map +1 -1
  102. package/src/utils/test-files/react-lib-non-buildable-jest.json +1 -4
  103. package/src/utils/test-files/react-lib-non-buildable-vitest.json +1 -4
  104. package/src/utils/test-files/react-mixed-project.config.json +1 -6
  105. package/src/utils/test-files/react-vite-project.config.json +1 -4
  106. package/src/utils/test-files/unknown-project.config.json +1 -4
  107. package/src/utils/test-utils.d.ts +1 -1
  108. package/src/utils/test-utils.js +10 -18
  109. package/src/utils/test-utils.js.map +1 -1
  110. package/src/utils/versions.d.ts +7 -9
  111. package/src/utils/versions.js +7 -15
  112. package/src/utils/versions.js.map +1 -1
  113. package/src/utils/vite-config-edit-utils.js +1 -1
  114. package/src/utils/vite-config-edit-utils.js.map +1 -1
  115. package/src/utils/test-files/react-project.config.json +0 -85
  116. package/src/utils/test-files/web-project.config.json +0 -72
@@ -6,17 +6,17 @@ function _export(target, all) {
6
6
  });
7
7
  }
8
8
  _export(exports, {
9
- findExistingTargetsInProject: function() {
10
- return findExistingTargetsInProject;
9
+ findExistingJsBuildTargetInProject: function() {
10
+ return findExistingJsBuildTargetInProject;
11
11
  },
12
12
  addOrChangeTestTarget: function() {
13
13
  return addOrChangeTestTarget;
14
14
  },
15
- addOrChangeBuildTarget: function() {
16
- return addOrChangeBuildTarget;
15
+ addBuildTarget: function() {
16
+ return addBuildTarget;
17
17
  },
18
- addOrChangeServeTarget: function() {
19
- return addOrChangeServeTarget;
18
+ addServeTarget: function() {
19
+ return addServeTarget;
20
20
  },
21
21
  addPreviewTarget: function() {
22
22
  return addPreviewTarget;
@@ -42,42 +42,20 @@ _export(exports, {
42
42
  handleUnsupportedUserProvidedTargets: function() {
43
43
  return handleUnsupportedUserProvidedTargets;
44
44
  },
45
- handleUnknownExecutors: function() {
46
- return handleUnknownExecutors;
45
+ handleUnknownConfiguration: function() {
46
+ return handleUnknownConfiguration;
47
47
  }
48
48
  });
49
- const _extends = require("@swc/helpers/_/_extends");
50
49
  const _devkit = require("@nx/devkit");
51
50
  const _viteconfigeditutils = require("./vite-config-edit-utils");
52
- function findExistingTargetsInProject(targets, userProvidedTargets) {
53
- const output = {
54
- validFoundTargetName: {},
55
- projectContainsUnsupportedExecutor: false,
56
- userProvidedTargetIsUnsupported: {},
57
- alreadyHasNxViteTargets: {}
58
- };
51
+ const _addbuildtargetdefaults = require("@nx/devkit/src/generators/add-build-target-defaults");
52
+ function findExistingJsBuildTargetInProject(targets) {
53
+ const output = {};
59
54
  const supportedExecutors = {
60
55
  build: [
61
- '@nxext/vite:build',
62
56
  '@nx/js:babel',
63
57
  '@nx/js:swc',
64
- '@nx/webpack:webpack',
65
- '@nx/rollup:rollup',
66
- '@nrwl/js:babel',
67
- '@nrwl/js:swc',
68
- '@nrwl/webpack:webpack',
69
- '@nrwl/rollup:rollup',
70
- '@nrwl/web:rollup'
71
- ],
72
- serve: [
73
- '@nxext/vite:dev',
74
- '@nx/webpack:dev-server',
75
- '@nrwl/webpack:dev-server'
76
- ],
77
- test: [
78
- '@nx/jest:jest',
79
- '@nrwl/jest:jest',
80
- '@nxext/vitest:vitest'
58
+ '@nx/rollup:rollup'
81
59
  ]
82
60
  };
83
61
  const unsupportedExecutors = [
@@ -92,7 +70,6 @@ function findExistingTargetsInProject(targets, userProvidedTargets) {
92
70
  '@nx/react-native:build-android',
93
71
  '@nx/react-native:bundle',
94
72
  '@nx/next:build',
95
- '@nx/next:server',
96
73
  '@nx/js:tsc',
97
74
  '@nrwl/angular:ng-packagr-lite',
98
75
  '@nrwl/angular:package',
@@ -105,63 +82,29 @@ function findExistingTargetsInProject(targets, userProvidedTargets) {
105
82
  '@nrwl/react-native:build-android',
106
83
  '@nrwl/react-native:bundle',
107
84
  '@nrwl/next:build',
108
- '@nrwl/next:server',
109
85
  '@nrwl/js:tsc',
110
86
  '@angular-devkit/build-angular:browser',
111
- '@angular-devkit/build-angular:dev-server'
87
+ '@angular-devkit/build-angular:browser-esbuild',
88
+ '@angular-devkit/build-angular:application'
112
89
  ];
113
- // First, we check if the user has provided a target
114
- // If they have, we check if the executor the target is using is supported
115
- // If it's not supported, then we set the unsupported flag to true for that target
116
- function checkUserProvidedTarget(target) {
117
- if (userProvidedTargets == null ? void 0 : userProvidedTargets[target]) {
118
- var _targets_userProvidedTargets_target;
119
- if (supportedExecutors[target].includes((_targets_userProvidedTargets_target = targets[userProvidedTargets[target]]) == null ? void 0 : _targets_userProvidedTargets_target.executor)) {
120
- output.validFoundTargetName[target] = userProvidedTargets[target];
121
- } else {
122
- output.userProvidedTargetIsUnsupported[target] = true;
123
- }
124
- }
125
- }
126
- checkUserProvidedTarget('build');
127
- checkUserProvidedTarget('serve');
128
- checkUserProvidedTarget('test');
129
- // Returns early when we have a build, serve, and test targets.
130
- if (output.validFoundTargetName.build && output.validFoundTargetName.serve && output.validFoundTargetName.test) {
131
- return output;
132
- }
133
- // We try to find the targets that are using the supported executors
134
- // for build, serve and test, since these are the ones we will be converting
90
+ // We try to find the target that is using the supported executors
91
+ // for build since this is the one we will be converting
135
92
  for(const target in targets){
136
- var _hasViteTargets, _hasViteTargets1, _hasViteTargets2, _hasViteTargets3, _output;
137
93
  const executorName = targets[target].executor;
138
- const hasViteTargets = output.alreadyHasNxViteTargets;
139
- (_hasViteTargets = hasViteTargets).build || (_hasViteTargets.build = executorName === '@nx/vite:build' || executorName === '@nrwl/vite:build');
140
- (_hasViteTargets1 = hasViteTargets).serve || (_hasViteTargets1.serve = executorName === '@nx/vite:dev-server' || executorName === '@nrwl/vite:dev-server');
141
- (_hasViteTargets2 = hasViteTargets).test || (_hasViteTargets2.test = executorName === '@nx/vite:test' || executorName === '@nrwl/vite:test');
142
- (_hasViteTargets3 = hasViteTargets).preview || (_hasViteTargets3.preview = executorName === '@nx/vite:preview-server' || executorName === '@nrwl/vite:preview-server');
143
- const foundTargets = output.validFoundTargetName;
144
- if (!foundTargets.build && supportedExecutors.build.includes(executorName)) {
145
- foundTargets.build = target;
146
- }
147
- if (!foundTargets.serve && supportedExecutors.serve.includes(executorName)) {
148
- foundTargets.serve = target;
94
+ if (supportedExecutors.build.includes(executorName)) {
95
+ output.supported = target;
96
+ } else if (unsupportedExecutors.includes(executorName)) {
97
+ output.unsupported = target;
149
98
  }
150
- if (!foundTargets.test && supportedExecutors.test.includes(executorName)) {
151
- foundTargets.test = target;
152
- }
153
- (_output = output).projectContainsUnsupportedExecutor || (_output.projectContainsUnsupportedExecutor = unsupportedExecutors.includes(executorName));
154
99
  }
155
100
  return output;
156
101
  }
157
102
  function addOrChangeTestTarget(tree, options, target) {
158
103
  var _project;
159
104
  const project = (0, _devkit.readProjectConfiguration)(tree, options.project);
160
- const coveragePath = (0, _devkit.joinPathFragments)('coverage', project.root === '.' ? options.project : project.root);
105
+ const reportsDirectory = (0, _devkit.joinPathFragments)((0, _devkit.offsetFromRoot)(project.root), 'coverage', project.root === '.' ? options.project : project.root);
161
106
  const testOptions = {
162
- passWithNoTests: true,
163
- // vitest runs in the project root so we have to offset to the workspaceRoot
164
- reportsDirectory: (0, _devkit.joinPathFragments)((0, _devkit.offsetFromRoot)(project.root), coveragePath)
107
+ reportsDirectory
165
108
  };
166
109
  var _targets;
167
110
  (_targets = (_project = project).targets) != null ? _targets : _project.targets = {};
@@ -180,82 +123,55 @@ function addOrChangeTestTarget(tree, options, target) {
180
123
  }
181
124
  (0, _devkit.updateProjectConfiguration)(tree, options.project, project);
182
125
  }
183
- function addOrChangeBuildTarget(tree, options, target) {
126
+ function addBuildTarget(tree, options, target) {
184
127
  var _project;
128
+ (0, _addbuildtargetdefaults.addBuildTargetDefaults)(tree, '@nx/vite:build');
185
129
  const project = (0, _devkit.readProjectConfiguration)(tree, options.project);
186
130
  const buildOptions = {
187
131
  outputPath: (0, _devkit.joinPathFragments)('dist', project.root != '.' ? project.root : options.project)
188
132
  };
189
133
  var _targets;
190
134
  (_targets = (_project = project).targets) != null ? _targets : _project.targets = {};
191
- if (project.targets[target]) {
192
- var _project_targets_target_options;
193
- buildOptions.fileReplacements = (_project_targets_target_options = project.targets[target].options) == null ? void 0 : _project_targets_target_options.fileReplacements;
194
- if (project.targets[target].executor === '@nxext/vite:build') {
195
- var _project_targets_target_options1, _project_targets_target_options2;
196
- buildOptions.base = (_project_targets_target_options1 = project.targets[target].options) == null ? void 0 : _project_targets_target_options1.baseHref;
197
- buildOptions.sourcemap = (_project_targets_target_options2 = project.targets[target].options) == null ? void 0 : _project_targets_target_options2.sourcemaps;
198
- }
199
- project.targets[target].options = _extends._({}, buildOptions);
200
- project.targets[target].executor = '@nx/vite:build';
201
- } else {
202
- project.targets[target] = {
203
- executor: '@nx/vite:build',
204
- outputs: [
205
- '{options.outputPath}'
206
- ],
207
- defaultConfiguration: 'production',
208
- options: buildOptions,
209
- configurations: {
210
- development: {
211
- mode: 'development'
212
- },
213
- production: {
214
- mode: 'production'
215
- }
135
+ project.targets[target] = {
136
+ executor: '@nx/vite:build',
137
+ outputs: [
138
+ '{options.outputPath}'
139
+ ],
140
+ defaultConfiguration: 'production',
141
+ options: buildOptions,
142
+ configurations: {
143
+ development: {
144
+ mode: 'development'
145
+ },
146
+ production: {
147
+ mode: 'production'
216
148
  }
217
- };
218
- }
149
+ }
150
+ };
219
151
  (0, _devkit.updateProjectConfiguration)(tree, options.project, project);
220
152
  }
221
- function addOrChangeServeTarget(tree, options, target) {
153
+ function addServeTarget(tree, options, target) {
222
154
  var _project;
223
155
  const project = (0, _devkit.readProjectConfiguration)(tree, options.project);
224
156
  var _targets;
225
157
  (_targets = (_project = project).targets) != null ? _targets : _project.targets = {};
226
- if (project.targets[target]) {
227
- var _project_targets_target_options, _project_targets_target_options1, _project_targets_target_options2;
228
- const serveTarget = project.targets[target];
229
- const serveOptions = {
230
- buildTarget: `${options.project}:build`,
231
- https: (_project_targets_target_options = project.targets[target].options) == null ? void 0 : _project_targets_target_options.https,
232
- hmr: (_project_targets_target_options1 = project.targets[target].options) == null ? void 0 : _project_targets_target_options1.hmr,
233
- open: (_project_targets_target_options2 = project.targets[target].options) == null ? void 0 : _project_targets_target_options2.open
234
- };
235
- if (serveTarget.executor === '@nxext/vite:dev') {
236
- serveOptions.proxyConfig = project.targets[target].options.proxyConfig;
237
- }
238
- serveTarget.executor = '@nx/vite:dev-server';
239
- serveTarget.options = serveOptions;
240
- } else {
241
- project.targets[target] = {
242
- executor: '@nx/vite:dev-server',
243
- defaultConfiguration: 'development',
244
- options: {
245
- buildTarget: `${options.project}:build`
158
+ project.targets[target] = {
159
+ executor: '@nx/vite:dev-server',
160
+ defaultConfiguration: 'development',
161
+ options: {
162
+ buildTarget: `${options.project}:build`
163
+ },
164
+ configurations: {
165
+ development: {
166
+ buildTarget: `${options.project}:build:development`,
167
+ hmr: true
246
168
  },
247
- configurations: {
248
- development: {
249
- buildTarget: `${options.project}:build:development`,
250
- hmr: true
251
- },
252
- production: {
253
- buildTarget: `${options.project}:build:production`,
254
- hmr: false
255
- }
169
+ production: {
170
+ buildTarget: `${options.project}:build:production`,
171
+ hmr: false
256
172
  }
257
- };
258
- }
173
+ }
174
+ };
259
175
  (0, _devkit.updateProjectConfiguration)(tree, options.project, project);
260
176
  }
261
177
  function addPreviewTarget(tree, options, serveTarget) {
@@ -273,8 +189,8 @@ function addPreviewTarget(tree, options, serveTarget) {
273
189
  if (target.executor === '@nxext/vite:dev') {
274
190
  previewOptions.proxyConfig = target.options.proxyConfig;
275
191
  }
276
- previewOptions.https = (_target_options = target.options) == null ? void 0 : _target_options.https;
277
- previewOptions.open = (_target_options1 = target.options) == null ? void 0 : _target_options1.open;
192
+ previewOptions['https'] = (_target_options = target.options) == null ? void 0 : _target_options.https;
193
+ previewOptions['open'] = (_target_options1 = target.options) == null ? void 0 : _target_options1.open;
278
194
  }
279
195
  // Adds a preview target.
280
196
  project.targets.preview = {
@@ -295,56 +211,26 @@ function addPreviewTarget(tree, options, serveTarget) {
295
211
  function editTsConfig(tree, options) {
296
212
  const projectConfig = (0, _devkit.readProjectConfiguration)(tree, options.project);
297
213
  const config = (0, _devkit.readJson)(tree, `${projectConfig.root}/tsconfig.json`);
298
- const commonCompilerOptions = {
299
- target: 'ESNext',
300
- useDefineForClassFields: true,
301
- module: 'ESNext',
302
- strict: true,
303
- moduleResolution: 'Node',
304
- resolveJsonModule: true,
305
- isolatedModules: true,
306
- types: [
307
- 'vite/client'
308
- ],
309
- noEmit: true
310
- };
311
214
  switch(options.uiFramework){
312
215
  case 'react':
313
- config.compilerOptions = _extends._({}, commonCompilerOptions, {
314
- lib: [
315
- 'DOM',
316
- 'DOM.Iterable',
317
- 'ESNext'
318
- ],
216
+ config.compilerOptions = {
217
+ jsx: 'react-jsx',
319
218
  allowJs: false,
320
219
  esModuleInterop: false,
321
- skipLibCheck: true,
322
220
  allowSyntheticDefaultImports: true,
323
- forceConsistentCasingInFileNames: true,
324
- jsx: 'react-jsx'
325
- });
326
- config.include = [
327
- ...config.include,
328
- 'src'
329
- ];
221
+ strict: true
222
+ };
330
223
  break;
331
224
  case 'none':
332
- config.compilerOptions = _extends._({}, commonCompilerOptions, {
333
- lib: [
334
- 'ESNext',
335
- 'DOM'
336
- ],
337
- skipLibCheck: true,
338
- esModuleInterop: true,
225
+ config.compilerOptions = {
226
+ module: 'commonjs',
227
+ forceConsistentCasingInFileNames: true,
339
228
  strict: true,
340
- noUnusedLocals: true,
341
- noUnusedParameters: true,
342
- noImplicitReturns: true
343
- });
344
- config.include = [
345
- ...config.include,
346
- 'src'
347
- ];
229
+ noImplicitOverride: true,
230
+ noPropertyAccessFromIndexSignature: true,
231
+ noImplicitReturns: true,
232
+ noFallthroughCasesInSwitch: true
233
+ };
348
234
  break;
349
235
  default:
350
236
  break;
@@ -357,13 +243,10 @@ function deleteWebpackConfig(tree, projectRoot, webpackConfigFilePath) {
357
243
  tree.delete(webpackConfigPath);
358
244
  }
359
245
  }
360
- function moveAndEditIndexHtml(tree, options, buildTarget) {
361
- var _projectConfig_targets_buildTarget_options, _projectConfig_targets_buildTarget, _projectConfig_targets, _projectConfig_targets_buildTarget_options1, _projectConfig_targets_buildTarget1, _projectConfig_targets1;
246
+ function moveAndEditIndexHtml(tree, options) {
362
247
  const projectConfig = (0, _devkit.readProjectConfiguration)(tree, options.project);
363
- var _projectConfig_targets_buildTarget_options_index;
364
- let indexHtmlPath = (_projectConfig_targets_buildTarget_options_index = (_projectConfig_targets = projectConfig.targets) == null ? void 0 : (_projectConfig_targets_buildTarget = _projectConfig_targets[buildTarget]) == null ? void 0 : (_projectConfig_targets_buildTarget_options = _projectConfig_targets_buildTarget.options) == null ? void 0 : _projectConfig_targets_buildTarget_options.index) != null ? _projectConfig_targets_buildTarget_options_index : `${projectConfig.root}/src/index.html`;
365
- var _projectConfig_targets_buildTarget_options_main;
366
- let mainPath = (_projectConfig_targets_buildTarget_options_main = (_projectConfig_targets1 = projectConfig.targets) == null ? void 0 : (_projectConfig_targets_buildTarget1 = _projectConfig_targets1[buildTarget]) == null ? void 0 : (_projectConfig_targets_buildTarget_options1 = _projectConfig_targets_buildTarget1.options) == null ? void 0 : _projectConfig_targets_buildTarget_options1.main) != null ? _projectConfig_targets_buildTarget_options_main : `${projectConfig.root}/src/main.ts${options.uiFramework === 'react' ? 'x' : ''}`;
248
+ let indexHtmlPath = `${projectConfig.root}/src/index.html`;
249
+ let mainPath = `${projectConfig.root}/src/main.ts${options.uiFramework === 'react' ? 'x' : ''}`;
367
250
  if (projectConfig.root !== '.') {
368
251
  mainPath = mainPath.replace(projectConfig.root, '');
369
252
  }
@@ -395,14 +278,20 @@ function moveAndEditIndexHtml(tree, options, buildTarget) {
395
278
  </html>`);
396
279
  }
397
280
  }
398
- function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasViteTargets) {
399
- const projectConfig = (0, _devkit.readProjectConfiguration)(tree, options.project);
400
- const viteConfigPath = `${projectConfig.root}/vite.config.ts`;
281
+ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasViteTargets, vitestFileName) {
282
+ const { root: projectRoot } = (0, _devkit.readProjectConfiguration)(tree, options.project);
283
+ const viteConfigPath = vitestFileName ? `${projectRoot}/vitest.config.ts` : `${projectRoot}/vite.config.ts`;
284
+ const buildOutDir = projectRoot === '.' ? `./dist/${options.project}` : `${(0, _devkit.offsetFromRoot)(projectRoot)}dist/${projectRoot}`;
401
285
  var _options_rollupOptionsExternal;
402
286
  const buildOption = onlyVitest ? '' : options.includeLib ? `
403
287
  // Configuration for building your library.
404
288
  // See: https://vitejs.dev/guide/build.html#library-mode
405
289
  build: {
290
+ outDir: '${buildOutDir}',
291
+ reportCompressedSize: true,
292
+ commonjsOptions: {
293
+ transformMixedEsModules: true,
294
+ },
406
295
  lib: {
407
296
  // Could also be a dictionary or array of multiple entry points.
408
297
  entry: 'src/index.ts',
@@ -415,8 +304,16 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
415
304
  rollupOptions: {
416
305
  // External packages that should not be bundled into your library.
417
306
  external: [${(_options_rollupOptionsExternal = options.rollupOptionsExternal) != null ? _options_rollupOptionsExternal : ''}]
418
- }
419
- },` : ``;
307
+ },
308
+ },` : `
309
+ build: {
310
+ outDir: '${buildOutDir}',
311
+ reportCompressedSize: true,
312
+ commonjsOptions: {
313
+ transformMixedEsModules: true,
314
+ },
315
+ },
316
+ `;
420
317
  const imports = options.imports ? options.imports : [];
421
318
  if (!onlyVitest && options.includeLib) {
422
319
  imports.push(`import dts from 'vite-plugin-dts'`, `import * as path from 'path'`);
@@ -429,17 +326,23 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
429
326
  `nxViteTsPaths()`
430
327
  ];
431
328
  if (!onlyVitest && options.includeLib) {
432
- plugins.push(`dts({ entryRoot: 'src', tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true })`);
329
+ plugins.push(`dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json') })`);
433
330
  }
331
+ const reportsDirectory = projectRoot === '.' ? `./coverage/${options.project}` : `${(0, _devkit.offsetFromRoot)(projectRoot)}coverage/${projectRoot}`;
434
332
  var _options_testEnvironment;
435
333
  const testOption = options.includeVitest ? `test: {
436
334
  globals: true,
437
335
  cache: {
438
- dir: '${(0, _devkit.offsetFromRoot)(projectConfig.root)}node_modules/.vitest'
336
+ dir: '${(0, _devkit.offsetFromRoot)(projectRoot)}node_modules/.vitest'
439
337
  },
440
338
  environment: '${(_options_testEnvironment = options.testEnvironment) != null ? _options_testEnvironment : 'jsdom'}',
441
339
  include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
442
- ${options.inSourceTests ? `includeSource: ['src/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']` : ''}
340
+ ${options.inSourceTests ? `includeSource: ['src/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],` : ''}
341
+ reporters: ['default'],
342
+ coverage: {
343
+ reportsDirectory: '${reportsDirectory}',
344
+ provider: ${options.coverageProvider ? `'${options.coverageProvider}'` : `'v8'`},
345
+ }
443
346
  },` : '';
444
347
  const defineOption = options.inSourceTests ? `define: {
445
348
  'import.meta.vitest': undefined
@@ -459,9 +362,9 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
459
362
  // worker: {
460
363
  // plugins: [ nxViteTsPaths() ],
461
364
  // },`;
462
- const cacheDir = `cacheDir: '${(0, _devkit.offsetFromRoot)(projectConfig.root)}node_modules/.vite/${options.project}',`;
365
+ const cacheDir = `cacheDir: '${(0, _devkit.offsetFromRoot)(projectRoot)}node_modules/.vite/${projectRoot}',`;
463
366
  if (tree.exists(viteConfigPath)) {
464
- handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, imports, plugins, testOption, cacheDir, (0, _devkit.offsetFromRoot)(projectConfig.root), projectAlreadyHasViteTargets);
367
+ handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, (0, _devkit.offsetFromRoot)(projectRoot), projectAlreadyHasViteTargets);
465
368
  return;
466
369
  }
467
370
  viteConfigContent = `
@@ -471,6 +374,7 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
471
374
  import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
472
375
 
473
376
  export default defineConfig({
377
+ root: __dirname,
474
378
  ${cacheDir}
475
379
  ${devServerOption}
476
380
  ${previewServerOption}
@@ -534,33 +438,32 @@ async function handleUnsupportedUserProvidedTargetsErrors(userProvidedTargetName
534
438
  `);
535
439
  }
536
440
  }
537
- async function handleUnknownExecutors(projectName) {
441
+ async function handleUnknownConfiguration(projectName) {
442
+ if (process.env.NX_INTERACTIVE === 'false') {
443
+ return;
444
+ }
538
445
  _devkit.logger.warn(`
539
- We could not find any targets in project ${projectName} that use executors which
540
- can be converted to the @nx/vite executors.
541
-
542
- This either means that your project may not have a target
543
- for building, serving, or testing at all, or that your targets are
544
- using executors that are not known to Nx.
446
+ We could not find any configuration in project ${projectName} that
447
+ indicates whether we can definitely convert to Vite.
545
448
 
546
- If you still want to convert your project to use the @nx/vite executors,
449
+ If you still want to convert your project to use Vite,
547
450
  please make sure to commit your changes before running this generator.
548
451
  `);
549
452
  const { Confirm } = require('enquirer');
550
453
  const prompt = new Confirm({
551
454
  name: 'question',
552
- message: `Should Nx convert your project to use the @nx/vite executors?`,
455
+ message: `Should Nx convert your project to use Vite?`,
553
456
  initial: true
554
457
  });
555
458
  const shouldConvert = await prompt.run();
556
459
  if (!shouldConvert) {
557
460
  throw new Error(`
558
- Nx could not verify that the executors you are using can be converted to the @nx/vite executors.
461
+ Nx could not verify that your project can be converted to use Vite.
559
462
  Please try again with a different project.
560
463
  `);
561
464
  }
562
465
  }
563
- function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, imports, plugins, testOption, cacheDir, offsetFromRoot, projectAlreadyHasViteTargets) {
466
+ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, offsetFromRoot, projectAlreadyHasViteTargets) {
564
467
  if ((projectAlreadyHasViteTargets == null ? void 0 : projectAlreadyHasViteTargets.build) && (projectAlreadyHasViteTargets == null ? void 0 : projectAlreadyHasViteTargets.test)) {
565
468
  return;
566
469
  }
@@ -568,7 +471,7 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
568
471
  _devkit.logger.info(`vite.config.ts already exists for project ${options.project}.`);
569
472
  }
570
473
  var _options_rollupOptionsExternal;
571
- const buildOptionObject = {
474
+ const buildOptionObject = options.includeLib ? {
572
475
  lib: {
573
476
  entry: 'src/index.ts',
574
477
  name: options.project,
@@ -580,17 +483,36 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
580
483
  },
581
484
  rollupOptions: {
582
485
  external: (_options_rollupOptionsExternal = options.rollupOptionsExternal) != null ? _options_rollupOptionsExternal : []
486
+ },
487
+ outDir: buildOutDir,
488
+ reportCompressedSize: true,
489
+ commonjsOptions: {
490
+ transformMixedEsModules: true
491
+ }
492
+ } : {
493
+ outDir: buildOutDir,
494
+ reportCompressedSize: true,
495
+ commonjsOptions: {
496
+ transformMixedEsModules: true
583
497
  }
584
498
  };
499
+ var _options_testEnvironment, _options_coverageProvider;
585
500
  const testOptionObject = {
586
501
  globals: true,
587
502
  cache: {
588
503
  dir: `${offsetFromRoot}node_modules/.vitest`
589
504
  },
590
- environment: 'jsdom',
505
+ environment: (_options_testEnvironment = options.testEnvironment) != null ? _options_testEnvironment : 'jsdom',
591
506
  include: [
592
507
  'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
593
- ]
508
+ ],
509
+ reporters: [
510
+ 'default'
511
+ ],
512
+ coverage: {
513
+ reportsDirectory: reportsDirectory,
514
+ provider: `${(_options_coverageProvider = options.coverageProvider) != null ? _options_coverageProvider : 'v8'}`
515
+ }
594
516
  };
595
517
  const changed = (0, _viteconfigeditutils.ensureViteConfigIsCorrect)(tree, viteConfigPath, buildOption, buildOptionObject, imports, plugins, testOption, testOptionObject, cacheDir, projectAlreadyHasViteTargets != null ? projectAlreadyHasViteTargets : {});
596
518
  if (!changed) {