Skip to content

Commit

Permalink
bugfix 路径查找中拉掉 root 查找
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Sep 2, 2015
1 parent 7918ac7 commit 2a08670
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ function tryBaseUrlLookUp(info, file, opts) {
}
}

// 基于 BaseUrl 查找
function tryRootLookUp(info, file, opts) {
return findResource(info.rest, root, opts.extList);
}

// 在 Paths 中查找
function tryPathsLookUp(info, file, opts) {
var id = info.rest;
Expand All @@ -97,14 +102,14 @@ function tryPathsLookUp(info, file, opts) {

function tryFolderLookUp(info, file, opts) {
var id = info.rest;

if (id === '.' || opts.packages) {
// 真麻烦,还得去查找当前目录是不是 match 一个 packages。
// 如果是,得找到 main 的设置。
var folderName = id[0] === '/' ? path.join(baseUrl, id) : path.join(file.dirname, id);

var pkg = findPkgByFolder(folderName, opts.packages);

if (pkg) {
return findResource(pkg.main || 'main', pkg.folder, opts.extList);
}
Expand All @@ -114,7 +119,7 @@ function tryFolderLookUp(info, file, opts) {
// 在 Pacakges 里面查找
function tryPackagesLookUp(info, file, opts) {
var id = info.rest;

if (/^([^\/]+)(?:\/(.*))?$/.test(id)) {
var prefix = RegExp.$1;
var subpath = RegExp.$2;
Expand Down Expand Up @@ -146,11 +151,12 @@ module.exports = function(info, file, silent) {
tryPathsLookUp,
tryPackagesLookUp,
tryFolderLookUp,
tryBaseUrlLookUp
tryBaseUrlLookUp,
tryRootLookUp
].every(function(finder) {

var ret = finder(info, file, opts);

if (ret && ret.file) {
info.id = ret.file.getId();
info.file = ret.file;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fis3-hook-commonjs",
"version": "0.1.0",
"version": "0.1.1",
"description": "fis3 commonJs module",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 2a08670

Please sign in to comment.