-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix external relative paths on Windows #1704
Closed
Closed
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eceac40
Fix external relative paths on Windows
Shingyx 775e5b4
Replace all \ with / in relative paths for OS-independent behavior
Shingyx 1f3cb40
Add simple .gitignore
Shingyx d292dce
Formatting
Shingyx 51c7e8e
Make relativePath function a bit clearer
Shingyx 4a558e3
Merge https://github.com/browserify/browserify
Shingyx 64cb665
Merge branch 'master' into master
Shingyx a689437
Merge branch 'master' into master
Shingyx File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,8 @@ inherits(Browserify, EventEmitter); | |
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var relativePath = require('cached-path-relative') | ||
var cachedPathRelative = require('cached-path-relative'); | ||
|
||
var paths = { | ||
empty: path.join(__dirname, 'lib/_empty.js') | ||
}; | ||
|
@@ -118,14 +119,12 @@ Browserify.prototype.require = function (file, opts) { | |
var expose = opts.expose; | ||
if (file === expose && /^[\.]/.test(expose)) { | ||
expose = '/' + relativePath(basedir, expose); | ||
expose = expose.replace(/\\/g, '/'); | ||
} | ||
if (expose === undefined && this._options.exposeAll) { | ||
expose = true; | ||
} | ||
if (expose === true) { | ||
expose = '/' + relativePath(basedir, file); | ||
expose = expose.replace(/\\/g, '/'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
} | ||
|
||
if (isStream(file)) { | ||
|
@@ -739,8 +738,7 @@ Browserify.prototype._debug = function (opts) { | |
return through.obj(function (row, enc, next) { | ||
if (opts.debug) { | ||
row.sourceRoot = 'file://localhost'; | ||
row.sourceFile = relativePath(basedir, row.file) | ||
.replace(/\\/g, '/'); | ||
row.sourceFile = relativePath(basedir, row.file); | ||
} | ||
this.push(row); | ||
next(); | ||
|
@@ -805,3 +803,7 @@ function isExternalModule (file) { | |
/^[\/.]/; | ||
return !regexp.test(file); | ||
} | ||
function relativePath (from, to) { | ||
// Replace \ with / for OS-independent behavior | ||
return cachedPathRelative(from, to).replace(/\\/g, '/'); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Couldn't you use your helper function from below here instead?
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 what you mean. My changes basically extended the existing
relativePath
method to replace backslashes with forward slashes, which means that adding the.replace(/\\/g, '/')
after arelativePath
call is no longer necessary.I don't quite remember, but I think the problem was that
.replace(/\\/g, '/')
was missing after some of the otherrelativePath
calls and so the path behaviour was inconsistent on Windows.