Skip to content

Commit d729167

Browse files
WooWan2heal1
andauthored
feat(dts-plugin): support type generation for yarn pnp (#4189)
Co-authored-by: Hanric <[email protected]>
1 parent a12226f commit d729167

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

.changeset/curly-carrots-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
---
4+
5+
Support type generation for yarn pnp enviornments

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,29 @@ const processTypesFile = async (options: {
158158
}
159159
};
160160

161+
const getPMFromUserAgent = () => {
162+
const userAgent = process.env['npm_config_user_agent'];
163+
if (userAgent == null) {
164+
return 'null';
165+
}
166+
167+
const name = userAgent.split('/')[0];
168+
return name;
169+
};
170+
171+
const resolvePackageManagerExecutable = () => {
172+
const pm = getPMFromUserAgent();
173+
174+
switch (pm) {
175+
case 'yarn':
176+
return 'yarn';
177+
case 'npm':
178+
case 'pnpm':
179+
default:
180+
return 'npx';
181+
}
182+
};
183+
161184
export const compileTs = async (
162185
mapComponentsToExpose: Record<string, string>,
163186
tsConfig: TsConfigJson,
@@ -186,7 +209,8 @@ export const compileTs = async (
186209
: undefined,
187210
});
188211
const execPromise = util.promisify(exec);
189-
const cmd = `npx ${remoteOptions.compilerInstance} --project '${tempTsConfigJsonPath}'`;
212+
const pmExecutable = resolvePackageManagerExecutable();
213+
const cmd = `${pmExecutable} ${remoteOptions.compilerInstance} --project '${tempTsConfigJsonPath}'`;
190214
try {
191215
await execPromise(cmd, {
192216
cwd:

0 commit comments

Comments
 (0)