@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
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ function _export(target, all) {
3
+ for(var name in all)Object.defineProperty(target, name, {
4
+ enumerable: true,
5
+ get: all[name]
6
+ });
7
+ }
8
+ _export(exports, {
9
+ createDependencies: function() {
10
+ return createDependencies;
11
+ },
12
+ createNodes: function() {
13
+ return createNodes;
14
+ }
15
+ });
16
+ const _devkit = require("@nx/devkit");
17
+ const _path = require("path");
18
+ const _getnamedinputs = require("@nx/devkit/src/utils/get-named-inputs");
19
+ const _fs = require("fs");
20
+ const _calculatehashforcreatenodes = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
21
+ const _cachedirectory = require("nx/src/utils/cache-directory");
22
+ const _js = require("@nx/js");
23
+ const _executorutils = require("../utils/executor-utils");
24
+ const cachePath = (0, _path.join)(_cachedirectory.projectGraphCacheDirectory, 'vite.hash');
25
+ const targetsCache = (0, _fs.existsSync)(cachePath) ? readTargetsCache() : {};
26
+ const calculatedTargets = {};
27
+ function readTargetsCache() {
28
+ return (0, _devkit.readJsonFile)(cachePath);
29
+ }
30
+ function writeTargetsToCache(targets) {
31
+ (0, _devkit.writeJsonFile)(cachePath, targets);
32
+ }
33
+ const createDependencies = ()=>{
34
+ writeTargetsToCache(calculatedTargets);
35
+ return [];
36
+ };
37
+ const createNodes = [
38
+ '**/{vite,vitest}.config.{js,ts,mjs,mts,cjs,cts}',
39
+ async (configFilePath, options, context)=>{
40
+ const projectRoot = (0, _path.dirname)(configFilePath);
41
+ // Do not create a project if package.json and project.json isn't there.
42
+ const siblingFiles = (0, _fs.readdirSync)((0, _path.join)(context.workspaceRoot, projectRoot));
43
+ if (!siblingFiles.includes('package.json') && !siblingFiles.includes('project.json')) {
44
+ return {};
45
+ }
46
+ options = normalizeOptions(options);
47
+ // We do not want to alter how the hash is calculated, so appending the config file path to the hash
48
+ // to prevent vite/vitest files overwriting the target cache created by the other
49
+ const hash = (0, _calculatehashforcreatenodes.calculateHashForCreateNodes)(projectRoot, options, context, [
50
+ (0, _js.getLockFileName)((0, _devkit.detectPackageManager)(context.workspaceRoot))
51
+ ]) + configFilePath;
52
+ const targets = targetsCache[hash] ? targetsCache[hash] : await buildViteTargets(configFilePath, projectRoot, options, context);
53
+ calculatedTargets[hash] = targets;
54
+ return {
55
+ projects: {
56
+ [projectRoot]: {
57
+ root: projectRoot,
58
+ targets
59
+ }
60
+ }
61
+ };
62
+ }
63
+ ];
64
+ async function buildViteTargets(configFilePath, projectRoot, options, context) {
65
+ const absoluteConfigFilePath = (0, _devkit.joinPathFragments)(context.workspaceRoot, configFilePath);
66
+ // Workaround for the `build$3 is not a function` error that we sometimes see in agents.
67
+ // This should be removed later once we address the issue properly
68
+ try {
69
+ const importEsbuild = ()=>new Function('return import("esbuild")')();
70
+ await importEsbuild();
71
+ } catch (e) {
72
+ // do nothing
73
+ }
74
+ const { resolveConfig } = await (0, _executorutils.loadViteDynamicImport)();
75
+ const viteConfig = await resolveConfig({
76
+ configFile: absoluteConfigFilePath,
77
+ mode: 'development'
78
+ }, 'build');
79
+ const { buildOutputs, testOutputs, hasTest, isBuildable } = getOutputs(viteConfig, projectRoot);
80
+ const namedInputs = (0, _getnamedinputs.getNamedInputs)(projectRoot, context);
81
+ const targets = {};
82
+ // If file is not vitest.config and buildable, create targets for build, serve, preview and serve-static
83
+ if (!configFilePath.includes('vitest.config') && isBuildable) {
84
+ targets[options.buildTargetName] = await buildTarget(options.buildTargetName, namedInputs, buildOutputs, projectRoot);
85
+ targets[options.serveTargetName] = serveTarget(projectRoot);
86
+ targets[options.previewTargetName] = previewTarget(projectRoot);
87
+ targets[options.serveStaticTargetName] = serveStaticTarget(options);
88
+ }
89
+ // if file is vitest.config or vite.config has definition for test, create target for test
90
+ if (configFilePath.includes('vitest.config') || hasTest) {
91
+ targets[options.testTargetName] = await testTarget(namedInputs, testOutputs, projectRoot);
92
+ }
93
+ return targets;
94
+ }
95
+ async function buildTarget(buildTargetName, namedInputs, outputs, projectRoot) {
96
+ return {
97
+ command: `vite build`,
98
+ options: {
99
+ cwd: (0, _devkit.joinPathFragments)(projectRoot)
100
+ },
101
+ cache: true,
102
+ dependsOn: [
103
+ `^${buildTargetName}`
104
+ ],
105
+ inputs: [
106
+ ...'production' in namedInputs ? [
107
+ 'production',
108
+ '^production'
109
+ ] : [
110
+ 'default',
111
+ '^default'
112
+ ],
113
+ {
114
+ externalDependencies: [
115
+ 'vite'
116
+ ]
117
+ }
118
+ ],
119
+ outputs
120
+ };
121
+ }
122
+ function serveTarget(projectRoot) {
123
+ const targetConfig = {
124
+ command: `vite serve`,
125
+ options: {
126
+ cwd: (0, _devkit.joinPathFragments)(projectRoot)
127
+ }
128
+ };
129
+ return targetConfig;
130
+ }
131
+ function previewTarget(projectRoot) {
132
+ const targetConfig = {
133
+ command: `vite preview`,
134
+ options: {
135
+ cwd: (0, _devkit.joinPathFragments)(projectRoot)
136
+ }
137
+ };
138
+ return targetConfig;
139
+ }
140
+ async function testTarget(namedInputs, outputs, projectRoot) {
141
+ return {
142
+ command: `vitest run`,
143
+ options: {
144
+ cwd: (0, _devkit.joinPathFragments)(projectRoot)
145
+ },
146
+ cache: true,
147
+ inputs: [
148
+ ...'production' in namedInputs ? [
149
+ 'default',
150
+ '^production'
151
+ ] : [
152
+ 'default',
153
+ '^default'
154
+ ],
155
+ {
156
+ externalDependencies: [
157
+ 'vitest'
158
+ ]
159
+ }
160
+ ],
161
+ outputs
162
+ };
163
+ }
164
+ function serveStaticTarget(options) {
165
+ const targetConfig = {
166
+ executor: '@nx/web:file-server',
167
+ options: {
168
+ buildTarget: `${options.buildTargetName}`,
169
+ spa: true
170
+ }
171
+ };
172
+ return targetConfig;
173
+ }
174
+ function getOutputs(viteConfig, projectRoot) {
175
+ var _build_rollupOptions, _test_coverage;
176
+ const { build, test } = viteConfig;
177
+ const buildOutputPath = normalizeOutputPath(build == null ? void 0 : build.outDir, projectRoot, 'dist');
178
+ const isBuildable = (build == null ? void 0 : build.lib) || (build == null ? void 0 : (_build_rollupOptions = build.rollupOptions) == null ? void 0 : _build_rollupOptions.inputs) || (0, _fs.existsSync)((0, _path.join)(_devkit.workspaceRoot, projectRoot, 'index.html'));
179
+ const reportsDirectoryPath = normalizeOutputPath(test == null ? void 0 : (_test_coverage = test.coverage) == null ? void 0 : _test_coverage.reportsDirectory, projectRoot, 'coverage');
180
+ return {
181
+ buildOutputs: [
182
+ buildOutputPath
183
+ ],
184
+ testOutputs: [
185
+ reportsDirectoryPath
186
+ ],
187
+ hasTest: !!test,
188
+ isBuildable
189
+ };
190
+ }
191
+ function normalizeOutputPath(outputPath, projectRoot, path) {
192
+ if (!outputPath) {
193
+ if (projectRoot === '.') {
194
+ return `{projectRoot}/${path}`;
195
+ } else {
196
+ return `{workspaceRoot}/${path}/{projectRoot}`;
197
+ }
198
+ } else {
199
+ if ((0, _path.isAbsolute)(outputPath)) {
200
+ return `{workspaceRoot}/${(0, _path.relative)(_devkit.workspaceRoot, outputPath)}`;
201
+ } else {
202
+ if (outputPath.startsWith('..')) {
203
+ return (0, _path.join)('{workspaceRoot}', (0, _path.join)(projectRoot, outputPath));
204
+ } else {
205
+ return (0, _path.join)('{projectRoot}', outputPath);
206
+ }
207
+ }
208
+ }
209
+ }
210
+ function normalizeOptions(options) {
211
+ var _options, _options1, _options2, _options3, _options4;
212
+ options != null ? options : options = {};
213
+ var _buildTargetName;
214
+ (_buildTargetName = (_options = options).buildTargetName) != null ? _buildTargetName : _options.buildTargetName = 'build';
215
+ var _serveTargetName;
216
+ (_serveTargetName = (_options1 = options).serveTargetName) != null ? _serveTargetName : _options1.serveTargetName = 'serve';
217
+ var _previewTargetName;
218
+ (_previewTargetName = (_options2 = options).previewTargetName) != null ? _previewTargetName : _options2.previewTargetName = 'preview';
219
+ var _testTargetName;
220
+ (_testTargetName = (_options3 = options).testTargetName) != null ? _testTargetName : _options3.testTargetName = 'test';
221
+ var _serveStaticTargetName;
222
+ (_serveStaticTargetName = (_options4 = options).serveStaticTargetName) != null ? _serveStaticTargetName : _options4.serveStaticTargetName = 'serve-static';
223
+ return options;
224
+ }
225
+
226
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/vite/src/plugins/plugin.ts"],"sourcesContent":["import {\n CreateDependencies,\n CreateNodes,\n CreateNodesContext,\n detectPackageManager,\n joinPathFragments,\n readJsonFile,\n TargetConfiguration,\n workspaceRoot,\n writeJsonFile,\n} from '@nx/devkit';\nimport { dirname, isAbsolute, join, relative } from 'path';\nimport { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';\nimport { existsSync, readdirSync } from 'fs';\nimport { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';\nimport { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';\nimport { getLockFileName } from '@nx/js';\nimport { loadViteDynamicImport } from '../utils/executor-utils';\n\nexport interface VitePluginOptions {\n buildTargetName?: string;\n testTargetName?: string;\n serveTargetName?: string;\n previewTargetName?: string;\n serveStaticTargetName?: string;\n}\n\nconst cachePath = join(projectGraphCacheDirectory, 'vite.hash');\nconst targetsCache = existsSync(cachePath) ? readTargetsCache() : {};\n\nconst calculatedTargets: Record<\n string,\n Record<string, TargetConfiguration>\n> = {};\n\nfunction readTargetsCache(): Record<\n string,\n Record<string, TargetConfiguration>\n> {\n return readJsonFile(cachePath);\n}\n\nfunction writeTargetsToCache(\n targets: Record<string, Record<string, TargetConfiguration>>\n) {\n writeJsonFile(cachePath, targets);\n}\n\nexport const createDependencies: CreateDependencies = () => {\n writeTargetsToCache(calculatedTargets);\n return [];\n};\n\nexport const createNodes: CreateNodes<VitePluginOptions> = [\n '**/{vite,vitest}.config.{js,ts,mjs,mts,cjs,cts}',\n async (configFilePath, options, context) => {\n const projectRoot = dirname(configFilePath);\n // Do not create a project if package.json and project.json isn't there.\n const siblingFiles = readdirSync(join(context.workspaceRoot, projectRoot));\n if (\n !siblingFiles.includes('package.json') &&\n !siblingFiles.includes('project.json')\n ) {\n return {};\n }\n\n options = normalizeOptions(options);\n\n // We do not want to alter how the hash is calculated, so appending the config file path to the hash\n // to prevent vite/vitest files overwriting the target cache created by the other\n const hash =\n calculateHashForCreateNodes(projectRoot, options, context, [\n getLockFileName(detectPackageManager(context.workspaceRoot)),\n ]) + configFilePath;\n const targets = targetsCache[hash]\n ? targetsCache[hash]\n : await buildViteTargets(configFilePath, projectRoot, options, context);\n\n calculatedTargets[hash] = targets;\n\n return {\n projects: {\n [projectRoot]: {\n root: projectRoot,\n targets,\n },\n },\n };\n },\n];\n\nasync function buildViteTargets(\n configFilePath: string,\n projectRoot: string,\n options: VitePluginOptions,\n context: CreateNodesContext\n) {\n const absoluteConfigFilePath = joinPathFragments(\n context.workspaceRoot,\n configFilePath\n );\n\n // Workaround for the `build$3 is not a function` error that we sometimes see in agents.\n // This should be removed later once we address the issue properly\n try {\n const importEsbuild = () => new Function('return import(\"esbuild\")')();\n await importEsbuild();\n } catch {\n // do nothing\n }\n const { resolveConfig } = await loadViteDynamicImport();\n const viteConfig = await resolveConfig(\n {\n configFile: absoluteConfigFilePath,\n mode: 'development',\n },\n 'build'\n );\n\n const { buildOutputs, testOutputs, hasTest, isBuildable } = getOutputs(\n viteConfig,\n projectRoot\n );\n\n const namedInputs = getNamedInputs(projectRoot, context);\n\n const targets: Record<string, TargetConfiguration> = {};\n\n // If file is not vitest.config and buildable, create targets for build, serve, preview and serve-static\n if (!configFilePath.includes('vitest.config') && isBuildable) {\n targets[options.buildTargetName] = await buildTarget(\n options.buildTargetName,\n namedInputs,\n buildOutputs,\n projectRoot\n );\n\n targets[options.serveTargetName] = serveTarget(projectRoot);\n\n targets[options.previewTargetName] = previewTarget(projectRoot);\n\n targets[options.serveStaticTargetName] = serveStaticTarget(options) as {};\n }\n\n // if file is vitest.config or vite.config has definition for test, create target for test\n if (configFilePath.includes('vitest.config') || hasTest) {\n targets[options.testTargetName] = await testTarget(\n namedInputs,\n testOutputs,\n projectRoot\n );\n }\n\n return targets;\n}\n\nasync function buildTarget(\n buildTargetName: string,\n namedInputs: {\n [inputName: string]: any[];\n },\n outputs: string[],\n projectRoot: string\n) {\n return {\n command: `vite build`,\n options: { cwd: joinPathFragments(projectRoot) },\n cache: true,\n dependsOn: [`^${buildTargetName}`],\n inputs: [\n ...('production' in namedInputs\n ? ['production', '^production']\n : ['default', '^default']),\n {\n externalDependencies: ['vite'],\n },\n ],\n outputs,\n };\n}\n\nfunction serveTarget(projectRoot: string) {\n const targetConfig: TargetConfiguration = {\n command: `vite serve`,\n options: {\n cwd: joinPathFragments(projectRoot),\n },\n };\n\n return targetConfig;\n}\n\nfunction previewTarget(projectRoot: string) {\n const targetConfig: TargetConfiguration = {\n command: `vite preview`,\n options: {\n cwd: joinPathFragments(projectRoot),\n },\n };\n\n return targetConfig;\n}\n\nasync function testTarget(\n namedInputs: {\n [inputName: string]: any[];\n },\n outputs: string[],\n projectRoot: string\n) {\n return {\n command: `vitest run`,\n options: { cwd: joinPathFragments(projectRoot) },\n cache: true,\n inputs: [\n ...('production' in namedInputs\n ? ['default', '^production']\n : ['default', '^default']),\n {\n externalDependencies: ['vitest'],\n },\n ],\n outputs,\n };\n}\n\nfunction serveStaticTarget(options: VitePluginOptions) {\n const targetConfig: TargetConfiguration = {\n executor: '@nx/web:file-server',\n options: {\n buildTarget: `${options.buildTargetName}`,\n spa: true,\n },\n };\n\n return targetConfig;\n}\n\nfunction getOutputs(\n viteConfig: Record<string, any> | undefined,\n projectRoot: string\n): {\n buildOutputs: string[];\n testOutputs: string[];\n hasTest: boolean;\n isBuildable: boolean;\n} {\n const { build, test } = viteConfig;\n\n const buildOutputPath = normalizeOutputPath(\n build?.outDir,\n projectRoot,\n 'dist'\n );\n\n const isBuildable =\n build?.lib ||\n build?.rollupOptions?.inputs ||\n existsSync(join(workspaceRoot, projectRoot, 'index.html'));\n\n const reportsDirectoryPath = normalizeOutputPath(\n test?.coverage?.reportsDirectory,\n projectRoot,\n 'coverage'\n );\n\n return {\n buildOutputs: [buildOutputPath],\n testOutputs: [reportsDirectoryPath],\n hasTest: !!test,\n isBuildable,\n };\n}\n\nfunction normalizeOutputPath(\n outputPath: string | undefined,\n projectRoot: string,\n path: 'coverage' | 'dist'\n): string | undefined {\n if (!outputPath) {\n if (projectRoot === '.') {\n return `{projectRoot}/${path}`;\n } else {\n return `{workspaceRoot}/${path}/{projectRoot}`;\n }\n } else {\n if (isAbsolute(outputPath)) {\n return `{workspaceRoot}/${relative(workspaceRoot, outputPath)}`;\n } else {\n if (outputPath.startsWith('..')) {\n return join('{workspaceRoot}', join(projectRoot, outputPath));\n } else {\n return join('{projectRoot}', outputPath);\n }\n }\n }\n}\n\nfunction normalizeOptions(options: VitePluginOptions): VitePluginOptions {\n options ??= {};\n options.buildTargetName ??= 'build';\n options.serveTargetName ??= 'serve';\n options.previewTargetName ??= 'preview';\n options.testTargetName ??= 'test';\n options.serveStaticTargetName ??= 'serve-static';\n return options;\n}\n"],"names":["createDependencies","createNodes","cachePath","join","projectGraphCacheDirectory","targetsCache","existsSync","readTargetsCache","calculatedTargets","readJsonFile","writeTargetsToCache","targets","writeJsonFile","configFilePath","options","context","projectRoot","dirname","siblingFiles","readdirSync","workspaceRoot","includes","normalizeOptions","hash","calculateHashForCreateNodes","getLockFileName","detectPackageManager","buildViteTargets","projects","root","absoluteConfigFilePath","joinPathFragments","importEsbuild","Function","resolveConfig","loadViteDynamicImport","viteConfig","configFile","mode","buildOutputs","testOutputs","hasTest","isBuildable","getOutputs","namedInputs","getNamedInputs","buildTargetName","buildTarget","serveTargetName","serveTarget","previewTargetName","previewTarget","serveStaticTargetName","serveStaticTarget","testTargetName","testTarget","outputs","command","cwd","cache","dependsOn","inputs","externalDependencies","targetConfig","executor","spa","build","test","buildOutputPath","normalizeOutputPath","outDir","lib","rollupOptions","reportsDirectoryPath","coverage","reportsDirectory","outputPath","path","isAbsolute","relative","startsWith"],"mappings":";;;;;;;;IAgDaA,kBAAkB;eAAlBA;;IAKAC,WAAW;eAAXA;;;wBA3CN;sBAC6C;gCACrB;oBACS;6CACI;gCACD;oBACX;+BACM;AAUtC,MAAMC,YAAYC,IAAAA,UAAI,EAACC,0CAA0B,EAAE;AACnD,MAAMC,eAAeC,IAAAA,cAAU,EAACJ,aAAaK,qBAAqB,CAAC;AAEnE,MAAMC,oBAGF,CAAC;AAEL,SAASD;IAIP,OAAOE,IAAAA,oBAAY,EAACP;AACtB;AAEA,SAASQ,oBACPC,OAA4D;IAE5DC,IAAAA,qBAAa,EAACV,WAAWS;AAC3B;AAEO,MAAMX,qBAAyC;IACpDU,oBAAoBF;IACpB,OAAO,EAAE;AACX;AAEO,MAAMP,cAA8C;IACzD;IACA,OAAOY,gBAAgBC,SAASC;QAC9B,MAAMC,cAAcC,IAAAA,aAAO,EAACJ;QAC5B,wEAAwE;QACxE,MAAMK,eAAeC,IAAAA,eAAW,EAAChB,IAAAA,UAAI,EAACY,QAAQK,aAAa,EAAEJ;QAC7D,IACE,CAACE,aAAaG,QAAQ,CAAC,mBACvB,CAACH,aAAaG,QAAQ,CAAC,iBACvB;YACA,OAAO,CAAC;QACV;QAEAP,UAAUQ,iBAAiBR;QAE3B,oGAAoG;QACpG,iFAAiF;QACjF,MAAMS,OACJC,IAAAA,wDAA2B,EAACR,aAAaF,S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I,EAACa,aAAa4D;YACnD,OAAO;gBACL,OAAOzE,IAAAA,UAAI,EAAC,iBAAiByE;YAC/B;QACF;IACF;AACF;AAEA,SAAStD,iBAAiBR,OAA0B;QAElDA,UACAA,WACAA,WACAA,WACAA;IALAA,kBAAAA,UAAAA,UAAY,CAAC;;IACbA,qBAAAA,WAAAA,SAAQgC,8CAARhC,SAAQgC,kBAAoB;;IAC5BhC,qBAAAA,YAAAA,SAAQkC,8CAARlC,UAAQkC,kBAAoB;;IAC5BlC,uBAAAA,YAAAA,SAAQoC,kDAARpC,UAAQoC,oBAAsB;;IAC9BpC,oBAAAA,YAAAA,SAAQwC,4CAARxC,UAAQwC,iBAAmB;;IAC3BxC,2BAAAA,YAAAA,SAAQsC,0DAARtC,UAAQsC,wBAA0B;IAClC,OAAOtC;AACT"}
@@ -0,0 +1,8 @@
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
+ export type EnsureDependenciesOptions = {
3
+ uiFramework: 'react' | 'none';
4
+ compiler?: 'babel' | 'swc';
5
+ includeLib?: boolean;
6
+ testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
7
+ };
8
+ export declare function ensureDependencies(host: Tree, schema: EnsureDependenciesOptions): GeneratorCallback;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "ensureDependencies", {
3
+ enumerable: true,
4
+ get: function() {
5
+ return ensureDependencies;
6
+ }
7
+ });
8
+ const _devkit = require("@nx/devkit");
9
+ const _versions = require("./versions");
10
+ function ensureDependencies(host, schema) {
11
+ const devDependencies = {};
12
+ if (schema.testEnvironment === 'jsdom') {
13
+ devDependencies['jsdom'] = _versions.jsdomVersion;
14
+ } else if (schema.testEnvironment === 'happy-dom') {
15
+ devDependencies['happy-dom'] = _versions.happyDomVersion;
16
+ } else if (schema.testEnvironment === 'edge-runtime') {
17
+ devDependencies['@edge-runtime/vm'] = _versions.edgeRuntimeVmVersion;
18
+ } else if (schema.testEnvironment !== 'node' && schema.testEnvironment) {
19
+ _devkit.logger.info(`A custom environment was provided: ${schema.testEnvironment}. You need to install it manually.`);
20
+ }
21
+ if (schema.uiFramework === 'react') {
22
+ if (schema.compiler === 'swc') {
23
+ devDependencies['@vitejs/plugin-react-swc'] = _versions.vitePluginReactSwcVersion;
24
+ } else {
25
+ devDependencies['@vitejs/plugin-react'] = _versions.vitePluginReactVersion;
26
+ }
27
+ }
28
+ if (schema.includeLib) {
29
+ devDependencies['vite-plugin-dts'] = _versions.vitePluginDtsVersion;
30
+ }
31
+ return (0, _devkit.addDependenciesToPackageJson)(host, {}, devDependencies);
32
+ }
33
+
34
+ //# sourceMappingURL=ensure-dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/vite/src/utils/ensure-dependencies.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n logger,\n type GeneratorCallback,\n type Tree,\n} from '@nx/devkit';\nimport {\n edgeRuntimeVmVersion,\n happyDomVersion,\n jsdomVersion,\n vitePluginDtsVersion,\n vitePluginReactSwcVersion,\n vitePluginReactVersion,\n} from './versions';\n\nexport type EnsureDependenciesOptions = {\n uiFramework: 'react' | 'none';\n compiler?: 'babel' | 'swc';\n includeLib?: boolean;\n testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;\n};\n\nexport function ensureDependencies(\n host: Tree,\n schema: EnsureDependenciesOptions\n): GeneratorCallback {\n const devDependencies: Record<string, string> = {};\n\n if (schema.testEnvironment === 'jsdom') {\n devDependencies['jsdom'] = jsdomVersion;\n } else if (schema.testEnvironment === 'happy-dom') {\n devDependencies['happy-dom'] = happyDomVersion;\n } else if (schema.testEnvironment === 'edge-runtime') {\n devDependencies['@edge-runtime/vm'] = edgeRuntimeVmVersion;\n } else if (schema.testEnvironment !== 'node' && schema.testEnvironment) {\n logger.info(\n `A custom environment was provided: ${schema.testEnvironment}. You need to install it manually.`\n );\n }\n\n if (schema.uiFramework === 'react') {\n if (schema.compiler === 'swc') {\n devDependencies['@vitejs/plugin-react-swc'] = vitePluginReactSwcVersion;\n } else {\n devDependencies['@vitejs/plugin-react'] = vitePluginReactVersion;\n }\n }\n\n if (schema.includeLib) {\n devDependencies['vite-plugin-dts'] = vitePluginDtsVersion;\n }\n\n return addDependenciesToPackageJson(host, {}, devDependencies);\n}\n"],"names":["ensureDependencies","host","schema","devDependencies","testEnvironment","jsdomVersion","happyDomVersion","edgeRuntimeVmVersion","logger","info","uiFramework","compiler","vitePluginReactSwcVersion","vitePluginReactVersion","includeLib","vitePluginDtsVersion","addDependenciesToPackageJson"],"mappings":";+BAsBgBA;;;eAAAA;;;wBAjBT;0BAQA;AASA,SAASA,mBACdC,IAAU,EACVC,MAAiC;IAEjC,MAAMC,kBAA0C,CAAC;IAEjD,IAAID,OAAOE,eAAe,KAAK,SAAS;QACtCD,eAAe,CAAC,QAAQ,GAAGE,sBAAY;IACzC,OAAO,IAAIH,OAAOE,eAAe,KAAK,aAAa;QACjDD,eAAe,CAAC,YAAY,GAAGG,yBAAe;IAChD,OAAO,IAAIJ,OAAOE,eAAe,KAAK,gBAAgB;QACpDD,eAAe,CAAC,mBAAmB,GAAGI,8BAAoB;IAC5D,OAAO,IAAIL,OAAOE,eAAe,KAAK,UAAUF,OAAOE,eAAe,EAAE;QACtEI,cAAM,CAACC,IAAI,CACT,CAAC,mCAAmC,EAAEP,OAAOE,eAAe,CAAC,kCAAkC,CAAC;IAEpG;IAEA,IAAIF,OAAOQ,WAAW,KAAK,SAAS;QAClC,IAAIR,OAAOS,QAAQ,KAAK,OAAO;YAC7BR,eAAe,CAAC,2BAA2B,GAAGS,mCAAyB;QACzE,OAAO;YACLT,eAAe,CAAC,uBAAuB,GAAGU,gCAAsB;QAClE;IACF;IAEA,IAAIX,OAAOY,UAAU,EAAE;QACrBX,eAAe,CAAC,kBAAkB,GAAGY,8BAAoB;IAC3D;IAEA,OAAOC,IAAAA,oCAA4B,EAACf,MAAM,CAAC,GAAGE;AAChD"}
@@ -7,3 +7,5 @@ export declare function validateTypes(opts: {
7
7
  tsconfig: string;
8
8
  }): Promise<void>;
9
9
  export declare function createBuildableTsConfig(projectRoot: string, options: ViteBuildExecutorOptions | ViteDevServerExecutorOptions, context: ExecutorContext): void;
10
+ export declare function loadViteDynamicImport(): Promise<typeof import("vite")>;
11
+ export declare function loadVitestDynamicImport(): Promise<typeof import("vitest/node")>;
@@ -11,11 +11,18 @@ _export(exports, {
11
11
  },
12
12
  createBuildableTsConfig: function() {
13
13
  return createBuildableTsConfig;
14
+ },
15
+ loadViteDynamicImport: function() {
16
+ return loadViteDynamicImport;
17
+ },
18
+ loadVitestDynamicImport: function() {
19
+ return loadVitestDynamicImport;
14
20
  }
15
21
  });
