@nx/vite 18.1.0-beta.0 → 18.1.0-beta.10
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/migrations.json +21 -0
- package/package.json +5 -5
- package/src/executors/test/lib/utils.d.ts +2 -2
- package/src/executors/test/lib/utils.js +22 -12
- package/src/executors/test/lib/utils.js.map +1 -1
- package/src/executors/test/schema.d.ts +1 -0
- package/src/executors/test/schema.json +4 -0
- package/src/executors/test/vitest.impl.js +3 -3
- package/src/executors/test/vitest.impl.js.map +1 -1
- package/src/generators/configuration/configuration.js +13 -74
- package/src/generators/configuration/configuration.js.map +1 -1
- package/src/generators/configuration/lib/convert-non-vite.d.ts +5 -0
- package/src/generators/configuration/lib/convert-non-vite.js +62 -0
- package/src/generators/configuration/lib/convert-non-vite.js.map +1 -0
- package/src/generators/configuration/schema.d.ts +0 -3
- package/src/generators/configuration/schema.json +0 -12
- package/src/generators/init/init.js +3 -1
- package/src/generators/init/init.js.map +1 -1
- package/src/generators/vitest/vitest-generator.js +8 -3
- package/src/generators/vitest/vitest-generator.js.map +1 -1
- package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js +2 -16
- package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js.map +1 -1
- package/src/migrations/update-17-2-0/update-vite-config.js +2 -16
- package/src/migrations/update-17-2-0/update-vite-config.js.map +1 -1
- package/src/utils/executor-utils.d.ts +1 -0
- package/src/utils/executor-utils.js +6 -0
- package/src/utils/executor-utils.js.map +1 -1
- package/src/{migrations/update-17-2-0/lib → utils}/find-vite-config.d.ts +1 -0
- package/src/utils/find-vite-config.js +46 -0
- package/src/utils/find-vite-config.js.map +1 -0
- package/src/utils/generator-utils.d.ts +8 -11
- package/src/utils/generator-utils.js +71 -186
- package/src/utils/generator-utils.js.map +1 -1
- package/src/utils/test-utils.d.ts +1 -1
- package/src/utils/test-utils.js +10 -18
- package/src/utils/test-utils.js.map +1 -1
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/src/utils/versions.js.map +1 -1
- package/src/migrations/update-17-2-0/lib/find-vite-config.js +0 -25
- package/src/migrations/update-17-2-0/lib/find-vite-config.js.map +0 -1
- package/src/utils/test-files/react-project.config.json +0 -82
- package/src/utils/test-files/web-project.config.json +0 -69
package/migrations.json
CHANGED
|
@@ -53,6 +53,27 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"packageJsonUpdates": {
|
|
56
|
+
"18.1.0": {
|
|
57
|
+
"version": "18.1.0-beta.1",
|
|
58
|
+
"packages": {
|
|
59
|
+
"vitest": {
|
|
60
|
+
"version": "^1.3.1",
|
|
61
|
+
"alwaysAddToPackageJson": false
|
|
62
|
+
},
|
|
63
|
+
"@vitest/coverage-v8": {
|
|
64
|
+
"version": "^1.3.1",
|
|
65
|
+
"alwaysAddToPackageJson": false
|
|
66
|
+
},
|
|
67
|
+
"@vitest/ui": {
|
|
68
|
+
"version": "^1.3.1",
|
|
69
|
+
"alwaysAddToPackageJson": false
|
|
70
|
+
},
|
|
71
|
+
"@vitest/coverage-istanbul": {
|
|
72
|
+
"version": "^1.3.1",
|
|
73
|
+
"alwaysAddToPackageJson": false
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
56
77
|
"17.3.0": {
|
|
57
78
|
"version": "17.3.0-beta.0",
|
|
58
79
|
"packages": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "18.1.0-beta.
|
|
3
|
+
"version": "18.1.0-beta.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for building and testing applications using Vite",
|
|
6
6
|
"repository": {
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"migrations": "./migrations.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nx/devkit": "18.1.0-beta.
|
|
32
|
+
"@nx/devkit": "18.1.0-beta.10",
|
|
33
33
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
34
34
|
"@swc/helpers": "~0.5.0",
|
|
35
35
|
"enquirer": "~2.3.6",
|
|
36
|
-
"@nx/js": "18.1.0-beta.
|
|
36
|
+
"@nx/js": "18.1.0-beta.10",
|
|
37
37
|
"tsconfig-paths": "^4.1.2",
|
|
38
|
-
"@nrwl/vite": "18.1.0-beta.
|
|
38
|
+
"@nrwl/vite": "18.1.0-beta.10"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"vite": "^5.0.0",
|
|
42
|
-
"vitest": "^1.
|
|
42
|
+
"vitest": "^1.3.1"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { VitestExecutorOptions } from '../schema';
|
|
3
|
-
export declare function getOptions(options: VitestExecutorOptions, context: ExecutorContext, projectRoot: string
|
|
4
|
-
export declare function
|
|
3
|
+
export declare function getOptions(options: VitestExecutorOptions, context: ExecutorContext, projectRoot: string): Promise<Record<string, any>>;
|
|
4
|
+
export declare function getOptionsAsArgv(obj: Record<string, any>): string[];
|
|
@@ -9,8 +9,8 @@ _export(exports, {
|
|
|
9
9
|
getOptions: function() {
|
|
10
10
|
return getOptions;
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
return
|
|
12
|
+
getOptionsAsArgv: function() {
|
|
13
|
+
return getOptionsAsArgv;
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
const _extends = require("@swc/helpers/_/_extends");
|
|
@@ -18,7 +18,7 @@ const _devkit = require("@nx/devkit");
|
|
|
18
18
|
const _optionsutils = require("../../../utils/options-utils");
|
|
19
19
|
const _path = require("path");
|
|
20
20
|
const _executorutils = require("../../../utils/executor-utils");
|
|
21
|
-
async function getOptions(options, context, projectRoot
|
|
21
|
+
async function getOptions(options, context, projectRoot) {
|
|
22
22
|
var _resolved_config, _resolved_config1;
|
|
23
23
|
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
24
24
|
const { loadConfigFromFile, mergeConfig } = await (0, _executorutils.loadViteDynamicImport)();
|
|
@@ -32,9 +32,9 @@ async function getOptions(options, context, projectRoot, extraArgs) {
|
|
|
32
32
|
You can read more here: https://nx.dev/nx-api/vite/generators/vitest
|
|
33
33
|
`);
|
|
34
34
|
}
|
|
35
|
-
var
|
|
35
|
+
var _options_mode;
|
|
36
36
|
const resolved = await loadConfigFromFile({
|
|
37
|
-
mode: (
|
|
37
|
+
mode: (_options_mode = options == null ? void 0 : options.mode) != null ? _options_mode : 'production',
|
|
38
38
|
command: 'serve'
|
|
39
39
|
}, viteConfigPath);
|
|
40
40
|
if (!viteConfigPath || !(resolved == null ? void 0 : (_resolved_config = resolved.config) == null ? void 0 : _resolved_config['test'])) {
|
|
@@ -45,8 +45,13 @@ async function getOptions(options, context, projectRoot, extraArgs) {
|
|
|
45
45
|
`);
|
|
46
46
|
}
|
|
47
47
|
const root = projectRoot === '.' ? process.cwd() : (0, _path.relative)(context.cwd, (0, _devkit.joinPathFragments)(context.root, projectRoot));
|
|
48
|
+
const { parseCLI } = await (0, _executorutils.loadVitestDynamicImport)();
|
|
49
|
+
const normalizedExtraArgs = parseCLI([
|
|
50
|
+
'vitest',
|
|
51
|
+
...getOptionsAsArgv(options)
|
|
52
|
+
]);
|
|
48
53
|
var _resolved_config_root;
|
|
49
|
-
const settings = _extends._({},
|
|
54
|
+
const settings = _extends._({}, normalizedExtraArgs, {
|
|
50
55
|
// This should not be needed as it's going to be set in vite.config.ts
|
|
51
56
|
// but leaving it here in case someone did not migrate correctly
|
|
52
57
|
root: (_resolved_config_root = resolved.config.root) != null ? _resolved_config_root : root,
|
|
@@ -55,13 +60,18 @@ async function getOptions(options, context, projectRoot, extraArgs) {
|
|
|
55
60
|
var _resolved_config_test;
|
|
56
61
|
return mergeConfig((_resolved_config_test = resolved == null ? void 0 : (_resolved_config1 = resolved.config) == null ? void 0 : _resolved_config1['test']) != null ? _resolved_config_test : {}, settings);
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
function getOptionsAsArgv(obj) {
|
|
64
|
+
const argv = [];
|
|
65
|
+
for (const [key, value] of Object.entries(obj)){
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
value.forEach((item)=>argv.push(`--${key}=${item}`));
|
|
68
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
69
|
+
argv.push(`--${key}='${JSON.stringify(value)}'`);
|
|
70
|
+
} else {
|
|
71
|
+
argv.push(`--${key}=${value}`);
|
|
72
|
+
}
|
|
63
73
|
}
|
|
64
|
-
return
|
|
74
|
+
return argv;
|
|
65
75
|
}
|
|
66
76
|
|
|
67
77
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/vite/src/executors/test/lib/utils.ts"],"sourcesContent":["import {\n ExecutorContext,\n joinPathFragments,\n logger,\n stripIndents,\n} from '@nx/devkit';\nimport { VitestExecutorOptions } from '../schema';\nimport { normalizeViteConfigFilePath } from '../../../utils/options-utils';\nimport { relative } from 'path';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/executors/test/lib/utils.ts"],"sourcesContent":["import {\n ExecutorContext,\n joinPathFragments,\n logger,\n stripIndents,\n} from '@nx/devkit';\nimport { VitestExecutorOptions } from '../schema';\nimport { normalizeViteConfigFilePath } from '../../../utils/options-utils';\nimport { relative } from 'path';\nimport {\n loadViteDynamicImport,\n loadVitestDynamicImport,\n} from '../../../utils/executor-utils';\n\nexport async function getOptions(\n options: VitestExecutorOptions,\n context: ExecutorContext,\n projectRoot: string\n) {\n // Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.\n const { loadConfigFromFile, mergeConfig } = await loadViteDynamicImport();\n\n const viteConfigPath = normalizeViteConfigFilePath(\n context.root,\n projectRoot,\n options.configFile\n );\n\n if (!viteConfigPath) {\n throw new Error(\n stripIndents`\n Unable to load test config from config file ${viteConfigPath}.\n \n Please make sure that vitest is configured correctly, \n or use the @nx/vite:vitest generator to configure it for you.\n You can read more here: https://nx.dev/nx-api/vite/generators/vitest\n `\n );\n }\n\n const resolved = await loadConfigFromFile(\n {\n mode: options?.mode ?? 'production',\n command: 'serve',\n },\n viteConfigPath\n );\n\n if (!viteConfigPath || !resolved?.config?.['test']) {\n logger.warn(stripIndents`Unable to load test config from config file ${\n resolved?.path ?? viteConfigPath\n }\n Some settings may not be applied as expected.\n You can manually set the config in the project, ${\n context.projectName\n }, configuration.\n `);\n }\n const root =\n projectRoot === '.'\n ? process.cwd()\n : relative(context.cwd, joinPathFragments(context.root, projectRoot));\n\n const { parseCLI } = await loadVitestDynamicImport();\n\n const normalizedExtraArgs = parseCLI([\n 'vitest',\n ...getOptionsAsArgv(options),\n ]);\n\n const settings = {\n ...normalizedExtraArgs,\n // This should not be needed as it's going to be set in vite.config.ts\n // but leaving it here in case someone did not migrate correctly\n root: resolved.config.root ?? root,\n configFile: viteConfigPath,\n };\n\n return mergeConfig(resolved?.config?.['test'] ?? {}, settings);\n}\n\nexport function getOptionsAsArgv(obj: Record<string, any>): string[] {\n const argv: string[] = [];\n\n for (const [key, value] of Object.entries(obj)) {\n if (Array.isArray(value)) {\n value.forEach((item) => argv.push(`--${key}=${item}`));\n } else if (typeof value === 'object' && value !== null) {\n argv.push(`--${key}='${JSON.stringify(value)}'`);\n } else {\n argv.push(`--${key}=${value}`);\n }\n }\n\n return argv;\n}\n"],"names":["getOptions","getOptionsAsArgv","options","context","projectRoot","resolved","loadConfigFromFile","mergeConfig","loadViteDynamicImport","viteConfigPath","normalizeViteConfigFilePath","root","configFile","Error","stripIndents","mode","command","config","logger","warn","path","projectName","process","cwd","relative","joinPathFragments","parseCLI","loadVitestDynamicImport","normalizedExtraArgs","settings","obj","argv","key","value","Object","entries","Array","isArray","forEach","item","push","JSON","stringify"],"mappings":";;;;;;;;IAcsBA,UAAU;eAAVA;;IAmENC,gBAAgB;eAAhBA;;;;wBA5ET;8BAEqC;sBACnB;+BAIlB;AAEA,eAAeD,WACpBE,OAA8B,EAC9BC,OAAwB,EACxBC,WAAmB;QA+BKC,kBA8BLA;IA3DnB,yFAAyF;IACzF,MAAM,EAAEC,kBAAkB,EAAEC,WAAW,EAAE,GAAG,MAAMC,IAAAA,oCAAqB;IAEvE,MAAMC,iBAAiBC,IAAAA,yCAA2B,EAChDP,QAAQQ,IAAI,EACZP,aACAF,QAAQU,UAAU;IAGpB,IAAI,CAACH,gBAAgB;QACnB,MAAM,IAAII,MACRC,IAAAA,oBAAY,CAAA,CAAC;oDACiC,EAAEL,eAAe;;;;;QAK7D,CAAC;IAEP;QAIUP;IAFV,MAAMG,WAAW,MAAMC,mBACrB;QACES,MAAMb,CAAAA,gBAAAA,2BAAAA,QAASa,IAAI,YAAbb,gBAAiB;QACvBc,SAAS;IACX,GACAP;IAGF,IAAI,CAACA,kBAAkB,EAACJ,6BAAAA,mBAAAA,SAAUY,MAAM,qBAAhBZ,gBAAkB,CAAC,OAAO,GAAE;YAEhDA;QADFa,cAAM,CAACC,IAAI,CAACL,IAAAA,oBAAY,CAAA,CAAC,4CAA4C,EACnET,CAAAA,iBAAAA,4BAAAA,SAAUe,IAAI,YAAdf,iBAAkBI,eACnB;;kDAE6C,EAC9CN,QAAQkB,WAAW,CACpB;QACK,CAAC;IACP;IACA,MAAMV,OACJP,gBAAgB,MACZkB,QAAQC,GAAG,KACXC,IAAAA,cAAQ,EAACrB,QAAQoB,GAAG,EAAEE,IAAAA,yBAAiB,EAACtB,QAAQQ,IAAI,EAAEP;IAE5D,MAAM,EAAEsB,QAAQ,EAAE,GAAG,MAAMC,IAAAA,sCAAuB;IAElD,MAAMC,sBAAsBF,SAAS;QACnC;WACGzB,iBAAiBC;KACrB;QAMOG;IAJR,MAAMwB,WAAW,eACZD;QACH,sEAAsE;QACtE,gEAAgE;QAChEjB,MAAMN,CAAAA,wBAAAA,SAASY,MAAM,CAACN,IAAI,YAApBN,wBAAwBM;QAC9BC,YAAYH;;QAGKJ;IAAnB,OAAOE,YAAYF,CAAAA,wBAAAA,6BAAAA,oBAAAA,SAAUY,MAAM,qBAAhBZ,iBAAkB,CAAC,OAAO,YAA1BA,wBAA8B,CAAC,GAAGwB;AACvD;AAEO,SAAS5B,iBAAiB6B,GAAwB;IACvD,MAAMC,OAAiB,EAAE;IAEzB,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACL,KAAM;QAC9C,IAAIM,MAAMC,OAAO,CAACJ,QAAQ;YACxBA,MAAMK,OAAO,CAAC,CAACC,OAASR,KAAKS,IAAI,CAAC,CAAC,EAAE,EAAER,IAAI,CAAC,EAAEO,KAAK,CAAC;QACtD,OAAO,IAAI,OAAON,UAAU,YAAYA,UAAU,MAAM;YACtDF,KAAKS,IAAI,CAAC,CAAC,EAAE,EAAER,IAAI,EAAE,EAAES,KAAKC,SAAS,CAACT,OAAO,CAAC,CAAC;QACjD,OAAO;YACLF,KAAKS,IAAI,CAAC,CAAC,EAAE,EAAER,IAAI,CAAC,EAAEC,MAAM,CAAC;QAC/B;IACF;IAEA,OAAOF;AACT"}
|
|
@@ -18,15 +18,15 @@ const _path = require("path");
|
|
|
18
18
|
const _internal = require("@nx/js/src/internal");
|
|
19
19
|
const _nxreporter = require("./lib/nx-reporter");
|
|
20
20
|
const _utils = require("./lib/utils");
|
|
21
|
+
const _executorutils = require("../../utils/executor-utils");
|
|
21
22
|
async function* vitestExecutor(options, context) {
|
|
22
23
|
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
23
24
|
(0, _internal.registerTsConfigPaths)((0, _path.resolve)(_devkit.workspaceRoot, projectRoot, 'tsconfig.json'));
|
|
24
25
|
process.env.VITE_CJS_IGNORE_WARNING = 'true';
|
|
25
26
|
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
26
|
-
const { startVitest } = await
|
|
27
|
-
const extraArgs = await (0, _utils.getExtraArgs)(options);
|
|
27
|
+
const { startVitest } = await (0, _executorutils.loadVitestDynamicImport)();
|
|
28
28
|
var _ref;
|
|
29
|
-
const resolvedOptions = (_ref = await (0, _utils.getOptions)(options, context, projectRoot
|
|
29
|
+
const resolvedOptions = (_ref = await (0, _utils.getOptions)(options, context, projectRoot)) != null ? _ref : {};
|
|
30
30
|
const nxReporter = new _nxreporter.NxReporter(resolvedOptions['watch']);
|
|
31
31
|
if (resolvedOptions['reporters'] === undefined) {
|
|
32
32
|
resolvedOptions['reporters'] = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/executors/test/vitest.impl.ts"],"sourcesContent":["import { ExecutorContext, workspaceRoot } from '@nx/devkit';\nimport { VitestExecutorOptions } from './schema';\nimport { resolve } from 'path';\nimport { registerTsConfigPaths } from '@nx/js/src/internal';\nimport { NxReporter } from './lib/nx-reporter';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/executors/test/vitest.impl.ts"],"sourcesContent":["import { ExecutorContext, workspaceRoot } from '@nx/devkit';\nimport { VitestExecutorOptions } from './schema';\nimport { resolve } from 'path';\nimport { registerTsConfigPaths } from '@nx/js/src/internal';\nimport { NxReporter } from './lib/nx-reporter';\nimport { getOptions } from './lib/utils';\nimport { loadVitestDynamicImport } from '../../utils/executor-utils';\n\nexport async function* vitestExecutor(\n options: VitestExecutorOptions,\n context: ExecutorContext\n) {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n\n registerTsConfigPaths(resolve(workspaceRoot, projectRoot, 'tsconfig.json'));\n\n process.env.VITE_CJS_IGNORE_WARNING = 'true';\n // Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.\n const { startVitest } = await loadVitestDynamicImport();\n\n const resolvedOptions =\n (await getOptions(options, context, projectRoot)) ?? {};\n\n const nxReporter = new NxReporter(resolvedOptions['watch']);\n if (resolvedOptions['reporters'] === undefined) {\n resolvedOptions['reporters'] = [];\n } else if (typeof resolvedOptions['reporters'] === 'string') {\n resolvedOptions['reporters'] = [resolvedOptions['reporters']];\n }\n resolvedOptions['reporters'].push(nxReporter);\n\n const cliFilters = options.testFiles ?? [];\n\n const ctx = await startVitest(\n resolvedOptions['mode'] ?? 'test',\n cliFilters,\n resolvedOptions\n );\n\n let hasErrors = false;\n\n const processExit = () => {\n ctx.exit();\n if (hasErrors) {\n process.exit(1);\n } else {\n process.exit(0);\n }\n };\n\n if (resolvedOptions['watch'] === true) {\n process.on('SIGINT', processExit);\n process.on('SIGTERM', processExit);\n process.on('exit', processExit);\n }\n\n for await (const report of nxReporter) {\n // vitest sets the exitCode = 1 when code coverage isn't met\n hasErrors =\n report.hasErrors || (process.exitCode && process.exitCode !== 0);\n }\n\n return {\n success: !hasErrors,\n };\n}\n\nexport default vitestExecutor;\n"],"names":["vitestExecutor","options","context","projectRoot","projectsConfigurations","projects","projectName","root","registerTsConfigPaths","resolve","workspaceRoot","process","env","VITE_CJS_IGNORE_WARNING","startVitest","loadVitestDynamicImport","resolvedOptions","getOptions","nxReporter","NxReporter","undefined","push","cliFilters","testFiles","ctx","hasErrors","processExit","exit","on","report","exitCode","success"],"mappings":";;;;;;;;IAQuBA,cAAc;eAAdA;;IA4DvB,OAA8B;eAA9B;;;wBApE+C;sBAEvB;0BACc;4BACX;uBACA;+BACa;AAEjC,gBAAgBA,eACrBC,OAA8B,EAC9BC,OAAwB;IAExB,MAAMC,cACJD,QAAQE,sBAAsB,CAACC,QAAQ,CAACH,QAAQI,WAAW,CAAC,CAACC,IAAI;IAEnEC,IAAAA,+BAAqB,EAACC,IAAAA,aAAO,EAACC,qBAAa,EAAEP,aAAa;IAE1DQ,QAAQC,GAAG,CAACC,uBAAuB,GAAG;IACtC,yFAAyF;IACzF,MAAM,EAAEC,WAAW,EAAE,GAAG,MAAMC,IAAAA,sCAAuB;QAGlD;IADH,MAAMC,kBACJ,CAAC,OAAA,MAAMC,IAAAA,iBAAU,EAAChB,SAASC,SAASC,wBAAnC,OAAoD,CAAC;IAExD,MAAMe,aAAa,IAAIC,sBAAU,CAACH,eAAe,CAAC,QAAQ;IAC1D,IAAIA,eAAe,CAAC,YAAY,KAAKI,WAAW;QAC9CJ,eAAe,CAAC,YAAY,GAAG,EAAE;IACnC,OAAO,IAAI,OAAOA,eAAe,CAAC,YAAY,KAAK,UAAU;QAC3DA,eAAe,CAAC,YAAY,GAAG;YAACA,eAAe,CAAC,YAAY;SAAC;IAC/D;IACAA,eAAe,CAAC,YAAY,CAACK,IAAI,CAACH;QAEfjB;IAAnB,MAAMqB,aAAarB,CAAAA,qBAAAA,QAAQsB,SAAS,YAAjBtB,qBAAqB,EAAE;QAGxCe;IADF,MAAMQ,MAAM,MAAMV,YAChBE,CAAAA,wBAAAA,eAAe,CAAC,OAAO,YAAvBA,wBAA2B,QAC3BM,YACAN;IAGF,IAAIS,YAAY;IAEhB,MAAMC,cAAc;QAClBF,IAAIG,IAAI;QACR,IAAIF,WAAW;YACbd,QAAQgB,IAAI,CAAC;QACf,OAAO;YACLhB,QAAQgB,IAAI,CAAC;QACf;IACF;IAEA,IAAIX,eAAe,CAAC,QAAQ,KAAK,MAAM;QACrCL,QAAQiB,EAAE,CAAC,UAAUF;QACrBf,QAAQiB,EAAE,CAAC,WAAWF;QACtBf,QAAQiB,EAAE,CAAC,QAAQF;IACrB;IAEA,WAAW,MAAMG,UAAUX,WAAY;QACrC,4DAA4D;QAC5DO,YACEI,OAAOJ,SAAS,IAAKd,QAAQmB,QAAQ,IAAInB,QAAQmB,QAAQ,KAAK;IAClE;IAEA,OAAO;QACLC,SAAS,CAACN;IACZ;AACF;MAEA,WAAezB"}
|
|
@@ -23,6 +23,7 @@ const _generatorutils = require("../../utils/generator-utils");
|
|
|
23
23
|
const _init = require("../init/init");
|
|
24
24
|
const _vitestgenerator = require("../vitest/vitest-generator");
|
|
25
25
|
const _ensuredependencies = require("../../utils/ensure-dependencies");
|
|
26
|
+
const _convertnonvite = require("./lib/convert-non-vite");
|
|
26
27
|
function viteConfigurationGenerator(host, schema) {
|
|
27
28
|
return viteConfigurationGeneratorInternal(host, _extends._({
|
|
28
29
|
addPlugin: false
|
|
@@ -30,89 +31,24 @@ function viteConfigurationGenerator(host, schema) {
|
|
|
30
31
|
}
|
|
31
32
|
async function viteConfigurationGeneratorInternal(tree, schema) {
|
|
32
33
|
var _nxJson_plugins;
|
|
33
|
-
var _schema,
|
|
34
|
+
var _schema, // Setting default to jsdom since it is the most common use case (React, Web).
|
|
34
35
|
// The @nx/js:lib generator specifically sets this to node to be more generic.
|
|
35
|
-
_schema2;
|
|
36
|
+
_schema1, _schema2;
|
|
36
37
|
const tasks = [];
|
|
37
|
-
var _addPlugin;
|
|
38
|
-
(_addPlugin = (_schema = schema).addPlugin) != null ? _addPlugin : _schema.addPlugin = process.env.NX_ADD_PLUGINS !== 'false';
|
|
39
38
|
const projectConfig = (0, _devkit.readProjectConfiguration)(tree, schema.project);
|
|
40
39
|
const { targets, root: projectRoot } = projectConfig;
|
|
41
40
|
var _projectConfig_projectType;
|
|
42
41
|
const projectType = (_projectConfig_projectType = projectConfig.projectType) != null ? _projectConfig_projectType : 'library';
|
|
43
|
-
let buildTargetName = 'build';
|
|
44
|
-
let serveTargetName = 'serve';
|
|
45
|
-
let testTargetName = 'test';
|
|
46
42
|
var _includeLib;
|
|
47
|
-
(_includeLib = (
|
|
43
|
+
(_includeLib = (_schema = schema).includeLib) != null ? _includeLib : _schema.includeLib = projectType === 'library';
|
|
48
44
|
var _testEnvironment;
|
|
49
|
-
(_testEnvironment = (
|
|
45
|
+
(_testEnvironment = (_schema1 = schema).testEnvironment) != null ? _testEnvironment : _schema1.testEnvironment = 'jsdom';
|
|
50
46
|
/**
|
|
51
47
|
* This is for when we are converting an existing project
|
|
52
48
|
* to use the vite executors.
|
|
53
49
|
*/ let projectAlreadyHasViteTargets = {};
|
|
54
50
|
if (!schema.newProject) {
|
|
55
|
-
|
|
56
|
-
const userProvidedTargetName = {
|
|
57
|
-
build: schema.buildTarget,
|
|
58
|
-
serve: schema.serveTarget,
|
|
59
|
-
test: schema.testTarget
|
|
60
|
-
};
|
|
61
|
-
const { validFoundTargetName, projectContainsUnsupportedExecutor, userProvidedTargetIsUnsupported, alreadyHasNxViteTargets } = (0, _generatorutils.findExistingTargetsInProject)(targets, userProvidedTargetName);
|
|
62
|
-
projectAlreadyHasViteTargets = alreadyHasNxViteTargets;
|
|
63
|
-
/**
|
|
64
|
-
* This means that we only found unsupported build targets in that project.
|
|
65
|
-
* The only way that buildTarget is defined, means that it is supported.
|
|
66
|
-
*
|
|
67
|
-
* If the `unsupported` flag was false, it would mean that we did not find
|
|
68
|
-
* a build target at all, so we can create a new one.
|
|
69
|
-
*
|
|
70
|
-
* So we only throw if we found a target, but it is unsupported.
|
|
71
|
-
*/ if (!validFoundTargetName.build && projectContainsUnsupportedExecutor) {
|
|
72
|
-
throw new Error(`The project ${schema.project} cannot be converted to use the @nx/vite executors.`);
|
|
73
|
-
}
|
|
74
|
-
if (alreadyHasNxViteTargets.build && (alreadyHasNxViteTargets.serve || projectType === 'library') && alreadyHasNxViteTargets.test) {
|
|
75
|
-
throw new Error(`The project ${schema.project} is already configured to use the @nx/vite executors.
|
|
76
|
-
Please try a different project, or remove the existing targets
|
|
77
|
-
and re-run this generator to reset the existing Vite Configuration.
|
|
78
|
-
`);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* This means that we did not find any supported executors
|
|
82
|
-
* so we don't have any valid target names.
|
|
83
|
-
*
|
|
84
|
-
* However, the executors that we may have found are not in the
|
|
85
|
-
* list of the specifically unsupported executors either.
|
|
86
|
-
*
|
|
87
|
-
* So, we should warn the user about it.
|
|
88
|
-
*/ if (!projectContainsUnsupportedExecutor && !validFoundTargetName.build && !validFoundTargetName.serve && !validFoundTargetName.test) {
|
|
89
|
-
await (0, _generatorutils.handleUnknownExecutors)(schema.project);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* There is a possibility at this stage that the user has provided
|
|
93
|
-
* targets with unsupported executors.
|
|
94
|
-
* We keep track here of which of the targets that the user provided
|
|
95
|
-
* are unsupported.
|
|
96
|
-
* We do this with the `userProvidedTargetIsUnsupported` object,
|
|
97
|
-
* which contains flags for each target (whether it is supported or not).
|
|
98
|
-
*
|
|
99
|
-
* We also keep track of the targets that we found in the project,
|
|
100
|
-
* through the findExistingTargetsInProject function, which returns
|
|
101
|
-
* targets for build/serve/test that use supported executors, and
|
|
102
|
-
* can be converted to use the vite executors. These are the
|
|
103
|
-
* kept in the validFoundTargetName object.
|
|
104
|
-
*/ await (0, _generatorutils.handleUnsupportedUserProvidedTargets)(userProvidedTargetIsUnsupported, userProvidedTargetName, validFoundTargetName);
|
|
105
|
-
var _validFoundTargetName_build;
|
|
106
|
-
/**
|
|
107
|
-
* Once the user is at this stage, then they can go ahead and convert.
|
|
108
|
-
*/ buildTargetName = (_validFoundTargetName_build = validFoundTargetName.build) != null ? _validFoundTargetName_build : buildTargetName;
|
|
109
|
-
var _validFoundTargetName_serve;
|
|
110
|
-
serveTargetName = (_validFoundTargetName_serve = validFoundTargetName.serve) != null ? _validFoundTargetName_serve : serveTargetName;
|
|
111
|
-
if (projectType === 'application') {
|
|
112
|
-
(0, _generatorutils.moveAndEditIndexHtml)(tree, schema, buildTargetName);
|
|
113
|
-
}
|
|
114
|
-
(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);
|
|
115
|
-
(0, _generatorutils.editTsConfig)(tree, schema);
|
|
51
|
+
await (0, _convertnonvite.convertNonVite)(tree, schema, projectRoot, projectType, targets);
|
|
116
52
|
}
|
|
117
53
|
const jsInitTask = await (0, _js.initGenerator)(tree, _extends._({}, schema, {
|
|
118
54
|
skipFormat: true,
|
|
@@ -125,17 +61,20 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
|
|
|
125
61
|
tasks.push(initTask);
|
|
126
62
|
tasks.push((0, _ensuredependencies.ensureDependencies)(tree, schema));
|
|
127
63
|
const nxJson = (0, _devkit.readNxJson)(tree);
|
|
64
|
+
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && nxJson.useInferencePlugins !== false;
|
|
65
|
+
var _addPlugin;
|
|
66
|
+
(_addPlugin = (_schema2 = schema).addPlugin) != null ? _addPlugin : _schema2.addPlugin = addPluginDefault;
|
|
128
67
|
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');
|
|
129
68
|
if (!hasPlugin) {
|
|
130
69
|
if (!projectAlreadyHasViteTargets.build) {
|
|
131
|
-
(0, _generatorutils.
|
|
70
|
+
(0, _generatorutils.addBuildTarget)(tree, schema, 'build');
|
|
132
71
|
}
|
|
133
72
|
if (!schema.includeLib) {
|
|
134
73
|
if (!projectAlreadyHasViteTargets.serve) {
|
|
135
|
-
(0, _generatorutils.
|
|
74
|
+
(0, _generatorutils.addServeTarget)(tree, schema, 'serve');
|
|
136
75
|
}
|
|
137
76
|
if (!projectAlreadyHasViteTargets.preview) {
|
|
138
|
-
(0, _generatorutils.addPreviewTarget)(tree, schema,
|
|
77
|
+
(0, _generatorutils.addPreviewTarget)(tree, schema, 'preview');
|
|
139
78
|
}
|
|
140
79
|
}
|
|
141
80
|
}
|
|
@@ -192,7 +131,7 @@ async function viteConfigurationGeneratorInternal(tree, schema) {
|
|
|
192
131
|
inSourceTests: schema.inSourceTests,
|
|
193
132
|
coverageProvider: 'v8',
|
|
194
133
|
skipViteConfig: true,
|
|
195
|
-
testTarget:
|
|
134
|
+
testTarget: 'test',
|
|
196
135
|
skipFormat: true,
|
|
197
136
|
addPlugin: schema.addPlugin
|
|
198
137
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/generators/configuration/configuration.ts"],"sourcesContent":["import {\n formatFiles,\n GeneratorCallback,\n joinPathFragments,\n readNxJson,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\nimport { initGenerator as jsInitGenerator } from '@nx/js';\n\nimport {\n 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 function viteConfigurationGenerator(\n host: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n return viteConfigurationGeneratorInternal(host, {\n addPlugin: false,\n ...schema,\n });\n}\n\nexport async function viteConfigurationGeneratorInternal(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';\n\n const projectConfig = readProjectConfiguration(tree, schema.project);\n const {\n targets,\n\n root: projectRoot,\n } = projectConfig;\n\n const projectType = projectConfig.projectType ?? 'library';\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, { ...schema, 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 addPlugin: schema.addPlugin,\n });\n tasks.push(vitestTask);\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nexport default viteConfigurationGenerator;\n"],"names":["viteConfigurationGenerator","viteConfigurationGeneratorInternal","host","schema","addPlugin","tree","nxJson","tasks","process","env","NX_ADD_PLUGINS","projectConfig","readProjectConfiguration","project","targets","root","projectRoot","projectType","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","vitest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B,UAAU,EAAE;QACtB,iDAAiD;QACjD,IAAIrB,OAAOkE,WAAW,KAAK,SAAS;YAClCC,IAAAA,sCAAsB,EACpBjE,MACA;gBACEQ,SAASV,OAAOU,OAAO;gBACvBQ,YAAYlB,OAAOkB,UAAU;gBAC7BkD,eAAepE,OAAOoE,aAAa;gBACnCC,eAAerE,OAAOqE,aAAa;gBACnCC,uBAAuB;oBACrB;oBACA;oBACA;iBACD;gBACDC,SAAS;oBACPvE,OAAOwE,QAAQ,KAAK,QAChB,CAAC,4CAA4C,CAAC,GAC9C,CAAC,wCAAwC,CAAC;iBAC/C;gBACDpB,SAAS;oBAAC;iBAAU;YACtB,GACA,OACAqB;QAEJ,OAAO;YACLN,IAAAA,sCAAsB,EAACjE,MAAMF,QAAQ,OAAOoB;QAC9C;IACF;IAEA,IAAIpB,OAAOoE,aAAa,EAAE;QACxB,MAAMM,aAAa,MAAMC,IAAAA,wBAAe,EAACzE,MAAM;YAC7CQ,SAASV,OAAOU,OAAO;YACvBwD,aAAalE,OAAOkE,WAAW;YAC/BG,eAAerE,OAAOqE,aAAa;YACnCO,kBAAkB;YAClBC,gBAAgB;YAChBjD,YAAYX;YACZ2B,YAAY;YACZ3C,WAAWD,OAAOC,SAAS;QAC7B;QACAG,MAAM0C,IAAI,CAAC4B;IACb;IAEA,IAAI,CAAC1E,OAAO4C,UAAU,EAAE;QACtB,MAAMkC,IAAAA,mBAAW,EAAC5E;IACpB;IAEA,OAAO6E,IAAAA,wBAAgB,KAAI3E;AAC7B;MAEA,WAAeP"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/generators/configuration/configuration.ts"],"sourcesContent":["import {\n formatFiles,\n GeneratorCallback,\n joinPathFragments,\n readNxJson,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\nimport { initGenerator as jsInitGenerator } from '@nx/js';\n\nimport {\n addBuildTarget,\n addServeTarget,\n addPreviewTarget,\n createOrEditViteConfig,\n TargetFlags,\n} from '../../utils/generator-utils';\n\nimport initGenerator from '../init/init';\nimport vitestGenerator from '../vitest/vitest-generator';\nimport { ViteConfigurationGeneratorSchema } from './schema';\nimport { ensureDependencies } from '../../utils/ensure-dependencies';\nimport { convertNonVite } from './lib/convert-non-vite';\n\nexport function viteConfigurationGenerator(\n host: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n return viteConfigurationGeneratorInternal(host, {\n addPlugin: false,\n ...schema,\n });\n}\n\nexport async function viteConfigurationGeneratorInternal(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const projectConfig = readProjectConfiguration(tree, schema.project);\n const { targets, root: projectRoot } = projectConfig;\n\n const projectType = projectConfig.projectType ?? 'library';\n\n schema.includeLib ??= projectType === 'library';\n\n // Setting default to jsdom since it is the most common use case (React, Web).\n // The @nx/js:lib generator specifically sets this to node to be more generic.\n schema.testEnvironment ??= 'jsdom';\n\n /**\n * This is for when we are converting an existing project\n * to use the vite executors.\n */\n let projectAlreadyHasViteTargets: TargetFlags = {};\n\n if (!schema.newProject) {\n await convertNonVite(tree, schema, projectRoot, projectType, targets);\n }\n\n const jsInitTask = await jsInitGenerator(tree, {\n ...schema,\n skipFormat: true,\n tsConfigName: projectRoot === '.' ? 'tsconfig.json' : 'tsconfig.base.json',\n });\n tasks.push(jsInitTask);\n const initTask = await initGenerator(tree, { ...schema, skipFormat: true });\n tasks.push(initTask);\n tasks.push(ensureDependencies(tree, schema));\n\n const nxJson = readNxJson(tree);\n const addPluginDefault =\n process.env.NX_ADD_PLUGINS !== 'false' &&\n nxJson.useInferencePlugins !== false;\n schema.addPlugin ??= addPluginDefault;\n\n const hasPlugin = nxJson.plugins?.some((p) =>\n typeof p === 'string'\n ? p === '@nx/vite/plugin'\n : p.plugin === '@nx/vite/plugin'\n );\n\n if (!hasPlugin) {\n if (!projectAlreadyHasViteTargets.build) {\n addBuildTarget(tree, schema, 'build');\n }\n\n if (!schema.includeLib) {\n if (!projectAlreadyHasViteTargets.serve) {\n addServeTarget(tree, schema, 'serve');\n }\n if (!projectAlreadyHasViteTargets.preview) {\n addPreviewTarget(tree, schema, 'preview');\n }\n }\n }\n if (projectType === 'library') {\n // update tsconfig.lib.json to include vite/client\n updateJson(\n tree,\n joinPathFragments(projectRoot, 'tsconfig.lib.json'),\n (json) => {\n if (!json.compilerOptions) {\n json.compilerOptions = {};\n }\n if (!json.compilerOptions.types) {\n json.compilerOptions.types = [];\n }\n if (!json.compilerOptions.types.includes('vite/client')) {\n return {\n ...json,\n compilerOptions: {\n ...json.compilerOptions,\n types: [...json.compilerOptions.types, 'vite/client'],\n },\n };\n }\n return json;\n }\n );\n }\n\n if (!schema.newProject) {\n // We are converting existing project to use Vite\n if (schema.uiFramework === 'react') {\n createOrEditViteConfig(\n tree,\n {\n project: schema.project,\n includeLib: schema.includeLib,\n includeVitest: schema.includeVitest,\n inSourceTests: schema.inSourceTests,\n rollupOptionsExternal: [\n \"'react'\",\n \"'react-dom'\",\n \"'react/jsx-runtime'\",\n ],\n imports: [\n schema.compiler === 'swc'\n ? `import react from '@vitejs/plugin-react-swc'`\n : `import react from '@vitejs/plugin-react'`,\n ],\n plugins: ['react()'],\n },\n false,\n undefined\n );\n } else {\n createOrEditViteConfig(tree, schema, false, projectAlreadyHasViteTargets);\n }\n }\n\n if (schema.includeVitest) {\n const vitestTask = await vitestGenerator(tree, {\n project: schema.project,\n uiFramework: schema.uiFramework,\n inSourceTests: schema.inSourceTests,\n coverageProvider: 'v8',\n skipViteConfig: true,\n testTarget: 'test',\n skipFormat: true,\n addPlugin: schema.addPlugin,\n });\n tasks.push(vitestTask);\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nexport default viteConfigurationGenerator;\n"],"names":["viteConfigurationGenerator","viteConfigurationGeneratorInternal","host","schema","addPlugin","tree","nxJson","tasks","projectConfig","readProjectConfiguration","project","targets","root","projectRoot","projectType","includeLib","testEnvironment","projectAlreadyHasViteTargets","newProject","convertNonVite","jsInitTask","jsInitGenerator","skipFormat","tsConfigName","push","initTask","initGenerator","ensureDependencies","readNxJson","addPluginDefault","process","env","NX_ADD_PLUGINS","useInferencePlugins","hasPlugin","plugins","some","p","plugin","build","addBuildTarget","serve","addServeTarget","preview","addPreviewTarget","updateJson","joinPathFragments","json","compilerOptions","types","includes","uiFramework","createOrEditViteConfig","includeVitest","inSourceTests","rollupOptionsExternal","imports","compiler","undefined","vitestTask","vitestGenerator","coverageProvider","skipViteConfig","testTarget","formatFiles","runTasksInSerial"],"mappings":";;;;;;;;IA0BgBA,0BAA0B;eAA1BA;;IAUMC,kCAAkC;eAAlCA;;IA4ItB,OAA0C;eAA1C;;;;wBAvKO;oBAC0C;gCAQ1C;sBAEmB;iCACE;oCAEO;gCACJ;AAExB,SAASD,2BACdE,IAAU,EACVC,MAAwC;IAExC,OAAOF,mCAAmCC,MAAM;QAC9CE,WAAW;OACRD;AAEP;AAEO,eAAeF,mCACpBI,IAAU,EACVF,MAAwC;QAyCtBG;QAhClBH,SAEA,8EAA8E;IAC9E,8EAA8E;IAC9EA,UA0BAA;IArCA,MAAMI,QAA6B,EAAE;IAErC,MAAMC,gBAAgBC,IAAAA,gCAAwB,EAACJ,MAAMF,OAAOO,OAAO;IACnE,MAAM,EAAEC,OAAO,EAAEC,MAAMC,WAAW,EAAE,GAAGL;QAEnBA;IAApB,MAAMM,cAAcN,CAAAA,6BAAAA,cAAcM,WAAW,YAAzBN,6BAA6B;;IAEjDL,gBAAAA,UAAAA,QAAOY,oCAAPZ,QAAOY,aAAeD,gBAAgB;;IAItCX,qBAAAA,WAAAA,QAAOa,8CAAPb,SAAOa,kBAAoB;IAE3B;;;GAGC,GACD,IAAIC,+BAA4C,CAAC;IAEjD,IAAI,CAACd,OAAOe,UAAU,EAAE;QACtB,MAAMC,IAAAA,8BAAc,EAACd,MAAMF,QAAQU,aAAaC,aAAaH;IAC/D;IAEA,MAAMS,aAA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5 @@
|
|
|
1
|
+
import { TargetConfiguration, Tree } from '@nx/devkit';
|
|
2
|
+
import { ViteConfigurationGeneratorSchema } from '../schema';
|
|
3
|
+
export declare function convertNonVite(tree: Tree, schema: ViteConfigurationGeneratorSchema, projectRoot: string, projectType: string, targets: {
|
|
4
|
+
[targetName: string]: TargetConfiguration<any>;
|
|
5
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "convertNonVite", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return convertNonVite;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _devkit = require("@nx/devkit");
|
|
9
|
+
const _findviteconfig = require("../../../utils/find-vite-config");
|
|
10
|
+
const _generatorutils = require("../../../utils/generator-utils");
|
|
11
|
+
async function convertNonVite(tree, schema, projectRoot, projectType, targets) {
|
|
12
|
+
// Check if it has vite
|
|
13
|
+
const hasViteConfig = (0, _findviteconfig.findViteConfig)(tree, projectRoot);
|
|
14
|
+
const hasIndexHtmlAtRoot = tree.exists((0, _devkit.joinPathFragments)(projectRoot, 'index.html'));
|
|
15
|
+
// Check if it has webpack
|
|
16
|
+
const hasWebpackConfig = (0, _findviteconfig.findWebpackConfig)(tree, projectRoot);
|
|
17
|
+
if (hasWebpackConfig) {
|
|
18
|
+
if (projectType === 'application') {
|
|
19
|
+
(0, _generatorutils.moveAndEditIndexHtml)(tree, schema);
|
|
20
|
+
}
|
|
21
|
+
(0, _generatorutils.deleteWebpackConfig)(tree, projectRoot, hasWebpackConfig);
|
|
22
|
+
(0, _generatorutils.editTsConfig)(tree, schema);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (projectType === 'application' && hasViteConfig && hasIndexHtmlAtRoot && !hasWebpackConfig) {
|
|
26
|
+
throw new Error(`The project ${schema.project} is already configured to use Vite.`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (projectType === 'library' && hasViteConfig) {
|
|
30
|
+
// continue anyway - it could need to be updated - only update vite.config.ts in any case
|
|
31
|
+
(0, _generatorutils.editTsConfig)(tree, schema);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Does the project have js executors?
|
|
35
|
+
const { supported: jsTargetName, unsupported } = (0, _generatorutils.findExistingJsBuildTargetInProject)(targets);
|
|
36
|
+
if (jsTargetName) {
|
|
37
|
+
(0, _generatorutils.editTsConfig)(tree, schema);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (unsupported) {
|
|
41
|
+
throw new Error(`
|
|
42
|
+
Nx cannot convert your project to use vite.
|
|
43
|
+
Please try again with a different project.
|
|
44
|
+
`);
|
|
45
|
+
}
|
|
46
|
+
// If it's a library, it's most possible it's non-buildable
|
|
47
|
+
// So fix the tsconfig and return, to continue with the rest of the setup
|
|
48
|
+
if (projectType === 'library' && !hasViteConfig && !hasWebpackConfig && !jsTargetName) {
|
|
49
|
+
(0, _generatorutils.editTsConfig)(tree, schema);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The project is an app.
|
|
54
|
+
* The project has no js executors, no webpack config, no vite config.
|
|
55
|
+
* We did not find any configuration that hints the project can
|
|
56
|
+
* definitely be converted.
|
|
57
|
+
* So, we should warn the user about it.
|
|
58
|
+
* They can choose whether to convert it or not
|
|
59
|
+
*/ await (0, _generatorutils.handleUnknownConfiguration)(schema.project);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=convert-non-vite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/generators/configuration/lib/convert-non-vite.ts"],"sourcesContent":["import {\n TargetConfiguration,\n Tree,\n joinPathFragments,\n logger,\n} from '@nx/devkit';\nimport {\n findViteConfig,\n findWebpackConfig,\n} from '../../../utils/find-vite-config';\nimport { ViteConfigurationGeneratorSchema } from '../schema';\nimport {\n deleteWebpackConfig,\n editTsConfig,\n findExistingJsBuildTargetInProject,\n handleUnknownConfiguration,\n moveAndEditIndexHtml,\n} from '../../../utils/generator-utils';\n\nexport async function convertNonVite(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema,\n projectRoot: string,\n projectType: string,\n targets: {\n [targetName: string]: TargetConfiguration<any>;\n }\n) {\n // Check if it has vite\n const hasViteConfig = findViteConfig(tree, projectRoot);\n const hasIndexHtmlAtRoot = tree.exists(\n joinPathFragments(projectRoot, 'index.html')\n );\n\n // Check if it has webpack\n const hasWebpackConfig = findWebpackConfig(tree, projectRoot);\n if (hasWebpackConfig) {\n if (projectType === 'application') {\n moveAndEditIndexHtml(tree, schema);\n }\n deleteWebpackConfig(tree, projectRoot, hasWebpackConfig);\n editTsConfig(tree, schema);\n return;\n }\n\n if (\n projectType === 'application' &&\n hasViteConfig &&\n hasIndexHtmlAtRoot &&\n !hasWebpackConfig\n ) {\n throw new Error(\n `The project ${schema.project} is already configured to use Vite.`\n );\n return;\n }\n\n if (projectType === 'library' && hasViteConfig) {\n // continue anyway - it could need to be updated - only update vite.config.ts in any case\n editTsConfig(tree, schema);\n return;\n }\n\n // Does the project have js executors?\n const { supported: jsTargetName, unsupported } =\n findExistingJsBuildTargetInProject(targets);\n if (jsTargetName) {\n editTsConfig(tree, schema);\n return;\n }\n\n if (unsupported) {\n throw new Error(`\n Nx cannot convert your project to use vite.\n Please try again with a different project.\n `);\n }\n\n // If it's a library, it's most possible it's non-buildable\n // So fix the tsconfig and return, to continue with the rest of the setup\n if (\n projectType === 'library' &&\n !hasViteConfig &&\n !hasWebpackConfig &&\n !jsTargetName\n ) {\n editTsConfig(tree, schema);\n return;\n }\n\n /**\n * The project is an app.\n * The project has no js executors, no webpack config, no vite config.\n * We did not find any configuration that hints the project can\n * definitely be converted.\n * So, we should warn the user about it.\n * They can choose whether to convert it or not\n */\n await handleUnknownConfiguration(schema.project);\n}\n"],"names":["convertNonVite","tree","schema","projectRoot","projectType","targets","hasViteConfig","findViteConfig","hasIndexHtmlAtRoot","exists","joinPathFragments","hasWebpackConfig","findWebpackConfig","moveAndEditIndexHtml","deleteWebpackConfig","editTsConfig","Error","project","supported","jsTargetName","unsupported","findExistingJsBuildTargetInProject","handleUnknownConfiguration"],"mappings":";+BAmBsBA;;;eAAAA;;;wBAdf;gCAIA;gCAQA;AAEA,eAAeA,eACpBC,IAAU,EACVC,MAAwC,EACxCC,WAAmB,EACnBC,WAAmB,EACnBC,OAEC;IAED,uBAAuB;IACvB,MAAMC,gBAAgBC,IAAAA,8BAAc,EAACN,MAAME;IAC3C,MAAMK,qBAAqBP,KAAKQ,MAAM,CACpCC,IAAAA,yBAAiB,EAACP,aAAa;IAGjC,0BAA0B;IAC1B,MAAMQ,mBAAmBC,IAAAA,iCAAiB,EAACX,MAAME;IACjD,IAAIQ,kBAAkB;QACpB,IAAIP,gBAAgB,eAAe;YACjCS,IAAAA,oCAAoB,EAACZ,MAAMC;QAC7B;QACAY,IAAAA,mCAAmB,EAACb,MAAME,aAAaQ;QACvCI,IAAAA,4BAAY,EAACd,MAAMC;QACnB;IACF;IAEA,IACEE,gBAAgB,iBAChBE,iBACAE,sBACA,CAACG,kBACD;QACA,MAAM,IAAIK,MACR,CAAC,YAAY,EAAEd,OAAOe,OAAO,CAAC,mCAAmC,CAAC;QAEpE;IACF;IAEA,IAAIb,gBAAgB,aAAaE,eAAe;QAC9C,yFAAyF;QACzFS,IAAAA,4BAAY,EAACd,MAAMC;QACnB;IACF;IAEA,sCAAsC;IACtC,MAAM,EAAEgB,WAAWC,YAAY,EAAEC,WAAW,EAAE,GAC5CC,IAAAA,kDAAkC,EAAChB;IACrC,IAAIc,cAAc;QAChBJ,IAAAA,4BAAY,EAACd,MAAMC;QACnB;IACF;IAEA,IAAIkB,aAAa;QACf,MAAM,IAAIJ,MAAM,CAAC;;;IAGjB,CAAC;IACH;IAEA,2DAA2D;IAC3D,yEAAyE;IACzE,IACEZ,gBAAgB,aAChB,CAACE,iBACD,CAACK,oBACD,CAACQ,cACD;QACAJ,IAAAA,4BAAY,EAACd,MAAMC;QACnB;IACF;IAEA;;;;;;;GAOC,GACD,MAAMoB,IAAAA,0CAA0B,EAACpB,OAAOe,OAAO;AACjD"}
|
|
@@ -6,9 +6,6 @@ export interface ViteConfigurationGeneratorSchema {
|
|
|
6
6
|
includeVitest?: boolean;
|
|
7
7
|
inSourceTests?: boolean;
|
|
8
8
|
includeLib?: boolean;
|
|
9
|
-
buildTarget?: string;
|
|
10
|
-
serveTarget?: string;
|
|
11
|
-
testTarget?: string;
|
|
12
9
|
skipFormat?: boolean;
|
|
13
10
|
testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
|
|
14
11
|
addPlugin?: boolean;
|
|
@@ -44,18 +44,6 @@
|
|
|
44
44
|
"default": false,
|
|
45
45
|
"hidden": true
|
|
46
46
|
},
|
|
47
|
-
"buildTarget": {
|
|
48
|
-
"type": "string",
|
|
49
|
-
"description": "The build target of the project to be transformed to use the @nx/vite:build executor."
|
|
50
|
-
},
|
|
51
|
-
"serveTarget": {
|
|
52
|
-
"type": "string",
|
|
53
|
-
"description": "The serve target of the project to be transformed to use the @nx/vite:dev-server and @nx/vite:preview-server executors."
|
|
54
|
-
},
|
|
55
|
-
"testTarget": {
|
|
56
|
-
"type": "string",
|
|
57
|
-
"description": "The test target of the project to be transformed to use the @nx/vite:test executor."
|
|
58
|
-
},
|
|
59
47
|
"skipFormat": {
|
|
60
48
|
"description": "Skip formatting files.",
|
|
61
49
|
"type": "boolean",
|
|
@@ -56,8 +56,10 @@ function initGenerator(tree, schema) {
|
|
|
56
56
|
}
|
|
57
57
|
async function initGeneratorInternal(tree, schema) {
|
|
58
58
|
var _schema;
|
|
59
|
+
const nxJson = (0, _devkit.readNxJson)(tree);
|
|
60
|
+
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && nxJson.useInferencePlugins !== false;
|
|
59
61
|
var _addPlugin;
|
|
60
|
-
(_addPlugin = (_schema = schema).addPlugin) != null ? _addPlugin : _schema.addPlugin =
|
|
62
|
+
(_addPlugin = (_schema = schema).addPlugin) != null ? _addPlugin : _schema.addPlugin = addPluginDefault;
|
|
61
63
|
if (schema.addPlugin) {
|
|
62
64
|
(0, _utils.addPlugin)(tree);
|
|
63
65
|
}
|
|
@@ -1 +1 @@
|
|
|
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';\nimport { updatePackageScripts } from '@nx/devkit/src/utils/update-package-scripts';\n\nimport { createNodes } from '../../plugins/plugin';\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 function initGenerator(tree: Tree, schema: InitGeneratorSchema) {\n return initGeneratorInternal(tree, { addPlugin: false, ...schema });\n}\n\nexport async function initGeneratorInternal(\n tree: Tree,\n schema: InitGeneratorSchema\n) {\n
|
|
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';\nimport { updatePackageScripts } from '@nx/devkit/src/utils/update-package-scripts';\n\nimport { createNodes } from '../../plugins/plugin';\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 function initGenerator(tree: Tree, schema: InitGeneratorSchema) {\n return initGeneratorInternal(tree, { addPlugin: false, ...schema });\n}\n\nexport async function initGeneratorInternal(\n tree: Tree,\n schema: InitGeneratorSchema\n) {\n const nxJson = readNxJson(tree);\n const addPluginDefault =\n process.env.NX_ADD_PLUGINS !== 'false' &&\n nxJson.useInferencePlugins !== false;\n schema.addPlugin ??= addPluginDefault;\n if (schema.addPlugin) {\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.updatePackageScripts) {\n await updatePackageScripts(tree, createNodes);\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","initGeneratorInternal","tree","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","hasPlugin","plugins","some","p","plugin","targetDefaults","cache","inputs","updateNxJson","schema","addPlugin","addPluginDefault","process","env","NX_ADD_PLUGINS","useInferencePlugins","tasks","skipPackageJson","moveToDevDependencies","checkDependenciesInstalled","updatePackageScripts","createNodes","skipFormat","formatFiles","runTasksInSerial"],"mappings":";;;;;;;;IAkBgBA,oBAAoB;eAApBA;;IAgCAC,aAAa;eAAbA;;IAIMC,qBAAqB;eAArBA;;IAgCtB,OAA6B;eAA7B;;;;wBA/EO;sCAC8B;wBAET;uBAMrB;AAEA,SAASF,qBAAqBG,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,SAASH,cAAcE,IAAU,EAAEmB,MAA2B;IACnE,OAAOpB,sBAAsBC,MAAM;QAAEoB,WAAW;OAAUD;AAC5D;AAEO,eAAepB,sBACpBC,IAAU,EACVmB,MAA2B;QAM3BA;IAJA,MAAMlB,SAASC,IAAAA,kBAAU,EAACF;IAC1B,MAAMqB,mBACJC,QAAQC,GAAG,CAACC,cAAc,KAAK,WAC/BvB,OAAOwB,mBAAmB,KAAK;;IACjCN,eAAAA,UAAAA,QAAOC,kCAAPD,QAAOC,YAAcC;IACrB,IAAIF,OAAOC,SAAS,EAAE;QACpBA,IAAAA,gBAAS,EAACpB;IACZ;IAEAH,qBAAqBG;IAErB,MAAM0B,QAA6B,EAAE;IACrC,IAAI,CAACP,OAAOQ,eAAe,EAAE;QAC3BD,MAAMpB,IAAI,CAACsB,IAAAA,4BAAqB,EAAC5B;QACjC0B,MAAMpB,IAAI,CAACuB,IAAAA,iCAA0B,EAAC7B,MAAMmB;IAC9C;IAEA,IAAIA,OAAOW,oBAAoB,EAAE;QAC/B,MAAMA,IAAAA,0CAAoB,EAAC9B,MAAM+B,mBAAW;IAC9C;IAEA,IAAI,CAACZ,OAAOa,UAAU,EAAE;QACtB,MAAMC,IAAAA,mBAAW,EAACjC;IACpB;IAEA,OAAOkC,IAAAA,wBAAgB,KAAIR;AAC7B;MAEA,WAAe5B"}
|
|
@@ -32,7 +32,8 @@ function vitestGenerator(tree, schema, hasPlugin = false) {
|
|
|
32
32
|
async function vitestGeneratorInternal(tree, schema, hasPlugin = false) {
|
|
33
33
|
var _nxJson_plugins;
|
|
34
34
|
const tasks = [];
|
|
35
|
-
const {
|
|
35
|
+
const { root, projectType } = (0, _devkit.readProjectConfiguration)(tree, schema.project);
|
|
36
|
+
const isRootProject = root === '.';
|
|
36
37
|
tasks.push(await (0, _js.initGenerator)(tree, _extends._({}, schema, {
|
|
37
38
|
skipFormat: true
|
|
38
39
|
})));
|
|
@@ -45,8 +46,8 @@ async function vitestGeneratorInternal(tree, schema, hasPlugin = false) {
|
|
|
45
46
|
const nxJson = (0, _devkit.readNxJson)(tree);
|
|
46
47
|
const hasPluginCheck = (_nxJson_plugins = nxJson.plugins) == null ? void 0 : _nxJson_plugins.some((p)=>(typeof p === 'string' ? p === '@nx/vite/plugin' : p.plugin === '@nx/vite/plugin') || hasPlugin);
|
|
47
48
|
if (!hasPluginCheck) {
|
|
48
|
-
var _schema_testTarget
|
|
49
|
-
const testTarget = (
|
|
49
|
+
var _schema_testTarget;
|
|
50
|
+
const testTarget = (_schema_testTarget = schema.testTarget) != null ? _schema_testTarget : 'test';
|
|
50
51
|
(0, _generatorutils.addOrChangeTestTarget)(tree, schema, testTarget);
|
|
51
52
|
}
|
|
52
53
|
if (!schema.skipViteConfig) {
|
|
@@ -81,6 +82,10 @@ async function vitestGeneratorInternal(tree, schema, hasPlugin = false) {
|
|
|
81
82
|
const coverageProviderDependency = getCoverageProviderDependency(schema.coverageProvider);
|
|
82
83
|
const installCoverageProviderTask = (0, _devkit.addDependenciesToPackageJson)(tree, {}, coverageProviderDependency);
|
|
83
84
|
tasks.push(installCoverageProviderTask);
|
|
85
|
+
// Setup workspace config file (https://vitest.dev/guide/workspace.html)
|
|
86
|
+
if (!isRootProject && !tree.exists(`vitest.workspace.ts`) && !tree.exists(`vitest.workspace.js`) && !tree.exists(`vitest.workspace.json`) && !tree.exists(`vitest.projects.ts`) && !tree.exists(`vitest.projects.js`) && !tree.exists(`vitest.projects.json`)) {
|
|
87
|
+
tree.write('vitest.workspace.ts', `export default ['**/*/vite.config.ts', '**/*/vitest.config.ts'];`);
|
|
88
|
+
}
|
|
84
89
|
if (!schema.skipFormat) {
|
|
85
90
|
await (0, _devkit.formatFiles)(tree);
|
|
86
91
|
}
|