@nx/vite 19.0.2 → 19.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.
- package/package.json +4 -4
- package/src/migrations/update-17-2-0/lib/vite-config-with-additional-js.fixture.d.ts +1 -0
- package/src/migrations/update-17-2-0/lib/vite-config-with-additional-js.fixture.js +73 -0
- package/src/migrations/update-17-2-0/lib/vite-config-with-additional-js.fixture.js.map +1 -0
- package/src/migrations/update-17-2-0/update-vite-config.js +8 -5
- package/src/migrations/update-17-2-0/update-vite-config.js.map +1 -1
- package/src/plugins/plugin.js +3 -2
- package/src/plugins/plugin.js.map +1 -1
- package/src/utils/generator-utils.js +9 -5
- package/src/utils/generator-utils.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "19.0.
|
|
3
|
+
"version": "19.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for building and testing applications using Vite",
|
|
6
6
|
"repository": {
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"migrations": "./migrations.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nx/devkit": "19.0.
|
|
32
|
+
"@nx/devkit": "19.0.4",
|
|
33
33
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
34
34
|
"@swc/helpers": "~0.5.0",
|
|
35
35
|
"enquirer": "~2.3.6",
|
|
36
|
-
"@nx/js": "19.0.
|
|
36
|
+
"@nx/js": "19.0.4",
|
|
37
37
|
"tsconfig-paths": "^4.1.2",
|
|
38
|
-
"@nrwl/vite": "19.0.
|
|
38
|
+
"@nrwl/vite": "19.0.4"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"vite": "^5.0.0",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const viteConfigFixture = "/// <reference types=\"vitest\" />\nimport react from '@vitejs/plugin-react';\nimport dns from 'dns';\nimport { PluginOption, defineConfig } from 'vite';\nimport { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n\ndns.setDefaultResultOrder('verbatim');\nconst BASE_HREF = '/app';\n\n/**\n * Adds <base href=\"/app\">` to the head of the index.html\n * The reason why the `base` configuration property doesn't work is because it makes\n * all assets served under `/app` of `/` and this impacts the download zip service worker\n * We only want to the service worker to listen to events related to downloads, but not capture any other events\n * and the only way to do this is make sure all assets are served from the root, but we still want our app path to be `/app`\n *\n * This mimics the same behavior we had with webpack before migrating to vite\n */\nconst baseHrefPlugin: () => PluginOption = () => {\n return {\n name: 'html-transform',\n transformIndexHtml(html) {\n return html.replace('<head>', `<head>\\n <base href=\"${BASE_HREF}\">`);\n },\n };\n};\n\nexport default defineConfig({\n cacheDir: '../../node_modules/.vite/jetstream',\n envPrefix: 'NX',\n\n server: {\n port: 4200,\n host: 'localhost',\n },\n\n build: {\n // Put all assets at the root of the app instead of under /assets\n assetsDir: './',\n sourcemap: true,\n rollupOptions: {\n output: {\n sourcemap: true,\n },\n },\n },\n\n plugins: [\n react({\n jsxImportSource: '@emotion/react',\n babel: {\n plugins: ['@emotion/babel-plugin'],\n },\n }),\n nxViteTsPaths(),\n baseHrefPlugin(),\n ],\n\n worker: {\n plugins: [\n nxViteTsPaths(),\n ],\n },\n});";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "viteConfigFixture", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return viteConfigFixture;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const viteConfigFixture = `/// <reference types="vitest" />
|
|
9
|
+
import react from '@vitejs/plugin-react';
|
|
10
|
+
import dns from 'dns';
|
|
11
|
+
import { PluginOption, defineConfig } from 'vite';
|
|
12
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
13
|
+
|
|
14
|
+
dns.setDefaultResultOrder('verbatim');
|
|
15
|
+
const BASE_HREF = '/app';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Adds <base href="/app">\` to the head of the index.html
|
|
19
|
+
* The reason why the \`base\` configuration property doesn't work is because it makes
|
|
20
|
+
* all assets served under \`/app\` of \`/\` and this impacts the download zip service worker
|
|
21
|
+
* We only want to the service worker to listen to events related to downloads, but not capture any other events
|
|
22
|
+
* and the only way to do this is make sure all assets are served from the root, but we still want our app path to be \`/app\`
|
|
23
|
+
*
|
|
24
|
+
* This mimics the same behavior we had with webpack before migrating to vite
|
|
25
|
+
*/
|
|
26
|
+
const baseHrefPlugin: () => PluginOption = () => {
|
|
27
|
+
return {
|
|
28
|
+
name: 'html-transform',
|
|
29
|
+
transformIndexHtml(html) {
|
|
30
|
+
return html.replace('<head>', \`<head>\\n <base href="\${BASE_HREF}">\`);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default defineConfig({
|
|
36
|
+
cacheDir: '../../node_modules/.vite/jetstream',
|
|
37
|
+
envPrefix: 'NX',
|
|
38
|
+
|
|
39
|
+
server: {
|
|
40
|
+
port: 4200,
|
|
41
|
+
host: 'localhost',
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
build: {
|
|
45
|
+
// Put all assets at the root of the app instead of under /assets
|
|
46
|
+
assetsDir: './',
|
|
47
|
+
sourcemap: true,
|
|
48
|
+
rollupOptions: {
|
|
49
|
+
output: {
|
|
50
|
+
sourcemap: true,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
plugins: [
|
|
56
|
+
react({
|
|
57
|
+
jsxImportSource: '@emotion/react',
|
|
58
|
+
babel: {
|
|
59
|
+
plugins: ['@emotion/babel-plugin'],
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
nxViteTsPaths(),
|
|
63
|
+
baseHrefPlugin(),
|
|
64
|
+
],
|
|
65
|
+
|
|
66
|
+
worker: {
|
|
67
|
+
plugins: [
|
|
68
|
+
nxViteTsPaths(),
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
});`;
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=vite-config-with-additional-js.fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/migrations/update-17-2-0/lib/vite-config-with-additional-js.fixture.ts"],"sourcesContent":["export const viteConfigFixture = `/// <reference types=\"vitest\" />\nimport react from '@vitejs/plugin-react';\nimport dns from 'dns';\nimport { PluginOption, defineConfig } from 'vite';\nimport { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n\ndns.setDefaultResultOrder('verbatim');\nconst BASE_HREF = '/app';\n\n/**\n * Adds <base href=\"/app\">\\` to the head of the index.html\n * The reason why the \\`base\\` configuration property doesn't work is because it makes\n * all assets served under \\`/app\\` of \\`/\\` and this impacts the download zip service worker\n * We only want to the service worker to listen to events related to downloads, but not capture any other events\n * and the only way to do this is make sure all assets are served from the root, but we still want our app path to be \\`/app\\`\n *\n * This mimics the same behavior we had with webpack before migrating to vite\n */\nconst baseHrefPlugin: () => PluginOption = () => {\n return {\n name: 'html-transform',\n transformIndexHtml(html) {\n return html.replace('<head>', \\`<head>\\\\n <base href=\"\\${BASE_HREF}\">\\`);\n },\n };\n};\n\nexport default defineConfig({\n cacheDir: '../../node_modules/.vite/jetstream',\n envPrefix: 'NX',\n\n server: {\n port: 4200,\n host: 'localhost',\n },\n\n build: {\n // Put all assets at the root of the app instead of under /assets\n assetsDir: './',\n sourcemap: true,\n rollupOptions: {\n output: {\n sourcemap: true,\n },\n },\n },\n\n plugins: [\n react({\n jsxImportSource: '@emotion/react',\n babel: {\n plugins: ['@emotion/babel-plugin'],\n },\n }),\n nxViteTsPaths(),\n baseHrefPlugin(),\n ],\n\n worker: {\n plugins: [\n nxViteTsPaths(),\n ],\n },\n});`;\n"],"names":["viteConfigFixture"],"mappings":";+BAAaA;;;eAAAA;;;AAAN,MAAMA,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+D/B,CAAC"}
|
|
@@ -44,14 +44,17 @@ async function updateBuildDir(tree) {
|
|
|
44
44
|
await (0, _devkit.formatFiles)(tree);
|
|
45
45
|
}
|
|
46
46
|
function getConfigNode(configFileContents) {
|
|
47
|
-
var _tsquery_query
|
|
47
|
+
var _tsquery_query;
|
|
48
48
|
if (!configFileContents) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
let configNode = (_tsquery_query = _tsquery.tsquery.query(configFileContents, `ObjectLiteralExpression`)) == null ? void 0 : _tsquery_query[0];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
let configNode = (_tsquery_query = _tsquery.tsquery.query(configFileContents, `CallExpression:has(Identifier[name=defineConfig]) > ObjectLiteralExpression`)) == null ? void 0 : _tsquery_query[0];
|
|
52
|
+
if (!configNode) {
|
|
53
|
+
var _tsquery_query1;
|
|
54
|
+
const arrowFunctionReturnStatement = (_tsquery_query1 = _tsquery.tsquery.query(configFileContents, `ArrowFunction Block ReturnStatement ObjectLiteralExpression`)) == null ? void 0 : _tsquery_query1[0];
|
|
55
|
+
if (arrowFunctionReturnStatement) {
|
|
56
|
+
configNode = arrowFunctionReturnStatement;
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
59
|
return configNode;
|
|
57
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/migrations/update-17-2-0/update-vite-config.ts"],"sourcesContent":["import {\n Tree,\n formatFiles,\n getProjects,\n joinPathFragments,\n logger,\n} from '@nx/devkit';\nimport { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils';\nimport { ViteBuildExecutorOptions } from '../../executors/build/schema';\nimport { updateBuildOutDirAndRoot } from './lib/edit-build-config';\nimport { updateTestConfig } from './lib/edit-test-config';\nimport { addFileReplacements } from './lib/add-file-replacements';\nimport { tsquery } from '@phenomnomnominal/tsquery';\nimport ts = require('typescript');\nimport { findViteConfig } from '../../utils/find-vite-config';\n\nexport default async function updateBuildDir(tree: Tree) {\n const projects = getProjects(tree);\n forEachExecutorOptions<ViteBuildExecutorOptions>(\n tree,\n '@nx/vite:build',\n (options, projectName, targetName) => {\n const projectConfig = projects.get(projectName);\n const config =\n options.configFile || findViteConfig(tree, projectConfig.root);\n if (!config || !tree.exists(config)) {\n return;\n }\n let configContents = tree.read(config, 'utf-8');\n\n configContents = updateBuildOutDirAndRoot(\n options,\n configContents,\n projectConfig,\n targetName,\n tree,\n projectName,\n config\n );\n\n configContents = updateTestConfig(configContents, projectConfig, config);\n\n if (options['fileReplacements']?.length > 0) {\n configContents = addFileReplacements(\n configContents,\n options['fileReplacements'],\n config\n );\n }\n\n tree.write(config, configContents);\n }\n );\n\n await formatFiles(tree);\n}\n\nexport function getConfigNode(configFileContents: string): ts.Node | undefined {\n if (!configFileContents) {\n return;\n }\n let configNode = tsquery.query(\n configFileContents,\n `ObjectLiteralExpression`\n )?.[0];\n\n const arrowFunctionReturnStatement = tsquery.query(\n
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/migrations/update-17-2-0/update-vite-config.ts"],"sourcesContent":["import {\n Tree,\n formatFiles,\n getProjects,\n joinPathFragments,\n logger,\n} from '@nx/devkit';\nimport { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils';\nimport { ViteBuildExecutorOptions } from '../../executors/build/schema';\nimport { updateBuildOutDirAndRoot } from './lib/edit-build-config';\nimport { updateTestConfig } from './lib/edit-test-config';\nimport { addFileReplacements } from './lib/add-file-replacements';\nimport { tsquery } from '@phenomnomnominal/tsquery';\nimport ts = require('typescript');\nimport { findViteConfig } from '../../utils/find-vite-config';\n\nexport default async function updateBuildDir(tree: Tree) {\n const projects = getProjects(tree);\n forEachExecutorOptions<ViteBuildExecutorOptions>(\n tree,\n '@nx/vite:build',\n (options, projectName, targetName) => {\n const projectConfig = projects.get(projectName);\n const config =\n options.configFile || findViteConfig(tree, projectConfig.root);\n if (!config || !tree.exists(config)) {\n return;\n }\n let configContents = tree.read(config, 'utf-8');\n\n configContents = updateBuildOutDirAndRoot(\n options,\n configContents,\n projectConfig,\n targetName,\n tree,\n projectName,\n config\n );\n\n configContents = updateTestConfig(configContents, projectConfig, config);\n\n if (options['fileReplacements']?.length > 0) {\n configContents = addFileReplacements(\n configContents,\n options['fileReplacements'],\n config\n );\n }\n\n tree.write(config, configContents);\n }\n );\n\n await formatFiles(tree);\n}\n\nexport function getConfigNode(configFileContents: string): ts.Node | undefined {\n if (!configFileContents) {\n return;\n }\n let configNode = tsquery.query(\n configFileContents,\n `CallExpression:has(Identifier[name=defineConfig]) > ObjectLiteralExpression`\n )?.[0];\n\n if (!configNode) {\n const arrowFunctionReturnStatement = tsquery.query(\n configFileContents,\n `ArrowFunction Block ReturnStatement ObjectLiteralExpression`\n )?.[0];\n\n if (arrowFunctionReturnStatement) {\n configNode = arrowFunctionReturnStatement;\n }\n }\n\n return configNode;\n}\n\nexport function notFoundWarning(configPath: string) {\n logger.warn(`\n Could not migrate your ${configPath} file.\n Please add the build.outDir and root options in your ${configPath} file.\n You can find more information on how to configure vite for Nx here:\n \n https://nx.dev/recipes/vite/configure-vite\n `);\n}\n"],"names":["updateBuildDir","getConfigNode","notFoundWarning","ts","tree","projects","getProjects","forEachExecutorOptions","options","projectName","targetName","projectConfig","get","config","configFile","findViteConfig","root","exists","configContents","read","updateBuildOutDirAndRoot","updateTestConfig","length","addFileReplacements","write","formatFiles","configFileContents","tsquery","configNode","query","arrowFunctionReturnStatement","configPath","logger","warn"],"mappings":";;;;;;;;IAgBA,OAuCC;eAvC6BA;;IAyCdC,aAAa;eAAbA;;IAuBAC,eAAe;eAAfA;;;wBA1ET;sCACgC;iCAEE;gCACR;qCACG;yBACZ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cAAM,CAACC,IAAI,CAAC,CAAC;yBACU,EAAEF,WAAW;uDACiB,EAAEA,WAAW;;;;EAIlE,CAAC;AACH"}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -140,9 +140,10 @@ function previewTarget(projectRoot) {
|
|
|
140
140
|
}
|
|
141
141
|
async function testTarget(namedInputs, outputs, projectRoot) {
|
|
142
142
|
return {
|
|
143
|
-
command: `vitest
|
|
143
|
+
command: `vitest`,
|
|
144
144
|
options: {
|
|
145
|
-
cwd: (0, _devkit.joinPathFragments)(projectRoot)
|
|
145
|
+
cwd: (0, _devkit.joinPathFragments)(projectRoot),
|
|
146
|
+
watch: false
|
|
146
147
|
},
|
|
147
148
|
cache: true,
|
|
148
149
|
inputs: [
|
|
@@ -1 +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 const hasRemixPlugin =\n viteConfig.plugins && viteConfig.plugins.some((p) => p.name === 'remix');\n if (\n !configFilePath.includes('vitest.config') &&\n !hasRemixPlugin &&\n isBuildable\n ) {\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","hasRemixPlugin","plugins","some","p","name","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;QACj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,EAAEG,IAAAA,cAAQ,EAAChE,qBAAa,EAAE6D,YAAY,CAAC;QACjE,OAAO;YACL,IAAIA,WAAWI,UAAU,CAAC,OAAO;gBAC/B,OAAOlF,IAAAA,UAAI,EAAC,mBAAmBA,IAAAA,UAAI,EAACa,aAAaiE;YACnD,OAAO;gBACL,OAAO9E,IAAAA,UAAI,EAAC,iBAAiB8E;YAC/B;QACF;IACF;AACF;AAEA,SAAS3D,iBAAiBR,OAA0B;QAElDA,UACAA,WACAA,WACAA,WACAA;IALAA,kBAAAA,UAAAA,UAAY,CAAC;;IACbA,qBAAAA,WAAAA,SAAQqC,8CAARrC,SAAQqC,kBAAoB;;IAC5BrC,qBAAAA,YAAAA,SAAQuC,8CAARvC,UAAQuC,kBAAoB;;IAC5BvC,uBAAAA,YAAAA,SAAQyC,kDAARzC,UAAQyC,oBAAsB;;IAC9BzC,oBAAAA,YAAAA,SAAQ6C,4CAAR7C,UAAQ6C,iBAAmB;;IAC3B7C,2BAAAA,YAAAA,SAAQ2C,0DAAR3C,UAAQ2C,wBAA0B;IAClC,OAAO3C;AACT"}
|
|
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 const hasRemixPlugin =\n viteConfig.plugins && viteConfig.plugins.some((p) => p.name === 'remix');\n if (\n !configFilePath.includes('vitest.config') &&\n !hasRemixPlugin &&\n isBuildable\n ) {\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`,\n options: { cwd: joinPathFragments(projectRoot), watch: false },\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","hasRemixPlugin","plugins","some","p","name","buildTargetName","buildTarget","serveTargetName","serveTarget","previewTargetName","previewTarget","serveStaticTargetName","serveStaticTarget","testTargetName","testTarget","outputs","command","cwd","cache","dependsOn","inputs","externalDependencies","targetConfig","watch","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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YAAY;QACf,IAAIlE,gBAAgB,KAAK;YACvB,OAAO,CAAC,cAAc,EAAEmE,KAAK,CAAC;QAChC,OAAO;YACL,OAAO,CAAC,gBAAgB,EAAEA,KAAK,cAAc,CAAC;QAChD;IACF,OAAO;QACL,IAAIC,IAAAA,gBAAU,EAACF,aAAa;YAC1B,OAAO,CAAC,gBAAgB,EAAEG,IAAAA,cAAQ,EAACjE,qBAAa,EAAE8D,YAAY,CAAC;QACjE,OAAO;YACL,IAAIA,WAAWI,UAAU,CAAC,OAAO;gBAC/B,OAAOnF,IAAAA,UAAI,EAAC,mBAAmBA,IAAAA,UAAI,EAACa,aAAakE;YACnD,OAAO;gBACL,OAAO/E,IAAAA,UAAI,EAAC,iBAAiB+E;YAC/B;QACF;IACF;AACF;AAEA,SAAS5D,iBAAiBR,OAA0B;QAElDA,UACAA,WACAA,WACAA,WACAA;IALAA,kBAAAA,UAAAA,UAAY,CAAC;;IACbA,qBAAAA,WAAAA,SAAQqC,8CAARrC,SAAQqC,kBAAoB;;IAC5BrC,qBAAAA,YAAAA,SAAQuC,8CAARvC,UAAQuC,kBAAoB;;IAC5BvC,uBAAAA,YAAAA,SAAQyC,kDAARzC,UAAQyC,oBAAsB;;IAC9BzC,oBAAAA,YAAAA,SAAQ6C,4CAAR7C,UAAQ6C,iBAAmB;;IAC3B7C,2BAAAA,YAAAA,SAAQ2C,0DAAR3C,UAAQ2C,wBAA0B;IAClC,OAAO3C;AACT"}
|
|
@@ -333,7 +333,7 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
|
|
|
333
333
|
const testOption = options.includeVitest ? `test: {
|
|
334
334
|
globals: true,
|
|
335
335
|
cache: {
|
|
336
|
-
dir: '${(0, _devkit.offsetFromRoot)(projectRoot)
|
|
336
|
+
dir: '${normalizedJoinPaths((0, _devkit.offsetFromRoot)(projectRoot), 'node_modules', '.vitest', projectRoot === '.' ? options.project : projectRoot)}'
|
|
337
337
|
},
|
|
338
338
|
environment: '${(_options_testEnvironment = options.testEnvironment) != null ? _options_testEnvironment : 'jsdom'}',
|
|
339
339
|
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
@@ -362,9 +362,9 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
|
|
|
362
362
|
// worker: {
|
|
363
363
|
// plugins: [ nxViteTsPaths() ],
|
|
364
364
|
// },`;
|
|
365
|
-
const cacheDir = `cacheDir: '${(0, _devkit.offsetFromRoot)(projectRoot)
|
|
365
|
+
const cacheDir = `cacheDir: '${normalizedJoinPaths((0, _devkit.offsetFromRoot)(projectRoot), 'node_modules', '.vite', projectRoot === '.' ? options.project : projectRoot)}',`;
|
|
366
366
|
if (tree.exists(viteConfigPath)) {
|
|
367
|
-
handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, (0, _devkit.offsetFromRoot)(projectRoot), projectAlreadyHasViteTargets);
|
|
367
|
+
handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, projectRoot, (0, _devkit.offsetFromRoot)(projectRoot), projectAlreadyHasViteTargets);
|
|
368
368
|
return;
|
|
369
369
|
}
|
|
370
370
|
viteConfigContent = `
|
|
@@ -463,7 +463,7 @@ async function handleUnknownConfiguration(projectName) {
|
|
|
463
463
|
`);
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
|
-
function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, offsetFromRoot, projectAlreadyHasViteTargets) {
|
|
466
|
+
function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, projectRoot, offsetFromRoot, projectAlreadyHasViteTargets) {
|
|
467
467
|
if ((projectAlreadyHasViteTargets == null ? void 0 : projectAlreadyHasViteTargets.build) && (projectAlreadyHasViteTargets == null ? void 0 : projectAlreadyHasViteTargets.test)) {
|
|
468
468
|
return;
|
|
469
469
|
}
|
|
@@ -500,7 +500,7 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
|
|
|
500
500
|
const testOptionObject = {
|
|
501
501
|
globals: true,
|
|
502
502
|
cache: {
|
|
503
|
-
dir:
|
|
503
|
+
dir: normalizedJoinPaths(offsetFromRoot, 'node_modules', '.vitest', projectRoot === '.' ? options.project : projectRoot)
|
|
504
504
|
},
|
|
505
505
|
environment: (_options_testEnvironment = options.testEnvironment) != null ? _options_testEnvironment : 'jsdom',
|
|
506
506
|
include: [
|
|
@@ -523,5 +523,9 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
|
|
|
523
523
|
`);
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
|
+
function normalizedJoinPaths(...paths) {
|
|
527
|
+
const path = (0, _devkit.joinPathFragments)(...paths);
|
|
528
|
+
return path.startsWith('.') ? path : `./${path}`;
|
|
529
|
+
}
|
|
526
530
|
|
|
527
531
|
//# sourceMappingURL=generator-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/vite/src/utils/generator-utils.ts"],"sourcesContent":["import {\n joinPathFragments,\n logger,\n offsetFromRoot,\n readJson,\n readProjectConfiguration,\n TargetConfiguration,\n Tree,\n updateProjectConfiguration,\n writeJson,\n} from '@nx/devkit';\nimport { ViteBuildExecutorOptions } from '../executors/build/schema';\nimport { VitePreviewServerExecutorOptions } from '../executors/preview-server/schema';\nimport { VitestExecutorOptions } from '../executors/test/schema';\nimport { ViteConfigurationGeneratorSchema } from '../generators/configuration/schema';\nimport { ensureViteConfigIsCorrect } from './vite-config-edit-utils';\nimport { addBuildTargetDefaults } from '@nx/devkit/src/generators/add-build-target-defaults';\n\nexport type Target = 'build' | 'serve' | 'test' | 'preview';\nexport type TargetFlags = Partial<Record<Target, boolean>>;\nexport type UserProvidedTargetName = Partial<Record<Target, string>>;\nexport type ValidFoundTargetName = Partial<Record<Target, string>>;\n\nexport function findExistingJsBuildTargetInProject(targets: {\n [targetName: string]: TargetConfiguration;\n}): {\n supported?: string;\n unsupported?: string;\n} {\n const output: {\n supported?: string;\n unsupported?: string;\n } = {};\n\n const supportedExecutors = {\n build: ['@nx/js:babel', '@nx/js:swc', '@nx/rollup:rollup'],\n };\n const unsupportedExecutors = [\n '@nx/angular:ng-packagr-lite',\n '@nx/angular:package',\n '@nx/angular:webpack-browser',\n '@nx/esbuild:esbuild',\n '@nx/react-native:run-ios',\n '@nx/react-native:start',\n '@nx/react-native:run-android',\n '@nx/react-native:bundle',\n '@nx/react-native:build-android',\n '@nx/react-native:bundle',\n '@nx/next:build',\n '@nx/js:tsc',\n '@nrwl/angular:ng-packagr-lite',\n '@nrwl/angular:package',\n '@nrwl/angular:webpack-browser',\n '@nrwl/esbuild:esbuild',\n '@nrwl/react-native:run-ios',\n '@nrwl/react-native:start',\n '@nrwl/react-native:run-android',\n '@nrwl/react-native:bundle',\n '@nrwl/react-native:build-android',\n '@nrwl/react-native:bundle',\n '@nrwl/next:build',\n '@nrwl/js:tsc',\n '@angular-devkit/build-angular:browser',\n '@angular-devkit/build-angular:browser-esbuild',\n '@angular-devkit/build-angular:application',\n ];\n\n // We try to find the target that is using the supported executors\n // for build since this is the one we will be converting\n for (const target in targets) {\n const executorName = targets[target].executor;\n if (supportedExecutors.build.includes(executorName)) {\n output.supported = target;\n } else if (unsupportedExecutors.includes(executorName)) {\n output.unsupported = target;\n }\n }\n return output;\n}\n\nexport function addOrChangeTestTarget(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema,\n target: string\n) {\n const project = readProjectConfiguration(tree, options.project);\n\n const reportsDirectory = joinPathFragments(\n offsetFromRoot(project.root),\n 'coverage',\n project.root === '.' ? options.project : project.root\n );\n const testOptions: VitestExecutorOptions = {\n reportsDirectory,\n };\n\n project.targets ??= {};\n\n if (project.targets[target]) {\n project.targets[target].executor = '@nx/vite:test';\n delete project.targets[target].options?.jestConfig;\n } else {\n project.targets[target] = {\n executor: '@nx/vite:test',\n outputs: ['{options.reportsDirectory}'],\n options: testOptions,\n };\n }\n\n updateProjectConfiguration(tree, options.project, project);\n}\n\nexport function addBuildTarget(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema,\n target: string\n) {\n addBuildTargetDefaults(tree, '@nx/vite:build');\n const project = readProjectConfiguration(tree, options.project);\n const buildOptions: ViteBuildExecutorOptions = {\n outputPath: joinPathFragments(\n 'dist',\n project.root != '.' ? project.root : options.project\n ),\n };\n project.targets ??= {};\n project.targets[target] = {\n executor: '@nx/vite:build',\n outputs: ['{options.outputPath}'],\n defaultConfiguration: 'production',\n options: buildOptions,\n configurations: {\n development: {\n mode: 'development',\n },\n production: {\n mode: 'production',\n },\n },\n };\n\n updateProjectConfiguration(tree, options.project, project);\n}\n\nexport function addServeTarget(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema,\n target: string\n) {\n const project = readProjectConfiguration(tree, options.project);\n\n project.targets ??= {};\n\n project.targets[target] = {\n executor: '@nx/vite:dev-server',\n defaultConfiguration: 'development',\n options: {\n buildTarget: `${options.project}:build`,\n },\n configurations: {\n development: {\n buildTarget: `${options.project}:build:development`,\n hmr: true,\n },\n production: {\n buildTarget: `${options.project}:build:production`,\n hmr: false,\n },\n },\n };\n\n updateProjectConfiguration(tree, options.project, project);\n}\n\n/**\n * Adds a target for the preview server.\n *\n * @param tree\n * @param options\n * @param serveTarget An existing serve target.\n */\nexport function addPreviewTarget(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema,\n serveTarget: string\n) {\n const project = readProjectConfiguration(tree, options.project);\n\n const previewOptions: VitePreviewServerExecutorOptions = {\n buildTarget: `${options.project}:build`,\n };\n\n project.targets ??= {};\n\n // Update the options from the passed serve target.\n if (project.targets[serveTarget]) {\n const target = project.targets[serveTarget];\n if (target.executor === '@nxext/vite:dev') {\n previewOptions.proxyConfig = target.options.proxyConfig;\n }\n previewOptions['https'] = target.options?.https;\n previewOptions['open'] = target.options?.open;\n }\n\n // Adds a preview target.\n project.targets.preview = {\n executor: '@nx/vite:preview-server',\n defaultConfiguration: 'development',\n options: previewOptions,\n configurations: {\n development: {\n buildTarget: `${options.project}:build:development`,\n },\n production: {\n buildTarget: `${options.project}:build:production`,\n },\n },\n };\n\n updateProjectConfiguration(tree, options.project, project);\n}\n\nexport function editTsConfig(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema\n) {\n const projectConfig = readProjectConfiguration(tree, options.project);\n\n const config = readJson(tree, `${projectConfig.root}/tsconfig.json`);\n\n switch (options.uiFramework) {\n case 'react':\n config.compilerOptions = {\n jsx: 'react-jsx',\n allowJs: false,\n esModuleInterop: false,\n allowSyntheticDefaultImports: true,\n strict: true,\n };\n break;\n case 'none':\n config.compilerOptions = {\n module: 'commonjs',\n forceConsistentCasingInFileNames: true,\n strict: true,\n noImplicitOverride: true,\n noPropertyAccessFromIndexSignature: true,\n noImplicitReturns: true,\n noFallthroughCasesInSwitch: true,\n };\n break;\n default:\n break;\n }\n\n writeJson(tree, `${projectConfig.root}/tsconfig.json`, config);\n}\n\nexport function deleteWebpackConfig(\n tree: Tree,\n projectRoot: string,\n webpackConfigFilePath?: string\n) {\n const webpackConfigPath =\n webpackConfigFilePath && tree.exists(webpackConfigFilePath)\n ? webpackConfigFilePath\n : tree.exists(`${projectRoot}/webpack.config.js`)\n ? `${projectRoot}/webpack.config.js`\n : tree.exists(`${projectRoot}/webpack.config.ts`)\n ? `${projectRoot}/webpack.config.ts`\n : null;\n if (webpackConfigPath) {\n tree.delete(webpackConfigPath);\n }\n}\n\nexport function moveAndEditIndexHtml(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema\n) {\n const projectConfig = readProjectConfiguration(tree, options.project);\n\n let indexHtmlPath = `${projectConfig.root}/src/index.html`;\n let mainPath = `${projectConfig.root}/src/main.ts${\n options.uiFramework === 'react' ? 'x' : ''\n }`;\n\n if (projectConfig.root !== '.') {\n mainPath = mainPath.replace(projectConfig.root, '');\n }\n\n if (\n !tree.exists(indexHtmlPath) &&\n tree.exists(`${projectConfig.root}/index.html`)\n ) {\n indexHtmlPath = `${projectConfig.root}/index.html`;\n }\n\n if (tree.exists(indexHtmlPath)) {\n const indexHtmlContent = tree.read(indexHtmlPath, 'utf8');\n if (\n !indexHtmlContent.includes(\n `<script type='module' src='${mainPath}'></script>`\n )\n ) {\n tree.write(\n `${projectConfig.root}/index.html`,\n indexHtmlContent.replace(\n '</body>',\n `<script type='module' src='${mainPath}'></script>\n </body>`\n )\n );\n\n if (tree.exists(`${projectConfig.root}/src/index.html`)) {\n tree.delete(`${projectConfig.root}/src/index.html`);\n }\n }\n } else {\n tree.write(\n `${projectConfig.root}/index.html`,\n `<!DOCTYPE html>\n <html lang='en'>\n <head>\n <meta charset='UTF-8' />\n <link rel='icon' href='/favicon.ico' />\n <meta name='viewport' content='width=device-width, initial-scale=1.0' />\n <title>Vite</title>\n </head>\n <body>\n <div id='root'></div>\n <script type='module' src='${mainPath}'></script>\n </body>\n </html>`\n );\n }\n}\n\nexport interface ViteConfigFileOptions {\n project: string;\n includeLib?: boolean;\n includeVitest?: boolean;\n inSourceTests?: boolean;\n testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;\n rollupOptionsExternal?: string[];\n imports?: string[];\n plugins?: string[];\n coverageProvider?: 'v8' | 'istanbul' | 'custom';\n}\n\nexport function createOrEditViteConfig(\n tree: Tree,\n options: ViteConfigFileOptions,\n onlyVitest: boolean,\n projectAlreadyHasViteTargets?: TargetFlags,\n vitestFileName?: boolean\n) {\n const { root: projectRoot } = readProjectConfiguration(tree, options.project);\n\n const viteConfigPath = vitestFileName\n ? `${projectRoot}/vitest.config.ts`\n : `${projectRoot}/vite.config.ts`;\n\n const buildOutDir =\n projectRoot === '.'\n ? `./dist/${options.project}`\n : `${offsetFromRoot(projectRoot)}dist/${projectRoot}`;\n\n const buildOption = onlyVitest\n ? ''\n : options.includeLib\n ? `\n // Configuration for building your library.\n // See: https://vitejs.dev/guide/build.html#library-mode\n build: {\n outDir: '${buildOutDir}',\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n lib: {\n // Could also be a dictionary or array of multiple entry points.\n entry: 'src/index.ts',\n name: '${options.project}',\n fileName: 'index',\n // Change this to the formats you want to support.\n // Don't forget to update your package.json as well.\n formats: ['es', 'cjs']\n },\n rollupOptions: {\n // External packages that should not be bundled into your library.\n external: [${options.rollupOptionsExternal ?? ''}]\n },\n },`\n : `\n build: {\n outDir: '${buildOutDir}',\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n },\n `;\n\n const imports: string[] = options.imports ? options.imports : [];\n\n if (!onlyVitest && options.includeLib) {\n imports.push(\n `import dts from 'vite-plugin-dts'`,\n `import * as path from 'path'`\n );\n }\n\n let viteConfigContent = '';\n\n const plugins = options.plugins\n ? [...options.plugins, `nxViteTsPaths()`]\n : [`nxViteTsPaths()`];\n\n if (!onlyVitest && options.includeLib) {\n plugins.push(\n `dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json') })`\n );\n }\n\n const reportsDirectory =\n projectRoot === '.'\n ? `./coverage/${options.project}`\n : `${offsetFromRoot(projectRoot)}coverage/${projectRoot}`;\n\n const testOption = options.includeVitest\n ? `test: {\n globals: true,\n cache: {\n dir: '${offsetFromRoot(projectRoot)}node_modules/.vitest'\n },\n environment: '${options.testEnvironment ?? 'jsdom'}',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n ${\n options.inSourceTests\n ? `includeSource: ['src/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],`\n : ''\n }\n reporters: ['default'],\n coverage: {\n reportsDirectory: '${reportsDirectory}',\n provider: ${\n options.coverageProvider ? `'${options.coverageProvider}'` : `'v8'`\n },\n }\n },`\n : '';\n\n const defineOption = options.inSourceTests\n ? `define: {\n 'import.meta.vitest': undefined\n },`\n : '';\n\n const devServerOption = onlyVitest\n ? ''\n : options.includeLib\n ? ''\n : `\n server:{\n port: 4200,\n host: 'localhost',\n },`;\n\n const previewServerOption = onlyVitest\n ? ''\n : options.includeLib\n ? ''\n : `\n preview:{\n port: 4300,\n host: 'localhost',\n },`;\n\n const workerOption = `\n // Uncomment this if you are using workers. \n // worker: {\n // plugins: [ nxViteTsPaths() ],\n // },`;\n\n const cacheDir = `cacheDir: '${offsetFromRoot(\n projectRoot\n )}node_modules/.vite/${projectRoot}',`;\n\n if (tree.exists(viteConfigPath)) {\n handleViteConfigFileExists(\n tree,\n viteConfigPath,\n options,\n buildOption,\n buildOutDir,\n imports,\n plugins,\n testOption,\n reportsDirectory,\n cacheDir,\n offsetFromRoot(projectRoot),\n projectAlreadyHasViteTargets\n );\n return;\n }\n\n viteConfigContent = `\n /// <reference types='vitest' />\n import { defineConfig } from 'vite';\n ${imports.join(';\\n')}${imports.length ? ';' : ''}\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n \n export default defineConfig({\n root: __dirname,\n ${cacheDir}\n ${devServerOption}\n ${previewServerOption}\n \n plugins: [${plugins.join(',\\n')}],\n ${workerOption}\n ${buildOption}\n ${defineOption}\n ${testOption}\n });`;\n\n tree.write(viteConfigPath, viteConfigContent);\n}\n\nexport function normalizeViteConfigFilePathWithTree(\n tree: Tree,\n projectRoot: string,\n configFile?: string\n): string {\n return configFile && tree.exists(configFile)\n ? configFile\n : tree.exists(joinPathFragments(`${projectRoot}/vite.config.ts`))\n ? joinPathFragments(`${projectRoot}/vite.config.ts`)\n : tree.exists(joinPathFragments(`${projectRoot}/vite.config.js`))\n ? joinPathFragments(`${projectRoot}/vite.config.js`)\n : undefined;\n}\n\nexport function getViteConfigPathForProject(\n tree: Tree,\n projectName: string,\n target?: string\n) {\n let viteConfigPath: string | undefined;\n const { targets, root } = readProjectConfiguration(tree, projectName);\n if (target) {\n viteConfigPath = targets?.[target]?.options?.configFile;\n } else {\n const config = Object.values(targets).find(\n (config) =>\n config.executor === '@nrwl/nx:build' ||\n config.executor === '@nrwl/vite:build'\n );\n viteConfigPath = config?.options?.configFile;\n }\n\n return normalizeViteConfigFilePathWithTree(tree, root, viteConfigPath);\n}\n\nexport async function handleUnsupportedUserProvidedTargets(\n userProvidedTargetIsUnsupported: TargetFlags,\n userProvidedTargetName: UserProvidedTargetName,\n validFoundTargetName: ValidFoundTargetName\n) {\n if (userProvidedTargetIsUnsupported.build && validFoundTargetName.build) {\n await handleUnsupportedUserProvidedTargetsErrors(\n userProvidedTargetName.build,\n validFoundTargetName.build,\n 'build',\n 'build'\n );\n }\n\n if (userProvidedTargetIsUnsupported.serve && validFoundTargetName.serve) {\n await handleUnsupportedUserProvidedTargetsErrors(\n userProvidedTargetName.serve,\n validFoundTargetName.serve,\n 'serve',\n 'dev-server'\n );\n }\n\n if (userProvidedTargetIsUnsupported.test && validFoundTargetName.test) {\n await handleUnsupportedUserProvidedTargetsErrors(\n userProvidedTargetName.test,\n validFoundTargetName.test,\n 'test',\n 'test'\n );\n }\n}\n\nasync function handleUnsupportedUserProvidedTargetsErrors(\n userProvidedTargetName: string,\n validFoundTargetName: string,\n target: Target,\n executor: 'build' | 'dev-server' | 'test'\n) {\n logger.warn(\n `The custom ${target} target you provided (${userProvidedTargetName}) cannot be converted to use the @nx/vite:${executor} executor.\n However, we found the following ${target} target in your project that can be converted: ${validFoundTargetName}\n\n Please note that converting a potentially non-compatible project to use Vite.js may result in unexpected behavior. Always commit\n your changes before converting a project to use Vite.js, and test the converted project thoroughly before deploying it.\n `\n );\n const { Confirm } = require('enquirer');\n const prompt = new Confirm({\n name: 'question',\n message: `Should we convert the ${validFoundTargetName} target to use the @nx/vite:${executor} executor?`,\n initial: true,\n });\n const shouldConvert = await prompt.run();\n if (!shouldConvert) {\n throw new Error(\n `The ${target} target ${userProvidedTargetName} cannot be converted to use the @nx/vite:${executor} executor.\n Please try again, either by providing a different ${target} target or by not providing a target at all (Nx will\n convert the first one it finds, most probably this one: ${validFoundTargetName})\n\n Please note that converting a potentially non-compatible project to use Vite.js may result in unexpected behavior. Always commit\n your changes before converting a project to use Vite.js, and test the converted project thoroughly before deploying it.\n `\n );\n }\n}\n\nexport async function handleUnknownConfiguration(projectName: string) {\n if (process.env.NX_INTERACTIVE === 'false') {\n return;\n }\n\n logger.warn(\n `\n We could not find any configuration in project ${projectName} that \n indicates whether we can definitely convert to Vite.\n \n If you still want to convert your project to use Vite,\n please make sure to commit your changes before running this generator.\n `\n );\n\n const { Confirm } = require('enquirer');\n const prompt = new Confirm({\n name: 'question',\n message: `Should Nx convert your project to use Vite?`,\n initial: true,\n });\n const shouldConvert = await prompt.run();\n if (!shouldConvert) {\n throw new Error(`\n Nx could not verify that your project can be converted to use Vite.\n Please try again with a different project.\n `);\n }\n}\n\nfunction handleViteConfigFileExists(\n tree: Tree,\n viteConfigPath: string,\n options: ViteConfigFileOptions,\n buildOption: string,\n buildOutDir: string,\n imports: string[],\n plugins: string[],\n testOption: string,\n reportsDirectory: string,\n cacheDir: string,\n offsetFromRoot: string,\n projectAlreadyHasViteTargets?: TargetFlags\n) {\n if (\n projectAlreadyHasViteTargets?.build &&\n projectAlreadyHasViteTargets?.test\n ) {\n return;\n }\n\n if (process.env.NX_VERBOSE_LOGGING === 'true') {\n logger.info(\n `vite.config.ts already exists for project ${options.project}.`\n );\n }\n\n const buildOptionObject = options.includeLib\n ? {\n lib: {\n entry: 'src/index.ts',\n name: options.project,\n fileName: 'index',\n formats: ['es', 'cjs'],\n },\n rollupOptions: {\n external: options.rollupOptionsExternal ?? [],\n },\n outDir: buildOutDir,\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n }\n : {\n outDir: buildOutDir,\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n };\n\n const testOptionObject = {\n globals: true,\n cache: {\n dir: `${offsetFromRoot}node_modules/.vitest`,\n },\n environment: options.testEnvironment ?? 'jsdom',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n reporters: ['default'],\n coverage: {\n reportsDirectory: reportsDirectory,\n provider: `${options.coverageProvider ?? 'v8'}`,\n },\n };\n\n const changed = ensureViteConfigIsCorrect(\n tree,\n viteConfigPath,\n buildOption,\n buildOptionObject,\n imports,\n plugins,\n testOption,\n testOptionObject,\n cacheDir,\n projectAlreadyHasViteTargets ?? {}\n );\n\n if (!changed) {\n logger.warn(\n `Make sure the following setting exists in your Vite configuration file (${viteConfigPath}):\n \n ${buildOption}\n \n `\n );\n }\n}\n"],"names":["findExistingJsBuildTargetInProject","addOrChangeTestTarget","addBuildTarget","addServeTarget","addPreviewTarget","editTsConfig","deleteWebpackConfig","moveAndEditIndexHtml","createOrEditViteConfig","normalizeViteConfigFilePathWithTree","getViteConfigPathForProject","handleUnsupportedUserProvidedTargets","handleUnknownConfiguration","targets","output","supportedExecutors","build","unsupportedExecutors","target","executorName","executor","includes","supported","unsupported","tree","options","project","readProjectConfiguration","reportsDirectory","joinPathFragments","offsetFromRoot","root","testOptions","jestConfig","outputs","updateProjectConfiguration","addBuildTargetDefaults","buildOptions","outputPath","defaultConfiguration","configurations","development","mode","production","buildTarget","hmr","serveTarget","previewOptions","proxyConfig","https","open","preview","projectConfig","config","readJson","uiFramework","compilerOptions","jsx","allowJs","esModuleInterop","allowSyntheticDefaultImports","strict","module","forceConsistentCasingInFileNames","noImplicitOverride","noPropertyAccessFromIndexSignature","noImplicitReturns","noFallthroughCasesInSwitch","writeJson","projectRoot","webpackConfigFilePath","webpackConfigPath","exists","delete","indexHtmlPath","mainPath","replace","indexHtmlContent","read","write","onlyVitest","projectAlreadyHasViteTargets","vitestFileName","viteConfigPath","buildOutDir","buildOption","includeLib","rollupOptionsExternal","imports","push","viteConfigContent","plugins","testOption","includeVitest","testEnvironment","inSourceTests","coverageProvider","defineOption","devServerOption","previewServerOption","workerOption","cacheDir","handleViteConfigFileExists","join","length","configFile","undefined","projectName","Object","values","find","userProvidedTargetIsUnsupported","userProvidedTargetName","validFoundTargetName","handleUnsupportedUserProvidedTargetsErrors","serve","test","logger","warn","Confirm","require","prompt","name","message","initial","shouldConvert","run","Error","process","env","NX_INTERACTIVE","NX_VERBOSE_LOGGING","info","buildOptionObject","lib","entry","fileName","formats","rollupOptions","external","outDir","reportCompressedSize","commonjsOptions","transformMixedEsModules","testOptionObject","globals","cache","dir","environment","include","reporters","coverage","provider","changed","ensureViteConfigIsCorrect"],"mappings":";;;;;;;;IAuBgBA,kCAAkC;eAAlCA;;IAyDAC,qBAAqB;eAArBA;;IAgCAC,cAAc;eAAdA;;IAgCAC,cAAc;eAAdA;;IAqCAC,gBAAgB;eAAhBA;;IAyCAC,YAAY;eAAZA;;IAoCAC,mBAAmB;eAAnBA;;IAkBAC,oBAAoB;eAApBA;;IA0EAC,sBAAsB;eAAtBA;;IAmLAC,mCAAmC;eAAnCA;;IAcAC,2BAA2B;eAA3BA;;IAqBMC,oCAAoC;eAApCA;;IAmEAC,0BAA0B;eAA1BA;;;wBA7mBf;qCAKmC;wCACH;AAOhC,SAASZ,mCAAmCa,OAElD;IAIC,MAAMC,SAGF,CAAC;IAEL,MAAMC,qBAAqB;QACzBC,OAAO;YAAC;YAAgB;YAAc;SAAoB;IAC5D;IACA,MAAMC,uBAAuB;QAC3B;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IAED,kEAAkE;IAClE,wDAAwD;IACxD,IAAK,MAAMC,UAAUL,QAAS;QAC5B,MAAMM,eAAeN,OAAO,CAACK,OAAO,CAACE,QAAQ;QAC7C,IAAIL,mBAAmBC,KAAK,CAACK,QAAQ,CAACF,eAAe;YACnDL,OAAOQ,SAAS,GAAGJ;QACrB,OAAO,IAAID,qBAAqBI,QAAQ,CAACF,eAAe;YACtDL,OAAOS,WAAW,GAAGL;QACvB;IACF;IACA,OA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bC,UAAUlH,CAAAA,iCAAAA,QAAQ8D,qBAAqB,YAA7B9D,iCAAiC,EAAE;QAC/C;QACAmH,QAAQxD;QACRyD,sBAAsB;QACtBC,iBAAiB;YACfC,yBAAyB;QAC3B;IACF,IACA;QACEH,QAAQxD;QACRyD,sBAAsB;QACtBC,iBAAiB;YACfC,yBAAyB;QAC3B;IACF;QAOWtH,0BAKEA;IAVjB,MAAMuH,mBAAmB;QACvBC,SAAS;QACTC,OAAO;YACLC,KAAK,CAAC,EAAErH,eAAe,oBAAoB,CAAC;QAC9C;QACAsH,aAAa3H,CAAAA,2BAAAA,QAAQqE,eAAe,YAAvBrE,2BAA2B;QACxC4H,SAAS;YAAC;SAAuD;QACjEC,WAAW;YAAC;SAAU;QACtBC,UAAU;YACR3H,kBAAkBA;YAClB4H,UAAU,CAAC,EAAE/H,CAAAA,4BAAAA,QAAQuE,gBAAgB,YAAxBvE,4BAA4B,KAAK,CAAC;QACjD;IACF;IAEA,MAAMgI,UAAUC,IAAAA,8CAAyB,EACvClI,MACA2D,gBACAE,aACAgD,mBACA7C,SACAG,SACAC,YACAoD,kBACA3C,UACApB,uCAAAA,+BAAgC,CAAC;IAGnC,IAAI,CAACwE,SAAS;QACZpC,cAAM,CAACC,IAAI,CACT,CAAC,wEAAwE,EAAEnC,eAAe;;QAExF,EAAEE,YAAY;;QAEd,CAAC;IAEP;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/vite/src/utils/generator-utils.ts"],"sourcesContent":["import {\n joinPathFragments,\n logger,\n offsetFromRoot,\n readJson,\n readProjectConfiguration,\n TargetConfiguration,\n Tree,\n updateProjectConfiguration,\n writeJson,\n} from '@nx/devkit';\nimport { ViteBuildExecutorOptions } from '../executors/build/schema';\nimport { VitePreviewServerExecutorOptions } from '../executors/preview-server/schema';\nimport { VitestExecutorOptions } from '../executors/test/schema';\nimport { ViteConfigurationGeneratorSchema } from '../generators/configuration/schema';\nimport { ensureViteConfigIsCorrect } from './vite-config-edit-utils';\nimport { addBuildTargetDefaults } from '@nx/devkit/src/generators/add-build-target-defaults';\n\nexport type Target = 'build' | 'serve' | 'test' | 'preview';\nexport type TargetFlags = Partial<Record<Target, boolean>>;\nexport type UserProvidedTargetName = Partial<Record<Target, string>>;\nexport type ValidFoundTargetName = Partial<Record<Target, string>>;\n\nexport function findExistingJsBuildTargetInProject(targets: {\n [targetName: string]: TargetConfiguration;\n}): {\n supported?: string;\n unsupported?: string;\n} {\n const output: {\n supported?: string;\n unsupported?: string;\n } = {};\n\n const supportedExecutors = {\n build: ['@nx/js:babel', '@nx/js:swc', '@nx/rollup:rollup'],\n };\n const unsupportedExecutors = [\n '@nx/angular:ng-packagr-lite',\n '@nx/angular:package',\n '@nx/angular:webpack-browser',\n '@nx/esbuild:esbuild',\n '@nx/react-native:run-ios',\n '@nx/react-native:start',\n '@nx/react-native:run-android',\n '@nx/react-native:bundle',\n '@nx/react-native:build-android',\n '@nx/react-native:bundle',\n '@nx/next:build',\n '@nx/js:tsc',\n '@nrwl/angular:ng-packagr-lite',\n '@nrwl/angular:package',\n '@nrwl/angular:webpack-browser',\n '@nrwl/esbuild:esbuild',\n '@nrwl/react-native:run-ios',\n '@nrwl/react-native:start',\n '@nrwl/react-native:run-android',\n '@nrwl/react-native:bundle',\n '@nrwl/react-native:build-android',\n '@nrwl/react-native:bundle',\n '@nrwl/next:build',\n '@nrwl/js:tsc',\n '@angular-devkit/build-angular:browser',\n '@angular-devkit/build-angular:browser-esbuild',\n '@angular-devkit/build-angular:application',\n ];\n\n // We try to find the target that is using the supported executors\n // for build since this is the one we will be converting\n for (const target in targets) {\n const executorName = targets[target].executor;\n if (supportedExecutors.build.includes(executorName)) {\n output.supported = target;\n } else if (unsupportedExecutors.includes(executorName)) {\n output.unsupported = target;\n }\n }\n return output;\n}\n\nexport function addOrChangeTestTarget(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema,\n target: string\n) {\n const project = readProjectConfiguration(tree, options.project);\n\n const reportsDirectory = joinPathFragments(\n offsetFromRoot(project.root),\n 'coverage',\n project.root === '.' ? options.project : project.root\n );\n const testOptions: VitestExecutorOptions = {\n reportsDirectory,\n };\n\n project.targets ??= {};\n\n if (project.targets[target]) {\n project.targets[target].executor = '@nx/vite:test';\n delete project.targets[target].options?.jestConfig;\n } else {\n project.targets[target] = {\n executor: '@nx/vite:test',\n outputs: ['{options.reportsDirectory}'],\n options: testOptions,\n };\n }\n\n updateProjectConfiguration(tree, options.project, project);\n}\n\nexport function addBuildTarget(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema,\n target: string\n) {\n addBuildTargetDefaults(tree, '@nx/vite:build');\n const project = readProjectConfiguration(tree, options.project);\n const buildOptions: ViteBuildExecutorOptions = {\n outputPath: joinPathFragments(\n 'dist',\n project.root != '.' ? project.root : options.project\n ),\n };\n project.targets ??= {};\n project.targets[target] = {\n executor: '@nx/vite:build',\n outputs: ['{options.outputPath}'],\n defaultConfiguration: 'production',\n options: buildOptions,\n configurations: {\n development: {\n mode: 'development',\n },\n production: {\n mode: 'production',\n },\n },\n };\n\n updateProjectConfiguration(tree, options.project, project);\n}\n\nexport function addServeTarget(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema,\n target: string\n) {\n const project = readProjectConfiguration(tree, options.project);\n\n project.targets ??= {};\n\n project.targets[target] = {\n executor: '@nx/vite:dev-server',\n defaultConfiguration: 'development',\n options: {\n buildTarget: `${options.project}:build`,\n },\n configurations: {\n development: {\n buildTarget: `${options.project}:build:development`,\n hmr: true,\n },\n production: {\n buildTarget: `${options.project}:build:production`,\n hmr: false,\n },\n },\n };\n\n updateProjectConfiguration(tree, options.project, project);\n}\n\n/**\n * Adds a target for the preview server.\n *\n * @param tree\n * @param options\n * @param serveTarget An existing serve target.\n */\nexport function addPreviewTarget(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema,\n serveTarget: string\n) {\n const project = readProjectConfiguration(tree, options.project);\n\n const previewOptions: VitePreviewServerExecutorOptions = {\n buildTarget: `${options.project}:build`,\n };\n\n project.targets ??= {};\n\n // Update the options from the passed serve target.\n if (project.targets[serveTarget]) {\n const target = project.targets[serveTarget];\n if (target.executor === '@nxext/vite:dev') {\n previewOptions.proxyConfig = target.options.proxyConfig;\n }\n previewOptions['https'] = target.options?.https;\n previewOptions['open'] = target.options?.open;\n }\n\n // Adds a preview target.\n project.targets.preview = {\n executor: '@nx/vite:preview-server',\n defaultConfiguration: 'development',\n options: previewOptions,\n configurations: {\n development: {\n buildTarget: `${options.project}:build:development`,\n },\n production: {\n buildTarget: `${options.project}:build:production`,\n },\n },\n };\n\n updateProjectConfiguration(tree, options.project, project);\n}\n\nexport function editTsConfig(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema\n) {\n const projectConfig = readProjectConfiguration(tree, options.project);\n\n const config = readJson(tree, `${projectConfig.root}/tsconfig.json`);\n\n switch (options.uiFramework) {\n case 'react':\n config.compilerOptions = {\n jsx: 'react-jsx',\n allowJs: false,\n esModuleInterop: false,\n allowSyntheticDefaultImports: true,\n strict: true,\n };\n break;\n case 'none':\n config.compilerOptions = {\n module: 'commonjs',\n forceConsistentCasingInFileNames: true,\n strict: true,\n noImplicitOverride: true,\n noPropertyAccessFromIndexSignature: true,\n noImplicitReturns: true,\n noFallthroughCasesInSwitch: true,\n };\n break;\n default:\n break;\n }\n\n writeJson(tree, `${projectConfig.root}/tsconfig.json`, config);\n}\n\nexport function deleteWebpackConfig(\n tree: Tree,\n projectRoot: string,\n webpackConfigFilePath?: string\n) {\n const webpackConfigPath =\n webpackConfigFilePath && tree.exists(webpackConfigFilePath)\n ? webpackConfigFilePath\n : tree.exists(`${projectRoot}/webpack.config.js`)\n ? `${projectRoot}/webpack.config.js`\n : tree.exists(`${projectRoot}/webpack.config.ts`)\n ? `${projectRoot}/webpack.config.ts`\n : null;\n if (webpackConfigPath) {\n tree.delete(webpackConfigPath);\n }\n}\n\nexport function moveAndEditIndexHtml(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema\n) {\n const projectConfig = readProjectConfiguration(tree, options.project);\n\n let indexHtmlPath = `${projectConfig.root}/src/index.html`;\n let mainPath = `${projectConfig.root}/src/main.ts${\n options.uiFramework === 'react' ? 'x' : ''\n }`;\n\n if (projectConfig.root !== '.') {\n mainPath = mainPath.replace(projectConfig.root, '');\n }\n\n if (\n !tree.exists(indexHtmlPath) &&\n tree.exists(`${projectConfig.root}/index.html`)\n ) {\n indexHtmlPath = `${projectConfig.root}/index.html`;\n }\n\n if (tree.exists(indexHtmlPath)) {\n const indexHtmlContent = tree.read(indexHtmlPath, 'utf8');\n if (\n !indexHtmlContent.includes(\n `<script type='module' src='${mainPath}'></script>`\n )\n ) {\n tree.write(\n `${projectConfig.root}/index.html`,\n indexHtmlContent.replace(\n '</body>',\n `<script type='module' src='${mainPath}'></script>\n </body>`\n )\n );\n\n if (tree.exists(`${projectConfig.root}/src/index.html`)) {\n tree.delete(`${projectConfig.root}/src/index.html`);\n }\n }\n } else {\n tree.write(\n `${projectConfig.root}/index.html`,\n `<!DOCTYPE html>\n <html lang='en'>\n <head>\n <meta charset='UTF-8' />\n <link rel='icon' href='/favicon.ico' />\n <meta name='viewport' content='width=device-width, initial-scale=1.0' />\n <title>Vite</title>\n </head>\n <body>\n <div id='root'></div>\n <script type='module' src='${mainPath}'></script>\n </body>\n </html>`\n );\n }\n}\n\nexport interface ViteConfigFileOptions {\n project: string;\n includeLib?: boolean;\n includeVitest?: boolean;\n inSourceTests?: boolean;\n testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;\n rollupOptionsExternal?: string[];\n imports?: string[];\n plugins?: string[];\n coverageProvider?: 'v8' | 'istanbul' | 'custom';\n}\n\nexport function createOrEditViteConfig(\n tree: Tree,\n options: ViteConfigFileOptions,\n onlyVitest: boolean,\n projectAlreadyHasViteTargets?: TargetFlags,\n vitestFileName?: boolean\n) {\n const { root: projectRoot } = readProjectConfiguration(tree, options.project);\n\n const viteConfigPath = vitestFileName\n ? `${projectRoot}/vitest.config.ts`\n : `${projectRoot}/vite.config.ts`;\n\n const buildOutDir =\n projectRoot === '.'\n ? `./dist/${options.project}`\n : `${offsetFromRoot(projectRoot)}dist/${projectRoot}`;\n\n const buildOption = onlyVitest\n ? ''\n : options.includeLib\n ? `\n // Configuration for building your library.\n // See: https://vitejs.dev/guide/build.html#library-mode\n build: {\n outDir: '${buildOutDir}',\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n lib: {\n // Could also be a dictionary or array of multiple entry points.\n entry: 'src/index.ts',\n name: '${options.project}',\n fileName: 'index',\n // Change this to the formats you want to support.\n // Don't forget to update your package.json as well.\n formats: ['es', 'cjs']\n },\n rollupOptions: {\n // External packages that should not be bundled into your library.\n external: [${options.rollupOptionsExternal ?? ''}]\n },\n },`\n : `\n build: {\n outDir: '${buildOutDir}',\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n },\n `;\n\n const imports: string[] = options.imports ? options.imports : [];\n\n if (!onlyVitest && options.includeLib) {\n imports.push(\n `import dts from 'vite-plugin-dts'`,\n `import * as path from 'path'`\n );\n }\n\n let viteConfigContent = '';\n\n const plugins = options.plugins\n ? [...options.plugins, `nxViteTsPaths()`]\n : [`nxViteTsPaths()`];\n\n if (!onlyVitest && options.includeLib) {\n plugins.push(\n `dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json') })`\n );\n }\n\n const reportsDirectory =\n projectRoot === '.'\n ? `./coverage/${options.project}`\n : `${offsetFromRoot(projectRoot)}coverage/${projectRoot}`;\n\n const testOption = options.includeVitest\n ? `test: {\n globals: true,\n cache: {\n dir: '${normalizedJoinPaths(\n offsetFromRoot(projectRoot),\n 'node_modules',\n '.vitest',\n projectRoot === '.' ? options.project : projectRoot\n )}'\n },\n environment: '${options.testEnvironment ?? 'jsdom'}',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n ${\n options.inSourceTests\n ? `includeSource: ['src/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],`\n : ''\n }\n reporters: ['default'],\n coverage: {\n reportsDirectory: '${reportsDirectory}',\n provider: ${\n options.coverageProvider ? `'${options.coverageProvider}'` : `'v8'`\n },\n }\n },`\n : '';\n\n const defineOption = options.inSourceTests\n ? `define: {\n 'import.meta.vitest': undefined\n },`\n : '';\n\n const devServerOption = onlyVitest\n ? ''\n : options.includeLib\n ? ''\n : `\n server:{\n port: 4200,\n host: 'localhost',\n },`;\n\n const previewServerOption = onlyVitest\n ? ''\n : options.includeLib\n ? ''\n : `\n preview:{\n port: 4300,\n host: 'localhost',\n },`;\n\n const workerOption = `\n // Uncomment this if you are using workers. \n // worker: {\n // plugins: [ nxViteTsPaths() ],\n // },`;\n\n const cacheDir = `cacheDir: '${normalizedJoinPaths(\n offsetFromRoot(projectRoot),\n 'node_modules',\n '.vite',\n projectRoot === '.' ? options.project : projectRoot\n )}',`;\n\n if (tree.exists(viteConfigPath)) {\n handleViteConfigFileExists(\n tree,\n viteConfigPath,\n options,\n buildOption,\n buildOutDir,\n imports,\n plugins,\n testOption,\n reportsDirectory,\n cacheDir,\n projectRoot,\n offsetFromRoot(projectRoot),\n projectAlreadyHasViteTargets\n );\n return;\n }\n\n viteConfigContent = `\n /// <reference types='vitest' />\n import { defineConfig } from 'vite';\n ${imports.join(';\\n')}${imports.length ? ';' : ''}\n import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n \n export default defineConfig({\n root: __dirname,\n ${cacheDir}\n ${devServerOption}\n ${previewServerOption}\n \n plugins: [${plugins.join(',\\n')}],\n ${workerOption}\n ${buildOption}\n ${defineOption}\n ${testOption}\n });`;\n\n tree.write(viteConfigPath, viteConfigContent);\n}\n\nexport function normalizeViteConfigFilePathWithTree(\n tree: Tree,\n projectRoot: string,\n configFile?: string\n): string {\n return configFile && tree.exists(configFile)\n ? configFile\n : tree.exists(joinPathFragments(`${projectRoot}/vite.config.ts`))\n ? joinPathFragments(`${projectRoot}/vite.config.ts`)\n : tree.exists(joinPathFragments(`${projectRoot}/vite.config.js`))\n ? joinPathFragments(`${projectRoot}/vite.config.js`)\n : undefined;\n}\n\nexport function getViteConfigPathForProject(\n tree: Tree,\n projectName: string,\n target?: string\n) {\n let viteConfigPath: string | undefined;\n const { targets, root } = readProjectConfiguration(tree, projectName);\n if (target) {\n viteConfigPath = targets?.[target]?.options?.configFile;\n } else {\n const config = Object.values(targets).find(\n (config) =>\n config.executor === '@nrwl/nx:build' ||\n config.executor === '@nrwl/vite:build'\n );\n viteConfigPath = config?.options?.configFile;\n }\n\n return normalizeViteConfigFilePathWithTree(tree, root, viteConfigPath);\n}\n\nexport async function handleUnsupportedUserProvidedTargets(\n userProvidedTargetIsUnsupported: TargetFlags,\n userProvidedTargetName: UserProvidedTargetName,\n validFoundTargetName: ValidFoundTargetName\n) {\n if (userProvidedTargetIsUnsupported.build && validFoundTargetName.build) {\n await handleUnsupportedUserProvidedTargetsErrors(\n userProvidedTargetName.build,\n validFoundTargetName.build,\n 'build',\n 'build'\n );\n }\n\n if (userProvidedTargetIsUnsupported.serve && validFoundTargetName.serve) {\n await handleUnsupportedUserProvidedTargetsErrors(\n userProvidedTargetName.serve,\n validFoundTargetName.serve,\n 'serve',\n 'dev-server'\n );\n }\n\n if (userProvidedTargetIsUnsupported.test && validFoundTargetName.test) {\n await handleUnsupportedUserProvidedTargetsErrors(\n userProvidedTargetName.test,\n validFoundTargetName.test,\n 'test',\n 'test'\n );\n }\n}\n\nasync function handleUnsupportedUserProvidedTargetsErrors(\n userProvidedTargetName: string,\n validFoundTargetName: string,\n target: Target,\n executor: 'build' | 'dev-server' | 'test'\n) {\n logger.warn(\n `The custom ${target} target you provided (${userProvidedTargetName}) cannot be converted to use the @nx/vite:${executor} executor.\n However, we found the following ${target} target in your project that can be converted: ${validFoundTargetName}\n\n Please note that converting a potentially non-compatible project to use Vite.js may result in unexpected behavior. Always commit\n your changes before converting a project to use Vite.js, and test the converted project thoroughly before deploying it.\n `\n );\n const { Confirm } = require('enquirer');\n const prompt = new Confirm({\n name: 'question',\n message: `Should we convert the ${validFoundTargetName} target to use the @nx/vite:${executor} executor?`,\n initial: true,\n });\n const shouldConvert = await prompt.run();\n if (!shouldConvert) {\n throw new Error(\n `The ${target} target ${userProvidedTargetName} cannot be converted to use the @nx/vite:${executor} executor.\n Please try again, either by providing a different ${target} target or by not providing a target at all (Nx will\n convert the first one it finds, most probably this one: ${validFoundTargetName})\n\n Please note that converting a potentially non-compatible project to use Vite.js may result in unexpected behavior. Always commit\n your changes before converting a project to use Vite.js, and test the converted project thoroughly before deploying it.\n `\n );\n }\n}\n\nexport async function handleUnknownConfiguration(projectName: string) {\n if (process.env.NX_INTERACTIVE === 'false') {\n return;\n }\n\n logger.warn(\n `\n We could not find any configuration in project ${projectName} that \n indicates whether we can definitely convert to Vite.\n \n If you still want to convert your project to use Vite,\n please make sure to commit your changes before running this generator.\n `\n );\n\n const { Confirm } = require('enquirer');\n const prompt = new Confirm({\n name: 'question',\n message: `Should Nx convert your project to use Vite?`,\n initial: true,\n });\n const shouldConvert = await prompt.run();\n if (!shouldConvert) {\n throw new Error(`\n Nx could not verify that your project can be converted to use Vite.\n Please try again with a different project.\n `);\n }\n}\n\nfunction handleViteConfigFileExists(\n tree: Tree,\n viteConfigPath: string,\n options: ViteConfigFileOptions,\n buildOption: string,\n buildOutDir: string,\n imports: string[],\n plugins: string[],\n testOption: string,\n reportsDirectory: string,\n cacheDir: string,\n projectRoot: string,\n offsetFromRoot: string,\n projectAlreadyHasViteTargets?: TargetFlags\n) {\n if (\n projectAlreadyHasViteTargets?.build &&\n projectAlreadyHasViteTargets?.test\n ) {\n return;\n }\n\n if (process.env.NX_VERBOSE_LOGGING === 'true') {\n logger.info(\n `vite.config.ts already exists for project ${options.project}.`\n );\n }\n\n const buildOptionObject = options.includeLib\n ? {\n lib: {\n entry: 'src/index.ts',\n name: options.project,\n fileName: 'index',\n formats: ['es', 'cjs'],\n },\n rollupOptions: {\n external: options.rollupOptionsExternal ?? [],\n },\n outDir: buildOutDir,\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n }\n : {\n outDir: buildOutDir,\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n };\n\n const testOptionObject = {\n globals: true,\n cache: {\n dir: normalizedJoinPaths(\n offsetFromRoot,\n 'node_modules',\n '.vitest',\n projectRoot === '.' ? options.project : projectRoot\n ),\n },\n environment: options.testEnvironment ?? 'jsdom',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n reporters: ['default'],\n coverage: {\n reportsDirectory: reportsDirectory,\n provider: `${options.coverageProvider ?? 'v8'}`,\n },\n };\n\n const changed = ensureViteConfigIsCorrect(\n tree,\n viteConfigPath,\n buildOption,\n buildOptionObject,\n imports,\n plugins,\n testOption,\n testOptionObject,\n cacheDir,\n projectAlreadyHasViteTargets ?? {}\n );\n\n if (!changed) {\n logger.warn(\n `Make sure the following setting exists in your Vite configuration file (${viteConfigPath}):\n \n ${buildOption}\n \n `\n );\n }\n}\n\nfunction normalizedJoinPaths(...paths: string[]): string {\n const path = joinPathFragments(...paths);\n\n return path.startsWith('.') ? path : `./${path}`;\n}\n"],"names":["findExistingJsBuildTargetInProject","addOrChangeTestTarget","addBuildTarget","addServeTarget","addPreviewTarget","editTsConfig","deleteWebpackConfig","moveAndEditIndexHtml","createOrEditViteConfig","normalizeViteConfigFilePathWithTree","getViteConfigPathForProject","handleUnsupportedUserProvidedTargets","handleUnknownConfiguration","targets","output","supportedExecutors","build","unsupportedExecutors","target","executorName","executor","includes","supported","unsupported","tree","options","project","readProjectConfiguration","reportsDirectory","joinPathFragments","offsetFromRoot","root","testOptions","jestConfig","outputs","updateProjectConfiguration","addBuildTargetDefaults","buildOptions","outputPath","defaultConfiguration","configurations","development","mode","production","buildTarget","hmr","serveTarget","previewOptions","proxyConfig","https","open","preview","projectConfig","config","readJson","uiFramework","compilerOptions","jsx","allowJs","esModuleInterop","allowSyntheticDefaultImports","strict","module","forceConsistentCasingInFileNames","noImplicitOverride","noPropertyAccessFromIndexSignature","noImplicitReturns","noFallthroughCasesInSwitch","writeJson","projectRoot","webpackConfigFilePath","webpackConfigPath","exists","delete","indexHtmlPath","mainPath","replace","indexHtmlContent","read","write","onlyVitest","projectAlreadyHasViteTargets","vitestFileName","viteConfigPath","buildOutDir","buildOption","includeLib","rollupOptionsExternal","imports","push","viteConfigContent","plugins","testOption","includeVitest","normalizedJoinPaths","testEnvironment","inSourceTests","coverageProvider","defineOption","devServerOption","previewServerOption","workerOption","cacheDir","handleViteConfigFileExists","join","length","configFile","undefined","projectName","Object","values","find","userProvidedTargetIsUnsupported","userProvidedTargetName","validFoundTargetName","handleUnsupportedUserProvidedTargetsErrors","serve","test","logger","warn","Confirm","require","prompt","name","message","initial","shouldConvert","run","Error","process","env","NX_INTERACTIVE","NX_VERBOSE_LOGGING","info","buildOptionObject","lib","entry","fileName","formats","rollupOptions","external","outDir","reportCompressedSize","commonjsOptions","transformMixedEsModules","testOptionObject","globals","cache","dir","environment","include","reporters","coverage","provider","changed","ensureViteConfigIsCorrect","paths","path","startsWith"],"mappings":";;;;;;;;IAuBgBA,kCAAkC;eAAlCA;;IAyDAC,qBAAqB;eAArBA;;IAgCAC,cAAc;eAAdA;;IAgCAC,cAAc;eAAdA;;IAqCAC,gBAAgB;eAAhBA;;IAyCAC,YAAY;eAAZA;;IAoCAC,mBAAmB;eAAnBA;;IAkBAC,oBAAoB;eAApBA;;IA0EAC,sBAAsB;eAAtBA;;IA4LAC,mCAAmC;eAAnCA;;IAcAC,2BAA2B;eAA3BA;;IAqBMC,oCAAoC;eAApCA;;IAmEAC,0BAA0B;eAA1BA;;;wBAtnBf;qCAKmC;wCACH;AAOhC,SAASZ,mCAAmCa,OAElD;IAIC,MAAMC,SAGF,CAAC;IAEL,MAAMC,qBAAqB;QACzBC,OAAO;YAAC;YAAgB;YAAc;SAAoB;IAC5D;IAC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