@nx/vite 16.9.0-beta.1 → 16.9.0-beta.3

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": "16.9.0-beta.1",
3
+ "version": "16.9.0-beta.3",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for building and testing applications using Vite",
6
6
  "repository": {
@@ -29,9 +29,9 @@
29
29
  "migrations": "./migrations.json"
30
30
  },
31
31
  "dependencies": {
32
- "@nrwl/vite": "16.9.0-beta.1",
33
- "@nx/devkit": "16.9.0-beta.1",
34
- "@nx/js": "16.9.0-beta.1",
32
+ "@nrwl/vite": "16.9.0-beta.3",
33
+ "@nx/devkit": "16.9.0-beta.3",
34
+ "@nx/js": "16.9.0-beta.3",
35
35
  "@phenomnomnominal/tsquery": "~5.0.1",
36
36
  "@swc/helpers": "~0.5.0",
37
37
  "enquirer": "~2.3.6",
@@ -57,5 +57,5 @@
57
57
  "./plugins/nx-tsconfig-paths.plugin": "./plugins/nx-tsconfig-paths.plugin.js"
58
58
  },
59
59
  "type": "commonjs",
60
- "gitHead": "5056d6cefb2949ba865019e8b71e633fba28c091"
60
+ "gitHead": "d5692528c089a75c76b21d2d1235d8cc5dbb1d26"
61
61
  }
@@ -19,7 +19,7 @@ const _vite = require("vite");
19
19
  const _optionsutils = require("../../utils/options-utils");
20
20
  async function* vitePreviewServerExecutor(options, context) {
21
21
  var _context_projectsConfigurations_projects_target_project;
22
- const target = (0, _devkit.parseTargetString)(options.buildTarget, context.projectGraph);
22
+ const target = (0, _devkit.parseTargetString)(options.buildTarget, context);
23
23
  const targetConfiguration = (_context_projectsConfigurations_projects_target_project = context.projectsConfigurations.projects[target.project]) == null ? void 0 : _context_projectsConfigurations_projects_target_project.targets[target.target];
24
24
  if (!targetConfiguration) {
25
25
  throw new Error(`Invalid buildTarget: ${options.buildTarget}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/vite/src/executors/preview-server/preview-server.impl.ts"],"sourcesContent":["import { ExecutorContext, parseTargetString, runExecutor } from '@nx/devkit';\nimport { InlineConfig, mergeConfig, preview, PreviewServer } from 'vite';\nimport {\n getNxTargetOptions,\n getViteSharedConfig,\n getViteBuildOptions,\n getVitePreviewOptions,\n} from '../../utils/options-utils';\nimport { ViteBuildExecutorOptions } from '../build/schema';\nimport { VitePreviewServerExecutorOptions } from './schema';\n\ninterface CustomBuildTargetOptions {\n outputPath: string;\n}\n\nexport async function* vitePreviewServerExecutor(\n options: VitePreviewServerExecutorOptions,\n context: ExecutorContext\n) {\n const target = parseTargetString(options.buildTarget, context.projectGraph);\n const targetConfiguration =\n context.projectsConfigurations.projects[target.project]?.targets[\n target.target\n ];\n if (!targetConfiguration) {\n throw new Error(`Invalid buildTarget: ${options.buildTarget}`);\n }\n\n const isCustomBuildTarget =\n targetConfiguration.executor !== '@nx/vite:build' &&\n targetConfiguration.executor !== '@nrwl/vite:build';\n\n // Retrieve the option for the configured buildTarget.\n const buildTargetOptions:\n | ViteBuildExecutorOptions\n | CustomBuildTargetOptions = getNxTargetOptions(\n options.buildTarget,\n context\n );\n\n const outputPath = options.staticFilePath ?? buildTargetOptions.outputPath;\n\n if (!outputPath) {\n throw new Error(\n `Could not infer the \"outputPath\". It should either be a property of the \"${options.buildTarget}\" buildTarget or provided explicitly as a \"staticFilePath\" option.`\n );\n }\n\n // Merge the options from the build and preview-serve targets.\n // The latter takes precedence.\n const mergedOptions = {\n ...{ watch: {} },\n ...(isCustomBuildTarget ? {} : buildTargetOptions),\n ...options,\n outputPath,\n };\n\n // Retrieve the server configuration.\n const serverConfig: InlineConfig = mergeConfig(\n getViteSharedConfig(mergedOptions, options.clearScreen, context),\n {\n build: getViteBuildOptions(mergedOptions, context),\n preview: getVitePreviewOptions(mergedOptions, context),\n }\n );\n\n if (serverConfig.mode === 'production') {\n console.warn('WARNING: preview is not meant to be run in production!');\n }\n\n let server: PreviewServer | undefined;\n\n const processOnExit = async () => {\n await closeServer(server);\n };\n\n process.once('SIGINT', processOnExit);\n process.once('SIGTERM', processOnExit);\n process.once('exit', processOnExit);\n\n // Launch the build target.\n // If customBuildTarget is set to true, do not provide any overrides to it\n const buildTargetOverrides = isCustomBuildTarget ? {} : mergedOptions;\n const build = await runExecutor(target, buildTargetOverrides, context);\n\n for await (const result of build) {\n if (result.success) {\n try {\n if (!server) {\n server = await preview(serverConfig);\n }\n server.printUrls();\n\n const resolvedUrls = [\n ...server.resolvedUrls.local,\n ...server.resolvedUrls.network,\n ];\n\n yield {\n success: true,\n baseUrl: resolvedUrls[0] ?? '',\n };\n } catch (e) {\n console.error(e);\n yield {\n success: false,\n baseUrl: '',\n };\n }\n } else {\n yield {\n success: false,\n baseUrl: '',\n };\n }\n }\n\n await new Promise<void>((resolve) => {\n process.once('SIGINT', () => resolve());\n process.once('SIGTERM', () => resolve());\n process.once('exit', () => resolve());\n });\n}\n\nfunction closeServer(server?: PreviewServer): Promise<void> {\n return new Promise((resolve) => {\n if (!server) {\n resolve();\n } else {\n const { httpServer } = server;\n // closeAllConnections was added in Node v18.2.0\n httpServer.closeAllConnections && httpServer.closeAllConnections();\n httpServer.close(() => resolve());\n }\n });\n}\n\nexport default vitePreviewServerExecutor;\n"],"names":["vitePreviewServerExecutor","options","context","target","parseTargetString","buildTarget","projectGraph","targetConfiguration","projectsConfigurations","projects","project","targets","Error","isCustomBuildTarget","executor","buildTargetOptions","getNxTargetOptions","outputPath","staticFilePath","mergedOptions","watch","serverConfig","mergeConfig","getViteSharedConfig","clearScreen","build","getViteBuildOptions","preview","getVitePreviewOptions","mode","console","warn","server","processOnExit","closeServer","process","once","buildTargetOverrides","runExecutor","result","success","printUrls","resolvedUrls","local","network","baseUrl","e","error","Promise","resolve","httpServer","closeAllConnections","close"],"mappings":";;;;;;;;IAeuBA,yBAAyB;eAAzBA;;IA0HvB,OAAyC;eAAzC;;;;wBAzIgE;sBACE;8BAM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AAWC,mBAAmB,IAAID,WAAWC,mBAAmB;YAChED,WAAWE,KAAK,CAAC,IAAMH;QACzB,CAAC;IACH;AACF;MAEA,WAAejD"}
1
+ {"version":3,"sources":["../../../../../../packages/vite/src/executors/preview-server/preview-server.impl.ts"],"sourcesContent":["import { ExecutorContext, parseTargetString, runExecutor } from '@nx/devkit';\nimport { InlineConfig, mergeConfig, preview, PreviewServer } from 'vite';\nimport {\n getNxTargetOptions,\n getViteSharedConfig,\n getViteBuildOptions,\n getVitePreviewOptions,\n} from '../../utils/options-utils';\nimport { ViteBuildExecutorOptions } from '../build/schema';\nimport { VitePreviewServerExecutorOptions } from './schema';\n\ninterface CustomBuildTargetOptions {\n outputPath: string;\n}\n\nexport async function* vitePreviewServerExecutor(\n options: VitePreviewServerExecutorOptions,\n context: ExecutorContext\n) {\n const target = parseTargetString(options.buildTarget, context);\n const targetConfiguration =\n context.projectsConfigurations.projects[target.project]?.targets[\n target.target\n ];\n if (!targetConfiguration) {\n throw new Error(`Invalid buildTarget: ${options.buildTarget}`);\n }\n\n const isCustomBuildTarget =\n targetConfiguration.executor !== '@nx/vite:build' &&\n targetConfiguration.executor !== '@nrwl/vite:build';\n\n // Retrieve the option for the configured buildTarget.\n const buildTargetOptions:\n | ViteBuildExecutorOptions\n | CustomBuildTargetOptions = getNxTargetOptions(\n options.buildTarget,\n context\n );\n\n const outputPath = options.staticFilePath ?? buildTargetOptions.outputPath;\n\n if (!outputPath) {\n throw new Error(\n `Could not infer the \"outputPath\". It should either be a property of the \"${options.buildTarget}\" buildTarget or provided explicitly as a \"staticFilePath\" option.`\n );\n }\n\n // Merge the options from the build and preview-serve targets.\n // The latter takes precedence.\n const mergedOptions = {\n ...{ watch: {} },\n ...(isCustomBuildTarget ? {} : buildTargetOptions),\n ...options,\n outputPath,\n };\n\n // Retrieve the server configuration.\n const serverConfig: InlineConfig = mergeConfig(\n getViteSharedConfig(mergedOptions, options.clearScreen, context),\n {\n build: getViteBuildOptions(mergedOptions, context),\n preview: getVitePreviewOptions(mergedOptions, context),\n }\n );\n\n if (serverConfig.mode === 'production') {\n console.warn('WARNING: preview is not meant to be run in production!');\n }\n\n let server: PreviewServer | undefined;\n\n const processOnExit = async () => {\n await closeServer(server);\n };\n\n process.once('SIGINT', processOnExit);\n process.once('SIGTERM', processOnExit);\n process.once('exit', processOnExit);\n\n // Launch the build target.\n // If customBuildTarget is set to true, do not provide any overrides to it\n const buildTargetOverrides = isCustomBuildTarget ? {} : mergedOptions;\n const build = await runExecutor(target, buildTargetOverrides, context);\n\n for await (const result of build) {\n if (result.success) {\n try {\n if (!server) {\n server = await preview(serverConfig);\n }\n server.printUrls();\n\n const resolvedUrls = [\n ...server.resolvedUrls.local,\n ...server.resolvedUrls.network,\n ];\n\n yield {\n success: true,\n baseUrl: resolvedUrls[0] ?? '',\n };\n } catch (e) {\n console.error(e);\n yield {\n success: false,\n baseUrl: '',\n };\n }\n } else {\n yield {\n success: false,\n baseUrl: '',\n };\n }\n }\n\n await new Promise<void>((resolve) => {\n process.once('SIGINT', () => resolve());\n process.once('SIGTERM', () => resolve());\n process.once('exit', () => resolve());\n });\n}\n\nfunction closeServer(server?: PreviewServer): Promise<void> {\n return new Promise((resolve) => {\n if (!server) {\n resolve();\n } else {\n const { httpServer } = server;\n // closeAllConnections was added in Node v18.2.0\n httpServer.closeAllConnections && httpServer.closeAllConnections();\n httpServer.close(() => resolve());\n }\n });\n}\n\nexport default vitePreviewServerExecutor;\n"],"names":["vitePreviewServerExecutor","options","context","target","parseTargetString","buildTarget","targetConfiguration","projectsConfigurations","projects","project","targets","Error","isCustomBuildTarget","executor","buildTargetOptions","getNxTargetOptions","outputPath","staticFilePath","mergedOptions","watch","serverConfig","mergeConfig","getViteSharedConfig","clearScreen","build","getViteBuildOptions","preview","getVitePreviewOptions","mode","console","warn","server","processOnExit","closeServer","process","once","buildTargetOverrides","runExecutor","result","success","printUrls","resolvedUrls","local","network","baseUrl","e","error","Promise","resolve","httpServer","closeAllConnections","close"],"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ACF,OAAO;YACL,MAAM,EAAEC,WAAU,EAAE,GAAGlB;YACvB,gDAAgD;YAChDkB,WAAWC,mBAAmB,IAAID,WAAWC,mBAAmB;YAChED,WAAWE,KAAK,CAAC,IAAMH;QACzB,CAAC;IACH;AACF;MAEA,WAAehD"}
@@ -141,7 +141,28 @@ async function viteConfigurationGenerator(tree, schema) {
141
141
  return json;
142
142
  });
