@nx/vite 17.2.0-rc.2 → 17.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/migrations/update-17-2-0/lib/add-file-replacements.d.ts +1 -1
- package/src/migrations/update-17-2-0/lib/add-file-replacements.js +10 -4
- package/src/migrations/update-17-2-0/lib/add-file-replacements.js.map +1 -1
- package/src/migrations/update-17-2-0/lib/edit-build-config.d.ts +1 -1
- package/src/migrations/update-17-2-0/lib/edit-build-config.js +36 -26
- package/src/migrations/update-17-2-0/lib/edit-build-config.js.map +1 -1
- package/src/migrations/update-17-2-0/lib/edit-test-config.d.ts +1 -1
- package/src/migrations/update-17-2-0/lib/edit-test-config.js +8 -2
- package/src/migrations/update-17-2-0/lib/edit-test-config.js.map +1 -1
- package/src/migrations/update-17-2-0/update-vite-config.d.ts +3 -0
- package/src/migrations/update-17-2-0/update-vite-config.js +40 -6
- package/src/migrations/update-17-2-0/update-vite-config.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "17.2.
|
|
3
|
+
"version": "17.2.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for building and testing applications using Vite",
|
|
6
6
|
"repository": {
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"migrations": "./migrations.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nx/devkit": "17.2.
|
|
32
|
+
"@nx/devkit": "17.2.1",
|
|
33
33
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
34
34
|
"@swc/helpers": "~0.5.0",
|
|
35
35
|
"enquirer": "~2.3.6",
|
|
36
|
-
"@nx/js": "17.2.
|
|
36
|
+
"@nx/js": "17.2.1",
|
|
37
37
|
"tsconfig-paths": "^4.1.2",
|
|
38
|
-
"@nrwl/vite": "17.2.
|
|
38
|
+
"@nrwl/vite": "17.2.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"vite": "^5.0.0",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { FileReplacement } from '../../../../plugins/rollup-replace-files.plugin';
|
|
2
|
-
export declare function addFileReplacements(configContents: string, fileReplacements: FileReplacement[]): string;
|
|
2
|
+
export declare function addFileReplacements(configContents: string, fileReplacements: FileReplacement[], configPath: string): string;
|
|
@@ -7,10 +7,16 @@ Object.defineProperty(exports, "addFileReplacements", {
|
|
|
7
7
|
});
|
|
8
8
|
const _devkit = require("@nx/devkit");
|
|
9
9
|
const _tsquery = require("@phenomnomnominal/tsquery");
|
|
10
|
-
|
|
10
|
+
const _updateviteconfig = require("../update-vite-config");
|
|
11
|
+
function addFileReplacements(configContents, fileReplacements, configPath) {
|
|
11
12
|
var _tsquery_query, _tsquery_query1, _tsquery_query2;
|
|
12
|
-
const
|
|
13
|
-
|
|
13
|
+
const configNode = (0, _updateviteconfig.getConfigNode)(configContents);
|
|
14
|
+
if (!configNode) {
|
|
15
|
+
(0, _updateviteconfig.notFoundWarning)(configPath);
|
|
16
|
+
return configContents;
|
|
17
|
+
}
|
|
18
|
+
const pluginsObject = (_tsquery_query = _tsquery.tsquery.query(configNode, `PropertyAssignment:has(Identifier[name="plugins"])`)) == null ? void 0 : _tsquery_query[0];
|
|
19
|
+
const replaceFilesPlugin = (_tsquery_query1 = _tsquery.tsquery.query(configNode, `PropertyAssignment:has(Identifier[name="plugins"]) CallExpression:has(Identifier[name="replaceFiles"])`)) == null ? void 0 : _tsquery_query1[0];
|
|
14
20
|
const firstImportDeclaration = (_tsquery_query2 = _tsquery.tsquery.query(configContents, 'ImportDeclaration')) == null ? void 0 : _tsquery_query2[0];
|
|
15
21
|
if (pluginsObject) {
|
|
16
22
|
if (replaceFilesPlugin) {
|
|
@@ -42,7 +48,7 @@ function addFileReplacements(configContents, fileReplacements) {
|
|
|
42
48
|
return (0, _devkit.applyChangesToString)(configContents, [
|
|
43
49
|
{
|
|
44
50
|
type: _devkit.ChangeType.Insert,
|
|
45
|
-
index:
|
|
51
|
+
index: configNode.getStart() + 1,
|
|
46
52
|
text: `plugins: [replaceFiles(${JSON.stringify(fileReplacements)})],`
|
|
47
53
|
},
|
|
48
54
|
firstImportDeclaration ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/vite/src/migrations/update-17-2-0/lib/add-file-replacements.ts"],"sourcesContent":["import { ChangeType, applyChangesToString } from '@nx/devkit';\nimport { FileReplacement } from '../../../../plugins/rollup-replace-files.plugin';\nimport { tsquery } from '@phenomnomnominal/tsquery';\n\nexport function addFileReplacements(\n configContents: string,\n fileReplacements: FileReplacement[]\n): string {\n const pluginsObject = tsquery.query(\n
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/migrations/update-17-2-0/lib/add-file-replacements.ts"],"sourcesContent":["import { ChangeType, applyChangesToString } from '@nx/devkit';\nimport { FileReplacement } from '../../../../plugins/rollup-replace-files.plugin';\nimport { tsquery } from '@phenomnomnominal/tsquery';\nimport { getConfigNode, notFoundWarning } from '../update-vite-config';\n\nexport function addFileReplacements(\n configContents: string,\n fileReplacements: FileReplacement[],\n configPath: string\n): string {\n const configNode = getConfigNode(configContents);\n if (!configNode) {\n notFoundWarning(configPath);\n return configContents;\n }\n const pluginsObject = tsquery.query(\n configNode,\n `PropertyAssignment:has(Identifier[name=\"plugins\"])`\n )?.[0];\n const replaceFilesPlugin = tsquery.query(\n configNode,\n `PropertyAssignment:has(Identifier[name=\"plugins\"]) CallExpression:has(Identifier[name=\"replaceFiles\"])`\n )?.[0];\n\n const firstImportDeclaration = tsquery.query(\n configContents,\n 'ImportDeclaration'\n )?.[0];\n\n if (pluginsObject) {\n if (replaceFilesPlugin) {\n return configContents;\n } else {\n return applyChangesToString(configContents, [\n {\n type: ChangeType.Insert,\n index: pluginsObject.getStart() + `plugins: [`.length + 1,\n text: `replaceFiles(${JSON.stringify(fileReplacements)}),`,\n },\n firstImportDeclaration\n ? {\n type: ChangeType.Insert,\n index: firstImportDeclaration.getStart(),\n text: `import replaceFiles from '@nx/vite/plugins/rollup-replace-files.plugin';\\n`,\n }\n : {\n type: ChangeType.Insert,\n index: 0,\n text: `import replaceFiles from '@nx/vite/plugins/rollup-replace-files.plugin';\\n`,\n },\n ]);\n }\n } else {\n const foundDefineConfig = tsquery.query(\n configContents,\n 'CallExpression:has(Identifier[name=\"defineConfig\"])'\n )?.[0];\n\n if (!foundDefineConfig) {\n return;\n }\n return applyChangesToString(configContents, [\n {\n type: ChangeType.Insert,\n index: configNode.getStart() + 1,\n text: `plugins: [replaceFiles(${JSON.stringify(fileReplacements)})],`,\n },\n firstImportDeclaration\n ? {\n type: ChangeType.Insert,\n index: firstImportDeclaration.getStart(),\n text: `import replaceFiles from '@nx/vite/plugins/rollup-replace-files.plugin';`,\n }\n : {\n type: ChangeType.Insert,\n index: 0,\n text: `import replaceFiles from '@nx/vite/plugins/rollup-replace-files.plugin';`,\n },\n ]);\n }\n}\n"],"names":["addFileReplacements","configContents","fileReplacements","configPath","tsquery","configNode","getConfigNode","notFoundWarning","pluginsObject","query","replaceFilesPlugin","firstImportDeclaration","applyChangesToString","type","ChangeType","Insert","index","getStart","length","text","JSON","stringify","foundDefineConfig"],"mappings":";+BAKgBA;;;eAAAA;;;wBALiC;yBAEzB;kCACuB;AAExC,SAASA,oBACdC,cAAsB,EACtBC,gBAAmC,EACnCC,UAAkB;QAOIC,gBAIKA,iBAKIA;IAd/B,MAAMC,aAAaC,IAAAA,+BAAa,EAACL;IACjC,IAAI,CAACI,YAAY;QACfE,IAAAA,iCAAe,EAACJ;QAChB,OAAOF;IACT;IACA,MAAMO,iBAAgBJ,iBAAAA,gBAAO,CAACK,KAAK,CACjCJ,YACA,CAAC,kDAAkD,CAAC,sBAFhCD,cAGnB,CAAC,EAAE;IACN,MAAMM,sBAAqBN,kBAAAA,gBAAO,CAACK,KA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AC,wEAAwE,CAAC;YAClF;SACL;IACH;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ProjectConfiguration, Tree } from '@nx/devkit';
|
|
2
|
-
export declare function updateBuildOutDirAndRoot(options: Record<string, any>, configContents: string, projectConfig: ProjectConfiguration, targetName: string, tree: Tree, projectName: string): string;
|
|
2
|
+
export declare function updateBuildOutDirAndRoot(options: Record<string, any>, configContents: string, projectConfig: ProjectConfiguration, targetName: string, tree: Tree, projectName: string, configPath: string): string;
|
|
@@ -7,22 +7,26 @@ Object.defineProperty(exports, "updateBuildOutDirAndRoot", {
|
|
|
7
7
|
});
|
|
8
8
|
const _devkit = require("@nx/devkit");
|
|
9
9
|
const _tsquery = require("@phenomnomnominal/tsquery");
|
|
10
|
+
const _updateviteconfig = require("../update-vite-config");
|
|
10
11
|
const ts = require("typescript");
|
|
11
|
-
function updateBuildOutDirAndRoot(options, configContents, projectConfig, targetName, tree, projectName) {
|
|
12
|
+
function updateBuildOutDirAndRoot(options, configContents, projectConfig, targetName, tree, projectName, configPath) {
|
|
12
13
|
var _tsquery_query;
|
|
13
14
|
const foundDefineConfig = (_tsquery_query = _tsquery.tsquery.query(configContents, 'CallExpression:has(Identifier[name="defineConfig"])')) == null ? void 0 : _tsquery_query[0];
|
|
14
15
|
if (!foundDefineConfig) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Please add the build.outDir and root options to your vite.config file.
|
|
18
|
-
`);
|
|
16
|
+
(0, _updateviteconfig.notFoundWarning)(configPath);
|
|
17
|
+
return;
|
|
19
18
|
}
|
|
20
|
-
configContents = fixBuild(options, configContents, projectConfig, targetName, tree, projectName,
|
|
21
|
-
configContents = addRoot(configContents,
|
|
19
|
+
configContents = fixBuild(options, configContents, projectConfig, targetName, tree, projectName, configPath);
|
|
20
|
+
configContents = addRoot(configContents, configPath);
|
|
22
21
|
return configContents;
|
|
23
22
|
}
|
|
24
|
-
function fixBuild(options, configContents, projectConfig, targetName, tree, projectName,
|
|
23
|
+
function fixBuild(options, configContents, projectConfig, targetName, tree, projectName, configPath) {
|
|
25
24
|
var _tsquery_query;
|
|
25
|
+
const configNode = (0, _updateviteconfig.getConfigNode)(configContents);
|
|
26
|
+
if (!configNode) {
|
|
27
|
+
(0, _updateviteconfig.notFoundWarning)(configPath);
|
|
28
|
+
return configContents;
|
|
29
|
+
}
|
|
26
30
|
let outputPath = '';
|
|
27
31
|
// In vite.config.ts, we want to keep the path relative to workspace root
|
|
28
32
|
if (options.outputPath) {
|
|
@@ -33,7 +37,7 @@ function fixBuild(options, configContents, projectConfig, targetName, tree, proj
|
|
|
33
37
|
// In project.json, we want to keep the path starting from workspace root
|
|
34
38
|
projectConfig.targets[targetName].options.outputPath = options.outputPath ? options.outputPath : (0, _devkit.joinPathFragments)('dist', projectConfig.root);
|
|
35
39
|
(0, _devkit.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
36
|
-
const buildObject = (_tsquery_query = _tsquery.tsquery.query(
|
|
40
|
+
const buildObject = (_tsquery_query = _tsquery.tsquery.query(configNode, `PropertyAssignment:has(Identifier[name="build"])`)) == null ? void 0 : _tsquery_query[0];
|
|
37
41
|
if (buildObject) {
|
|
38
42
|
var _tsquery_query1, _tsquery_query2, _tsquery_query3;
|
|
39
43
|
const reportCompressedSizeExists = ((_tsquery_query1 = _tsquery.tsquery.query(buildObject, `PropertyAssignment:has(Identifier[name="reportCompressedSize"])`)) == null ? void 0 : _tsquery_query1.length) > 0;
|
|
@@ -69,43 +73,49 @@ function fixBuild(options, configContents, projectConfig, targetName, tree, proj
|
|
|
69
73
|
return (0, _devkit.applyChangesToString)(configContents, changes);
|
|
70
74
|
}
|
|
71
75
|
} else {
|
|
72
|
-
return addBuildProperty(configContents, outputPath,
|
|
76
|
+
return addBuildProperty(configContents, outputPath, configPath);
|
|
73
77
|
}
|
|
74
78
|
return configContents;
|
|
75
79
|
}
|
|
76
|
-
function addRoot(configFileContents,
|
|
80
|
+
function addRoot(configFileContents, configPath) {
|
|
77
81
|
var _tsquery_query;
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
82
|
+
const configNode = (0, _updateviteconfig.getConfigNode)(configFileContents);
|
|
83
|
+
if (!configNode) {
|
|
84
|
+
(0, _updateviteconfig.notFoundWarning)(configPath);
|
|
85
|
+
return configFileContents;
|
|
86
|
+
}
|
|
87
|
+
const rootOption = (_tsquery_query = _tsquery.tsquery.query(configNode, `PropertyAssignment:has(Identifier[name="root"]) Identifier[name="__dirname"]`)) == null ? void 0 : _tsquery_query[0];
|
|
88
|
+
if (rootOption) {
|
|
80
89
|
return configFileContents;
|
|
81
90
|
} else {
|
|
82
91
|
return (0, _devkit.applyChangesToString)(configFileContents, [
|
|
83
92
|
{
|
|
84
93
|
type: _devkit.ChangeType.Insert,
|
|
85
|
-
index:
|
|
94
|
+
index: configNode.getStart() + 1,
|
|
86
95
|
text: `root: __dirname,`
|
|
87
96
|
}
|
|
88
97
|
]);
|
|
89
98
|
}
|
|
90
99
|
}
|
|
91
|
-
function addBuildProperty(configFileContents, outputPath,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
function addBuildProperty(configFileContents, outputPath, configPath) {
|
|
101
|
+
const configNode = (0, _updateviteconfig.getConfigNode)(configFileContents);
|
|
102
|
+
if (!configNode) {
|
|
103
|
+
(0, _updateviteconfig.notFoundWarning)(configPath);
|
|
104
|
+
return configFileContents;
|
|
105
|
+
}
|
|
106
|
+
return (0, _devkit.applyChangesToString)(configFileContents, [
|
|
107
|
+
{
|
|
108
|
+
type: _devkit.ChangeType.Insert,
|
|
109
|
+
index: configNode.getStart() + 1,
|
|
110
|
+
text: `build: {
|
|
98
111
|
outDir: '${outputPath}',
|
|
99
112
|
reportCompressedSize: true,
|
|
100
113
|
commonjsOptions: {
|
|
101
114
|
transformMixedEsModules: true,
|
|
102
115
|
},
|
|
103
116
|
},`
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
} else {
|
|
107
|
-
return configFileContents;
|
|
108
|
-
}
|
|
117
|
+
}
|
|
118
|
+
]);
|
|
109
119
|
}
|
|
110
120
|
|
|
111
121
|
//# sourceMappingURL=edit-build-config.js.map
|
|
@@ -1 +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
|
|
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 offsetFromRoot,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { tsquery } from '@phenomnomnominal/tsquery';\nimport ts = require('typescript');\nimport { getConfigNode, notFoundWarning } from '../update-vite-config';\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 configPath: string\n): string {\n const foundDefineConfig = tsquery.query(\n configContents,\n 'CallExpression:has(Identifier[name=\"defineConfig\"])'\n )?.[0];\n\n if (!foundDefineConfig) {\n notFoundWarning(configPath);\n return;\n }\n\n configContents = fixBuild(\n options,\n configContents,\n projectConfig,\n targetName,\n tree,\n projectName,\n configPath\n );\n\n configContents = addRoot(configContents, configPath);\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 configPath: string\n) {\n const configNode = getConfigNode(configContents);\n if (!configNode) {\n notFoundWarning(configPath);\n return configContents;\n }\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 configNode,\n `PropertyAssignment:has(Identifier[name=\"build\"])`\n )?.[0];\n\n if (buildObject) {\n const reportCompressedSizeExists =\n tsquery.query(\n buildObject,\n `PropertyAssignment:has(Identifier[name=\"reportCompressedSize\"])`\n )?.length > 0;\n\n const commonjsOptionsExists =\n tsquery.query(\n buildObject,\n `PropertyAssignment:has(Identifier[name=\"commonjsOptions\"])`\n )?.length > 0;\n\n const buildOutDir = tsquery.query(\n buildObject,\n `PropertyAssignment:has(Identifier[name=\"outDir\"])`\n )?.length;\n\n // Array to store changes\n let changes = [];\n\n // Add outDir if not present\n if (!buildOutDir) {\n changes.push({\n type: ChangeType.Insert,\n index: buildObject.getStart() + `build: {`.length + 1,\n text: `outDir: '${outputPath}',`,\n });\n }\n\n // Add reportCompressedSize if not present\n if (!reportCompressedSizeExists) {\n changes.push({\n type: ChangeType.Insert,\n index: buildObject.getStart() + `build: {`.length + 1,\n text: `reportCompressedSize: true,`,\n });\n }\n\n // Add commonjsOptions if not present\n if (!commonjsOptionsExists) {\n changes.push({\n type: ChangeType.Insert,\n index: buildObject.getStart() + `build: {`.length + 1,\n text: `commonjsOptions: { transformMixedEsModules: true },`,\n });\n }\n\n if (changes.length > 0) {\n return applyChangesToString(configContents, changes);\n }\n } else {\n return addBuildProperty(configContents, outputPath, configPath);\n }\n\n return configContents;\n}\n\nfunction addRoot(configFileContents: string, configPath: string): string {\n const configNode = getConfigNode(configFileContents);\n\n if (!configNode) {\n notFoundWarning(configPath);\n return configFileContents;\n }\n\n const rootOption = tsquery.query(\n configNode,\n `PropertyAssignment:has(Identifier[name=\"root\"]) Identifier[name=\"__dirname\"]`\n )?.[0];\n\n if (rootOption) {\n return configFileContents;\n } else {\n return applyChangesToString(configFileContents, [\n {\n type: ChangeType.Insert,\n index: configNode.getStart() + 1,\n text: `root: __dirname,`,\n },\n ]);\n }\n}\n\nfunction addBuildProperty(\n configFileContents: string,\n outputPath: string,\n configPath: string\n): string {\n const configNode = getConfigNode(configFileContents);\n if (!configNode) {\n notFoundWarning(configPath);\n return configFileContents;\n }\n\n return applyChangesToString(configFileContents, [\n {\n type: ChangeType.Insert,\n index: configNode.getStart() + 1,\n text: `build: {\n outDir: '${outputPath}',\n reportCompressedSize: true,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n },`,\n },\n ]);\n}\n"],"names":["updateBuildOutDirAndRoot","ts","options","configContents","projectConfig","targetName","tree","projectName","configPath","tsquery","foundDefineConfig","query","notFoundWarning","fixBuild","addRoot","configNode","getConfigNode","outputPath","joinPathFragments","offsetFromRoot","root","targets","updateProjectConfiguration","buildObject","reportCompressedSizeExists","length","commonjsOptionsExists","buildOutDir","changes","push","type","ChangeType","Insert","index","getStart","text","applyChangesToString","addBuildProperty","configFileContents","rootOption"],"mappings":";+BAagBA;;;eAAAA;;;wBALT;yBACiB;kCAEuB;AAD/C,MAAOC,aAAa;AAGb,SAASD,yBACdE,OAA4B,EAC5BC,cAAsB,EACtBC,aAAmC,EACnCC,UAAkB,EAClBC,IAAU,EACVC,WAAmB,EACnBC,UAAkB;QAEQC;IAA1B,MAAMC,qBAAoBD,iBAAAA,gBAAO,CAACE,KAAK,CACrCR,gBACA,2EAFwBM,cAGvB,CAAC,EAAE;IAEN,IAAI,CAACC,mBAAmB;QACtBE,IAAAA,iCAAe,EAACJ;QAChB;IACF;IAEAL,iBAAiBU,SACfX,SACAC,gBACAC,eACAC,YACAC,MACAC,aACAC;IAGFL,iBAAiBW,QAAQX,gBAAgBK;IAEzC,OAAOL;AACT;AAEA,SAASU,SACPX,OAA4B,EAC5BC,cAAsB,EACtBC,aAAmC,EACnCC,UAAkB,EAClBC,IAAU,EACVC,WAAmB,EACnBC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BC,MAAM,CAAC,gBAAgB,CAAC;YAC1B;SACD;IACH;AACF;AAEA,SAASE,iBACPC,kBAA0B,EAC1BrB,UAAkB,EAClBT,UAAkB;IAElB,MAAMO,aAAaC,IAAAA,+BAAa,EAACsB;IACjC,IAAI,CAACvB,YAAY;QACfH,IAAAA,iCAAe,EAACJ;QAChB,OAAO8B;IACT;IAEA,OAAOF,IAAAA,4BAAoB,EAACE,oBAAoB;QAC9C;YACER,MAAMC,kBAAU,CAACC,MAAM;YACvBC,OAAOlB,WAAWmB,QAAQ,KAAK;YAC/BC,MAAM,CAAC;yBACY,EAAElB,WAAW;;;;;gBAKtB,CAAC;QACb;KACD;AACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ProjectConfiguration } from '@nx/devkit';
|
|
2
|
-
export declare function updateTestConfig(configContents: string, projectConfig: ProjectConfiguration): string;
|
|
2
|
+
export declare function updateTestConfig(configContents: string, projectConfig: ProjectConfiguration, configPath: string): string;
|
|
@@ -7,10 +7,16 @@ Object.defineProperty(exports, "updateTestConfig", {
|
|
|
7
7
|
});
|
|
8
8
|
const _devkit = require("@nx/devkit");
|
|
9
9
|
const _tsquery = require("@phenomnomnominal/tsquery");
|
|
10
|
+
const _updateviteconfig = require("../update-vite-config");
|
|
10
11
|
const ts = require("typescript");
|
|
11
|
-
function updateTestConfig(configContents, projectConfig) {
|
|
12
|
+
function updateTestConfig(configContents, projectConfig, configPath) {
|
|
12
13
|
var _tsquery_query, _projectConfig_targets_test_options, _projectConfig_targets_test, _projectConfig_targets;
|
|
13
|
-
const
|
|
14
|
+
const configNode = (0, _updateviteconfig.getConfigNode)(configContents);
|
|
15
|
+
if (!configNode) {
|
|
16
|
+
(0, _updateviteconfig.notFoundWarning)(configPath);
|
|
17
|
+
return configContents;
|
|
18
|
+
}
|
|
19
|
+
const testObject = (_tsquery_query = _tsquery.tsquery.query(configNode, `PropertyAssignment:has(Identifier[name="test"])`)) == null ? void 0 : _tsquery_query[0];
|
|
14
20
|
let testCoverageDir;
|
|
15
21
|
let testCoverage;
|
|
16
22
|
let provider;
|
|
@@ -1 +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
|
|
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');\nimport { getConfigNode, notFoundWarning } from '../update-vite-config';\n\nexport function updateTestConfig(\n configContents: string,\n projectConfig: ProjectConfiguration,\n configPath: string\n): string {\n const configNode = getConfigNode(configContents);\n if (!configNode) {\n notFoundWarning(configPath);\n return configContents;\n }\n\n const testObject = tsquery.query(\n configNode,\n `PropertyAssignment:has(Identifier[name=\"test\"])`\n )?.[0];\n let testCoverageDir: ts.Node;\n let testCoverage: ts.Node;\n let provider: ts.Node;\n let reporters: ts.Node;\n\n if (testObject) {\n testCoverage = tsquery.query(\n testObject,\n `PropertyAssignment:has(Identifier[name=\"coverage\"])`\n )?.[0];\n reporters = tsquery.query(\n testObject,\n `PropertyAssignment:has(Identifier[name=\"reporters\"])`\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 let changes = [];\n\n if (!reporters && testObject) {\n changes.push({\n type: ChangeType.Insert,\n index: testObject.getStart() + `test: {`.length + 1,\n text: `reporters: ['default'],`,\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 changes.push({\n type: ChangeType.Insert,\n index: testCoverage.getStart() + `coverage: {`.length + 1,\n text: `reportsDirectory: '${coverageDir}',`,\n });\n if (!provider) {\n changes.push({\n type: ChangeType.Insert,\n index: testCoverage.getStart() + `coverage: {`.length + 1,\n text: `provider: 'v8',`,\n });\n }\n } else if (testObject) {\n changes.push({\n type: ChangeType.Insert,\n index: testObject.getStart() + `test: {`.length + 1,\n text: `coverage: {\n reportsDirectory: '${coverageDir}',\n provider: 'v8',\n },`,\n });\n }\n\n if (changes.length > 0) {\n return applyChangesToString(configContents, changes);\n } else {\n return configContents;\n }\n}\n"],"names":["updateTestConfig","ts","configContents","projectConfig","configPath","tsquery","configNode","getConfigNode","notFoundWarning","testObject","query","testCoverageDir","testCoverage","provider","reporters","coverageDir","targets","test","options","reportsDirectory","joinPathFragments","offsetFromRoot","root","changes","push","type","ChangeType","Insert","index","getStart","length","text","applyChangesToString"],"mappings":";+BAWgBA;;;eAAAA;;;wBALT;yBACiB;kCAEuB;AAD/C,MAAOC,aAAa;AAGb,SAASD,iBACdE,cAAsB,EACtBC,aAAmC,EACnCC,UAAkB;QAQCC,gBAgCfF,qCAAAA,6BAAAA;IAtCJ,MAAMG,aAAaC,IAAAA,+BAAa,EAACL;IACjC,IAAI,CAACI,YAAY;QACfE,IAAAA,iCAAe,EAACJ;QAChB,OAAOF;IACT;IAEA,MAAMO,cAAaJ,iBAAAA,gBAAO,CAACK,KAAK,CAC9BJ,YAC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C,MAAM,CAAC,uBAAuB,CAAC;QACjC;IACF;IAEA,IAAIpB,iBAAiB;IACnB,aAAa;IACf,OAAO,IAAIC,cAAc;QACvB,6CAA6C;QAC7C,0BAA0B;QAC1BW,QAAQC,IAAI,CAAC;YACXC,MAAMC,kBAAU,CAACC,MAAM;YACvBC,OAAOhB,aAAaiB,QAAQ,KAAK,CAAC,WAAW,CAAC,CAACC,MAAM,GAAG;YACxDC,MAAM,CAAC,mBAAmB,EAAEhB,YAAY,EAAE,CAAC;QAC7C;QACA,IAAI,CAACF,UAAU;YACbU,QAAQC,IAAI,CAAC;gBACXC,MAAMC,kBAAU,CAACC,MAAM;gBACvBC,OAAOhB,aAAaiB,QAAQ,KAAK,CAAC,WAAW,CAAC,CAACC,MAAM,GAAG;gBACxDC,MAAM,CAAC,eAAe,CAAC;YACzB;QACF;IACF,OAAO,IAAItB,YAAY;QACrBc,QAAQC,IAAI,CAAC;YACXC,MAAMC,kBAAU,CAACC,MAAM;YACvBC,OAAOnB,WAAWoB,QAAQ,KAAK,CAAC,OAAO,CAAC,CAACC,MAAM,GAAG;YAClDC,MAAM,CAAC;6BACgB,EAAEhB,YAAY;;UAEjC,CAAC;QACP;IACF;IAEA,IAAIQ,QAAQO,MAAM,GAAG,GAAG;QACtB,OAAOE,IAAAA,4BAAoB,EAAC9B,gBAAgBqB;IAC9C,OAAO;QACL,OAAOrB;IACT;AACF"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
|
+
import ts = require('typescript');
|
|
2
3
|
export default function updateBuildDir(tree: Tree): Promise<void>;
|
|
4
|
+
export declare function getConfigNode(configFileContents: string): ts.Node | undefined;
|
|
5
|
+
export declare function notFoundWarning(configPath: string): void;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
default: function() {
|
|
5
10
|
return updateBuildDir;
|
|
11
|
+
},
|
|
12
|
+
getConfigNode: function() {
|
|
13
|
+
return getConfigNode;
|
|
14
|
+
},
|
|
15
|
+
notFoundWarning: function() {
|
|
16
|
+
return notFoundWarning;
|
|
6
17
|
}
|
|
7
18
|
});
|
|
8
19
|
const _devkit = require("@nx/devkit");
|
|
@@ -10,6 +21,8 @@ const _executoroptionsutils = require("@nx/devkit/src/generators/executor-option
|
|
|
10
21
|
const _editbuildconfig = require("./lib/edit-build-config");
|
|
11
22
|
const _edittestconfig = require("./lib/edit-test-config");
|
|
12
23
|
const _addfilereplacements = require("./lib/add-file-replacements");
|
|
24
|
+
const _tsquery = require("@phenomnomnominal/tsquery");
|
|
25
|
+
const ts = require("typescript");
|
|
13
26
|
async function updateBuildDir(tree) {
|
|
14
27
|
const projects = (0, _devkit.getProjects)(tree);
|
|
15
28
|
(0, _executoroptionsutils.forEachExecutorOptions)(tree, '@nx/vite:build', (options, projectName, targetName)=>{
|
|
@@ -20,10 +33,10 @@ async function updateBuildDir(tree) {
|
|
|
20
33
|
return;
|
|
21
34
|
}
|
|
22
35
|
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);
|
|
36
|
+
configContents = (0, _editbuildconfig.updateBuildOutDirAndRoot)(options, configContents, projectConfig, targetName, tree, projectName, config);
|
|
37
|
+
configContents = (0, _edittestconfig.updateTestConfig)(configContents, projectConfig, config);
|
|
25
38
|
if (((_options_fileReplacements = options.fileReplacements) == null ? void 0 : _options_fileReplacements.length) > 0) {
|
|
26
|
-
configContents = (0, _addfilereplacements.addFileReplacements)(configContents, options.fileReplacements);
|
|
39
|
+
configContents = (0, _addfilereplacements.addFileReplacements)(configContents, options.fileReplacements, config);
|
|
27
40
|
}
|
|
28
41
|
tree.write(config, configContents);
|
|
29
42
|
});
|
|
@@ -44,5 +57,26 @@ function findViteConfig(tree, searchRoot) {
|
|
|
44
57
|
}
|
|
45
58
|
}
|
|
46
59
|
}
|
|
60
|
+
function getConfigNode(configFileContents) {
|
|
61
|
+
var _tsquery_query, _tsquery_query1;
|
|
62
|
+
if (!configFileContents) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
let configNode = (_tsquery_query = _tsquery.tsquery.query(configFileContents, `ObjectLiteralExpression`)) == null ? void 0 : _tsquery_query[0];
|
|
66
|
+
const arrowFunctionReturnStatement = (_tsquery_query1 = _tsquery.tsquery.query(configFileContents, `ArrowFunction Block ReturnStatement ObjectLiteralExpression`)) == null ? void 0 : _tsquery_query1[0];
|
|
67
|
+
if (arrowFunctionReturnStatement) {
|
|
68
|
+
configNode = arrowFunctionReturnStatement;
|
|
69
|
+
}
|
|
70
|
+
return configNode;
|
|
71
|
+
}
|
|
72
|
+
function notFoundWarning(configPath) {
|
|
73
|
+
_devkit.logger.warn(`
|
|
74
|
+
Could not migrate your ${configPath} file.
|
|
75
|
+
Please add the build.outDir and root options in your ${configPath} file.
|
|
76
|
+
You can find more information on how to configure vite for Nx here:
|
|
77
|
+
|
|
78
|
+
https://nx.dev/recipes/vite/configure-vite
|
|
79
|
+
`);
|
|
80
|
+
}
|
|
47
81
|
|
|
48
82
|
//# sourceMappingURL=update-vite-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/migrations/update-17-2-0/update-vite-config.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/migrations/update-17-2-0/update-vite-config.ts"],"sourcesContent":["import {\n Tree,\n formatFiles,\n getProjects,\n joinPathFragments,\n logger,\n} 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';\nimport { tsquery } from '@phenomnomnominal/tsquery';\nimport ts = require('typescript');\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 config\n );\n\n configContents = updateTestConfig(configContents, projectConfig, config);\n\n if (options.fileReplacements?.length > 0) {\n configContents = addFileReplacements(\n configContents,\n options.fileReplacements,\n config\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\nexport function getConfigNode(configFileContents: string): ts.Node | undefined {\n if (!configFileContents) {\n return;\n }\n let configNode = tsquery.query(\n configFileContents,\n `ObjectLiteralExpression`\n )?.[0];\n\n const arrowFunctionReturnStatement = tsquery.query(\n configFileContents,\n `ArrowFunction Block ReturnStatement ObjectLiteralExpression`\n )?.[0];\n\n if (arrowFunctionReturnStatement) {\n configNode = arrowFunctionReturnStatement;\n }\n\n return configNode;\n}\n\nexport function notFoundWarning(configPath: string) {\n logger.warn(`\n Could not migrate your ${configPath} file.\n Please add the build.outDir and root options in your ${configPath} file.\n You can find more information on how to configure vite for Nx here:\n \n https://nx.dev/recipes/vite/configure-vite\n `);\n}\n"],"names":["updateBuildDir","getConfigNode","notFoundWarning","ts","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","configFileContents","tsquery","configNode","query","arrowFunctionReturnStatement","configPath","logger","warn"],"mappings":";;;;;;;;IAeA,OAuCC;eAvC6BA;;IAmDdC,aAAa;eAAbA;;IAqBAC,eAAe;eAAfA;;;wBAjFT;sCACgC;iCAEE;gCACR;qCACG;yBACZ;AACxB,MAAOC,aAAa;AAEL,eAAeH,eAAeI,IAAU;IACrD,MAAMC,WAAWC,IAAAA,mBAAW,EAACF;IAC7BG,IAAAA,4CAAsB,EACpBH,MACA,kBACA,CAACI,SAASC,aAAaC;YAqBjBF;QApBJ,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,aACAI;QAGFK,iBAAiBG,IAAAA,gCAAgB,EAACH,gBAAgBP,eAAeE;QAEjE,IAAIL,EAAAA,4BAAAA,QAAQc,gBAAgB,qBAAxBd,0BAA0Be,MAAM,IAAG,GAAG;YACxCL,iBAAiBM,IAAAA,wCAAmB,EAClCN,gBACAV,QAAQc,gBAAgB,EACxBT;QAEJ;QAEAT,KAAKqB,KAAK,CAACZ,QAAQK;IACrB;IAGF,MAAMQ,IAAAA,mBAAW,EAACtB;AACpB;AAEA,SAASW,eAAeX,IAAU,E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