Skip to content

Commit

Permalink
fix(manifest): stats should add prefetchInterface if enable dataPrefe…
Browse files Browse the repository at this point in the history
…tch (#3327)
  • Loading branch information
2heal1 authored Dec 10, 2024
1 parent ee39a50 commit 85ef6c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-ligers-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/manifest': patch
---

fix(manifest): stats should add prefetchInterface if enable dataPrefetch
15 changes: 0 additions & 15 deletions packages/manifest/src/ManifestManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from 'path';
import fs from 'fs';
import chalk from 'chalk';
import {
Expand Down Expand Up @@ -103,20 +102,6 @@ class ManifestManager {
return sum;
}, [] as ManifestRemote[]);

let prefetchInterface = false;
const prefetchFilePath = path.resolve(
compiler.options.context || process.cwd(),
`node_modules/.mf/${encodeName(stats.name)}/${MFPrefetchCommon.fileName}`,
);
const existPrefetch = fs.existsSync(prefetchFilePath);
if (existPrefetch) {
const content = fs.readFileSync(prefetchFilePath).toString();
if (content) {
prefetchInterface = true;
}
}
stats.metaData.prefetchInterface = prefetchInterface;

this._manifest = manifest;

const manifestFileName = this.fileName;
Expand Down
19 changes: 18 additions & 1 deletion packages/manifest/src/StatsManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable max-lines-per-function */
/* eslint-disable @typescript-eslint/member-ordering */
/* eslint-disable max-depth */

import fs from 'fs';
import path from 'path';
import {
StatsRemote,
StatsBuildInfo,
Expand All @@ -11,6 +12,8 @@ import {
StatsAssets,
moduleFederationPlugin,
RemoteEntryType,
encodeName,
MFPrefetchCommon,
} from '@module-federation/sdk';
import {
Compilation,
Expand Down Expand Up @@ -136,6 +139,20 @@ class StatsManager {
pluginVersion: this._pluginVersion,
};

let prefetchInterface = false;
const prefetchFilePath = path.resolve(
compiler.options.context || process.cwd(),
`node_modules/.mf/${encodeName(name!)}/${MFPrefetchCommon.fileName}`,
);
const existPrefetch = fs.existsSync(prefetchFilePath);
if (existPrefetch) {
const content = fs.readFileSync(prefetchFilePath).toString();
if (content) {
prefetchInterface = true;
}
}
metaData.prefetchInterface = prefetchInterface;

if (this._options.getPublicPath) {
if ('publicPath' in metaData) {
delete metaData.publicPath;
Expand Down

0 comments on commit 85ef6c4

Please sign in to comment.