Skip to content

Commit

Permalink
fix: normalize paths to unix style
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Dec 15, 2024
1 parent b6a119a commit 159a518
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/service/deleteReassembledXML.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

import { stat, readdir, rm } from "node:fs/promises";
import { join } from "node:path";
import { join } from "node:path/posix";

export async function deleteReassembledXML(
disassembledPath: string,
Expand Down
2 changes: 1 addition & 1 deletion src/service/json2xmlReassembler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

import { stat, readdir } from "node:fs/promises";
import { join } from "node:path";
import { join } from "node:path/posix";

import { logger } from "@src/index";
import { reassembleHandler } from "@src/service/reassembleHandler";
Expand Down
2 changes: 1 addition & 1 deletion src/service/transform2JSON.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

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

import { logger } from "@src/index";
Expand Down
18 changes: 16 additions & 2 deletions src/service/xml2jsonDisassembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

import { existsSync } from "node:fs";
import { stat, readdir, readFile } from "node:fs/promises";
import { resolve, join, basename, dirname, extname, relative } from "node:path";
import {
resolve,
join,
basename,
dirname,
extname,
relative,
} from "node:path/posix";
import ignore, { Ignore } from "ignore";

import { logger } from "@src/index";
Expand Down Expand Up @@ -53,9 +60,12 @@ export class XmlToJsonDisassembler {
});
} else if (fileStat.isDirectory()) {
const subFiles = await readdir(filePath);
const resolvedBasePath = dirname(resolvedIgnorePath); // Base path of the ignore file
for (const subFile of subFiles) {
const subFilePath = join(filePath, subFile);
const relativeSubFilePath = relative(process.cwd(), subFilePath);
const relativeSubFilePath = this.posixPath(
relative(resolvedBasePath, subFilePath),
);
if (
subFilePath.endsWith(".xml") &&
!this.ign.ignores(relativeSubFilePath)
Expand Down Expand Up @@ -96,4 +106,8 @@ export class XmlToJsonDisassembler {
const baseName = fullName.split(".")[0];
await transform2JSON(join(basePath, baseName));
}
private posixPath(path: string): string {
// Normalize path to POSIX-style (for cross-platform compatibility)
return path.replace(/\\+/g, "/");
}
}
2 changes: 1 addition & 1 deletion test/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readdir, readFile, writeFile, rm } from "node:fs/promises";
import { strictEqual } from "node:assert";
import { resolve, join } from "node:path";
import { resolve, join } from "node:path/posix";
import { copy } from "fs-extra";

import {
Expand Down

0 comments on commit 159a518

Please sign in to comment.