@nx/vite 20.0.7 → 20.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/vite",
3
- "version": "20.0.7",
3
+ "version": "20.1.0-beta.0",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for building and testing applications using Vite",
6
6
  "repository": {
@@ -30,11 +30,11 @@
30
30
  "migrations": "./migrations.json"
31
31
  },
32
32
  "dependencies": {
33
- "@nx/devkit": "20.0.7",
33
+ "@nx/devkit": "20.1.0-beta.0",
34
34
  "@phenomnomnominal/tsquery": "~5.0.1",
35
35
  "@swc/helpers": "~0.5.0",
36
36
  "enquirer": "~2.3.6",
37
- "@nx/js": "20.0.7",
37
+ "@nx/js": "20.1.0-beta.0",
38
38
  "tsconfig-paths": "^4.1.2",
39
39
  "minimatch": "9.0.3"
40
40
  },
@@ -162,9 +162,14 @@ There should at least be a tsconfig.base.json or tsconfig.json in the root of th
162
162
  }
163
163
  function findFile(path) {
164
164
  for (const ext of options.extensions){
165
+ // Support file with "." in the name.
166
+ let resolvedPath = (0, _nodepath.resolve)(path + ext);
167
+ if ((0, _nodefs.existsSync)(resolvedPath)) {
168
+ return resolvedPath;
169
+ }
165
170
  // Support file extensions such as .css and .js in the import path.
166
171
  const { dir, name } = (0, _nodepath.parse)(path);
167
- const resolvedPath = (0, _nodepath.resolve)(dir, name + ext);
172
+ resolvedPath = (0, _nodepath.resolve)(dir, name + ext);
168
173
  if ((0, _nodefs.existsSync)(resolvedPath)) {
169
174
  return resolvedPath;
170
175
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"sourcesContent":["import {\n createProjectGraphAsync,\n joinPathFragments,\n stripIndents,\n workspaceRoot,\n} from '@nx/devkit';\nimport { copyFileSync, existsSync } from 'node:fs';\nimport { join, parse, relative, resolve } from 'node:path';\nimport {\n loadConfig,\n createMatchPath,\n MatchPath,\n ConfigLoaderSuccessResult,\n} from 'tsconfig-paths';\nimport {\n calculateProjectBuildableDependencies,\n createTmpTsConfig,\n} from '@nx/js/src/utils/buildable-libs-utils';\nimport { Plugin } from 'vite';\nimport { nxViteBuildCoordinationPlugin } from './nx-vite-build-coordination.plugin';\n\nexport interface nxViteTsPathsOptions {\n /**\n * Enable debug logging\n * @default false\n **/\n debug?: boolean;\n /**\n * export fields in package.json to use for resolving\n * @default [['exports', '.', 'import'], 'module', 'main']\n *\n * fallback resolution will use ['main', 'module']\n **/\n mainFields?: (string | string[])[];\n /**\n * extensions to check when resolving files when package.json resolution fails\n * @default ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs', '.cjs']\n **/\n extensions?: string[];\n /**\n * Inform Nx whether to use the raw source or to use the built output for buildable dependencies.\n * Set to `false` to use incremental builds.\n * @default true\n */\n buildLibsFromSource?: boolean;\n}\n\nexport function nxViteTsPaths(options: nxViteTsPathsOptions = {}) {\n let matchTsPathEsm: MatchPath;\n let matchTsPathFallback: MatchPath | undefined;\n let tsConfigPathsEsm: ConfigLoaderSuccessResult;\n let tsConfigPathsFallback: ConfigLoaderSuccessResult;\n\n options.extensions ??= [\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.json',\n '.mts',\n '.mjs',\n '.cts',\n '.cjs',\n '.css',\n '.scss',\n '.less',\n ];\n options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];\n options.buildLibsFromSource ??= true;\n let projectRoot = '';\n\n return {\n name: 'nx-vite-ts-paths',\n // Ensure the resolveId aspect of the plugin is called before vite's internal resolver\n // Otherwise, issues can arise with Yarn Workspaces and Pnpm Workspaces\n enforce: 'pre',\n async configResolved(config: any) {\n projectRoot = config.root;\n const projectRootFromWorkspaceRoot = relative(workspaceRoot, projectRoot);\n let foundTsConfigPath = getTsConfig(\n join(\n workspaceRoot,\n 'tmp',\n projectRootFromWorkspaceRoot,\n process.env.NX_TASK_TARGET_TARGET ?? 'build',\n 'tsconfig.generated.json'\n )\n );\n if (!foundTsConfigPath) {\n throw new Error(stripIndents`Unable to find a tsconfig in the workspace! \nThere should at least be a tsconfig.base.json or tsconfig.json in the root of the workspace ${workspaceRoot}`);\n }\n\n if (\n !options.buildLibsFromSource &&\n !global.NX_GRAPH_CREATION &&\n config.mode !== 'test'\n ) {\n const projectGraph = await createProjectGraphAsync({\n exitOnError: false,\n resetDaemonClient: true,\n });\n const { dependencies } = calculateProjectBuildableDependencies(\n undefined,\n projectGraph,\n workspaceRoot,\n process.env.NX_TASK_TARGET_PROJECT,\n // When using incremental building and the serve target is called\n // we need to get the deps for the 'build' target instead.\n process.env.NX_TASK_TARGET_TARGET === 'serve'\n ? 'build'\n : process.env.NX_TASK_TARGET_TARGET,\n process.env.NX_TASK_TARGET_CONFIGURATION\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 foundTsConfigPath = createTmpTsConfig(\n foundTsConfigPath,\n workspaceRoot,\n relative(workspaceRoot, projectRoot),\n dependencies,\n true\n );\n\n if (config.command === 'serve') {\n const buildableLibraryDependencies = dependencies\n .filter((dep) => dep.node.type === 'lib')\n .map((dep) => dep.node.name)\n .join(',');\n const buildCommand = `npx nx run-many --target=${process.env.NX_TASK_TARGET_TARGET} --projects=${buildableLibraryDependencies}`;\n config.plugins.push(nxViteBuildCoordinationPlugin({ buildCommand }));\n }\n }\n\n const parsed = loadConfig(foundTsConfigPath);\n\n logIt('first parsed tsconfig: ', parsed);\n if (parsed.resultType === 'failed') {\n throw new Error(`Failed loading tsconfig at ${foundTsConfigPath}`);\n }\n tsConfigPathsEsm = parsed;\n\n matchTsPathEsm = createMatchPath(\n parsed.absoluteBaseUrl,\n parsed.paths,\n options.mainFields\n );\n\n const rootLevelTsConfig = getTsConfig(\n join(workspaceRoot, 'tsconfig.base.json')\n );\n const rootLevelParsed = loadConfig(rootLevelTsConfig);\n logIt('fallback parsed tsconfig: ', rootLevelParsed);\n if (rootLevelParsed.resultType === 'success') {\n tsConfigPathsFallback = rootLevelParsed;\n matchTsPathFallback = createMatchPath(\n rootLevelParsed.absoluteBaseUrl,\n rootLevelParsed.paths,\n ['main', 'module']\n );\n }\n },\n resolveId(importPath: string) {\n let resolvedFile: string;\n try {\n resolvedFile = matchTsPathEsm(importPath);\n } catch (e) {\n logIt('Using fallback path matching.');\n resolvedFile = matchTsPathFallback?.(importPath);\n }\n\n if (!resolvedFile) {\n if (tsConfigPathsEsm || tsConfigPathsFallback) {\n logIt(\n `Unable to resolve ${importPath} with tsconfig paths. Using fallback file matching.`\n );\n resolvedFile =\n loadFileFromPaths(tsConfigPathsEsm, importPath) ||\n loadFileFromPaths(tsConfigPathsFallback, importPath);\n } else {\n logIt(`Unable to resolve ${importPath} with tsconfig paths`);\n }\n }\n\n logIt(`Resolved ${importPath} to ${resolvedFile}`);\n // Returning null defers to other resolveId functions and eventually the default resolution behavior\n // https://rollupjs.org/plugin-development/#resolveid\n return resolvedFile || null;\n },\n async writeBundle(options) {\n const outDir = options.dir || 'dist';\n const src = resolve(projectRoot, 'package.json');\n if (existsSync(src)) {\n const dest = join(outDir, 'package.json');\n\n try {\n copyFileSync(src, dest);\n } catch (err) {\n console.error('Error copying package.json:', err);\n }\n }\n },\n } as Plugin;\n\n function getTsConfig(preferredTsConfigPath: string): string {\n return [\n resolve(preferredTsConfigPath),\n resolve(join(workspaceRoot, 'tsconfig.base.json')),\n resolve(join(workspaceRoot, 'tsconfig.json')),\n ].find((tsPath) => {\n if (existsSync(tsPath)) {\n logIt('Found tsconfig at', tsPath);\n return tsPath;\n }\n });\n }\n\n function logIt(...msg: any[]) {\n if (process.env.NX_VERBOSE_LOGGING === 'true' || options?.debug) {\n console.debug('\\n[Nx Vite TsPaths]', ...msg);\n }\n }\n\n function loadFileFromPaths(\n tsconfig: ConfigLoaderSuccessResult,\n importPath: string\n ) {\n logIt(\n `Trying to resolve file from config in ${tsconfig.configFileAbsolutePath}`\n );\n let resolvedFile: string;\n for (const alias in tsconfig.paths) {\n const paths = tsconfig.paths[alias];\n\n const normalizedImport = alias.replace(/\\/\\*$/, '');\n\n if (importPath.startsWith(normalizedImport)) {\n const joinedPath = joinPathFragments(\n tsconfig.absoluteBaseUrl,\n paths[0].replace(/\\/\\*$/, '')\n );\n\n resolvedFile = findFile(\n importPath.replace(normalizedImport, joinedPath)\n );\n }\n }\n\n return resolvedFile;\n }\n\n function findFile(path: string): string {\n for (const ext of options.extensions) {\n // Support file extensions such as .css and .js in the import path.\n const { dir, name } = parse(path);\n const resolvedPath = resolve(dir, name + ext);\n if (existsSync(resolvedPath)) {\n return resolvedPath;\n }\n\n const resolvedIndexPath = resolve(path, `index${ext}`);\n if (existsSync(resolvedIndexPath)) {\n return resolvedIndexPath;\n }\n }\n }\n}\n"],"names":["nxViteTsPaths","options","matchTsPathEsm","matchTsPathFallback","tsConfigPathsEsm","tsConfigPathsFallback","extensions","mainFields","buildLibsFromSource","projectRoot","name","enforce","configResolved","config","root","projectRootFromWorkspaceRoot","relative","workspaceRoot","process","foundTsConfigPath","getTsConfig","join","env","NX_TASK_TARGET_TARGET","Error","stripIndents","global","NX_GRAPH_CREATION","mode","projectGraph","createProjectGraphAsync","exitOnError","resetDaemonClient","dependencies","calculateProjectBuildableDependencies","undefined","NX_TASK_TARGET_PROJECT","NX_TASK_TARGET_CONFIGURATION","createTmpTsConfig","command","buildableLibraryDependencies","filter","dep","node","type","map","buildCommand","plugins","push","nxViteBuildCoordinationPlugin","parsed","loadConfig","logIt","resultType","createMatchPath","absoluteBaseUrl","paths","rootLevelTsConfig","rootLevelParsed","resolveId","importPath","resolvedFile","e","loadFileFromPaths","writeBundle","outDir","dir","src","resolve","existsSync","dest","copyFileSync","err","console","error","preferredTsConfigPath","find","tsPath","msg","NX_VERBOSE_LOGGING","debug","tsconfig","configFileAbsolutePath","alias","normalizedImport","replace","startsWith","joinedPath","joinPathFragments","findFile","path","ext","parse","resolvedPath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eAAe;gBAC5B,OAAOA;YACT;YAEA,MAAMC,oBAAoB1B,IAAAA,iBAAO,EAACsB,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC;YACrD,IAAItB,IAAAA,kBAAU,EAACyB,oBAAoB;gBACjC,OAAOA;YACT;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"sourcesContent":["import {\n createProjectGraphAsync,\n joinPathFragments,\n stripIndents,\n workspaceRoot,\n} from '@nx/devkit';\nimport { copyFileSync, existsSync } from 'node:fs';\nimport { join, parse, relative, resolve } from 'node:path';\nimport {\n loadConfig,\n createMatchPath,\n MatchPath,\n ConfigLoaderSuccessResult,\n} from 'tsconfig-paths';\nimport {\n calculateProjectBuildableDependencies,\n createTmpTsConfig,\n} from '@nx/js/src/utils/buildable-libs-utils';\nimport { Plugin } from 'vite';\nimport { nxViteBuildCoordinationPlugin } from './nx-vite-build-coordination.plugin';\n\nexport interface nxViteTsPathsOptions {\n /**\n * Enable debug logging\n * @default false\n **/\n debug?: boolean;\n /**\n * export fields in package.json to use for resolving\n * @default [['exports', '.', 'import'], 'module', 'main']\n *\n * fallback resolution will use ['main', 'module']\n **/\n mainFields?: (string | string[])[];\n /**\n * extensions to check when resolving files when package.json resolution fails\n * @default ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs', '.cjs']\n **/\n extensions?: string[];\n /**\n * Inform Nx whether to use the raw source or to use the built output for buildable dependencies.\n * Set to `false` to use incremental builds.\n * @default true\n */\n buildLibsFromSource?: boolean;\n}\n\nexport function nxViteTsPaths(options: nxViteTsPathsOptions = {}) {\n let matchTsPathEsm: MatchPath;\n let matchTsPathFallback: MatchPath | undefined;\n let tsConfigPathsEsm: ConfigLoaderSuccessResult;\n let tsConfigPathsFallback: ConfigLoaderSuccessResult;\n\n options.extensions ??= [\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.json',\n '.mts',\n '.mjs',\n '.cts',\n '.cjs',\n '.css',\n '.scss',\n '.less',\n ];\n options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];\n options.buildLibsFromSource ??= true;\n let projectRoot = '';\n\n return {\n name: 'nx-vite-ts-paths',\n // Ensure the resolveId aspect of the plugin is called before vite's internal resolver\n // Otherwise, issues can arise with Yarn Workspaces and Pnpm Workspaces\n enforce: 'pre',\n async configResolved(config: any) {\n projectRoot = config.root;\n const projectRootFromWorkspaceRoot = relative(workspaceRoot, projectRoot);\n let foundTsConfigPath = getTsConfig(\n join(\n workspaceRoot,\n 'tmp',\n projectRootFromWorkspaceRoot,\n process.env.NX_TASK_TARGET_TARGET ?? 'build',\n 'tsconfig.generated.json'\n )\n );\n if (!foundTsConfigPath) {\n throw new Error(stripIndents`Unable to find a tsconfig in the workspace! \nThere should at least be a tsconfig.base.json or tsconfig.json in the root of the workspace ${workspaceRoot}`);\n }\n\n if (\n !options.buildLibsFromSource &&\n !global.NX_GRAPH_CREATION &&\n config.mode !== 'test'\n ) {\n const projectGraph = await createProjectGraphAsync({\n exitOnError: false,\n resetDaemonClient: true,\n });\n const { dependencies } = calculateProjectBuildableDependencies(\n undefined,\n projectGraph,\n workspaceRoot,\n process.env.NX_TASK_TARGET_PROJECT,\n // When using incremental building and the serve target is called\n // we need to get the deps for the 'build' target instead.\n process.env.NX_TASK_TARGET_TARGET === 'serve'\n ? 'build'\n : process.env.NX_TASK_TARGET_TARGET,\n process.env.NX_TASK_TARGET_CONFIGURATION\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 foundTsConfigPath = createTmpTsConfig(\n foundTsConfigPath,\n workspaceRoot,\n relative(workspaceRoot, projectRoot),\n dependencies,\n true\n );\n\n if (config.command === 'serve') {\n const buildableLibraryDependencies = dependencies\n .filter((dep) => dep.node.type === 'lib')\n .map((dep) => dep.node.name)\n .join(',');\n const buildCommand = `npx nx run-many --target=${process.env.NX_TASK_TARGET_TARGET} --projects=${buildableLibraryDependencies}`;\n config.plugins.push(nxViteBuildCoordinationPlugin({ buildCommand }));\n }\n }\n\n const parsed = loadConfig(foundTsConfigPath);\n\n logIt('first parsed tsconfig: ', parsed);\n if (parsed.resultType === 'failed') {\n throw new Error(`Failed loading tsconfig at ${foundTsConfigPath}`);\n }\n tsConfigPathsEsm = parsed;\n\n matchTsPathEsm = createMatchPath(\n parsed.absoluteBaseUrl,\n parsed.paths,\n options.mainFields\n );\n\n const rootLevelTsConfig = getTsConfig(\n join(workspaceRoot, 'tsconfig.base.json')\n );\n const rootLevelParsed = loadConfig(rootLevelTsConfig);\n logIt('fallback parsed tsconfig: ', rootLevelParsed);\n if (rootLevelParsed.resultType === 'success') {\n tsConfigPathsFallback = rootLevelParsed;\n matchTsPathFallback = createMatchPath(\n rootLevelParsed.absoluteBaseUrl,\n rootLevelParsed.paths,\n ['main', 'module']\n );\n }\n },\n resolveId(importPath: string) {\n let resolvedFile: string;\n try {\n resolvedFile = matchTsPathEsm(importPath);\n } catch (e) {\n logIt('Using fallback path matching.');\n resolvedFile = matchTsPathFallback?.(importPath);\n }\n\n if (!resolvedFile) {\n if (tsConfigPathsEsm || tsConfigPathsFallback) {\n logIt(\n `Unable to resolve ${importPath} with tsconfig paths. Using fallback file matching.`\n );\n resolvedFile =\n loadFileFromPaths(tsConfigPathsEsm, importPath) ||\n loadFileFromPaths(tsConfigPathsFallback, importPath);\n } else {\n logIt(`Unable to resolve ${importPath} with tsconfig paths`);\n }\n }\n\n logIt(`Resolved ${importPath} to ${resolvedFile}`);\n // Returning null defers to other resolveId functions and eventually the default resolution behavior\n // https://rollupjs.org/plugin-development/#resolveid\n return resolvedFile || null;\n },\n async writeBundle(options) {\n const outDir = options.dir || 'dist';\n const src = resolve(projectRoot, 'package.json');\n if (existsSync(src)) {\n const dest = join(outDir, 'package.json');\n\n try {\n copyFileSync(src, dest);\n } catch (err) {\n console.error('Error copying package.json:', err);\n }\n }\n },\n } as Plugin;\n\n function getTsConfig(preferredTsConfigPath: string): string {\n return [\n resolve(preferredTsConfigPath),\n resolve(join(workspaceRoot, 'tsconfig.base.json')),\n resolve(join(workspaceRoot, 'tsconfig.json')),\n ].find((tsPath) => {\n if (existsSync(tsPath)) {\n logIt('Found tsconfig at', tsPath);\n return tsPath;\n }\n });\n }\n\n function logIt(...msg: any[]) {\n if (process.env.NX_VERBOSE_LOGGING === 'true' || options?.debug) {\n console.debug('\\n[Nx Vite TsPaths]', ...msg);\n }\n }\n\n function loadFileFromPaths(\n tsconfig: ConfigLoaderSuccessResult,\n importPath: string\n ) {\n logIt(\n `Trying to resolve file from config in ${tsconfig.configFileAbsolutePath}`\n );\n let resolvedFile: string;\n for (const alias in tsconfig.paths) {\n const paths = tsconfig.paths[alias];\n\n const normalizedImport = alias.replace(/\\/\\*$/, '');\n\n if (importPath.startsWith(normalizedImport)) {\n const joinedPath = joinPathFragments(\n tsconfig.absoluteBaseUrl,\n paths[0].replace(/\\/\\*$/, '')\n );\n\n resolvedFile = findFile(\n importPath.replace(normalizedImport, joinedPath)\n );\n }\n }\n\n return resolvedFile;\n }\n\n function findFile(path: string): string {\n for (const ext of options.extensions) {\n // Support file with \".\" in the name.\n let resolvedPath = resolve(path + ext);\n if (existsSync(resolvedPath)) {\n return resolvedPath;\n }\n\n // Support file extensions such as .css and .js in the import path.\n const { dir, name } = parse(path);\n resolvedPath = resolve(dir, name + ext);\n if (existsSync(resolvedPath)) {\n return resolvedPath;\n }\n\n const resolvedIndexPath = resolve(path, `index${ext}`);\n if (existsSync(resolvedIndexPath)) {\n return resolvedIndexPath;\n }\n }\n }\n}\n"],"names":["nxViteTsPaths","options","matchTsPathEsm","matchTsPathFallback","tsConfigPathsEsm","tsConfigPathsFallback","extensions","mainFields","buildLibsFromSource","projectRoot","name","enforce","configResolved","config","root","projectRootFromWorkspaceRoot","relative","workspaceRoot","process","foundTsConfigPath","getTsConfig","join","env","NX_TASK_TARGET_TARGET","Error","stripIndents","global","NX_GRAPH_CREATION","mode","projectGraph","createProjectGraphAsync","exitOnError","resetDaemonClient","dependencies","calculateProjectBuildableDependencies","undefined","NX_TASK_TARGET_PROJECT","NX_TASK_TARGET_CONFIGURATION","createTmpTsConfig","command","buildableLibraryDependencies","filter","dep","node","type","map","buildCommand","plugins","push","nxViteBuildCoordinationPlugin","parsed","loadConfig","logIt","resultType","createMatchPath","absoluteBaseUrl","paths","rootLevelTsConfig","rootLevelParsed","resolveId","importPath","resolvedFile","e","loadFileFromPaths","writeBundle","outDir","dir","src","resolve","existsSync","dest","copyFileSync","err","console","error","preferredTsConfigPath","find","tsPath","msg","NX_VERBOSE_LOGGING","debug","tsconfig","configFileAbsolutePath","alias","normalizedImport","replace","startsWith","joinedPath","joinPathFragments","findFile","path","ext","resolvedPath","parse","resolvedIndexPath"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";+BA+CgBA;;;eAAAA;;;wBA1CT;wBACkC;0BACM;+BAMxC;oCAIA;+CAEuC;AA4BvC,SAASA,cAAcC,UAAgC,CAAC,CAAC;QAM9DA,UAcAA,WACAA;IApBA,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;;IAEJJ,gBAAAA,WAAAA,SAAQK,oCAARL,SAAQK,aAAe;QACrB;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;;IACDL,gBAAAA,YAAAA,SAAQM,oCAARN,UAAQM,aAAe;QAAC;YAAC;YAAW;YAAK;SAAS;QAAE;QAAU;KAAO;;IACrEN,yBAAAA,YAAAA,SAAQO,sDAARP,UAAQO,sBAAwB;IAChC,IAAIC,cAAc;IAElB,OAAO;QACLC,MAAM;QACN,sFAAsF;QACtF,uEAAuE;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mBAAmB;gBAC3C,MAAMG,aAAaC,IAAAA,yBAAiB,EAClCP,SAAS1B,eAAe,EACxBC,KAAK,CAAC,EAAE,CAAC6B,OAAO,CAAC,SAAS;gBAG5BxB,eAAe4B,SACb7B,WAAWyB,OAAO,CAACD,kBAAkBG;YAEzC;QACF;QAEA,OAAO1B;IACT;IAEA,SAAS4B,SAASC,IAAY;QAC5B,KAAK,MAAMC,OAAO1F,QAAQK,UAAU,CAAE;YACpC,qCAAqC;YACrC,IAAIsF,eAAexB,IAAAA,iBAAO,EAACsB,OAAOC;YAClC,IAAItB,IAAAA,kBAAU,EAACuB,eAAe;gBAC5B,OAAOA;YACT;YAEA,mEAAmE;YACnE,MAAM,EAAE1B,GAAG,EAAExD,IAAI,EAAE,GAAGmF,IAAAA,eAAK,EAACH;YAC5BE,eAAexB,IAAAA,iBAAO,EAACF,KAAKxD,OAAOiF;YACnC,IAAItB,IAAAA,kBAAU,EAACuB,eAAe;gBAC5B,OAAOA;YACT;YAEA,MAAME,oBAAoB1B,IAAAA,iBAAO,EAACsB,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC;YACrD,IAAItB,IAAAA,kBAAU,EAACyB,oBAAoB;gBACjC,OAAOA;YACT;QACF;IACF;AACF"}
@@ -19,10 +19,13 @@ _export(exports, {
19
19
  const _extends = require("@swc/helpers/_/_extends");
20
20
  const _devkit = require("@nx/devkit");
21
21
  const _js = require("@nx/js");
22
+ const _getimportpath = require("@nx/js/src/utils/get-import-path");
23
+ const _tssolutionsetup = require("@nx/js/src/utils/typescript/ts-solution-setup");
24
+ const _posix = require("node:path/posix");
25
+ const _ensuredependencies = require("../../utils/ensure-dependencies");
22
26
  const _generatorutils = require("../../utils/generator-utils");
23
27
  const _init = require("../init/init");
24
28
  const _vitestgenerator = require("../vitest/vitest-generator");
25
- const _ensuredependencies = require("../../utils/ensure-dependencies");
26
29
  const _convertnonvite = require("./lib/convert-non-vite");
27
30
  function viteConfigurationGenerator(host, schema) {
28
31
  return viteConfigurationGeneratorInternal(host, _extends._({
@@ -81,21 +84,13 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
81
84
  if (projectType === 'library') {
82
85
  // update tsconfig.lib.json to include vite/client
83
86
  (0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.lib.json'), (json)=>{
84
- if (!json.compilerOptions) {
85
- json.compilerOptions = {};
86
- }
87
- if (!json.compilerOptions.types) {
88
- json.compilerOptions.types = [];
89
- }
87
+ var _json, _json_compilerOptions;
88
+ var _compilerOptions;
89
+ (_compilerOptions = (_json = json).compilerOptions) != null ? _compilerOptions : _json.compilerOptions = {};
90
+ var _types;
91
+ (_types = (_json_compilerOptions = json.compilerOptions).types) != null ? _types : _json_compilerOptions.types = [];
90
92
  if (!json.compilerOptions.types.includes('vite/client')) {
91
- return _extends._({}, json, {
92
- compilerOptions: _extends._({}, json.compilerOptions, {
93
- types: [
94
- ...json.compilerOptions.types,
95
- 'vite/client'
96
- ]
97
- })
98
- });
93
+ json.compilerOptions.types.push('vite/client');
99
94
  }
100
95
  return json;
101
96
  });
@@ -138,11 +133,50 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
138
133
  });
139
134
  tasks.push(vitestTask);
140
135
  }
136
+ if ((0, _tssolutionsetup.isUsingTsSolutionSetup)(tree)) {
137
+ updatePackageJson(tree, schema);
138
+ }
141
139
  if (!schema.skipFormat) {
142
140
  await (0, _devkit.formatFiles)(tree);
143
141
  }
144
142
  return (0, _devkit.runTasksInSerial)(...tasks);
145
143
  }
146
144
  const _default = viteConfigurationGenerator;
145
+ function updatePackageJson(tree, options) {
146
+ const project = (0, _devkit.readProjectConfiguration)(tree, options.project);
147
+ const packageJsonPath = (0, _posix.join)(project.root, 'package.json');
148
+ let packageJson;
149
+ if (tree.exists(packageJsonPath)) {
150
+ packageJson = (0, _devkit.readJson)(tree, packageJsonPath);
151
+ } else {
152
+ packageJson = {
153
+ name: (0, _getimportpath.getImportPath)(tree, options.project),
154
+ version: '0.0.1'
155
+ };
156
+ }
157
+ // we always write/override the vite and project config with some set values,
158
+ // so we can rely on them
159
+ const main = (0, _posix.join)(project.root, 'src/index.ts');
160
+ // we configure the dts plugin with the entryRoot set to `src`
161
+ const rootDir = (0, _posix.join)(project.root, 'src');
162
+ const outputPath = (0, _devkit.joinPathFragments)(project.root, 'dist');
163
+ packageJson = (0, _js.getUpdatedPackageJsonContent)(packageJson, {
164
+ main,
165
+ outputPath,
166
+ projectRoot: project.root,
167
+ rootDir,
168
+ generateExportsField: true,
169
+ packageJsonPath,
170
+ format: [
171
+ 'esm',
172
+ 'cjs'
173
+ ],
174
+ // when building both formats, we don't set the package.json "type" field, so
175
+ // we need to set the esm extension to ".mjs" to match vite output
176
+ // see the "File Extensions" callout in https://vite.dev/guide/build.html#library-mode
177
+ outputFileExtensionForEsm: '.mjs'
178
+ });
179
+ (0, _devkit.writeJson)(tree, packageJsonPath, packageJson);
180
+ }
147
181
 
148
182
  //# sourceMappingURL=configuration.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/vite/src/generators/configuration/configuration.ts"],"sourcesContent":["import {\n formatFiles,\n GeneratorCallback,\n joinPathFragments,\n readNxJson,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\nimport { initGenerator as jsInitGenerator } from '@nx/js';\n\nimport {\n addBuildTarget,\n addServeTarget,\n addPreviewTarget,\n createOrEditViteConfig,\n TargetFlags,\n} from '../../utils/generator-utils';\n\nimport initGenerator from '../init/init';\nimport vitestGenerator from '../vitest/vitest-generator';\nimport { ViteConfigurationGeneratorSchema } from './schema';\nimport { ensureDependencies } from '../../utils/ensure-dependencies';\nimport { convertNonVite } from './lib/convert-non-vite';\n\nexport function viteConfigurationGenerator(\n host: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n return viteConfigurationGeneratorInternal(host, {\n addPlugin: false,\n ...schema,\n });\n}\n\nexport async function viteConfigurationGeneratorInternal(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const projectConfig = readProjectConfiguration(tree, schema.project);\n const { targets, root: projectRoot } = projectConfig;\n\n const projectType = projectConfig.projectType ?? 'library';\n\n schema.includeLib ??= projectType === 'library';\n\n // Setting default to jsdom since it is the most common use case (React, Web).\n // The @nx/js:lib generator specifically sets this to node to be more generic.\n schema.testEnvironment ??= 'jsdom';\n\n /**\n * This is for when we are converting an existing project\n * to use the vite executors.\n */\n let projectAlreadyHasViteTargets: TargetFlags = {};\n\n if (!schema.newProject) {\n await convertNonVite(tree, schema, projectRoot, projectType, targets);\n }\n\n const jsInitTask = await jsInitGenerator(tree, {\n ...schema,\n skipFormat: true,\n tsConfigName: projectRoot === '.' ? 'tsconfig.json' : 'tsconfig.base.json',\n });\n tasks.push(jsInitTask);\n const initTask = await initGenerator(tree, { ...schema, skipFormat: true });\n tasks.push(initTask);\n tasks.push(ensureDependencies(tree, schema));\n\n const nxJson = readNxJson(tree);\n const addPluginDefault =\n process.env.NX_ADD_PLUGINS !== 'false' &&\n nxJson.useInferencePlugins !== false;\n schema.addPlugin ??= addPluginDefault;\n\n const hasPlugin = nxJson.plugins?.some((p) =>\n typeof p === 'string'\n ? p === '@nx/vite/plugin'\n : p.plugin === '@nx/vite/plugin'\n );\n\n if (!hasPlugin) {\n if (!projectAlreadyHasViteTargets.build) {\n addBuildTarget(tree, schema, 'build');\n }\n\n if (!schema.includeLib) {\n if (!projectAlreadyHasViteTargets.serve) {\n addServeTarget(tree, schema, 'serve');\n }\n if (!projectAlreadyHasViteTargets.preview) {\n addPreviewTarget(tree, schema, 'preview');\n }\n }\n }\n if (projectType === 'library') {\n // update tsconfig.lib.json to include vite/client\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.lib.json'),\n (json) => {\n if (!json.compilerOptions) {\n json.compilerOptions = {};\n }\n if (!json.compilerOptions.types) {\n json.compilerOptions.types = [];\n }\n if (!json.compilerOptions.types.includes('vite/client')) {\n return {\n ...json,\n compilerOptions: {\n ...json.compilerOptions,\n types: [...json.compilerOptions.types, 'vite/client'],\n },\n };\n }\n return json;\n }\n );\n }\n\n if (!schema.newProject) {\n // We are converting existing project to use Vite\n if (schema.uiFramework === 'react') {\n createOrEditViteConfig(\n tree,\n {\n project: schema.project,\n includeLib: schema.includeLib,\n includeVitest: schema.includeVitest,\n inSourceTests: schema.inSourceTests,\n rollupOptionsExternal: [\n \"'react'\",\n \"'react-dom'\",\n \"'react/jsx-runtime'\",\n ],\n imports: [\n schema.compiler === 'swc'\n ? `import react from '@vitejs/plugin-react-swc'`\n : `import react from '@vitejs/plugin-react'`,\n ],\n plugins: ['react()'],\n },\n false,\n undefined\n );\n } else {\n createOrEditViteConfig(tree, schema, false, projectAlreadyHasViteTargets);\n }\n }\n\n if (schema.includeVitest) {\n const vitestTask = await vitestGenerator(tree, {\n project: schema.project,\n uiFramework: schema.uiFramework,\n inSourceTests: schema.inSourceTests,\n coverageProvider: 'v8',\n skipViteConfig: true,\n testTarget: 'test',\n skipFormat: true,\n addPlugin: schema.addPlugin,\n compiler: schema.compiler,\n });\n tasks.push(vitestTask);\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nexport default viteConfigurationGenerator;\n"],"names":["viteConfigurationGenerator","viteConfigurationGeneratorInternal","host","schema","addPlugin","tree","nxJson","tasks","projectConfig","readProjectConfiguration","project","targets","root","projectRoot","projectType","includeLib","testEnvironment","projectAlreadyHasViteTargets","newProject","convertNonVite","jsInitTask","jsInitGenerator","skipFormat","tsConfigName","push","initTask","initGenerator","ensureDependencies","readNxJson","addPluginDefault","process","env","NX_ADD_PLUGINS","useInferencePlugins","hasPlugin","plugins","some","p","plugin","build","addBuildTarget","serve","addServeTarget","preview","addPreviewTarget","updateJson","joinPathFragments","json","compilerOptions","types","includes","uiFramework","createOrEditViteConfig","includeVitest","inSourceTests","rollupOptionsExternal","imports","compiler","undefined","vitestTask","v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B,eACZD,KAAKC,eAAe;wBACvBC,OAAO;+BAAIF,KAAKC,eAAe,CAACC,KAAK;4BAAE;yBAAc;;;YAG3D;YACA,OAAOF;QACT;IAEJ;IAEA,IAAI,CAAC5C,OAAOe,UAAU,EAAE;QACtB,iDAAiD;QACjD,IAAIf,OAAOgD,WAAW,KAAK,SAAS;YAClCC,IAAAA,sCAAsB,EACpB/C,MACA;gBACEK,SAASP,OAAOO,OAAO;gBACvBK,YAAYZ,OAAOY,UAAU;gBAC7BsC,eAAelD,OAAOkD,aAAa;gBACnCC,eAAenD,OAAOmD,aAAa;gBACnCC,uBAAuB;oBACrB;oBACA;oBACA;iBACD;gBACDC,SAAS;oBACPrD,OAAOsD,QAAQ,KAAK,QAChB,CAAC,4CAA4C,CAAC,GAC9C,CAAC,wCAAwC,CAAC;iBAC/C;gBACDtB,SAAS;oBAAC;iBAAU;YACtB,GACA,OACAuB;QAEJ,OAAO;YACLN,IAAAA,sCAAsB,EAAC/C,MAAMF,QAAQ,OAAOc;QAC9C;IACF;IAEA,IAAId,OAAOkD,aAAa,EAAE;QACxB,MAAMM,aAAa,MAAMC,IAAAA,wBAAe,EAACvD,MAAM;YAC7CK,SAASP,OAAOO,OAAO;YACvByC,aAAahD,OAAOgD,WAAW;YAC/BG,eAAenD,OAAOmD,aAAa;YACnCO,kBAAkB;YAClBC,gBAAgB;YAChBC,YAAY;YACZzC,YAAY;YACZlB,WAAWD,OAAOC,SAAS;YAC3BqD,UAAUtD,OAAOsD,QAAQ;QAC3B;QACAlD,MAAMiB,IAAI,CAACmC;IACb;IAEA,IAAI,CAACxD,OAAOmB,UAAU,EAAE;QACtB,MAAM0C,IAAAA,mBAAW,EAAC3D;IACpB;IAEA,OAAO4D,IAAAA,wBAAgB,KAAI1D;AAC7B;MAEA,WAAeP"}
1
+ {"version":3,"sources":["../../../../../../packages/vite/src/generators/configuration/configuration.ts"],"sourcesContent":["import {\n formatFiles,\n GeneratorCallback,\n joinPathFragments,\n readJson,\n readNxJson,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n writeJson,\n} from '@nx/devkit';\nimport {\n getUpdatedPackageJsonContent,\n initGenerator as jsInitGenerator,\n} from '@nx/js';\nimport { getImportPath } from '@nx/js/src/utils/get-import-path';\nimport { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';\nimport { join } from 'node:path/posix';\nimport type { PackageJson } from 'nx/src/utils/package-json';\nimport { ensureDependencies } from '../../utils/ensure-dependencies';\nimport {\n addBuildTarget,\n addPreviewTarget,\n addServeTarget,\n createOrEditViteConfig,\n TargetFlags,\n} from '../../utils/generator-utils';\nimport initGenerator from '../init/init';\nimport vitestGenerator from '../vitest/vitest-generator';\nimport { convertNonVite } from './lib/convert-non-vite';\nimport { ViteConfigurationGeneratorSchema } from './schema';\n\nexport function viteConfigurationGenerator(\n host: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n return viteConfigurationGeneratorInternal(host, {\n addPlugin: false,\n ...schema,\n });\n}\n\nexport async function viteConfigurationGeneratorInternal(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const projectConfig = readProjectConfiguration(tree, schema.project);\n const { targets, root: projectRoot } = projectConfig;\n\n const projectType = projectConfig.projectType ?? 'library';\n\n schema.includeLib ??= projectType === 'library';\n\n // Setting default to jsdom since it is the most common use case (React, Web).\n // The @nx/js:lib generator specifically sets this to node to be more generic.\n schema.testEnvironment ??= 'jsdom';\n\n /**\n * This is for when we are converting an existing project\n * to use the vite executors.\n */\n let projectAlreadyHasViteTargets: TargetFlags = {};\n\n if (!schema.newProject) {\n await convertNonVite(tree, schema, projectRoot, projectType, targets);\n }\n\n const jsInitTask = await jsInitGenerator(tree, {\n ...schema,\n skipFormat: true,\n tsConfigName: projectRoot === '.' ? 'tsconfig.json' : 'tsconfig.base.json',\n });\n tasks.push(jsInitTask);\n const initTask = await initGenerator(tree, { ...schema, skipFormat: true });\n tasks.push(initTask);\n tasks.push(ensureDependencies(tree, schema));\n\n const nxJson = readNxJson(tree);\n const addPluginDefault =\n process.env.NX_ADD_PLUGINS !== 'false' &&\n nxJson.useInferencePlugins !== false;\n schema.addPlugin ??= addPluginDefault;\n\n const hasPlugin = nxJson.plugins?.some((p) =>\n typeof p === 'string'\n ? p === '@nx/vite/plugin'\n : p.plugin === '@nx/vite/plugin'\n );\n\n if (!hasPlugin) {\n if (!projectAlreadyHasViteTargets.build) {\n addBuildTarget(tree, schema, 'build');\n }\n\n if (!schema.includeLib) {\n if (!projectAlreadyHasViteTargets.serve) {\n addServeTarget(tree, schema, 'serve');\n }\n if (!projectAlreadyHasViteTargets.preview) {\n addPreviewTarget(tree, schema, 'preview');\n }\n }\n }\n if (projectType === 'library') {\n // update tsconfig.lib.json to include vite/client\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.lib.json'),\n (json) => {\n json.compilerOptions ??= {};\n json.compilerOptions.types ??= [];\n if (!json.compilerOptions.types.includes('vite/client')) {\n json.compilerOptions.types.push('vite/client');\n }\n return json;\n }\n );\n }\n\n if (!schema.newProject) {\n // We are converting existing project to use Vite\n if (schema.uiFramework === 'react') {\n createOrEditViteConfig(\n tree,\n {\n project: schema.project,\n includeLib: schema.includeLib,\n includeVitest: schema.includeVitest,\n inSourceTests: schema.inSourceTests,\n rollupOptionsExternal: [\n \"'react'\",\n \"'react-dom'\",\n \"'react/jsx-runtime'\",\n ],\n imports: [\n schema.compiler === 'swc'\n ? `import react from '@vitejs/plugin-react-swc'`\n : `import react from '@vitejs/plugin-react'`,\n ],\n plugins: ['react()'],\n },\n false,\n undefined\n );\n } else {\n createOrEditViteConfig(tree, schema, false, projectAlreadyHasViteTargets);\n }\n }\n\n if (schema.includeVitest) {\n const vitestTask = await vitestGenerator(tree, {\n project: schema.project,\n uiFramework: schema.uiFramework,\n inSourceTests: schema.inSourceTests,\n coverageProvider: 'v8',\n skipViteConfig: true,\n testTarget: 'test',\n skipFormat: true,\n addPlugin: schema.addPlugin,\n compiler: schema.compiler,\n });\n tasks.push(vitestTask);\n }\n\n if (isUsingTsSolutionSetup(tree)) {\n updatePackageJson(tree, schema);\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nexport default viteConfigurationGenerator;\n\nfunction updatePackageJson(\n tree: Tree,\n options: ViteConfigurationGeneratorSchema\n) {\n const project = readProjectConfiguration(tree, options.project);\n\n const packageJsonPath = join(project.root, 'package.json');\n let packageJson: PackageJson;\n if (tree.exists(packageJsonPath)) {\n packageJson = readJson(tree, packageJsonPath);\n } else {\n packageJson = {\n name: getImportPath(tree, options.project),\n version: '0.0.1',\n };\n }\n\n // we always write/override the vite and project config with some set values,\n // so we can rely on them\n const main = join(project.root, 'src/index.ts');\n // we configure the dts plugin with the entryRoot set to `src`\n const rootDir = join(project.root, 'src');\n const outputPath = joinPathFragments(project.root, 'dist');\n\n packageJson = getUpdatedPackageJsonContent(packageJson, {\n main,\n outputPath,\n projectRoot: project.root,\n rootDir,\n generateExportsField: true,\n packageJsonPath,\n format: ['esm', 'cjs'],\n // when building both formats, we don't set the package.json \"type\" field, so\n // we need to set the esm extension to \".mjs\" to match vite output\n // see the \"File Extensions\" callout in https://vite.dev/guide/build.html#library-mode\n outputFileExtensionForEsm: '.mjs',\n });\n\n writeJson(tree, packageJsonPath, packageJson);\n}\n"],"names":["viteConfigurationGenerator","viteConfigurationGeneratorInternal","host","schema","addPlugin","tree","nxJson","tasks","projectConfig","readProjectConfiguration","project","targets","root","projectRoot","projectType","includeLib","testEnvironment","projectAlreadyHasViteTargets","newProject","convertNonVite","jsInitTask","jsInitGenerator","skipFormat","tsConfigName","push","initTask","initGenerator","ensureDependencies","readNxJson","addPluginDefault","process","env","NX_ADD_PLUGINS","useInferencePlugins","hasPlugin","plugins","some","p","plugin","build","addBuildTarget","serve","addServeTarget","preview","addPreviewTarget","updateJson","joinPathFragments","json","compilerOptions","types","includes","uiFramework","createOrEditViteConfig","includeVitest","inSourceTests","rollupOptionsExternal","imports","compiler","undefined","vitestTask","vitestGenerator","coverageProvider","skipViteConfig","testTarget","isUsingTsSolutionSetup","updatePackageJson","formatFiles","runTasksInSerial","options","packageJsonPath","join","packageJson","exists","readJson","name","getImportPath","version","main","rootDir","outputPath","getUpdatedPackageJsonContent","generateExportsField","format","outputFileExtensionForEsm","writeJson"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAkLA,OAA0C;eAA1C;;IAjJgBA,0BAA0B;eAA1BA;;IAUMC,kCAAkC;eAAlCA;;;;wBAhCf;oBAIA;+BACuB;iCACS;uBAClB;oCAEc;gCAO5B;sBACmB;iCACE;gCACG;AAGxB,SAASD,2BACdE,IAAU,EACVC,MAAwC;IAExC,OAAOF,mCAAmCC,MAAM;QAC9CE,WAAW;OACRD;AAEP;AAEO,eAAeF,mCACpBI,IAAU,EACVF,MAAwC;QAyCtBG;QAhClBH,SAEA,8EAA8E;IAC9E,8EAA8E;IAC9EA,UA0BAA;IArCA,MAAMI,QAA6B,EAAE;IAErC,MAAMC,gBAAgBC,IAAAA,gCAAwB,EAACJ,MAAMF,OAAOO,OAAO;IACnE,MAAM,EAAEC,OAAO,EAAEC,MAAMC,WAAW,EAAE,GAAGL;QAEnBA;IAApB,MAAMM,cAAcN,CAAAA,6BAAAA,cAAcM,WAAW,YAAzBN,6BAA6B;;IAEjDL,gBAAAA,UAAAA,QAAOY,oCAAPZ,QAAOY,aAAeD,gBAAgB;;IAItCX,qBAAAA,WAAAA,QAAOa,8CAAPb,SAAOa,kBAAoB;IAE3B;;;GAGC,GACD,IAAIC,+BAA4C,CAAC;IAEjD,IAAI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AAE;QACtB,MAAM4C,IAAAA,mBAAW,EAAC7D;IACpB;IAEA,OAAO8D,IAAAA,wBAAgB,KAAI5D;AAC7B;MAEA,WAAeP;AAEf,SAASiE,kBACP5D,IAAU,EACV+D,OAAyC;IAEzC,MAAM1D,UAAUD,IAAAA,gCAAwB,EAACJ,MAAM+D,QAAQ1D,OAAO;IAE9D,MAAM2D,kBAAkBC,IAAAA,WAAI,EAAC5D,QAAQE,IAAI,EAAE;IAC3C,IAAI2D;IACJ,IAAIlE,KAAKmE,MAAM,CAACH,kBAAkB;QAChCE,cAAcE,IAAAA,gBAAQ,EAACpE,MAAMgE;IAC/B,OAAO;QACLE,cAAc;YACZG,MAAMC,IAAAA,4BAAa,EAACtE,MAAM+D,QAAQ1D,OAAO;YACzCkE,SAAS;QACX;IACF;IAEA,6EAA6E;IAC7E,yBAAyB;IACzB,MAAMC,OAAOP,IAAAA,WAAI,EAAC5D,QAAQE,IAAI,EAAE;IAChC,8DAA8D;IAC9D,MAAMkE,UAAUR,IAAAA,WAAI,EAAC5D,QAAQE,IAAI,EAAE;IACnC,MAAMmE,aAAajC,IAAAA,yBAAiB,EAACpC,QAAQE,IAAI,EAAE;IAEnD2D,cAAcS,IAAAA,gCAA4B,EAACT,aAAa;QACtDM;QACAE;QACAlE,aAAaH,QAAQE,IAAI;QACzBkE;QACAG,sBAAsB;QACtBZ;QACAa,QAAQ;YAAC;YAAO;SAAM;QACtB,6EAA6E;QAC7E,kEAAkE;QAClE,sFAAsF;QACtFC,2BAA2B;IAC7B;IAEAC,IAAAA,iBAAS,EAAC/E,MAAMgE,iBAAiBE;AACnC"}
@@ -31,7 +31,7 @@ function updateNxJsonSettings(tree) {
31
31
  const nxJson = (0, _devkit.readNxJson)(tree);
32
32
  const productionFileSet = (_nxJson_namedInputs = nxJson.namedInputs) == null ? void 0 : _nxJson_namedInputs.production;
33
33
  if (productionFileSet) {
34
- productionFileSet.push('!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json');
34
+ productionFileSet.push('!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json', '!{projectRoot}/src/test-setup.[jt]s');
35
35
  nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
36
36
  }
37
37
  const hasPlugin = (_nxJson_plugins = nxJson.plugins) == null ? void 0 : _nxJson_plugins.some((p)=>typeof p === 'string' ? p === '@nx/vite/plugin' : p.plugin === '@nx/vite/plugin');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"sourcesContent":["import {\n createProjectGraphAsync,\n formatFiles,\n GeneratorCallback,\n readNxJson,\n runTasksInSerial,\n Tree,\n updateNxJson,\n} from '@nx/devkit';\nimport { addPlugin } from '@nx/devkit/src/utils/add-plugin';\n\nimport { setupPathsPlugin } from '../setup-paths-plugin/setup-paths-plugin';\nimport { createNodesV2 } from '../../plugins/plugin';\nimport { InitGeneratorSchema } from './schema';\nimport { checkDependenciesInstalled, moveToDevDependencies } from './lib/utils';\nimport { addViteTempFilesToGitIgnore } from '../../utils/add-vite-temp-files-to-gitignore';\n\nexport function updateNxJsonSettings(tree: Tree) {\n const nxJson = readNxJson(tree);\n\n const productionFileSet = nxJson.namedInputs?.production;\n if (productionFileSet) {\n productionFileSet.push(\n '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',\n '!{projectRoot}/tsconfig.spec.json'\n );\n\n nxJson.namedInputs.production = Array.from(new Set(productionFileSet));\n }\n\n const hasPlugin = nxJson.plugins?.some((p) =>\n typeof p === 'string'\n ? p === '@nx/vite/plugin'\n : p.plugin === '@nx/vite/plugin'\n );\n\n if (!hasPlugin) {\n nxJson.targetDefaults ??= {};\n nxJson.targetDefaults['@nx/vite:test'] ??= {};\n nxJson.targetDefaults['@nx/vite:test'].cache ??= true;\n nxJson.targetDefaults['@nx/vite:test'].inputs ??= [\n 'default',\n productionFileSet ? '^production' : '^default',\n ];\n }\n\n updateNxJson(tree, nxJson);\n}\n\nexport function initGenerator(tree: Tree, schema: InitGeneratorSchema) {\n return initGeneratorInternal(tree, { addPlugin: false, ...schema });\n}\n\nexport async function initGeneratorInternal(\n tree: Tree,\n schema: InitGeneratorSchema\n) {\n const nxJson = readNxJson(tree);\n const addPluginDefault =\n process.env.NX_ADD_PLUGINS !== 'false' &&\n nxJson.useInferencePlugins !== false;\n schema.addPlugin ??= addPluginDefault;\n\n if (schema.addPlugin) {\n await addPlugin(\n tree,\n await createProjectGraphAsync(),\n '@nx/vite/plugin',\n createNodesV2,\n {\n buildTargetName: ['build', 'vite:build', 'vite-build'],\n testTargetName: ['test', 'vite:test', 'vite-test'],\n serveTargetName: ['serve', 'vite:serve', 'vite-serve'],\n previewTargetName: ['preview', 'vite:preview', 'vite-preview'],\n serveStaticTargetName: [\n 'serve-static',\n 'vite:serve-static',\n 'vite-serve-static',\n ],\n typecheckTargetName: ['typecheck', 'vite:typecheck', 'vite-typecheck'],\n },\n schema.updatePackageScripts\n );\n }\n\n updateNxJsonSettings(tree);\n addViteTempFilesToGitIgnore(tree);\n\n if (schema.setupPathsPlugin) {\n await setupPathsPlugin(tree, { skipFormat: true });\n }\n\n const tasks: GeneratorCallback[] = [];\n if (!schema.skipPackageJson) {\n tasks.push(moveToDevDependencies(tree));\n tasks.push(checkDependenciesInstalled(tree, schema));\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nexport default initGenerator;\n"],"names":["initGenerator","initGeneratorInternal","updateNxJsonSettings","tree","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","hasPlugin","plugins","some","p","plugin","targetDefaults","cache","inputs","updateNxJson","schema","addPlugin","addPluginDefault","process","env","NX_ADD_PLUGINS","useInferencePlugins","createProjectGraphAsync","createNodesV2","buildTargetName","testTargetName","serveTargetName","previewTargetName","serveStaticTargetName","typecheckTargetName","updatePackageScripts","addViteTempFilesToGitIgnore","setupPathsPlugin","skipFormat","tasks","skipPackageJson","moveToDevDependencies","checkDependenciesInstalled","formatFiles","runTasksInSerial"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAyGA,OAA6B;eAA7B;;IAxDgBA,aAAa;eAAbA;;IAIMC,qBAAqB;eAArBA;;IApCNC,oBAAoB;eAApBA;;;;wBATT;2BACmB;kCAEO;wBACH;uBAEoC;6CACtB;AAErC,SAASA,qBAAqBC,IAAU;QAGnBC,qBAURA;IAZlB,MAAMA,SAASC,IAAAA,kBAAU,EAACF;IAE1B,MAAMG,qBAAoBF,sBAAAA,OAAOG,WAAW,qBAAlBH,oBAAoBI,UAAU;IACxD,IAAIF,mBAAmB;QACrBA,kBAAkBG,IAAI,CACpB,yDACA;QAGFL,OAAOG,WAAW,CAACC,UAAU,GAAGE,MAAMC,IAAI,CAAC,IAAIC,IAAIN;IACrD;IAEA,MAAMO,aAAYT,kBAAAA,OAAOU,OAAO,qBAAdV,gBAAgBW,IAAI,CAAC,CAACC,IACtC,OAAOA,MAAM,WACTA,MAAM,oBACNA,EAAEC,MAAM,KAAK;IAGnB,IAAI,CAACJ,WAAW;YACdT,SACAA,wBAAsB,aACtBA,mCACAA;;QAHAA,oBAAAA,UAAAA,QAAOc,4CAAPd,QAAOc,iBAAmB,CAAC;;QAC3Bd,MAAAA,yBAAAA,OAAOc,cAAc,CAAA,CAAC,cAAA,gBAAgB,gBAAtCd,sBAAqB,CAAC,YAAgB,GAAK,CAAC;;QAC5CA,WAAAA,oCAAAA,OAAOc,cAAc,CAAC,gBAAgB,EAACC,0BAAvCf,kCAAuCe,QAAU;;QACjDf,YAAAA,qCAAAA,OAAOc,cAAc,CAAC,gBAAgB,EAACE,4BAAvChB,mCAAuCgB,SAAW;YAChD;YACAd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AAC1C;IACpB;IAEA,OAAO2C,IAAAA,wBAAgB,KAAIL;AAC7B;MAEA,WAAezC"}
1
+ {"version":3,"sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"sourcesContent":["import {\n createProjectGraphAsync,\n formatFiles,\n GeneratorCallback,\n readNxJson,\n runTasksInSerial,\n Tree,\n updateNxJson,\n} from '@nx/devkit';\nimport { addPlugin } from '@nx/devkit/src/utils/add-plugin';\n\nimport { setupPathsPlugin } from '../setup-paths-plugin/setup-paths-plugin';\nimport { createNodesV2 } from '../../plugins/plugin';\nimport { InitGeneratorSchema } from './schema';\nimport { checkDependenciesInstalled, moveToDevDependencies } from './lib/utils';\nimport { addViteTempFilesToGitIgnore } from '../../utils/add-vite-temp-files-to-gitignore';\n\nexport function updateNxJsonSettings(tree: Tree) {\n const nxJson = readNxJson(tree);\n\n const productionFileSet = nxJson.namedInputs?.production;\n if (productionFileSet) {\n productionFileSet.push(\n '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',\n '!{projectRoot}/tsconfig.spec.json',\n '!{projectRoot}/src/test-setup.[jt]s'\n );\n\n nxJson.namedInputs.production = Array.from(new Set(productionFileSet));\n }\n\n const hasPlugin = nxJson.plugins?.some((p) =>\n typeof p === 'string'\n ? p === '@nx/vite/plugin'\n : p.plugin === '@nx/vite/plugin'\n );\n\n if (!hasPlugin) {\n nxJson.targetDefaults ??= {};\n nxJson.targetDefaults['@nx/vite:test'] ??= {};\n nxJson.targetDefaults['@nx/vite:test'].cache ??= true;\n nxJson.targetDefaults['@nx/vite:test'].inputs ??= [\n 'default',\n productionFileSet ? '^production' : '^default',\n ];\n }\n\n updateNxJson(tree, nxJson);\n}\n\nexport function initGenerator(tree: Tree, schema: InitGeneratorSchema) {\n return initGeneratorInternal(tree, { addPlugin: false, ...schema });\n}\n\nexport async function initGeneratorInternal(\n tree: Tree,\n schema: InitGeneratorSchema\n) {\n const nxJson = readNxJson(tree);\n const addPluginDefault =\n process.env.NX_ADD_PLUGINS !== 'false' &&\n nxJson.useInferencePlugins !== false;\n schema.addPlugin ??= addPluginDefault;\n\n if (schema.addPlugin) {\n await addPlugin(\n tree,\n await createProjectGraphAsync(),\n '@nx/vite/plugin',\n createNodesV2,\n {\n buildTargetName: ['build', 'vite:build', 'vite-build'],\n testTargetName: ['test', 'vite:test', 'vite-test'],\n serveTargetName: ['serve', 'vite:serve', 'vite-serve'],\n previewTargetName: ['preview', 'vite:preview', 'vite-preview'],\n serveStaticTargetName: [\n 'serve-static',\n 'vite:serve-static',\n 'vite-serve-static',\n ],\n typecheckTargetName: ['typecheck', 'vite:typecheck', 'vite-typecheck'],\n },\n schema.updatePackageScripts\n );\n }\n\n updateNxJsonSettings(tree);\n addViteTempFilesToGitIgnore(tree);\n\n if (schema.setupPathsPlugin) {\n await setupPathsPlugin(tree, { skipFormat: true });\n }\n\n const tasks: GeneratorCallback[] = [];\n if (!schema.skipPackageJson) {\n tasks.push(moveToDevDependencies(tree));\n tasks.push(checkDependenciesInstalled(tree, schema));\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nexport default initGenerator;\n"],"names":["initGenerator","initGeneratorInternal","updateNxJsonSettings","tree","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","hasPlugin","plugins","some","p","plugin","targetDefaults","cache","inputs","updateNxJson","schema","addPlugin","addPluginDefault","process","env","NX_ADD_PLUGINS","useInferencePlugins","createProjectGraphAsync","createNodesV2","buildTargetName","testTargetName","serveTargetName","previewTargetName","serveStaticTargetName","typecheckTargetName","updatePackageScripts","addViteTempFilesToGitIgnore","setupPathsPlugin","skipFormat","tasks","skipPackageJson","moveToDevDependencies","checkDependenciesInstalled","formatFiles","runTasksInSerial"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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IAJA,MAAMlB,SAASC,IAAAA,kBAAU,EAACF;IAC1B,MAAMqB,mBACJC,QAAQC,GAAG,CAACC,cAAc,KAAK,WAC/BvB,OAAOwB,mBAAmB,KAAK;;IACjCN,eAAAA,UAAAA,QAAOC,kCAAPD,QAAOC,YAAcC;IAErB,IAAIF,OAAOC,SAAS,EAAE;QACpB,MAAMA,IAAAA,oBAAS,EACbpB,MACA,MAAM0B,IAAAA,+BAAuB,KAC7B,mBACAC,qBAAa,EACb;YACEC,iBAAiB;gBAAC;gBAAS;gBAAc;aAAa;YACtDC,gBAAgB;gBAAC;gBAAQ;gBAAa;aAAY;YAClDC,iBAAiB;gBAAC;gBAAS;gBAAc;aAAa;YACtDC,mBAAmB;gBAAC;gBAAW;gBAAgB;aAAe;YAC9DC,uBAAuB;gBACrB;gBACA;gBACA;aACD;YACDC,qBAAqB;gBAAC;gBAAa;gBAAkB;aAAiB;QACxE,GACAd,OAAOe,oBAAoB;IAE/B;IAEAnC,qBAAqBC;IACrBmC,IAAAA,wDAA2B,EAACnC;IAE5B,IAAImB,OAAOiB,gBAAgB,EAAE;QAC3B,MAAMA,IAAAA,kCAAgB,EAACpC,MAAM;YAAEqC,YAAY;QAAK;IAClD;IAEA,MAAMC,QAA6B,EAAE;IACrC,IAAI,CAACnB,OAAOoB,eAAe,EAAE;QAC3BD,MAAMhC,IAAI,CAACkC,IAAAA,4BAAqB,EAACxC;QACjCsC,MAAMhC,IAAI,CAACmC,IAAAA,iCAA0B,EAACzC,MAAMmB;IAC9C;IAEA,IAAI,CAACA,OAAOkB,UAAU,EAAE;QACtB,MAAMK,IAAAA,mBAAW,EAAC1C;IACpB;IAEA,OAAO2C,IAAAA,wBAAgB,KAAIL;AAC7B;MAEA,WAAezC"}
@@ -97,6 +97,7 @@ async function vitestGeneratorInternal(tree, schema, hasPlugin = false) {
97
97
  return (0, _devkit.runTasksInSerial)(...tasks);
98
98
  }
99
99
  function updateTsConfig(tree, options, projectRoot, projectType) {
100
+ const setupFile = tryFindSetupFile(tree, projectRoot);
100
101
  if (tree.exists((0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.spec.json'))) {
101
102
  (0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.spec.json'), (json)=>{
102
103
  var _json_compilerOptions_types, _json_compilerOptions;
@@ -113,6 +114,13 @@ function updateTsConfig(tree, options, projectRoot, projectType) {
113
114
  ];
114
115
  }
115
116
  }
117
+ if (setupFile) {
118
+ var _json_files;
119
+ json.files = [
120
+ ...(_json_files = json.files) != null ? _json_files : [],
121
+ setupFile
122
+ ];
123
+ }
116
124
  return json;
117
125
  });
118
126
  (0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.json'), (json)=>{
@@ -149,19 +157,13 @@ function updateTsConfig(tree, options, projectRoot, projectType) {
149
157
  throw new Error(`Cannot find the specified runtimeTsConfigFileName ("${options.runtimeTsconfigFileName}") at the project root "${projectRoot}".`);
150
158
  }
151
159
  }
152
- if (options.inSourceTests) {
153
- if (tree.exists(runtimeTsconfigPath)) {
154
- (0, _devkit.updateJson)(tree, runtimeTsconfigPath, (json)=>{
160
+ if (tree.exists(runtimeTsconfigPath)) {
161
+ (0, _devkit.updateJson)(tree, runtimeTsconfigPath, (json)=>{
162
+ if (options.inSourceTests) {
155
163
  var _json_compilerOptions;
156
164
  var _types;
157
165
  ((_types = (_json_compilerOptions = json.compilerOptions).types) != null ? _types : _json_compilerOptions.types = []).push('vitest/importMeta');
158
- return json;
159
- });
160
- }
161
- (0, _js.addTsLibDependencies)(tree);
162
- } else {
163
- if (tree.exists(runtimeTsconfigPath)) {
164
- (0, _devkit.updateJson)(tree, runtimeTsconfigPath, (json)=>{
166
+ } else {
165
167
  const uniqueExclude = new Set([
166
168
  ...json.exclude || [],
167
169
  'vite.config.ts',
@@ -180,11 +182,18 @@ function updateTsConfig(tree, options, projectRoot, projectType) {
180
182
  json.exclude = [
181
183
  ...uniqueExclude
182
184
  ];
183
- return json;
184
- });
185
- } else {
186
- _devkit.logger.warn(`Couldn't find a runtime tsconfig file at ${runtimeTsconfigPath} to exclude the test files from. ` + `If you're using a different filename for your runtime tsconfig, please provide it with the '--runtimeTsconfigFileName' flag.`);
187
- }
185
+ }
186
+ if (setupFile) {
187
+ var _json_exclude;
188
+ json.exclude = [
189
+ ...(_json_exclude = json.exclude) != null ? _json_exclude : [],
190
+ setupFile
191
+ ];
192
+ }
193
+ return json;
194
+ });
195
+ } else {
196
+ _devkit.logger.warn(`Couldn't find a runtime tsconfig file at ${runtimeTsconfigPath} to exclude the test files from. ` + `If you're using a different filename for your runtime tsconfig, please provide it with the '--runtimeTsconfigFileName' flag.`);
188
197
  }
189
198
  }
190
199
  function createFiles(tree, options, projectRoot) {
@@ -211,6 +220,12 @@ function getCoverageProviderDependency(coverageProvider) {
211
220
  };
212
221
  }
213
222
  }
223
+ function tryFindSetupFile(tree, projectRoot) {
224
+ const setupFile = (0, _devkit.joinPathFragments)('src', 'test-setup.ts');
225
+ if (tree.exists((0, _devkit.joinPathFragments)(projectRoot, setupFile))) {
226
+ return setupFile;
227
+ }
228
+ }
214
229
  const _default = vitestGenerator;
215
230
 
216
231
  //# sourceMappingURL=vitest-generator.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/vite/src/generators/vitest/vitest-generator.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n formatFiles,\n generateFiles,\n GeneratorCallback,\n joinPathFragments,\n logger,\n offsetFromRoot,\n ProjectType,\n readNxJson,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\nimport {\n addOrChangeTestTarget,\n createOrEditViteConfig,\n} from '../../utils/generator-utils';\nimport { VitestGeneratorSchema } from './schema';\n\nimport initGenerator from '../init/init';\nimport {\n vitestCoverageIstanbulVersion,\n vitestCoverageV8Version,\n} from '../../utils/versions';\n\nimport { addTsLibDependencies, initGenerator as jsInitGenerator } from '@nx/js';\nimport { join } from 'path';\nimport { ensureDependencies } from '../../utils/ensure-dependencies';\n\nexport function vitestGenerator(\n tree: Tree,\n schema: VitestGeneratorSchema,\n hasPlugin = false\n) {\n return vitestGeneratorInternal(\n tree,\n { addPlugin: false, ...schema },\n hasPlugin\n );\n}\n\nexport async function vitestGeneratorInternal(\n tree: Tree,\n schema: VitestGeneratorSchema,\n hasPlugin = false\n) {\n // Setting default to jsdom since it is the most common use case (React, Web).\n // The @nx/js:lib generator specifically sets this to node to be more generic.\n schema.testEnvironment ??= 'jsdom';\n\n const tasks: GeneratorCallback[] = [];\n\n const { root, projectType } = readProjectConfiguration(tree, schema.project);\n const isRootProject = root === '.';\n\n tasks.push(await jsInitGenerator(tree, { ...schema, skipFormat: true }));\n const initTask = await initGenerator(tree, {\n skipFormat: true,\n addPlugin: schema.addPlugin,\n });\n tasks.push(initTask);\n tasks.push(ensureDependencies(tree, schema));\n\n const nxJson = readNxJson(tree);\n const hasPluginCheck = nxJson.plugins?.some(\n (p) =>\n (typeof p === 'string'\n ? p === '@nx/vite/plugin'\n : p.plugin === '@nx/vite/plugin') || hasPlugin\n );\n if (!hasPluginCheck) {\n const testTarget = schema.testTarget ?? 'test';\n addOrChangeTestTarget(tree, schema, testTarget);\n }\n\n if (!schema.skipViteConfig) {\n if (schema.uiFramework === 'react') {\n createOrEditViteConfig(\n tree,\n {\n project: schema.project,\n includeLib: projectType === 'library',\n includeVitest: true,\n inSourceTests: schema.inSourceTests,\n rollupOptionsExternal: [\n \"'react'\",\n \"'react-dom'\",\n \"'react/jsx-runtime'\",\n ],\n imports: [\n schema.compiler === 'swc'\n ? `import react from '@vitejs/plugin-react-swc'`\n : `import react from '@vitejs/plugin-react'`,\n ],\n plugins: ['react()'],\n coverageProvider: schema.coverageProvider,\n },\n true\n );\n } else {\n createOrEditViteConfig(\n tree,\n {\n ...schema,\n includeVitest: true,\n includeLib: projectType === 'library',\n },\n true\n );\n }\n }\n\n createFiles(tree, schema, root);\n updateTsConfig(tree, schema, root, projectType);\n\n const coverageProviderDependency = getCoverageProviderDependency(\n schema.coverageProvider\n );\n\n const installCoverageProviderTask = addDependenciesToPackageJson(\n tree,\n {},\n coverageProviderDependency\n );\n tasks.push(installCoverageProviderTask);\n\n // Setup workspace config file (https://vitest.dev/guide/workspace.html)\n if (\n !isRootProject &&\n !tree.exists(`vitest.workspace.ts`) &&\n !tree.exists(`vitest.workspace.js`) &&\n !tree.exists(`vitest.workspace.json`) &&\n !tree.exists(`vitest.projects.ts`) &&\n !tree.exists(`vitest.projects.js`) &&\n !tree.exists(`vitest.projects.json`)\n ) {\n tree.write(\n 'vitest.workspace.ts',\n `export default ['**/*/vite.config.{ts,mts}', '**/*/vitest.config.{ts,mts}'];`\n );\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nfunction updateTsConfig(\n tree: Tree,\n options: VitestGeneratorSchema,\n projectRoot: string,\n projectType: ProjectType\n) {\n if (tree.exists(joinPathFragments(projectRoot, 'tsconfig.spec.json'))) {\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.spec.json'),\n (json) => {\n if (!json.compilerOptions?.types?.includes('vitest')) {\n if (json.compilerOptions?.types) {\n json.compilerOptions.types.push('vitest');\n } else {\n json.compilerOptions ??= {};\n json.compilerOptions.types = ['vitest'];\n }\n }\n return json;\n }\n );\n\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.json'),\n (json) => {\n if (\n json.references &&\n !json.references.some((r) => r.path === './tsconfig.spec.json')\n ) {\n json.references.push({\n path: './tsconfig.spec.json',\n });\n }\n return json;\n }\n );\n } else {\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.json'),\n (json) => {\n if (!json.compilerOptions?.types?.includes('vitest')) {\n if (json.compilerOptions?.types) {\n json.compilerOptions.types.push('vitest');\n } else {\n json.compilerOptions ??= {};\n json.compilerOptions.types = ['vitest'];\n }\n }\n return json;\n }\n );\n }\n\n let runtimeTsconfigPath = joinPathFragments(\n projectRoot,\n projectType === 'application' ? 'tsconfig.app.json' : 'tsconfig.lib.json'\n );\n if (options.runtimeTsconfigFileName) {\n runtimeTsconfigPath = joinPathFragments(\n projectRoot,\n options.runtimeTsconfigFileName\n );\n if (!tree.exists(runtimeTsconfigPath)) {\n throw new Error(\n `Cannot find the specified runtimeTsConfigFileName (\"${options.runtimeTsconfigFileName}\") at the project root \"${projectRoot}\".`\n );\n }\n }\n\n if (options.inSourceTests) {\n if (tree.exists(runtimeTsconfigPath)) {\n updateJson(tree, runtimeTsconfigPath, (json) => {\n (json.compilerOptions.types ??= []).push('vitest/importMeta');\n return json;\n });\n }\n\n addTsLibDependencies(tree);\n } else {\n if (tree.exists(runtimeTsconfigPath)) {\n updateJson(tree, runtimeTsconfigPath, (json) => {\n const uniqueExclude = new Set([\n ...(json.exclude || []),\n 'vite.config.ts',\n 'vite.config.mts',\n 'vitest.config.ts',\n 'vitest.config.mts',\n 'src/**/*.test.ts',\n 'src/**/*.spec.ts',\n 'src/**/*.test.tsx',\n 'src/**/*.spec.tsx',\n 'src/**/*.test.js',\n 'src/**/*.spec.js',\n 'src/**/*.test.jsx',\n 'src/**/*.spec.jsx',\n ]);\n json.exclude = [...uniqueExclude];\n return json;\n });\n } else {\n logger.warn(\n `Couldn't find a runtime tsconfig file at ${runtimeTsconfigPath} to exclude the test files from. ` +\n `If you're using a different filename for your runtime tsconfig, please provide it with the '--runtimeTsconfigFileName' flag.`\n );\n }\n }\n}\n\nfunction createFiles(\n tree: Tree,\n options: VitestGeneratorSchema,\n projectRoot: string\n) {\n generateFiles(tree, join(__dirname, 'files'), projectRoot, {\n tmpl: '',\n ...options,\n projectRoot,\n offsetFromRoot: offsetFromRoot(projectRoot),\n });\n}\n\nfunction getCoverageProviderDependency(\n coverageProvider: VitestGeneratorSchema['coverageProvider']\n) {\n switch (coverageProvider) {\n case 'v8':\n return {\n '@vitest/coverage-v8': vitestCoverageV8Version,\n };\n case 'istanbul':\n return {\n '@vitest/coverage-istanbul': vitestCoverageIstanbulVersion,\n };\n default:\n return {\n '@vitest/coverage-v8': vitestCoverageV8Version,\n };\n }\n}\n\nexport default vitestGenerator;\n"],"names":["vitestGenerator","vitestGeneratorInternal","tree","schema","hasPlugin","addPlugin","nxJson","testEnvironment","tasks","root","projectType","readProjectConfiguration","project","isRootProject","push","jsInitGenerator","skipFormat","initTask","initGenerator","ensureDependencies","readNxJson","hasPluginCheck","plugins","some","p","plugin","testTarget","addOrChangeTestTarget","skipViteConfig","uiFramework","createOrEditViteConfig","includeLib","includeVitest","inSourceTests","rollupOptionsExternal","imports","compiler","coverageProvider","createFiles","updateTsConfig","coverageProviderDependency","getCoverageProviderDependency","installCoverageProviderTask","addDependenciesToPackageJson","exists","write","formatFiles","runTasksInSerial","options","projectRoot","joinPathFragments","updateJson","json","compilerOptions","types","includes","references","r","path","runtimeTsconfigPath","runtimeTsconfigFileName","Error","addTsLibDependencies","uniqueExclude","Set","exclude","logger","warn","generateFiles","join","__dirname","tmpl","offsetFromRoot","vitestCoverageV8Version","vitestCoverageIstanbulVersion"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAsSA,OAA+B;eAA/B;;IAvQgBA,eAAe;eAAfA;;IAYMC,uBAAuB;eAAvBA;;;;wBA7Bf;gCAIA;sBAGmB;0BAInB;oBAEgE;sBAClD;oCACc;AAE5B,SAASD,gBACdE,IAAU,EACVC,MAA6B,EAC7BC,YAAY,KAAK;IAEjB,OAAOH,wBACLC,MACA;QAAEG,WAAW;OAAUF,SACvBC;AAEJ;AAEO,eAAeH,wBACpBC,IAAU,EAC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HvB;QACHC;QACAuB,gBAAgBA,IAAAA,sBAAc,EAACvB;;AAEnC;AAEA,SAASR,8BACPJ,gBAA2D;IAE3D,OAAQA;QACN,KAAK;YACH,OAAO;gBACL,uBAAuBoC,iCAAuB;YAChD;QACF,KAAK;YACH,OAAO;gBACL,6BAA6BC,uCAA6B;YAC5D;QACF;YACE,OAAO;gBACL,uBAAuBD,iCAAuB;YAChD;IACJ;AACF;MAEA,WAAezE"}
1
+ {"version":3,"sources":["../../../../../../packages/vite/src/generators/vitest/vitest-generator.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n formatFiles,\n generateFiles,\n GeneratorCallback,\n joinPathFragments,\n logger,\n offsetFromRoot,\n ProjectType,\n readNxJson,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\nimport {\n addOrChangeTestTarget,\n createOrEditViteConfig,\n} from '../../utils/generator-utils';\nimport { VitestGeneratorSchema } from './schema';\n\nimport initGenerator from '../init/init';\nimport {\n vitestCoverageIstanbulVersion,\n vitestCoverageV8Version,\n} from '../../utils/versions';\n\nimport { addTsLibDependencies, initGenerator as jsInitGenerator } from '@nx/js';\nimport { join } from 'path';\nimport { ensureDependencies } from '../../utils/ensure-dependencies';\n\nexport function vitestGenerator(\n tree: Tree,\n schema: VitestGeneratorSchema,\n hasPlugin = false\n) {\n return vitestGeneratorInternal(\n tree,\n { addPlugin: false, ...schema },\n hasPlugin\n );\n}\n\nexport async function vitestGeneratorInternal(\n tree: Tree,\n schema: VitestGeneratorSchema,\n hasPlugin = false\n) {\n // Setting default to jsdom since it is the most common use case (React, Web).\n // The @nx/js:lib generator specifically sets this to node to be more generic.\n schema.testEnvironment ??= 'jsdom';\n\n const tasks: GeneratorCallback[] = [];\n\n const { root, projectType } = readProjectConfiguration(tree, schema.project);\n const isRootProject = root === '.';\n\n tasks.push(await jsInitGenerator(tree, { ...schema, skipFormat: true }));\n const initTask = await initGenerator(tree, {\n skipFormat: true,\n addPlugin: schema.addPlugin,\n });\n tasks.push(initTask);\n tasks.push(ensureDependencies(tree, schema));\n\n const nxJson = readNxJson(tree);\n const hasPluginCheck = nxJson.plugins?.some(\n (p) =>\n (typeof p === 'string'\n ? p === '@nx/vite/plugin'\n : p.plugin === '@nx/vite/plugin') || hasPlugin\n );\n if (!hasPluginCheck) {\n const testTarget = schema.testTarget ?? 'test';\n addOrChangeTestTarget(tree, schema, testTarget);\n }\n\n if (!schema.skipViteConfig) {\n if (schema.uiFramework === 'react') {\n createOrEditViteConfig(\n tree,\n {\n project: schema.project,\n includeLib: projectType === 'library',\n includeVitest: true,\n inSourceTests: schema.inSourceTests,\n rollupOptionsExternal: [\n \"'react'\",\n \"'react-dom'\",\n \"'react/jsx-runtime'\",\n ],\n imports: [\n schema.compiler === 'swc'\n ? `import react from '@vitejs/plugin-react-swc'`\n : `import react from '@vitejs/plugin-react'`,\n ],\n plugins: ['react()'],\n coverageProvider: schema.coverageProvider,\n },\n true\n );\n } else {\n createOrEditViteConfig(\n tree,\n {\n ...schema,\n includeVitest: true,\n includeLib: projectType === 'library',\n },\n true\n );\n }\n }\n\n createFiles(tree, schema, root);\n updateTsConfig(tree, schema, root, projectType);\n\n const coverageProviderDependency = getCoverageProviderDependency(\n schema.coverageProvider\n );\n\n const installCoverageProviderTask = addDependenciesToPackageJson(\n tree,\n {},\n coverageProviderDependency\n );\n tasks.push(installCoverageProviderTask);\n\n // Setup workspace config file (https://vitest.dev/guide/workspace.html)\n if (\n !isRootProject &&\n !tree.exists(`vitest.workspace.ts`) &&\n !tree.exists(`vitest.workspace.js`) &&\n !tree.exists(`vitest.workspace.json`) &&\n !tree.exists(`vitest.projects.ts`) &&\n !tree.exists(`vitest.projects.js`) &&\n !tree.exists(`vitest.projects.json`)\n ) {\n tree.write(\n 'vitest.workspace.ts',\n `export default ['**/*/vite.config.{ts,mts}', '**/*/vitest.config.{ts,mts}'];`\n );\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nfunction updateTsConfig(\n tree: Tree,\n options: VitestGeneratorSchema,\n projectRoot: string,\n projectType: ProjectType\n) {\n const setupFile = tryFindSetupFile(tree, projectRoot);\n\n if (tree.exists(joinPathFragments(projectRoot, 'tsconfig.spec.json'))) {\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.spec.json'),\n (json) => {\n if (!json.compilerOptions?.types?.includes('vitest')) {\n if (json.compilerOptions?.types) {\n json.compilerOptions.types.push('vitest');\n } else {\n json.compilerOptions ??= {};\n json.compilerOptions.types = ['vitest'];\n }\n }\n\n if (setupFile) {\n json.files = [...(json.files ?? []), setupFile];\n }\n\n return json;\n }\n );\n\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.json'),\n (json) => {\n if (\n json.references &&\n !json.references.some((r) => r.path === './tsconfig.spec.json')\n ) {\n json.references.push({\n path: './tsconfig.spec.json',\n });\n }\n return json;\n }\n );\n } else {\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.json'),\n (json) => {\n if (!json.compilerOptions?.types?.includes('vitest')) {\n if (json.compilerOptions?.types) {\n json.compilerOptions.types.push('vitest');\n } else {\n json.compilerOptions ??= {};\n json.compilerOptions.types = ['vitest'];\n }\n }\n return json;\n }\n );\n }\n\n let runtimeTsconfigPath = joinPathFragments(\n projectRoot,\n projectType === 'application' ? 'tsconfig.app.json' : 'tsconfig.lib.json'\n );\n if (options.runtimeTsconfigFileName) {\n runtimeTsconfigPath = joinPathFragments(\n projectRoot,\n options.runtimeTsconfigFileName\n );\n if (!tree.exists(runtimeTsconfigPath)) {\n throw new Error(\n `Cannot find the specified runtimeTsConfigFileName (\"${options.runtimeTsconfigFileName}\") at the project root \"${projectRoot}\".`\n );\n }\n }\n\n if (tree.exists(runtimeTsconfigPath)) {\n updateJson(tree, runtimeTsconfigPath, (json) => {\n if (options.inSourceTests) {\n (json.compilerOptions.types ??= []).push('vitest/importMeta');\n } else {\n const uniqueExclude = new Set([\n ...(json.exclude || []),\n 'vite.config.ts',\n 'vite.config.mts',\n 'vitest.config.ts',\n 'vitest.config.mts',\n 'src/**/*.test.ts',\n 'src/**/*.spec.ts',\n 'src/**/*.test.tsx',\n 'src/**/*.spec.tsx',\n 'src/**/*.test.js',\n 'src/**/*.spec.js',\n 'src/**/*.test.jsx',\n 'src/**/*.spec.jsx',\n ]);\n json.exclude = [...uniqueExclude];\n }\n\n if (setupFile) {\n json.exclude = [...(json.exclude ?? []), setupFile];\n }\n\n return json;\n });\n } else {\n logger.warn(\n `Couldn't find a runtime tsconfig file at ${runtimeTsconfigPath} to exclude the test files from. ` +\n `If you're using a different filename for your runtime tsconfig, please provide it with the '--runtimeTsconfigFileName' flag.`\n );\n }\n}\n\nfunction createFiles(\n tree: Tree,\n options: VitestGeneratorSchema,\n projectRoot: string\n) {\n generateFiles(tree, join(__dirname, 'files'), projectRoot, {\n tmpl: '',\n ...options,\n projectRoot,\n offsetFromRoot: offsetFromRoot(projectRoot),\n });\n}\n\nfunction getCoverageProviderDependency(\n coverageProvider: VitestGeneratorSchema['coverageProvider']\n) {\n switch (coverageProvider) {\n case 'v8':\n return {\n '@vitest/coverage-v8': vitestCoverageV8Version,\n };\n case 'istanbul':\n return {\n '@vitest/coverage-istanbul': vitestCoverageIstanbulVersion,\n };\n default:\n return {\n '@vitest/coverage-v8': vitestCoverageV8Version,\n };\n }\n}\n\nfunction tryFindSetupFile(tree: Tree, projectRoot: string) {\n const setupFile = joinPathFragments('src', 'test-setup.ts');\n if (tree.exists(joinPathFragments(projectRoot, setupFile))) {\n return setupFile;\n }\n}\n\nexport default vitestGenerator;\n"],"names":["vitestGenerator","vitestGeneratorInternal","tree","schema","hasPlugin","addPlugin","nxJson","testEnvironment","tasks","root","projectType","readProjectConfiguration","project","isRootProject","push","jsInitGenerator","skipFormat","initTask","initGenerator","ensureDependencies","readNxJson","hasPluginCheck","plugins","some","p","plugin","testTarget","addOrChangeTestTarget","skipViteConfig","uiFramework","createOrEditViteConfig","includeLib","includeVitest","inSourceTests","rollupOptionsExternal","imports","compiler","coverageProvider","createFiles","updateTsConfig","coverageProviderDependency","getCoverageProviderDependency","installCoverageProviderTask","addDependenciesToPackageJson","exists","write","formatFiles","runTasksInSerial","options","projectRoot","setupFile","tryFindSetupFile","joinPathFragments","updateJson","json","compilerOptions","types","includes","files","references","r","path","runtimeTsconfigPath","runtimeTsconfigFileName","Error","uniqueExclude","Set","exclude","logger","warn","generateFiles","join","__dirname","tmpl","offsetFromRoot","vitestCoverageV8Version","vitestCoverageIstanbulVersion"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAkTA,OAA+B;eAA/B;;IAnRgBA,eAAe;eAAfA;;IAYMC,uBAAuB;eAAvBA;;;;wBA7Bf;gCAIA;sBAGmB;0BAInB;oBAEgE;sBAClD;oCACc;AAE5B,SAASD,gBACdE,IAAU,EACVC,MAA6B,EAC7BC,YAAY,KAAK;IAEjB,OAAOH,wBACLC,MACA;QAAEG,WAAW;OAAUF,SACvBC;AAEJ;AAEO,eAAeH,wBACpBC,IAAU,EACVC,MAA6B,EAC7BC,YAAY,KAAK;QAoBME;QAlBvB,8EAA8E;IAC9E,8EAA8E;IAC9EH;;IAAAA,qBAAAA,UAAAA,QAAOI,8CAAPJ,QAAOI,kBAAoB;IAE3B,MAAMC,QAA6B,EAAE;IAErC,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGC,IAAAA,gCAAwB,EAACT,MAAMC,OAAOS,OAAO;IAC3E,MAAMC,gBAAgBJ,SAAS;IAE/BD,MAAMM,IA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L,uBAAuBsC,iCAAuB;YAChD;QACF,KAAK;YACH,OAAO;gBACL,6BAA6BC,uCAA6B;YAC5D;QACF;YACE,OAAO;gBACL,uBAAuBD,iCAAuB;YAChD;IACJ;AACF;AAEA,SAASxB,iBAAiBjD,IAAU,EAAE+C,WAAmB;IACvD,MAAMC,YAAYE,IAAAA,yBAAiB,EAAC,OAAO;IAC3C,IAAIlD,KAAK0C,MAAM,CAACQ,IAAAA,yBAAiB,EAACH,aAAaC,aAAa;QAC1D,OAAOA;IACT;AACF;MAEA,WAAelD"}
@@ -34,6 +34,8 @@ export interface ViteConfigFileOptions {
34
34
  imports?: string[];
35
35
  plugins?: string[];
36
36
  coverageProvider?: 'v8' | 'istanbul' | 'custom';
37
+ setupFile?: string;
38
+ useEsmExtension?: boolean;
37
39
  }
38
40
  export declare function createOrEditViteConfig(tree: Tree, options: ViteConfigFileOptions, onlyVitest: boolean, projectAlreadyHasViteTargets?: TargetFlags, vitestFileName?: boolean): void;
39
41
  export declare function normalizeViteConfigFilePathWithTree(tree: Tree, projectRoot: string, configFile?: string): string;
@@ -128,8 +128,9 @@ function addBuildTarget(tree, options, target) {
128
128
  var _project;
129
129
  (0, _targetdefaultsutils.addBuildTargetDefaults)(tree, '@nx/vite:build');
130
130
  const project = (0, _devkit.readProjectConfiguration)(tree, options.project);
131
+ const isTsSolutionSetup = (0, _tssolutionsetup.isUsingTsSolutionSetup)(tree);
131
132
  const buildOptions = {
132
- outputPath: (0, _devkit.joinPathFragments)('dist', project.root != '.' ? project.root : options.project)
133
+ outputPath: isTsSolutionSetup ? (0, _devkit.joinPathFragments)(project.root, 'dist') : (0, _devkit.joinPathFragments)('dist', project.root != '.' ? project.root : options.project)
133
134
  };
134
135
  var _targets;
135
136
  (_targets = (_project = project).targets) != null ? _targets : _project.targets = {};
@@ -214,7 +215,15 @@ function addPreviewTarget(tree, options, serveTarget) {
214
215
  }
215
216
  function editTsConfig(tree, options) {
216
217
  const projectConfig = (0, _devkit.readProjectConfiguration)(tree, options.project);
217
- const config = (0, _devkit.readJson)(tree, `${projectConfig.root}/tsconfig.json`);
218
+ let tsconfigPath = (0, _devkit.joinPathFragments)(projectConfig.root, 'tsconfig.json');
219
+ const isTsSolutionSetup = (0, _tssolutionsetup.isUsingTsSolutionSetup)(tree);
220
+ if (isTsSolutionSetup) {
221
+ tsconfigPath = [
222
+ (0, _devkit.joinPathFragments)(projectConfig.root, 'tsconfig.app.json'),
223
+ (0, _devkit.joinPathFragments)(projectConfig.root, 'tsconfig.lib.json')
224
+ ].find((p)=>tree.exists(p));
225
+ }
226
+ const config = (0, _devkit.readJson)(tree, tsconfigPath);
218
227
  switch(options.uiFramework){
219
228
  case 'react':
220
229
  config.compilerOptions = {
@@ -226,20 +235,22 @@ function editTsConfig(tree, options) {
226
235
  };
227
236
  break;
228
237
  case 'none':
229
- config.compilerOptions = {
230
- module: 'commonjs',
231
- forceConsistentCasingInFileNames: true,
232
- strict: true,
233
- noImplicitOverride: true,
234
- noPropertyAccessFromIndexSignature: true,
235
- noImplicitReturns: true,
236
- noFallthroughCasesInSwitch: true
237
- };
238
+ if (!isTsSolutionSetup) {
239
+ config.compilerOptions = {
240
+ module: 'commonjs',
241
+ forceConsistentCasingInFileNames: true,
242
+ strict: true,
243
+ noImplicitOverride: true,
244
+ noPropertyAccessFromIndexSignature: true,
245
+ noImplicitReturns: true,
246
+ noFallthroughCasesInSwitch: true
247
+ };
248
+ }
238
249
  break;
239
250
  default:
240
251
  break;
241
252
  }
242
- (0, _devkit.writeJson)(tree, `${projectConfig.root}/tsconfig.json`, config);
253
+ (0, _devkit.writeJson)(tree, tsconfigPath, config);
243
254
  }
244
255
  function deleteWebpackConfig(tree, projectRoot, webpackConfigFilePath) {
245
256
  const webpackConfigPath = webpackConfigFilePath && tree.exists(webpackConfigFilePath) ? webpackConfigFilePath : tree.exists(`${projectRoot}/webpack.config.js`) ? `${projectRoot}/webpack.config.js` : tree.exists(`${projectRoot}/webpack.config.ts`) ? `${projectRoot}/webpack.config.ts` : null;
@@ -283,8 +294,9 @@ function moveAndEditIndexHtml(tree, options) {
283
294
  }
284
295
  }
285
296
  function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasViteTargets, vitestFileName) {
286
- const { root: projectRoot } = (0, _devkit.readProjectConfiguration)(tree, options.project);
287
- const viteConfigPath = vitestFileName ? `${projectRoot}/vitest.config.ts` : `${projectRoot}/vite.config.ts`;
297
+ const { root: projectRoot, projectType } = (0, _devkit.readProjectConfiguration)(tree, options.project);
298
+ const extension = options.useEsmExtension ? 'mts' : 'ts';
299
+ const viteConfigPath = vitestFileName ? `${projectRoot}/vitest.config.${extension}` : `${projectRoot}/vite.config.${extension}`;
288
300
  const isUsingTsPlugin = (0, _tssolutionsetup.isUsingTsSolutionSetup)(tree);
289
301
  const buildOutDir = isUsingTsPlugin ? './dist' : projectRoot === '.' ? `./dist/${options.project}` : `${(0, _devkit.offsetFromRoot)(projectRoot)}dist/${projectRoot}`;
290
302
  var _options_rollupOptionsExternal;
@@ -318,19 +330,19 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
318
330
  transformMixedEsModules: true,
319
331
  },
320
332
  },`;
321
- const imports = options.imports ? options.imports : [];
333
+ const imports = options.imports ? [
334
+ ...options.imports
335
+ ] : [];
336
+ const plugins = options.plugins ? [
337
+ ...options.plugins
338
+ ] : [];
322
339
  if (!onlyVitest && options.includeLib) {
323
340
  imports.push(`import dts from 'vite-plugin-dts'`, `import * as path from 'path'`);
324
341
  }
325
- let viteConfigContent = '';
326
- const plugins = options.plugins ? [
327
- ...options.plugins,
328
- `nxViteTsPaths()`,
329
- `nxCopyAssetsPlugin(['*.md'])`
330
- ] : [
331
- `nxViteTsPaths()`,
332
- `nxCopyAssetsPlugin(['*.md'])`
333
- ];
342
+ if (!isUsingTsPlugin) {
343
+ imports.push(`import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'`, `import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'`);
344
+ plugins.push(`nxViteTsPaths()`, `nxCopyAssetsPlugin(['*.md'])`);
345
+ }
334
346
  if (!onlyVitest && options.includeLib) {
335
347
  plugins.push(`dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json') })`);
336
348
  }
@@ -340,8 +352,9 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
340
352
  watch: false,
341
353
  globals: true,
342
354
  environment: '${(_options_testEnvironment = options.testEnvironment) != null ? _options_testEnvironment : 'jsdom'}',
343
- include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],${options.inSourceTests ? `
344
- includeSource: ['src/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],` : ''}
355
+ include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
356
+ ${options.setupFile ? ` setupFiles: ['${options.setupFile}'],\n` : ''}\
357
+ ${options.inSourceTests ? ` includeSource: ['src/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n` : ''}\
345
358
  reporters: ['default'],
346
359
  coverage: {
347
360
  reportsDirectory: '${reportsDirectory}',
@@ -368,11 +381,9 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
368
381
  handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, buildOutDir, imports, plugins, testOption, reportsDirectory, cacheDir, projectRoot, (0, _devkit.offsetFromRoot)(projectRoot), projectAlreadyHasViteTargets);
369
382
  return;
370
383
  }
371
- viteConfigContent = `/// <reference types='vitest' />
384
+ const viteConfigContent = `/// <reference types='vitest' />
372
385
  import { defineConfig } from 'vite';
373
386
  ${imports.join(';\n')}${imports.length ? ';' : ''}
374
- import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
375
- import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
376
387
 
377
388
  export default defineConfig({
378
389
  root: __dirname,
@@ -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 { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';\nimport { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';\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';\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 dependsOn: ['build'],\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 isUsingTsPlugin = isUsingTsSolutionSetup(tree);\n const buildOutDir = isUsingTsPlugin\n ? './dist'\n : projectRoot === '.'\n ? `./dist/${options.project}`\n : `${offsetFromRoot(projectRoot)}dist/${projectRoot}`;\n\n const buildOption = onlyVitest\n ? ''\n : options.includeLib\n ? ` // Configuration for building your library.\n // See: https://vitejs.dev/guide/build.html#library-mode\n build: {\n outDir: '${buildOutDir}',\n emptyOutDir: true,\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 : ` build: {\n outDir: '${buildOutDir}',\n emptyOutDir: true,\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\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()`, `nxCopyAssetsPlugin(['*.md'])`]\n : [`nxViteTsPaths()`, `nxCopyAssetsPlugin(['*.md'])`];\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 watch: false,\n globals: true,\n environment: '${options.testEnvironment ?? 'jsdom'}',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],${\n options.inSourceTests\n ? `\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 : ` server:{\n port: 4200,\n host: 'localhost',\n },`;\n\n const previewServerOption = onlyVitest\n ? ''\n : options.includeLib\n ? ''\n : ` preview:{\n port: 4300,\n host: 'localhost',\n },`;\n\n const workerOption = ` // 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 = `/// <reference types='vitest' />\nimport { defineConfig } from 'vite';\n${imports.join(';\\n')}${imports.length ? ';' : ''}\nimport { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\nimport { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';\n\nexport default defineConfig({\n root: __dirname,\n ${printOptions(\n cacheDir,\n devServerOption,\n previewServerOption,\n ` plugins: [${plugins.join(', ')}],`,\n workerOption,\n buildOption,\n defineOption,\n testOption\n )}\n});\n`.replace(/\\s+(?=(\\n|$))/gm, '\\n');\n\n tree.write(viteConfigPath, viteConfigContent);\n}\n\nfunction printOptions(...options: string[]): string {\n return options.filter(Boolean).join('\\n');\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 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":["addBuildTarget","addOrChangeTestTarget","addPreviewTarget","addServeTarget","createOrEditViteConfig","deleteWebpackConfig","editTsConfig","findExistingJsBuildTargetInProject","getViteConfigPathForProject","handleUnknownConfiguration","handleUnsupportedUserProvidedTargets","moveAndEditIndexHtml","normalizeViteConfigFilePathWithTree","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","dependsOn","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","isUsingTsPlugin","isUsingTsSolutionSetup","buildOutDir","buildOption","includeLib","rollupOptionsExternal","imports","push","viteConfigContent","plugins","testOption","includeVitest","testEnvironment","inSourceTests","coverageProvider","defineOption","devServerOption","previewServerOption","workerOption","cacheDir","normalizedJoinPaths","handleViteConfigFileExists","join","length","printOptions","filter","Boolean","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","environment","include","reporters","coverage","provider","changed","ensureViteConfigIsCorrect","paths","path","startsWith"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAiHgBA,cAAc;eAAdA;;IAhCAC,qBAAqB;eAArBA;;IAqGAC,gBAAgB;eAAhBA;;IArCAC,cAAc;eAAdA;;IA+MAC,sBAAsB;eAAtBA;;IA5FAC,mBAAmB;eAAnBA;;IApCAC,YAAY;eAAZA;;IAxMAC,kCAAkC;eAAlCA;;IA+gBAC,2BAA2B;eAA3BA;;IAwFMC,0BAA0B;eAA1BA;;IAnEAC,oCAAoC;eAApCA;;IAtSNC,oBAAoB;eAApBA;;IAmQAC,mCAAmC;eAAnCA;;;wBA/gBT;qCACgC;iCACA;qCAKG;AAOnC,SAASL,mCAAmCM,OAElD;IAIC,MAAMC,SAGF,CAAC;IAEL,MAAMC,qBAAqB;QACzBC,OAAO;YAAC;YAAgB;YAAc;SAAoB;IAC5D;IACA,MAAMC,uB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ACAoD,mBACAjD,SACAG,SACAC,YACAwD,kBACA/C,UACAtB,uCAAAA,+BAAgC,CAAC;IAGnC,IAAI,CAAC4E,SAAS;QACZlC,cAAM,CAACC,IAAI,CACT,CAAC,wEAAwE,EAAEzC,eAAe;;QAExF,EAAEI,YAAY;;QAEd,CAAC;IAEP;AACF;AAEA,SAASiB,oBAAoB,GAAGuD,KAAe;IAC7C,MAAMC,OAAOpI,IAAAA,yBAAiB,KAAImI;IAElC,OAAOC,KAAKC,UAAU,CAAC,OAAOD,OAAO,CAAC,EAAE,EAAEA,KAAK,CAAC;AAClD"}
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 { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';\nimport { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';\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';\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\n const isTsSolutionSetup = isUsingTsSolutionSetup(tree);\n const buildOptions: ViteBuildExecutorOptions = {\n outputPath: isTsSolutionSetup\n ? joinPathFragments(project.root, 'dist')\n : 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 dependsOn: ['build'],\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 let tsconfigPath = joinPathFragments(projectConfig.root, 'tsconfig.json');\n const isTsSolutionSetup = isUsingTsSolutionSetup(tree);\n if (isTsSolutionSetup) {\n tsconfigPath = [\n joinPathFragments(projectConfig.root, 'tsconfig.app.json'),\n joinPathFragments(projectConfig.root, 'tsconfig.lib.json'),\n ].find((p) => tree.exists(p));\n }\n const config = readJson(tree, tsconfigPath);\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 if (!isTsSolutionSetup) {\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 }\n break;\n default:\n break;\n }\n\n writeJson(tree, tsconfigPath, 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 setupFile?: string;\n useEsmExtension?: boolean;\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, projectType } = readProjectConfiguration(\n tree,\n options.project\n );\n\n const extension = options.useEsmExtension ? 'mts' : 'ts';\n const viteConfigPath = vitestFileName\n ? `${projectRoot}/vitest.config.${extension}`\n : `${projectRoot}/vite.config.${extension}`;\n\n const isUsingTsPlugin = isUsingTsSolutionSetup(tree);\n const buildOutDir = isUsingTsPlugin\n ? './dist'\n : projectRoot === '.'\n ? `./dist/${options.project}`\n : `${offsetFromRoot(projectRoot)}dist/${projectRoot}`;\n\n const buildOption = onlyVitest\n ? ''\n : options.includeLib\n ? ` // Configuration for building your library.\n // See: https://vitejs.dev/guide/build.html#library-mode\n build: {\n outDir: '${buildOutDir}',\n emptyOutDir: true,\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 : ` build: {\n outDir: '${buildOutDir}',\n emptyOutDir: true,\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n },`;\n\n const imports: string[] = options.imports ? [...options.imports] : [];\n const plugins: string[] = options.plugins ? [...options.plugins] : [];\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 if (!isUsingTsPlugin) {\n imports.push(\n `import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'`,\n `import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'`\n );\n plugins.push(`nxViteTsPaths()`, `nxCopyAssetsPlugin(['*.md'])`);\n }\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 watch: false,\n globals: true,\n environment: '${options.testEnvironment ?? 'jsdom'}',\n include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\n${options.setupFile ? ` setupFiles: ['${options.setupFile}'],\\n` : ''}\\\n${\n options.inSourceTests\n ? ` includeSource: ['src/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],\\n`\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 : ` server:{\n port: 4200,\n host: 'localhost',\n },`;\n\n const previewServerOption = onlyVitest\n ? ''\n : options.includeLib\n ? ''\n : ` preview:{\n port: 4300,\n host: 'localhost',\n },`;\n\n const workerOption = ` // 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 const viteConfigContent = `/// <reference types='vitest' />\nimport { defineConfig } from 'vite';\n${imports.join(';\\n')}${imports.length ? ';' : ''}\n\nexport default defineConfig({\n root: __dirname,\n ${printOptions(\n cacheDir,\n devServerOption,\n previewServerOption,\n ` plugins: [${plugins.join(', ')}],`,\n workerOption,\n buildOption,\n defineOption,\n testOption\n )}\n});\n`.replace(/\\s+(?=(\\n|$))/gm, '\\n');\n\n tree.write(viteConfigPath, viteConfigContent);\n}\n\nfunction printOptions(...options: string[]): string {\n return options.filter(Boolean).join('\\n');\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 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":["addBuildTarget","addOrChangeTestTarget","addPreviewTarget","addServeTarget","createOrEditViteConfig","deleteWebpackConfig","editTsConfig","findExistingJsBuildTargetInProject","getViteConfigPathForProject","handleUnknownConfiguration","handleUnsupportedUserProvidedTargets","moveAndEditIndexHtml","normalizeViteConfigFilePathWithTree","targets","output","supportedExecutors","build","unsupportedExecutors","target","executorName","executor","includes","supported","unsupported","tree","options","project","readProjectConfiguration","reportsDirectory","joinPathFragments","offsetFromRoot","root","testOptions","jestConfig","outputs","updateProjectConfiguration","addBuildTargetDefaults","isTsSolutionSetup","isUsingTsSolutionSetup","buildOptions","outputPath","defaultConfiguration","configurations","development","mode","production","buildTarget","hmr","serveTarget","previewOptions","proxyConfig","https","open","preview","dependsOn","projectConfig","tsconfigPath","find","p","exists","config","readJson","uiFramework","compilerOptions","jsx","allowJs","esModuleInterop","allowSyntheticDefaultImports","strict","module","forceConsistentCasingInFileNames","noImplicitOverride","noPropertyAccessFromIndexSignature","noImplicitReturns","noFallthroughCasesInSwitch","writeJson","projectRoot","webpackConfigFilePath","webpackConfigPath","delete","indexHtmlPath","mainPath","replace","indexHtmlContent","read","write","onlyVitest","projectAlreadyHasViteTargets","vitestFileName","projectType","extension","useEsmExtension","viteConfigPath","isUsingTsPlugin","buildOutDir","buildOption","includeLib","rollupOptionsExternal","imports","plugins","push","testOption","includeVitest","testEnvironment","setupFile","inSourceTests","coverageProvider","defineOption","devServerOption","previewServerOption","workerOption","cacheDir","normalizedJoinPaths","handleViteConfigFileExists","viteConfigContent","join","length","printOptions","filter","Boolean","configFile","undefined","projectName","Object","values","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","environment","include","reporters","coverage","provider","changed","ensureViteConfigIsCorrect","paths","path","startsWith"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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Q8E,eAAe,YAAvB9E,2BAA2B;QACxCwI,SAAS;YAAC;SAAuD;QACjEC,WAAW;YAAC;SAAU;QACtBC,UAAU;YACRvI,kBAAkBA;YAClBwI,UAAU,CAAC,EAAE3I,CAAAA,4BAAAA,QAAQiF,gBAAgB,YAAxBjF,4BAA4B,KAAK,CAAC;QACjD;IACF;IAEA,MAAM4I,UAAUC,IAAAA,8CAAyB,EACvC9I,MACAoE,gBACAG,aACAoD,mBACAjD,SACAC,SACAE,YACAyD,kBACA/C,UACAxB,uCAAAA,+BAAgC,CAAC;IAGnC,IAAI,CAAC8E,SAAS;QACZlC,cAAM,CAACC,IAAI,CACT,CAAC,wEAAwE,EAAExC,eAAe;;QAExF,EAAEG,YAAY;;QAEd,CAAC;IAEP;AACF;AAEA,SAASiB,oBAAoB,GAAGuD,KAAe;IAC7C,MAAMC,OAAO3I,IAAAA,yBAAiB,KAAI0I;IAElC,OAAOC,KAAKC,UAAU,CAAC,OAAOD,OAAO,CAAC,EAAE,EAAEA,KAAK,CAAC;AAClD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/vite/src/utils/versions.ts"],"sourcesContent":["export const nxVersion = require('../../package.json').version;\nexport const viteVersion = '^5.0.0';\nexport const vitestVersion = '^1.3.1';\nexport const vitePluginReactVersion = '^4.2.0';\nexport const vitePluginReactSwcVersion = '^3.5.0';\nexport const jsdomVersion = '~22.1.0';\nexport const vitePluginDtsVersion = '~3.8.1';\nexport const happyDomVersion = '~9.20.3';\nexport const edgeRuntimeVmVersion = '~3.0.2';\n\n// Coverage providers\nexport const vitestCoverageV8Version = '^1.0.4';\nexport const vitestCoverageIstanbulVersion = '^1.0.4';\n"],"names":["edgeRuntimeVmVersion","happyDomVersion","jsdomVersion","nxVersion","vitePluginDtsVersion","vitePluginReactSwcVersion","vitePluginReactVersion","viteVersion","vitestCoverageIstanbulVersion","vitestCoverageV8Version","vitestVersion","require","version"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAQaA,oBAAoB;eAApBA;;IADAC,eAAe;eAAfA;;IAFAC,YAAY;eAAZA;;IALAC,SAAS;eAATA;;IAMAC,oBAAoB;eAApBA;;IAFAC,yBAAyB;eAAzBA;;IADAC,sBAAsB;eAAtBA;;IAFAC,WAAW;eAAXA;;IAWAC,6BAA6B;eAA7BA;;IADAC,uBAAuB;eAAvBA;;IATAC,aAAa;eAAbA;;;AAFN,MAAMP,YAAYQ,QAAQ,sBAAsBC,OAAO;AACvD,MAAML,cAAc;AACpB,MAAMG,gBAAgB;AACtB,MAAMJ,yBAAyB;AAC/B,MAAMD,4BAA4B;AAClC,MAAMH,eAAe;AACrB,MAAME,uBAAuB;AAC7B,MAAMH,kBAAkB;AACxB,MAAMD,uBAAuB;AAG7B,MAAMS,0BAA0B;AAChC,MAAMD,gCAAgC"}
1
+ {"version":3,"sources":["../../../../../packages/vite/src/utils/versions.ts"],"sourcesContent":["export const nxVersion = require('../../package.json').version;\n// Also update @nx/remix/utils/versions when changing vite version\nexport const viteVersion = '^5.0.0';\nexport const vitestVersion = '^1.3.1';\nexport const vitePluginReactVersion = '^4.2.0';\nexport const vitePluginReactSwcVersion = '^3.5.0';\nexport const jsdomVersion = '~22.1.0';\nexport const vitePluginDtsVersion = '~3.8.1';\nexport const happyDomVersion = '~9.20.3';\nexport const edgeRuntimeVmVersion = '~3.0.2';\n\n// Coverage providers\nexport const vitestCoverageV8Version = '^1.0.4';\nexport const vitestCoverageIstanbulVersion = '^1.0.4';\n"],"names":["edgeRuntimeVmVersion","happyDomVersion","jsdomVersion","nxVersion","vitePluginDtsVersion","vitePluginReactSwcVersion","vitePluginReactVersion","viteVersion","vitestCoverageIstanbulVersion","vitestCoverageV8Version","vitestVersion","require","version"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IASaA,oBAAoB;eAApBA;;IADAC,eAAe;eAAfA;;IAFAC,YAAY;eAAZA;;IANAC,SAAS;eAATA;;IAOAC,oBAAoB;eAApBA;;IAFAC,yBAAyB;eAAzBA;;IADAC,sBAAsB;eAAtBA;;IAFAC,WAAW;eAAXA;;IAWAC,6BAA6B;eAA7BA;;IADAC,uBAAuB;eAAvBA;;IATAC,aAAa;eAAbA;;;AAHN,MAAMP,YAAYQ,QAAQ,sBAAsBC,OAAO;AAEvD,MAAML,cAAc;AACpB,MAAMG,gBAAgB;AACtB,MAAMJ,yBAAyB;AAC/B,MAAMD,4BAA4B;AAClC,MAAMH,eAAe;AACrB,MAAME,uBAAuB;AAC7B,MAAMH,kBAAkB;AACxB,MAAMD,uBAAuB;AAG7B,MAAMS,0BAA0B;AAChC,MAAMD,gCAAgC"}