Skip to content

Commit

Permalink
update normalizePath to work on widows
Browse files Browse the repository at this point in the history
  • Loading branch information
dichovsky committed Aug 30, 2024
1 parent 045aa83 commit 2cc26aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions __tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ test('should normalize root path', () => {
const path = '/';
const normalizedPath: string = normalizePath(path);
expect(normalizedPath).to.equal('/');

Check failure on line 26 in __tests__/normalize.test.ts

View workflow job for this annotation

GitHub Actions / windows (20)

__tests__/normalize.test.ts > should normalize root path

AssertionError: expected '/\' to equal '/' Expected: "/" Received: "/\" ❯ __tests__/normalize.test.ts:26:31
});

test('should append trailing backslash if path ends with backslash on Windows systems', () => {
const path = 'C:\\Users\\test\\Projects\\pdf-to-png-converter\\src\\';
const normalizedPath = normalizePath(path);
expect(normalizedPath).to.equal('C:\\Users\\test\\Projects\\pdf-to-png-converter\\src\\');

Check failure on line 32 in __tests__/normalize.test.ts

View workflow job for this annotation

GitHub Actions / ubuntu (18)

__tests__/normalize.test.ts > should append trailing backslash if path ends with backslash on Windows systems

AssertionError: expected '/home/runner/work/pdf-to-png-converte…' to equal 'C:\Users\test\Projects\pdf-to-png-con…' Expected: "C:\Users\test\Projects\pdf-to-png-converter\src\" Received: "/home/runner/work/pdf-to-png-converter/pdf-to-png-converter/C:\Users\test\Projects\pdf-to-png-converter\src\/" ❯ __tests__/normalize.test.ts:32:31

Check failure on line 32 in __tests__/normalize.test.ts

View workflow job for this annotation

GitHub Actions / windows (20)

__tests__/normalize.test.ts > should append trailing backslash if path ends with backslash on Windows systems

AssertionError: expected '/a/pdf-to-png-converter/pdf-to-png-co…' to equal 'C:\Users\test\Projects\pdf-to-png-con…' Expected: "C:\Users\test\Projects\pdf-to-png-converter\src\" Received: "/a/pdf-to-png-converter/pdf-to-png-converter/C:\Users\test\Projects\pdf-to-png-converter\src\" ❯ __tests__/normalize.test.ts:32:31

Check failure on line 32 in __tests__/normalize.test.ts

View workflow job for this annotation

GitHub Actions / ubuntu (20)

__tests__/normalize.test.ts > should append trailing backslash if path ends with backslash on Windows systems

AssertionError: expected '/home/runner/work/pdf-to-png-converte…' to equal 'C:\Users\test\Projects\pdf-to-png-con…' Expected: "C:\Users\test\Projects\pdf-to-png-converter\src\" Received: "/home/runner/work/pdf-to-png-converter/pdf-to-png-converter/C:\Users\test\Projects\pdf-to-png-converter\src\/" ❯ __tests__/normalize.test.ts:32:31
});
13 changes: 11 additions & 2 deletions src/normalize.path.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { resolve, join } from "path/posix";
import { resolve, join, normalize } from "path/posix";

export function normalizePath(path: string): string {
const resolvedPath: string = resolve(join(path));
const resolvedPath: string = normalize(resolve(join(path)));
console.log(process.platform)
if (process.platform === 'win32') {
if (resolvedPath.endsWith('\\')) {
return resolvedPath;
}
return `${resolvedPath}\\`;
}

if (resolvedPath.endsWith('/')) {
return resolvedPath;
}

return `${resolvedPath}/`;
}

0 comments on commit 2cc26aa

Please sign in to comment.