Skip to content

Commit a49135b

Browse files
committed
mod:
1. fix the bug that unable to resolve modules in subdirectory of project. 2. add bug test case 3. update change log and package version
1 parent 6398d98 commit a49135b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.0.2] - 2016-01-05
8+
### Changed
9+
- fix the bug that it's unable to resolve non-relative path modules when current working directory is subdirectory of the project root directory.
10+
711
## [1.0.1] - 2016-12-23
812
### Changed
913
- remove package `resolve` to fix the bug caused by format changing of the internal file core.json of resolve 1.1.7

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ require('./core.json').forEach(function (m) {
1414
exports.interfaceVersion = 2;
1515

1616
const Module = module.constructor;
17-
const cwd = process.cwd();
1817

1918
exports.resolve = (modulePath, sourceFile, config) => {
2019
const isRelativePath = modulePath[0] === '.';
@@ -47,6 +46,7 @@ exports.resolve = (modulePath, sourceFile, config) => {
4746
}
4847

4948
const paths = resolveLookupPaths(findPath, sourceDir);
49+
console.log('paths', paths);
5050
return findModulePath(findPath, paths);
5151
};
5252

@@ -67,7 +67,7 @@ function resolveLookupPaths(modulePath, absoluteSourceDir) {
6767
let p = curDir + path.sep + 'node_modules';
6868
paths.push(p);
6969
nextDir = path.resolve(curDir, '..');
70-
} while(nextDir !== curDir && curDir !== cwd);
70+
} while(nextDir !== curDir);
7171

7272
paths.push.apply(paths, Module.globalPaths);
7373
return paths;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"license": "MIT",
77
"name": "eslint-import-resolver-alias",
8-
"version": "1.0.1",
8+
"version": "1.0.2",
99
"description": "a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias.",
1010
"scripts": {
1111
"test": "mocha test/test.js --require test/setup.js",

test/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,16 @@ describe('resolver-alias/index.js', () => {
4949
});
5050
});
5151

52+
it('change current working directory into sub directory of project and resolve exists modules', () => {
53+
54+
process.chdir('test');
55+
delete require.cache[require.resolve('..')];
56+
const newResolver = require('..');
57+
58+
normalModulePathArr.forEach((p) => {
59+
const resolveModule = newResolver.resolve(p, sourceFile, alias);
60+
assert(resolveModule.found, `normal modulePath ${p} isn't resolved`);
61+
});
62+
});
63+
5264
});

0 commit comments

Comments
 (0)