@nx/vite 17.3.0-beta.3 → 17.3.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/vite",
3
- "version": "17.3.0-beta.3",
3
+ "version": "17.3.0-beta.4",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for building and testing applications using Vite",
6
6
  "repository": {
@@ -29,13 +29,13 @@
29
29
  "migrations": "./migrations.json"
30
30
  },
31
31
  "dependencies": {
32
- "@nx/devkit": "17.3.0-beta.3",
32
+ "@nx/devkit": "17.3.0-beta.4",
33
33
  "@phenomnomnominal/tsquery": "~5.0.1",
34
34
  "@swc/helpers": "~0.5.0",
35
35
  "enquirer": "~2.3.6",
36
- "@nx/js": "17.3.0-beta.3",
36
+ "@nx/js": "17.3.0-beta.4",
37
37
  "tsconfig-paths": "^4.1.2",
38
- "@nrwl/vite": "17.3.0-beta.3"
38
+ "@nrwl/vite": "17.3.0-beta.4"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "vite": "^5.0.0",
@@ -15,9 +15,11 @@ _export(exports, {
15
15
  });
16
16
  const _extends = require("@swc/helpers/_/_extends");
17
17
  const _devkit = require("@nx/devkit");
18
+ const _js = require("@nx/js");
18
19
  const _generatorutils = require("../../utils/generator-utils");
19
20
  const _init = require("../init/init");
20
21
  const _vitestgenerator = require("../vitest/vitest-generator");
22
+ const _ensuredependencies = require("../../utils/ensure-dependencies");
21
23
  async function viteConfigurationGenerator(tree, schema) {
22
24
  var _nxJson_plugins;
23
25
  var _schema, // Setting default to jsdom since it is the most common use case (React, Web).
@@ -99,14 +101,16 @@ async function viteConfigurationGenerator(tree, schema) {
99
101
  (0, _generatorutils.deleteWebpackConfig)(tree, projectRoot, targets == null ? void 0 : (_targets_buildTargetName = targets[buildTargetName]) == null ? void 0 : (_targets_buildTargetName_options = _targets_buildTargetName.options) == null ? void 0 : _targets_buildTargetName_options.webpackConfig);
100
102
  (0, _generatorutils.editTsConfig)(tree, schema);
101
103
  }
104
+ const jsInitTask = await (0, _js.initGenerator)(tree, _extends._({}, schema, {
105
+ skipFormat: true,
106
+ tsConfigName: projectRoot === '.' ? 'tsconfig.json' : 'tsconfig.base.json'
107
+ }));
108
+ tasks.push(jsInitTask);
102
109
  const initTask = await (0, _init.default)(tree, {
103
- uiFramework: schema.uiFramework,
104
- includeLib: schema.includeLib,
105
- compiler: schema.compiler,
106
- testEnvironment: schema.testEnvironment,
107
- rootProject: projectRoot === '.'
110
+ skipFormat: true
108
111
  });
109
112
  tasks.push(initTask);
113
+ tasks.push((0, _ensuredependencies.ensureDependencies)(tree, schema));
110
114
  const nxJson = (0, _devkit.readNxJson)(tree);
111
115
  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');
112
116
  if (!hasPlugin) {
@@ -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';\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 {\n targets,\n projectType,\n root: projectRoot,\n } = readProjectConfiguration(tree, schema.project);\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 projectRoot,\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 rootProject: projectRoot === '.',\n });\n tasks.push(initTask);\n\n const nxJson = readNxJson(tree);\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 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(\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: 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;\n"],"names":["viteConfigurationGenerator","tree","schema","nxJson","tasks","targets","projectType","root","projectRoot","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","rootProject","push","readNxJson","hasPlugin","plugins","some","p","plugin","addOrChangeBuildTarget","addOrChangeServeTarget","preview","addPreviewTarget","updateJson","joinPathFragments","json","compilerOptions","types","includes","createOrEditViteConfig","includeVitest","inSourceTests","rollupOptionsExternal","imports","undefined","vitestTask","vitestGenerator","coverageProvider","skipViteConfig","skipFormat","formatFiles","runTasksInSerial"],"mappings":";;;;;;;;IA8BsBA,0BAA0B;eAA1BA;;IA0OtB,OAA0C;eAA1C;;;;wBA/PO;gCAeA;sBAEmB;iCACE;AAGrB,eAAeA,2BACpBC,IAAU,EACVC,MAAwC;QAwItBC;QA3HlBD,SAEA,8EAA8E;IAC9E,8EAA8E;IAC9EA;IAfA,MAAME,QAA6B,EAAE;IAErC,MAAM,EACJC,OAAO,EACPC,WAAW,EACXC,MAAMC,WAAW,EAClB,GAAGC,IAAAA,gCAAwB,EAACR,MAAMC,OAAOQ,OAAO;IACjD,IAAIC,kBAAkB;IACtB,IAAIC,kBAAkB;IACtB,IAAIC,iBAAiB;;IAErBX,gBAAAA,UAAAA,QAAOY,oCAAPZ,QAAOY,aAAeR,gBAAgB;;IAItCJ,qBAAAA,WAAAA,QAAOa,8CAAPb,SAAOa,kBAAoB;IAE3B;;;GAGC,GACD,IAAIC,+BAA4C,CAAC;IAEjD,IAAI,CAACd,OAAOe,UAAU,EAAE;YA+FpBZ,kCAAAA;QA9FF,MAAMa,yBAAiD;YACrDC,OAAOjB,OAAOkB,WAAW;YACzBC,OAAOnB,OAAOoB,WAAW;YACzBC,MAAMrB,OAAOsB,UAAU;QACzB;QAEA,MAAM,EACJC,oBAAoB,EACpBC,kCAAkC,EAClCC,+BAA+B,EAC/BC,uBAAuB,EACxB,GAAGC,IAAAA,4CAA4B,EAACxB,SAASa;QAC1CF,+BAA+BY;QAC/B;;;;;;;;KAQC,GACD,IAAI,CAACH,qBAAqBN,KAAK,IAAIO,oCAAoC;YACrE,MAAM,IAAII,MACR,CAAC,YAAY,EAAE5B,OAAOQ,OAAO,CAAC,mDAAmD,CAAC;QAEtF;QAEA,IACEkB,wBAAwBT,KAAK,IAC5BS,CAAAA,wBAAwBP,KAAK,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AOuC,QAAQ,KAAK,QAChB,CAAC,4CAA4C,CAAC,GAC9C,CAAC,wCAAwC,CAAC;iBAC/C;gBACDK,SAAS;oBAAC;iBAAU;YACtB,GACA,OACAmB;QAEJ,OAAO;YACLL,IAAAA,sCAAsB,EAAC3D,MAAMC,QAAQ,OAAOc;QAC9C;IACF;IAEA,IAAId,OAAO2D,aAAa,EAAE;QACxB,MAAMK,aAAa,MAAMC,IAAAA,wBAAe,EAAClE,MAAM;YAC7CS,SAASR,OAAOQ,OAAO;YACvB8B,aAAatC,OAAOsC,WAAW;YAC/BsB,eAAe5D,OAAO4D,aAAa;YACnCM,kBAAkB;YAClBC,gBAAgB;YAChB7C,YAAYX;YACZyD,YAAY;QACd;QACAlE,MAAMuC,IAAI,CAACuB;IACb;IAEA,IAAI,CAAChE,OAAOoE,UAAU,EAAE;QACtB,MAAMC,IAAAA,mBAAW,EAACtE;IACpB;IAEA,OAAOuE,IAAAA,wBAAgB,KAAIpE;AAC7B;MAEA,WAAeJ"}
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 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';\nimport { ensureDependencies } from '../../utils/ensure-dependencies';\n\nexport async function viteConfigurationGenerator(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const {\n targets,\n projectType,\n root: projectRoot,\n } = readProjectConfiguration(tree, schema.project);\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 projectRoot,\n targets?.[buildTargetName]?.options?.webpackConfig\n );\n\n editTsConfig(tree, schema);\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, { skipFormat: true });\n tasks.push(initTask);\n tasks.push(ensureDependencies(tree, schema));\n\n const nxJson = readNxJson(tree);\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 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(\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: 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;\n"],"names":["viteConfigurationGenerator","tree","schema","nxJson","tasks","targets","projectType","root","projectRoot","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","jsInitTask","jsInitGenerator","skipFormat","tsConfigName","push","initTask","initGenerator","ensureDependencies","readNxJson","hasPlugin","plugins","some","p","plugin","addOrChangeBuildTarget","addOrChangeServeTarget","preview","addPreviewTarget","updateJson","joinPathFragments","json","compilerOptions","types","includes","uiFramework","createOrEditViteConfig","includeVitest","inSourceTests","rollupOptionsExternal","imports","compiler","undefined","vitestTask","vitestGenerator","coverageProvider","skipViteConfig","formatFiles","runTasksInSerial"],"mappings":";;;;;;;;IAgCsBA,0BAA0B;eAA1BA;;IA2OtB,OAA0C;eAA1C;;;;wBAlQO;oBAC0C;gCAe1C;sBAEmB;iCACE;oCAEO;AAE5B,eAAeA,2BACpBC,IAAU,EACVC,MAAwC;QAyItBC;QA5HlBD,SAEA,8EAA8E;IAC9E,8EAA8E;IAC9EA;IAfA,MAAME,QAA6B,EAAE;IAErC,MAAM,EACJC,OAAO,EACPC,WAAW,EACXC,MAAMC,WAAW,EAClB,GAAGC,IAAAA,gCAAwB,EAACR,MAAMC,OAAOQ,OAAO;IACjD,IAAIC,kBAAkB;IACtB,IAAIC,kBAAkB;IACtB,IAAIC,iBAAiB;;IAErBX,gBAAAA,UAAAA,QAAOY,oCAAPZ,QAAOY,aAAeR,gBAAgB;;IAItCJ,qBAAAA,WAAAA,QAAOa,8CAAPb,SAAOa,kBAAoB;IAE3B;;;GAGC,GACD,IAAIC,+BAA4C,CAAC;IAEjD,IAAI,CAACd,OAAOe,UAAU,EAAE;YA+FpBZ,kCAAAA;QA9FF,MAAMa,yBAAiD;YACrDC,OAAOjB,OAAOkB,WAAW;YACzBC,OAAOnB,OAAOoB,WAAW;YACzBC,MAAMrB,OAAOsB,UAAU;QACzB;QAEA,MAAM,EACJC,oBAAoB,EACpBC,kCAAkC,EAClCC,+BAA+B,EAC/BC,uBAAuB,EACxB,GAAGC,IAAAA,4CAA4B,EAACxB,SAASa;QAC1CF,+BAA+BY;QAC/B;;;;;;;;KAQC,GACD,IAAI,CAACH,qBAAqBN,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AAK,SAAS;YAClCC,IAAAA,sCAAsB,EACpB9D,MACA;gBACES,SAASR,OAAOQ,OAAO;gBACvBI,YAAYZ,OAAOY,UAAU;gBAC7BkD,eAAe9D,OAAO8D,aAAa;gBACnCC,eAAe/D,OAAO+D,aAAa;gBACnCC,uBAAuB;oBACrB;oBACA;oBACA;iBACD;gBACDC,SAAS;oBACPjE,OAAOkE,QAAQ,KAAK,QAChB,CAAC,4CAA4C,CAAC,GAC9C,CAAC,wCAAwC,CAAC;iBAC/C;gBACDpB,SAAS;oBAAC;iBAAU;YACtB,GACA,OACAqB;QAEJ,OAAO;YACLN,IAAAA,sCAAsB,EAAC9D,MAAMC,QAAQ,OAAOc;QAC9C;IACF;IAEA,IAAId,OAAO8D,aAAa,EAAE;QACxB,MAAMM,aAAa,MAAMC,IAAAA,wBAAe,EAACtE,MAAM;YAC7CS,SAASR,OAAOQ,OAAO;YACvBoD,aAAa5D,OAAO4D,WAAW;YAC/BG,eAAe/D,OAAO+D,aAAa;YACnCO,kBAAkB;YAClBC,gBAAgB;YAChBjD,YAAYX;YACZ2B,YAAY;QACd;QACApC,MAAMsC,IAAI,CAAC4B;IACb;IAEA,IAAI,CAACpE,OAAOsC,UAAU,EAAE;QACtB,MAAMkC,IAAAA,mBAAW,EAACzE;IACpB;IAEA,OAAO0E,IAAAA,wBAAgB,KAAIvE;AAC7B;MAEA,WAAeJ"}
@@ -1,5 +1,5 @@
1
- import { Tree } from '@nx/devkit';
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { InitGeneratorSchema } from './schema';
3
3
  export declare function updateNxJsonSettings(tree: Tree): void;
4
- export declare function initGenerator(tree: Tree, schema: InitGeneratorSchema): Promise<import("@nx/devkit").GeneratorCallback>;
4
+ export declare function initGenerator(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
5
5
  export default initGenerator;
@@ -16,9 +16,7 @@ _export(exports, {
16
16
  return _default;
17
17
  }
18
18
  });
19
- const _extends = require("@swc/helpers/_/_extends");
20
19
  const _devkit = require("@nx/devkit");
21
- const _js = require("@nx/js");
22
20
  const _utils = require("./lib/utils");
23
21
  function updateNxJsonSettings(tree) {
24
22
  var _nxJson_namedInputs, _nxJson_plugins;
@@ -46,18 +44,18 @@ function updateNxJsonSettings(tree) {
46
44
  (0, _devkit.updateNxJson)(tree, nxJson);
47
45
  }
48
46
  async function initGenerator(tree, schema) {
49
- (0, _utils.moveToDevDependencies)(tree);
47
+ if (process.env.NX_PCV3 === 'true') {
48
+ (0, _utils.addPlugin)(tree);
49
+ }
50
50
  updateNxJsonSettings(tree);
51
51
  const tasks = [];
52
- tasks.push(await (0, _js.initGenerator)(tree, _extends._({}, schema, {
53
- skipFormat: true,
54
- tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json'
55
- })));
56
- const addPlugins = process.env.NX_PCV3 === 'true';
57
- if (addPlugins) {
58
- (0, _utils.addPlugin)(tree);
52
+ if (!schema.skipPackageJson) {
53
+ tasks.push((0, _utils.moveToDevDependencies)(tree));
54
+ tasks.push((0, _utils.checkDependenciesInstalled)(tree, schema));
55
+ }
56
+ if (!schema.skipFormat) {
57
+ await (0, _devkit.formatFiles)(tree);
59
58
  }
60
- tasks.push((0, _utils.checkDependenciesInstalled)(tree, schema));
61
59
  return (0, _devkit.runTasksInSerial)(...tasks);
62
60
  }
63
61
  const _default = initGenerator;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"sourcesContent":["import { readNxJson, runTasksInSerial, Tree, updateNxJson } from '@nx/devkit';\n\nimport { initGenerator as jsInitGenerator } from '@nx/js';\n\nimport { InitGeneratorSchema } from './schema';\nimport {\n addPlugin,\n checkDependenciesInstalled,\n moveToDevDependencies,\n} from './lib/utils';\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 async function initGenerator(tree: Tree, schema: InitGeneratorSchema) {\n moveToDevDependencies(tree);\n updateNxJsonSettings(tree);\n const tasks = [];\n\n tasks.push(\n await jsInitGenerator(tree, {\n ...schema,\n skipFormat: true,\n tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',\n })\n );\n const addPlugins = process.env.NX_PCV3 === 'true';\n if (addPlugins) {\n addPlugin(tree);\n }\n tasks.push(checkDependenciesInstalled(tree, schema));\n return runTasksInSerial(...tasks);\n}\n\nexport default initGenerator;\n"],"names":["updateNxJsonSettings","initGenerator","tree","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","hasPlugin","plugins","some","p","plugin","targetDefaults","cache","inputs","updateNxJson","schema","moveToDevDependencies","tasks","jsInitGenerator","skipFormat","tsConfigName","rootProject","addPlugins","process","env","NX_PCV3","addPlugin","checkDependenciesInstalled","runTasksInSerial"],"mappings":";;;;;;;;IAWgBA,oBAAoB;eAApBA;;IAgCMC,aAAa;eAAbA;;IAoBtB,OAA6B;eAA7B;;;;wBA/DiE;oBAEhB;uBAO1C;AAEA,SAASD,qBAAqBE,IAAU;QAGnBC,qBAURA;IAZlB,MAAMA,SAASC,IAAAA,kBAAU,EAACF;IAE1B,MAAMG,qBAAoBF,sBAAAA,OAAOG,WAAW,qBAAlB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,WAAetB"}
1
+ {"version":3,"sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"sourcesContent":["import {\n formatFiles,\n GeneratorCallback,\n readNxJson,\n runTasksInSerial,\n Tree,\n updateNxJson,\n} from '@nx/devkit';\n\nimport { InitGeneratorSchema } from './schema';\nimport {\n addPlugin,\n checkDependenciesInstalled,\n moveToDevDependencies,\n} from './lib/utils';\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 async function initGenerator(tree: Tree, schema: InitGeneratorSchema) {\n if (process.env.NX_PCV3 === 'true') {\n addPlugin(tree);\n }\n\n updateNxJsonSettings(tree);\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":["updateNxJsonSettings","initGenerator","tree","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","hasPlugin","plugins","some","p","plugin","targetDefaults","cache","inputs","updateNxJson","schema","process","env","NX_PCV3","addPlugin","tasks","skipPackageJson","moveToDevDependencies","checkDependenciesInstalled","skipFormat","formatFiles","runTasksInSerial"],"mappings":";;;;;;;;IAgBgBA,oBAAoB;eAApBA;;IAgCMC,aAAa;eAAbA;;IAoBtB,OAA6B;eAA7B;;;wBA7DO;uBAOA;AAEA,SAASD,qBAAqBE,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,oBAAoB,gBAAgB;SACrC;IACH;IAEAe,IAAAA,oBAAY,EAAClB,MAAMC;AACrB;AAEO,eAAeF,cAAcC,IAAU,EAAEmB,MAA2B;IACzE,IAAIC,QAAQC,GAAG,CAACC,OAAO,KAAK,QAAQ;QAClCC,IAAAA,gBAAS,EAACvB;IACZ;IAEAF,qBAAqBE;IAErB,MAAMwB,QAA6B,EAAE;IACrC,IAAI,CAACL,OAAOM,eAAe,EAAE;QAC3BD,MAAMlB,IAAI,CAACoB,IAAAA,4BAAqB,EAAC1B;QACjCwB,MAAMlB,IAAI,CAACqB,IAAAA,iCAA0B,EAAC3B,MAAMmB;IAC9C;IAEA,IAAI,CAACA,OAAOS,UAAU,EAAE;QACtB,MAAMC,IAAAA,mBAAW,EAAC7B;IACpB;IAEA,OAAO8B,IAAAA,wBAAgB,KAAIN;AAC7B;MAEA,WAAezB"}
@@ -1,6 +1,6 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { InitGeneratorSchema } from '../schema';
3
3
  export declare function checkDependenciesInstalled(host: Tree, schema: InitGeneratorSchema): import("@nx/devkit").GeneratorCallback;
4
- export declare function moveToDevDependencies(tree: Tree): void;
4
+ export declare function moveToDevDependencies(tree: Tree): () => void;
5
5
  export declare function createVitestConfig(tree: Tree): void;
6
6
  export declare function addPlugin(tree: Tree): void;
@@ -22,47 +22,26 @@ _export(exports, {
22
22
  const _devkit = require("@nx/devkit");
23
23
  const _versions = require("../../../utils/versions");
24
24
  function checkDependenciesInstalled(host, schema) {
25
- const packageJson = (0, _devkit.readJson)(host, 'package.json');
26
- const devDependencies = {};
27
- const dependencies = {};
28
- packageJson.dependencies = packageJson.dependencies || {};
29
- packageJson.devDependencies = packageJson.devDependencies || {};
30
- // base deps
31
- devDependencies['@nx/vite'] = _versions.nxVersion;
32
- devDependencies['vite'] = _versions.viteVersion;
33
- devDependencies['vitest'] = _versions.vitestVersion;
34
- devDependencies['@vitest/ui'] = _versions.vitestVersion;
35
- if (schema.testEnvironment === 'jsdom') {
36
- devDependencies['jsdom'] = _versions.jsdomVersion;
37
- } else if (schema.testEnvironment === 'happy-dom') {
38
- devDependencies['happy-dom'] = _versions.happyDomVersion;
39
- } else if (schema.testEnvironment === 'edge-runtime') {
40
- devDependencies['@edge-runtime/vm'] = _versions.edgeRuntimeVmVersion;
41
- } else if (schema.testEnvironment !== 'node' && schema.testEnvironment) {
42
- _devkit.logger.info(`A custom environment was provided: ${schema.testEnvironment}. You need to install it manually.`);
43
- }
44
- if (schema.uiFramework === 'react') {
45
- if (schema.compiler === 'swc') {
46
- devDependencies['@vitejs/plugin-react-swc'] = _versions.vitePluginReactSwcVersion;
47
- } else {
48
- devDependencies['@vitejs/plugin-react'] = _versions.vitePluginReactVersion;
49
- }
50
- }
51
- if (schema.includeLib) {
52
- devDependencies['vite-plugin-dts'] = _versions.vitePluginDtsVersion;
53
- }
54
- return (0, _devkit.addDependenciesToPackageJson)(host, dependencies, devDependencies);
25
+ return (0, _devkit.addDependenciesToPackageJson)(host, {}, {
26
+ '@nx/vite': _versions.nxVersion,
27
+ vite: _versions.viteVersion,
28
+ vitest: _versions.vitestVersion,
29
+ '@vitest/ui': _versions.vitestVersion
30
+ });
55
31
  }
56
32
  function moveToDevDependencies(tree) {
33
+ let wasUpdated = false;
57
34
  (0, _devkit.updateJson)(tree, 'package.json', (packageJson)=>{
58
35
  packageJson.dependencies = packageJson.dependencies || {};
59
36
  packageJson.devDependencies = packageJson.devDependencies || {};
60
37
  if (packageJson.dependencies['@nx/vite']) {
61
38
  packageJson.devDependencies['@nx/vite'] = packageJson.dependencies['@nx/vite'];
62
39
  delete packageJson.dependencies['@nx/vite'];
40
+ wasUpdated = true;
63
41
  }
64
42
  return packageJson;
65
43
  });
44
+ return wasUpdated ? ()=>(0, _devkit.installPackagesTask)(tree) : ()=>{};
66
45
  }
67
46
  function createVitestConfig(tree) {
68
47
  var _nxJson_namedInputs;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../packages/vite/src/generators/init/lib/utils.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n logger,\n readJson,\n readNxJson,\n Tree,\n updateJson,\n updateNxJson,\n} from '@nx/devkit';\n\nimport {\n edgeRuntimeVmVersion,\n happyDomVersion,\n jsdomVersion,\n nxVersion,\n vitePluginDtsVersion,\n vitePluginReactSwcVersion,\n vitePluginReactVersion,\n vitestVersion,\n viteVersion,\n} from '../../../utils/versions';\nimport { InitGeneratorSchema } from '../schema';\n\nexport function checkDependenciesInstalled(\n host: Tree,\n schema: InitGeneratorSchema\n) {\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'] = vitestVersion;\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\nexport function 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 updateNxJson(tree, nxJson);\n}\n\nexport function addPlugin(tree: Tree) {\n const nxJson = readNxJson(tree);\n nxJson.plugins ??= [];\n\n for (const plugin of nxJson.plugins) {\n if (\n typeof plugin === 'string'\n ? plugin === '@nx/vite/plugin'\n : plugin.plugin === '@nx/vite/plugin'\n ) {\n return;\n }\n }\n\n nxJson.plugins.push({\n plugin: '@nx/vite/plugin',\n options: {\n buildTargetName: 'build',\n previewTargetName: 'preview',\n testTargetName: 'test',\n serveTargetName: 'serve',\n serveStaticTargetName: 'serve-static',\n },\n });\n updateNxJson(tree, nxJson);\n}\n"],"names":["checkDependenciesInstalled","moveToDevDependencies","createVitestConfig","addPlugin","host","schema","packageJson","readJson","devDependencies","dependencies","nxVersion","viteVersion","vitestVersion","testEnvironment","jsdomVersion","happyDomVersion","edgeRuntimeVmVersion","logger","info","uiFramework","compiler","vitePluginReactSwcVersion","vitePluginReactVersion","includeLib","vitePluginDtsVersion","addDependenciesToPackageJson","tree","updateJson","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","updateNxJson","plugins","plugin","options","buildTargetName","previewTargetName","testTargetName","serveTargetName","serveStaticTargetName"],"mappings":";;;;;;;;IAuBgBA,0BAA0B;eAA1BA;;IA2CAC,qBAAqB;eAArBA;;IAcAC,kBAAkB;eAAlBA;;IAgBAC,SAAS;eAATA;;;wBAxFT;0BAYA;AAGA,SAASH,2BACdI,IAAU,EACVC,MAA2B;IAE3B,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;IAE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AAYG,YAAY,CAAC,WAAW;QAC7C;QACA,OAAOH;IACT;AACF;AAEO,SAASJ,mBAAmBwB,IAAU;QAGjBE;IAF1B,MAAMA,SAASC,IAAAA,kBAAU,EAACH;IAE1B,MAAMI,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;IAEAO,IAAAA,oBAAY,EAACX,MAAME;AACrB;AAEO,SAASzB,UAAUuB,IAAU;QAElCE;IADA,MAAMA,SAASC,IAAAA,kBAAU,EAACH;;IAC1BE,aAAAA,UAAAA,QAAOU,8BAAPV,QAAOU,UAAY,EAAE;IAErB,KAAK,MAAMC,UAAUX,OAAOU,OAAO,CAAE;QACnC,IACE,OAAOC,WAAW,WACdA,WAAW,oBACXA,OAAOA,MAAM,KAAK,mBACtB;YACA;QACF;IACF;IAEAX,OAAOU,OAAO,CAACL,IAAI,CAAC;QAClBM,QAAQ;QACRC,SAAS;YACPC,iBAAiB;YACjBC,mBAAmB;YACnBC,gBAAgB;YAChBC,iBAAiB;YACjBC,uBAAuB;QACzB;IACF;IACAR,IAAAA,oBAAY,EAACX,MAAME;AACrB"}
1
+ {"version":3,"sources":["../../../../../../../packages/vite/src/generators/init/lib/utils.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n installPackagesTask,\n readNxJson,\n Tree,\n updateJson,\n updateNxJson,\n} from '@nx/devkit';\nimport { nxVersion, vitestVersion, viteVersion } from '../../../utils/versions';\nimport { InitGeneratorSchema } from '../schema';\n\nexport function checkDependenciesInstalled(\n host: Tree,\n schema: InitGeneratorSchema\n) {\n return addDependenciesToPackageJson(\n host,\n {},\n {\n '@nx/vite': nxVersion,\n vite: viteVersion,\n vitest: vitestVersion,\n '@vitest/ui': vitestVersion,\n }\n );\n}\n\nexport function moveToDevDependencies(tree: Tree) {\n let wasUpdated = false;\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 wasUpdated = true;\n }\n return packageJson;\n });\n\n return wasUpdated ? () => installPackagesTask(tree) : () => {};\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 updateNxJson(tree, nxJson);\n}\n\nexport function addPlugin(tree: Tree) {\n const nxJson = readNxJson(tree);\n nxJson.plugins ??= [];\n\n for (const plugin of nxJson.plugins) {\n if (\n typeof plugin === 'string'\n ? plugin === '@nx/vite/plugin'\n : plugin.plugin === '@nx/vite/plugin'\n ) {\n return;\n }\n }\n\n nxJson.plugins.push({\n plugin: '@nx/vite/plugin',\n options: {\n buildTargetName: 'build',\n previewTargetName: 'preview',\n testTargetName: 'test',\n serveTargetName: 'serve',\n serveStaticTargetName: 'serve-static',\n },\n });\n updateNxJson(tree, nxJson);\n}\n"],"names":["checkDependenciesInstalled","moveToDevDependencies","createVitestConfig","addPlugin","host","schema","addDependenciesToPackageJson","nxVersion","vite","viteVersion","vitest","vitestVersion","tree","wasUpdated","updateJson","packageJson","dependencies","devDependencies","installPackagesTask","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","updateNxJson","plugins","plugin","options","buildTargetName","previewTargetName","testTargetName","serveTargetName","serveStaticTargetName"],"mappings":";;;;;;;;IAWgBA,0BAA0B;eAA1BA;;IAgBAC,qBAAqB;eAArBA;;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,WAAW,WACdA,WAAW,oBACXA,OAAOA,MAAM,KAAK,mBACtB;YACA;QACF;IACF;IAEAX,OAAOU,OAAO,CAACL,IAAI,CAAC;QAClBM,QAAQ;QACRC,SAAS;YACPC,iBAAiB;YACjBC,mBAAmB;YACnBC,gBAAgB;YAChBC,iBAAiB;YACjBC,uBAAuB;QACzB;IACF;IACAR,IAAAA,oBAAY,EAAChB,MAAMO;AACrB"}
@@ -1,7 +1,4 @@
1
1
  export interface InitGeneratorSchema {
2
- uiFramework: 'react' | 'none';
3
- compiler?: 'babel' | 'swc';
4
- includeLib?: boolean;
5
- testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
6
- rootProject?: boolean;
2
+ skipFormat?: boolean;
3
+ skipPackageJson?: boolean;
7
4
  }
@@ -5,30 +5,15 @@
5
5
  "$id": "init-vite-plugin",
6
6
  "type": "object",
7
7
  "properties": {
8
- "uiFramework": {
9
- "type": "string",
10
- "description": "UI Framework to use for Vite.",
11
- "enum": ["react", "none"],
12
- "default": "react",
13
- "x-prompt": "What UI framework plugin should Vite use?"
14
- },
15
- "compiler": {
16
- "type": "string",
17
- "description": "Compiler to use for Vite when UI Framework is React.",
18
- "enum": ["babel", "swc"],
19
- "default": "babel"
20
- },
21
- "includeLib": {
8
+ "skipFormat": {
9
+ "description": "Skip formatting files.",
22
10
  "type": "boolean",
23
- "description": "Add dependencies needed to build libraries.",
24
11
  "default": false
25
12
  },
26
- "testEnvironment": {
27
- "description": "The vitest environment to use. See https://vitest.dev/config/#environment.",
28
- "type": "string",
29
- "enum": ["node", "jsdom", "happy-dom", "edge-runtime"],
30
- "default": "jsdom"
13
+ "skipPackageJson": {
14
+ "description": "Do not add dependencies to `package.json`.",
15
+ "type": "boolean",
16
+ "default": false
31
17
  }
32
- },
33
- "examplesFile": "../../../docs/init-examples.md"
18
+ }
34
19
  }
@@ -20,6 +20,7 @@ const _init = require("../init/init");
20
20
  const _versions = require("../../utils/versions");
21
21
  const _js = require("@nx/js");
22
22
  const _path = require("path");
23
+ const _ensuredependencies = require("../../utils/ensure-dependencies");
23
24
  async function vitestGenerator(tree, schema, hasPlugin = false) {
24
25
  var _nxJson_plugins;
25
26
  const tasks = [];
@@ -31,11 +32,14 @@ async function vitestGenerator(tree, schema, hasPlugin = false) {
31
32
  const testTarget = (_ref = (_schema_testTarget = schema.testTarget) != null ? _schema_testTarget : (0, _generatorutils.findExistingTargetsInProject)(targets).validFoundTargetName.test) != null ? _ref : 'test';
32
33
  (0, _generatorutils.addOrChangeTestTarget)(tree, schema, testTarget);
33
34
  }
35
+ tasks.push(await (0, _js.initGenerator)(tree, _extends._({}, schema, {
36
+ skipFormat: true
37
+ })));
34
38
  const initTask = await (0, _init.default)(tree, {
35
- uiFramework: schema.uiFramework,
36
- testEnvironment: schema.testEnvironment
39
+ skipFormat: true
37
40
  });
38
41
  tasks.push(initTask);
42
+ tasks.push((0, _ensuredependencies.ensureDependencies)(tree, schema));
39
43
  if (!schema.skipViteConfig) {
40
44
  if (schema.uiFramework === 'react') {
41
45
  (0, _generatorutils.createOrEditViteConfig)(tree, {
@@ -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 offsetFromRoot,\n readNxJson,\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 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 hasPlugin = false\n) {\n const tasks: GeneratorCallback[] = [];\n\n const { targets, root, projectType } = readProjectConfiguration(\n tree,\n schema.project\n );\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 =\n schema.testTarget ??\n findExistingTargetsInProject(targets).validFoundTargetName.test ??\n 'test';\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 imports: [`import react from '@vitejs/plugin-react'`],\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);\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 '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","tree","schema","hasPlugin","nxJson","tasks","targets","root","projectType","readProjectConfiguration","project","readNxJson","hasPluginCheck","plugins","some","p","plugin","testTarget","findExistingTargetsInProject","validFoundTargetName","test","addOrChangeTestTarget","initTask","initGenerator","uiFramework","testEnvironment","push","skipViteConfig","createOrEditViteConfig","includeLib","includeVitest","inSourceTests","rollupOptionsExternal","imports","coverageProvider","createFiles","updateTsConfig","coverageProviderDependency","getCoverageProviderDependency","installCoverageProviderTask","addDependenciesToPackageJson","skipFormat","formatFiles","runTasksInSerial","options","projectRoot","exists","joinPathFragments","updateJson","json","compilerOptions","types","includes","references","r","path","tsconfigLibPath","tsconfigAppPath","addTsLibDependencies","generateFiles","join","__dirname","tmpl","offsetFromRoot","vitestCoverageV8Version","vitestCoverageIstanbulVersion"],"mappings":";;;;;;;;IA6BsBA,eAAe;eAAfA;;IAwMtB,OAA+B;eAA/B;;;;wBAzNO;gCAKA;sBAGmB;0BAInB;oBAE8B;sBAChB;AAEd,eAAeA,gBACpBC,IAAU,EACVC,MAA6B,EAC7BC,YAAY,KAAK;QAUMC;IARvB,MAAMC,QAA6B,EAAE;IAErC,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGC,IAAAA,gCAAwB,EAC7DR,MACAC,OAAOQ,OAAO;IAGhB,MAAMN,SAASO,IAAAA,kBAAU,EAACV;IAC1B,MAAMW,kBAAiBR,kBAAAA,OAAOS,OAAO,qBAAdT,gBAAgBU,IAAI,CACzC,CAACC,IACC,AAAC,CAAA,OAAOA,MAAM,WACVA,MAAM,oBACNA,EAAEC,MAAM,KAAK,iBAAgB,KAAMb;IAE3C,IAAI,CAACS,gBAAgB;YAEjBV,oBAAAA;QADF,MAAMe,aACJf,CAAAA,OAAAA,CAAAA,qBAAAA,OAAOe,UAAU,YAAjBf,qBACAgB,IAAAA,4CAA4B,EAACZ,SAASa,oBAAoB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YACA,OAAOF;QACT;IAEJ;IAEA,IAAIL,QAAQb,aAAa,EAAE;QACzB,MAAMyB,kBAAkBT,IAAAA,yBAAiB,EAACF,aAAa;QACvD,MAAMY,kBAAkBV,IAAAA,yBAAiB,EAACF,aAAa;QACvD,IAAI5C,KAAK6C,MAAM,CAACU,kBAAkB;YAChCR,IAAAA,kBAAU,EACR/C,MACA8C,IAAAA,yBAAiB,EAACF,aAAa,sBAC/B,CAACI;oBACEA;;gBAAAA,CAAAA,WAAAA,wBAAAA,KAAKC,eAAe,EAACC,0BAArBF,sBAAqBE,QAAU,EAAE,AAAD,EAAGzB,IAAI,CAAC;gBACzC,OAAOuB;YACT;QAEJ,OAAO,IAAIhD,KAAK6C,MAAM,CAACW,kBAAkB;YACvCT,IAAAA,kBAAU,EACR/C,MACA8C,IAAAA,yBAAiB,EAACF,aAAa,sBAC/B,CAACI;oBACEA;;gBAAAA,CAAAA,WAAAA,wBAAAA,KAAKC,eAAe,EAACC,0BAArBF,sBAAqBE,QAAU,EAAE,AAAD,EAAGzB,IAAI,CAAC;gBACzC,OAAOuB;YACT;QAEJ;QAEAS,IAAAA,wBAAoB,EAACzD;IACvB;AACF;AAEA,SAASkC,YACPlC,IAAU,EACV2C,OAA8B,EAC9BC,WAAmB;IAEnBc,IAAAA,qBAAa,EAAC1D,MAAM2D,IAAAA,UAAI,EAACC,WAAW,UAAUhB,aAAa;QACzDiB,MAAM;OACHlB;QACHC;QACAkB,gBAAgBA,IAAAA,sBAAc,EAAClB;;AAEnC;AAEA,SAASP,8BACPJ,gBAA2D;IAE3D,OAAQA;QACN,KAAK;YACH,OAAO;gBACL,uBAAuB8B,iCAAuB;YAChD;QACF,KAAK;YACH,OAAO;gBACL,6BAA6BC,uCAA6B;YAC5D;QACF;YACE,OAAO;gBACL,uBAAuBD,iCAAuB;YAChD;IACJ;AACF;MAEA,WAAehE"}
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 offsetFromRoot,\n readNxJson,\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 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 async function vitestGenerator(\n tree: Tree,\n schema: VitestGeneratorSchema,\n hasPlugin = false\n) {\n const tasks: GeneratorCallback[] = [];\n\n const { targets, root, projectType } = readProjectConfiguration(\n tree,\n schema.project\n );\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 =\n schema.testTarget ??\n findExistingTargetsInProject(targets).validFoundTargetName.test ??\n 'test';\n addOrChangeTestTarget(tree, schema, testTarget);\n }\n\n tasks.push(await jsInitGenerator(tree, { ...schema, skipFormat: true }));\n const initTask = await initGenerator(tree, { skipFormat: true });\n tasks.push(initTask);\n tasks.push(ensureDependencies(tree, schema));\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: [`import react from '@vitejs/plugin-react'`],\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);\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 '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","tree","schema","hasPlugin","nxJson","tasks","targets","root","projectType","readProjectConfiguration","project","readNxJson","hasPluginCheck","plugins","some","p","plugin","testTarget","findExistingTargetsInProject","validFoundTargetName","test","addOrChangeTestTarget","push","jsInitGenerator","skipFormat","initTask","initGenerator","ensureDependencies","skipViteConfig","uiFramework","createOrEditViteConfig","includeLib","includeVitest","inSourceTests","rollupOptionsExternal","imports","coverageProvider","createFiles","updateTsConfig","coverageProviderDependency","getCoverageProviderDependency","installCoverageProviderTask","addDependenciesToPackageJson","formatFiles","runTasksInSerial","options","projectRoot","exists","joinPathFragments","updateJson","json","compilerOptions","types","includes","references","r","path","tsconfigLibPath","tsconfigAppPath","addTsLibDependencies","generateFiles","join","__dirname","tmpl","offsetFromRoot","vitestCoverageV8Version","vitestCoverageIstanbulVersion"],"mappings":";;;;;;;;IA8BsBA,eAAe;eAAfA;;IAwMtB,OAA+B;eAA/B;;;;wBA1NO;gCAKA;sBAGmB;0BAInB;oBAEgE;sBAClD;oCACc;A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AAAA,CAAAA,WAAAA,wBAAAA,KAAKC,eAAe,EAACC,0BAArBF,sBAAqBE,QAAU,EAAE,AAAD,EAAG9B,IAAI,CAAC;gBACzC,OAAO4B;YACT;QAEJ;QAEAS,IAAAA,wBAAoB,EAAC1D;IACvB;AACF;AAEA,SAASoC,YACPpC,IAAU,EACV4C,OAA8B,EAC9BC,WAAmB;IAEnBc,IAAAA,qBAAa,EAAC3D,MAAM4D,IAAAA,UAAI,EAACC,WAAW,UAAUhB,aAAa;QACzDiB,MAAM;OACHlB;QACHC;QACAkB,gBAAgBA,IAAAA,sBAAc,EAAClB;;AAEnC;AAEA,SAASN,8BACPJ,gBAA2D;IAE3D,OAAQA;QACN,KAAK;YACH,OAAO;gBACL,uBAAuB6B,iCAAuB;YAChD;QACF,KAAK;YACH,OAAO;gBACL,6BAA6BC,uCAA6B;YAC5D;QACF;YACE,OAAO;gBACL,uBAAuBD,iCAAuB;YAChD;IACJ;AACF;MAEA,WAAejE"}
@@ -0,0 +1,8 @@
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
+ export type EnsureDependenciesOptions = {
3
+ uiFramework: 'react' | 'none';
4
+ compiler?: 'babel' | 'swc';
5
+ includeLib?: boolean;
6
+ testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
7
+ };
8
+ export declare function ensureDependencies(host: Tree, schema: EnsureDependenciesOptions): GeneratorCallback;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "ensureDependencies", {
3
+ enumerable: true,
4
+ get: function() {
5
+ return ensureDependencies;
6
+ }
7
+ });
8
+ const _devkit = require("@nx/devkit");
9
+ const _versions = require("./versions");
10
+ function ensureDependencies(host, schema) {
11
+ const devDependencies = {};
12
+ if (schema.testEnvironment === 'jsdom') {
13
+ devDependencies['jsdom'] = _versions.jsdomVersion;
14
+ } else if (schema.testEnvironment === 'happy-dom') {
15
+ devDependencies['happy-dom'] = _versions.happyDomVersion;
16
+ } else if (schema.testEnvironment === 'edge-runtime') {
17
+ devDependencies['@edge-runtime/vm'] = _versions.edgeRuntimeVmVersion;
18
+ } else if (schema.testEnvironment !== 'node' && schema.testEnvironment) {
19
+ _devkit.logger.info(`A custom environment was provided: ${schema.testEnvironment}. You need to install it manually.`);
20
+ }
21
+ if (schema.uiFramework === 'react') {
22
+ if (schema.compiler === 'swc') {
23
+ devDependencies['@vitejs/plugin-react-swc'] = _versions.vitePluginReactSwcVersion;
24
+ } else {
25
+ devDependencies['@vitejs/plugin-react'] = _versions.vitePluginReactVersion;
26
+ }
27
+ }
28
+ if (schema.includeLib) {
29
+ devDependencies['vite-plugin-dts'] = _versions.vitePluginDtsVersion;
30
+ }
31
+ return (0, _devkit.addDependenciesToPackageJson)(host, {}, devDependencies);
32
+ }
33
+
34
+ //# sourceMappingURL=ensure-dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/vite/src/utils/ensure-dependencies.ts"],"sourcesContent":["import {\n addDependenciesToPackageJson,\n logger,\n type GeneratorCallback,\n type Tree,\n} from '@nx/devkit';\nimport {\n edgeRuntimeVmVersion,\n happyDomVersion,\n jsdomVersion,\n vitePluginDtsVersion,\n vitePluginReactSwcVersion,\n vitePluginReactVersion,\n} from './versions';\n\nexport type EnsureDependenciesOptions = {\n uiFramework: 'react' | 'none';\n compiler?: 'babel' | 'swc';\n includeLib?: boolean;\n testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;\n};\n\nexport function ensureDependencies(\n host: Tree,\n schema: EnsureDependenciesOptions\n): GeneratorCallback {\n const devDependencies: Record<string, string> = {};\n\n if (schema.testEnvironment === 'jsdom') {\n devDependencies['jsdom'] = jsdomVersion;\n } else if (schema.testEnvironment === 'happy-dom') {\n devDependencies['happy-dom'] = happyDomVersion;\n } else if (schema.testEnvironment === 'edge-runtime') {\n devDependencies['@edge-runtime/vm'] = edgeRuntimeVmVersion;\n } else if (schema.testEnvironment !== 'node' && schema.testEnvironment) {\n logger.info(\n `A custom environment was provided: ${schema.testEnvironment}. You need to install it manually.`\n );\n }\n\n if (schema.uiFramework === 'react') {\n if (schema.compiler === 'swc') {\n devDependencies['@vitejs/plugin-react-swc'] = vitePluginReactSwcVersion;\n } else {\n devDependencies['@vitejs/plugin-react'] = vitePluginReactVersion;\n }\n }\n\n if (schema.includeLib) {\n devDependencies['vite-plugin-dts'] = vitePluginDtsVersion;\n }\n\n return addDependenciesToPackageJson(host, {}, devDependencies);\n}\n"],"names":["ensureDependencies","host","schema","devDependencies","testEnvironment","jsdomVersion","happyDomVersion","edgeRuntimeVmVersion","logger","info","uiFramework","compiler","vitePluginReactSwcVersion","vitePluginReactVersion","includeLib","vitePluginDtsVersion","addDependenciesToPackageJson"],"mappings":";+BAsBgBA;;;eAAAA;;;wBAjBT;0BAQA;AASA,SAASA,mBACdC,IAAU,EACVC,MAAiC;IAEjC,MAAMC,kBAA0C,CAAC;IAEjD,IAAID,OAAOE,eAAe,KAAK,SAAS;QACtCD,eAAe,CAAC,QAAQ,GAAGE,sBAAY;IACzC,OAAO,IAAIH,OAAOE,eAAe,KAAK,aAAa;QACjDD,eAAe,CAAC,YAAY,GAAGG,yBAAe;IAChD,OAAO,IAAIJ,OAAOE,eAAe,KAAK,gBAAgB;QACpDD,eAAe,CAAC,mBAAmB,GAAGI,8BAAoB;IAC5D,OAAO,IAAIL,OAAOE,eAAe,KAAK,UAAUF,OAAOE,eAAe,EAAE;QACtEI,cAAM,CAACC,IAAI,CACT,CAAC,mCAAmC,EAAEP,OAAOE,eAAe,CAAC,kCAAkC,CAAC;IAEpG;IAEA,IAAIF,OAAOQ,WAAW,KAAK,SAAS;QAClC,IAAIR,OAAOS,QAAQ,KAAK,OAAO;YAC7BR,eAAe,CAAC,2BAA2B,GAAGS,mCAAyB;QACzE,OAAO;YACLT,eAAe,CAAC,uBAAuB,GAAGU,gCAAsB;QAClE;IACF;IAEA,IAAIX,OAAOY,UAAU,EAAE;QACrBX,eAAe,CAAC,kBAAkB,GAAGY,8BAAoB;IAC3D;IAEA,OAAOC,IAAAA,oCAA4B,EAACf,MAAM,CAAC,GAAGE;AAChD"}