Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tweaking relative path handling for windows compatibility #18

Merged
merged 11 commits into from
Dec 14, 2023
127 changes: 122 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"src"
],
"scripts": {
"compile": "rimraf out && tsc -p ./ && cp -R algosdk out/algosdk",
"compile": "shx rm -rf out && tsc -p ./ && shx cp -R algosdk out/algosdk",
"lint": "eslint src --ext ts",
"typecheck": "tsc -p tsconfig.json --noEmit",
"check-format": "prettier . --check",
Expand Down Expand Up @@ -98,6 +98,7 @@
"nyc": "^15.1.0",
"prettier": "^3.0.3",
"rimraf": "^3.0.2",
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
"shx": "^0.3.4",
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
"ts-mocha": "^10.0.0",
"typescript": "^4.6.3",
"url": "^0.11.3"
Expand Down
15 changes: 14 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as JSONbigWithoutConfig from 'json-bigint';
import * as algosdk from '../../algosdk';
import { FileAccessor } from './fileAccessor';
import * as path from 'path';
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved

/**
* Attempt to decode the given data as UTF-8 and return the result if it is
Expand Down Expand Up @@ -122,7 +123,19 @@ export class ByteArrayMap<T> {
}

function filePathRelativeTo(base: string, filePath: string): string {
return new URL(filePath, new URL(base, 'file://')).pathname;
// Normalize the base path to convert any Windows backslashes to forward slashes
// This is necessary because the URL object expects forward slashes
const normalizedBase = base.replace(/\\/g, '/');

// Create a URL object with the file protocol and the normalized base path
const baseURL = new URL(normalizedBase, 'file:///');
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved

// Resolve the file path against the base URL
const fullURL = new URL(filePath, baseURL);

// Convert the URL back to a local file path
// On Windows, this will correctly handle the drive letter and convert to backslashes
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
return path.resolve(fullURL.pathname);
}

interface ProgramSourceEntryFile {
Expand Down
Loading