Skip to content

Commit 8e172c8

Browse files
authored
feat(dts-plugin): allow users to specify a cwd to generate the types (#3339)
1 parent fa7a0bd commit 8e172c8

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

.changeset/real-otters-explode.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
'@module-federation/sdk': patch
4+
---
5+
6+
add `cwd` property to generate types

apps/website-new/docs/en/configure/dts.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface PluginDtsOptions {
1414
generateTypes?: boolean | DtsRemoteOptions;
1515
consumeTypes?: boolean | DtsHostOptions;
1616
tsConfigPath?: string;
17+
cwd?: string;
1718
}
1819
```
1920

@@ -215,3 +216,11 @@ Before loading type files, whether to delete the previously loaded `typesFolder`
215216
- Default value: `path.join(process.cwd(),'./tsconfig.json')`
216217

217218
tsconfig configuration file path
219+
220+
### cwd
221+
222+
- Type: `string`
223+
- Required: No
224+
- Default value: `undefined`
225+
226+
The working directory to run the compiler

packages/dts-plugin/src/core/lib/typeScriptCompiler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,12 @@ export const compileTs = async (
180180
const execPromise = util.promisify(exec);
181181
const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
182182
try {
183-
await execPromise(cmd);
183+
await execPromise(cmd, {
184+
cwd:
185+
typeof remoteOptions.moduleFederationConfig.dts !== 'boolean'
186+
? (remoteOptions.moduleFederationConfig.dts?.cwd ?? undefined)
187+
: undefined,
188+
});
184189
} catch (err) {
185190
throw new Error(
186191
getShortErrorMsg(TYPE_001, typeDescMap, {

packages/sdk/src/types/plugins/ModuleFederationPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export interface PluginDtsOptions {
166166
tsConfigPath?: string;
167167
extraOptions?: Record<string, any>;
168168
implementation?: string;
169+
cwd?: string;
169170
}
170171

171172
export type AsyncBoundaryOptions = {

0 commit comments

Comments
 (0)