Skip to content

Commit

Permalink
fix(@umijs/plugins): model files could be collected more then one time
Browse files Browse the repository at this point in the history
  • Loading branch information
刘文壮 committed Jul 4, 2024
1 parent c0da93f commit a2c84a3
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 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,28 +126,30 @@ export class ModelUtils {
getAllModels(opts: { sort?: object; extraModels: string[] }) {
// reset count
this.count = 1;
const models = [
...this.getModels({
base: join(this.api.paths.absSrcPath, 'models'),
pattern: '**/*.{ts,tsx,js,jsx}',
}),
...this.getModels({
base: join(this.api.paths.absPagesPath),
pattern: '**/models/**/*.{ts,tsx,js,jsx}',
}),
...this.getModels({
base: join(this.api.paths.absPagesPath),
pattern: '**/model.{ts,tsx,js,jsx}',
}),
...opts.extraModels,
].map((file: string) => {
return new Model(
file,
this.api.paths.absSrcPath,
opts.sort,
this.count++,
);
});
const models = lodash
.uniq([
...this.getModels({
base: join(this.api.paths.absSrcPath, 'models'),
pattern: '**/*.{ts,tsx,js,jsx}',
}),
...this.getModels({
base: join(this.api.paths.absPagesPath),
pattern: '**/models/**/*.{ts,tsx,js,jsx}',
}),
...this.getModels({
base: join(this.api.paths.absPagesPath),
pattern: '**/model.{ts,tsx,js,jsx}',
}),
...opts.extraModels,
])
.map((file: string) => {
return new Model(
file,
this.api.paths.absSrcPath,
opts.sort,
this.count++,
);
});
// check duplicate
const namespaces = models.map((model) => model.namespace);
if (new Set(namespaces).size !== namespaces.length) {
Expand Down

0 comments on commit a2c84a3

Please sign in to comment.