Skip to content

Feat: add basehref #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
May 28, 2025
Merged

Feat: add basehref #74

merged 38 commits into from
May 28, 2025

Conversation

fiorin
Copy link
Contributor

@fiorin fiorin commented Mar 26, 2025

What's added in this PR?

Provide an implementation summary. What did you add beyond the described task? What are the additional details you'd like people to pay attention to? To help people review this PR understand what's changed.

Some customers need a custom path for their file structure, so was requested to add as a zephyr config parameter a custom public path on the snapshots for each one of the bundlers.

Some changes in the zephyr-engine to evaluate basehref parameters and save to snapshot.

Each bundler has a way to pass the basehref as parameter:

  • Webpack : uses config.output.publicPath
  • Rspack : uses config.output.publicPath
  • Rolldown : uses config.output.publicPath
  • Rollup : uses publicPath as withZephyr param
  • Vite : uses config.base

The ones with examples are way ahead on testing.

Examples using basehref:

The MF + Rspack example was moved to backlog until further implementation around MF dynamic remote handling with Zephyr.

Screenshots

Webpack example:
image
render

image
requests

image
snapshot


Rspack example
image
deploy

Vite example
image
render

image
snapshot

image
deploy

What's the issues or discussion related to this PR ?

Provide some background information related to this PR, including issues or task. Prior to this PR what's the behavior that wasn't expected.

If there wasn't discussion related to this PR, you can include the reasoning behind this PR of why you did it.

This work was conducted along @ryok90 to explore the possibilities of each plugin using the default parameters structure pass to zephyr-engine the basehref and the zephyr be fully responsible for the snapshot creation and pointing. So the goal is have less as possible configuration with the plugins, relying the assign behavior to zephyr-engine.

The Basehref + MF + Rspack with Zephyr implementation was moved to backlog until further implementation for dynamic domain handling.

What are the steps to test this PR?

To help reviewer and tester to understand what's needed

Implement some more basehref with each bundler using vanilla setup or MF with NX.

Documentation update for this PR (if applicable)?

Add documentation if how the application will behave differently than previous state. Copy paste your PR in zephyr-documentation PR link here.

https://webpack.js.org/guides/public-path/
module-federation/core#2633

(Optional) What's left to be done for this PR?

More examples implementation. Other bundlers public path linking
Deeper build testing with the current examples

(Optional) What's the potential risk and how to mitigate it?

Needed to check all the examples execution looking for missing assets.

@zackarychapple @valorkin @ryok90

(Required) Pre-PR/Merge checklist

  • [] I have added/updated/opened a PR to documentation to cover this new behavior
  • I have added an explanation of my changes
  • I have written new tests (if applicable)
  • I have tested this locally (standing from a first time user point of view, never touch this app before)
  • I have/will run tests, or ask for help to add test

zackarychapple and others added 11 commits March 24, 2025 12:21
Created a utility function to standardize base path handling across all plugins.
The function handles special cases like root paths, and strips leading/trailing slashes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Implemented a function to transform asset paths by applying baseHref prefix:
- Uses normalizeBasePath for consistent formatting
- Preserves index.html and absolute paths
- Creates deep copies of assets to avoid modifying originals
- Includes comprehensive unit tests

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Implemented webpack-basehref-integration.ts utility to extract baseHref from multiple sources
- Added priority logic: Plugin options > HTML Plugin > publicPath
- Updated ZeWebpackPlugin and ZeRspackPlugin to detect and store baseHref in ZephyrEngine
- Modified build-webpack-assets-map to apply baseHref to asset paths

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Extract base property from Vite configuration
- Added support for explicit baseHref override in plugin options
- Store baseHref in ZephyrEngine.buildProperties
- Normalize baseHref using utility functions
- Apply baseHref to asset paths with special case handling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

cla-assistant bot commented Mar 26, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

cla-assistant bot commented Mar 26, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ zackarychapple
❌ fiorin
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

