Skip to content

Commit ee08e7c

Browse files
committed
[Fix] make check whether subpath changed work on Windows
1 parent 2dedde3 commit ee08e7c

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/async.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ module.exports = function resolve(x, options, callback) {
303303
});
304304
}
305305

306-
function processDirs(cb, dirs, subpath) {
306+
function processDirs(cb, dirs, subpath, endsWithSubpath) {
307307
if (dirs.length === 0) return cb(null, undefined);
308308
var dir = dirs[0];
309309

310-
if (env.length > 0 && dir.substring(dir.length - subpath.length) === subpath) {
310+
if (env.length > 0 && endsWithSubpath(dir)) {
311311
var pkgDir = dir.substring(0, dir.length - subpath.length);
312312
loadManifestInDir(pkgDir, onmanifestWithExports);
313313
} else {
@@ -337,21 +337,21 @@ module.exports = function resolve(x, options, callback) {
337337

338338
function isdir(err, isdir) {
339339
if (err) return cb(err);
340-
if (!isdir) return processDirs(cb, dirs.slice(1), subpath);
340+
if (!isdir) return processDirs(cb, dirs.slice(1), subpath, endsWithSubpath);
341341
loadAsFile(dir, opts.package, onfile);
342342
}
343343

344344
function onfile(err, m, pkg) {
345345
if (err) return cb(err);
346346
if (m) return cb(null, m, pkg);
347-
if (!tryLoadAsDirectory) return processDirs(cb, dirs.slice(1), subpath);
347+
if (!tryLoadAsDirectory) return processDirs(cb, dirs.slice(1), subpath, endsWithSubpath);
348348
loadAsDirectory(dir, opts.package, ondir);
349349
}
350350

351351
function ondir(err, n, pkg) {
352352
if (err) return cb(err);
353353
if (n) return cb(null, n, pkg);
354-
processDirs(cb, dirs.slice(1), subpath);
354+
processDirs(cb, dirs.slice(1), subpath, endsWithSubpath);
355355
}
356356
}
357357

@@ -369,10 +369,16 @@ module.exports = function resolve(x, options, callback) {
369369
}
370370

371371
var thunk = function () { return getPackageCandidates(x, start, opts); };
372+
var endsWithSubpath = function (dir) {
373+
var endOfDir = dir.substring(dir.length - subpath.length);
374+
375+
return endOfDir === subpath || endOfDir.replace(/\\/g, '/') === subpath;
376+
}
372377
processDirs(
373378
cb,
374379
packageIterator ? packageIterator(x, start, thunk, opts) : thunk(),
375-
subpath
380+
subpath,
381+
endsWithSubpath
376382
);
377383
}
378384
};

lib/sync.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,18 @@ module.exports = function resolveSync(x, options) {
219219
}
220220
var subpathLength = subpath.length;
221221

222+
var endsWithSubpath = function (dir) {
223+
var endOfDir = dir.substring(dir.length - subpathLength);
224+
225+
return endOfDir === subpath || endOfDir.replace(/\\/g, '/') === subpath;
226+
};
227+
222228
for (var i = 0; i < dirs.length; i++) {
223229
var dir = dirs[i];
224230

225231
var pkg;
226232
var tryLoadAsDirectory = true;
227-
if (dir.substring(dir.length - subpathLength) === subpath) {
233+
if (endsWithSubpath(dir)) {
228234
var pkgDir = dir.substring(0, dir.length - subpathLength);
229235
if ((pkg = loadManifestInDir(pkgDir)) && pkg.exports) {
230236
var resolvedExport = resolveExports(pkgDir, parent, subpath, pkg.exports, env);

0 commit comments

Comments
 (0)