Skip to content

Commit 10b93d8

Browse files
substacksubstack
substack
authored and
substack
committed
use cached-path-relative fixes from #1544
1 parent 8f5ebbf commit 10b93d8

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ inherits(Browserify, EventEmitter);
2929

3030
var fs = require('fs');
3131
var path = require('path');
32+
var relativePath = require('cached-path-relative')
3233
var paths = {
3334
empty: path.join(__dirname, 'lib/_empty.js')
3435
};
@@ -116,14 +117,14 @@ Browserify.prototype.require = function (file, opts) {
116117
var basedir = defined(opts.basedir, self._options.basedir, process.cwd());
117118
var expose = opts.expose;
118119
if (file === expose && /^[\.]/.test(expose)) {
119-
expose = '/' + path.relative(basedir, expose);
120+
expose = '/' + relativePath(basedir, expose);
120121
expose = expose.replace(/\\/g, '/');
121122
}
122123
if (expose === undefined && this._options.exposeAll) {
123124
expose = true;
124125
}
125126
if (expose === true) {
126-
expose = '/' + path.relative(basedir, file);
127+
expose = '/' + relativePath(basedir, file);
127128
expose = expose.replace(/\\/g, '/');
128129
}
129130

@@ -256,15 +257,15 @@ Browserify.prototype.external = function (file, opts) {
256257
if (!opts) opts = {};
257258
var basedir = defined(opts.basedir, process.cwd());
258259
this._external.push(file);
259-
this._external.push('/' + path.relative(basedir, file));
260+
this._external.push('/' + relativePath(basedir, file));
260261
return this;
261262
};
262263

263264
Browserify.prototype.exclude = function (file, opts) {
264265
if (!opts) opts = {};
265266
var basedir = defined(opts.basedir, process.cwd());
266267
this._exclude.push(file);
267-
this._exclude.push('/' + path.relative(basedir, file));
268+
this._exclude.push('/' + relativePath(basedir, file));
268269
return this;
269270
};
270271

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

411412
if (isAbsolutePath(row.id)) {
412-
row.id = '/' + path.relative(basedir, row.file);
413+
row.id = '/' + relativePath(basedir, row.file);
413414
}
414415
Object.keys(row.deps || {}).forEach(function (key) {
415-
row.deps[key] = '/' + path.relative(basedir, row.deps[key]);
416+
row.deps[key] = '/' + relativePath(basedir, row.deps[key]);
416417
});
417418
this.push(row);
418419
next();
@@ -475,7 +476,7 @@ Browserify.prototype._createDeps = function (opts) {
475476
}
476477

477478
if (file) {
478-
var ex = '/' + path.relative(basedir, file);
479+
var ex = '/' + relativePath(basedir, file);
479480
if (self._external.indexOf(ex) >= 0) {
480481
return cb(null, ex);
481482
}
@@ -678,7 +679,7 @@ Browserify.prototype._label = function (opts) {
678679
var prev = row.id;
679680

680681
if (self._external.indexOf(row.id) >= 0) return next();
681-
if (self._external.indexOf('/' + path.relative(basedir, row.id)) >= 0) {
682+
if (self._external.indexOf('/' + relativePath(basedir, row.id)) >= 0) {
682683
return next();
683684
}
684685
if (self._external.indexOf(row.file) >= 0) return next();
@@ -695,7 +696,7 @@ Browserify.prototype._label = function (opts) {
695696
}
696697

697698
var afile = path.resolve(path.dirname(row.file), key);
698-
var rfile = '/' + path.relative(basedir, afile);
699+
var rfile = '/' + relativePath(basedir, afile);
699700
if (self._external.indexOf(rfile) >= 0) {
700701
row.deps[key] = rfile;
701702
}
@@ -738,7 +739,7 @@ Browserify.prototype._debug = function (opts) {
738739
return through.obj(function (row, enc, next) {
739740
if (opts.debug) {
740741
row.sourceRoot = 'file://localhost';
741-
row.sourceFile = path.relative(basedir, row.file)
742+
row.sourceFile = relativePath(basedir, row.file)
742743
.replace(/\\/g, '/');
743744
}
744745
this.push(row);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"browser-resolve": "^1.11.0",
2727
"browserify-zlib": "~0.1.2",
2828
"buffer": "^4.1.0",
29+
"cached-path-relative": "^1.0.0",
2930
"concat-stream": "~1.5.1",
3031
"console-browserify": "^1.1.0",
3132
"constants-browserify": "~1.0.0",
@@ -42,7 +43,7 @@
4243
"inherits": "~2.0.1",
4344
"insert-module-globals": "^7.0.0",
4445
"labeled-stream-splicer": "^2.0.0",
45-
"module-deps": "^4.0.2",
46+
"module-deps": "^4.0.8",
4647
"os-browserify": "~0.1.1",
4748
"parents": "^1.0.1",
4849
"path-browserify": "~0.0.0",

0 commit comments

Comments
 (0)