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
[TIMOB-16078] Implement full NodeJS require specs so we can use NPM for modules #8075
Conversation
@@ -770,7 +770,7 @@ -(id)loadCommonJSModule:(NSString*)code withSourceURL:(NSURL *)sourceURL | |||
* "/Resources/views/login/window.js" __dirname = "views/login" | |||
*/ | |||
|
|||
NSString *filename = [sourceURL lastPathComponent]; | |||
NSString *filename = [sourceURL lastPathComponent]; // FIXME This should be the absolute path to the file! |
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.
@sgtcoolguy isn't the absolute file path the following line?
NSString *js = [[NSString alloc] initWithFormat:TitaniumModuleRequireFormat, dirname, filename,code];
What do you need changed here?
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 opened a separate ticket for parity about this, and didn't really investigate it in this one. Basically __filename should be the full absolute path to the resolved file on all platforms. On iOS and Android we report just the filename (i.e "test.js"). On Windows we report the base name of the file (i.e. "test")
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.
And in this case, it's some variation of the sourceURL without the preceding scheme and maybe some of the first path segments we don't "expose" (like maybe a "Resources/" prefix)?
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.
@sgtcoolguy so now with this fixed here: #8098
do we still need to address this? @hansemannn fyi.
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 be fixed with the mentioned PR. The line is only used to expose the __filename
and that's done.
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.
k. @sgtcoolguy can you fix the merge conflicts? Thanks.
@cheekiatng Ok, rebased on master and fixed the conflict. |
@@ -1124,6 +1173,14 @@ - (id)require:(KrollContext *)kroll path:(NSString *)path | |||
return module; | |||
} | |||
} | |||
|
|||
// Need base path to work from for determining the node_modules search paths. | |||
NSString *workingPath = [oldURL relativePath]; |
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.
correct this indentation
FT passed. @sgtcoolguy Can you fix that minor indention and I'll be able to merge this. |
👏🙌👏🙌👏🙌 |
Merged this manually after massaging the commits a little to combine the iOS changes into one, Android into one, unit test as one. |
JIRA: https://jira.appcelerator.org/browse/TIMOB-16078
Description:
This adds searching node_modules directories up the directory tree for modules when doing a require without any /, ./, or ../ prefix.
Continuation of #8004 work.
TODO: What's the priority between node modules, CommonJS modules, and legacy Titanium requires? Currently this will try to load module.id/module.id.js for CommonJS first, then node_modules, then legacy/CommonJS loading.
So with this PR, the require algorithm looks like this: