@nx/vite 17.2.0-beta.0 → 17.2.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 +35 -15
- package/package.json +8 -7
- package/plugins/rollup-replace-files.plugin.d.ts +2 -2
- package/plugins/rollup-replace-files.plugin.js +1 -1
- package/plugins/rollup-replace-files.plugin.js.map +1 -1
- package/src/executors/build/build.impl.d.ts +1 -1
- package/src/executors/build/build.impl.js +80 -18
- package/src/executors/build/build.impl.js.map +1 -1
- package/src/executors/build/schema.d.ts +3 -15
- package/src/executors/build/schema.json +0 -86
- package/src/executors/dev-server/dev-server.impl.js +31 -8
- package/src/executors/dev-server/dev-server.impl.js.map +1 -1
- package/src/executors/dev-server/schema.d.ts +0 -10
- package/src/executors/dev-server/schema.json +0 -63
- package/src/executors/preview-server/preview-server.impl.js +47 -14
- package/src/executors/preview-server/preview-server.impl.js.map +1 -1
- package/src/executors/preview-server/schema.d.ts +0 -7
- package/src/executors/preview-server/schema.json +0 -50
- 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 +69 -0
- package/src/executors/test/lib/utils.js.map +1 -0
- package/src/executors/test/schema.d.ts +2 -8
- package/src/executors/test/schema.json +7 -43
- package/src/executors/test/vitest.impl.js +17 -113
- package/src/executors/test/vitest.impl.js.map +1 -1
- package/src/generators/configuration/configuration.js +4 -4
- package/src/generators/configuration/configuration.js.map +1 -1
- package/src/generators/init/init.d.ts +1 -1
- package/src/generators/init/init.js +23 -15
- package/src/generators/init/init.js.map +1 -1
- package/src/generators/vitest/files/tsconfig.spec.json__tmpl__ +1 -0
- package/src/generators/vitest/vitest-generator.js +2 -1
- package/src/generators/vitest/vitest-generator.js.map +1 -1
- 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 +61 -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 +88 -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 +71 -0
- package/src/migrations/update-17-2-0/lib/edit-test-config.js.map +1 -0
- package/src/migrations/update-17-2-0/lib/find-vite-config.d.ts +2 -0
- package/src/migrations/update-17-2-0/lib/find-vite-config.js +25 -0
- package/src/migrations/update-17-2-0/lib/find-vite-config.js.map +1 -0
- package/src/migrations/update-17-2-0/update-vite-config.d.ts +2 -0
- package/src/migrations/update-17-2-0/update-vite-config.js +48 -0
- package/src/migrations/update-17-2-0/update-vite-config.js.map +1 -0
- package/src/utils/executor-utils.js +4 -4
- package/src/utils/executor-utils.js.map +1 -1
- package/src/utils/generator-utils.d.ts +2 -1
- package/src/utils/generator-utils.js +38 -27
- package/src/utils/generator-utils.js.map +1 -1
- package/src/utils/options-utils.d.ts +3 -15
- package/src/utils/options-utils.js +17 -61
- package/src/utils/options-utils.js.map +1 -1
- package/src/utils/test-files/react-lib-non-buildable-jest.json +1 -4
- package/src/utils/test-files/react-lib-non-buildable-vitest.json +1 -4
- package/src/utils/test-files/react-mixed-project.config.json +1 -6
- package/src/utils/test-files/react-project.config.json +1 -4
- package/src/utils/test-files/react-vite-project.config.json +1 -4
- package/src/utils/test-files/unknown-project.config.json +1 -4
- package/src/utils/test-files/web-project.config.json +1 -4
- package/src/utils/versions.d.ts +3 -3
- package/src/utils/versions.js +3 -3
- package/src/utils/versions.js.map +1 -1
- package/src/utils/vite-config-edit-utils.js +1 -1
- package/src/utils/vite-config-edit-utils.js.map +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "updateBuildOutDirAndRoot", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return updateBuildOutDirAndRoot;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _devkit = require("@nx/devkit");
|
|
9
|
+
const _tsquery = require("@phenomnomnominal/tsquery");
|
|
10
|
+
const ts = require("typescript");
|
|
11
|
+
function updateBuildOutDirAndRoot(options, configContents, projectConfig, targetName, tree, projectName) {
|
|
12
|
+
var _tsquery_query;
|
|
13
|
+
const foundDefineConfig = (_tsquery_query = _tsquery.tsquery.query(configContents, 'CallExpression:has(Identifier[name="defineConfig"])')) == null ? void 0 : _tsquery_query[0];
|
|
14
|
+
if (!foundDefineConfig) {
|
|
15
|
+
_devkit.logger.warn(`
|
|
16
|
+
Could not find defineConfig in your vite.config file.
|
|
17
|
+
Please add the build.outDir and root options to your vite.config file.
|
|
18
|
+
`);
|
|
19
|
+
}
|
|
20
|
+
configContents = fixBuild(options, configContents, projectConfig, targetName, tree, projectName, foundDefineConfig);
|
|
21
|
+
configContents = addRoot(configContents, foundDefineConfig);
|
|
22
|
+
return configContents;
|
|
23
|
+
}
|
|
24
|
+
function fixBuild(options, configContents, projectConfig, targetName, tree, projectName, foundDefineConfig) {
|
|
25
|
+
var _tsquery_query;
|
|
26
|
+
let outputPath = '';
|
|
27
|
+
// In vite.config.ts, we want to keep the path relative to workspace root
|
|
28
|
+
if (options.outputPath) {
|
|
29
|
+
outputPath = (0, _devkit.joinPathFragments)((0, _devkit.offsetFromRoot)(projectConfig.root), options.outputPath);
|
|
30
|
+
} else {
|
|
31
|
+
outputPath = (0, _devkit.joinPathFragments)((0, _devkit.offsetFromRoot)(projectConfig.root), 'dist', projectConfig.root);
|
|
32
|
+
}
|
|
33
|
+
// In project.json, we want to keep the path starting from workspace root
|
|
34
|
+
projectConfig.targets[targetName].options.outputPath = options.outputPath ? options.outputPath : (0, _devkit.joinPathFragments)('dist', projectConfig.root);
|
|
35
|
+
(0, _devkit.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
36
|
+
const buildObject = (_tsquery_query = _tsquery.tsquery.query(configContents, `PropertyAssignment:has(Identifier[name="build"])`)) == null ? void 0 : _tsquery_query[0];
|
|
37
|
+
let buildOutDir;
|
|
38
|
+
if (buildObject) {
|
|
39
|
+
buildOutDir = _tsquery.tsquery.query(buildObject, `PropertyAssignment:has(Identifier[name="outDir"])`);
|
|
40
|
+
}
|
|
41
|
+
if ((buildOutDir == null ? void 0 : buildOutDir.length) > 0) {
|
|
42
|
+
return configContents;
|
|
43
|
+
} else if (buildObject) {
|
|
44
|
+
// has build, has no outDir
|
|
45
|
+
// so add outDir
|
|
46
|
+
return (0, _devkit.applyChangesToString)(configContents, [
|
|
47
|
+
{
|
|
48
|
+
type: _devkit.ChangeType.Insert,
|
|
49
|
+
index: buildObject.getStart() + `build: {`.length + 1,
|
|
50
|
+
text: `outDir: '${outputPath}',`
|
|
51
|
+
}
|
|
52
|
+
]);
|
|
53
|
+
} else {
|
|
54
|
+
return addBuildProperty(configContents, outputPath, foundDefineConfig);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function addRoot(configFileContents, foundDefineConfig) {
|
|
58
|
+
var _tsquery_query;
|
|
59
|
+
const rootOption = (_tsquery_query = _tsquery.tsquery.query(configFileContents, `PropertyAssignment:has(Identifier[name="root"]) Identifier[name="__dirname"]`)) == null ? void 0 : _tsquery_query[0];
|
|
60
|
+
if (rootOption || !foundDefineConfig) {
|
|
61
|
+
return configFileContents;
|
|
62
|
+
} else {
|
|
63
|
+
return (0, _devkit.applyChangesToString)(configFileContents, [
|
|
64
|
+
{
|
|
65
|
+
type: _devkit.ChangeType.Insert,
|
|
66
|
+
index: foundDefineConfig.getStart() + 14,
|
|
67
|
+
text: `root: __dirname,`
|
|
68
|
+
}
|
|
69
|
+
]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function addBuildProperty(configFileContents, outputPath, foundDefineConfig) {
|
|
73
|
+
if (foundDefineConfig) {
|
|
74
|
+
return (0, _devkit.applyChangesToString)(configFileContents, [
|
|
75
|
+
{
|
|
76
|
+
type: _devkit.ChangeType.Insert,
|
|
77
|
+
index: foundDefineConfig.getStart() + 14,
|
|
78
|
+
text: `build: {
|
|
79
|
+
outDir: '${outputPath}',
|
|
80
|
+
},`
|
|
81
|
+
}
|
|
82
|
+
]);
|
|
83
|
+
} else {
|
|
84
|
+
return configFileContents;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=edit-build-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/migrations/update-17-2-0/lib/edit-build-config.ts"],"sourcesContent":["import {\n ChangeType,\n ProjectConfiguration,\n Tree,\n applyChangesToString,\n joinPathFragments,\n logger,\n offsetFromRoot,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { tsquery } from '@phenomnomnominal/tsquery';\nimport ts = require('typescript');\n\nexport function updateBuildOutDirAndRoot(\n options: Record<string, any>,\n configContents: string,\n projectConfig: ProjectConfiguration,\n targetName: string,\n tree: Tree,\n projectName: string\n): string {\n const foundDefineConfig = tsquery.query(\n configContents,\n 'CallExpression:has(Identifier[name=\"defineConfig\"])'\n )?.[0];\n\n if (!foundDefineConfig) {\n logger.warn(`\n Could not find defineConfig in your vite.config file.\n Please add the build.outDir and root options to your vite.config file.\n `);\n }\n\n configContents = fixBuild(\n options,\n configContents,\n projectConfig,\n targetName,\n tree,\n projectName,\n foundDefineConfig\n );\n\n configContents = addRoot(configContents, foundDefineConfig);\n\n return configContents;\n}\n\nfunction fixBuild(\n options: Record<string, any>,\n configContents: string,\n projectConfig: ProjectConfiguration,\n targetName: string,\n tree: Tree,\n projectName: string,\n foundDefineConfig?: ts.Node\n) {\n let outputPath = '';\n\n // In vite.config.ts, we want to keep the path relative to workspace root\n if (options.outputPath) {\n outputPath = joinPathFragments(\n offsetFromRoot(projectConfig.root),\n options.outputPath\n );\n } else {\n outputPath = joinPathFragments(\n offsetFromRoot(projectConfig.root),\n 'dist',\n projectConfig.root\n );\n }\n\n // In project.json, we want to keep the path starting from workspace root\n projectConfig.targets[targetName].options.outputPath = options.outputPath\n ? options.outputPath\n : joinPathFragments('dist', projectConfig.root);\n updateProjectConfiguration(tree, projectName, projectConfig);\n\n const buildObject = tsquery.query(\n configContents,\n `PropertyAssignment:has(Identifier[name=\"build\"])`\n )?.[0];\n let buildOutDir: ts.Node[];\n if (buildObject) {\n buildOutDir = tsquery.query(\n buildObject,\n `PropertyAssignment:has(Identifier[name=\"outDir\"])`\n );\n }\n\n if (buildOutDir?.length > 0) {\n return configContents;\n } else if (buildObject) {\n // has build, has no outDir\n // so add outDir\n return applyChangesToString(configContents, [\n {\n type: ChangeType.Insert,\n index: buildObject.getStart() + `build: {`.length + 1,\n text: `outDir: '${outputPath}',`,\n },\n ]);\n } else {\n return addBuildProperty(configContents, outputPath, foundDefineConfig);\n }\n}\n\nfunction addRoot(\n configFileContents: string,\n foundDefineConfig?: ts.Node\n): string {\n const rootOption = tsquery.query(\n configFileContents,\n `PropertyAssignment:has(Identifier[name=\"root\"]) Identifier[name=\"__dirname\"]`\n )?.[0];\n\n if (rootOption || !foundDefineConfig) {\n return configFileContents;\n } else {\n return applyChangesToString(configFileContents, [\n {\n type: ChangeType.Insert,\n index: foundDefineConfig.getStart() + 14,\n text: `root: __dirname,`,\n },\n ]);\n }\n}\n\nfunction addBuildProperty(\n configFileContents: string,\n outputPath: string,\n foundDefineConfig: ts.Node\n): string {\n if (foundDefineConfig) {\n return applyChangesToString(configFileContents, [\n {\n type: ChangeType.Insert,\n index: foundDefineConfig.getStart() + 14,\n text: `build: {\n outDir: '${outputPath}',\n },`,\n },\n ]);\n } else {\n return configFileContents;\n }\n}\n"],"names":["updateBuildOutDirAndRoot","ts","options","configContents","projectConfig","targetName","tree","projectName","tsquery","foundDefineConfig","query","logger","warn","fixBuild","addRoot","outputPath","joinPathFragments","offsetFromRoot","root","targets","updateProjectConfiguration","buildObject","buildOutDir","length","applyChangesToString","type","ChangeType","Insert","index","getStart","text","addBuildProperty","configFileContents","rootOption"],"mappings":"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"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "updateTestConfig", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return updateTestConfig;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _devkit = require("@nx/devkit");
|
|
9
|
+
const _tsquery = require("@phenomnomnominal/tsquery");
|
|
10
|
+
const ts = require("typescript");
|
|
11
|
+
function updateTestConfig(configContents, projectConfig) {
|
|
12
|
+
var _tsquery_query, _projectConfig_targets_test_options, _projectConfig_targets_test, _projectConfig_targets;
|
|
13
|
+
const testObject = (_tsquery_query = _tsquery.tsquery.query(configContents, `PropertyAssignment:has(Identifier[name="test"])`)) == null ? void 0 : _tsquery_query[0];
|
|
14
|
+
let testCoverageDir;
|
|
15
|
+
let testCoverage;
|
|
16
|
+
let provider;
|
|
17
|
+
if (testObject) {
|
|
18
|
+
var _tsquery_query1;
|
|
19
|
+
testCoverage = (_tsquery_query1 = _tsquery.tsquery.query(testObject, `PropertyAssignment:has(Identifier[name="coverage"])`)) == null ? void 0 : _tsquery_query1[0];
|
|
20
|
+
if (testCoverage) {
|
|
21
|
+
var _tsquery_query2, _tsquery_query3;
|
|
22
|
+
testCoverageDir = (_tsquery_query2 = _tsquery.tsquery.query(testCoverage, `PropertyAssignment:has(Identifier[name="reportsDirectory"])`)) == null ? void 0 : _tsquery_query2[0];
|
|
23
|
+
provider = (_tsquery_query3 = _tsquery.tsquery.query(testCoverage, `PropertyAssignment:has(Identifier[name="provider"])`)) == null ? void 0 : _tsquery_query3[0];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let coverageDir = '';
|
|
27
|
+
if ((_projectConfig_targets = projectConfig.targets) == null ? void 0 : (_projectConfig_targets_test = _projectConfig_targets.test) == null ? void 0 : (_projectConfig_targets_test_options = _projectConfig_targets_test.options) == null ? void 0 : _projectConfig_targets_test_options.reportsDirectory) {
|
|
28
|
+
var _projectConfig_targets_test_options1, _projectConfig_targets_test1, _projectConfig_targets1;
|
|
29
|
+
coverageDir = (_projectConfig_targets1 = projectConfig.targets) == null ? void 0 : (_projectConfig_targets_test1 = _projectConfig_targets1.test) == null ? void 0 : (_projectConfig_targets_test_options1 = _projectConfig_targets_test1.options) == null ? void 0 : _projectConfig_targets_test_options1.reportsDirectory;
|
|
30
|
+
} else {
|
|
31
|
+
coverageDir = (0, _devkit.joinPathFragments)((0, _devkit.offsetFromRoot)(projectConfig.root), 'coverage', projectConfig.root);
|
|
32
|
+
}
|
|
33
|
+
if (testCoverageDir) {
|
|
34
|
+
// Do nothing
|
|
35
|
+
} else if (testCoverage) {
|
|
36
|
+
// has test.coverage, has no reportsDirectory
|
|
37
|
+
// so add reportsDirectory
|
|
38
|
+
configContents = (0, _devkit.applyChangesToString)(configContents, [
|
|
39
|
+
{
|
|
40
|
+
type: _devkit.ChangeType.Insert,
|
|
41
|
+
index: testCoverage.getStart() + `coverage: {`.length + 1,
|
|
42
|
+
text: `reportsDirectory: '${coverageDir}',`
|
|
43
|
+
}
|
|
44
|
+
]);
|
|
45
|
+
if (!provider) {
|
|
46
|
+
configContents = (0, _devkit.applyChangesToString)(configContents, [
|
|
47
|
+
{
|
|
48
|
+
type: _devkit.ChangeType.Insert,
|
|
49
|
+
index: testCoverage.getStart() + `coverage: {`.length + 1,
|
|
50
|
+
text: `provider: 'v8',`
|
|
51
|
+
}
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
} else if (testObject) {
|
|
55
|
+
configContents = (0, _devkit.applyChangesToString)(configContents, [
|
|
56
|
+
{
|
|
57
|
+
type: _devkit.ChangeType.Insert,
|
|
58
|
+
index: testObject.getStart() + `test: {`.length + 1,
|
|
59
|
+
text: `coverage: {
|
|
60
|
+
reportsDirectory: '${coverageDir}',
|
|
61
|
+
provider: 'v8',
|
|
62
|
+
},`
|
|
63
|
+
}
|
|
64
|
+
]);
|
|
65
|
+
} else {
|
|
66
|
+
// has no test so do nothing
|
|
67
|
+
}
|
|
68
|
+
return configContents;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=edit-test-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/migrations/update-17-2-0/lib/edit-test-config.ts"],"sourcesContent":["import {\n ChangeType,\n ProjectConfiguration,\n applyChangesToString,\n joinPathFragments,\n offsetFromRoot,\n} from '@nx/devkit';\nimport { tsquery } from '@phenomnomnominal/tsquery';\nimport ts = require('typescript');\n\nexport function updateTestConfig(\n configContents: string,\n projectConfig: ProjectConfiguration\n): string {\n const testObject = tsquery.query(\n configContents,\n `PropertyAssignment:has(Identifier[name=\"test\"])`\n )?.[0];\n let testCoverageDir: ts.Node;\n let testCoverage: ts.Node;\n let provider: ts.Node;\n if (testObject) {\n testCoverage = tsquery.query(\n testObject,\n `PropertyAssignment:has(Identifier[name=\"coverage\"])`\n )?.[0];\n if (testCoverage) {\n testCoverageDir = tsquery.query(\n testCoverage,\n `PropertyAssignment:has(Identifier[name=\"reportsDirectory\"])`\n )?.[0];\n provider = tsquery.query(\n testCoverage,\n `PropertyAssignment:has(Identifier[name=\"provider\"])`\n )?.[0];\n }\n }\n\n let coverageDir = '';\n\n if (projectConfig.targets?.test?.options?.reportsDirectory) {\n coverageDir = projectConfig.targets?.test?.options?.reportsDirectory;\n } else {\n coverageDir = joinPathFragments(\n offsetFromRoot(projectConfig.root),\n 'coverage',\n projectConfig.root\n );\n }\n\n if (testCoverageDir) {\n // Do nothing\n } else if (testCoverage) {\n // has test.coverage, has no reportsDirectory\n // so add reportsDirectory\n configContents = applyChangesToString(configContents, [\n {\n type: ChangeType.Insert,\n index: testCoverage.getStart() + `coverage: {`.length + 1,\n text: `reportsDirectory: '${coverageDir}',`,\n },\n ]);\n if (!provider) {\n configContents = applyChangesToString(configContents, [\n {\n type: ChangeType.Insert,\n index: testCoverage.getStart() + `coverage: {`.length + 1,\n text: `provider: 'v8',`,\n },\n ]);\n }\n } else if (testObject) {\n configContents = applyChangesToString(configContents, [\n {\n type: ChangeType.Insert,\n index: testObject.getStart() + `test: {`.length + 1,\n text: `coverage: {\n reportsDirectory: '${coverageDir}',\n provider: 'v8',\n },`,\n },\n ]);\n } else {\n // has no test so do nothing\n }\n\n return configContents;\n}\n"],"names":["updateTestConfig","ts","configContents","projectConfig","tsquery","testObject","query","testCoverageDir","testCoverage","provider","coverageDir","targets","test","options","reportsDirectory","joinPathFragments","offsetFromRoot","root","applyChangesToString","type","ChangeType","Insert","index","getStart","length","text"],"mappings":";+BAUgBA;;;eAAAA;;;wBAJT;yBACiB;AACxB,MAAOC,aAAa;AAEb,SAASD,iBACdE,cAAsB,EACtBC,aAAmC;QAEhBC,gBA0BfD,qCAAAA,6BAAAA;IA1BJ,MAAME,cAAaD,iBAAAA,gBAAO,CAACE,KAAK,CAC9BJ,gBACA,CAAC,+CAA+C,CAAC,sBAFhCE,cAGhB,CAAC,EAAE;IACN,IAAIG;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIJ,YAAY;YACCD;QAAfI,gBAAeJ,kBAAAA,gBAAO,CAACE,KAAK,CAC1BD,YACA,CAAC,mDAAmD,CAAC,sBAFxCD,eAGZ,CAAC,EAAE;QACN,IAAII,cAAc;gBACEJ,iBAIPA;YAJXG,mBAAkBH,kBAAAA,gBAAO,CAACE,KAAK,CAC7BE,cACA,CAAC,2DAA2D,CAAC,sBAF7CJ,eAGf,CAAC,EAAE;YACNK,YAAWL,kBAAAA,gBAAO,CAACE,KAAK,CACtBE,cACA,CAAC,mDAAmD,CAAC,sBAF5CJ,eAGR,CAAC,EAAE;QACR;IACF;IAEA,IAAIM,cAAc;IAElB,KAAIP,yBAAAA,cAAcQ,OAAO,sBAArBR,8BAAAA,uBAAuBS,IAAI,sBAA3BT,sCAAAA,4BAA6BU,OAAO,qBAApCV,oCAAsCW,gBAAgB,EAAE;YAC5CX,sCAAAA,8BAAAA;QAAdO,eAAcP,0BAAAA,cAAcQ,OAAO,sBAArBR,+BAAAA,wBAAuBS,IAAI,sBAA3BT,uCAAAA,6BAA6BU,OAAO,qBAApCV,qCAAsCW,gBAAgB;IACtE,OAAO;QACLJ,cAAcK,IAAAA,yBAAiB,EAC7BC,IAAAA,sBAAc,EAACb,cAAcc,IAAI,GACjC,YACAd,cAAcc,IAAI;IAEtB;IAEA,IAAIV,iBAAiB;IACnB,aAAa;IACf,OAAO,IAAIC,cAAc;QACvB,6CAA6C;QAC7C,0BAA0B;QAC1BN,iBAAiBgB,IAAAA,4BAAoB,EAAChB,gBAAgB;YACpD;gBACEiB,MAAMC,kBAAU,CAACC,MAAM;gBACvBC,OAAOd,aAAae,QAAQ,KAAK,CAAC,WAAW,CAAC,CAACC,MAAM,GAAG;gBACxDC,MAAM,CAAC,mBAAmB,EAAEf,YAAY,EAAE,CAAC;YAC7C;SACD;QACD,IAAI,CAACD,UAAU;YACbP,iBAAiBgB,IAAAA,4BAAoB,EAAChB,gBAAgB;gBACpD;oBACEiB,MAAMC,kBAAU,CAACC,MAAM;oBACvBC,OAAOd,aAAae,QAAQ,KAAK,CAAC,WAAW,CAAC,CAACC,MAAM,GAAG;oBACxDC,MAAM,CAAC,eAAe,CAAC;gBACzB;aACD;QACH;IACF,OAAO,IAAIpB,YAAY;QACrBH,iBAAiBgB,IAAAA,4BAAoB,EAAChB,gBAAgB;YACpD;gBACEiB,MAAMC,kBAAU,CAACC,MAAM;gBACvBC,OAAOjB,WAAWkB,QAAQ,KAAK,CAAC,OAAO,CAAC,CAACC,MAAM,GAAG;gBAClDC,MAAM,CAAC;6BACc,EAAEf,YAAY;;UAEjC,CAAC;YACL;SACD;IACH,OAAO;IACL,4BAA4B;IAC9B;IAEA,OAAOR;AACT"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "findViteConfig", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return findViteConfig;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _devkit = require("@nx/devkit");
|
|
9
|
+
function findViteConfig(tree, searchRoot) {
|
|
10
|
+
const allowsExt = [
|
|
11
|
+
'js',
|
|
12
|
+
'mjs',
|
|
13
|
+
'ts',
|
|
14
|
+
'cjs',
|
|
15
|
+
'mts',
|
|
16
|
+
'cts'
|
|
17
|
+
];
|
|
18
|
+
for (const ext of allowsExt){
|
|
19
|
+
if (tree.exists((0, _devkit.joinPathFragments)(searchRoot, `vite.config.${ext}`))) {
|
|
20
|
+
return (0, _devkit.joinPathFragments)(searchRoot, `vite.config.${ext}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=find-vite-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/migrations/update-17-2-0/lib/find-vite-config.ts"],"sourcesContent":["import { Tree, joinPathFragments } from '@nx/devkit';\n\nexport function findViteConfig(tree: Tree, searchRoot: string) {\n const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];\n\n for (const ext of allowsExt) {\n if (tree.exists(joinPathFragments(searchRoot, `vite.config.${ext}`))) {\n return joinPathFragments(searchRoot, `vite.config.${ext}`);\n }\n }\n}\n"],"names":["findViteConfig","tree","searchRoot","allowsExt","ext","exists","joinPathFragments"],"mappings":";+BAEgBA;;;eAAAA;;;wBAFwB;AAEjC,SAASA,eAAeC,IAAU,EAAEC,UAAkB;IAC3D,MAAMC,YAAY;QAAC;QAAM;QAAO;QAAM;QAAO;QAAO;KAAM;IAE1D,KAAK,MAAMC,OAAOD,UAAW;QAC3B,IAAIF,KAAKI,MAAM,CAACC,IAAAA,yBAAiB,EAACJ,YAAY,CAAC,YAAY,EAAEE,IAAI,CAAC,IAAI;YACpE,OAAOE,IAAAA,yBAAiB,EAACJ,YAAY,CAAC,YAAY,EAAEE,IAAI,CAAC;QAC3D;IACF;AACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "default", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return updateBuildDir;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _devkit = require("@nx/devkit");
|
|
9
|
+
const _executoroptionsutils = require("@nx/devkit/src/generators/executor-options-utils");
|
|
10
|
+
const _editbuildconfig = require("./lib/edit-build-config");
|
|
11
|
+
const _edittestconfig = require("./lib/edit-test-config");
|
|
12
|
+
const _addfilereplacements = require("./lib/add-file-replacements");
|
|
13
|
+
async function updateBuildDir(tree) {
|
|
14
|
+
const projects = (0, _devkit.getProjects)(tree);
|
|
15
|
+
(0, _executoroptionsutils.forEachExecutorOptions)(tree, '@nx/vite:build', (options, projectName, targetName)=>{
|
|
16
|
+
var _options_fileReplacements;
|
|
17
|
+
const projectConfig = projects.get(projectName);
|
|
18
|
+
const config = options.configFile || findViteConfig(tree, projectConfig.root);
|
|
19
|
+
if (!config || !tree.exists(config)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
let configContents = tree.read(config, 'utf-8');
|
|
23
|
+
configContents = (0, _editbuildconfig.updateBuildOutDirAndRoot)(options, configContents, projectConfig, targetName, tree, projectName);
|
|
24
|
+
configContents = (0, _edittestconfig.updateTestConfig)(configContents, projectConfig);
|
|
25
|
+
if (((_options_fileReplacements = options.fileReplacements) == null ? void 0 : _options_fileReplacements.length) > 0) {
|
|
26
|
+
configContents = (0, _addfilereplacements.addFileReplacements)(configContents, options.fileReplacements);
|
|
27
|
+
}
|
|
28
|
+
tree.write(config, configContents);
|
|
29
|
+
});
|
|
30
|
+
await (0, _devkit.formatFiles)(tree);
|
|
31
|
+
}
|
|
32
|
+
function findViteConfig(tree, searchRoot) {
|
|
33
|
+
const allowsExt = [
|
|
34
|
+
'js',
|
|
35
|
+
'mjs',
|
|
36
|
+
'ts',
|
|
37
|
+
'cjs',
|
|
38
|
+
'mts',
|
|
39
|
+
'cts'
|
|
40
|
+
];
|
|
41
|
+
for (const ext of allowsExt){
|
|
42
|
+
if (tree.exists((0, _devkit.joinPathFragments)(searchRoot, `vite.config.${ext}`))) {
|
|
43
|
+
return (0, _devkit.joinPathFragments)(searchRoot, `vite.config.${ext}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=update-vite-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/migrations/update-17-2-0/update-vite-config.ts"],"sourcesContent":["import { Tree, formatFiles, getProjects, joinPathFragments } from '@nx/devkit';\nimport { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils';\nimport { ViteBuildExecutorOptions } from '../../executors/build/schema';\nimport { updateBuildOutDirAndRoot } from './lib/edit-build-config';\nimport { updateTestConfig } from './lib/edit-test-config';\nimport { addFileReplacements } from './lib/add-file-replacements';\n\nexport default async function updateBuildDir(tree: Tree) {\n const projects = getProjects(tree);\n forEachExecutorOptions<ViteBuildExecutorOptions>(\n tree,\n '@nx/vite:build',\n (options, projectName, targetName) => {\n const projectConfig = projects.get(projectName);\n const config =\n options.configFile || findViteConfig(tree, projectConfig.root);\n if (!config || !tree.exists(config)) {\n return;\n }\n let configContents = tree.read(config, 'utf-8');\n\n configContents = updateBuildOutDirAndRoot(\n options,\n configContents,\n projectConfig,\n targetName,\n tree,\n projectName\n );\n\n configContents = updateTestConfig(configContents, projectConfig);\n\n if (options.fileReplacements?.length > 0) {\n configContents = addFileReplacements(\n configContents,\n options.fileReplacements\n );\n }\n\n tree.write(config, configContents);\n }\n );\n\n await formatFiles(tree);\n}\n\nfunction findViteConfig(tree: Tree, searchRoot: string) {\n const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];\n\n for (const ext of allowsExt) {\n if (tree.exists(joinPathFragments(searchRoot, `vite.config.${ext}`))) {\n return joinPathFragments(searchRoot, `vite.config.${ext}`);\n }\n }\n}\n"],"names":["updateBuildDir","tree","projects","getProjects","forEachExecutorOptions","options","projectName","targetName","projectConfig","get","config","configFile","findViteConfig","root","exists","configContents","read","updateBuildOutDirAndRoot","updateTestConfig","fileReplacements","length","addFileReplacements","write","formatFiles","searchRoot","allowsExt","ext","joinPathFragments"],"mappings":";+BAOA;;;eAA8BA;;;wBAPoC;sCAC3B;iCAEE;gCACR;qCACG;AAErB,eAAeA,eAAeC,IAAU;IACrD,MAAMC,WAAWC,IAAAA,mBAAW,EAACF;IAC7BG,IAAAA,4CAAsB,EACpBH,MACA,kBACA,CAACI,SAASC,aAAaC;YAoBjBF;QAnBJ,MAAMG,gBAAgBN,SAASO,GAAG,CAACH;QACnC,MAAMI,SACJL,QAAQM,UAAU,IAAIC,eAAeX,MAAMO,cAAcK,IAAI;QAC/D,IAAI,CAACH,UAAU,CAACT,KAAKa,MAAM,CAACJ,SAAS;YACnC;QACF;QACA,IAAIK,iBAAiBd,KAAKe,IAAI,CAACN,QAAQ;QAEvCK,iBAAiBE,IAAAA,yCAAwB,EACvCZ,SACAU,gBACAP,eACAD,YACAN,MACAK;QAGFS,iBAAiBG,IAAAA,gCAAgB,EAACH,gBAAgBP;QAElD,IAAIH,EAAAA,4BAAAA,QAAQc,gBAAgB,qBAAxBd,0BAA0Be,MAAM,IAAG,GAAG;YACxCL,iBAAiBM,IAAAA,wCAAmB,EAClCN,gBACAV,QAAQc,gBAAgB;QAE5B;QAEAlB,KAAKqB,KAAK,CAACZ,QAAQK;IACrB;IAGF,MAAMQ,IAAAA,mBAAW,EAACtB;AACpB;AAEA,SAASW,eAAeX,IAAU,EAAEuB,UAAkB;IACpD,MAAMC,YAAY;QAAC;QAAM;QAAO;QAAM;QAAO;QAAO;KAAM;IAE1D,KAAK,MAAMC,OAAOD,UAAW;QAC3B,IAAIxB,KAAKa,MAAM,CAACa,IAAAA,yBAAiB,EAACH,YAAY,CAAC,YAAY,EAAEE,IAAI,CAAC,IAAI;YACpE,OAAOC,IAAAA,yBAAiB,EAACH,YAAY,CAAC,YAAY,EAAEE,IAAI,CAAC;QAC3D;IACF;AACF"}
|
|
@@ -28,11 +28,11 @@ async function validateTypes(opts) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
function createBuildableTsConfig(projectRoot, options, context) {
|
|
31
|
-
var _options;
|
|
31
|
+
var _options, _buildLibsFromSource;
|
|
32
32
|
const tsConfig = (0, _path.resolve)(projectRoot, 'tsconfig.json');
|
|
33
|
-
var
|
|
34
|
-
(
|
|
35
|
-
if (!options
|
|
33
|
+
var _;
|
|
34
|
+
(_ = (_options = options)[_buildLibsFromSource = 'buildLibsFromSource']) != null ? _ : _options[_buildLibsFromSource] = true;
|
|
35
|
+
if (!options['buildLibsFromSource']) {
|
|
36
36
|
const { dependencies } = (0, _buildablelibsutils.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, // When using incremental building and the serve target is called
|
|
37
37
|
// we need to get the deps for the 'build' target instead.
|
|
38
38
|
context.targetName === 'serve' ? 'build' : context.targetName, context.configurationName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/vite/src/utils/executor-utils.ts"],"sourcesContent":["import { printDiagnostics, runTypeCheck } from '@nx/js';\nimport { join, resolve } from 'path';\nimport { ViteBuildExecutorOptions } from '../executors/build/schema';\nimport { ExecutorContext } from '@nx/devkit';\nimport { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';\nimport {\n calculateProjectBuildableDependencies,\n createTmpTsConfig,\n} from '@nx/js/src/utils/buildable-libs-utils';\n\nexport async function validateTypes(opts: {\n workspaceRoot: string;\n projectRoot: string;\n tsconfig: string;\n}): Promise<void> {\n const result = await runTypeCheck({\n workspaceRoot: opts.workspaceRoot,\n tsConfigPath: join(opts.workspaceRoot, opts.tsconfig),\n mode: 'noEmit',\n });\n\n await printDiagnostics(result.errors, result.warnings);\n\n if (result.errors.length > 0) {\n throw new Error('Found type errors. See above.');\n }\n}\n\nexport function createBuildableTsConfig(\n projectRoot: string,\n options: ViteBuildExecutorOptions | ViteDevServerExecutorOptions,\n context: ExecutorContext\n) {\n const tsConfig = resolve(projectRoot, 'tsconfig.json');\n options
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/vite/src/utils/executor-utils.ts"],"sourcesContent":["import { printDiagnostics, runTypeCheck } from '@nx/js';\nimport { join, resolve } from 'path';\nimport { ViteBuildExecutorOptions } from '../executors/build/schema';\nimport { ExecutorContext } from '@nx/devkit';\nimport { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';\nimport {\n calculateProjectBuildableDependencies,\n createTmpTsConfig,\n} from '@nx/js/src/utils/buildable-libs-utils';\n\nexport async function validateTypes(opts: {\n workspaceRoot: string;\n projectRoot: string;\n tsconfig: string;\n}): Promise<void> {\n const result = await runTypeCheck({\n workspaceRoot: opts.workspaceRoot,\n tsConfigPath: join(opts.workspaceRoot, opts.tsconfig),\n mode: 'noEmit',\n });\n\n await printDiagnostics(result.errors, result.warnings);\n\n if (result.errors.length > 0) {\n throw new Error('Found type errors. See above.');\n }\n}\n\nexport function createBuildableTsConfig(\n projectRoot: string,\n options: ViteBuildExecutorOptions | ViteDevServerExecutorOptions,\n context: ExecutorContext\n) {\n const tsConfig = resolve(projectRoot, 'tsconfig.json');\n options['buildLibsFromSource'] ??= true;\n\n if (!options['buildLibsFromSource']) {\n const { dependencies } = calculateProjectBuildableDependencies(\n context.taskGraph,\n context.projectGraph,\n context.root,\n context.projectName,\n // When using incremental building and the serve target is called\n // we need to get the deps for the 'build' target instead.\n context.targetName === 'serve' ? 'build' : context.targetName,\n context.configurationName\n );\n // this tsconfig is used via the vite ts paths plugin\n createTmpTsConfig(tsConfig, context.root, projectRoot, dependencies);\n }\n}\n"],"names":["validateTypes","createBuildableTsConfig","opts","result","runTypeCheck","workspaceRoot","tsConfigPath","join","tsconfig","mode","printDiagnostics","errors","warnings","length","Error","projectRoot","options","context","tsConfig","resolve","dependencies","calculateProjectBuildableDependencies","taskGraph","projectGraph","root","projectName","targetName","configurationName","createTmpTsConfig"],"mappings":";;;;;;;;IAUsBA,aAAa;eAAbA;;IAkBNC,uBAAuB;eAAvBA;;;oBA5B+B;sBACjB;oCAOvB;AAEA,eAAeD,cAAcE,IAInC;IACC,MAAMC,SAAS,MAAMC,IAAAA,gBAAY,EAAC;QAChCC,eAAeH,KAAKG,aAAa;QACjCC,cAAcC,IAAAA,UAAI,EAACL,KAAKG,aAAa,EAAEH,KAAKM,QAAQ;QACpDC,MAAM;IACR;IAEA,MAAMC,IAAAA,oBAAgB,EAACP,OAAOQ,MAAM,EAAER,OAAOS,QAAQ;IAErD,IAAIT,OAAOQ,MAAM,CAACE,MAAM,GAAG,GAAG;QAC5B,MAAM,IAAIC,MAAM;IAClB;AACF;AAEO,SAASb,wBACdc,WAAmB,EACnBC,OAAgE,EAChEC,OAAwB;QAGxBD,UAAQ;IADR,MAAME,WAAWC,IAAAA,aAAO,EAACJ,aAAa;;IACtCC,MAAAA,WAAAA,QAAO,CAAC,uBAAA,sBAAsB,gBAA9BA,QAAO,CAAC,qBAAsB,GAAK;IAEnC,IAAI,CAACA,OAAO,CAAC,sBAAsB,EAAE;QACnC,MAAM,EAAEI,YAAY,EAAE,GAAGC,IAAAA,yDAAqC,EAC5DJ,QAAQK,SAAS,EACjBL,QAAQM,YAAY,EACpBN,QAAQO,IAAI,EACZP,QAAQQ,WAAW,EACnB,iEAAiE;QACjE,0DAA0D;QAC1DR,QAAQS,UAAU,KAAK,UAAU,UAAUT,QAAQS,UAAU,EAC7DT,QAAQU,iBAAiB;QAE3B,qDAAqD;QACrDC,IAAAA,qCAAiB,EAACV,UAAUD,QAAQO,IAAI,EAAET,aAAaK;IACzD;AACF"}
|
|
@@ -36,8 +36,9 @@ export interface ViteConfigFileOptions {
|
|
|
36
36
|
rollupOptionsExternal?: string[];
|
|
37
37
|
imports?: string[];
|
|
38
38
|
plugins?: string[];
|
|
39
|
+
coverageProvider?: 'v8' | 'istanbul' | 'custom';
|
|
39
40
|
}
|
|
40
|
-
export declare function createOrEditViteConfig(tree: Tree, options: ViteConfigFileOptions, onlyVitest: boolean, projectAlreadyHasViteTargets?: TargetFlags): void;
|
|
41
|
+
export declare function createOrEditViteConfig(tree: Tree, options: ViteConfigFileOptions, onlyVitest: boolean, projectAlreadyHasViteTargets?: TargetFlags, vitestFileName?: boolean): void;
|
|
41
42
|
export declare function normalizeViteConfigFilePathWithTree(tree: Tree, projectRoot: string, configFile?: string): string;
|
|
42
43
|
export declare function getViteConfigPathForProject(tree: Tree, projectName: string, target?: string): string;
|
|
43
44
|
export declare function handleUnsupportedUserProvidedTargets(userProvidedTargetIsUnsupported: TargetFlags, userProvidedTargetName: UserProvidedTargetName, validFoundTargetName: ValidFoundTargetName): Promise<void>;
|
|
@@ -157,11 +157,9 @@ function findExistingTargetsInProject(targets, userProvidedTargets) {
|
|
|
157
157
|
function addOrChangeTestTarget(tree, options, target) {
|
|
158
158
|
var _project;
|
|
159
159
|
const project = (0, _devkit.readProjectConfiguration)(tree, options.project);
|
|
160
|
-
const
|
|
160
|
+
const reportsDirectory = (0, _devkit.joinPathFragments)((0, _devkit.offsetFromRoot)(project.root), 'coverage', project.root === '.' ? options.project : project.root);
|
|
161
161
|
const testOptions = {
|
|
162
|
-
|
|
163
|
-
// vitest runs in the project root so we have to offset to the workspaceRoot
|
|
164
|
-
reportsDirectory: (0, _devkit.joinPathFragments)((0, _devkit.offsetFromRoot)(project.root), coveragePath)
|
|
162
|
+
reportsDirectory
|
|
165
163
|
};
|
|
166
164
|
var _targets;
|
|
167
165
|
(_targets = (_project = project).targets) != null ? _targets : _project.targets = {};
|
|
@@ -193,8 +191,8 @@ function addOrChangeBuildTarget(tree, options, target) {
|
|
|
193
191
|
buildOptions.fileReplacements = (_project_targets_target_options = project.targets[target].options) == null ? void 0 : _project_targets_target_options.fileReplacements;
|
|
194
192
|
if (project.targets[target].executor === '@nxext/vite:build') {
|
|
195
193
|
var _project_targets_target_options1, _project_targets_target_options2;
|
|
196
|
-
buildOptions
|
|
197
|
-
buildOptions
|
|
194
|
+
buildOptions['base'] = (_project_targets_target_options1 = project.targets[target].options) == null ? void 0 : _project_targets_target_options1.baseHref;
|
|
195
|
+
buildOptions['sourcemap'] = (_project_targets_target_options2 = project.targets[target].options) == null ? void 0 : _project_targets_target_options2.sourcemaps;
|
|
198
196
|
}
|
|
199
197
|
project.targets[target].options = _extends._({}, buildOptions);
|
|
200
198
|
project.targets[target].executor = '@nx/vite:build';
|
|
@@ -224,13 +222,9 @@ function addOrChangeServeTarget(tree, options, target) {
|
|
|
224
222
|
var _targets;
|
|
225
223
|
(_targets = (_project = project).targets) != null ? _targets : _project.targets = {};
|
|
226
224
|
if (project.targets[target]) {
|
|
227
|
-
var _project_targets_target_options, _project_targets_target_options1, _project_targets_target_options2;
|
|
228
225
|
const serveTarget = project.targets[target];
|
|
229
226
|
const serveOptions = {
|
|
230
|
-
buildTarget: `${options.project}:build
|
|
231
|
-
https: (_project_targets_target_options = project.targets[target].options) == null ? void 0 : _project_targets_target_options.https,
|
|
232
|
-
hmr: (_project_targets_target_options1 = project.targets[target].options) == null ? void 0 : _project_targets_target_options1.hmr,
|
|
233
|
-
open: (_project_targets_target_options2 = project.targets[target].options) == null ? void 0 : _project_targets_target_options2.open
|
|
227
|
+
buildTarget: `${options.project}:build`
|
|
234
228
|
};
|
|
235
229
|
if (serveTarget.executor === '@nxext/vite:dev') {
|
|
236
230
|
serveOptions.proxyConfig = project.targets[target].options.proxyConfig;
|
|
@@ -273,8 +267,8 @@ function addPreviewTarget(tree, options, serveTarget) {
|
|
|
273
267
|
if (target.executor === '@nxext/vite:dev') {
|
|
274
268
|
previewOptions.proxyConfig = target.options.proxyConfig;
|
|
275
269
|
}
|
|
276
|
-
previewOptions
|
|
277
|
-
previewOptions
|
|
270
|
+
previewOptions['https'] = (_target_options = target.options) == null ? void 0 : _target_options.https;
|
|
271
|
+
previewOptions['open'] = (_target_options1 = target.options) == null ? void 0 : _target_options1.open;
|
|
278
272
|
}
|
|
279
273
|
// Adds a preview target.
|
|
280
274
|
project.targets.preview = {
|
|
@@ -395,14 +389,15 @@ function moveAndEditIndexHtml(tree, options, buildTarget) {
|
|
|
395
389
|
</html>`);
|
|
396
390
|
}
|
|
397
391
|
}
|
|
398
|
-
function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasViteTargets) {
|
|
399
|
-
const
|
|
400
|
-
const viteConfigPath = `${
|
|
392
|
+
function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasViteTargets, vitestFileName) {
|
|
393
|
+
const { root: projectRoot } = (0, _devkit.readProjectConfiguration)(tree, options.project);
|
|
394
|
+
const viteConfigPath = vitestFileName ? `${projectRoot}/vitest.config.ts` : `${projectRoot}/vite.config.ts`;
|
|
401
395
|
var _options_rollupOptionsExternal;
|
|
402
396
|
const buildOption = onlyVitest ? '' : options.includeLib ? `
|
|
403
397
|
// Configuration for building your library.
|
|
404
398
|
// See: https://vitejs.dev/guide/build.html#library-mode
|
|
405
399
|
build: {
|
|
400
|
+
outDir: '${(0, _devkit.offsetFromRoot)(projectRoot)}dist/${projectRoot}',
|
|
406
401
|
lib: {
|
|
407
402
|
// Could also be a dictionary or array of multiple entry points.
|
|
408
403
|
entry: 'src/index.ts',
|
|
@@ -415,8 +410,12 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
|
|
|
415
410
|
rollupOptions: {
|
|
416
411
|
// External packages that should not be bundled into your library.
|
|
417
412
|
external: [${(_options_rollupOptionsExternal = options.rollupOptionsExternal) != null ? _options_rollupOptionsExternal : ''}]
|
|
418
|
-
}
|
|
419
|
-
},` :
|
|
413
|
+
},
|
|
414
|
+
},` : `
|
|
415
|
+
build: {
|
|
416
|
+
outDir: '${(0, _devkit.offsetFromRoot)(projectRoot)}dist/${projectRoot}',
|
|
417
|
+
},
|
|
418
|
+
`;
|
|
420
419
|
const imports = options.imports ? options.imports : [];
|
|
421
420
|
if (!onlyVitest && options.includeLib) {
|
|
422
421
|
imports.push(`import dts from 'vite-plugin-dts'`, `import * as path from 'path'`);
|
|
@@ -435,11 +434,15 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
|
|
|
435
434
|
const testOption = options.includeVitest ? `test: {
|
|
436
435
|
globals: true,
|
|
437
436
|
cache: {
|
|
438
|
-
dir: '${(0, _devkit.offsetFromRoot)(
|
|
437
|
+
dir: '${(0, _devkit.offsetFromRoot)(projectRoot)}node_modules/.vitest'
|
|
439
438
|
},
|
|
440
439
|
environment: '${(_options_testEnvironment = options.testEnvironment) != null ? _options_testEnvironment : 'jsdom'}',
|
|
441
440
|
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
442
|
-
${options.inSourceTests ? `includeSource: ['src/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
|
|
441
|
+
${options.inSourceTests ? `includeSource: ['src/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],` : ''}
|
|
442
|
+
coverage: {
|
|
443
|
+
reportsDirectory: '${(0, _devkit.offsetFromRoot)(projectRoot)}coverage/${projectRoot}',
|
|
444
|
+
provider: ${options.coverageProvider ? `'${options.coverageProvider}'` : `'v8'`},
|
|
445
|
+
}
|
|
443
446
|
},` : '';
|
|
444
447
|
const defineOption = options.inSourceTests ? `define: {
|
|
445
448
|
'import.meta.vitest': undefined
|
|
@@ -459,9 +462,9 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
|
|
|
459
462
|
// worker: {
|
|
460
463
|
// plugins: [ nxViteTsPaths() ],
|
|
461
464
|
// },`;
|
|
462
|
-
const cacheDir = `cacheDir: '${(0, _devkit.offsetFromRoot)(
|
|
465
|
+
const cacheDir = `cacheDir: '${(0, _devkit.offsetFromRoot)(projectRoot)}node_modules/.vite/${projectRoot}',`;
|
|
463
466
|
if (tree.exists(viteConfigPath)) {
|
|
464
|
-
handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, imports, plugins, testOption, cacheDir, (0, _devkit.offsetFromRoot)(
|
|
467
|
+
handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, imports, plugins, testOption, cacheDir, (0, _devkit.offsetFromRoot)(projectRoot), projectRoot, projectAlreadyHasViteTargets);
|
|
465
468
|
return;
|
|
466
469
|
}
|
|
467
470
|
viteConfigContent = `
|
|
@@ -471,6 +474,7 @@ function createOrEditViteConfig(tree, options, onlyVitest, projectAlreadyHasVite
|
|
|
471
474
|
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
472
475
|
|
|
473
476
|
export default defineConfig({
|
|
477
|
+
root: __dirname,
|
|
474
478
|
${cacheDir}
|
|
475
479
|
${devServerOption}
|
|
476
480
|
${previewServerOption}
|
|
@@ -560,7 +564,7 @@ async function handleUnknownExecutors(projectName) {
|
|
|
560
564
|
`);
|
|
561
565
|
}
|
|
562
566
|
}
|
|
563
|
-
function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, imports, plugins, testOption, cacheDir, offsetFromRoot, projectAlreadyHasViteTargets) {
|
|
567
|
+
function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption, imports, plugins, testOption, cacheDir, offsetFromRoot, projectRoot, projectAlreadyHasViteTargets) {
|
|
564
568
|
if ((projectAlreadyHasViteTargets == null ? void 0 : projectAlreadyHasViteTargets.build) && (projectAlreadyHasViteTargets == null ? void 0 : projectAlreadyHasViteTargets.test)) {
|
|
565
569
|
return;
|
|
566
570
|
}
|
|
@@ -568,7 +572,7 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
|
|
|
568
572
|
_devkit.logger.info(`vite.config.ts already exists for project ${options.project}.`);
|
|
569
573
|
}
|
|
570
574
|
var _options_rollupOptionsExternal;
|
|
571
|
-
const buildOptionObject = {
|
|
575
|
+
const buildOptionObject = options.includeLib ? {
|
|
572
576
|
lib: {
|
|
573
577
|
entry: 'src/index.ts',
|
|
574
578
|
name: options.project,
|
|
@@ -580,9 +584,12 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
|
|
|
580
584
|
},
|
|
581
585
|
rollupOptions: {
|
|
582
586
|
external: (_options_rollupOptionsExternal = options.rollupOptionsExternal) != null ? _options_rollupOptionsExternal : []
|
|
583
|
-
}
|
|
587
|
+
},
|
|
588
|
+
outDir: `${offsetFromRoot}dist/${projectRoot}`
|
|
589
|
+
} : {
|
|
590
|
+
outDir: `${offsetFromRoot}dist/${projectRoot}`
|
|
584
591
|
};
|
|
585
|
-
var _options_testEnvironment;
|
|
592
|
+
var _options_testEnvironment, _options_coverageProvider;
|
|
586
593
|
const testOptionObject = {
|
|
587
594
|
globals: true,
|
|
588
595
|
cache: {
|
|
@@ -591,7 +598,11 @@ function handleViteConfigFileExists(tree, viteConfigPath, options, buildOption,
|
|
|
591
598
|
environment: (_options_testEnvironment = options.testEnvironment) != null ? _options_testEnvironment : 'jsdom',
|
|
592
599
|
include: [
|
|
593
600
|
'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
|
|
594
|
-
]
|
|
601
|
+
],
|
|
602
|
+
coverage: {
|
|
603
|
+
reportsDirectory: `${offsetFromRoot}coverage/${projectRoot}`,
|
|
604
|
+
provider: `${(_options_coverageProvider = options.coverageProvider) != null ? _options_coverageProvider : 'v8'}`
|
|
605
|
+
}
|
|
595
606
|
};
|
|
596
607
|
const changed = (0, _viteconfigeditutils.ensureViteConfigIsCorrect)(tree, viteConfigPath, buildOption, buildOptionObject, imports, plugins, testOption, testOptionObject, cacheDir, projectAlreadyHasViteTargets != null ? projectAlreadyHasViteTargets : {});
|
|
597
608
|
if (!changed) {
|