Skip to content

Commit

Permalink
Fix external relative paths on Windows
Browse files Browse the repository at this point in the history
Replace backslashes with forward slashes when adding relative paths for
external references.
  • Loading branch information
Shingyx authored and goto-bus-stop committed Mar 30, 2018
1 parent 9151a03 commit e09df06
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions index.js
Expand Up @@ -30,7 +30,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')
};
Expand Down Expand Up @@ -136,14 +137,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, '/');
}

if (isStream(file)) {
Expand Down Expand Up @@ -789,8 +788,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();
Expand Down Expand Up @@ -855,3 +853,7 @@ function isExternalModule (file) {
/^[\/.]/;
return !regexp.test(file);
}
function relativePath (from, to) {
// Replace \ with / for OS-independent behavior
return cachedPathRelative(from, to).replace(/\\/g, '/');
}

0 comments on commit e09df06

Please sign in to comment.