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

Add tests for asconfig and windows #1419

Merged
merged 10 commits into from
Jul 30, 2020

Conversation

willemneal
Copy link
Contributor

@willemneal willemneal commented Jul 29, 2020

This tests checks if an entry file from another project imports from a relative path it is found on windows.

  • I've read the contributing guidelines

Willem Wyndham added 2 commits July 29, 2020 14:37
Currently adding an extra entry that depends on relative files breaks things on windows.
@willemneal
Copy link
Contributor Author

@dcodeIO As I had suspected the issue is here:

> @ test D:\a\assemblyscript\assemblyscript\tests\asconfig\entry-points\node-resolution
> node ../../index.js

[2 parse error(s)]
ERROR TS6054: File 'globalTwo.ts' not found.

 import "./globalTwo";
        ~~~~~~~~~~~~~
 in ..\assembly\globals.ts(2,8)

@dcodeIO
Copy link
Member

dcodeIO commented Jul 29, 2020

Hmm, that's a strange error, especially because Windows doesn't really care about capitalization in file names. Would rather expect *nix to fail if it was that.

cli/asc.js Outdated Show resolved Hide resolved
@willemneal
Copy link
Contributor Author

@dcodeIO could we make this an issue and just merge the patch for now?

@dcodeIO
Copy link
Member

dcodeIO commented Jul 30, 2020

I'd prefer to find out what's actually wrong there.

Tried this locally now, and what I can tell so far is that the problem happens in test:asconfig/entry-points/nested, with

  • entry = assembly/globals.ts
  • asconfigDir = C:\path\to\assemblyscript\tests\asconfig\entry-points
  • baseDir = .

and the output of optionsUtil.resolvePath(entry, asconfigDir) being C:\path\to\assemblyscript\tests\asconfig\entry-points\assembly\globals.ts, ultimately resulting in ERROR TS6054: File 'globalTwo.ts' not found..

Looks like this has something to do with absolute paths coming from the require.resolve branch in resolvePath, but might even be general for all absolute paths.

The corresponding counterpart on Linux is

  • entry = assembly/globals.ts
  • asconfigDir = ..
  • baseDir = .

with output ../assembly/globals.ts, indicating that something works differently there.

@dcodeIO
Copy link
Member

dcodeIO commented Jul 30, 2020

Diving a little deeper into it, the problem appears to be the call to readFile in getAsconfig reading a different file on Windows than on Linux, even though file=asconfig.json and baseDir=. are the same. On Windows, it loads entry-points/node-resolution/asconfig.json, while on Linux it loads entry-points/nested/asconfig.json. In particular, it appears that both commands are operating on a different process.cwd(), indicated by the directory used to look up asconfig.json.

@willemneal
Copy link
Contributor Author

How could process.cwd() be different?

@dcodeIO
Copy link
Member

dcodeIO commented Jul 30, 2020

That's the question. On Windows, it is C:\path\to\assemblyscript\tests\asconfig\entry-points while on Linux it is /path/to/assemblyscript/tests/asconfig/entry-points/nested when executing test:nested. Might have something to do with a difference on propagating cwd in npm scripts, but just guessing.

@dcodeIO
Copy link
Member

dcodeIO commented Jul 30, 2020

False alarm, I was executing a different test.

@dcodeIO
Copy link
Member

dcodeIO commented Jul 30, 2020

I see the problem now. At

assemblyscript.parse(program, sourceText, sourcePath, true);

sourcePath is ..\assembly\globals.ts on Windows, but internal

export function normalizePath(path: string): string {

where the path ultimately ends at is supposed to be dealing with Unix-like paths, in turn normalizing differently. Adding a path = path.replaceAll("\\", "/"); to normalizePath fixes the problem.

@willemneal
Copy link
Contributor Author

Great! Can you push those changes to this branch? You should have the permissions since it's a PR to this repo?

@dcodeIO
Copy link
Member

dcodeIO commented Jul 30, 2020

Yes, can push it here. Still looking for the best place to fix it at.

cli/asc.js Outdated Show resolved Hide resolved
@willemneal willemneal requested a review from dcodeIO July 30, 2020 17:27
@dcodeIO dcodeIO merged commit a73141f into AssemblyScript:master Jul 30, 2020
@dcodeIO
Copy link
Member

dcodeIO commented Jul 30, 2020

Thanks! :)

@github-actions
Copy link

🎉 This PR is included in version 0.14.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants