Skip to content

Commit

Permalink
fix: project first dependency resolve support lerna with yarn workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Mar 4, 2020
1 parent 7cbcc63 commit e4e8d47
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/preset-built-in/src/plugins/features/alias.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IApi } from '@umijs/types';
import { dirname, join } from 'path';
import { winPath } from '@umijs/utils';
import { winPath, resolve } from '@umijs/utils';

export default (api: IApi) => {
const { paths, pkg, cwd } = api;
Expand Down Expand Up @@ -30,7 +30,15 @@ export default (api: IApi) => {
(pkg.dependencies && pkg.dependencies[library]) ||
(pkg.devDependencies && pkg.devDependencies[library])
) {
return winPath(join(cwd, 'node_modules', library));
return winPath(
dirname(
// 通过 resolve 往上找,可支持 lerna 仓库
// lerna 仓库如果用 yarn workspace 的依赖不一定在 node_modules,可能被提到根目录,并且没有 link
resolve.sync(`${library}/package.json`, {
basedir: cwd,
}),
),
);
}
return null;
}
Expand Down

0 comments on commit e4e8d47

Please sign in to comment.