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

feat: allow specify tsconfig name #801

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

father 支持以下配置项。

## 环境变量

### FATHER_TSCONFIG_NAME

- 默认值:tsconfig.name

在许多项目中,供编辑器使用的 `tsconfig` 配置并不适合直接用来构建,因此可能需要提供一个 `tsconfig.build.json` 来定制构建的规则。

```bash
FATHER_TSCONFIG_NAME=tsconfig.build.json father build
```

## 公共配置

### alias
Expand Down
6 changes: 5 additions & 1 deletion src/builder/bundless/dts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export function getTsconfigPath(cwd: string) {
// ref: https://github.com/nodejs/node/issues/35889
const ts: typeof import('typescript') = require('typescript');

return ts.findConfigFile(cwd, ts.sys.fileExists);
return ts.findConfigFile(
cwd,
ts.sys.fileExists,
process.env.FATHER_TSCONFIG_NAME,
);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ beforeAll(() => {
afterAll(() => {
delete process.env.APP_ROOT;
delete process.env.FATHER_CACHE;
delete process.env.FATHER_TSCONFIG_NAME;
mockExit.mockRestore();
jest.unmock('@umijs/utils');
});
Expand Down Expand Up @@ -81,3 +82,20 @@ test('config: nested extends', async () => {
// check result
require(`${process.env.APP_ROOT}/expect`).default(fileMap);
});

test('config: custom tsconfig name', async () => {
// execute build
process.env.FATHER_TSCONFIG_NAME = 'tsconfig.build.json';
process.env.APP_ROOT = path.join(CASES_DIR, 'config-custom-tsconfig-name');
await cli.run({
args: { _: ['build'], $0: 'node' },
});

// prepare file map
const fileMap = distToMap(
path.join(CASES_DIR, 'config-custom-tsconfig-name', 'dist'),
);

// check result
require(`${process.env.APP_ROOT}/expect`).default(fileMap);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
cjs: {},
esm: {},
};
4 changes: 4 additions & 0 deletions tests/fixtures/config/config-custom-tsconfig-name/expect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default (files: Record<string, string>) => {
expect(files['cjs/index.d.ts']).not.toBeUndefined();
expect(files['cjs/exclude/index.d.ts']).toBeUndefined();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'exclude';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default async () => {
try {
await import('./exclude/index');
} catch {}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"declaration": true,
"jsx": "react"
},
"exclude": ["src/exclude/**/*"]
}
Loading