Skip to content

Commit

Permalink
fix: use relative path in tsconfig (#12557)
Browse files Browse the repository at this point in the history
  • Loading branch information
fz6m committed Jul 12, 2024
1 parent 6feef32 commit b64c49a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/preset-umi/src/features/tmpFiles/tmpFiles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { importLazy, lodash, winPath } from '@umijs/utils';
import { existsSync, readdirSync } from 'fs';
import { basename, dirname, join } from 'path';
import { basename, dirname, join, relative } from 'path';
import { RUNTIME_TYPE_FILE_NAME } from 'umi';
import { getMarkupArgs } from '../../commands/dev/getMarkupArgs';
import { TEMPLATES_DIR } from '../../constants';
Expand All @@ -23,6 +23,8 @@ export default (api: IApi) => {
},
});

const TSCONFIG_FILE_NAME = 'tsconfig.json';

api.onGenerateFiles(async (opts) => {
const rendererPath = winPath(
await api.applyPlugins({
Expand All @@ -47,6 +49,12 @@ export default (api: IApi) => {
const isTs5 = api.appData.typescript.tsVersion?.startsWith('5');
const isTslibInstalled = !!api.appData.typescript.tslibVersion;

// https://github.com/umijs/umi/issues/12545
const tsconfigFilePath = join(api.paths.absTmpPath, TSCONFIG_FILE_NAME);
const relativeUmiDirPath = winPath(
relative(dirname(tsconfigFilePath), umiDir),
);

// x 1、basic config
// x 2、alias
// 3、language service platform
Expand Down Expand Up @@ -81,7 +89,7 @@ export default (api: IApi) => {
paths: {
'@/*': [`${srcPrefix}*`],
'@@/*': [`${umiTempDir}/*`],
[`${api.appData.umi.importSource}`]: [umiDir],
[`${api.appData.umi.importSource}`]: [relativeUmiDirPath],
[`${api.appData.umi.importSource}/typings`]: [
`${umiTempDir}/typings`,
],
Expand Down Expand Up @@ -110,7 +118,7 @@ export default (api: IApi) => {

api.writeTmpFile({
noPluginDir: true,
path: 'tsconfig.json',
path: TSCONFIG_FILE_NAME,
content: JSON.stringify(umiTsConfig, null, 2),
});

Expand Down

0 comments on commit b64c49a

Please sign in to comment.