@nx/vite 0.0.0-pr-22179-271588f
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/LICENSE +22 -0
- package/README.md +68 -0
- package/executors.d.ts +8 -0
- package/executors.js +27 -0
- package/executors.js.map +1 -0
- package/executors.json +46 -0
- package/generators.json +25 -0
- package/index.d.ts +8 -0
- package/index.js +26 -0
- package/index.js.map +1 -0
- package/migrations.json +253 -0
- package/package.json +62 -0
- package/plugin.d.ts +1 -0
- package/plugin.js +21 -0
- package/plugin.js.map +1 -0
- package/plugins/nx-tsconfig-paths.plugin.d.ts +24 -0
- package/plugins/nx-tsconfig-paths.plugin.js +132 -0
- package/plugins/nx-tsconfig-paths.plugin.js.map +1 -0
- package/plugins/rollup-replace-files.plugin.d.ts +16 -0
- package/plugins/rollup-replace-files.plugin.js +51 -0
- package/plugins/rollup-replace-files.plugin.js.map +1 -0
- package/src/executors/build/build.impl.d.ts +13 -0
- package/src/executors/build/build.impl.js +187 -0
- package/src/executors/build/build.impl.js.map +1 -0
- package/src/executors/build/compat.d.ts +2 -0
- package/src/executors/build/compat.js +12 -0
- package/src/executors/build/compat.js.map +1 -0
- package/src/executors/build/schema.d.js +3 -0
- package/src/executors/build/schema.d.js.map +1 -0
- package/src/executors/build/schema.d.ts +10 -0
- package/src/executors/build/schema.json +67 -0
- package/src/executors/dev-server/compat.d.ts +2 -0
- package/src/executors/dev-server/compat.js +12 -0
- package/src/executors/dev-server/compat.js.map +1 -0
- package/src/executors/dev-server/dev-server.impl.d.ts +7 -0
- package/src/executors/dev-server/dev-server.impl.js +136 -0
- package/src/executors/dev-server/dev-server.impl.js.map +1 -0
- package/src/executors/dev-server/schema.d.js +3 -0
- package/src/executors/dev-server/schema.d.js.map +1 -0
- package/src/executors/dev-server/schema.d.ts +5 -0
- package/src/executors/dev-server/schema.json +38 -0
- package/src/executors/preview-server/compat.d.ts +2 -0
- package/src/executors/preview-server/compat.js +12 -0
- package/src/executors/preview-server/compat.js.map +1 -0
- package/src/executors/preview-server/preview-server.impl.d.ts +7 -0
- package/src/executors/preview-server/preview-server.impl.js +176 -0
- package/src/executors/preview-server/preview-server.impl.js.map +1 -0
- package/src/executors/preview-server/schema.d.js +3 -0
- package/src/executors/preview-server/schema.d.js.map +1 -0
- package/src/executors/preview-server/schema.d.ts +5 -0
- package/src/executors/preview-server/schema.json +37 -0
- package/src/executors/test/compat.d.ts +2 -0
- package/src/executors/test/compat.js +12 -0
- package/src/executors/test/compat.js.map +1 -0
- package/src/executors/test/lib/nx-reporter.d.ts +14 -0
- package/src/executors/test/lib/nx-reporter.js +40 -0
- package/src/executors/test/lib/nx-reporter.js.map +1 -0
- package/src/executors/test/lib/utils.d.ts +4 -0
- package/src/executors/test/lib/utils.js +77 -0
- package/src/executors/test/lib/utils.js.map +1 -0
- package/src/executors/test/schema.d.js +3 -0
- package/src/executors/test/schema.d.js.map +1 -0
- package/src/executors/test/schema.d.ts +7 -0
- package/src/executors/test/schema.json +36 -0
- package/src/executors/test/vitest.impl.d.ts +6 -0
- package/src/executors/test/vitest.impl.js +67 -0
- package/src/executors/test/vitest.impl.js.map +1 -0
- package/src/generators/configuration/configuration.d.ts +5 -0
- package/src/generators/configuration/configuration.js +147 -0
- package/src/generators/configuration/configuration.js.map +1 -0
- 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.js +3 -0
- package/src/generators/configuration/schema.d.js.map +1 -0
- package/src/generators/configuration/schema.d.ts +12 -0
- package/src/generators/configuration/schema.json +61 -0
- package/src/generators/init/init.d.ts +6 -0
- package/src/generators/init/init.js +82 -0
- package/src/generators/init/init.js.map +1 -0
- package/src/generators/init/lib/utils.d.ts +6 -0
- package/src/generators/init/lib/utils.js +80 -0
- package/src/generators/init/lib/utils.js.map +1 -0
- package/src/generators/init/schema.d.js +3 -0
- package/src/generators/init/schema.d.js.map +1 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +31 -0
- package/src/generators/vitest/files/tsconfig.spec.json__tmpl__ +20 -0
- package/src/generators/vitest/schema.d.js +3 -0
- package/src/generators/vitest/schema.d.js.map +1 -0
- package/src/generators/vitest/schema.d.ts +11 -0
- package/src/generators/vitest/schema.json +56 -0
- package/src/generators/vitest/vitest-generator.d.ts +5 -0
- package/src/generators/vitest/vitest-generator.js +187 -0
- package/src/generators/vitest/vitest-generator.js.map +1 -0
- package/src/migrations/update-15-3-1/update-vite-tsconfig-paths.d.ts +3 -0
- package/src/migrations/update-15-3-1/update-vite-tsconfig-paths.js +67 -0
- package/src/migrations/update-15-3-1/update-vite-tsconfig-paths.js.map +1 -0
- package/src/migrations/update-15-3-4/set-mode-in-configuration.d.ts +3 -0
- package/src/migrations/update-15-3-4/set-mode-in-configuration.js +37 -0
- package/src/migrations/update-15-3-4/set-mode-in-configuration.js.map +1 -0
- package/src/migrations/update-15-4-3/update-report-directory.d.ts +3 -0
- package/src/migrations/update-15-4-3/update-report-directory.js +39 -0
- package/src/migrations/update-15-4-3/update-report-directory.js.map +1 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +15 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +1 -0
- package/src/migrations/update-16-4-1-update-test-file-config/update-16-4-1-test-file-config.d.ts +2 -0
- package/src/migrations/update-16-4-1-update-test-file-config/update-16-4-1-test-file-config.js +35 -0
- package/src/migrations/update-16-4-1-update-test-file-config/update-16-4-1-test-file-config.js.map +1 -0
- package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.d.ts +2 -0
- package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js +39 -0
- package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js.map +1 -0
- package/src/migrations/update-17-1-0/move-target-defaults.d.ts +2 -0
- package/src/migrations/update-17-1-0/move-target-defaults.js +77 -0
- package/src/migrations/update-17-1-0/move-target-defaults.js.map +1 -0
- package/src/migrations/update-17-2-0/lib/add-file-replacements.d.ts +2 -0
- package/src/migrations/update-17-2-0/lib/add-file-replacements.js +67 -0
- package/src/migrations/update-17-2-0/lib/add-file-replacements.js.map +1 -0
- package/src/migrations/update-17-2-0/lib/edit-build-config.d.ts +2 -0
- package/src/migrations/update-17-2-0/lib/edit-build-config.js +121 -0
- package/src/migrations/update-17-2-0/lib/edit-build-config.js.map +1 -0
- package/src/migrations/update-17-2-0/lib/edit-test-config.d.ts +2 -0
- package/src/migrations/update-17-2-0/lib/edit-test-config.js +83 -0
- package/src/migrations/update-17-2-0/lib/edit-test-config.js.map +1 -0
- package/src/migrations/update-17-2-0/update-vite-config.d.ts +5 -0
- package/src/migrations/update-17-2-0/update-vite-config.js +68 -0
- package/src/migrations/update-17-2-0/update-vite-config.js.map +1 -0
- package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.d.ts +3 -0
- package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.js +117 -0
- package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.js.map +1 -0
- package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.d.ts +2 -0
- package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.js +45 -0
- package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.js.map +1 -0
- package/src/plugins/plugin.d.ts +10 -0
- package/src/plugins/plugin.js +223 -0
- package/src/plugins/plugin.js.map +1 -0
- package/src/utils/ensure-dependencies.d.ts +8 -0
- package/src/utils/ensure-dependencies.js +34 -0
- package/src/utils/ensure-dependencies.js.map +1 -0
- package/src/utils/executor-utils.d.ts +11 -0
- package/src/utils/executor-utils.js +59 -0
- package/src/utils/executor-utils.js.map +1 -0
- package/src/utils/find-vite-config.d.ts +3 -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 +42 -0
- package/src/utils/generator-utils.js +527 -0
- package/src/utils/generator-utils.js.map +1 -0
- package/src/utils/options-utils.d.ts +17 -0
- package/src/utils/options-utils.js +100 -0
- package/src/utils/options-utils.js.map +1 -0
- package/src/utils/test-files/angular-project.config.json +89 -0
- package/src/utils/test-files/react-lib-non-buildable-jest.json +22 -0
- package/src/utils/test-files/react-lib-non-buildable-vitest.json +22 -0
- package/src/utils/test-files/react-mixed-project.config.json +47 -0
- package/src/utils/test-files/react-vite-project.config.json +54 -0
- package/src/utils/test-files/test-vite-configs.d.ts +31 -0
- package/src/utils/test-files/test-vite-configs.js +291 -0
- package/src/utils/test-files/test-vite-configs.js.map +1 -0
- package/src/utils/test-files/unknown-project.config.json +69 -0
- package/src/utils/test-utils.d.ts +9 -0
- package/src/utils/test-utils.js +522 -0
- package/src/utils/test-utils.js.map +1 -0
- package/src/utils/versions.d.ts +11 -0
- package/src/utils/versions.js +55 -0
- package/src/utils/versions.js.map +1 -0
- package/src/utils/vite-config-edit-utils.d.ts +3 -0
- package/src/utils/vite-config-edit-utils.js +314 -0
- package/src/utils/vite-config-edit-utils.js.map +1 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export(target, all) {
|
|
3
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: all[name]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
_export(exports, {
|
|
9
|
+
getOptions: function() {
|
|
10
|
+
return getOptions;
|
|
11
|
+
},
|
|
12
|
+
getOptionsAsArgv: function() {
|
|
13
|
+
return getOptionsAsArgv;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const _extends = require("@swc/helpers/_/_extends");
|
|
17
|
+
const _devkit = require("@nx/devkit");
|
|
18
|
+
const _optionsutils = require("../../../utils/options-utils");
|
|
19
|
+
const _path = require("path");
|
|
20
|
+
const _executorutils = require("../../../utils/executor-utils");
|
|
21
|
+
async function getOptions(options, context, projectRoot) {
|
|
22
|
+
var _resolved_config, _resolved_config1;
|
|
23
|
+
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
24
|
+
const { loadConfigFromFile, mergeConfig } = await (0, _executorutils.loadViteDynamicImport)();
|
|
25
|
+
const viteConfigPath = (0, _optionsutils.normalizeViteConfigFilePath)(context.root, projectRoot, options.configFile);
|
|
26
|
+
if (!viteConfigPath) {
|
|
27
|
+
throw new Error((0, _devkit.stripIndents)`
|
|
28
|
+
Unable to load test config from config file ${viteConfigPath}.
|
|
29
|
+
|
|
30
|
+
Please make sure that vitest is configured correctly,
|
|
31
|
+
or use the @nx/vite:vitest generator to configure it for you.
|
|
32
|
+
You can read more here: https://nx.dev/nx-api/vite/generators/vitest
|
|
33
|
+
`);
|
|
34
|
+
}
|
|
35
|
+
var _options_mode;
|
|
36
|
+
const resolved = await loadConfigFromFile({
|
|
37
|
+
mode: (_options_mode = options == null ? void 0 : options.mode) != null ? _options_mode : 'production',
|
|
38
|
+
command: 'serve'
|
|
39
|
+
}, viteConfigPath);
|
|
40
|
+
if (!viteConfigPath || !(resolved == null ? void 0 : (_resolved_config = resolved.config) == null ? void 0 : _resolved_config['test'])) {
|
|
41
|
+
var _resolved_path;
|
|
42
|
+
_devkit.logger.warn((0, _devkit.stripIndents)`Unable to load test config from config file ${(_resolved_path = resolved == null ? void 0 : resolved.path) != null ? _resolved_path : viteConfigPath}
|
|
43
|
+
Some settings may not be applied as expected.
|
|
44
|
+
You can manually set the config in the project, ${context.projectName}, configuration.
|
|
45
|
+
`);
|
|
46
|
+
}
|
|
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
|
+
]);
|
|
53
|
+
var _resolved_config_root;
|
|
54
|
+
const settings = _extends._({}, normalizedExtraArgs, {
|
|
55
|
+
// This should not be needed as it's going to be set in vite.config.ts
|
|
56
|
+
// but leaving it here in case someone did not migrate correctly
|
|
57
|
+
root: (_resolved_config_root = resolved.config.root) != null ? _resolved_config_root : root,
|
|
58
|
+
configFile: viteConfigPath
|
|
59
|
+
});
|
|
60
|
+
var _resolved_config_test;
|
|
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);
|
|
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
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return argv;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +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 {\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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/executors/test/schema.d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Vitest executor",
|
|
6
|
+
"description": "Test using Vitest.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"configFile": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The path to the local vitest config",
|
|
12
|
+
"x-completion-type": "file",
|
|
13
|
+
"x-completion-glob": "@(vitest|vite).config@(.js|.ts)",
|
|
14
|
+
"aliases": ["config"]
|
|
15
|
+
},
|
|
16
|
+
"reportsDirectory": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Directory to write coverage report to."
|
|
19
|
+
},
|
|
20
|
+
"mode": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Mode for Vite."
|
|
23
|
+
},
|
|
24
|
+
"testFiles": {
|
|
25
|
+
"aliases": ["testFile"],
|
|
26
|
+
"type": "array",
|
|
27
|
+
"items": { "type": "string" }
|
|
28
|
+
},
|
|
29
|
+
"watch": {
|
|
30
|
+
"description": "Watch files for changes and rerun tests related to changed files.",
|
|
31
|
+
"type": "boolean"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"required": [],
|
|
35
|
+
"examplesFile": "../../../docs/test-examples.md"
|
|
36
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { VitestExecutorOptions } from './schema';
|
|
3
|
+
export declare function vitestExecutor(options: VitestExecutorOptions, context: ExecutorContext): AsyncGenerator<never, {
|
|
4
|
+
success: boolean;
|
|
5
|
+
}, unknown>;
|
|
6
|
+
export default vitestExecutor;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export(target, all) {
|
|
3
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: all[name]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
_export(exports, {
|
|
9
|
+
vitestExecutor: function() {
|
|
10
|
+
return vitestExecutor;
|
|
11
|
+
},
|
|
12
|
+
default: function() {
|
|
13
|
+
return _default;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const _devkit = require("@nx/devkit");
|
|
17
|
+
const _path = require("path");
|
|
18
|
+
const _internal = require("@nx/js/src/internal");
|
|
19
|
+
const _nxreporter = require("./lib/nx-reporter");
|
|
20
|
+
const _utils = require("./lib/utils");
|
|
21
|
+
const _executorutils = require("../../utils/executor-utils");
|
|
22
|
+
async function* vitestExecutor(options, context) {
|
|
23
|
+
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
24
|
+
(0, _internal.registerTsConfigPaths)((0, _path.resolve)(_devkit.workspaceRoot, projectRoot, 'tsconfig.json'));
|
|
25
|
+
process.env.VITE_CJS_IGNORE_WARNING = 'true';
|
|
26
|
+
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
27
|
+
const { startVitest } = await (0, _executorutils.loadVitestDynamicImport)();
|
|
28
|
+
var _ref;
|
|
29
|
+
const resolvedOptions = (_ref = await (0, _utils.getOptions)(options, context, projectRoot)) != null ? _ref : {};
|
|
30
|
+
const nxReporter = new _nxreporter.NxReporter(resolvedOptions['watch']);
|
|
31
|
+
if (resolvedOptions['reporters'] === undefined) {
|
|
32
|
+
resolvedOptions['reporters'] = [];
|
|
33
|
+
} else if (typeof resolvedOptions['reporters'] === 'string') {
|
|
34
|
+
resolvedOptions['reporters'] = [
|
|
35
|
+
resolvedOptions['reporters']
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
resolvedOptions['reporters'].push(nxReporter);
|
|
39
|
+
var _options_testFiles;
|
|
40
|
+
const cliFilters = (_options_testFiles = options.testFiles) != null ? _options_testFiles : [];
|
|
41
|
+
var _resolvedOptions_mode;
|
|
42
|
+
const ctx = await startVitest((_resolvedOptions_mode = resolvedOptions['mode']) != null ? _resolvedOptions_mode : 'test', cliFilters, resolvedOptions);
|
|
43
|
+
let hasErrors = false;
|
|
44
|
+
const processExit = ()=>{
|
|
45
|
+
ctx.exit();
|
|
46
|
+
if (hasErrors) {
|
|
47
|
+
process.exit(1);
|
|
48
|
+
} else {
|
|
49
|
+
process.exit(0);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
if (resolvedOptions['watch'] === true) {
|
|
53
|
+
process.on('SIGINT', processExit);
|
|
54
|
+
process.on('SIGTERM', processExit);
|
|
55
|
+
process.on('exit', processExit);
|
|
56
|
+
}
|
|
57
|
+
for await (const report of nxReporter){
|
|
58
|
+
// vitest sets the exitCode = 1 when code coverage isn't met
|
|
59
|
+
hasErrors = report.hasErrors || process.exitCode && process.exitCode !== 0;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
success: !hasErrors
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const _default = vitestExecutor;
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=vitest.impl.js.map
|
|
@@ -0,0 +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 { 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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { ViteConfigurationGeneratorSchema } from './schema';
|
|
3
|
+
export declare function viteConfigurationGenerator(host: Tree, schema: ViteConfigurationGeneratorSchema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function viteConfigurationGeneratorInternal(tree: Tree, schema: ViteConfigurationGeneratorSchema): Promise<GeneratorCallback>;
|
|
5
|
+
export default viteConfigurationGenerator;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export(target, all) {
|
|
3
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: all[name]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
_export(exports, {
|
|
9
|
+
viteConfigurationGenerator: function() {
|
|
10
|
+
return viteConfigurationGenerator;
|
|
11
|
+
},
|
|
12
|
+
viteConfigurationGeneratorInternal: function() {
|
|
13
|
+
return viteConfigurationGeneratorInternal;
|
|
14
|
+
},
|
|
15
|
+
default: function() {
|
|
16
|
+
return _default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _extends = require("@swc/helpers/_/_extends");
|
|
20
|
+
const _devkit = require("@nx/devkit");
|
|
21
|
+
const _js = require("@nx/js");
|
|
22
|
+
const _generatorutils = require("../../utils/generator-utils");
|
|
23
|
+
const _init = require("../init/init");
|
|
24
|
+
const _vitestgenerator = require("../vitest/vitest-generator");
|
|
25
|
+
const _ensuredependencies = require("../../utils/ensure-dependencies");
|
|
26
|
+
const _convertnonvite = require("./lib/convert-non-vite");
|
|
27
|
+
function viteConfigurationGenerator(host, schema) {
|
|
28
|
+
return viteConfigurationGeneratorInternal(host, _extends._({
|
|
29
|
+
addPlugin: false
|
|
30
|
+
}, schema));
|
|
31
|
+
}
|
|
32
|
+
async function viteConfigurationGeneratorInternal(tree, schema) {
|
|
33
|
+
var _nxJson_plugins;
|
|
34
|
+
var _schema, _schema1, // Setting default to jsdom since it is the most common use case (React, Web).
|
|
35
|
+
// The @nx/js:lib generator specifically sets this to node to be more generic.
|
|
36
|
+
_schema2;
|
|
37
|
+
const tasks = [];
|
|
38
|
+
const nxJson = (0, _devkit.readNxJson)(tree);
|
|
39
|
+
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && nxJson.useInferencePlugins !== false;
|
|
40
|
+
var _addPlugin;
|
|
41
|
+
(_addPlugin = (_schema = schema).addPlugin) != null ? _addPlugin : _schema.addPlugin = addPluginDefault;
|
|
42
|
+
const projectConfig = (0, _devkit.readProjectConfiguration)(tree, schema.project);
|
|
43
|
+
const { targets, root: projectRoot } = projectConfig;
|
|
44
|
+
var _projectConfig_projectType;
|
|
45
|
+
const projectType = (_projectConfig_projectType = projectConfig.projectType) != null ? _projectConfig_projectType : 'library';
|
|
46
|
+
var _includeLib;
|
|
47
|
+
(_includeLib = (_schema1 = schema).includeLib) != null ? _includeLib : _schema1.includeLib = projectType === 'library';
|
|
48
|
+
var _testEnvironment;
|
|
49
|
+
(_testEnvironment = (_schema2 = schema).testEnvironment) != null ? _testEnvironment : _schema2.testEnvironment = 'jsdom';
|
|
50
|
+
/**
|
|
51
|
+
* This is for when we are converting an existing project
|
|
52
|
+
* to use the vite executors.
|
|
53
|
+
*/ let projectAlreadyHasViteTargets = {};
|
|
54
|
+
if (!schema.newProject) {
|
|
55
|
+
await (0, _convertnonvite.convertNonVite)(tree, schema, projectRoot, projectType, targets);
|
|
56
|
+
}
|
|
57
|
+
const jsInitTask = await (0, _js.initGenerator)(tree, _extends._({}, schema, {
|
|
58
|
+
skipFormat: true,
|
|
59
|
+
tsConfigName: projectRoot === '.' ? 'tsconfig.json' : 'tsconfig.base.json'
|
|
60
|
+
}));
|
|
61
|
+
tasks.push(jsInitTask);
|
|
62
|
+
const initTask = await (0, _init.default)(tree, _extends._({}, schema, {
|
|
63
|
+
skipFormat: true
|
|
64
|
+
}));
|
|
65
|
+
tasks.push(initTask);
|
|
66
|
+
tasks.push((0, _ensuredependencies.ensureDependencies)(tree, schema));
|
|
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');
|
|
68
|
+
if (!hasPlugin) {
|
|
69
|
+
if (!projectAlreadyHasViteTargets.build) {
|
|
70
|
+
(0, _generatorutils.addBuildTarget)(tree, schema, 'build');
|
|
71
|
+
}
|
|
72
|
+
if (!schema.includeLib) {
|
|
73
|
+
if (!projectAlreadyHasViteTargets.serve) {
|
|
74
|
+
(0, _generatorutils.addServeTarget)(tree, schema, 'serve');
|
|
75
|
+
}
|
|
76
|
+
if (!projectAlreadyHasViteTargets.preview) {
|
|
77
|
+
(0, _generatorutils.addPreviewTarget)(tree, schema, 'preview');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (projectType === 'library') {
|
|
82
|
+
// update tsconfig.lib.json to include vite/client
|
|
83
|
+
(0, _devkit.updateJson)(tree, (0, _devkit.joinPathFragments)(projectRoot, 'tsconfig.lib.json'), (json)=>{
|
|
84
|
+
if (!json.compilerOptions) {
|
|
85
|
+
json.compilerOptions = {};
|
|
86
|
+
}
|
|
87
|
+
if (!json.compilerOptions.types) {
|
|
88
|
+
json.compilerOptions.types = [];
|
|
89
|
+
}
|
|
90
|
+
if (!json.compilerOptions.types.includes('vite/client')) {
|
|
91
|
+
return _extends._({}, json, {
|
|
92
|
+
compilerOptions: _extends._({}, json.compilerOptions, {
|
|
93
|
+
types: [
|
|
94
|
+
...json.compilerOptions.types,
|
|
95
|
+
'vite/client'
|
|
96
|
+
]
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return json;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (!schema.newProject) {
|
|
104
|
+
// We are converting existing project to use Vite
|
|
105
|
+
if (schema.uiFramework === 'react') {
|
|
106
|
+
(0, _generatorutils.createOrEditViteConfig)(tree, {
|
|
107
|
+
project: schema.project,
|
|
108
|
+
includeLib: schema.includeLib,
|
|
109
|
+
includeVitest: schema.includeVitest,
|
|
110
|
+
inSourceTests: schema.inSourceTests,
|
|
111
|
+
rollupOptionsExternal: [
|
|
112
|
+
"'react'",
|
|
113
|
+
"'react-dom'",
|
|
114
|
+
"'react/jsx-runtime'"
|
|
115
|
+
],
|
|
116
|
+
imports: [
|
|
117
|
+
schema.compiler === 'swc' ? `import react from '@vitejs/plugin-react-swc'` : `import react from '@vitejs/plugin-react'`
|
|
118
|
+
],
|
|
119
|
+
plugins: [
|
|
120
|
+
'react()'
|
|
121
|
+
]
|
|
122
|
+
}, false, undefined);
|
|
123
|
+
} else {
|
|
124
|
+
(0, _generatorutils.createOrEditViteConfig)(tree, schema, false, projectAlreadyHasViteTargets);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (schema.includeVitest) {
|
|
128
|
+
const vitestTask = await (0, _vitestgenerator.default)(tree, {
|
|
129
|
+
project: schema.project,
|
|
130
|
+
uiFramework: schema.uiFramework,
|
|
131
|
+
inSourceTests: schema.inSourceTests,
|
|
132
|
+
coverageProvider: 'v8',
|
|
133
|
+
skipViteConfig: true,
|
|
134
|
+
testTarget: 'test',
|
|
135
|
+
skipFormat: true,
|
|
136
|
+
addPlugin: schema.addPlugin
|
|
137
|
+
});
|
|
138
|
+
tasks.push(vitestTask);
|
|
139
|
+
}
|
|
140
|
+
if (!schema.skipFormat) {
|
|
141
|
+
await (0, _devkit.formatFiles)(tree);
|
|
142
|
+
}
|
|
143
|
+
return (0, _devkit.runTasksInSerial)(...tasks);
|
|
144
|
+
}
|
|
145
|
+
const _default = viteConfigurationGenerator;
|
|
146
|
+
|
|
147
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/generators/configuration/configuration.ts"],"sourcesContent":["import {\n formatFiles,\n GeneratorCallback,\n joinPathFragments,\n readNxJson,\n readProjectConfiguration,\n runTasksInSerial,\n Tree,\n updateJson,\n} from '@nx/devkit';\nimport { initGenerator as jsInitGenerator } from '@nx/js';\n\nimport {\n addBuildTarget,\n addServeTarget,\n addPreviewTarget,\n createOrEditViteConfig,\n TargetFlags,\n} from '../../utils/generator-utils';\n\nimport initGenerator from '../init/init';\nimport vitestGenerator from '../vitest/vitest-generator';\nimport { ViteConfigurationGeneratorSchema } from './schema';\nimport { ensureDependencies } from '../../utils/ensure-dependencies';\nimport { convertNonVite } from './lib/convert-non-vite';\n\nexport function viteConfigurationGenerator(\n host: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n return viteConfigurationGeneratorInternal(host, {\n addPlugin: false,\n ...schema,\n });\n}\n\nexport async function viteConfigurationGeneratorInternal(\n tree: Tree,\n schema: ViteConfigurationGeneratorSchema\n) {\n const tasks: GeneratorCallback[] = [];\n\n const nxJson = readNxJson(tree);\n const addPluginDefault =\n process.env.NX_ADD_PLUGINS !== 'false' &&\n nxJson.useInferencePlugins !== false;\n schema.addPlugin ??= addPluginDefault;\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 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","readNxJson","addPluginDefault","process","env","NX_ADD_PLUGINS","useInferencePlugins","projectConfig","readProjectConfiguration","project","targets","root","projectRoot","projectType","includeLib","testEnvironment","projectAlreadyHasViteTargets","newProject","convertNonVite","jsInitTask","jsInitGenerator","skipFormat","tsConfigName","push","initTask","initGenerator","ensureDependencies","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":"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"}
|
|
@@ -0,0 +1,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/generators/configuration/schema.d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ViteConfigurationGeneratorSchema {
|
|
2
|
+
uiFramework: 'react' | 'none';
|
|
3
|
+
compiler?: 'babel' | 'swc';
|
|
4
|
+
project: string;
|
|
5
|
+
newProject?: boolean;
|
|
6
|
+
includeVitest?: boolean;
|
|
7
|
+
inSourceTests?: boolean;
|
|
8
|
+
includeLib?: boolean;
|
|
9
|
+
skipFormat?: boolean;
|
|
10
|
+
testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
|
|
11
|
+
addPlugin?: boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cli": "nx",
|
|
3
|
+
"title": "Configure a project to use Vite.js.",
|
|
4
|
+
"description": "Configure a project to use Vite.js.",
|
|
5
|
+
"$id": "configure-vite-project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The name of the project.",
|
|
11
|
+
"$default": {
|
|
12
|
+
"$source": "argv",
|
|
13
|
+
"index": 0
|
|
14
|
+
},
|
|
15
|
+
"aliases": ["name", "projectName"],
|
|
16
|
+
"x-dropdown": "project",
|
|
17
|
+
"x-prompt": "What is the name of the project to set up Vite for?"
|
|
18
|
+
},
|
|
19
|
+
"includeLib": {
|
|
20
|
+
"type": "boolean",
|
|
21
|
+
"description": "Add a library build option and skip the server option.",
|
|
22
|
+
"hidden": true
|
|
23
|
+
},
|
|
24
|
+
"includeVitest": {
|
|
25
|
+
"type": "boolean",
|
|
26
|
+
"description": "Use vitest for the test suite."
|
|
27
|
+
},
|
|
28
|
+
"uiFramework": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"description": "UI Framework to use for Vite.",
|
|
31
|
+
"enum": ["react", "none"],
|
|
32
|
+
"default": "none",
|
|
33
|
+
"x-prompt": "What UI framework plugin should Vite use?"
|
|
34
|
+
},
|
|
35
|
+
"compiler": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "Compiler to use for Vite when UI Framework is React.",
|
|
38
|
+
"enum": ["babel", "swc"],
|
|
39
|
+
"default": "babel"
|
|
40
|
+
},
|
|
41
|
+
"newProject": {
|
|
42
|
+
"type": "boolean",
|
|
43
|
+
"description": "Is this a new project?",
|
|
44
|
+
"default": false,
|
|
45
|
+
"hidden": true
|
|
46
|
+
},
|
|
47
|
+
"skipFormat": {
|
|
48
|
+
"description": "Skip formatting files.",
|
|
49
|
+
"type": "boolean",
|
|
50
|
+
"default": false,
|
|
51
|
+
"x-priority": "internal"
|
|
52
|
+
},
|
|
53
|
+
"testEnvironment": {
|
|
54
|
+
"description": "The vitest environment to use. See https://vitest.dev/config/#environment.",
|
|
55
|
+
"type": "string",
|
|
56
|
+
"enum": ["node", "jsdom", "happy-dom", "edge-runtime"],
|
|
57
|
+
"default": "jsdom"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"examplesFile": "../../../docs/configuration-examples.md"
|
|
61
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { InitGeneratorSchema } from './schema';
|
|
3
|
+
export declare function updateNxJsonSettings(tree: Tree): void;
|
|
4
|
+
export declare function initGenerator(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
|
|
5
|
+
export declare function initGeneratorInternal(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
|
|
6
|
+
export default initGenerator;
|