Skip to content

Commit

Permalink
use cached-path-relative fixes from #1544
Browse files Browse the repository at this point in the history
  • Loading branch information
substack authored and substack committed Oct 22, 2016
1 parent 8f5ebbf commit 10b93d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 11 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ inherits(Browserify, EventEmitter);

var fs = require('fs');
var path = require('path');
var relativePath = require('cached-path-relative')
var paths = {
empty: path.join(__dirname, 'lib/_empty.js')
};
Expand Down Expand Up @@ -116,14 +117,14 @@ Browserify.prototype.require = function (file, opts) {
var basedir = defined(opts.basedir, self._options.basedir, process.cwd());
var expose = opts.expose;
if (file === expose && /^[\.]/.test(expose)) {
expose = '/' + path.relative(basedir, expose);
expose = '/' + relativePath(basedir, expose);
expose = expose.replace(/\\/g, '/');
}
if (expose === undefined && this._options.exposeAll) {
expose = true;
}
if (expose === true) {
expose = '/' + path.relative(basedir, file);
expose = '/' + relativePath(basedir, file);
expose = expose.replace(/\\/g, '/');
}

Expand Down Expand Up @@ -256,15 +257,15 @@ Browserify.prototype.external = function (file, opts) {
if (!opts) opts = {};
var basedir = defined(opts.basedir, process.cwd());
this._external.push(file);
this._external.push('/' + path.relative(basedir, file));
this._external.push('/' + relativePath(basedir, file));
return this;
};

Browserify.prototype.exclude = function (file, opts) {
if (!opts) opts = {};
var basedir = defined(opts.basedir, process.cwd());
this._exclude.push(file);
this._exclude.push('/' + path.relative(basedir, file));
this._exclude.push('/' + relativePath(basedir, file));
return this;
};

Expand Down Expand Up @@ -409,10 +410,10 @@ Browserify.prototype._createPipeline = function (opts) {
if (self._external.indexOf(row.file) >= 0) return next();

if (isAbsolutePath(row.id)) {
row.id = '/' + path.relative(basedir, row.file);
row.id = '/' + relativePath(basedir, row.file);
}
Object.keys(row.deps || {}).forEach(function (key) {
row.deps[key] = '/' + path.relative(basedir, row.deps[key]);
row.deps[key] = '/' + relativePath(basedir, row.deps[key]);
});
this.push(row);
next();
Expand Down Expand Up @@ -475,7 +476,7 @@ Browserify.prototype._createDeps = function (opts) {
}

if (file) {
var ex = '/' + path.relative(basedir, file);
var ex = '/' + relativePath(basedir, file);
if (self._external.indexOf(ex) >= 0) {
return cb(null, ex);
}
Expand Down Expand Up @@ -678,7 +679,7 @@ Browserify.prototype._label = function (opts) {
var prev = row.id;

if (self._external.indexOf(row.id) >= 0) return next();
if (self._external.indexOf('/' + path.relative(basedir, row.id)) >= 0) {
if (self._external.indexOf('/' + relativePath(basedir, row.id)) >= 0) {
return next();
}
if (self._external.indexOf(row.file) >= 0) return next();
Expand All @@ -695,7 +696,7 @@ Browserify.prototype._label = function (opts) {
}

var afile = path.resolve(path.dirname(row.file), key);
var rfile = '/' + path.relative(basedir, afile);
var rfile = '/' + relativePath(basedir, afile);
if (self._external.indexOf(rfile) >= 0) {
row.deps[key] = rfile;
}
Expand Down Expand Up @@ -738,7 +739,7 @@ Browserify.prototype._debug = function (opts) {
return through.obj(function (row, enc, next) {
if (opts.debug) {
row.sourceRoot = 'file://localhost';
row.sourceFile = path.relative(basedir, row.file)
row.sourceFile = relativePath(basedir, row.file)
.replace(/\\/g, '/');
}
this.push(row);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"browser-resolve": "^1.11.0",
"browserify-zlib": "~0.1.2",
"buffer": "^4.1.0",
"cached-path-relative": "^1.0.0",
"concat-stream": "~1.5.1",
"console-browserify": "^1.1.0",
"constants-browserify": "~1.0.0",
Expand All @@ -42,7 +43,7 @@
"inherits": "~2.0.1",
"insert-module-globals": "^7.0.0",
"labeled-stream-splicer": "^2.0.0",
"module-deps": "^4.0.2",
"module-deps": "^4.0.8",
"os-browserify": "~0.1.1",
"parents": "^1.0.1",
"path-browserify": "~0.0.0",
Expand Down

0 comments on commit 10b93d8

Please sign in to comment.