Skip to content

Commit

Permalink
fix: adjust stats fetch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
2heal1 committed Jan 21, 2025
1 parent b1f0153 commit ef69e62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .changeset/clever-pianos-cough.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@module-federation/dts-plugin': patch
---

perf(dts-plugin): only block build process in prod env when generating types
fix(dts-plugin): only block build process in prod env when generating types
4 changes: 2 additions & 2 deletions packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
const apiAssetName = path.join(zipPrefix, apiFileName);
if (zipTypesPath && !compilation.getAsset(zipAssetName)) {
compilation.emitAsset(
path.join(zipPrefix, zipName),
zipAssetName,
new compiler.webpack.sources.RawSource(
fs.readFileSync(zipTypesPath),
false,
Expand All @@ -130,7 +130,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {

if (apiTypesPath && !compilation.getAsset(apiAssetName)) {
compilation.emitAsset(
path.join(zipPrefix, apiFileName),
apiAssetName,
new compiler.webpack.sources.RawSource(
fs.readFileSync(apiTypesPath),
false,
Expand Down
16 changes: 14 additions & 2 deletions packages/manifest/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Chunk, Compilation, StatsCompilation, StatsModule } from 'webpack';
import path from 'path';
import fs from 'fs';
import {
StatsAssets,
moduleFederationPlugin,
Expand Down Expand Up @@ -307,7 +308,18 @@ export function getTypesMetaInfo(
const zip = path.join(zipPrefix, zipName);
const api = path.join(zipPrefix, apiFileName);

if (!zip || !compilation.getAsset(zip)) {
const getTargetFile = (filename: string) => {
try {
if (!isDev()) {
return Boolean(compilation.getAsset(path.join(zipPrefix, filename)));
}
return Boolean(fs.readFileSync(filename));
} catch (e) {
return false;
}
};

if (!zip || !getTargetFile(zipName)) {
return {
path: '',
name: '',
Expand All @@ -316,7 +328,7 @@ export function getTypesMetaInfo(
};
}

if (!api || !compilation.getAsset(api)) {
if (!api || !getTargetFile(apiFileName)) {
return {
path: '',
name: '',
Expand Down

0 comments on commit ef69e62

Please sign in to comment.