Skip to content

fix(manifest): stats should add prefetchInterface if enable dataPrefetch#3327

Merged
zhoushaw merged 1 commit intomainfrom
fix/prefetch-stats
Dec 10, 2024
Merged

fix(manifest): stats should add prefetchInterface if enable dataPrefetch#3327
zhoushaw merged 1 commit intomainfrom
fix/prefetch-stats

Conversation

@2heal1
Copy link
Copy Markdown
Member

@2heal1 2heal1 commented Dec 6, 2024

Description

the stats and manifest should both add prefetchInterface if enable dataPrefetch

Related Issue

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Dec 6, 2024

🦋 Changeset detected

Latest commit: 88dc835

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@module-federation/manifest Patch
@module-federation/enhanced Patch
@module-federation/modern-js Patch
@module-federation/rspack Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/rsbuild-plugin Patch
@module-federation/storybook-addon Patch
@module-federation/modernjsapp Patch
@module-federation/runtime Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/sdk Patch
@module-federation/runtime-tools Patch
@module-federation/managers Patch
@module-federation/dts-plugin Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/devtools Patch
@module-federation/bridge-react Patch
@module-federation/bridge-vue3 Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/retry-plugin Patch
@module-federation/data-prefetch Patch
@module-federation/error-codes Patch
@module-federation/esbuild Patch
@module-federation/utilities Patch
website-new Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link
Copy Markdown

netlify bot commented Dec 6, 2024

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 88dc835
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/675277d2f074e60008887be3
😎 Deploy Preview https://deploy-preview-3327--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Copy Markdown
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This pull request addresses an issue with the stats and manifest functionality, ensuring that the prefetchInterface property is correctly set when the dataPrefetch feature is enabled. The changes made in this pull request are as follows:

  • The ManifestManager class has been updated to set the prefetchInterface property in the stats.metaData object based on the dataPrefetch flag, rather than checking for the existence of a prefetchFilePath.
  • The StatsManager class has been updated to include a check to determine if the prefetchInterface should be included in the metaData object, based on the existence of a file at a specific path. This ensures that the prefetchInterface is correctly included in the metaData object, which is likely used for further processing or reporting.

These changes help to improve the overall functionality and reliability of the stats and manifest features, ensuring that the prefetchInterface is properly handled when the dataPrefetch feature is enabled.

File Summaries
File Summary
packages/manifest/src/ManifestManager.ts The code changes update the ManifestManager class to ensure that the prefetchInterface property is set correctly in the stats.metaData object. The changes remove the previous logic that checked for the existence of a prefetchFilePath and instead rely on the dataPrefetch flag to determine whether to set the prefetchInterface property.
packages/manifest/src/StatsManager.ts The code changes add a check to determine if the prefetchInterface should be included in the metaData object. It checks for the existence of a file at a specific path and sets the prefetchInterface flag accordingly. This ensures that the prefetchInterface is correctly included in the metaData object, which is likely used for further processing or reporting.

Copy link
Copy Markdown
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incremental Review

Comments posted: 3

Configuration

Squadron Mode: essential

Commits Reviewed

cafc5f040274ccb274f13d16910146415e8bd973...88dc8353b5c90a3fcee15f16c922982d14b85a0d

Files Reviewed
  • packages/manifest/src/StatsManager.ts
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/shaggy-ligers-teach.md

Comment on lines +142 to +153
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;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefetch interface check could be extracted into a separate method for better readability and reusability. Here's a suggested refactor:

Suggested change
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;
}
}
private checkPrefetchInterface(compiler: Compiler, name: string): boolean {
const prefetchFilePath = path.resolve(
compiler.options.context || process.cwd(),
`node_modules/.mf/${encodeName(name)}/${MFPrefetchCommon.fileName}`,
);
if (!fs.existsSync(prefetchFilePath)) {
return false;
}
const content = fs.readFileSync(prefetchFilePath).toString();
return !!content;
}

Then use it as: metaData.prefetchInterface = this.checkPrefetchInterface(compiler, name!);

Comment on lines +143 to +146
const prefetchFilePath = path.resolve(
compiler.options.context || process.cwd(),
`node_modules/.mf/${encodeName(name!)}/${MFPrefetchCommon.fileName}`,
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path resolution could be improved by using a more robust approach to handle path separators across different operating systems. Consider using path.join() instead of path.resolve():

Suggested change
const prefetchFilePath = path.resolve(
compiler.options.context || process.cwd(),
`node_modules/.mf/${encodeName(name!)}/${MFPrefetchCommon.fileName}`,
);
const prefetchFilePath = path.join(
compiler.options.context || process.cwd(),
'node_modules',
'.mf',
encodeName(name!),
MFPrefetchCommon.fileName
);

Comment on lines +149 to +152
const content = fs.readFileSync(prefetchFilePath).toString();
if (content) {
prefetchInterface = true;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file reading operation should include error handling to prevent crashes from file system issues:

Suggested change
const content = fs.readFileSync(prefetchFilePath).toString();
if (content) {
prefetchInterface = true;
}
try {
const content = fs.readFileSync(prefetchFilePath).toString();
if (content) {
prefetchInterface = true;
}
} catch (error) {
console.warn(`Failed to read prefetch interface file: ${error.message}`);
prefetchInterface = false;
}

These changes will make the code more robust and maintainable.

@zhoushaw zhoushaw merged commit 85ef6c4 into main Dec 10, 2024
@zhoushaw zhoushaw deleted the fix/prefetch-stats branch December 10, 2024 11:31
@KyrieLii KyrieLii mentioned this pull request Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants