diff --git a/src/resolve-dependency.js b/src/resolve-dependency.js index ac43ddc9..9b50c0dc 100644 --- a/src/resolve-dependency.js +++ b/src/resolve-dependency.js @@ -14,10 +14,11 @@ module.exports = function resolveDependency (specifier, parent, job) { }; function resolvePath (path, parent, job) { - return resolveFile(path, job) || resolveDir(path, parent, job) || notFound(path, parent); + return resolveFile(path, parent, job) || resolveDir(path, parent, job) || notFound(path, parent); } -function resolveFile (path, job) { +function resolveFile (path, parent, job) { + path = job.realpath(path, parent); if (path.endsWith('/')) return; if (job.isFile(path)) return path; if (job.ts && path.startsWith(job.base) && path.substr(job.base.length).indexOf(sep + 'node_modules' + sep) === -1 && job.isFile(path + '.ts')) return path + '.ts'; @@ -37,14 +38,14 @@ function resolveDir (path, parent, job) { } catch (e) {} if (pjson && typeof pjson.main === 'string') { - const resolved = resolveFile(resolve(path, pjson.main), job) || resolveFile(resolve(path, pjson.main, 'index'), job); + const resolved = resolveFile(resolve(path, pjson.main), parent, job) || resolveFile(resolve(path, pjson.main, 'index'), parent, job); if (resolved) { job.emitFile(realPjsonPath, 'resolve', parent); return resolved; } } } - return resolveFile(resolve(path, 'index'), job); + return resolveFile(resolve(path, 'index'), parent, job); } function notFound (specifier, parent) { @@ -65,7 +66,7 @@ function resolvePackage (name, parent, job) { const nodeModulesDir = packageParent + '/node_modules'; const stat = job.stat(nodeModulesDir); if (!stat || !stat.isDirectory()) continue; - const resolved = resolveFile(nodeModulesDir + '/' + name, job) || resolveDir(nodeModulesDir + '/' + name, parent, job); + const resolved = resolveFile(nodeModulesDir + '/' + name, parent, job) || resolveDir(nodeModulesDir + '/' + name, parent, job); if (resolved) return resolved; } notFound(name, parent); diff --git a/test/unit/yarn-workspaces/output.js b/test/unit/yarn-workspaces/output.js index 08e5986c..2714b4e2 100644 --- a/test/unit/yarn-workspaces/output.js +++ b/test/unit/yarn-workspaces/output.js @@ -2,6 +2,6 @@ "test/unit/yarn-workspaces/input.js", "test/unit/yarn-workspaces/node_modules/x", "test/unit/yarn-workspaces/packages/x/dep.js", - "test/unit/yarn-workspaces/packages/x/main.js", + "test/unit/yarn-workspaces/packages/x/main.ts", "test/unit/yarn-workspaces/packages/x/package.json" ] \ No newline at end of file diff --git a/test/unit/yarn-workspaces/packages/x/main.js b/test/unit/yarn-workspaces/packages/x/main.ts similarity index 100% rename from test/unit/yarn-workspaces/packages/x/main.js rename to test/unit/yarn-workspaces/packages/x/main.ts diff --git a/test/unit/yarn-workspaces/packages/x/package.json b/test/unit/yarn-workspaces/packages/x/package.json index 2af9e0d1..528005c9 100644 --- a/test/unit/yarn-workspaces/packages/x/package.json +++ b/test/unit/yarn-workspaces/packages/x/package.json @@ -1,3 +1,3 @@ { - "main": "./main.js" + "main": "./main" }