Skip to content

Commit

Permalink
Revert "refactor: resolve project dep func"
Browse files Browse the repository at this point in the history
This reverts commit 4f6933e.
  • Loading branch information
fz6m committed Nov 23, 2023
1 parent 09f9550 commit c291e40
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 32 deletions.
8 changes: 2 additions & 6 deletions packages/plugins/src/antd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import AntdMomentWebpackPlugin from '@ant-design/moment-webpack-plugin';
import assert from 'assert';
import { dirname, join } from 'path';
import { IApi, RUNTIME_TYPE_FILE_NAME } from 'umi';
import {
deepmerge,
resolveProjectDep,
semver,
winPath,
} from 'umi/plugin-utils';
import { deepmerge, semver, winPath } from 'umi/plugin-utils';
import { TEMPLATES_DIR } from './constants';
import { resolveProjectDep } from './utils/resolveProjectDep';
import { withTmpPath } from './utils/withTmpPath';

const ANTD_TEMPLATES_DIR = join(TEMPLATES_DIR, 'antd');
Expand Down
9 changes: 2 additions & 7 deletions packages/plugins/src/layout.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { existsSync, readFileSync } from 'fs';
import { dirname, join } from 'path';
import { IApi, RUNTIME_TYPE_FILE_NAME } from 'umi';
import {
lodash,
Mustache,
NpmClientEnum,
resolveProjectDep,
winPath,
} from 'umi/plugin-utils';
import { lodash, Mustache, NpmClientEnum, winPath } from 'umi/plugin-utils';
import { resolveProjectDep } from './utils/resolveProjectDep';
import { withTmpPath } from './utils/withTmpPath';

// 获取所有 icons
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/react-query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { winPath } from '@umijs/utils';
import { dirname } from 'path';
import { IApi } from 'umi';
import { resolveProjectDep, winPath } from 'umi/plugin-utils';
import { resolveProjectDep } from './utils/resolveProjectDep';
import { withTmpPath } from './utils/withTmpPath';

export default (api: IApi) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dirname } from 'path';
import resolve from '../compiled/resolve';
import { resolve } from 'umi/plugin-utils';

export function resolveProjectDep(opts: {
pkg: any;
Expand Down
15 changes: 14 additions & 1 deletion packages/preset-umi/src/features/configPlugins/configPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { getSchemas as getViteSchemas } from '@umijs/bundler-vite/dist/schema';
import { getSchemas as getWebpackSchemas } from '@umijs/bundler-webpack/dist/schema';
import { resolveProjectDep } from '@umijs/utils';
import { resolve } from '@umijs/utils';
import { dirname, join } from 'path';
import type { IApi } from '../../types';
import { getSchemas as getExtraSchemas } from './schema';

function resolveProjectDep(opts: { pkg: any; cwd: string; dep: string }) {
if (
opts.pkg.dependencies?.[opts.dep] ||
opts.pkg.devDependencies?.[opts.dep]
) {
return dirname(
resolve.sync(`${opts.dep}/package.json`, {
basedir: opts.cwd,
}),
);
}
}

export default (api: IApi) => {
const { userConfig } = api;
const reactDOMPath =
Expand Down
3 changes: 1 addition & 2 deletions packages/preset-vue/src/features/default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { resolveProjectDep } from '@umijs/utils';
import { dirname } from 'path';
import type { IApi } from 'umi';
import { resolveVuePath } from '../utils/resolveVuePath';
import { resolveProjectDep, resolveVuePath } from '../utils/resolveProjectDep';

export default (api: IApi) => {
api.describe({
Expand Down
30 changes: 30 additions & 0 deletions packages/preset-vue/src/utils/resolveProjectDep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { dirname, join } from 'path';
import { resolve } from 'umi/plugin-utils';

export function resolveProjectDep(opts: {
pkg: any;
cwd: string;
dep: string;
}) {
if (
opts.pkg.dependencies?.[opts.dep] ||
opts.pkg.devDependencies?.[opts.dep]
) {
return dirname(
resolve.sync(`${opts.dep}/package.json`, {
basedir: opts.cwd,
}),
);
}
}

export function resolveVuePath(opts: { pkg: any; cwd: string; path: string }) {
const vuePkgPath =
resolveProjectDep({
pkg: opts.pkg,
cwd: opts.cwd,
dep: 'vue',
}) || dirname(require.resolve('vue/package.json'));

return join(vuePkgPath, opts.path);
}
13 changes: 0 additions & 13 deletions packages/preset-vue/src/utils/resolveVuePath.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export * from './npmClient';
export * from './randomColor/randomColor';
export * from './readDirFiles';
export * as register from './register';
export * from './resolveProjectDep';
export * from './setNoDeprecation';
export * from './tryPaths';
export * from './winPath';
Expand Down

0 comments on commit c291e40

Please sign in to comment.