Skip to content

Commit 89b1f81

Browse files
CopilotLipata
andcommitted
Implement vite.config.ts support in upgrade command with tests
Co-authored-by: Lipata <[email protected]>
1 parent 034a622 commit 89b1f81

File tree

2 files changed

+191
-6
lines changed

2 files changed

+191
-6
lines changed

packages/core/update/Update.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
116116
pkgJsonFiles.push(...fs.glob(workspace, `**/package.json`));
117117
}
118118

119+
// For React and WebComponents projects, also include vite.config.ts files
120+
if (framework.toLowerCase() === "react" || framework.toLowerCase() === "webcomponents") {
121+
const viteConfigFiles = fs.glob(rootPath, `vite.config.ts`, ['node_modules', 'dist']);
122+
if (viteConfigFiles && viteConfigFiles.length > 0) {
123+
logicFiles.push(...viteConfigFiles);
124+
}
125+
}
126+
119127
updateFileImports(logicFiles, styleFiles, upgradeable, fs);
120128
if (shouldUpgradeHTML) {
121129
updateHTMLImports(htmlFiles, upgradeable, fs);

spec/unit/update-spec.ts

Lines changed: 183 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ title = 'igniteui-angular example';
545545
}
546546
}));
547547
expect(fsSpy.writeFile).toHaveBeenCalledTimes(1);
548-
expect(fsSpy.glob).toHaveBeenCalledTimes(5);
548+
expect(fsSpy.glob).toHaveBeenCalledTimes(6);
549549
});
550550

551551
it("Should update import paths in files correctly", async () => {
@@ -713,7 +713,7 @@ export default function Home() {
713713
for (const fileEntry of mockFileArray) {
714714
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
715715
}
716-
expect(fsSpy.glob).toHaveBeenCalledTimes(5);
716+
expect(fsSpy.glob).toHaveBeenCalledTimes(6);
717717
});
718718

719719
it("Should update package.json files from workspaces", async () => {
@@ -826,7 +826,94 @@ export default function Home() {
826826
for (const fileEntry of mockFileArray) {
827827
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
828828
}
829-
expect(fsSpy.glob).toHaveBeenCalledTimes(8);
829+
expect(fsSpy.glob).toHaveBeenCalledTimes(9);
830+
});
831+
832+
it("Should update vite.config.ts file correctly", async () => {
833+
const mockFileArray: MockFile[] = [
834+
{
835+
path: "package.json",
836+
content:
837+
`{
838+
"dependencies": {
839+
"igniteui-react-grids": "^18.5.1",
840+
"some-package": "^0.0.0"
841+
}
842+
}
843+
`,
844+
expected:
845+
`{
846+
"dependencies": {
847+
"@infragistics/igniteui-react-grids": "^18.5.1",
848+
"some-package": "^0.0.0"
849+
}
850+
}
851+
`
852+
},
853+
{
854+
path: "vite.config.ts",
855+
content:
856+
`import { defineConfig } from 'vite';
857+
import { viteStaticCopy } from 'vite-plugin-static-copy';
858+
859+
export default defineConfig({
860+
plugins: [
861+
viteStaticCopy({
862+
targets: [
863+
{
864+
src: "node_modules/igniteui-react-grids/grids/themes/light/bootstrap.css",
865+
dest: "themes",
866+
},
867+
{
868+
src: "node_modules/igniteui-react-grids/grids/themes/light/fluent.css",
869+
dest: "themes",
870+
},
871+
],
872+
}),
873+
],
874+
});`,
875+
expected:
876+
`import { defineConfig } from 'vite';
877+
import { viteStaticCopy } from 'vite-plugin-static-copy';
878+
879+
export default defineConfig({
880+
plugins: [
881+
viteStaticCopy({
882+
targets: [
883+
{
884+
src: "node_modules/@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css",
885+
dest: "themes",
886+
},
887+
{
888+
src: "node_modules/@infragistics/igniteui-react-grids/grids/themes/light/fluent.css",
889+
dest: "themes",
890+
},
891+
],
892+
}),
893+
],
894+
});`
895+
}];
896+
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
897+
([ "package.json" ], // root package.json
898+
[], // html file
899+
[ "src/home.tsx" ], // logic files
900+
[], // for each style extension
901+
[], // inner package.json files
902+
["vite.config.ts"]); // vite config files
903+
(fsSpy.readFile as jasmine.Spy).and.callFake((filePath: string) => {
904+
if (filePath.indexOf("package.json") > -1) {
905+
return mockFileArray.find(entry => entry.path === "package.json").content;
906+
}
907+
const fileEntry = mockFileArray.find(entry => entry.path === filePath);
908+
return fileEntry ? fileEntry.content : "";
909+
});
910+
(fsSpy.fileExists as jasmine.Spy).and.returnValue(true);
911+
spyOn(PackageManager, "ensureRegistryUser").and.returnValue(true);
912+
expect(await updateWorkspace("")).toEqual(true);
913+
for (const fileEntry of mockFileArray) {
914+
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
915+
}
916+
expect(fsSpy.glob).toHaveBeenCalledTimes(6);
830917
});
831918
});
832919

