Skip to content

Commit

Permalink
fix: basic api missing types from dumi (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Nov 25, 2022
1 parent 95c90e6 commit 417540d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"@@/*": [".dumi/tmp/*"],
"dumi": ["."],
"dumi/theme/*": ["src/client/theme-default/*"]
},
"types": ["../../.dumi/tmp/typings"]
}
}
}
14 changes: 14 additions & 0 deletions src/client/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare module '*.less' {
const classes: CSSModuleClasses;
export default classes;
}

declare module '*.svg' {
import * as React from 'react';
export const ReactComponent: React.FunctionComponent<
React.SVGProps<SVGSVGElement> & { title?: string }
>;

const src: string;
export default src;
}
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export const CLIENT_DEPS = [
'react-copy-to-clipboard',
'react-intl',
];

export const USELESS_TMP_FILES = ['tsconfig.json', 'typings.d.ts'];
21 changes: 19 additions & 2 deletions src/features/derivative.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { CLIENT_DEPS, LOCAL_DUMI_DIR, LOCAL_PAGES_DIR } from '@/constants';
import {
CLIENT_DEPS,
LOCAL_DUMI_DIR,
LOCAL_PAGES_DIR,
USELESS_TMP_FILES,
} from '@/constants';
import type { IApi } from '@/types';
import { parseModule } from '@umijs/bundler-utils';
import assert from 'assert';
import fs from 'fs';
import path from 'path';
import { deepmerge, glob, logger, winPath } from 'umi/plugin-utils';
import { deepmerge, fsExtra, glob, logger, winPath } from 'umi/plugin-utils';

/**
* exclude pre-compiling modules in mfsu mode
Expand Down Expand Up @@ -166,6 +171,18 @@ export default (api: IApi) => {
},
});

// remove tsconfig.json, because the paths in tsconfig.json cannot be resolved in dumi project
api.register({
key: 'onGenerateFiles',
// make sure after umi generate files
stage: Infinity,
fn() {
USELESS_TMP_FILES.forEach((file) => {
fsExtra.rmSync(path.join(api.paths.absTmpPath, file), { force: true });
});
},
});

// built-in other umi plugins (such as analytics)
api.registerPlugins([require.resolve('../../compiled/@umijs/plugins')]);
};
2 changes: 1 addition & 1 deletion src/features/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default (api: IApi) => {
api.writeTmpFile({
noPluginDir: true,
path: 'dumi/exports.ts',
content: `export * from '../exports.ts';
content: `export * from '../exports';
export * from '${winPath(require.resolve('../client/theme-api'))}';`,
});
});
Expand Down

0 comments on commit 417540d

Please sign in to comment.