@nx/vite 16.9.0-beta.1 → 16.9.0-beta.2
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 +5 -5
- package/src/generators/configuration/configuration.js +22 -1
- package/src/generators/configuration/configuration.js.map +1 -1
- package/src/generators/init/init.js +1 -1
- package/src/generators/init/init.js.map +1 -1
- package/src/generators/vitest/vitest-generator.js +69 -25
- package/src/generators/vitest/vitest-generator.js.map +1 -1
- package/src/utils/generator-utils.d.ts +12 -1
- package/src/utils/generator-utils.js +36 -42
- package/src/utils/generator-utils.js.map +1 -1
- package/src/utils/test-files/test-vite-configs.d.ts +9 -10
- package/src/utils/test-files/test-vite-configs.js +26 -52
- package/src/utils/test-files/test-vite-configs.js.map +1 -1
- package/src/utils/test-utils.js +2 -4
- package/src/utils/test-utils.js.map +1 -1
- package/src/utils/vite-config-edit-utils.d.ts +1 -1
- package/src/utils/vite-config-edit-utils.js +48 -22
- package/src/utils/vite-config-edit-utils.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "16.9.0-beta.
|
|
3
|
+
"version": "16.9.0-beta.2",
|
|
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.
|
|
33
|
-
"@nx/devkit": "16.9.0-beta.
|
|
34
|
-
"@nx/js": "16.9.0-beta.
|
|
32
|
+
"@nrwl/vite": "16.9.0-beta.2",
|
|
33
|
+
"@nx/devkit": "16.9.0-beta.2",
|
|
34
|
+
"@nx/js": "16.9.0-beta.2",
|
|
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": "
|
|
60
|
+
"gitHead": "e11d538fa2c7266066d554d9405abab8e0a65040"
|
|
61
61
|
}
|
|
@@ -141,7 +141,28 @@ async function viteConfigurationGenerator(tree, schema) {
|
|
|
141
141
|
return json;
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
|
|
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,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,qBAAoB,EACpBC,mCAAkC,EAClCC,gCAA+B,EAC/BC,wBAAuB,EACxB,GAAGC,IAAAA,4CAA4B,EAACvB,SAASY;QAC1CF,+BAA+BY;QAC/B;;;;;;;;KAQC,GACD,IAAI,CAACH,qBAAqBN,KAAK,IAAIO,oCAAoC;YACrE,MAAM,IAAII,MACR,CAAC,YAAY,EAAE1B,OAAOM,OAAO,CAAC,mDAAmD,CAAC,EAClF;QACJ,CAAC;QAED,IACEkB,wBAAwBT,KAAK,IAC5BS,CAAAA,wBAAwBP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ACpB,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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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","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,
|
|
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":";;;;;;;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,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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
json.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
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","vitestCoverageV8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AAiB,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,OAA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teConfigurationG
|
|
|
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
|
|
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=
|
|
376
|
-
tree.write(`${projectConfig.root}/index.html`, indexHtmlContent.replace('</body>', `<script type=
|
|
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=
|
|
384
|
+
<html lang='en'>
|
|
385
385
|
<head>
|
|
386
|
-
<meta charset=
|
|
387
|
-
<link rel=
|
|
388
|
-
<meta name=
|
|
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=
|
|
393
|
-
<script type=
|
|
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.
|
|
417
|
+
external: [${(_options_rollupOptionsExternal = options.rollupOptionsExternal) != null ? _options_rollupOptionsExternal : ''}]
|
|
417
418
|
}
|
|
418
419
|
},` : ``;
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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,
|
|
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=
|
|
468
|
+
/// <reference types='vitest' />
|
|
470
469
|
import { defineConfig } from 'vite';
|
|
471
|
-
${
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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.
|
|
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,
|
|
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
|
|