@@ -914,7 +1001,7 @@ export default function Home() {
9141001
}
9151002
}));
9161003
expect(fsSpy.writeFile).toHaveBeenCalledTimes(2);
917-
expect(fsSpy.glob).toHaveBeenCalledTimes(4);
1004+
expect(fsSpy.glob).toHaveBeenCalledTimes(5);
9181005
});
9191006

9201007
it("Should update import paths in files correctly", async () => {
@@ -1069,7 +1156,7 @@ export default class App extends LitElement {
10691156
for (const fileEntry of mockFileArray) {
10701157
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
10711158
}
1072-
expect(fsSpy.glob).toHaveBeenCalledTimes(4);
1159+
expect(fsSpy.glob).toHaveBeenCalledTimes(5);
10731160
});
10741161

10751162
it("Should update package.json files from workspaces", async () => {
@@ -1180,7 +1267,97 @@ export default class App extends LitElement {
11801267
for (const fileEntry of mockFileArray) {
11811268
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
11821269
}
1183-
expect(fsSpy.glob).toHaveBeenCalledTimes(6);
1270+
expect(fsSpy.glob).toHaveBeenCalledTimes(7);
1271+
});
1272+
1273+
it("Should update vite.config.ts file correctly", async () => {
1274+
const mockFileArray: MockFile[] = [
1275+
{
1276+
path: "package.json",
1277+
content:
1278+
`{
1279+
"dependencies": {
1280+
"igniteui-webcomponents-grids": "^4.7.0",
1281+
"some-package": "^0.0.0"
1282+
}
1283+
}
1284+
`,
1285+
expected:
1286+
`{
1287+
"dependencies": {
1288+
"@infragistics/igniteui-webcomponents-grids": "^4.7.0",
1289+
"some-package": "^0.0.0"
1290+
}
1291+
}
1292+
`
1293+
},
1294+
{
1295+
path: "vite.config.ts",
1296+
content:
1297+
`import { defineConfig } from 'vite';
1298+
import { viteStaticCopy } from 'vite-plugin-static-copy';
1299+
1300+
export default defineConfig(({ mode }) => {
1301+
return {
1302+
plugins: [
1303+
viteStaticCopy({
1304+
targets: [
1305+
{
1306+
src: "node_modules/igniteui-webcomponents-grids/grids/themes/light/bootstrap.css",
1307+
dest: "themes",
1308+
},
1309+
{
1310+
src: "node_modules/igniteui-webcomponents-grids/grids/themes/light/fluent.css",
1311+
dest: "themes",
1312+
},
1313+
],
1314+
}),
1315+
],
1316+
};
1317+
});`,
1318+
expected:
1319+
`import { defineConfig } from 'vite';
1320+
import { viteStaticCopy } from 'vite-plugin-static-copy';
1321+
1322+
export default defineConfig(({ mode }) => {
1323+
return {
1324+
plugins: [
1325+
viteStaticCopy({
1326+
targets: [
1327+
{
1328+
src: "node_modules/@infragistics/igniteui-webcomponents-grids/grids/themes/light/bootstrap.css",
1329+
dest: "themes",
1330+
},
1331+
{
1332+
src: "node_modules/@infragistics/igniteui-webcomponents-grids/grids/themes/light/fluent.css",
1333+
dest: "themes",
1334+
},
1335+
],
1336+
}),
1337+
],
1338+
};
1339+
});`
1340+
}];
1341+
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
1342+
([ "package.json" ], // root package.json
1343+
[], // html file
1344+
["src/app.ts"], // logic files
1345+
[], // inner package.json files
1346+
["vite.config.ts"]); // vite config files
1347+
(fsSpy.readFile as jasmine.Spy).and.callFake((filePath: string) => {
1348+
if (filePath.indexOf("package.json") > -1) {
1349+
return mockFileArray.find(entry => entry.path === "package.json").content;
1350+
}
1351+
const fileEntry = mockFileArray.find(entry => entry.path === filePath);
1352+
return fileEntry ? fileEntry.content : "";
1353+
});
1354+
(fsSpy.fileExists as jasmine.Spy).and.returnValue(true);
1355+
spyOn(PackageManager, "ensureRegistryUser").and.returnValue(true);
1356+
expect(await updateWorkspace("")).toEqual(true);
1357+
for (const fileEntry of mockFileArray) {
1358+
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
1359+
}
1360+
expect(fsSpy.glob).toHaveBeenCalledTimes(5);
11841361
});
11851362
});
11861363
});

0 commit comments

Comments
 (0)