Skip to content

Commit 64f2735

Browse files
authored
fix(upgrade-packages): correctly glob files on windows (#1511)
1 parent ec63959 commit 64f2735

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

packages/cli/lib/commands/upgrade.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GoogleAnalytics, ProjectConfig, Util } from "@igniteui/cli-core";
1+
import { GoogleAnalytics, ProjectConfig, type ProjectTemplate, Util } from "@igniteui/cli-core";
22
import { PositionalArgs, UpgradeCommandType } from "./types";
33
import { ArgumentsCamelCase } from "yargs";
44

@@ -38,7 +38,7 @@ const command: UpgradeCommandType = {
3838
case "webcomponents":
3939
if (projectType === "igx-ts" || projectType === "igr-ts" || projectType === "igc-ts") {
4040
const projectLibrary = command.templateManager.getProjectLibrary(framework, projectType);
41-
let project;
41+
let project: ProjectTemplate;
4242
if (!config.project.projectTemplate || !projectLibrary.hasProject(config.project.projectTemplate)) {
4343
// in case project template is missing from the config we provide backward.
4444
project = projectLibrary.getProject(projectLibrary.projectIds[0]);

packages/core/util/FileSystem.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as fs from "fs";
33
import * as glob from "glob";
44
import * as path from "path";
5-
import { IFileSystem } from "../types/FileSystem";
5+
import type { IFileSystem } from "../types/FileSystem";
66

77
export class FsFileSystem implements IFileSystem {
88
public fileExists(filePath: string): boolean {
@@ -30,7 +30,8 @@ export class FsFileSystem implements IFileSystem {
3030
}
3131

3232
public glob(dirPath: string, pattern: string): string[] {
33-
return glob.sync(path.join(dirPath, pattern), { nodir: true })
34-
.map(filePath => filePath.replace(/\\/g, "/"));
33+
// NB!: glob 8+ patterns use `\` as escape only, so ensure posix-style:
34+
const globPattern = path.join(dirPath, pattern).replace(/\\/g, "/");
35+
return glob.sync(globPattern, { nodir: true });
3536
}
3637
}

spec/unit/FsFileSystem-spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as glob from "glob";
2+
import { FsFileSystem } from "../../packages/core/util/FileSystem";
3+
4+
describe("Unit - FsFileSystem", () => {
5+
let fileSystem: FsFileSystem;
6+
7+
beforeEach(() => {
8+
fileSystem = new FsFileSystem();
9+
});
10+
11+
describe("glob", () => {
12+
it("should pass a forward-slash pattern to glob even when dirPath uses backslashes", () => {
13+
spyOn(glob, "sync").and.returnValue([]);
14+
const windowsDirPath = "C:\\Work\\git\\project\\src";
15+
fileSystem.glob(windowsDirPath, "**/*.ts");
16+
expect(glob.sync).toHaveBeenCalledWith(
17+
"C:/Work/git/project/src/**/*.ts",
18+
jasmine.objectContaining({ nodir: true })
19+
);
20+
});
21+
22+
it("should pass a forward-slash pattern to glob even when pattern contains backslashes", () => {
23+
spyOn(glob, "sync").and.returnValue([]);
24+
fileSystem.glob("C:\\Work\\project", "sub\\**\\*.ts");
25+
expect(glob.sync).toHaveBeenCalledWith(
26+
"C:/Work/project/sub/**/*.ts",
27+
jasmine.objectContaining({ nodir: true })
28+
);
29+
});
30+
31+
it("should work correctly with forward-slash paths (non-Windows)", () => {
32+
spyOn(glob, "sync").and.returnValue([
33+
"/home/user/project/src/app.ts"
34+
] as any);
35+
const result = fileSystem.glob("/home/user/project", "src/**/*.ts");
36+
expect(glob.sync).toHaveBeenCalledWith(
37+
"/home/user/project/src/**/*.ts",
38+
jasmine.objectContaining({ nodir: true })
39+
);
40+
expect(result).toEqual(["/home/user/project/src/app.ts"]);
41+
});
42+
});
43+
});

0 commit comments

Comments
 (0)