Skip to content

Conversation

@LiaoPeng
Copy link
Contributor

Got the below errors, when executed command asc /Workspace/assemblyscript/tests/compiler/for.ts -t for.wast

The reason is that the asc command works improperly when using absolute path.

 asc /Workspace/assemblyscript/tests/compiler/for.ts -t for.wast
ERROR: Entry file '/Workspace/assemblyscript/tests/compiler/for.ts' not found.
    at Object.main (/Users/peng/Workspace/assemblyscript/cli/asc.js:391:25)
    at Object.<anonymous> (/Users/peng/Workspace/assemblyscript/bin/asc:21:26)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
    at internal/main/run_main_module.js:17:11

cli/asc.js Outdated

let sourcePath = String(filename).replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
// Setting the path to relative path
sourcePath = sourcePath.indexOf(baseDir) == 0 ? sourcePath.slice(baseDir.length) : sourcePath;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This somehow feels like half a fix for paths inside baseDir only. Or does it work for other absolute paths outside baseDir properly already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this test case. Now I fixed it.

What do you think the way to change implementation of readFileNode like this?

function readFileNode(filename, baseDir) {
    try {
      let text;
      stats.readCount++;
      stats.readTime += measure(() => {
        let filePath = path.isAbsolute(filename) ? filename :  path.join(baseDir, filename);
        text = fs.readFileSync(filePath , { encoding: "utf8" });
      });
      return text;
    } catch (e) {
      return null;
    }
  }

Signed-off-by: Liao.Peng <pengliao@live.cn>
@dcodeIO dcodeIO merged commit 3434b1b into AssemblyScript:master Jul 17, 2019
@dcodeIO
Copy link
Member

dcodeIO commented Jul 17, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants