Skip to content

Commit e3e4982

Browse files
CopilotLipata
andcommitted
fix(react): enhance upgrade-packages to support workspace glob patterns for projects without explicit workspaces
Co-authored-by: Lipata <[email protected]>
1 parent e8affb2 commit e3e4982

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

packages/core/update/Update.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,22 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
116116
}
117117
});
118118
} else {
119+
// For React and WebComponents projects without explicit workspaces,
120+
// check for common project patterns like projects/* in addition to src/
119121
workspaces.push(path.join(rootPath, "src"));
122+
123+
// Check for projects/* pattern common in React demo/example repositories
124+
// Only check if projects directory exists to avoid unnecessary glob calls
125+
const projectsDir = path.join(rootPath, "projects");
126+
if (fs.directoryExists(projectsDir)) {
127+
const projectsPattern = "projects/*";
128+
const projectsWorkspaces = fs.glob(rootPath, projectsPattern);
129+
projectsWorkspaces.forEach(projectPath => {
130+
if (fs.directoryExists(projectPath)) {
131+
workspaces.push(projectPath);
132+
}
133+
});
134+
}
120135
}
121136
break;
122137
default:

spec/unit/update-spec.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,110 @@ export default defineConfig({
932932
}
933933
expect(fsSpy.glob).toHaveBeenCalledTimes(6);
934934
});
935+
936+
it("Should detect and update React projects with projects/* structure but no explicit workspaces", async () => {
937+
const mockFileArray: MockFile[] = [
938+
{
939+
path: "package.json",
940+
content:
941+
`{
942+
"name": "grid-demos-react",
943+
"dependencies": {
944+
"igniteui-react-grids": "^18.5.1",
945+
"some-package": "^0.0.0"
946+
}
947+
}
948+
`,
949+
expected:
950+
`{
951+
"name": "grid-demos-react",
952+
"dependencies": {
953+
"@infragistics/igniteui-react-grids": "^18.5.1",
954+
"some-package": "^0.0.0"
955+
}
956+
}
957+
`
958+
},
959+
{
960+
path: "projects/erp-hierarchical-grid/src/app.tsx",
961+
content:
962+
`import { IgrGridModule, IgrGrid } from 'igniteui-react-grids';
963+
import 'igniteui-react-grids/grids/themes/light/bootstrap.css';
964+
965+
export default function App() {
966+
return <IgrGrid />;
967+
}`,
968+
expected:
969+
`import { IgrGridModule, IgrGrid } from '@infragistics/igniteui-react-grids';
970+
import '@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css';
971+
972+
export default function App() {
973+
return <IgrGrid />;
974+
}`
975+
},
976+
{
977+
path: "projects/finance-grid/src/components/GridComponent.tsx",
978+
content:
979+
`import { IgrColumn } from 'igniteui-react-grids';
980+
981+
export const GridComponent = () => {
982+
return <IgrColumn />;
983+
}`,
984+
expected:
985+
`import { IgrColumn } from '@infragistics/igniteui-react-grids';
986+
987+
export const GridComponent = () => {
988+
return <IgrColumn />;
989+
}`
990+
}];
991+
992+
(fsSpy.fileExists as jasmine.Spy).and.returnValue(true);
993+
// Mock directoryExists to return true for projects directories and src
994+
(fsSpy.directoryExists as jasmine.Spy).and.callFake((dirPath: string) => {
995+
return dirPath === "projects" || dirPath.endsWith("/projects") || dirPath.includes("projects/") || dirPath === "src" || dirPath.endsWith("/src");
996+
});
997+
998+
// Mock glob to simulate finding projects directories and files
999+
(fsSpy.glob as jasmine.Spy).and.callFake((dirPath: string, pattern: string) => {
1000+
if (pattern === "package.json") {
1001+
return ["package.json"];
1002+
} else if (pattern === "projects/*") {
1003+
return ["projects/erp-hierarchical-grid", "projects/finance-grid"];
1004+
} else if (pattern === "**/*.tsx") {
1005+
if (dirPath.includes("erp-hierarchical-grid")) {
1006+
return ["projects/erp-hierarchical-grid/src/app.tsx"];
1007+
} else if (dirPath.includes("finance-grid")) {
1008+
return ["projects/finance-grid/src/components/GridComponent.tsx"];
1009+
} else if (dirPath.endsWith("/src")) {
1010+
return []; // src directory has no tsx files
1011+
}
1012+
return [];
1013+
} else if (pattern === "**/*.css") {
1014+
return [];
1015+
} else if (pattern === "**/package.json") {
1016+
return [];
1017+
} else if (pattern === "vite.config.ts") {
1018+
return [];
1019+
}
1020+
return [];
1021+
});
1022+
1023+
(fsSpy.readFile as jasmine.Spy).and.callFake((filePath: string) => {
1024+
if (filePath.indexOf("package.json") > -1) {
1025+
return mockFileArray.find(entry => entry.path === "package.json").content;
1026+
}
1027+
const fileEntry = mockFileArray.find(entry => entry.path === filePath);
1028+
return fileEntry ? fileEntry.content : "";
1029+
});
1030+
spyOn(PackageManager, "ensureRegistryUser").and.returnValue(true);
1031+
spyOn(Util, "log");
1032+
expect(await updateWorkspace("")).toEqual(true);
1033+
for (const fileEntry of mockFileArray) {
1034+
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
1035+
}
1036+
// Expect calls for: package.json, projects/*, src tsx files, src css files, src package.json, vite.config.ts, erp-hierarchical-grid tsx files, erp-hierarchical-grid css files, erp-hierarchical-grid package.json, finance-grid tsx files, finance-grid css files, finance-grid package.json
1037+
expect(fsSpy.glob).toHaveBeenCalledTimes(13);
1038+
});
9351039
});
9361040

9371041
describe("Webcomponents", () => {

0 commit comments

Comments
 (0)