-
-
Notifications
You must be signed in to change notification settings - Fork 670
Add node module resolution by default and use --path for custom package locations #594
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
Conversation
Currently
Now it looks for an Also not sure why it's failing since the log on Travis says it passed. I'm going to add my tests from another branch soon. |
can run tests with `npm run test:packages`
Now `packages/d` will output it's trace of resolving files.
@dcodeIO @MaxGraey I've now got tests for testing the new argument and added two new commands: You can also run the tests with |
I don't think so using as-pect or any other third-party testing library is good idea |
cli/asc.js
Outdated
In this case the library wasn't found so we check paths | ||
*/ | ||
if (sourceText == null && args.path) { | ||
writeStdout(`Looking for ${sourcePath}\n`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should go to stderr - stdout might be module output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay will change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that should also be the case for traceResolution
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I think that the debugging might help now to implement the feature, but I'm skeptical that it deserves actual compiler options that nobody will ever use, unless debugging the feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well typescript has the option and I did need a way to debug it. I'm not attached though. tsc
also has --all
which is where you'll find these types of commands not just --help
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, hiding these behind an -all
flag sounds good, yeah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add that now or do a future PR?
That's because dist files have been touched (see). |
@MaxGraey Why? I understand your hesitation on adding this dependency, but from personal experience |
Yeah I figured that out from the logs and revert them. |
I agree with Max that adding additional dependencies (this isn't about as-pect) just to test this feature is overkill. The list of dependencies is intentionally minimal so package size doesn't tank unexpectedly or builds get broken by something external. Would prefer to keep it that way. |
@willemneal |
Well it's only a dependency of the subpackage and so it will only be installed for testing. I understand your hesitation, just wish there was a better way to add tests. I suppose I could use WASI, but node doesn't support it yet and then you'd depend on another runtime. My last point I want to make again is that if I'll go ahead and remove the lerna dependency as it's not really needed now that I can use my node script to build and run the tests. And if you really insist I'll remove |
No |
LGTM with the remaining comments addressed :) |
Hmm, strange, now seeing this error during
|
Weird. It still passes on my end and passed Travis. |
With
Any idea? |
I'm assume this is Windows? I'm not sure what |
XY is just a substitute for my local path where the assemblyscript repo is living. And yes, Windows. |
Somewhere, the path to a file becomes |
Ah okay, well try it again. I just moved the printing of where it's looking, so that we can get a better idea of what's going on. E.g. now it prints this Looking for ~lib/c imported by /Users/willem/Research/wasm/assemblyscript/tests/packages/packages/d
in node_modules/assembly/c
Found at node_modules/c/assembly/index.ts |
Hrmm, well I think it's because of adding SEP. Perhaps we should just stick with |
I think the use of SEP is fine, but it's currently also used for internal paths it seems, which are always using |
This works: let realPath = (_p) => {
if (_p.startsWith(exports.libraryPrefix)){
_p = _p.substring(exports.libraryPrefix.length);
}
let first = _p.substring(0, _p.indexOf("/"));
let second = _p.substring(_p.indexOf("/") + 1);
return path.join(_path, first, ascMain, second);
} |
Great can you commit that change? I think you have permission. I'm afk. |
nvm just got back to my computer. |
Great, thanks, working now :) |
By default uses a method similar to node-reslove to find packages. A package either has an
assembly
folder or anascMain
field in apackage.json
.If your project root is located at
/home/willem/c/hello
, then the valid paths from the following are added:/home/willem/c/hello/node_modules
/home/willem/c/node_modules
/home/willem/node_modules
/home/node_modules
/node_modules
--path relative/path
adds a path to the list of default paths.The big difference between this method and node is that because node dynamically loads the modules, imports start their search from the location of the file being loaded. However, currently a parsed files doesn't track the location of the file that imported it. So instead when a package is found its path is joined with
node_module
orrelative/path
which found it.For example, if a package was found at
.../hello/node_modules/b
, then..../hello/node_modules/b/node_modules
is added to the list of paths.