Skip to content

Commit

Permalink
fix: bundless ignore files are still checked in doctor (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Apr 3, 2023
1 parent 376407b commit e95c969
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
64 changes: 37 additions & 27 deletions src/doctor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { glob, lodash } from '@umijs/utils';
import fs from 'fs';
import path from 'path';
import {
createConfigProviders,
IBundleConfig,
IBundlessConfig,
normalizeUserConfig as getBuildConfig,
} from '../builder/config';
import { DEFAULT_BUNDLESS_IGNORES } from '../constants';
import { getConfig as getPreBundleConfig } from '../prebundler/config';
import { IFatherBuildTypes, type IApi } from '../types';
import type { IApi } from '../types';
import sourceParser from './parser';

export type IDoctorReport = {
Expand Down Expand Up @@ -49,21 +49,23 @@ export function getSourceDirs(

export default async (api: IApi): Promise<IDoctorReport> => {
// generate configs
const [bundleConfigs, bundlessConfigs] = getBuildConfig(
api.config,
api.pkg,
).reduce<[IBundleConfig[], IBundlessConfig[]]>(
(ret, config) => {
if (config.type === IFatherBuildTypes.BUNDLE) {
ret[0].push(config);
} else {
ret[1].push(config);
}

return ret;
},
[[], []],
const configProviders = createConfigProviders(api.config, api.pkg, api.cwd);
const bundleConfigs: IBundleConfig[] = [];
const bundlessConfigs: IBundlessConfig[] = [];
const bundleProviders = [configProviders.bundle!].filter(Boolean);
const bundlessProviders = [
configProviders.bundless.esm!,
configProviders.bundless.cjs!,
].filter(Boolean);

// extract configs from configProviders
bundleProviders.forEach((provider) =>
bundleConfigs.push(...provider.configs),
);
bundlessProviders.forEach((provider) =>
bundlessConfigs.push(...provider.configs),
);

const preBundleConfig = getPreBundleConfig({
userConfig: api.config.prebundle || { deps: [] },
pkg: api.pkg,
Expand All @@ -72,17 +74,25 @@ export default async (api: IApi): Promise<IDoctorReport> => {

// collect all source files
const sourceDirs = getSourceDirs(bundleConfigs, bundlessConfigs);
const sourceFiles = sourceDirs.reduce<string[]>(
(ret, dir) =>
ret.concat(
glob.sync(`${dir}/**`, {
cwd: api.cwd,
ignore: DEFAULT_BUNDLESS_IGNORES,
nodir: true,
}),
),
[],
);
const sourceFiles = sourceDirs
.reduce<string[]>(
(ret, dir) =>
ret.concat(
glob.sync(`${dir}/**`, {
cwd: api.cwd,
ignore: DEFAULT_BUNDLESS_IGNORES,
nodir: true,
}),
),
[],
)
.filter(
(f) =>
// include all files if bundle only
!bundlessProviders.length ||
// skip custom ignore files if has bundless config
bundlessProviders.some((p) => p.getConfigForFile(f)),
);

// collect all alias & externals
// TODO: split bundle & bundless checkup, because externals not work for bundle
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/doctor/errors/.fatherrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export default {
alias: 'alias',
'@org/alias': '@org/alias',
},
ignores: ['./src/ignore.ts'],
},
};
5 changes: 5 additions & 0 deletions tests/fixtures/doctor/errors/src/ignore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// this file should be ignored in doctor
// @ts-ignore
import a from 'phantom-dependency';

console.log(a);

0 comments on commit e95c969

Please sign in to comment.