Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@umijs/plugins): model files may be collected more than once in some cases #12535

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/plugins/src/utils/modelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { readFileSync } from 'fs';
import { basename, dirname, extname, format, join, relative } from 'path';
import { IApi } from 'umi';
import { chalk, glob, winPath } from 'umi/plugin-utils';
import { chalk, glob, lodash, winPath } from 'umi/plugin-utils';
import { getIdentifierDeclaration } from './astUtils';

export function transformSync(content: any, opts: any) {
Expand Down Expand Up @@ -126,7 +126,7 @@ export class ModelUtils {
getAllModels(opts: { sort?: object; extraModels: string[] }) {
// reset count
this.count = 1;
const models = [
const modelFiles = [
...this.getModels({
base: join(this.api.paths.absSrcPath, 'models'),
pattern: '**/*.{ts,tsx,js,jsx}',
Expand All @@ -140,7 +140,10 @@ export class ModelUtils {
pattern: '**/model.{ts,tsx,js,jsx}',
}),
...opts.extraModels,
].map((file: string) => {
];
// remove duplicate
const modelUniqFiles = lodash.uniq(modelFiles);
const models = modelUniqFiles.map((file: string) => {
return new Model(
file,
this.api.paths.absSrcPath,
Expand Down
Loading