Skip to content

Commit

Permalink
fix(dts-plugin): auto inject compiler output path to avoid duplicate …
Browse files Browse the repository at this point in the history
…zip file (#3401)
  • Loading branch information
2heal1 authored Dec 26, 2024
1 parent a1d46b7 commit c90bba2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-turkeys-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/dts-plugin': patch
---

fix(dts-plugin): auto inject compiler output path to avoid duplicate zip file
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('hostPlugin', () => {
implementation: '',
generateAPITypes: false,
context: process.cwd(),
outputDir: '',
abortOnError: true,
extractRemoteTypes: false,
extractThirdParty: false,
Expand Down Expand Up @@ -141,6 +142,7 @@ describe('hostPlugin', () => {
generateAPITypes: false,
implementation: '',
context: process.cwd(),
outputDir: '',
abortOnError: true,
extractRemoteTypes: false,
extractThirdParty: false,
Expand Down
4 changes: 3 additions & 1 deletion packages/dts-plugin/src/core/configurations/remotePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const defaultOptions = {
abortOnError: true,
extractRemoteTypes: false,
extractThirdParty: false,
outputDir: '',
} satisfies Partial<RemoteOptions>;

function getEffectiveRootDir(
Expand Down Expand Up @@ -59,6 +60,7 @@ const readTsConfig = (
compiledTypesFolder,
context,
additionalFilesToCompile,
outputDir,
}: Required<RemoteOptions>,
mapComponentsToExpose: Record<string, string>,
): TsConfigJson => {
Expand All @@ -84,7 +86,7 @@ const readTsConfig = (

const outDir = resolve(
context,
configContent.options.outDir || 'dist',
outputDir || configContent.options.outDir || 'dist',
typesFolder,
compiledTypesFolder,
);
Expand Down
1 change: 1 addition & 0 deletions packages/dts-plugin/src/core/interfaces/RemoteOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface RemoteOptions extends moduleFederationPlugin.DtsRemoteOptions {
context?: string;
implementation?: string;
hostRemoteTypesFolder?: string;
outputDir?: string;
}
4 changes: 4 additions & 0 deletions packages/dts-plugin/src/plugins/DevPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export class DevPlugin implements WebpackPluginInstance {
? undefined
: normalizedDtsOptions.implementation,
context: compiler.context,
outputDir: path.relative(
compiler.context,
compiler.outputPath || compiler.options.output.path,
),
moduleFederationConfig: {
...this._options,
},
Expand Down
14 changes: 11 additions & 3 deletions packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
generateTypes,
generateTypesInChildProcess,
retrieveTypesAssetsInfo,
type DTSManagerOptions,
} from '../core/index';
import path from 'path';

Expand Down Expand Up @@ -42,10 +43,14 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
return;
}

const finalOptions = {
const finalOptions: DTSManagerOptions = {
remote: {
implementation: dtsOptions.implementation,
context: compiler.context,
outputDir: path.relative(
compiler.context,
compiler.outputPath || compiler.options.output.path,
),
moduleFederationConfig: pluginOptions,
...normalizedGenerateTypes,
},
Expand Down Expand Up @@ -74,8 +79,11 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
const generateTypesFn = getGenerateTypesFn();
let compiledOnce = false;

const emitTypesFiles = async () => {
const emitTypesFilesDev = async () => {
try {
if (!isDev()) {
return;
}
const { zipTypesPath, apiTypesPath, zipName, apiFileName } =
retrieveTypesAssetsInfo(finalOptions.remote);

Expand Down Expand Up @@ -166,7 +174,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
}

if (compiledOnce) {
emitTypesFiles();
emitTypesFilesDev();
return;
}

Expand Down

0 comments on commit c90bba2

Please sign in to comment.