143
143
  }
144
- (0, _generatorutils.createOrEditViteConfig)(tree, schema, false, projectAlreadyHasViteTargets);
144
+ if (schema.uiFramework === 'react') {
145
+ (0, _generatorutils.createOrEditViteConfig)(tree, {
146
+ project: schema.project,
147
+ includeLib: schema.includeLib,
148
+ includeVitest: schema.includeVitest,
149
+ inSourceTests: schema.inSourceTests,
150
+ rollupOptionsExternal: [
151
+ `'react'`,
152
+ `'react-dom'`,
153
+ `'react/jsx-runtime'`
154
+ ],
155
+ rollupOptionsExternalString: `"'react', 'react-dom', 'react/jsx-runtime'"`,
156
+ imports: [
157
+ schema.compiler === 'swc' ? `import react from '@vitejs/plugin-react-swc'` : `import react from '@vitejs/plugin-react'`
158
+ ],
159
+ plugins: [
160
+ 'react()'
161
+ ]
162
+ }, false);
163
+ } else {
164
+ (0, _generatorutils.createOrEditViteConfig)(tree, schema, false, projectAlreadyHasViteTargets);
165
+ }
145
166
  if (schema.includeVitest) {
146
167
  const vitestTask = await (0, _vitestgenerator.default)(tree, {
147
168
  project: schema.project,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/vite/src/generators/configuration/configuration.ts"],"sourcesContent":["import {\n convertNxGenerator,\n formatFiles,\n GeneratorCallback,\n joinPathFragments,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\n\nimport {\n addOrChangeBuildTarget,\n addOrChangeServeTarget,\n addPreviewTarget,\n createOrEditViteConfig,\n deleteWebpackConfig,\n editTsConfig,\n findExistingTargetsInProject,\n handleUnknownExecutors,\n handleUnsupportedUserProvidedTargets,\n moveAndEditIndexHtml,\n TargetFlags,\n UserProvidedTargetName,\n} from '../../utils/generator-utils';\n\nimport initGenerator from '../init/init';\nimport vitestGenerator from '../vitest/vitest-generator';\nimport { ViteConfigurationGeneratorSchema } from './schema';\n\nexport async function viteConfigurationGenerator(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const { targets, projectType, root } = readProjectConfiguration(\n tree,\n schema.project\n );\n let buildTargetName = 'build';\n let serveTargetName = 'serve';\n let testTargetName = 'test';\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 const userProvidedTargetName: UserProvidedTargetName = {\n build: schema.buildTarget,\n serve: schema.serveTarget,\n test: schema.testTarget,\n };\n\n const {\n validFoundTargetName,\n projectContainsUnsupportedExecutor,\n userProvidedTargetIsUnsupported,\n alreadyHasNxViteTargets,\n } = findExistingTargetsInProject(targets, userProvidedTargetName);\n projectAlreadyHasViteTargets = alreadyHasNxViteTargets;\n /**\n * This means that we only found unsupported build targets in that project.\n * The only way that buildTarget is defined, means that it is supported.\n *\n * If the `unsupported` flag was false, it would mean that we did not find\n * a build target at all, so we can create a new one.\n *\n * So we only throw if we found a target, but it is unsupported.\n */\n if (!validFoundTargetName.build && projectContainsUnsupportedExecutor) {\n throw new Error(\n `The project ${schema.project} cannot be converted to use the @nx/vite executors.`\n );\n }\n\n if (\n alreadyHasNxViteTargets.build &&\n (alreadyHasNxViteTargets.serve || projectType === 'library') &&\n alreadyHasNxViteTargets.test\n ) {\n throw new Error(\n `The project ${schema.project} is already configured to use the @nx/vite executors.\n Please try a different project, or remove the existing targets \n and re-run this generator to reset the existing Vite Configuration.\n `\n );\n }\n\n /**\n * This means that we did not find any supported executors\n * so we don't have any valid target names.\n *\n * However, the executors that we may have found are not in the\n * list of the specifically unsupported executors either.\n *\n * So, we should warn the user about it.\n */\n\n if (\n !projectContainsUnsupportedExecutor &&\n !validFoundTargetName.build &&\n !validFoundTargetName.serve &&\n !validFoundTargetName.test\n ) {\n await handleUnknownExecutors(schema.project);\n }\n\n /**\n * There is a possibility at this stage that the user has provided\n * targets with unsupported executors.\n * We keep track here of which of the targets that the user provided\n * are unsupported.\n * We do this with the `userProvidedTargetIsUnsupported` object,\n * which contains flags for each target (whether it is supported or not).\n *\n * We also keep track of the targets that we found in the project,\n * through the findExistingTargetsInProject function, which returns\n * targets for build/serve/test that use supported executors, and\n * can be converted to use the vite executors. These are the\n * kept in the validFoundTargetName object.\n */\n await handleUnsupportedUserProvidedTargets(\n userProvidedTargetIsUnsupported,\n userProvidedTargetName,\n validFoundTargetName\n );\n\n /**\n * Once the user is at this stage, then they can go ahead and convert.\n */\n\n buildTargetName = validFoundTargetName.build ?? buildTargetName;\n serveTargetName = validFoundTargetName.serve ?? serveTargetName;\n\n if (projectType === 'application') {\n moveAndEditIndexHtml(tree, schema, buildTargetName);\n }\n\n deleteWebpackConfig(\n tree,\n root,\n targets?.[buildTargetName]?.options?.webpackConfig\n );\n\n editTsConfig(tree, schema);\n }\n\n const initTask = await initGenerator(tree, {\n uiFramework: schema.uiFramework,\n includeLib: schema.includeLib,\n compiler: schema.compiler,\n testEnvironment: schema.testEnvironment,\n });\n tasks.push(initTask);\n\n if (!projectAlreadyHasViteTargets.build) {\n addOrChangeBuildTarget(tree, schema, buildTargetName);\n }\n\n if (!schema.includeLib) {\n if (!projectAlreadyHasViteTargets.serve) {\n addOrChangeServeTarget(tree, schema, serveTargetName);\n }\n if (!projectAlreadyHasViteTargets.preview) {\n addPreviewTarget(tree, schema, serveTargetName);\n }\n }\n\n if (projectType === 'library') {\n // update tsconfig.lib.json to include vite/client\n updateJson(tree, joinPathFragments(root, 'tsconfig.lib.json'), (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 createOrEditViteConfig(tree, schema, false, projectAlreadyHasViteTargets);\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: 'c8',\n skipViteConfig: true,\n testTarget: testTargetName,\n skipFormat: true,\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;\nexport const configurationSchematic = convertNxGenerator(\n viteConfigurationGenerator\n);\n"],"names":["viteConfigurationGenerator","configurationSchematic","tree","schema","tasks","targets","projectType","root","readProjectConfiguration","project","buildTargetName","serveTargetName","testTargetName","includeLib","testEnvironment","projectAlreadyHasViteTargets","newProject","userProvidedTargetName","build","buildTarget","serve","serveTarget","test","testTarget","validFoundTargetName","projectContainsUnsupportedExecutor","userProvidedTargetIsUnsupported","alreadyHasNxViteTargets","findExistingTargetsInProject","Error","handleUnknownExecutors","handleUnsupportedUserProvidedTargets","moveAndEditIndexHtml","deleteWebpackConfig","options","webpackConfig","editTsConfig","initTask","initGenerator","uiFramework","compiler","push","addOrChangeBuildTarget","addOrChangeServeTarget","preview","addPreviewTarget","updateJson","joinPathFragments","json","compilerOptions","types","includes","createOrEditViteConfig","includeVitest","vitestTask","vitestGenerator","inSourceTests","coverageProvider","skipViteConfig","skipFormat","formatFiles","runTasksInSerial","convertNxGenerator"],"mappings":";;;;;;;;IA8BsBA,0BAA0B;eAA1BA;;IAgMtB,OAA0C;eAA1C;;IACaC,sBAAsB;eAAtBA;;;;wBAtNN;gCAeA;sBAEmB;iCACE;AAGrB,eAA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L,gBAAgB,WAAW;QAC7B,kDAAkD;QAClDwC,IAAAA,kBAAU,EAAC5C,MAAM6C,IAAAA,yBAAiB,EAACxC,MAAM,sBAAsB,CAACyC,OAAS;YACvE,IAAI,CAACA,KAAKC,eAAe,EAAE;gBACzBD,KAAKC,eAAe,GAAG,CAAC;YAC1B,CAAC;YACD,IAAI,CAACD,KAAKC,eAAe,CAACC,KAAK,EAAE;gBAC/BF,KAAKC,eAAe,CAACC,KAAK,GAAG,EAAE;YACjC,CAAC;YACD,IAAI,CAACF,KAAKC,eAAe,CAACC,KAAK,CAACC,QAAQ,CAAC,gBAAgB;gBACvD,OAAO,eACFH;oBACHC,iBAAiB,eACZD,KAAKC,eAAe;wBACvBC,OAAO;+BAAIF,KAAKC,eAAe,CAACC,KAAK;4BAAE;yBAAc;;;YAG3D,CAAC;YACD,OAAOF;QACT;IACF,CAAC;IAEDI,IAAAA,sCAAsB,EAAClD,MAAMC,QAAQ,KAAK,EAAEY;IAE5C,IAAIZ,OAAOkD,aAAa,EAAE;QACxB,MAAMC,aAAa,MAAMC,IAAAA,wBAAe,EAACrD,MAAM;YAC7CO,SAASN,OAAOM,OAAO;YACvB8B,aAAapC,OAAOoC,WAAW;YAC/BiB,eAAerD,OAAOqD,aAAa;YACnCC,kBAAkB;YAClBC,gBAAgB,IAAI;YACpBnC,YAAYX;YACZ+C,YAAY,IAAI;QAClB;QACAvD,MAAMqC,IAAI,CAACa;IACb,CAAC;IAED,IAAI,CAACnD,OAAOwD,UAAU,EAAE;QACtB,MAAMC,IAAAA,mBAAW,EAAC1D;IACpB,CAAC;IAED,OAAO2D,IAAAA,wBAAgB,KAAIzD;AAC7B;MAEA,WAAeJ;AACR,MAAMC,yBAAyB6D,IAAAA,0BAAkB,EACtD9D"}
1
+ {"version":3,"sources":["../../../../../../packages/vite/src/generators/configuration/configuration.ts"],"sourcesContent":["import {\n convertNxGenerator,\n formatFiles,\n GeneratorCallback,\n joinPathFragments,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\n\nimport {\n addOrChangeBuildTarget,\n addOrChangeServeTarget,\n addPreviewTarget,\n createOrEditViteConfig,\n deleteWebpackConfig,\n editTsConfig,\n findExistingTargetsInProject,\n handleUnknownExecutors,\n handleUnsupportedUserProvidedTargets,\n moveAndEditIndexHtml,\n TargetFlags,\n UserProvidedTargetName,\n} from '../../utils/generator-utils';\n\nimport initGenerator from '../init/init';\nimport vitestGenerator from '../vitest/vitest-generator';\nimport { ViteConfigurationGeneratorSchema } from './schema';\n\nexport async function viteConfigurationGenerator(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const { targets, projectType, root } = readProjectConfiguration(\n tree,\n schema.project\n );\n let buildTargetName = 'build';\n let serveTargetName = 'serve';\n let testTargetName = 'test';\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 const userProvidedTargetName: UserProvidedTargetName = {\n build: schema.buildTarget,\n serve: schema.serveTarget,\n test: schema.testTarget,\n };\n\n const {\n validFoundTargetName,\n projectContainsUnsupportedExecutor,\n userProvidedTargetIsUnsupported,\n alreadyHasNxViteTargets,\n } = findExistingTargetsInProject(targets, userProvidedTargetName);\n projectAlreadyHasViteTargets = alreadyHasNxViteTargets;\n /**\n * This means that we only found unsupported build targets in that project.\n * The only way that buildTarget is defined, means that it is supported.\n *\n * If the `unsupported` flag was false, it would mean that we did not find\n * a build target at all, so we can create a new one.\n *\n * So we only throw if we found a target, but it is unsupported.\n */\n if (!validFoundTargetName.build && projectContainsUnsupportedExecutor) {\n throw new Error(\n `The project ${schema.project} cannot be converted to use the @nx/vite executors.`\n );\n }\n\n if (\n alreadyHasNxViteTargets.build &&\n (alreadyHasNxViteTargets.serve || projectType === 'library') &&\n alreadyHasNxViteTargets.test\n ) {\n throw new Error(\n `The project ${schema.project} is already configured to use the @nx/vite executors.\n Please try a different project, or remove the existing targets \n and re-run this generator to reset the existing Vite Configuration.\n `\n );\n }\n\n /**\n * This means that we did not find any supported executors\n * so we don't have any valid target names.\n *\n * However, the executors that we may have found are not in the\n * list of the specifically unsupported executors either.\n *\n * So, we should warn the user about it.\n */\n\n if (\n !projectContainsUnsupportedExecutor &&\n !validFoundTargetName.build &&\n !validFoundTargetName.serve &&\n !validFoundTargetName.test\n ) {\n await handleUnknownExecutors(schema.project);\n }\n\n /**\n * There is a possibility at this stage that the user has provided\n * targets with unsupported executors.\n * We keep track here of which of the targets that the user provided\n * are unsupported.\n * We do this with the `userProvidedTargetIsUnsupported` object,\n * which contains flags for each target (whether it is supported or not).\n *\n * We also keep track of the targets that we found in the project,\n * through the findExistingTargetsInProject function, which returns\n * targets for build/serve/test that use supported executors, and\n * can be converted to use the vite executors. These are the\n * kept in the validFoundTargetName object.\n */\n await handleUnsupportedUserProvidedTargets(\n userProvidedTargetIsUnsupported,\n userProvidedTargetName,\n validFoundTargetName\n );\n\n /**\n * Once the user is at this stage, then they can go ahead and convert.\n */\n\n buildTargetName = validFoundTargetName.build ?? buildTargetName;\n serveTargetName = validFoundTargetName.serve ?? serveTargetName;\n\n if (projectType === 'application') {\n moveAndEditIndexHtml(tree, schema, buildTargetName);\n }\n\n deleteWebpackConfig(\n tree,\n root,\n targets?.[buildTargetName]?.options?.webpackConfig\n );\n\n editTsConfig(tree, schema);\n }\n\n const initTask = await initGenerator(tree, {\n uiFramework: schema.uiFramework,\n includeLib: schema.includeLib,\n compiler: schema.compiler,\n testEnvironment: schema.testEnvironment,\n });\n tasks.push(initTask);\n\n if (!projectAlreadyHasViteTargets.build) {\n addOrChangeBuildTarget(tree, schema, buildTargetName);\n }\n\n if (!schema.includeLib) {\n if (!projectAlreadyHasViteTargets.serve) {\n addOrChangeServeTarget(tree, schema, serveTargetName);\n }\n if (!projectAlreadyHasViteTargets.preview) {\n addPreviewTarget(tree, schema, serveTargetName);\n }\n }\n\n if (projectType === 'library') {\n // update tsconfig.lib.json to include vite/client\n updateJson(tree, joinPathFragments(root, 'tsconfig.lib.json'), (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 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 rollupOptionsExternalString: `\"'react', 'react-dom', 'react/jsx-runtime'\"`,\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 );\n } else {\n createOrEditViteConfig(tree, schema, false, projectAlreadyHasViteTargets);\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: 'c8',\n skipViteConfig: true,\n testTarget: testTargetName,\n skipFormat: true,\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;\nexport const configurationSchematic = convertNxGenerator(\n viteConfigurationGenerator\n);\n"],"names":["viteConfigurationGenerator","configurationSchematic","tree","schema","tasks","targets","projectType","root","readProjectConfiguration","project","buildTargetName","serveTargetName","testTargetName","includeLib","testEnvironment","projectAlreadyHasViteTargets","newProject","userProvidedTargetName","build","buildTarget","serve","serveTarget","test","testTarget","validFoundTargetName","projectContainsUnsupportedExecutor","userProvidedTargetIsUnsupported","alreadyHasNxViteTargets","findExistingTargetsInProject","Error","handleUnknownExecutors","handleUnsupportedUserProvidedTargets","moveAndEditIndexHtml","deleteWebpackConfig","options","webpackConfig","editTsConfig","initTask","initGenerator","uiFramework","compiler","push","addOrChangeBuildTarget","addOrChangeServeTarget","preview","addPreviewTarget","updateJson","joinPathFragments","json","compilerOptions","types","includes","createOrEditViteConfig","includeVitest","inSourceTests","rollupOptionsExternal","rollupOptionsExternalString","imports","plugins","vitestTask","vitestGenerator","coverageProvider","skipViteConfig","skipFormat","formatFiles","runTasksInSerial","convertNxGenerator"],"mappings":";;;;;;;;IA8BsBA,0BAA0B;eAA1BA;;IAyNtB,OAA0C;eAA1C;;IACaC,sBAAsB;eAAtBA;;;;wBA/ON;gCAeA;sBAEmB;iCACE;AAGrB,eAAeD,2BACpBE,IAAU,EACVC,MAAwC,EACxC;QAWAA,SAEA,8EAA8E;IAC9E,8EAA8E;IAC9EA;IAdA,MAAMC,QAA6B,EAAE;IAErC,MAAM,EAAEC,QAAO,EAAEC,YAAW,EAAEC,KAAI,EAAE,GAAGC,IAAAA,gCAAwB,EAC7DN,MACAC,OAAOM,OAAO;IAEhB,IAAIC,kBAAkB;IACtB,IAAIC,kBAAkB;IACtB,IAAIC,iBAAiB;;IAErBT,gBAAAA,UAAAA,QAAOU,oCAAPV,QAAOU,aAAeP,gBAAgB,SAAS;;IAI/CH,qBAAAA,WAAAA,QAAOW,8CAAPX,SAAOW,kBAAoB,OAAO;IAElC;;;GAGC,GACD,IAAIC,+BAA4C,CAAC;IAEjD,IAAI,CAACZ,OAAOa,UAAU,EAAE;YA+FpBX;QA9FF,MAAMY,yBAAiD;YACrDC,OAAOf,OAAOgB,WAAW;YACzBC,OAAOjB,OAAOkB,WAAW;YACzBC,MAAMnB,OAAOoB,UAAU;QACzB;QAEA,MAAM,EACJC,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AO;YACvBI,YAAYV,OAAOU,UAAU;YAC7BwC,eAAelD,OAAOkD,aAAa;YACnCC,eAAenD,OAAOmD,aAAa;YACnCC,uBAAuB;gBACrB,CAAC,OAAO,CAAC;gBACT,CAAC,WAAW,CAAC;gBACb,CAAC,mBAAmB,CAAC;aACtB;YACDC,6BAA6B,CAAC,2CAA2C,CAAC;YAC1EC,SAAS;gBACPtD,OAAOqC,QAAQ,KAAK,QAChB,CAAC,4CAA4C,CAAC,GAC9C,CAAC,wCAAwC,CAAC;aAC/C;YACDkB,SAAS;gBAAC;aAAU;QACtB,GACA,KAAK;IAET,OAAO;QACLN,IAAAA,sCAAsB,EAAClD,MAAMC,QAAQ,KAAK,EAAEY;IAC9C,CAAC;IAED,IAAIZ,OAAOkD,aAAa,EAAE;QACxB,MAAMM,aAAa,MAAMC,IAAAA,wBAAe,EAAC1D,MAAM;YAC7CO,SAASN,OAAOM,OAAO;YACvB8B,aAAapC,OAAOoC,WAAW;YAC/Be,eAAenD,OAAOmD,aAAa;YACnCO,kBAAkB;YAClBC,gBAAgB,IAAI;YACpBvC,YAAYX;YACZmD,YAAY,IAAI;QAClB;QACA3D,MAAMqC,IAAI,CAACkB;IACb,CAAC;IAED,IAAI,CAACxD,OAAO4D,UAAU,EAAE;QACtB,MAAMC,IAAAA,mBAAW,EAAC9D;IACpB,CAAC;IAED,OAAO+D,IAAAA,wBAAgB,KAAI7D;AAC7B;MAEA,WAAeJ;AACR,MAAMC,yBAAyBiE,IAAAA,0BAAkB,EACtDlE"}
@@ -40,7 +40,7 @@ function checkDependenciesInstalled(host, schema) {
40
40
  devDependencies['happy-dom'] = _versions.happyDomVersion;
41
41
  } else if (schema.testEnvironment === 'edge-runtime') {
42
42
  devDependencies['@edge-runtime/vm'] = _versions.edgeRuntimeVmVersion;
43
- } else if (schema.testEnvironment !== 'node') {
43
+ } else if (schema.testEnvironment !== 'node' && schema.testEnvironment) {
44
44
  _devkit.logger.info(`A custom environment was provided: ${schema.testEnvironment}. You need to install it manually.`);
45
45
  }
46
46
  if (schema.uiFramework === 'react') {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n convertNxGenerator,\n logger,\n readJson,\n readNxJson,\n runTasksInSerial,\n Tree,\n updateJson,\n updateNxJson,\n} from '@nx/devkit';\n\nimport { initGenerator as jsInitGenerator } from '@nx/js';\n\nimport {\n jsdomVersion,\n nxVersion,\n vitePluginDtsVersion,\n vitePluginReactVersion,\n vitePluginReactSwcVersion,\n vitestUiVersion,\n vitestVersion,\n viteVersion,\n happyDomVersion,\n edgeRuntimeVmVersion,\n} from '../../utils/versions';\nimport { InitGeneratorSchema } from './schema';\n\nfunction checkDependenciesInstalled(host: Tree, schema: InitGeneratorSchema) {\n const packageJson = readJson(host, 'package.json');\n const devDependencies = {};\n const dependencies = {};\n packageJson.dependencies = packageJson.dependencies || {};\n packageJson.devDependencies = packageJson.devDependencies || {};\n\n // base deps\n devDependencies['@nx/vite'] = nxVersion;\n devDependencies['vite'] = viteVersion;\n devDependencies['vitest'] = vitestVersion;\n devDependencies['@vitest/ui'] = vitestUiVersion;\n\n if (schema.testEnvironment === 'jsdom') {\n devDependencies['jsdom'] = jsdomVersion;\n } else if (schema.testEnvironment === 'happy-dom') {\n devDependencies['happy-dom'] = happyDomVersion;\n } else if (schema.testEnvironment === 'edge-runtime') {\n devDependencies['@edge-runtime/vm'] = edgeRuntimeVmVersion;\n } else if (schema.testEnvironment !== 'node') {\n logger.info(\n `A custom environment was provided: ${schema.testEnvironment}. You need to install it manually.`\n );\n }\n\n if (schema.uiFramework === 'react') {\n if (schema.compiler === 'swc') {\n devDependencies['@vitejs/plugin-react-swc'] = vitePluginReactSwcVersion;\n } else {\n devDependencies['@vitejs/plugin-react'] = vitePluginReactVersion;\n }\n }\n\n if (schema.includeLib) {\n devDependencies['vite-plugin-dts'] = vitePluginDtsVersion;\n }\n\n return addDependenciesToPackageJson(host, dependencies, devDependencies);\n}\n\nfunction moveToDevDependencies(tree: Tree) {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.dependencies = packageJson.dependencies || {};\n packageJson.devDependencies = packageJson.devDependencies || {};\n\n if (packageJson.dependencies['@nx/vite']) {\n packageJson.devDependencies['@nx/vite'] =\n packageJson.dependencies['@nx/vite'];\n delete packageJson.dependencies['@nx/vite'];\n }\n return packageJson;\n });\n}\n\nexport function createVitestConfig(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 nxJson.targetDefaults ??= {};\n nxJson.targetDefaults.test ??= {};\n nxJson.targetDefaults.test.inputs ??= [\n 'default',\n productionFileSet ? '^production' : '^default',\n ];\n\n updateNxJson(tree, nxJson);\n}\n\nexport async function initGenerator(tree: Tree, schema: InitGeneratorSchema) {\n moveToDevDependencies(tree);\n createVitestConfig(tree);\n const tasks = [];\n\n tasks.push(\n await jsInitGenerator(tree, {\n ...schema,\n skipFormat: true,\n })\n );\n\n tasks.push(checkDependenciesInstalled(tree, schema));\n return runTasksInSerial(...tasks);\n}\n\nexport default initGenerator;\nexport const initSchematic = convertNxGenerator(initGenerator);\n"],"names":["createVitestConfig","initGenerator","initSchematic","checkDependenciesInstalled","host","schema","packageJson","readJson","devDependencies","dependencies","nxVersion","viteVersion","vitestVersion","vitestUiVersion","testEnvironment","jsdomVersion","happyDomVersion","edgeRuntimeVmVersion","logger","info","uiFramework","compiler","vitePluginReactSwcVersion","vitePluginReactVersion","includeLib","vitePluginDtsVersion","addDependenciesToPackageJson","moveToDevDependencies","tree","updateJson","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","targetDefaults","test","inputs","updateNxJson","tasks","jsInitGenerator","skipF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4B;IACnB,MAAMe,QAAQ,EAAE;IAEhBA,MAAMR,IAAI,CACR,MAAMS,IAAAA,iBAAe,EAAChB,MAAM,eACvBvB;QACHwC,YAAY,IAAI;;IAIpBF,MAAMR,IAAI,CAAChC,2BAA2ByB,MAAMvB;IAC5C,OAAOyC,IAAAA,wBAAgB,KAAIH;AAC7B;MAEA,WAAe1C;AACR,MAAMC,gBAAgB6C,IAAAA,0BAAkB,EAAC9C"}
1
+ {"version":3,"sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n convertNxGenerator,\n logger,\n readJson,\n readNxJson,\n runTasksInSerial,\n Tree,\n updateJson,\n updateNxJson,\n} from '@nx/devkit';\n\nimport { initGenerator as jsInitGenerator } from '@nx/js';\n\nimport {\n jsdomVersion,\n nxVersion,\n vitePluginDtsVersion,\n vitePluginReactVersion,\n vitePluginReactSwcVersion,\n vitestUiVersion,\n vitestVersion,\n viteVersion,\n happyDomVersion,\n edgeRuntimeVmVersion,\n} from '../../utils/versions';\nimport { InitGeneratorSchema } from './schema';\n\nfunction checkDependenciesInstalled(host: Tree, schema: InitGeneratorSchema) {\n const packageJson = readJson(host, 'package.json');\n const devDependencies = {};\n const dependencies = {};\n packageJson.dependencies = packageJson.dependencies || {};\n packageJson.devDependencies = packageJson.devDependencies || {};\n\n // base deps\n devDependencies['@nx/vite'] = nxVersion;\n devDependencies['vite'] = viteVersion;\n devDependencies['vitest'] = vitestVersion;\n devDependencies['@vitest/ui'] = vitestUiVersion;\n\n if (schema.testEnvironment === 'jsdom') {\n devDependencies['jsdom'] = jsdomVersion;\n } else if (schema.testEnvironment === 'happy-dom') {\n devDependencies['happy-dom'] = happyDomVersion;\n } else if (schema.testEnvironment === 'edge-runtime') {\n devDependencies['@edge-runtime/vm'] = edgeRuntimeVmVersion;\n } else if (schema.testEnvironment !== 'node' && schema.testEnvironment) {\n logger.info(\n `A custom environment was provided: ${schema.testEnvironment}. You need to install it manually.`\n );\n }\n\n if (schema.uiFramework === 'react') {\n if (schema.compiler === 'swc') {\n devDependencies['@vitejs/plugin-react-swc'] = vitePluginReactSwcVersion;\n } else {\n devDependencies['@vitejs/plugin-react'] = vitePluginReactVersion;\n }\n }\n\n if (schema.includeLib) {\n devDependencies['vite-plugin-dts'] = vitePluginDtsVersion;\n }\n\n return addDependenciesToPackageJson(host, dependencies, devDependencies);\n}\n\nfunction moveToDevDependencies(tree: Tree) {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.dependencies = packageJson.dependencies || {};\n packageJson.devDependencies = packageJson.devDependencies || {};\n\n if (packageJson.dependencies['@nx/vite']) {\n packageJson.devDependencies['@nx/vite'] =\n packageJson.dependencies['@nx/vite'];\n delete packageJson.dependencies['@nx/vite'];\n }\n return packageJson;\n });\n}\n\nexport function createVitestConfig(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 nxJson.targetDefaults ??= {};\n nxJson.targetDefaults.test ??= {};\n nxJson.targetDefaults.test.inputs ??= [\n 'default',\n productionFileSet ? '^production' : '^default',\n ];\n\n updateNxJson(tree, nxJson);\n}\n\nexport async function initGenerator(tree: Tree, schema: InitGeneratorSchema) {\n moveToDevDependencies(tree);\n createVitestConfig(tree);\n const tasks = [];\n\n tasks.push(\n await jsInitGenerator(tree, {\n ...schema,\n skipFormat: true,\n })\n );\n\n tasks.push(checkDependenciesInstalled(tree, schema));\n return runTasksInSerial(...tasks);\n}\n\nexport default initGenerator;\nexport const initSchematic = convertNxGenerator(initGenerator);\n"],"names":["createVitestConfig","initGenerator","initSchematic","checkDependenciesInstalled","host","schema","packageJson","readJson","devDependencies","dependencies","nxVersion","viteVersion","vitestVersion","vitestUiVersion","testEnvironment","jsdomVersion","happyDomVersion","edgeRuntimeVmVersion","logger","info","uiFramework","compiler","vitePluginReactSwcVersion","vitePluginReactVersion","includeLib","vitePluginDtsVersion","addDependenciesToPackageJson","moveToDevDependencies","tree","updateJson","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","targetDefaults","test","inputs","updateNxJson","tasks","jsInitGenerator","skipFormat","runTasksInSerial","convertNxGenerator"],"mappings":";;;;;;;;IAkFgBA,kBAAkB;eAAlBA;;IAuBMC,aAAa;eAAbA;;IAgBtB,OAA6B;eAA7B;;IACaC,aAAa;eAAbA;;;;wBAhHN;oBAE0C;0BAa1C;AAGP,SAASC,2BAA2BC,IAAU,EAAEC,MAA2B,EAAE;IAC3E,MAAMC,cAAcC,IAAAA,gBAAQ,EAACH,MAAM;IACnC,MAAMI,kBAAkB,CAAC;IACzB,MAAMC,eAAe,CAAC;IACtBH,YAAYG,YAAY,GAAGH,YAAYG,YAAY,IAAI,CAAC;IACxDH,YAAYE,eAAe,GAAGF,YAAYE,eAAe,IAAI,CAAC;IAE9D,YAAY;IACZA,eAAe,CAAC,WAAW,GAAGE,mBAAS;IACvCF,eAAe,CAAC,OAAO,GAAGG,qBAAW;IACrCH,eAAe,CAAC,SAAS,GAAGI,uBAAa;IACzCJ,eAAe,CAAC,aAAa,GAAGK,yBAAe;IAE/C,IAAIR,OAAOS,eAAe,KAAK,SAAS;QACtCN,eAAe,CAAC,QAAQ,GAAGO,sBAAY;IACzC,OAAO,IAAIV,OAAOS,eAAe,KAAK,aAAa;QACjDN,eAAe,CAAC,YAAY,GAAGQ,yBAAe;IAChD,OAAO,IAAIX,OAAOS,eAAe,KAAK,gBAAgB;QACpDN,eAAe,CAAC,mBAAmB,GAAGS,8BAAoB;IAC5D,OAAO,IAAIZ,OAAOS,eAAe,KAAK,UAAUT,OAAOS,eAAe,EAAE;QACtEI,cAAM,CAACC,IAAI,CACT,CAAC,mCAAmC,EAAEd,OAAOS,eAAe,CAAC,kCAAkC,CAAC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;;IACjCV,YAAAA,8BAAAA,OAAOS,cAAc,CAACC,IAAI,EAACC,4BAA3BX,4BAA2BW,SAAW;QACpC;QACAT,oBAAoB,gBAAgB,UAAU;KAC/C;IAEDU,IAAAA,oBAAY,EAACd,MAAME;AACrB;AAEO,eAAe7B,cAAc2B,IAAU,EAAEvB,MAA2B,EAAE;IAC3EsB,sBAAsBC;IACtB5B,mBAAmB4B;IACnB,MAAMe,QAAQ,EAAE;IAEhBA,MAAMR,IAAI,CACR,MAAMS,IAAAA,iBAAe,EAAChB,MAAM,eACvBvB;QACHwC,YAAY,IAAI;;IAIpBF,MAAMR,IAAI,CAAChC,2BAA2ByB,MAAMvB;IAC5C,OAAOyC,IAAAA,wBAAgB,KAAIH;AAC7B;MAEA,WAAe1C;AACR,MAAMC,gBAAgB6C,IAAAA,0BAAkB,EAAC9C"}
@@ -35,10 +35,31 @@ async function vitestGenerator(tree, schema) {
35
35
  });
36
36
  tasks.push(initTask);
37
37
  if (!schema.skipViteConfig) {
38
- (0, _generatorutils.createOrEditViteConfig)(tree, _extends._({}, schema, {
39
- includeVitest: true,
40
- includeLib: projectType === 'library'
41
- }), true);
38
+ if (schema.uiFramework === 'react') {
39
+ (0, _generatorutils.createOrEditViteConfig)(tree, {
40
+ project: schema.project,
41
+ includeLib: projectType === 'library',
42
+ includeVitest: true,
43
+ inSourceTests: schema.inSourceTests,
44
+ rollupOptionsExternal: [
45
+ `'react'`,
46
+ `'react-dom'`,
47
+ `'react/jsx-runtime'`
48
+ ],
49
+ rollupOptionsExternalString: `"'react', 'react-dom', 'react/jsx-runtime'"`,
50
+ imports: [
51
+ `import react from '@vitejs/plugin-react'`
52
+ ],
53
+ plugins: [
54
+ 'react()'
55
+ ]
56
+ }, true);
57
+ } else {
58
+ (0, _generatorutils.createOrEditViteConfig)(tree, _extends._({}, schema, {
59
+ includeVitest: true,
60
+ includeLib: projectType === 'library'
61
+ }), true);
62
+ }
42
63
  }
43
64
  createFiles(tree, schema, root);
44
65
  updateTsConfig(tree, schema, root);
@@ -51,28 +72,51 @@ async function vitestGenerator(tree, schema) {
51
72
  return (0, _devkit.runTasksInSerial)(...tasks);
52
73
  }
53
74
  function updateTsConfig(tree, options, projectRoot) {
54
- (0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.json'), (json)=>{
55
- var _json_compilerOptions, _json_compilerOptions_types;
56
- if (json.references && !json.references.some((r)=>r.path === './tsconfig.spec.json')) {
57
- json.references.push({
58
- path: './tsconfig.spec.json'
59
- });
60
- }
61
- if (!((_json_compilerOptions = json.compilerOptions) == null ? void 0 : (_json_compilerOptions_types = _json_compilerOptions.types) == null ? void 0 : _json_compilerOptions_types.includes('vitest'))) {
62
- var _json_compilerOptions1;
63
- if ((_json_compilerOptions1 = json.compilerOptions) == null ? void 0 : _json_compilerOptions1.types) {
64
- json.compilerOptions.types.push('vitest');
65
- } else {
66
- var _json;
67
- var _compilerOptions;
68
- (_compilerOptions = (_json = json).compilerOptions) != null ? _compilerOptions : _json.compilerOptions = {};
69
- json.compilerOptions.types = [
70
- 'vitest'
71
- ];
75
+ if (tree.exists((0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.spec.json'))) {
76
+ (0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.spec.json'), (json)=>{
77
+ var _json_compilerOptions, _json_compilerOptions_types;
78
+ if (!((_json_compilerOptions = json.compilerOptions) == null ? void 0 : (_json_compilerOptions_types = _json_compilerOptions.types) == null ? void 0 : _json_compilerOptions_types.includes('vitest'))) {
79
+ var _json_compilerOptions1;
80
+ if ((_json_compilerOptions1 = json.compilerOptions) == null ? void 0 : _json_compilerOptions1.types) {
81
+ json.compilerOptions.types.push('vitest');
82
+ } else {
83
+ var _json;
84
+ var _compilerOptions;
85
+ (_compilerOptions = (_json = json).compilerOptions) != null ? _compilerOptions : _json.compilerOptions = {};
86
+ json.compilerOptions.types = [
87
+ 'vitest'
88
+ ];
89
+ }
72
90
  }
73
- }
74
- return json;
75
- });
91
+ return json;
92
+ });
93
+ (0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.json'), (json)=>{
94
+ if (json.references && !json.references.some((r)=>r.path === './tsconfig.spec.json')) {
95
+ json.references.push({
96
+ path: './tsconfig.spec.json'
97
+ });
98
+ }
99
+ return json;
100
+ });
101
+ } else {
102
+ (0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.json'), (json)=>{
103
+ var _json_compilerOptions, _json_compilerOptions_types;
104
+ if (!((_json_compilerOptions = json.compilerOptions) == null ? void 0 : (_json_compilerOptions_types = _json_compilerOptions.types) == null ? void 0 : _json_compilerOptions_types.includes('vitest'))) {
105
+ var _json_compilerOptions1;
106
+ if ((_json_compilerOptions1 = json.compilerOptions) == null ? void 0 : _json_compilerOptions1.types) {
107
+ json.compilerOptions.types.push('vitest');
108
+ } else {
109
+ var _json;
110
+ var _compilerOptions;
111
+ (_compilerOptions = (_json = json).compilerOptions) != null ? _compilerOptions : _json.compilerOptions = {};
112
+ json.compilerOptions.types = [
113
+ 'vitest'
114
+ ];
115
+ }
116
+ }
117
+ return json;
118
+ });
119
+ }
76
120
  if (options.inSourceTests) {
77
121
  const tsconfigLibPath = (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.lib.json');
78
122
  const tsconfigAppPath = (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.app.json');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/vite/src/generators/vitest/vitest-generator.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n convertNxGenerator,\n formatFiles,\n generateFiles,\n GeneratorCallback,\n joinPathFragments,\n offsetFromRoot,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\nimport {\n addOrChangeTestTarget,\n createOrEditViteConfig,\n findExistingTargetsInProject,\n} from '../../utils/generator-utils';\nimport { VitestGeneratorSchema } from './schema';\n\nimport initGenerator from '../init/init';\nimport {\n vitestCoverageC8Version,\n vitestCoverageIstanbulVersion,\n vitestCoverageV8Version,\n} from '../../utils/versions';\n\nimport { addTsLibDependencies } from '@nx/js';\nimport { join } from 'path';\n\nexport async function vitestGenerator(\n tree: Tree,\n schema: VitestGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const { targets, root, projectType } = readProjectConfiguration(\n tree,\n schema.project\n );\n let testTarget =\n schema.testTarget ??\n findExistingTargetsInProject(targets).validFoundTargetName.test ??\n 'test';\n\n addOrChangeTestTarget(tree, schema, testTarget);\n\n const initTask = await initGenerator(tree, {\n uiFramework: schema.uiFramework,\n testEnvironment: schema.testEnvironment,\n });\n tasks.push(initTask);\n\n if (!schema.skipViteConfig) {\n createOrEditViteConfig(\n tree,\n {\n ...schema,\n includeVitest: true,\n includeLib: projectType === 'library',\n },\n true\n );\n }\n\n createFiles(tree, schema, root);\n updateTsConfig(tree, schema, root);\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 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) {\n updateJson(tree, joinPathFragments(projectRoot, 'tsconfig.json'), (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\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 if (options.inSourceTests) {\n const tsconfigLibPath = joinPathFragments(projectRoot, 'tsconfig.lib.json');\n const tsconfigAppPath = joinPathFragments(projectRoot, 'tsconfig.app.json');\n if (tree.exists(tsconfigLibPath)) {\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.lib.json'),\n (json) => {\n (json.compilerOptions.types ??= []).push('vitest/importMeta');\n return json;\n }\n );\n } else if (tree.exists(tsconfigAppPath)) {\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.app.json'),\n (json) => {\n (json.compilerOptions.types ??= []).push('vitest/importMeta');\n return json;\n }\n );\n }\n\n addTsLibDependencies(tree);\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 'c8':\n return {\n '@vitest/coverage-c8': vitestCoverageC8Version,\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;\nexport const vitestSchematic = convertNxGenerator(vitestGenerator);\n"],"names":["vitestGenerator","vitestSchematic","tree","schema","tasks","targets","root","projectType","readProjectConfiguration","project","testTarget","findExistingTargetsInProject","validFoundTargetName","test","addOrChangeTestTarget","initTask","initGenerator","uiFramework","testEnvironment","push","skipViteConfig","createOrEditViteConfig","includeVitest","includeLib","createFiles","updateTsConfig","coverageProviderDependency","getCoverageProviderDependency","coverageProvider","installCoverageProviderTask","addDependenciesToPackageJson","skipFormat","formatFiles","runTasksInSerial","options","projectRoot","updateJson","joinPathFragments","json","references","some","r","path","compilerOptions","types","includes","inSourceTests","tsconfigLibPath","tsconfigAppPath","exists","addTsLibDependencies","generateFiles","join","__dirname","tmpl","offsetFromRoot","vitestCoverageC8Version","vitestCoverageIstanbulVersion","vitestCo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AA,yBAAiB,EAACF,aAAa,sBAC/B,CAACG,OAAS;oBACPA;;gBAAAA,CAAAA,WAAAA,wBAAAA,KAAKK,eAAe,EAACC,0BAArBN,sBAAqBM,QAAU,EAAE,AAAD,EAAGzB,IAAI,CAAC;gBACzC,OAAOmB;YACT;QAEJ,CAAC;QAEDY,IAAAA,wBAAoB,EAAChD;IACvB,CAAC;AACH;AAEA,SAASsB,YACPtB,IAAU,EACVgC,OAA8B,EAC9BC,WAAmB,EACnB;IACAgB,IAAAA,qBAAa,EAACjD,MAAMkD,IAAAA,UAAI,EAACC,WAAW,UAAUlB,aAAa;QACzDmB,MAAM;OACHpB;QACHC;QACAoB,gBAAgBA,IAAAA,sBAAc,EAACpB;;AAEnC;AAEA,SAASR,8BACPC,gBAA2D,EAC3D;IACA,OAAQA;QACN,KAAK;YACH,OAAO;gBACL,uBAAuB4B,iCAAuB;YAChD;QACF,KAAK;YACH,OAAO;gBACL,6BAA6BC,uCAA6B;YAC5D;QACF;YACE,OAAO;gBACL,uBAAuBC,iCAAuB;YAChD;IACJ;AACF;MAEA,WAAe1D;AACR,MAAMC,kBAAkB0D,IAAAA,0BAAkB,EAAC3D"}
1
+ {"version":3,"sources":["../../../../../../packages/vite/src/generators/vitest/vitest-generator.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n convertNxGenerator,\n formatFiles,\n generateFiles,\n GeneratorCallback,\n joinPathFragments,\n offsetFromRoot,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\nimport {\n addOrChangeTestTarget,\n createOrEditViteConfig,\n findExistingTargetsInProject,\n} from '../../utils/generator-utils';\nimport { VitestGeneratorSchema } from './schema';\n\nimport initGenerator from '../init/init';\nimport {\n vitestCoverageC8Version,\n vitestCoverageIstanbulVersion,\n vitestCoverageV8Version,\n} from '../../utils/versions';\n\nimport { addTsLibDependencies } from '@nx/js';\nimport { join } from 'path';\n\nexport async function vitestGenerator(\n tree: Tree,\n schema: VitestGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const { targets, root, projectType } = readProjectConfiguration(\n tree,\n schema.project\n );\n let testTarget =\n schema.testTarget ??\n findExistingTargetsInProject(targets).validFoundTargetName.test ??\n 'test';\n\n addOrChangeTestTarget(tree, schema, testTarget);\n\n const initTask = await initGenerator(tree, {\n uiFramework: schema.uiFramework,\n testEnvironment: schema.testEnvironment,\n });\n tasks.push(initTask);\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 rollupOptionsExternalString: `\"'react', 'react-dom', 'react/jsx-runtime'\"`,\n imports: [`import react from '@vitejs/plugin-react'`],\n plugins: ['react()'],\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);\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 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) {\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 if (options.inSourceTests) {\n const tsconfigLibPath = joinPathFragments(projectRoot, 'tsconfig.lib.json');\n const tsconfigAppPath = joinPathFragments(projectRoot, 'tsconfig.app.json');\n if (tree.exists(tsconfigLibPath)) {\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.lib.json'),\n (json) => {\n (json.compilerOptions.types ??= []).push('vitest/importMeta');\n return json;\n }\n );\n } else if (tree.exists(tsconfigAppPath)) {\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.app.json'),\n (json) => {\n (json.compilerOptions.types ??= []).push('vitest/importMeta');\n return json;\n }\n );\n }\n\n addTsLibDependencies(tree);\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 'c8':\n return {\n '@vitest/coverage-c8': vitestCoverageC8Version,\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;\nexport const vitestSchematic = convertNxGenerator(vitestGenerator);\n"],"names":["vitestGenerator","vitestSchematic","tree","schema","tasks","targets","root","projectType","readProjectConfiguration","project","testTarget","findExistingTargetsInProject","validFoundTargetName","test","addOrChangeTestTarget","initTask","initGenerator","uiFramework","testEnvironment","push","skipViteConfig","createOrEditViteConfig","includeLib","includeVitest","inSourceTests","rollupOptionsExternal","rollupOptionsExternalString","imports","plugins","createFiles","updateTsConfig","coverageProviderDependency","getCoverageProviderDependency","coverageProvider","installCoverageProviderTask","addDependenciesToPackageJson","skipFormat","formatFiles","runTasksInSerial","options","projectRoot","exists","joinPathFragments","updateJson","json","compilerOptions","types","includes","references","some","r","path","tsconfigLibPath","tsconfigAppPath","addTsLibDependencies","generateFiles","join","__dirname","tmpl","offsetFromRoot","vitestCoverageC8Version","vitestCoverageIstanbulVersion","vitestCoverageV8Version","convertNxGenerator"],"mappings":";;;;;;;;IA8BsBA,eAAe;eAAfA;;IA+LtB,OAA+B;eAA/B;;IACaC,eAAe;eAAfA;;;;wBAlNN;gCAKA;sBAGmB;0BAKnB;oBAE8B;sBAChB;AAEd,eAAeD,gBACpBE,IAAU,EACVC,MAA6B,EAC7B;IACA,MAAMC,QAA6B,EAAE;IAErC,MAAM,EAAEC,QAAO,EAAEC,KAAI,EAAEC,YAAW,EAAE,GAAGC,IAAAA,gCAAwB,EAC7DN,MACAC,OAAOM,OAAO;QAGdN,oBAAAA;IADF,IAAIO,aACFP,CAAAA,OAAAA,CAAAA,qBAAAA,OAAOO,UAAU,YAAjBP,qBACAQ,IAAAA,4CAA4B,EAACN,SAASO,oBAAoB,CAACC,IAAI,YAD/DV,OAEA,MAAM;IAERW,IAAAA,qCAAqB,EAACZ,MAAMC,QAAQO;IAEpC,MAAMK,WAAW,MAAMC,IAAAA,aAAa,EAACd,MAAM;QACzCe,aAAad,OAAOc,WAAW;QAC/BC,iBAAiBf,OAAOe,eAAe;IACzC;IACAd,MAAMe,IAAI,CAACJ;IAEX,IAAI,CAACZ,OAAOiB,cAAc,EAAE;QAC1B,IAAIjB,OAAO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,MAAM4B,kBAAkBV,IAAAA,yBAAiB,EAACF,aAAa;QACvD,MAAMa,kBAAkBX,IAAAA,yBAAiB,EAACF,aAAa;QACvD,IAAItC,KAAKuC,MAAM,CAACW,kBAAkB;YAChCT,IAAAA,kBAAU,EACRzC,MACAwC,IAAAA,yBAAiB,EAACF,aAAa,sBAC/B,CAACI,OAAS;oBACPA;;gBAAAA,CAAAA,WAAAA,wBAAAA,KAAKC,eAAe,EAACC,0BAArBF,sBAAqBE,QAAU,EAAE,AAAD,EAAG3B,IAAI,CAAC;gBACzC,OAAOyB;YACT;QAEJ,OAAO,IAAI1C,KAAKuC,MAAM,CAACY,kBAAkB;YACvCV,IAAAA,kBAAU,EACRzC,MACAwC,IAAAA,yBAAiB,EAACF,aAAa,sBAC/B,CAACI,OAAS;oBACPA;;gBAAAA,CAAAA,WAAAA,wBAAAA,KAAKC,eAAe,EAACC,0BAArBF,sBAAqBE,QAAU,EAAE,AAAD,EAAG3B,IAAI,CAAC;gBACzC,OAAOyB;YACT;QAEJ,CAAC;QAEDU,IAAAA,wBAAoB,EAACpD;IACvB,CAAC;AACH;AAEA,SAAS2B,YACP3B,IAAU,EACVqC,OAA8B,EAC9BC,WAAmB,EACnB;IACAe,IAAAA,qBAAa,EAACrD,MAAMsD,IAAAA,UAAI,EAACC,WAAW,UAAUjB,aAAa;QACzDkB,MAAM;OACHnB;QACHC;QACAmB,gBAAgBA,IAAAA,sBAAc,EAACnB;;AAEnC;AAEA,SAASR,8BACPC,gBAA2D,EAC3D;IACA,OAAQA;QACN,KAAK;YACH,OAAO;gBACL,uBAAuB2B,iCAAuB;YAChD;QACF,KAAK;YACH,OAAO;gBACL,6BAA6BC,uCAA6B;YAC5D;QACF;YACE,OAAO;gBACL,uBAAuBC,iCAAuB;YAChD;IACJ;AACF;MAEA,WAAe9D;AACR,MAAMC,kBAAkB8D,IAAAA,0BAAkB,EAAC/D"}
@@ -27,7 +27,18 @@ export declare function addPreviewTarget(tree: Tree, options: ViteConfigurationG
27
27
  export declare function editTsConfig(tree: Tree, options: ViteConfigurationGeneratorSchema): void;
28
28
  export declare function deleteWebpackConfig(tree: Tree, projectRoot: string, webpackConfigFilePath?: string): void;
29
29
  export declare function moveAndEditIndexHtml(tree: Tree, options: ViteConfigurationGeneratorSchema, buildTarget: string): void;
30
- export declare function createOrEditViteConfig(tree: Tree, options: ViteConfigurationGeneratorSchema, onlyVitest: boolean, projectAlreadyHasViteTargets?: TargetFlags): void;
30
+ export interface ViteConfigFileOptions {
31
+ project: string;
32
+ includeLib?: boolean;
33
+ includeVitest?: boolean;
34
+ inSourceTests?: boolean;
35
+ testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
36
+ rollupOptionsExternalString?: string;
37
+ rollupOptionsExternal?: string[];
38
+ imports?: string[];
39
+ plugins?: string[];
40
+ }
41
+ export declare function createOrEditViteConfig(tree: Tree, options: ViteConfigFileOptions, onlyVitest: boolean, projectAlreadyHasViteTargets?: TargetFlags): void;
31
42
  export declare function normalizeViteConfigFilePathWithTree(tree: Tree, projectRoot: string, configFile?: string): string;
32
43
  export declare function getViteConfigPathForProject(tree: Tree, projectName: string, target?: string): string;
33
44
  export declare function handleUnsupportedUserProvidedTargets(userProvidedTargetIsUnsupported: TargetFlags, userProvidedTargetName: UserProvidedTargetName, validFoundTargetName: ValidFoundTargetName): Promise<void>;
@@ -372,8 +372,8 @@ function moveAndEditIndexHtml(tree, options, buildTarget) {
372
372
  }
373
373
  if (tree.exists(indexHtmlPath)) {
374
374
  const indexHtmlContent = tree.read(indexHtmlPath, 'utf8');
375
- if (!indexHtmlContent.includes(`<script type="module" src="${mainPath}"></script>`)) {
376
- tree.write(`${projectConfig.root}/index.html`, indexHtmlContent.replace('</body>', `<script type="module" src="${mainPath}"></script>
375
+ if (!indexHtmlContent.includes(`<script type='module' src='${mainPath}'></script>`)) {
376
+ tree.write(`${projectConfig.root}/index.html`, indexHtmlContent.replace('</body>', `<script type='module' src='${mainPath}'></script>
377
377
  </body>`));
378
378
  if (tree.exists(`${projectConfig.root}/src/index.html`)) {
379
379
  tree.delete(`${projectConfig.root}/src/index.html`);
@@ -381,16 +381,16 @@ function moveAndEditIndexHtml(tree, options, buildTarget) {
381
381
  }
382
382
  } else {
383
383
  tree.write(`${projectConfig.root}/index.html`, `<!DOCTYPE html>
384
- <html lang="en">
384
+ <html lang='en'>
385
385
  <head>
386
- <meta charset="UTF-8" />
387
- <link rel="icon" href="/favicon.ico" />
388
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
386
+ <meta charset='UTF-8' />
387
+ <link rel='icon' href='/favicon.ico' />
388
+ <meta name='viewport' content='width=device-width, initial-scale=1.0' />
389
389
  <title>Vite</title>
390
390
  </head>
391
391
  <body>
392
- <div id="root"></div>
393
- <script type="module" src="${mainPath}"></script>
392
+ <div id='root'></div>
393
+ <script type='module' src='${mainPath}'></script>
394
394
  </body>
395
395
  </html>`);
396
396
  }
@@ -398,6 +398,7 @@ function moveAndEditIndexHtml(tree, options, buildTarget) {
398
398
  function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasViteTargets) {
399
399
  const projectConfig = (0, _devkit.readProjectConfiguration)(tree, options.project);
400
400
  const viteConfigPath = `${projectConfig.root}/vite.config.ts`;
401
+ var _options_rollupOptionsExternal;
401
402
  const buildOption = onlyVitest ? '' : options.includeLib ? `
402
403
  // Configuration for building your library.
403
404
  // See: https://vitejs.dev/guide/build.html#library-mode
@@ -413,16 +414,23 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
413
414
  },
414
415
  rollupOptions: {
415
416
  // External packages that should not be bundled into your library.
416
- external: [${options.uiFramework === 'react' ? "'react', 'react-dom', 'react/jsx-runtime'" : ''}]
417
+ external: [${(_options_rollupOptionsExternal = options.rollupOptionsExternal) != null ? _options_rollupOptionsExternal : ''}]
417
418
  }
418
419
  },` : ``;
419
- const dtsPlugin = onlyVitest ? '' : options.includeLib ? `dts({
420
- entryRoot: 'src',
421
- tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'),
422
- skipDiagnostics: true,
423
- }),` : '';
424
- const dtsImportLine = onlyVitest ? '' : options.includeLib ? `import dts from 'vite-plugin-dts';\nimport * as path from 'path';` : '';
420
+ const imports = options.imports ? options.imports : [];
421
+ if (!onlyVitest && options.includeLib) {
422
+ imports.push(`import dts from 'vite-plugin-dts'`, `import * as path from 'path'`);
423
+ }
425
424
  let viteConfigContent = '';
425
+ const plugins = options.plugins ? [
426
+ ...options.plugins,
427
+ `nxViteTsPaths()`
428
+ ] : [
429
+ `nxViteTsPaths()`
430
+ ];
431
+ if (!onlyVitest && options.includeLib) {
432
+ plugins.push(`dts({ entryRoot: 'src', tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true })`);
433
+ }
426
434
  var _options_testEnvironment;
427
435
  const testOption = options.includeVitest ? `test: {
428
436
  globals: true,
@@ -436,8 +444,6 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
436
444
  const defineOption = options.inSourceTests ? `define: {
437
445
  'import.meta.vitest': undefined
438
446
  },` : '';
439
- const reactPluginImportLine = options.uiFramework === 'react' ? options.compiler === 'swc' ? `import react from '@vitejs/plugin-react-swc';` : `import react from '@vitejs/plugin-react';` : '';
440
- const reactPlugin = options.uiFramework === 'react' ? `react(),` : '';
441
447
  const devServerOption = onlyVitest ? '' : options.includeLib ? '' : `
442
448
  server:{
443
449
  port: 4200,
@@ -448,13 +454,6 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
448
454
  port: 4300,
449
455
  host: 'localhost',
450
456
  },`;
451
- const pluginOption = `
452
- plugins: [
453
- ${dtsPlugin}
454
- ${reactPlugin}
455
- nxViteTsPaths(),
456
- ],
457
- `;
458
457
  const workerOption = `
459
458
  // Uncomment this if you are using workers.
460
459
  // worker: {
@@ -462,21 +461,21 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
462
461
  // },`;
463
462
  const cacheDir = `cacheDir: '${(0, _devkit.offsetFromRoot)(projectConfig.root)}node_modules/.vite/${options.project}',`;
464
463
  if (tree.exists(viteConfigPath)) {
465
- handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, dtsPlugin, dtsImportLine, pluginOption, testOption, cacheDir, (0, _devkit.offsetFromRoot)(projectConfig.root), projectAlreadyHasViteTargets);
464
+ handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, imports, plugins, testOption, cacheDir, (0, _devkit.offsetFromRoot)(projectConfig.root), projectAlreadyHasViteTargets);
466
465
  return;
467
466
  }
468
467
  viteConfigContent = `
469
- /// <reference types="vitest" />
468
+ /// <reference types='vitest' />
470
469
  import { defineConfig } from 'vite';
471
- ${reactPluginImportLine}
470
+ ${imports.join(';\n')}${imports.length ? ';' : ''}
472
471
  import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
473
- ${dtsImportLine}
474
472
 
475
473
  export default defineConfig({
476
474
  ${cacheDir}
477
475
  ${devServerOption}
478
476
  ${previewServerOption}
479
- ${pluginOption}
477
+
478
+ plugins: [${plugins.join(',\n')}],
480
479
  ${workerOption}
481
480
  ${buildOption}
482
481
  ${defineOption}
@@ -561,11 +560,14 @@ async function handleUnknownExecutors(projectName) {
561
560
  `);
562
561
  }
563
562
  }
564
- function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, dtsPlugin, dtsImportLine, pluginOption, testOption, cacheDir, offsetFromRoot, projectAlreadyHasViteTargets) {
565
- if (projectAlreadyHasViteTargets.build && projectAlreadyHasViteTargets.test) {
563
+ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, imports, plugins, testOption, cacheDir, offsetFromRoot, projectAlreadyHasViteTargets) {
564
+ if ((projectAlreadyHasViteTargets == null ? void 0 : projectAlreadyHasViteTargets.build) && (projectAlreadyHasViteTargets == null ? void 0 : projectAlreadyHasViteTargets.test)) {
566
565
  return;
567
566
  }
568
- _devkit.logger.info(`vite.config.ts already exists for project ${options.project}.`);
567
+ if (process.env.NX_VERBOSE_LOGGING === 'true') {
568
+ _devkit.logger.info(`vite.config.ts already exists for project ${options.project}.`);
569
+ }
570
+ var _options_rollupOptionsExternal;
569
571
  const buildOptionObject = {
570
572
  lib: {
571
573
  entry: 'src/index.ts',
@@ -577,11 +579,7 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
577
579
  ]
578
580
  },
579
581
  rollupOptions: {
580
- external: options.uiFramework === 'react' ? [
581
- 'react',
582
- 'react-dom',
583
- 'react/jsx-runtime'
584
- ] : []
582
+ external: (_options_rollupOptionsExternal = options.rollupOptionsExternal) != null ? _options_rollupOptionsExternal : []
585
583
  }
586
584
  };
587
585
  const testOptionObject = {
@@ -594,17 +592,13 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
594
592
  'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
595
593
  ]
596
594
  };
597
- const changed = (0, _viteconfigeditutils.ensureViteConfigIsCorrect)(tree, viteConfigPath, buildOption, buildOptionObject, dtsPlugin, dtsImportLine, pluginOption, testOption, testOptionObject, cacheDir, projectAlreadyHasViteTargets);
595
+ const changed = (0, _viteconfigeditutils.ensureViteConfigIsCorrect)(tree, viteConfigPath, buildOption, buildOptionObject, imports, plugins, testOption, testOptionObject, cacheDir, projectAlreadyHasViteTargets != null ? projectAlreadyHasViteTargets : {});
598
596
  if (!changed) {
599
597
  _devkit.logger.warn(`Make sure the following setting exists in your Vite configuration file (${viteConfigPath}):
600
598
 
601
599
  ${buildOption}
602
600
 
603
601
  `);
604
- } else {
605
- _devkit.logger.info(`
606
- Vite configuration file (${viteConfigPath}) has been updated with the required settings for the new target(s).
607
- `);
608
602
  }
609
603
  }
610
604