Skip to content

Commit e6502df

Browse files
committed
fix(core): preserve output directory separators in mkdir
Keep dirname results unchanged when creating output folders so mixed-separator paths on POSIX resolve to the same parent directory used for writes. Also update core path-handling tests and add a regression case for mixed separators (tmp\sub/out.js).
1 parent 122e396 commit e6502df

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

packages/core/__tests__/compress-paths.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ describe("compress path handling", () => {
3434

3535
await compress(settings);
3636

37-
expect(vi.mocked(mkdir)).toHaveBeenCalledWith("nested/dir", {
37+
expect(vi.mocked(mkdir)).toHaveBeenCalledWith("nested\\dir", {
3838
recursive: true,
3939
});
4040
expect(vi.mocked(compressSingleFile)).toHaveBeenCalledTimes(1);
4141
});
4242

43-
test("should normalize dirname output before mkdir", async () => {
43+
test("should preserve dirname separators before mkdir", async () => {
4444
vi.spyOn(path, "dirname").mockReturnValue("nested\\dir");
4545

4646
const compressor: Compressor = async () => ({ code: "ok" });
@@ -52,7 +52,23 @@ describe("compress path handling", () => {
5252

5353
await compress(settings);
5454

55-
expect(vi.mocked(mkdir)).toHaveBeenCalledWith("nested/dir", {
55+
expect(vi.mocked(mkdir)).toHaveBeenCalledWith("nested\\dir", {
56+
recursive: true,
57+
});
58+
expect(vi.mocked(compressSingleFile)).toHaveBeenCalledTimes(1);
59+
});
60+
61+
test("should preserve mixed-separator directory paths", async () => {
62+
const compressor: Compressor = async () => ({ code: "ok" });
63+
const settings: Settings = {
64+
compressor,
65+
input: "input.js",
66+
output: "tmp\\sub/out.js",
67+
};
68+
69+
await compress(settings);
70+
71+
expect(vi.mocked(mkdir)).toHaveBeenCalledWith("tmp\\sub", {
5672
recursive: true,
5773
});
5874
expect(vi.mocked(compressSingleFile)).toHaveBeenCalledTimes(1);

packages/core/src/compress.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ async function createDirectory(filePath: string | string[]) {
136136
function getDirectoryPath(outputPath: string): string {
137137
const dirPath = path.dirname(outputPath);
138138
if (dirPath && dirPath !== ".") {
139-
return dirPath.replaceAll("\\", "/");
139+
return dirPath;
140140
}
141141

142142
const windowsDirPath = path.win32.dirname(outputPath);
143143
if (windowsDirPath && windowsDirPath !== ".") {
144-
return windowsDirPath.replaceAll("\\", "/");
144+
return windowsDirPath;
145145
}
146146

147147
return "";

0 commit comments

Comments
 (0)