Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix: relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Jul 22, 2022
1 parent b75b579 commit 037d230
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "huff-language",
"version": "0.0.21",
"version": "0.0.22",
"displayName": "Huff",
"preview": true,
"icon": "resources/huff.png",
Expand Down
15 changes: 12 additions & 3 deletions src/features/debugger/function/debugger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require("fs");
const createKeccakHash = require('keccak');
const path = require("path");

// TODO: use a slimmer abicoder
const { AbiCoder } = require("@ethersproject/abi");
Expand Down Expand Up @@ -58,14 +59,22 @@ async function startDebugger(cwd, currentFile, imports, functionSelector, argsAr
* @returns
*/
function flattenFile(cwd, currentFile, imports){
// Get relative path of files
const dirPath = currentFile.split("/").slice(0,-1).join("/")
const paths = imports.map(importPath => `${cwd}/${dirPath}${importPath.replace(/#include\s?"./, "").replace('"', "")}`);

// Get absolute paths
const paths = imports.map(importPath => path.join(`${cwd}/${dirPath}`,importPath.replace(/#include\s?"/, "").replace('"', "")));
paths.push(cwd+ "/" + currentFile);
const files = paths.map(path => fs.readFileSync(path)

// Read file contents
const files = paths.map(path => {
console.log(path)
return fs.readFileSync(path)
.toString()
}
);

// remove include
// Flatten and remove imports
return `${files.join("\n")}`.replace(/#include\s".*"/gsm, "");
}

Expand Down

0 comments on commit 037d230

Please sign in to comment.