16
22
  const _js = require("@nx/js");
17
23
  const _path = require("path");
18
24
  const _buildablelibsutils = require("@nx/js/src/utils/buildable-libs-utils");
25
+ const _optionsutils = require("./options-utils");
19
26
  async function validateTypes(opts) {
20
27
  const result = await (0, _js.runTypeCheck)({
21
28
  workspaceRoot: opts.workspaceRoot,
@@ -28,17 +35,25 @@ async function validateTypes(opts) {
28
35
  }
29
36
  }
30
37
  function createBuildableTsConfig(projectRoot, options, context) {
31
- var _options;
32
- const tsConfig = (0, _path.resolve)(projectRoot, 'tsconfig.json');
33
- var _buildLibsFromSource;
34
- (_buildLibsFromSource = (_options = options).buildLibsFromSource) != null ? _buildLibsFromSource : _options.buildLibsFromSource = true;
35
- if (!options.buildLibsFromSource) {
38
+ var _options, _buildLibsFromSource;
39
+ const tsConfig = (0, _optionsutils.getProjectTsConfigPath)(projectRoot);
40
+ var _;
41
+ (_ = (_options = options)[_buildLibsFromSource = 'buildLibsFromSource']) != null ? _ : _options[_buildLibsFromSource] = true;
42
+ if (!options['buildLibsFromSource']) {
36
43
  const { dependencies } = (0, _buildablelibsutils.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, // When using incremental building and the serve target is called
37
44
  // we need to get the deps for the 'build' target instead.
38
45
  context.targetName === 'serve' ? 'build' : context.targetName, context.configurationName);
39
- // this tsconfig is used via the vite ts paths plugin
40
- (0, _buildablelibsutils.createTmpTsConfig)(tsConfig, context.root, projectRoot, dependencies);
46
+ // This tsconfig is used via the Vite ts paths plugin.
47
+ // It can be also used by other user-defined Vite plugins (e.g. for creating type declaration files).
48
+ const tmpTsConfigPath = (0, _buildablelibsutils.createTmpTsConfig)(tsConfig, context.root, projectRoot, dependencies);
49
+ process.env.NX_TSCONFIG_PATH = tmpTsConfigPath;
41
50
  }
42
51
  }
52
+ function loadViteDynamicImport() {
53
+ return Function('return import("vite")')();
54
+ }
55
+ function loadVitestDynamicImport() {
56
+ return Function('return import("vitest/node")')();
57
+ }
43
58
 
44
59
  //# sourceMappingURL=executor-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/vite/src/utils/executor-utils.ts"],"sourcesContent":["import { printDiagnostics, runTypeCheck } from '@nx/js';\nimport { join, resolve } from 'path';\nimport { ViteBuildExecutorOptions } from '../executors/build/schema';\nimport { ExecutorContext } from '@nx/devkit';\nimport { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';\nimport {\n calculateProjectBuildableDependencies,\n createTmpTsConfig,\n} from '@nx/js/src/utils/buildable-libs-utils';\n\nexport async function validateTypes(opts: {\n workspaceRoot: string;\n projectRoot: string;\n tsconfig: string;\n}): Promise<void> {\n const result = await runTypeCheck({\n workspaceRoot: opts.workspaceRoot,\n tsConfigPath: join(opts.workspaceRoot, opts.tsconfig),\n mode: 'noEmit',\n });\n\n await printDiagnostics(result.errors, result.warnings);\n\n if (result.errors.length > 0) {\n throw new Error('Found type errors. See above.');\n }\n}\n\nexport function createBuildableTsConfig(\n projectRoot: string,\n options: ViteBuildExecutorOptions | ViteDevServerExecutorOptions,\n context: ExecutorContext\n) {\n const tsConfig = resolve(projectRoot, 'tsconfig.json');\n options.buildLibsFromSource ??= true;\n\n if (!options.buildLibsFromSource) {\n const { dependencies } = calculateProjectBuildableDependencies(\n context.taskGraph,\n context.projectGraph,\n context.root,\n context.projectName,\n // When using incremental building and the serve target is called\n // we need to get the deps for the 'build' target instead.\n context.targetName === 'serve' ? 'build' : context.targetName,\n context.configurationName\n );\n // this tsconfig is used via the vite ts paths plugin\n createTmpTsConfig(tsConfig, context.root, projectRoot, dependencies);\n }\n}\n"],"names":["validateTypes","createBuildableTsConfig","opts","result","runTypeCheck","workspaceRoot","tsConfigPath","join","tsconfig","mode","printDiagnostics","errors","warnings","length","Error","projectRoot","options","context","tsConfig","resolve","buildLibsFromSource","dependencies","calculateProjectBuildableDependencies","taskGraph","projectGraph","root","projectName","targetName","configurationName","createTmpTsConfig"],"mappings":";;;;;;;;IAUsBA,aAAa;eAAbA;;IAkBNC,uBAAuB;eAAvBA;;;oBA5B+B;sBACjB;oCAOvB;AAEA,eAAeD,cAAcE,IAInC;IACC,MAAMC,SAAS,MAAMC,IAAAA,gBAAY,EAAC;QAChCC,eAAeH,KAAKG,aAAa;QACjCC,cAAcC,IAAAA,UAAI,EAACL,KAAKG,aAAa,EAAEH,KAAKM,QAAQ;QACpDC,MAAM;IACR;IAEA,MAAMC,IAAAA,oBAAgB,EAACP,OAAOQ,MAAM,EAAER,OAAOS,QAAQ;IAErD,IAAIT,OAAOQ,MAAM,CAACE,MAAM,GAAG,GAAG;QAC5B,MAAM,IAAIC,MAAM;IAClB;AACF;AAEO,SAASb,wBACdc,WAAmB,EACnBC,OAAgE,EAChEC,OAAwB;QAGxBD;IADA,MAAME,WAAWC,IAAAA,aAAO,EAACJ,aAAa;;IACtCC,yBAAAA,WAAAA,SAAQI,sDAARJ,SAAQI,sBAAwB;IAEhC,IAAI,CAACJ,QAAQI,mBAAmB,EAAE;QAChC,MAAM,EAAEC,YAAY,EAAE,GAAGC,IAAAA,yDAAqC,EAC5DL,QAAQM,SAAS,EACjBN,QAAQO,YAAY,EACpBP,QAAQQ,IAAI,EACZR,QAAQS,WAAW,EACnB,iEAAiE;QACjE,0DAA0D;QAC1DT,QAAQU,UAAU,KAAK,UAAU,UAAUV,QAAQU,UAAU,EAC7DV,QAAQW,iBAAiB;QAE3B,qDAAqD;QACrDC,IAAAA,qCAAiB,EAACX,UAAUD,QAAQQ,IAAI,EAAEV,aAAaM;IACzD;AACF"}
1
+ {"version":3,"sources":["../../../../../packages/vite/src/utils/executor-utils.ts"],"sourcesContent":["import { printDiagnostics, runTypeCheck } from '@nx/js';\nimport { join } from 'path';\nimport { ViteBuildExecutorOptions } from '../executors/build/schema';\nimport { ExecutorContext } from '@nx/devkit';\nimport { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';\nimport {\n calculateProjectBuildableDependencies,\n createTmpTsConfig,\n} from '@nx/js/src/utils/buildable-libs-utils';\nimport { getProjectTsConfigPath } from './options-utils';\n\nexport async function validateTypes(opts: {\n workspaceRoot: string;\n projectRoot: string;\n tsconfig: string;\n}): Promise<void> {\n const result = await runTypeCheck({\n workspaceRoot: opts.workspaceRoot,\n tsConfigPath: join(opts.workspaceRoot, opts.tsconfig),\n mode: 'noEmit',\n });\n\n await printDiagnostics(result.errors, result.warnings);\n\n if (result.errors.length > 0) {\n throw new Error('Found type errors. See above.');\n }\n}\n\nexport function createBuildableTsConfig(\n projectRoot: string,\n options: ViteBuildExecutorOptions | ViteDevServerExecutorOptions,\n context: ExecutorContext\n) {\n const tsConfig = getProjectTsConfigPath(projectRoot);\n options['buildLibsFromSource'] ??= true;\n\n if (!options['buildLibsFromSource']) {\n const { dependencies } = calculateProjectBuildableDependencies(\n context.taskGraph,\n context.projectGraph,\n context.root,\n context.projectName,\n // When using incremental building and the serve target is called\n // we need to get the deps for the 'build' target instead.\n context.targetName === 'serve' ? 'build' : context.targetName,\n context.configurationName\n );\n // This tsconfig is used via the Vite ts paths plugin.\n // It can be also used by other user-defined Vite plugins (e.g. for creating type declaration files).\n const tmpTsConfigPath = createTmpTsConfig(\n tsConfig,\n context.root,\n projectRoot,\n dependencies\n );\n process.env.NX_TSCONFIG_PATH = tmpTsConfigPath;\n }\n}\n\nexport function loadViteDynamicImport() {\n return Function('return import(\"vite\")')() as Promise<typeof import('vite')>;\n}\n\nexport function loadVitestDynamicImport() {\n return Function('return import(\"vitest/node\")')() as Promise<\n typeof import('vitest/node')\n >;\n}\n"],"names":["validateTypes","createBuildableTsConfig","loadViteDynamicImport","loadVitestDynamicImport","opts","result","runTypeCheck","workspaceRoot","tsConfigPath","join","tsconfig","mode","printDiagnostics","errors","warnings","length","Error","projectRoot","options","context","tsConfig","getProjectTsConfigPath","dependencies","calculateProjectBuildableDependencies","taskGraph","projectGraph","root","projectName","targetName","configurationName","tmpTsConfigPath","createTmpTsConfig","process","env","NX_TSCONFIG_PATH","Function"],"mappings":";;;;;;;;IAWsBA,aAAa;eAAbA;;IAkBNC,uBAAuB;eAAvBA;;IA+BAC,qBAAqB;eAArBA;;IAIAC,uBAAuB;eAAvBA;;;oBAhE+B;sBAC1B;oCAOd;8BACgC;AAEhC,eAAeH,cAAcI,IAInC;IACC,MAAMC,SAAS,MAAMC,IAAAA,gBAAY,EAAC;QAChCC,eAAeH,KAAKG,aAAa;QACjCC,cAAcC,IAAAA,UAAI,EAACL,KAAKG,aAAa,EAAEH,KAAKM,QAAQ;QACpDC,MAAM;IACR;IAEA,MAAMC,IAAAA,oBAAgB,EAACP,OAAOQ,MAAM,EAAER,OAAOS,QAAQ;IAErD,IAAIT,OAAOQ,MAAM,CAACE,MAAM,GAAG,GAAG;QAC5B,MAAM,IAAIC,MAAM;IAClB;AACF;AAEO,SAASf,wBACdgB,WAAmB,EACnBC,OAAgE,EAChEC,OAAwB;QAGxBD,UAAQ;IADR,MAAME,WAAWC,IAAAA,oCAAsB,EAACJ;;IACxCC,MAAAA,WAAAA,QAAO,CAAC,uBAAA,sBAAsB,gBAA9BA,QAAO,CAAC,qBAAsB,GAAK;IAEnC,IAAI,CAACA,OAAO,CAAC,sBAAsB,EAAE;QACnC,MAAM,EAAEI,YAAY,EAAE,GAAGC,IAAAA,yDAAqC,EAC5DJ,QAAQK,SAAS,EACjBL,QAAQM,YAAY,EACpBN,QAAQO,IAAI,EACZP,QAAQQ,WAAW,EACnB,iEAAiE;QACjE,0DAA0D;QAC1DR,QAAQS,UAAU,KAAK,UAAU,UAAUT,QAAQS,UAAU,EAC7DT,QAAQU,iBAAiB;QAE3B,sDAAsD;QACtD,qGAAqG;QACrG,MAAMC,kBAAkBC,IAAAA,qCAAiB,EACvCX,UACAD,QAAQO,IAAI,EACZT,aACAK;QAEFU,QAAQC,GAAG,CAACC,gBAAgB,GAAGJ;IACjC;AACF;AAEO,SAAS5B;IACd,OAAOiC,SAAS;AAClB;AAEO,SAAShC;IACd,OAAOgC,SAAS;AAGlB"}
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function findViteConfig(tree: Tree, searchRoot: string): string;
3
+ export declare function findWebpackConfig(tree: Tree, searchRoot: string): string;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ function _export(target, all) {
3
+ for(var name in all)Object.defineProperty(target, name, {
4
+ enumerable: true,
5
+ get: all[name]
6
+ });
7
+ }
8
+ _export(exports, {
9
+ findViteConfig: function() {
10
+ return findViteConfig;
11
+ },
12
+ findWebpackConfig: function() {
13
+ return findWebpackConfig;
14
+ }
15
+ });
16
+ const _devkit = require("@nx/devkit");
17
+ function findViteConfig(tree, searchRoot) {
18
+ const allowsExt = [
19
+ 'js',
20
+ 'mjs',
21
+ 'ts',
22
+ 'cjs',
23
+ 'mts',
24
+ 'cts'
25
+ ];
26
+ for (const ext of allowsExt){
27
+ if (tree.exists((0, _devkit.joinPathFragments)(searchRoot, `vite.config.${ext}`))) {
28
+ return (0, _devkit.joinPathFragments)(searchRoot, `vite.config.${ext}`);
29
+ }
30
+ }
31
+ }
32
+ function findWebpackConfig(tree, searchRoot) {
33
+ const allowsExt = [
34
+ 'js',
35
+ 'ts',
36
+ 'mjs',
37
+ 'cjs'
38
+ ];
39
+ for (const ext of allowsExt){
40
+ if (tree.exists((0, _devkit.joinPathFragments)(searchRoot, `webpack.config.${ext}`))) {
41
+ return (0, _devkit.joinPathFragments)(searchRoot, `webpack.config.${ext}`);
42
+ }
43
+ }
44
+ }
45
+
46
+ //# sourceMappingURL=find-vite-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/vite/src/utils/find-vite-config.ts"],"sourcesContent":["import { Tree, joinPathFragments } from '@nx/devkit';\n\nexport function findViteConfig(tree: Tree, searchRoot: string) {\n const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];\n\n for (const ext of allowsExt) {\n if (tree.exists(joinPathFragments(searchRoot, `vite.config.${ext}`))) {\n return joinPathFragments(searchRoot, `vite.config.${ext}`);\n }\n }\n}\n\nexport function findWebpackConfig(tree: Tree, searchRoot: string) {\n const allowsExt = ['js', 'ts', 'mjs', 'cjs'];\n\n for (const ext of allowsExt) {\n if (tree.exists(joinPathFragments(searchRoot, `webpack.config.${ext}`))) {\n return joinPathFragments(searchRoot, `webpack.config.${ext}`);\n }\n }\n}\n"],"names":["findViteConfig","findWebpackConfig","tree","searchRoot","allowsExt","ext","exists","joinPathFragments"],"mappings":";;;;;;;;IAEgBA,cAAc;eAAdA;;IAUAC,iBAAiB;eAAjBA;;;wBAZwB;AAEjC,SAASD,eAAeE,IAAU,EAAEC,UAAkB;IAC3D,MAAMC,YAAY;QAAC;QAAM;QAAO;QAAM;QAAO;QAAO;KAAM;IAE1D,KAAK,MAAMC,OAAOD,UAAW;QAC3B,IAAIF,KAAKI,MAAM,CAACC,IAAAA,yBAAiB,EAACJ,YAAY,CAAC,YAAY,EAAEE,IAAI,CAAC,IAAI;YACpE,OAAOE,IAAAA,yBAAiB,EAACJ,YAAY,CAAC,YAAY,EAAEE,IAAI,CAAC;QAC3D;IACF;AACF;AAEO,SAASJ,kBAAkBC,IAAU,EAAEC,UAAkB;IAC9D,MAAMC,YAAY;QAAC;QAAM;QAAM;QAAO;KAAM;IAE5C,KAAK,MAAMC,OAAOD,UAAW;QAC3B,IAAIF,KAAKI,MAAM,CAACC,IAAAA,yBAAiB,EAACJ,YAAY,CAAC,eAAe,EAAEE,IAAI,CAAC,IAAI;YACvE,OAAOE,IAAAA,yBAAiB,EAACJ,YAAY,CAAC,eAAe,EAAEE,IAAI,CAAC;QAC9D;IACF;AACF"}
@@ -4,29 +4,26 @@ export type Target = 'build' | 'serve' | 'test' | 'preview';
4
4
  export type TargetFlags = Partial<Record<Target, boolean>>;
5
5
  export type UserProvidedTargetName = Partial<Record<Target, string>>;
6
6
  export type ValidFoundTargetName = Partial<Record<Target, string>>;
7
- export declare function findExistingTargetsInProject(targets: {
7
+ export declare function findExistingJsBuildTargetInProject(targets: {
8
8
  [targetName: string]: TargetConfiguration;
9
- }, userProvidedTargets?: UserProvidedTargetName): {
10
- validFoundTargetName: ValidFoundTargetName;
11
- projectContainsUnsupportedExecutor: boolean;
12
- userProvidedTargetIsUnsupported: TargetFlags;
13
- alreadyHasNxViteTargets: TargetFlags;
9
+ }): {
10
+ supported?: string;
11
+ unsupported?: string;
14
12
  };
15
13
  export declare function addOrChangeTestTarget(tree: Tree, options: ViteConfigurationGeneratorSchema, target: string): void;
16
- export declare function addOrChangeBuildTarget(tree: Tree, options: ViteConfigurationGeneratorSchema, target: string): void;
17
- export declare function addOrChangeServeTarget(tree: Tree, options: ViteConfigurationGeneratorSchema, target: string): void;
14
+ export declare function addBuildTarget(tree: Tree, options: ViteConfigurationGeneratorSchema, target: string): void;
15
+ export declare function addServeTarget(tree: Tree, options: ViteConfigurationGeneratorSchema, target: string): void;
18
16
  /**
19
17
  * Adds a target for the preview server.
20
18
  *
21
19
  * @param tree
22
20
  * @param options
23
21
  * @param serveTarget An existing serve target.
24
- * @param previewTarget The preview target to create.
25
22
  */
26
23
  export declare function addPreviewTarget(tree: Tree, options: ViteConfigurationGeneratorSchema, serveTarget: string): void;
27
24
  export declare function editTsConfig(tree: Tree, options: ViteConfigurationGeneratorSchema): void;
28
25
  export declare function deleteWebpackConfig(tree: Tree, projectRoot: string, webpackConfigFilePath?: string): void;
29
- export declare function moveAndEditIndexHtml(tree: Tree, options: ViteConfigurationGeneratorSchema, buildTarget: string): void;
26
+ export declare function moveAndEditIndexHtml(tree: Tree, options: ViteConfigurationGeneratorSchema): void;
30
27
  export interface ViteConfigFileOptions {
31
28
  project: string;
32
29
  includeLib?: boolean;
@@ -36,9 +33,10 @@ export interface ViteConfigFileOptions {
36
33
  rollupOptionsExternal?: string[];
37
34
  imports?: string[];
38
35
  plugins?: string[];
36
+ coverageProvider?: 'v8' | 'istanbul' | 'custom';
39
37
  }
40
- export declare function createOrEditViteConfig(tree: Tree, options: ViteConfigFileOptions, onlyVitest: boolean, projectAlreadyHasViteTargets?: TargetFlags): void;
38
+ export declare function createOrEditViteConfig(tree: Tree, options: ViteConfigFileOptions, onlyVitest: boolean, projectAlreadyHasViteTargets?: TargetFlags, vitestFileName?: boolean): void;
41
39
  export declare function normalizeViteConfigFilePathWithTree(tree: Tree, projectRoot: string, configFile?: string): string;
42
40
  export declare function getViteConfigPathForProject(tree: Tree, projectName: string, target?: string): string;
43
41
  export declare function handleUnsupportedUserProvidedTargets(userProvidedTargetIsUnsupported: TargetFlags, userProvidedTargetName: UserProvidedTargetName, validFoundTargetName: ValidFoundTargetName): Promise<void>;
44
- export declare function handleUnknownExecutors(projectName: string): Promise<void>;
42
+ export declare function handleUnknownConfiguration(projectName: string): Promise<void>;