Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 159a518

Browse files
committed
fix: normalize paths to unix style
1 parent b6a119a commit 159a518

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

src/service/deleteReassembledXML.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import { stat, readdir, rm } from "node:fs/promises";
4-
import { join } from "node:path";
4+
import { join } from "node:path/posix";
55

66
export async function deleteReassembledXML(
77
disassembledPath: string,

src/service/json2xmlReassembler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import { stat, readdir } from "node:fs/promises";
4-
import { join } from "node:path";
4+
import { join } from "node:path/posix";
55

66
import { logger } from "@src/index";
77
import { reassembleHandler } from "@src/service/reassembleHandler";

src/service/transform2JSON.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import { readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
4-
import { join } from "node:path";
4+
import { join } from "node:path/posix";
55
import { XMLParser } from "fast-xml-parser";
66

77
import { logger } from "@src/index";

src/service/xml2jsonDisassembler.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
import { existsSync } from "node:fs";
44
import { stat, readdir, readFile } from "node:fs/promises";
5-
import { resolve, join, basename, dirname, extname, relative } from "node:path";
5+
import {
6+
resolve,
7+
join,
8+
basename,
9+
dirname,
10+
extname,
11+
relative,
12+
} from "node:path/posix";
613
import ignore, { Ignore } from "ignore";
714

815
import { logger } from "@src/index";
@@ -53,9 +60,12 @@ export class XmlToJsonDisassembler {
5360
});
5461
} else if (fileStat.isDirectory()) {
5562
const subFiles = await readdir(filePath);
63+
const resolvedBasePath = dirname(resolvedIgnorePath); // Base path of the ignore file
5664
for (const subFile of subFiles) {
5765
const subFilePath = join(filePath, subFile);
58-
const relativeSubFilePath = relative(process.cwd(), subFilePath);
66+
const relativeSubFilePath = this.posixPath(
67+
relative(resolvedBasePath, subFilePath),
68+
);
5969
if (
6070
subFilePath.endsWith(".xml") &&
6171
!this.ign.ignores(relativeSubFilePath)
@@ -96,4 +106,8 @@ export class XmlToJsonDisassembler {
96106
const baseName = fullName.split(".")[0];
97107
await transform2JSON(join(basePath, baseName));
98108
}
109+
private posixPath(path: string): string {
110+
// Normalize path to POSIX-style (for cross-platform compatibility)
111+
return path.replace(/\\+/g, "/");
112+
}
99113
}

test/main.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readdir, readFile, writeFile, rm } from "node:fs/promises";
22
import { strictEqual } from "node:assert";
3-
import { resolve, join } from "node:path";
3+
import { resolve, join } from "node:path/posix";
44
import { copy } from "fs-extra";
55

66
import {

0 commit comments

Comments
 (0)