Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/curly-carrots-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/dts-plugin': patch
---

Support type generation for yarn pnp enviornments
26 changes: 25 additions & 1 deletion packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ const processTypesFile = async (options: {
}
};

const getPMFromUserAgent = () => {
const userAgent = process.env['npm_config_user_agent'];
if (userAgent == null) {
return 'null';
}

const name = userAgent.split('/')[0];
return name;
};

const resolvePackageManagerExecutable = () => {
const pm = getPMFromUserAgent();

switch (pm) {
case 'yarn':
return 'yarn';
case 'npm':
case 'pnpm':
default:
return 'npx';
}
};

export const compileTs = async (
mapComponentsToExpose: Record<string, string>,
tsConfig: TsConfigJson,
Expand Down Expand Up @@ -186,7 +209,8 @@ export const compileTs = async (
: undefined,
});
const execPromise = util.promisify(exec);
const cmd = `npx ${remoteOptions.compilerInstance} --project '${tempTsConfigJsonPath}'`;
const pmExecutable = resolvePackageManagerExecutable();
const cmd = `${pmExecutable} ${remoteOptions.compilerInstance} --project '${tempTsConfigJsonPath}'`;
try {
await execPromise(cmd, {
cwd:
Expand Down