@nx/vitest 0.0.1-alpha.0
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/executors.json +10 -0
- package/generators.d.ts +4 -0
- package/generators.d.ts.map +1 -0
- package/generators.js +7 -0
- package/generators.json +18 -0
- package/index.d.ts +5 -0
- package/index.d.ts.map +1 -0
- package/index.js +9 -0
- package/migrations.json +9 -0
- package/package.json +69 -0
- package/project.json +52 -0
- package/src/executors/test/compat.d.ts +3 -0
- package/src/executors/test/compat.d.ts.map +1 -0
- package/src/executors/test/compat.js +5 -0
- package/src/executors/test/lib/nx-reporter.d.ts +19 -0
- package/src/executors/test/lib/nx-reporter.d.ts.map +1 -0
- package/src/executors/test/lib/nx-reporter.js +39 -0
- package/src/executors/test/lib/utils.d.ts +5 -0
- package/src/executors/test/lib/utils.d.ts.map +1 -0
- package/src/executors/test/lib/utils.js +68 -0
- package/src/executors/test/schema.d.ts +7 -0
- package/src/executors/test/schema.json +35 -0
- package/src/executors/test/vitest.impl.d.ts +7 -0
- package/src/executors/test/vitest.impl.d.ts.map +1 -0
- package/src/executors/test/vitest.impl.js +59 -0
- package/src/generators/configuration/configuration.d.ts +9 -0
- package/src/generators/configuration/configuration.d.ts.map +1 -0
- package/src/generators/configuration/configuration.js +284 -0
- package/src/generators/configuration/files/tsconfig.spec.json__tmpl__ +22 -0
- package/src/generators/configuration/schema.d.ts +16 -0
- package/src/generators/configuration/schema.json +65 -0
- package/src/generators/init/init.d.ts +8 -0
- package/src/generators/init/init.d.ts.map +1 -0
- package/src/generators/init/init.js +70 -0
- package/src/generators/init/schema.d.ts +11 -0
- package/src/generators/init/schema.json +41 -0
- package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.d.ts +3 -0
- package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.d.ts.map +1 -0
- package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.js +17 -0
- package/src/plugins/plugin.d.ts +19 -0
- package/src/plugins/plugin.d.ts.map +1 -0
- package/src/plugins/plugin.js +277 -0
- package/src/utils/detect-ui-framework.d.ts +2 -0
- package/src/utils/detect-ui-framework.d.ts.map +1 -0
- package/src/utils/detect-ui-framework.js +24 -0
- package/src/utils/ensure-dependencies.d.ts +9 -0
- package/src/utils/ensure-dependencies.d.ts.map +1 -0
- package/src/utils/ensure-dependencies.js +47 -0
- package/src/utils/executor-utils.d.ts +3 -0
- package/src/utils/executor-utils.d.ts.map +1 -0
- package/src/utils/executor-utils.js +10 -0
- package/src/utils/generator-utils.d.ts +35 -0
- package/src/utils/generator-utils.d.ts.map +1 -0
- package/src/utils/generator-utils.js +223 -0
- package/src/utils/ignore-vitest-temp-files.d.ts +5 -0
- package/src/utils/ignore-vitest-temp-files.d.ts.map +1 -0
- package/src/utils/ignore-vitest-temp-files.js +54 -0
- package/src/utils/options-utils.d.ts +8 -0
- package/src/utils/options-utils.d.ts.map +1 -0
- package/src/utils/options-utils.js +41 -0
- package/src/utils/version-utils.d.ts +16 -0
- package/src/utils/version-utils.d.ts.map +1 -0
- package/src/utils/version-utils.js +90 -0
- package/src/utils/versions.d.ts +23 -0
- package/src/utils/versions.d.ts.map +1 -0
- package/src/utils/versions.js +26 -0
- package/src/utils/vite-config-edit-utils.d.ts +4 -0
- package/src/utils/vite-config-edit-utils.d.ts.map +1 -0
- package/src/utils/vite-config-edit-utils.js +359 -0
- package/tsconfig.json +28 -0
- package/tsconfig.lib.json +20 -0
- package/tsconfig.lib.tsbuildinfo +1 -0
- package/tsconfig.spec.json +24 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ignoreVitestTempFiles = ignoreVitestTempFiles;
|
|
4
|
+
exports.addVitestTempFilesToGitIgnore = addVitestTempFilesToGitIgnore;
|
|
5
|
+
exports.isEslintInstalled = isEslintInstalled;
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const versions_1 = require("./versions");
|
|
8
|
+
async function ignoreVitestTempFiles(tree, projectRoot) {
|
|
9
|
+
addVitestTempFilesToGitIgnore(tree);
|
|
10
|
+
await ignoreVitestTempFilesInEslintConfig(tree, projectRoot);
|
|
11
|
+
}
|
|
12
|
+
function addVitestTempFilesToGitIgnore(tree) {
|
|
13
|
+
let gitIgnoreContents = tree.exists('.gitignore')
|
|
14
|
+
? tree.read('.gitignore', 'utf-8')
|
|
15
|
+
: '';
|
|
16
|
+
if (!/^vitest\.config\.\*\.timestamp\*$/m.test(gitIgnoreContents)) {
|
|
17
|
+
gitIgnoreContents = (0, devkit_1.stripIndents) `${gitIgnoreContents}
|
|
18
|
+
vitest.config.*.timestamp*`;
|
|
19
|
+
}
|
|
20
|
+
tree.write('.gitignore', gitIgnoreContents);
|
|
21
|
+
}
|
|
22
|
+
async function ignoreVitestTempFilesInEslintConfig(tree, projectRoot) {
|
|
23
|
+
if (!isEslintInstalled(tree)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
(0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
|
|
27
|
+
const { addIgnoresToLintConfig, isEslintConfigSupported } = await Promise.resolve().then(() => require('@nx/eslint/src/generators/utils/eslint-file'));
|
|
28
|
+
if (!isEslintConfigSupported(tree)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const { useFlatConfig } = await Promise.resolve().then(() => require('@nx/eslint/src/utils/flat-config'));
|
|
32
|
+
const isUsingFlatConfig = useFlatConfig(tree);
|
|
33
|
+
if (!projectRoot && !isUsingFlatConfig) {
|
|
34
|
+
// root eslintrc files ignore all files and the root eslintrc files add
|
|
35
|
+
// back all the project files, so we only add the ignores to the project
|
|
36
|
+
// eslintrc files
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// for flat config, we update the root config file
|
|
40
|
+
const directory = isUsingFlatConfig ? '' : projectRoot ?? '';
|
|
41
|
+
addIgnoresToLintConfig(tree, directory, ['**/vitest.config.*.timestamp*']);
|
|
42
|
+
}
|
|
43
|
+
function isEslintInstalled(tree) {
|
|
44
|
+
try {
|
|
45
|
+
require('eslint');
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
catch { }
|
|
49
|
+
// it might not be installed yet, but it might be in the tree pending install
|
|
50
|
+
const { devDependencies, dependencies } = tree.exists('package.json')
|
|
51
|
+
? (0, devkit_1.readJson)(tree, 'package.json')
|
|
52
|
+
: {};
|
|
53
|
+
return !!devDependencies?.['eslint'] || !!dependencies?.['eslint'];
|
|
54
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the path to the vite config file or undefined when not found.
|
|
4
|
+
*/
|
|
5
|
+
export declare function normalizeViteConfigFilePath(contextRoot: string, projectRoot: string, configFile?: string): string | undefined;
|
|
6
|
+
export declare function getProjectTsConfigPath(projectRoot: string): string | undefined;
|
|
7
|
+
export declare function getNxTargetOptions(target: string, context: ExecutorContext): any;
|
|
8
|
+
//# sourceMappingURL=options-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/vitest/src/utils/options-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAKhB,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,GAAG,SAAS,CAgCpB;AAED,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,SAAS,CAYpB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,OAG1E"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeViteConfigFilePath = normalizeViteConfigFilePath;
|
|
4
|
+
exports.getProjectTsConfigPath = getProjectTsConfigPath;
|
|
5
|
+
exports.getNxTargetOptions = getNxTargetOptions;
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
/**
|
|
9
|
+
* Returns the path to the vite config file or undefined when not found.
|
|
10
|
+
*/
|
|
11
|
+
function normalizeViteConfigFilePath(contextRoot, projectRoot, configFile) {
|
|
12
|
+
if (configFile) {
|
|
13
|
+
const normalized = (0, devkit_1.joinPathFragments)(contextRoot, configFile);
|
|
14
|
+
if (!(0, fs_1.existsSync)(normalized)) {
|
|
15
|
+
throw new Error(`Could not find vite config at provided path "${normalized}".`);
|
|
16
|
+
}
|
|
17
|
+
return normalized;
|
|
18
|
+
}
|
|
19
|
+
const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];
|
|
20
|
+
for (const ext of allowsExt) {
|
|
21
|
+
if ((0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(contextRoot, projectRoot, `vite.config.${ext}`))) {
|
|
22
|
+
return (0, devkit_1.joinPathFragments)(contextRoot, projectRoot, `vite.config.${ext}`);
|
|
23
|
+
}
|
|
24
|
+
else if ((0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(contextRoot, projectRoot, `vitest.config.${ext}`))) {
|
|
25
|
+
return (0, devkit_1.joinPathFragments)(contextRoot, projectRoot, `vitest.config.${ext}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getProjectTsConfigPath(projectRoot) {
|
|
30
|
+
return (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'tsconfig.app.json'))
|
|
31
|
+
? (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.app.json')
|
|
32
|
+
: (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'tsconfig.lib.json'))
|
|
33
|
+
? (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.lib.json')
|
|
34
|
+
: (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'tsconfig.json'))
|
|
35
|
+
? (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.json')
|
|
36
|
+
: undefined;
|
|
37
|
+
}
|
|
38
|
+
function getNxTargetOptions(target, context) {
|
|
39
|
+
const targetObj = (0, devkit_1.parseTargetString)(target, context);
|
|
40
|
+
return (0, devkit_1.readTargetOptions)(targetObj, context);
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Tree } from 'nx/src/generators/tree';
|
|
2
|
+
type VitestDependenciesVersions = {
|
|
3
|
+
vitest: string;
|
|
4
|
+
vitestUi: string;
|
|
5
|
+
vitestCoverageV8: string;
|
|
6
|
+
vitestCoverageIstanbul: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function getVitestDependenciesVersionsToInstall(tree: Tree): Promise<VitestDependenciesVersions>;
|
|
9
|
+
export declare function isVitestV1(tree: Tree): Promise<boolean>;
|
|
10
|
+
export declare function isVitestV2(tree: Tree): Promise<boolean>;
|
|
11
|
+
export declare function getInstalledVitestVersion(tree: Tree): string;
|
|
12
|
+
export declare function getInstalledViteVersion(tree: Tree): string;
|
|
13
|
+
export declare function getInstalledViteMajorVersion(tree: Tree): 5 | 6 | 7 | undefined;
|
|
14
|
+
export declare function getInstalledVitestVersionFromGraph(): Promise<string>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=version-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/vitest/src/utils/version-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAcnD,KAAK,0BAA0B,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,wBAAsB,sCAAsC,CAC1D,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,0BAA0B,CAAC,CAwBrC;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,IAAI,oBAM1C;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,IAAI,oBAM1C;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAiB5D;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAe1D;AAED,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,IAAI,GACT,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAWvB;AAED,wBAAsB,kCAAkC,oBASvD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVitestDependenciesVersionsToInstall = getVitestDependenciesVersionsToInstall;
|
|
4
|
+
exports.isVitestV1 = isVitestV1;
|
|
5
|
+
exports.isVitestV2 = isVitestV2;
|
|
6
|
+
exports.getInstalledVitestVersion = getInstalledVitestVersion;
|
|
7
|
+
exports.getInstalledViteVersion = getInstalledViteVersion;
|
|
8
|
+
exports.getInstalledViteMajorVersion = getInstalledViteMajorVersion;
|
|
9
|
+
exports.getInstalledVitestVersionFromGraph = getInstalledVitestVersionFromGraph;
|
|
10
|
+
const devkit_1 = require("@nx/devkit");
|
|
11
|
+
const semver_1 = require("semver");
|
|
12
|
+
const versions_1 = require("./versions");
|
|
13
|
+
async function getVitestDependenciesVersionsToInstall(tree) {
|
|
14
|
+
if (await isVitestV1(tree)) {
|
|
15
|
+
return {
|
|
16
|
+
vitest: versions_1.vitestV1Version,
|
|
17
|
+
vitestUi: versions_1.vitestV1Version,
|
|
18
|
+
vitestCoverageV8: versions_1.vitestV1CoverageV8Version,
|
|
19
|
+
vitestCoverageIstanbul: versions_1.vitestV1CoverageIstanbulVersion,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
else if (await isVitestV2(tree)) {
|
|
23
|
+
return {
|
|
24
|
+
vitest: versions_1.vitestV2Version,
|
|
25
|
+
vitestUi: versions_1.vitestV2Version,
|
|
26
|
+
vitestCoverageV8: versions_1.vitestV2CoverageV8Version,
|
|
27
|
+
vitestCoverageIstanbul: versions_1.vitestV2CoverageIstanbulVersion,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// Default to latest (v3)
|
|
32
|
+
return {
|
|
33
|
+
vitest: versions_1.vitestVersion,
|
|
34
|
+
vitestUi: versions_1.vitestVersion,
|
|
35
|
+
vitestCoverageV8: versions_1.vitestCoverageV8Version,
|
|
36
|
+
vitestCoverageIstanbul: versions_1.vitestCoverageIstanbulVersion,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function isVitestV1(tree) {
|
|
41
|
+
let installedVitestVersion = await getInstalledVitestVersionFromGraph();
|
|
42
|
+
if (!installedVitestVersion) {
|
|
43
|
+
installedVitestVersion = getInstalledVitestVersion(tree);
|
|
44
|
+
}
|
|
45
|
+
return (0, semver_1.major)(installedVitestVersion) === 1;
|
|
46
|
+
}
|
|
47
|
+
async function isVitestV2(tree) {
|
|
48
|
+
let installedVitestVersion = await getInstalledVitestVersionFromGraph();
|
|
49
|
+
if (!installedVitestVersion) {
|
|
50
|
+
installedVitestVersion = getInstalledVitestVersion(tree);
|
|
51
|
+
}
|
|
52
|
+
return (0, semver_1.major)(installedVitestVersion) === 2;
|
|
53
|
+
}
|
|
54
|
+
function getInstalledVitestVersion(tree) {
|
|
55
|
+
const installedVitestVersion = (0, devkit_1.getDependencyVersionFromPackageJson)(tree, 'vitest');
|
|
56
|
+
if (!installedVitestVersion ||
|
|
57
|
+
installedVitestVersion === 'latest' ||
|
|
58
|
+
installedVitestVersion === 'beta') {
|
|
59
|
+
return (0, semver_1.clean)(versions_1.vitestVersion) ?? (0, semver_1.coerce)(versions_1.vitestVersion).version;
|
|
60
|
+
}
|
|
61
|
+
return ((0, semver_1.clean)(installedVitestVersion) ?? (0, semver_1.coerce)(installedVitestVersion).version);
|
|
62
|
+
}
|
|
63
|
+
function getInstalledViteVersion(tree) {
|
|
64
|
+
const installedViteVersion = (0, devkit_1.getDependencyVersionFromPackageJson)(tree, 'vite');
|
|
65
|
+
if (!installedViteVersion ||
|
|
66
|
+
installedViteVersion === 'latest' ||
|
|
67
|
+
installedViteVersion === 'beta') {
|
|
68
|
+
return (0, semver_1.clean)(versions_1.vitestVersion) ?? (0, semver_1.coerce)(versions_1.vitestVersion).version;
|
|
69
|
+
}
|
|
70
|
+
return (0, semver_1.clean)(installedViteVersion) ?? (0, semver_1.coerce)(installedViteVersion).version;
|
|
71
|
+
}
|
|
72
|
+
function getInstalledViteMajorVersion(tree) {
|
|
73
|
+
const installedViteVersion = getInstalledViteVersion(tree);
|
|
74
|
+
if (!installedViteVersion) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const installedMajor = (0, semver_1.major)(installedViteVersion);
|
|
78
|
+
if (installedMajor < 5 || installedMajor > 7) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return installedMajor;
|
|
82
|
+
}
|
|
83
|
+
async function getInstalledVitestVersionFromGraph() {
|
|
84
|
+
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
|
85
|
+
const vitestDep = graph.externalNodes?.['npm:vitest'];
|
|
86
|
+
if (!vitestDep) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
return ((0, semver_1.clean)(vitestDep.data.version) ?? (0, semver_1.coerce)(vitestDep.data.version).version);
|
|
90
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const nxVersion: any;
|
|
2
|
+
export declare const viteVersion = "^7.0.0";
|
|
3
|
+
export declare const viteV6Version = "^6.0.0";
|
|
4
|
+
export declare const viteV5Version = "^5.0.0";
|
|
5
|
+
export declare const vitestVersion = "^3.0.0";
|
|
6
|
+
export declare const vitestV2Version = "^2.1.8";
|
|
7
|
+
export declare const vitestV1Version = "^1.3.1";
|
|
8
|
+
export declare const vitePluginReactVersion = "^4.2.0";
|
|
9
|
+
export declare const vitePluginReactSwcVersion = "^3.5.0";
|
|
10
|
+
export declare const jsdomVersion = "~22.1.0";
|
|
11
|
+
export declare const vitePluginDtsVersion = "~4.5.0";
|
|
12
|
+
export declare const ajvVersion = "^8.0.0";
|
|
13
|
+
export declare const happyDomVersion = "~9.20.3";
|
|
14
|
+
export declare const edgeRuntimeVmVersion = "~3.0.2";
|
|
15
|
+
export declare const jitiVersion = "2.4.2";
|
|
16
|
+
export declare const analogVitestAngular = "~1.19.1";
|
|
17
|
+
export declare const vitestCoverageV8Version = "^3.0.5";
|
|
18
|
+
export declare const vitestV2CoverageV8Version = "^2.1.8";
|
|
19
|
+
export declare const vitestV1CoverageV8Version = "^1.0.4";
|
|
20
|
+
export declare const vitestCoverageIstanbulVersion = "^3.0.5";
|
|
21
|
+
export declare const vitestV2CoverageIstanbulVersion = "^2.1.8";
|
|
22
|
+
export declare const vitestV1CoverageIstanbulVersion = "^1.0.4";
|
|
23
|
+
//# sourceMappingURL=versions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../../../../../packages/vitest/src/utils/versions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,KAAwC,CAAC;AAE/D,eAAO,MAAM,WAAW,WAAW,CAAC;AACpC,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,sBAAsB,WAAW,CAAC;AAC/C,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAClD,eAAO,MAAM,YAAY,YAAY,CAAC;AACtC,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAC7C,eAAO,MAAM,UAAU,WAAW,CAAC;AACnC,eAAO,MAAM,eAAe,YAAY,CAAC;AACzC,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAC7C,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAG7C,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAChD,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAClD,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAClD,eAAO,MAAM,6BAA6B,WAAW,CAAC;AACtD,eAAO,MAAM,+BAA+B,WAAW,CAAC;AACxD,eAAO,MAAM,+BAA+B,WAAW,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vitestV1CoverageIstanbulVersion = exports.vitestV2CoverageIstanbulVersion = exports.vitestCoverageIstanbulVersion = exports.vitestV1CoverageV8Version = exports.vitestV2CoverageV8Version = exports.vitestCoverageV8Version = exports.analogVitestAngular = exports.jitiVersion = exports.edgeRuntimeVmVersion = exports.happyDomVersion = exports.ajvVersion = exports.vitePluginDtsVersion = exports.jsdomVersion = exports.vitePluginReactSwcVersion = exports.vitePluginReactVersion = exports.vitestV1Version = exports.vitestV2Version = exports.vitestVersion = exports.viteV5Version = exports.viteV6Version = exports.viteVersion = exports.nxVersion = void 0;
|
|
4
|
+
exports.nxVersion = require('../../package.json').version;
|
|
5
|
+
exports.viteVersion = '^7.0.0';
|
|
6
|
+
exports.viteV6Version = '^6.0.0';
|
|
7
|
+
exports.viteV5Version = '^5.0.0';
|
|
8
|
+
exports.vitestVersion = '^3.0.0';
|
|
9
|
+
exports.vitestV2Version = '^2.1.8';
|
|
10
|
+
exports.vitestV1Version = '^1.3.1';
|
|
11
|
+
exports.vitePluginReactVersion = '^4.2.0';
|
|
12
|
+
exports.vitePluginReactSwcVersion = '^3.5.0';
|
|
13
|
+
exports.jsdomVersion = '~22.1.0';
|
|
14
|
+
exports.vitePluginDtsVersion = '~4.5.0';
|
|
15
|
+
exports.ajvVersion = '^8.0.0';
|
|
16
|
+
exports.happyDomVersion = '~9.20.3';
|
|
17
|
+
exports.edgeRuntimeVmVersion = '~3.0.2';
|
|
18
|
+
exports.jitiVersion = '2.4.2';
|
|
19
|
+
exports.analogVitestAngular = '~1.19.1';
|
|
20
|
+
// Coverage providers
|
|
21
|
+
exports.vitestCoverageV8Version = '^3.0.5';
|
|
22
|
+
exports.vitestV2CoverageV8Version = '^2.1.8';
|
|
23
|
+
exports.vitestV1CoverageV8Version = '^1.0.4';
|
|
24
|
+
exports.vitestCoverageIstanbulVersion = '^3.0.5';
|
|
25
|
+
exports.vitestV2CoverageIstanbulVersion = '^2.1.8';
|
|
26
|
+
exports.vitestV1CoverageIstanbulVersion = '^1.0.4';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { TargetFlags } from './generator-utils';
|
|
3
|
+
export declare function ensureViteConfigIsCorrect(tree: Tree, path: string, buildConfigString: string, buildConfigObject: {}, imports: string[], plugins: string[], testConfigString: string, testConfigObject: {}, cacheDir: string, projectAlreadyHasViteTargets?: TargetFlags): boolean;
|
|
4
|
+
//# sourceMappingURL=vite-config-edit-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-config-edit-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/vitest/src/utils/vite-config-edit-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,IAAI,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQhD,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,EACZ,iBAAiB,EAAE,MAAM,EACzB,iBAAiB,EAAE,EAAE,EACrB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,MAAM,EAAE,EACjB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,EAAE,EACpB,QAAQ,EAAE,MAAM,EAChB,4BAA4B,CAAC,EAAE,WAAW,GACzC,OAAO,CAwCT"}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureViteConfigIsCorrect = ensureViteConfigIsCorrect;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
function ensureViteConfigIsCorrect(tree, path, buildConfigString, buildConfigObject, imports, plugins, testConfigString, testConfigObject, cacheDir, projectAlreadyHasViteTargets) {
|
|
7
|
+
const fileContent = tree.read(path, 'utf-8');
|
|
8
|
+
let updatedContent = undefined;
|
|
9
|
+
if (!projectAlreadyHasViteTargets?.test && testConfigString?.length) {
|
|
10
|
+
updatedContent = handleBuildOrTestNode(fileContent, testConfigString, testConfigObject, 'test');
|
|
11
|
+
}
|
|
12
|
+
if (!projectAlreadyHasViteTargets?.build && buildConfigString?.length) {
|
|
13
|
+
updatedContent = handleBuildOrTestNode(updatedContent ?? fileContent, buildConfigString, buildConfigObject, 'build');
|
|
14
|
+
}
|
|
15
|
+
updatedContent =
|
|
16
|
+
handlePluginNode(updatedContent ?? fileContent, imports, plugins) ??
|
|
17
|
+
updatedContent;
|
|
18
|
+
if (cacheDir?.length) {
|
|
19
|
+
updatedContent = handleCacheDirNode(updatedContent ?? fileContent, cacheDir);
|
|
20
|
+
}
|
|
21
|
+
if (updatedContent) {
|
|
22
|
+
tree.write(path, updatedContent);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function handleBuildOrTestNode(updatedFileContent, configContentString, configContentObject, name) {
|
|
30
|
+
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
31
|
+
const buildOrTestNode = tsquery.query(updatedFileContent, `PropertyAssignment:has(Identifier[name="${name}"])`);
|
|
32
|
+
if (buildOrTestNode.length) {
|
|
33
|
+
return tsquery.replace(updatedFileContent, `PropertyAssignment:has(Identifier[name="${name}"])`, (node) => {
|
|
34
|
+
const existingProperties = tsquery.query(node.initializer, 'PropertyAssignment');
|
|
35
|
+
let updatedPropsString = '';
|
|
36
|
+
for (const prop of existingProperties) {
|
|
37
|
+
const propName = prop.name.getText();
|
|
38
|
+
if (!configContentObject[propName] &&
|
|
39
|
+
propName !== 'dir' &&
|
|
40
|
+
propName !== 'reportsDirectory' &&
|
|
41
|
+
propName !== 'provider') {
|
|
42
|
+
// NOTE: Watch for formatting.
|
|
43
|
+
updatedPropsString += ` '${propName}': ${prop.initializer.getText()},\n`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const [propName, propValue] of Object.entries(configContentObject)) {
|
|
47
|
+
// NOTE: Watch for formatting.
|
|
48
|
+
if (propName === 'coverage') {
|
|
49
|
+
let propString = ` '${propName}': {\n`;
|
|
50
|
+
for (const [pName, pValue] of Object.entries(propValue)) {
|
|
51
|
+
if (pName === 'provider') {
|
|
52
|
+
propString += ` '${pName}': ${pValue} as const,\n`;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
propString += ` '${pName}': '${pValue}',\n`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
propString += `}`;
|
|
59
|
+
updatedPropsString += `${propString}\n`;
|
|
60
|
+
}
|
|
61
|
+
else if (propName === 'lib') {
|
|
62
|
+
let propString = ` '${propName}': {\n`;
|
|
63
|
+
for (const [pName, pValue] of Object.entries(propValue)) {
|
|
64
|
+
if (pName === 'formats') {
|
|
65
|
+
propString += ` '${pName}': [${pValue
|
|
66
|
+
.map((format) => `'${format}' as const`)
|
|
67
|
+
.join(', ')}],\n`;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
propString += ` '${pName}': ${JSON.stringify(pValue)},\n`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
propString += ` },`;
|
|
74
|
+
updatedPropsString += `${propString}\n`;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
updatedPropsString += ` '${propName}': ${JSON.stringify(propValue)},\n`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return `${name}: {
|
|
81
|
+
${updatedPropsString} }`;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const foundDefineConfig = tsquery.query(updatedFileContent, 'CallExpression:has(Identifier[name="defineConfig"])');
|
|
86
|
+
if (foundDefineConfig.length) {
|
|
87
|
+
const conditionalConfig = tsquery.query(foundDefineConfig[0], 'ArrowFunction');
|
|
88
|
+
if (conditionalConfig.length) {
|
|
89
|
+
if (name === 'build') {
|
|
90
|
+
return transformConditionalConfig(conditionalConfig, updatedFileContent, configContentString);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// no test config in conditional config
|
|
94
|
+
return updatedFileContent;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const propertyAssignments = tsquery.query(foundDefineConfig[0], 'PropertyAssignment');
|
|
99
|
+
if (propertyAssignments.length) {
|
|
100
|
+
return (0, devkit_1.applyChangesToString)(updatedFileContent, [
|
|
101
|
+
{
|
|
102
|
+
type: devkit_1.ChangeType.Insert,
|
|
103
|
+
index: propertyAssignments[0].getStart(),
|
|
104
|
+
text: configContentString,
|
|
105
|
+
},
|
|
106
|
+
]);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return (0, devkit_1.applyChangesToString)(updatedFileContent, [
|
|
110
|
+
{
|
|
111
|
+
type: devkit_1.ChangeType.Insert,
|
|
112
|
+
index: foundDefineConfig[0].getStart() + 14,
|
|
113
|
+
text: configContentString,
|
|
114
|
+
},
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// build config does not exist and defineConfig is not used
|
|
121
|
+
// could also potentially be invalid syntax, so try-catch
|
|
122
|
+
try {
|
|
123
|
+
const defaultExport = tsquery.query(updatedFileContent, 'ExportAssignment');
|
|
124
|
+
const found = tsquery.query(defaultExport?.[0], 'ObjectLiteralExpression');
|
|
125
|
+
const startOfObject = found?.[0].getStart();
|
|
126
|
+
return (0, devkit_1.applyChangesToString)(updatedFileContent, [
|
|
127
|
+
{
|
|
128
|
+
type: devkit_1.ChangeType.Insert,
|
|
129
|
+
index: startOfObject + 1,
|
|
130
|
+
text: configContentString,
|
|
131
|
+
},
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return updatedFileContent;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function transformCurrentBuildObject(index, returnStatements, appFileContent, buildConfigObject) {
|
|
141
|
+
if (!returnStatements?.[index]) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
145
|
+
const currentBuildObject = tsquery
|
|
146
|
+
.query(returnStatements[index], 'ObjectLiteralExpression')?.[0]
|
|
147
|
+
.getText();
|
|
148
|
+
const currentBuildObjectStart = returnStatements[index].getStart();
|
|
149
|
+
const currentBuildObjectEnd = returnStatements[index].getEnd();
|
|
150
|
+
const newReturnObject = tsquery.replace(returnStatements[index].getText(), 'ObjectLiteralExpression', (_node) => {
|
|
151
|
+
return `{
|
|
152
|
+
...${currentBuildObject},
|
|
153
|
+
...${JSON.stringify(buildConfigObject)}
|
|
154
|
+
}`;
|
|
155
|
+
});
|
|
156
|
+
const newContents = (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
157
|
+
{
|
|
158
|
+
type: devkit_1.ChangeType.Delete,
|
|
159
|
+
start: currentBuildObjectStart,
|
|
160
|
+
length: currentBuildObjectEnd - currentBuildObjectStart,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
type: devkit_1.ChangeType.Insert,
|
|
164
|
+
index: currentBuildObjectStart,
|
|
165
|
+
text: newReturnObject,
|
|
166
|
+
},
|
|
167
|
+
]);
|
|
168
|
+
return newContents;
|
|
169
|
+
}
|
|
170
|
+
function transformConditionalConfig(conditionalConfig, appFileContent, buildConfigObject) {
|
|
171
|
+
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
172
|
+
const { SyntaxKind } = require('typescript');
|
|
173
|
+
const functionBlock = tsquery.query(conditionalConfig[0], 'Block');
|
|
174
|
+
const ifStatement = tsquery.query(functionBlock?.[0], 'IfStatement');
|
|
175
|
+
const binaryExpressions = tsquery.query(ifStatement?.[0], 'BinaryExpression');
|
|
176
|
+
const buildExists = binaryExpressions?.find((binaryExpression) => binaryExpression.getText() === `command === 'build'`);
|
|
177
|
+
const buildExistsExpressionIndex = binaryExpressions?.findIndex((binaryExpression) => binaryExpression.getText() === `command === 'build'`);
|
|
178
|
+
const serveExists = binaryExpressions?.find((binaryExpression) => binaryExpression.getText() === `command === 'serve'`);
|
|
179
|
+
const elseKeywordExists = (0, js_1.findNodes)(ifStatement?.[0], SyntaxKind.ElseKeyword);
|
|
180
|
+
const returnStatements = tsquery.query(ifStatement[0], 'ReturnStatement');
|
|
181
|
+
if (!buildExists) {
|
|
182
|
+
if (serveExists && elseKeywordExists) {
|
|
183
|
+
// build options live inside the else block
|
|
184
|
+
return (transformCurrentBuildObject(returnStatements?.length - 1, returnStatements, appFileContent, buildConfigObject) ?? appFileContent);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// no build options exist yet
|
|
188
|
+
const functionBlockStart = functionBlock?.[0].getStart();
|
|
189
|
+
const newContents = (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
190
|
+
{
|
|
191
|
+
type: devkit_1.ChangeType.Insert,
|
|
192
|
+
index: functionBlockStart + 1,
|
|
193
|
+
text: `
|
|
194
|
+
if (command === 'build') {
|
|
195
|
+
return ${JSON.stringify(buildConfigObject)}
|
|
196
|
+
}
|
|
197
|
+
`,
|
|
198
|
+
},
|
|
199
|
+
]);
|
|
200
|
+
return newContents;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
// build already exists
|
|
205
|
+
// it will be the return statement which lives
|
|
206
|
+
// at the buildExistsExpressionIndex
|
|
207
|
+
return (transformCurrentBuildObject(buildExistsExpressionIndex, returnStatements, appFileContent, buildConfigObject) ?? appFileContent);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function handlePluginNode(appFileContent, imports, plugins) {
|
|
211
|
+
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
212
|
+
const file = tsquery.ast(appFileContent);
|
|
213
|
+
const pluginsNode = tsquery.query(file, 'PropertyAssignment:has(Identifier[name="plugins"])');
|
|
214
|
+
let writeFile = false;
|
|
215
|
+
if (pluginsNode.length) {
|
|
216
|
+
appFileContent = tsquery.replace(file.getText(), 'PropertyAssignment:has(Identifier[name="plugins"])', (node) => {
|
|
217
|
+
const found = tsquery.query(node, 'ArrayLiteralExpression');
|
|
218
|
+
let updatedPluginsString = '';
|
|
219
|
+
const existingPluginNodes = found?.[0].elements ?? [];
|
|
220
|
+
for (const plugin of existingPluginNodes) {
|
|
221
|
+
updatedPluginsString += `${plugin.getText()}, `;
|
|
222
|
+
}
|
|
223
|
+
for (const plugin of plugins) {
|
|
224
|
+
if (!existingPluginNodes?.some((node) => node.getText().includes(plugin))) {
|
|
225
|
+
updatedPluginsString += `${plugin}, `;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return `plugins: [${updatedPluginsString}]`;
|
|
229
|
+
});
|
|
230
|
+
writeFile = true;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// Plugins node does not exist yet
|
|
234
|
+
// So make one from scratch
|
|
235
|
+
const foundDefineConfig = tsquery.query(file, 'CallExpression:has(Identifier[name="defineConfig"])');
|
|
236
|
+
if (foundDefineConfig.length) {
|
|
237
|
+
const conditionalConfig = tsquery.query(foundDefineConfig[0], 'ArrowFunction');
|
|
238
|
+
if (conditionalConfig.length) {
|
|
239
|
+
// We are NOT transforming the conditional config
|
|
240
|
+
// with plugins
|
|
241
|
+
writeFile = false;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
const propertyAssignments = tsquery.query(foundDefineConfig[0], 'PropertyAssignment');
|
|
245
|
+
if (propertyAssignments.length) {
|
|
246
|
+
appFileContent = (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
247
|
+
{
|
|
248
|
+
type: devkit_1.ChangeType.Insert,
|
|
249
|
+
index: propertyAssignments[0].getStart(),
|
|
250
|
+
text: `plugins: [${plugins.join(', ')}],`,
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
253
|
+
writeFile = true;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
appFileContent = (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
257
|
+
{
|
|
258
|
+
type: devkit_1.ChangeType.Insert,
|
|
259
|
+
index: foundDefineConfig[0].getStart() + 14,
|
|
260
|
+
text: `plugins: [${plugins.join(', ')}],`,
|
|
261
|
+
},
|
|
262
|
+
]);
|
|
263
|
+
writeFile = true;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
// Plugins option does not exist and defineConfig is not used
|
|
269
|
+
// could also potentially be invalid syntax, so try-catch
|
|
270
|
+
try {
|
|
271
|
+
const defaultExport = tsquery.query(file, 'ExportAssignment');
|
|
272
|
+
const found = tsquery?.query(defaultExport?.[0], 'ObjectLiteralExpression');
|
|
273
|
+
const startOfObject = found?.[0].getStart();
|
|
274
|
+
appFileContent = (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
275
|
+
{
|
|
276
|
+
type: devkit_1.ChangeType.Insert,
|
|
277
|
+
index: startOfObject + 1,
|
|
278
|
+
text: `plugins: [${plugins.join(', ')}],`,
|
|
279
|
+
},
|
|
280
|
+
]);
|
|
281
|
+
writeFile = true;
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
writeFile = false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (writeFile) {
|
|
289
|
+
const filteredImports = filterImport(appFileContent, imports);
|
|
290
|
+
return filteredImports.join(';\n') + '\n' + appFileContent;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function filterImport(appFileContent, imports) {
|
|
294
|
+
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
295
|
+
const file = tsquery.ast(appFileContent);
|
|
296
|
+
const importNodes = tsquery.query(file, ':matches(ImportDeclaration, VariableStatement)');
|
|
297
|
+
const importsArrayExisting = importNodes?.map((node) => {
|
|
298
|
+
return node.getText().slice(0, -1);
|
|
299
|
+
});
|
|
300
|
+
return imports.filter((importString) => {
|
|
301
|
+
return !importsArrayExisting?.includes(importString);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
function handleCacheDirNode(appFileContent, cacheDir) {
|
|
305
|
+
const { tsquery } = require('@phenomnomnominal/tsquery');
|
|
306
|
+
const file = tsquery.ast(appFileContent);
|
|
307
|
+
const cacheDirNode = tsquery.query(file, 'PropertyAssignment:has(Identifier[name="cacheDir"])');
|
|
308
|
+
if (!cacheDirNode?.length || cacheDirNode?.length === 0) {
|
|
309
|
+
// cacheDir node does not exist yet
|
|
310
|
+
// So make one from scratch
|
|
311
|
+
const foundDefineConfig = tsquery.query(file, 'CallExpression:has(Identifier[name="defineConfig"])');
|
|
312
|
+
if (foundDefineConfig.length) {
|
|
313
|
+
const conditionalConfig = tsquery.query(foundDefineConfig[0], 'ArrowFunction');
|
|
314
|
+
if (conditionalConfig.length) {
|
|
315
|
+
// We are NOT transforming the conditional config
|
|
316
|
+
// with cacheDir
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
const propertyAssignments = tsquery.query(foundDefineConfig[0], 'PropertyAssignment');
|
|
320
|
+
if (propertyAssignments.length) {
|
|
321
|
+
appFileContent = (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
322
|
+
{
|
|
323
|
+
type: devkit_1.ChangeType.Insert,
|
|
324
|
+
index: propertyAssignments[0].getStart(),
|
|
325
|
+
text: cacheDir,
|
|
326
|
+
},
|
|
327
|
+
]);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
appFileContent = (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
331
|
+
{
|
|
332
|
+
type: devkit_1.ChangeType.Insert,
|
|
333
|
+
index: foundDefineConfig[0].getStart() + 14,
|
|
334
|
+
text: cacheDir,
|
|
335
|
+
},
|
|
336
|
+
]);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
// cacheDir option does not exist and defineConfig is not used
|
|
342
|
+
// could also potentially be invalid syntax, so try-catch
|
|
343
|
+
try {
|
|
344
|
+
const defaultExport = tsquery.query(file, 'ExportAssignment');
|
|
345
|
+
const found = tsquery?.query(defaultExport?.[0], 'ObjectLiteralExpression');
|
|
346
|
+
const startOfObject = found?.[0].getStart();
|
|
347
|
+
appFileContent = (0, devkit_1.applyChangesToString)(appFileContent, [
|
|
348
|
+
{
|
|
349
|
+
type: devkit_1.ChangeType.Insert,
|
|
350
|
+
index: startOfObject + 1,
|
|
351
|
+
text: cacheDir,
|
|
352
|
+
},
|
|
353
|
+
]);
|
|
354
|
+
}
|
|
355
|
+
catch { }
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return appFileContent;
|
|
359
|
+
}
|