nx-cloud bot commented Mar 27, 2025

View your CI Pipeline Execution ↗ for commit 9e5cb18.

Command Status Duration Result
nx build sample-webpack-application ✅ Succeeded 6s View ↗
nx build ✅ Succeeded 4s View ↗
nx build rollup-sample-lib ✅ Succeeded 4s View ↗
nx build vite-plugin-zephyr ✅ Succeeded <1s View ↗
nx run-many -t build --projects=libs/* ✅ Succeeded 18s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-28 16:04:05 UTC

artem-sht
artem-sht previously approved these changes Apr 28, 2025
Copy link
Contributor

@valorkin valorkin left a comment

Choose a reason for hiding this comment

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

I see some inconsistency, I would love to make a more in depth code review

@artem-sht artem-sht added the QA: Approved QA tests are passed label May 14, 2025
@fiorin fiorin dismissed stale reviews from artem-sht and VladyslavZinchenko via 7a72a61 May 27, 2025 12:09
Copy link

claude bot commented May 27, 2025

Claude finished @fiorin's task —— View job


PR Review Analysis

This PR adds baseHref support to Zephyr bundler plugins, enabling custom public paths for assets across Webpack, Rspack, Rolldown, Rollup, and Vite.

Todo List:

  • Read and analyze core basehref implementation files
  • Review new zephyr-rsbuild-plugin implementation
  • Examine test coverage and quality
  • Check security implications
  • Evaluate performance considerations
  • Assess code maintainability and standards
  • Provide structured feedback with severity ratings

Code Review Results

Issues & Recommendations
Severity Line(s) Issue Recommendation
Critical libs/zephyr-rolldown-plugin/src/lib/zephyr-rolldown-plugin.ts:30 Incorrect baseHref assignment using _options.dir instead of publicPath Use _options.publicPath or detect from plugin options like other bundlers
High libs/zephyr-rsbuild-plugin/src/rsbuild-plugin/ze-rsbuild-plugin.ts:19-22 Plugin implementation is incomplete - only logs without functionality Implement proper baseHref detection and integration like webpack/rspack plugins
High libs/zephyr-rsbuild-plugin/src/rsbuild-plugin/ze-rsbuild-plugin.ts:8 Unsafe any type for mfConfig Use proper ModuleFederationPlugin type from zephyr-xpack-internal
High libs/zephyr-rsbuild-plugin/ Missing test coverage for new plugin Add comprehensive unit tests following the pattern in ze-basehref-handler.spec.ts
Medium libs/zephyr-agent/src/lib/transformers/ze-basehref-handler.ts:111 Memory inefficiency - iterates Object.values then creates new map Use Object.entries() for single iteration
Medium libs/zephyr-xpack-internal/src/basehref/basehref-integration.ts:88-93 Console.warn for function publicPath may spam logs Use structured logging with debug levels
Low libs/zephyr-agent/src/lib/transformers/ze-basehref-handler.ts:16 Function parameter type allows null/undefined but JSDoc doesn't mention it Update JSDoc to document null/undefined handling
Low .gitignore Large number of generated files committed in examples/rspress-ssg/doc_build/ Consider adding doc_build/ to .gitignore

Critical Issues Requiring Immediate Attention

1. Rolldown Plugin Incorrect Implementation

// Current (WRONG):
zephyr_engine.buildProperties.baseHref = _options.dir;

// Should be:
zephyr_engine.buildProperties.baseHref = _options.publicPath;
// OR implement proper detection like other bundlers

2. Incomplete Rsbuild Plugin
The new ze-rsbuild-plugin.ts is essentially a stub. It needs:

  • BaseHref detection from compiler options
  • Integration with zephyr-xpack-internal utilities
  • Proper typing instead of any
// Suggested implementation:
apply(compiler: any): void {
  this._options.zephyr_engine.buildProperties.output = compiler.outputPath;
  detectAndStoreBaseHref(this._options.zephyr_engine, compiler);
  logBuildSteps(this._options, compiler);
  setupZeDeploy(this._options, compiler);
}

Performance Considerations

Memory Optimization Needed:

// Current inefficient approach in ze-basehref-handler.ts:111
Object.values(assetsMap).forEach((asset) => {
  const newAsset: ZeBuildAsset = { ...asset };
  // ...
});

// More efficient:
Object.entries(assetsMap).forEach(([key, asset]) => {
  const newAsset: ZeBuildAsset = { ...asset };
  // ...
});

Security Analysis

No critical security vulnerabilities found

  • BaseHref values are properly normalized and sanitized
  • No path traversal vulnerabilities detected
  • Input validation handles edge cases appropriately

Test Coverage Assessment

Strong: Core basehref handler has excellent test coverage (ze-basehref-handler.spec.ts)
Weak: Missing tests for:

  • New zephyr-rsbuild-plugin
  • Integration tests for basehref across bundlers
  • Error handling scenarios

Code Quality Score: 6/10

Strengths:

  • Well-structured basehref utility functions
  • Comprehensive test coverage for core functionality
  • Consistent API across bundlers
  • Good separation of concerns

Areas for Improvement:

  • Incomplete plugin implementations
  • Type safety issues (any types)
  • Performance optimizations needed
  • Missing integration tests

Top 3 Next Steps:

  1. Fix Critical Issues: Complete the rsbuild plugin implementation and fix rolldown plugin baseHref assignment
  2. Add Missing Tests: Implement comprehensive test coverage for new plugins and integration scenarios
  3. Type Safety: Replace any types with proper interfaces and improve type definitions

Copy link

claude bot commented May 27, 2025

Claude finished @fiorin's task —— View job


PR Review Analysis

This PR adds baseHref support to Zephyr bundler plugins, enabling custom public paths for assets across Webpack, Rspack, Rolldown, Rollup, and Vite.

Todo List:

  • Read and analyze core basehref implementation files
  • Review new zephyr-rsbuild-plugin implementation
  • Examine test coverage and quality
  • Check security implications
  • Evaluate performance considerations
  • Assess code maintainability and standards
  • Provide structured feedback with severity ratings

Code Review Results

Issues & Recommendations
Severity Line(s) Issue Recommendation
Critical libs/zephyr-rolldown-plugin/src/lib/zephyr-rolldown-plugin.ts:30 Incorrect baseHref assignment using _options.dir instead of publicPath Use _options.publicPath or detect from plugin options like other bundlers
High libs/zephyr-rsbuild-plugin/src/rsbuild-plugin/ze-rsbuild-plugin.ts:19-22 Plugin implementation is incomplete - only logs without functionality Implement proper baseHref detection and integration like webpack/rspack plugins
High libs/zephyr-rsbuild-plugin/src/rsbuild-plugin/ze-rsbuild-plugin.ts:8 Unsafe any type for mfConfig Use proper ModuleFederationPlugin type from zephyr-xpack-internal
High libs/zephyr-rsbuild-plugin/ Missing test coverage for new plugin Add comprehensive unit tests following the pattern in ze-basehref-handler.spec.ts
Medium libs/zephyr-agent/src/lib/transformers/ze-basehref-handler.ts:111 Memory inefficiency - iterates Object.values then creates new map Use Object.entries() for single iteration
Medium libs/zephyr-xpack-internal/src/basehref/basehref-integration.ts:88-93 Console.warn for function publicPath may spam logs Use structured logging with debug levels
Low libs/zephyr-agent/src/lib/transformers/ze-basehref-handler.ts:16 Function parameter type allows null/undefined but JSDoc doesn't mention it Update JSDoc to document null/undefined handling
Low .gitignore Large number of generated files committed in examples/rspress-ssg/doc_build/ Consider adding doc_build/ to .gitignore

Critical Issues Requiring Immediate Attention

1. Rolldown Plugin Incorrect Implementation

// Current (WRONG):
zephyr_engine.buildProperties.baseHref = _options.dir;

// Should be:
zephyr_engine.buildProperties.baseHref = _options.publicPath;
// OR implement proper detection like other bundlers

2. Incomplete Rsbuild Plugin
The new ze-rsbuild-plugin.ts is essentially a stub. It needs:

  • BaseHref detection from compiler options
  • Integration with zephyr-xpack-internal utilities
  • Proper typing instead of any
// Suggested implementation:
apply(compiler: any): void {
  this._options.zephyr_engine.buildProperties.output = compiler.outputPath;
  detectAndStoreBaseHref(this._options.zephyr_engine, compiler);
  logBuildSteps(this._options, compiler);
  setupZeDeploy(this._options, compiler);
}

Performance Considerations

Memory Optimization Needed:

// Current inefficient approach in ze-basehref-handler.ts:111
Object.values(assetsMap).forEach((asset) => {
  const newAsset: ZeBuildAsset = { ...asset };
  // ...
});

// More efficient:
Object.entries(assetsMap).forEach(([key, asset]) => {
  const newAsset: ZeBuildAsset = { ...asset };
  // ...
});

Security Analysis

No critical security vulnerabilities found

  • BaseHref values are properly normalized and sanitized
  • No path traversal vulnerabilities detected
  • Input validation handles edge cases appropriately

Test Coverage Assessment

Strong: Core basehref handler has excellent test coverage (ze-basehref-handler.spec.ts)
Weak: Missing tests for:

  • New zephyr-rsbuild-plugin
  • Integration tests for basehref across bundlers
  • Error handling scenarios

Code Quality Score: 6/10

Strengths:

  • Well-structured basehref utility functions
  • Comprehensive test coverage for core functionality
  • Consistent API across bundlers
  • Good separation of concerns

Areas for Improvement:

  • Incomplete plugin implementations
  • Type safety issues (any types)
  • Performance optimizations needed
  • Missing integration tests

Top 3 Next Steps:

  1. Fix Critical Issues: Complete the rsbuild plugin implementation and fix rolldown plugin baseHref assignment
  2. Add Missing Tests: Implement comprehensive test coverage for new plugins and integration scenarios
  3. Type Safety: Replace any types with proper interfaces and improve type definitions

Copy link

claude bot commented May 27, 2025

Claude finished @fiorin's task —— View job


PR Review Analysis

This PR adds baseHref support to Zephyr bundler plugins, enabling custom public paths for assets across Webpack, Rspack, Rolldown, Rollup, and Vite.

Todo List:

  • Read and analyze core basehref implementation files
  • Review new zephyr-rsbuild-plugin implementation
  • Examine test coverage and quality
  • Check security implications
  • Evaluate performance considerations
  • Assess code maintainability and standards
  • Provide structured feedback with severity ratings

Code Review Results

Issues & Recommendations
Severity Line(s) Issue Recommendation
Critical libs/zephyr-rolldown-plugin/src/lib/zephyr-rolldown-plugin.ts:30 Incorrect baseHref assignment using _options.dir instead of publicPath Use _options.publicPath or detect from plugin options like other bundlers
High libs/zephyr-rsbuild-plugin/src/rsbuild-plugin/ze-rsbuild-plugin.ts:19-22 Plugin implementation is incomplete - only logs without functionality Implement proper baseHref detection and integration like webpack/rspack plugins
High libs/zephyr-rsbuild-plugin/src/rsbuild-plugin/ze-rsbuild-plugin.ts:8 Unsafe any type for mfConfig Use proper ModuleFederationPlugin type from zephyr-xpack-internal
High libs/zephyr-rsbuild-plugin/ Missing test coverage for new plugin Add comprehensive unit tests following the pattern in ze-basehref-handler.spec.ts
Medium libs/zephyr-agent/src/lib/transformers/ze-basehref-handler.ts:111 Memory inefficiency - iterates Object.values then creates new map Use Object.entries() for single iteration
Medium libs/zephyr-xpack-internal/src/basehref/basehref-integration.ts:88-93 Console.warn for function publicPath may spam logs Use structured logging with debug levels
Low libs/zephyr-agent/src/lib/transformers/ze-basehref-handler.ts:16 Function parameter type allows null/undefined but JSDoc doesn't mention it Update JSDoc to document null/undefined handling
Low .gitignore Large number of generated files committed in examples/rspress-ssg/doc_build/ Consider adding doc_build/ to .gitignore

Critical Issues Requiring Immediate Attention

1. Rolldown Plugin Incorrect Implementation

// Current (WRONG):
zephyr_engine.buildProperties.baseHref = _options.dir;

// Should be:
zephyr_engine.buildProperties.baseHref = _options.publicPath;
// OR implement proper detection like other bundlers

2. Incomplete Rsbuild Plugin
The new ze-rsbuild-plugin.ts is essentially a stub. It needs:

  • BaseHref detection from compiler options
  • Integration with zephyr-xpack-internal utilities
  • Proper typing instead of any
// Suggested implementation:
apply(compiler: any): void {
  this._options.zephyr_engine.buildProperties.output = compiler.outputPath;
  detectAndStoreBaseHref(this._options.zephyr_engine, compiler);
  logBuildSteps(this._options, compiler);
  setupZeDeploy(this._options, compiler);
}

Performance Considerations

Memory Optimization Needed:

// Current inefficient approach in ze-basehref-handler.ts:111
Object.values(assetsMap).forEach((asset) => {
  const newAsset: ZeBuildAsset = { ...asset };
  // ...
});

// More efficient:
Object.entries(assetsMap).forEach(([key, asset]) => {
  const newAsset: ZeBuildAsset = { ...asset };
  // ...
});

Security Analysis

No critical security vulnerabilities found

  • BaseHref values are properly normalized and sanitized
  • No path traversal vulnerabilities detected
  • Input validation handles edge cases appropriately

Test Coverage Assessment

Strong: Core basehref handler has excellent test coverage (ze-basehref-handler.spec.ts)
Weak: Missing tests for:

  • New zephyr-rsbuild-plugin
  • Integration tests for basehref across bundlers
  • Error handling scenarios

Code Quality Score: 6/10

Strengths:

  • Well-structured basehref utility functions
  • Comprehensive test coverage for core functionality
  • Consistent API across bundlers
  • Good separation of concerns

Areas for Improvement:

  • Incomplete plugin implementations
  • Type safety issues (any types)
  • Performance optimizations needed
  • Missing integration tests

Top 3 Next Steps:

  1. Fix Critical Issues: Complete the rsbuild plugin implementation and fix rolldown plugin baseHref assignment
  2. Add Missing Tests: Implement comprehensive test coverage for new plugins and integration scenarios
  3. Type Safety: Replace any types with proper interfaces and improve type definitions

View job

Copy link

claude bot commented May 28, 2025

Claude finished @fiorin's task —— View job


PR Review Analysis

This PR adds baseHref support to Zephyr bundler plugins, enabling custom public paths for assets across Webpack, Rspack, Rolldown, Rollup, and Vite.

Todo List:

  • Read and analyze core basehref implementation files
  • Review new zephyr-rsbuild-plugin implementation
  • Examine test coverage and quality
  • Check security implications
  • Evaluate performance considerations
  • Assess code maintainability and standards
  • Provide structured feedback with severity ratings

Code Review Results

Issues & Recommendations
Severity Line(s) Issue Recommendation
Critical libs/zephyr-rolldown-plugin/src/lib/zephyr-rolldown-plugin.ts:30 Incorrect baseHref assignment using _options.dir instead of publicPath Use _options.publicPath or detect from plugin options like other bundlers
High libs/zephyr-rsbuild-plugin/src/rsbuild-plugin/ze-rsbuild-plugin.ts:19-22 Plugin implementation is incomplete - only logs without functionality Implement proper baseHref detection and integration like webpack/rspack plugins
High libs/zephyr-rsbuild-plugin/src/rsbuild-plugin/ze-rsbuild-plugin.ts:8 Unsafe any type for mfConfig Use proper ModuleFederationPlugin type from zephyr-xpack-internal
High libs/zephyr-rsbuild-plugin/ Missing test coverage for new plugin Add comprehensive unit tests following the pattern in ze-basehref-handler.spec.ts
Medium libs/zephyr-agent/src/lib/transformers/ze-basehref-handler.ts:111 Memory inefficiency - iterates Object.values then creates new map Use Object.entries() for single iteration
Medium libs/zephyr-xpack-internal/src/basehref/basehref-integration.ts:88-93 Console.warn for function publicPath may spam logs Use structured logging with debug levels
Low libs/zephyr-agent/src/lib/transformers/ze-basehref-handler.ts:16 Function parameter type allows null/undefined but JSDoc doesn't mention it Update JSDoc to document null/undefined handling
Low .gitignore Large number of generated files committed in examples/rspress-ssg/doc_build/ Consider adding doc_build/ to .gitignore

Critical Issues Requiring Immediate Attention

1. Rolldown Plugin Incorrect Implementation

// Current (WRONG):
zephyr_engine.buildProperties.baseHref = _options.dir;

// Should be:
zephyr_engine.buildProperties.baseHref = _options.publicPath;
// OR implement proper detection like other bundlers

2. Incomplete Rsbuild Plugin
The new ze-rsbuild-plugin.ts is essentially a stub. It needs:

  • BaseHref detection from compiler options
  • Integration with zephyr-xpack-internal utilities
  • Proper typing instead of any
// Suggested implementation:
apply(compiler: any): void {
  this._options.zephyr_engine.buildProperties.output = compiler.outputPath;
  detectAndStoreBaseHref(this._options.zephyr_engine, compiler);
  logBuildSteps(this._options, compiler);
  setupZeDeploy(this._options, compiler);
}

Performance Considerations

Memory Optimization Needed:

// Current inefficient approach in ze-basehref-handler.ts:111
Object.values(assetsMap).forEach((asset) => {
  const newAsset: ZeBuildAsset = { ...asset };
  // ...
});

// More efficient:
Object.entries(assetsMap).forEach(([key, asset]) => {
  const newAsset: ZeBuildAsset = { ...asset };
  // ...
});

Security Analysis

No critical security vulnerabilities found

  • BaseHref values are properly normalized and sanitized
  • No path traversal vulnerabilities detected
  • Input validation handles edge cases appropriately

Test Coverage Assessment

Strong: Core basehref handler has excellent test coverage (ze-basehref-handler.spec.ts)
Weak: Missing tests for:

  • New zephyr-rsbuild-plugin
  • Integration tests for basehref across bundlers
  • Error handling scenarios

Code Quality Score: 6/10

Strengths:

  • Well-structured basehref utility functions
  • Comprehensive test coverage for core functionality
  • Consistent API across bundlers
  • Good separation of concerns

Areas for Improvement:

  • Incomplete plugin implementations
  • Type safety issues (any types)
  • Performance optimizations needed
  • Missing integration tests

Top 3 Next Steps:

  1. Fix Critical Issues: Complete the rsbuild plugin implementation and fix rolldown plugin baseHref assignment
  2. Add Missing Tests: Implement comprehensive test coverage for new plugins and integration scenarios
  3. Type Safety: Replace any types with proper interfaces and improve type definitions

@fiorin fiorin merged commit a320017 into master May 28, 2025
10 checks passed
@fiorin fiorin deleted the feat-basehref branch May 28, 2025 16:47
@ryok90 ryok90 mentioned this pull request Jun 5, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request QA: Approved QA tests are passed Ready for testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants