-
Notifications
You must be signed in to change notification settings - Fork 24
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
Limit use of require("path") to resolve Windows compatibility issues #7
Conversation
Currently there is a bug in Windows where all of the expanded aliases will have paths with backslashes in it. This is due to the use of path.join to create the alias, which uses the current platform's path separator. Since Glob is returning paths with forward slash - even on Windows - the solution is to put `pattern.expose + '/'` in front of the file when pattern.expose is present, or just using the file unhindered as the alias if pattern.expose is absent.
Currently when you create aliases, the aliases point to the full file path (ie: `c:\\dev\\workspace\\index.js`). However, this can result in the full file path ending up in the merged file in browserify in some circumstances (rendr has this problem). This simply changes the absolute path to a relative path based on the cwd option.
There are no more references to path, so we no longer need to require it.
@roncli I think we're working at cross-purposes here. The point of |
The statement about the purpose of I installed mocha and ran the existing test cases. Two already fail under Windows:
What's happening is that the alias is getting its path localized to its platform. As for the filePath, on both Linux and Windows it can expose the full path of a require file. This to me seems to be a security risk, so I made this optional. If the developer puts a relative path in FYI, there were a couple of bugs with my implementation that I found in running the tests that I didn't have in the project I'm using this in, so I'm going to test this a bit more thoroughly and redo this PR. I will also update the tests and add one specifically for the absolute |
@roncli thanks! I've re-opened this, so just push the updates to the same branch and let me know when ready. |
@joeybaker I had a bit of a struggle with gulp. For much of the day, it was running the lint job but not the test job, even on commits I had passing before. I think there was a transient error in one of gulp's dependencies because it started working again this evening after I wiped node_modules and reinstalled. I tend to do that frequently while developing. :) Anyway, good news is I got all 6 of the original tests and my one new test to pass on both Windows and on travis. roncli/remapify@14151dd is the latest commit, let me know if you have any further concerns, and thanks for your response! |
I have also been having issues on Windows. @joeybaker I have tried using your branch, but I still get the following: { [Error: module "C:/xampp/htdocs/web/js/router.js" not found from "C:\\xampp\\htdocs\\web\\js\\app.js"],
filename: 'C:/xampp/htdocs/web/js/router.js',
parent: 'C:\\xampp\\htdocs\\web\\js\\app.js'
} Is this the same issue or should I open a new bug? |
@danielgutenberg Yes, this is the same issue. It is complaining that your app.js is requiring "C:/xampp/htdocs/web/js/router.js", which is 1) an absolute path, and 2) using forward slashes. |
Thanks guys. I'll review and merge soon! |
@@ -79,7 +79,7 @@ describe('remapify', function(){ | |||
, 'path/nested/a.js' | |||
, 'path/nested/c.js' | |||
) | |||
expandedAliases['path/a.js'].should.equal(path.resolve(__dirname, './fixtures/target/a.js')) | |||
expandedAliases['path/a.js'].should.equal('./test/fixtures/target/a.js') |
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'm not sure this is a good idea? I agree this causes the tests to pass, but Browserify, unless I'm mistaken, needs absolute paths, Therefore, we should be testing for those, no?
Perhaps what we need here is path.join(__dirname, 'fixtures', 'target', 'a.js')
?
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 am using Browserify for building a rendr site on both Mac and Windows, and in my experience it did not need the absolute paths. Prior to the need for Remapify, it was using relative paths then as well.
hi @roncli, I tested the code from your fork, and I still have an issue when resolving the dependancies.
Note that one path has |
@tleunen I looked into this, and it seems to be an issue with benbria/aliasify. When it replaces a A workaround would be to use a relative path in your |
I worked out the problem and have submitted benbria/aliasify#13 to deal with absolute paths on Windows. |
Hello, and thank you for the fix. Will it be made public soon? |
Hopefully! :) Ultimately, it's up to the developer. Theoretically, this change could be applied. Absolute path functionality in Windows does not work today, and this patch does not fix it, as the problem resides in aliasify, a child module. I have PR benbria/aliasify#13 out with aliasify to fix the issue, and hopefully @jwalton will be able to look at it soon. However, relative path functionality - the functionality that I would expect to be used in the majority of use cases - in Windows is resolved by this patch. I am developing a rendr website on Windows and have been submitting a number of PR's with the goal of getting rendr working with the latest modules, so I, too, am looking forward to having these integrated! |
I'm currently reviewing, sorry it's taken so long. Should be soon. |
Okay, after playing with this some. I think the problem might actually be related to configuration vagueness/conflicts. Stay tuned… |
This might/should be fixed by #8. Can you try version 1.0.0. Can you try it and confirm? |
I updated to remapify 1.0.0 and now I'm getting an error in my |
@cnelson87 can you show me your remapify config? |
Sorry for the delay, been busy with work. Here's an example of how I'm using grunt-browserify and remapify: https://github.com/cnelson87/grunt-browserify-214-test/blob/master/grunt_tasks/browserify.js |
@cnelson87 I see. Can you try something for me? Instead of passing relative paths, pass absolute ones in {
cwd: path.join(__dirname, './src/scripts/config'),
src: '**/*.*',
expose: 'config'
}, Let me know if that works. |
Note that I have my grunt tasks in a sub folder 'grunt_tasks' and load them via the 'load-grunt-tasks' plugin. The sub folder is included in '__dirname' and I had to strip it out before joining paths. |
@cnelson87 and just to confirm, this doesn't work either? {
cwd: path.join(__dirname, '../src/scripts/config'),
src: '**/*.*',
expose: 'config'
}, |
That's much simpler than what I was doing, but no, sorry, still the same error. |
Fair enough. I'll take a deeper look when I can spin up a windows VM. |
To clarify, I get the error on both Mac and Win. |
Good to know! Thanks! Can you create a small repo to exactly demo your setup? That will make debugging much easier. |
https://github.com/cnelson87/grunt-browserify-214-test |
Pull Request has been updated for 1.0.0. |
@cnelson87 @roncli Hey guys, I finally got a windows VM up and ran the tests. Ya'll were of course, right, the tests didn't pass on windows. However, the reason was that the tests were assuming a path separator of I'm going to close this PR. |
Sounds good. I will try some time this week with 1.1.1, and if I still have an issue I'll let you know. |
I wanted to give you an update. I am now using rendr 0.5.1 with remapify 1.3.0. I was able to successfully get this to run in Windows by essentially "throwing out" all of the keys that I am not going to use. For instance, remapify's expandedAliases includes Here's the full grunt setup for browserify that I am now using successfully:
There may be a better way for me to do this, but this is a way that is working for me 100% right now. Thank you again for your work on this project. :) |
Interesting. Thanks @roncli |
This pull request is to eliminate the use of
require("path")
in order to resolve issues with Windows.First, the alias has been updated to not use path.join. Using path.join changed the path names from using forward slashes to backslashes on Windows, but kept them as forward slashes on Linux. Now, the alias will consistently use forward slashes.
Second, the file path has been updated to not resolve to an absolute path. Use of absolute paths was exposing the local file system's absolute path in the client source in browserify (rendr, for instance, would expose the location of the
app/router
file in the client-side mergedAssets.js file). While this can work, it is not ideal to expose the absolute path. Now, the user can choose whether to use a relative or absolute path based on thecwd
option.