Skip to content

feat: implement rslib with TypeScript declaration generation #3883

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 24 commits into from
Jul 23, 2025

Conversation

ScriptedAlchemy
Copy link
Member

Summary

  • Implement rslib configuration with TypeScript declaration file generation
  • Add missing entry points (helpers, core, global) to rslib config
  • Update runtime-core package.json exports to use generated declarations
  • Fix import patterns in runtime package to use namespace imports
  • Exclude dist directories from TypeScript compilation to prevent conflicts

Key Changes

  • ✅ Runtime-core builds successfully with .d.ts generation via rslib
  • ✅ Both pnpm build and nx run runtime-core:build work correctly
  • ✅ Added global variable definitions for build-time replacement
  • ✅ Updated package exports to point to generated declaration files
  • ✅ Most workspace packages now build successfully

Test plan

  • Runtime-core builds with rslib and generates TypeScript declarations
  • Runtime package builds successfully with corrected imports
  • Workspace build shows significant improvement in package success rate
  • Both rslib executor and direct pnpm scripts work correctly

🤖 Generated with Claude Code

ScriptedAlchemy and others added 7 commits May 16, 2025 01:24
- Configure rslib to generate TypeScript declaration files (.d.ts)
- Add missing entry points (helpers, core, global) to rslib config
- Update runtime-core package.json exports to use generated declarations
- Fix import patterns in runtime package to use namespace imports
- Exclude dist directories from TypeScript compilation to prevent conflicts
- Add global variable definitions for build-time replacement
- Update multiple package tsconfigs to prevent dual type resolution

This enables proper TypeScript declaration generation via rslib
while maintaining compatibility with existing build processes.

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

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

changeset-bot bot commented Jul 3, 2025

⚠️ No Changeset found

Latest commit: 232c673

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

netlify bot commented Jul 3, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 232c673
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/688028f27cd8b70008bec885
😎 Deploy Preview https://deploy-preview-3883--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 project configuration.

ScriptedAlchemy and others added 16 commits July 3, 2025 14:03
The tools/scripts/publish.mjs file was not referenced anywhere in the
codebase and appears to be legacy/template code that was never integrated
into the actual publishing workflow.

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

Co-Authored-By: Claude <[email protected]>
- Replace @nx/rollup executor with rslib for runtime-core package
- Add @rslib/core as devDependency and create rslib.config.ts
- Update package.json exports to match rslib output format (.js/.cjs)
- Add TypeScript declaration generation with proper env.d.ts
- Update tsconfig.lib.json for correct output paths
- Remove duplicate global.d.ts file
- Add build script to package.json for direct rslib execution

This migration enables better TypeScript declaration generation and
aligns with modern build tooling standards.

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

Co-Authored-By: Claude <[email protected]>
- Move global declarations from src/global.ts to separate global-types.d.ts
- This prevents conflicts between source and generated .d.ts files
- Resolves TypeScript errors where packages saw both src and dist types
- Enhanced package now builds successfully without type conflicts

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

Co-Authored-By: Claude <[email protected]>
- Configure project.json to use ../../tools/rslib-plugin:build executor
- Fix rslib.config.ts import to use JSON import instead of fs.readFileSync
- Add @rslib/core devDependency to package.json
- Ensure proper rslib configuration for TypeScript declaration generation

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

Co-Authored-By: Claude <[email protected]>
- Updated @nx dependencies from 21.0.3 to 21.2.3 in package.json
- Updated runtime-core package.json version and export paths
- Kept @rslib/core at 0.10.4 in apps/rslib-module
- Fixed export type conflicts in runtime-core/src/index.ts
- Regenerated pnpm-lock.yaml

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

Co-Authored-By: Claude <[email protected]>
- Add proper global type declarations in runtime/global.d.ts for Federation interfaces
- Fix implicit any type errors in runtime/src/utils.ts by adding proper typing
- Import Federation and RemoteEntryExports types from runtime-core
- Remove type casting in favor of proper TypeScript declarations

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

Co-Authored-By: Claude <[email protected]>
- Fix rslib bundling configuration in runtime-core (bundle: true)
- Add global type declarations for Federation interfaces
- Fix TypeScript implicit any type errors in runtime-core
- Correct package.json export conditions ordering in chrome-devtools
- Add global.d.ts files to bridge packages for type safety

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

Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Replace exec() calls with direct rslib build API
- Use rslib's loadConfig function for TypeScript config loading
- Improve reliability and performance in CI environments
- Fix package.json exports to match actual rslib output files

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

Co-Authored-By: Claude <[email protected]>
- Add support for external dependencies with glob patterns
- Support multiple output formats (esm, cjs, umd, iife)
- Add additional entry points support
- Implement proper TypeScript declaration generation
- Add comprehensive test suite for rslib executor
- Fix path resolution for Nx workspace conventions

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

Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
for (const ext of options.external) {
if (ext.includes('*')) {
// Handle glob patterns like "@module-federation/*"
const pattern = ext.replace('*', '(.*)');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This replaces only the first occurrence of '*'.

Copilot Autofix

AI 2 days ago

To fix the issue, the replace method should be updated to use a regular expression with the global flag (g) to ensure that all occurrences of * in the ext string are replaced. This change will make the code handle cases where ext contains multiple * characters correctly.

The replacement involves modifying the ext.replace('*', '(.*)') call to use a regular expression: ext.replace(/\*/g, '(.*)'). This ensures that every * in the string is replaced with (.*).


Suggested changeset 1
tools/rslib-plugin/src/executors/build/executor.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tools/rslib-plugin/src/executors/build/executor.ts b/tools/rslib-plugin/src/executors/build/executor.ts
--- a/tools/rslib-plugin/src/executors/build/executor.ts
+++ b/tools/rslib-plugin/src/executors/build/executor.ts
@@ -145,3 +145,3 @@
         // Handle glob patterns like "@module-federation/*"
-        const pattern = ext.replace('*', '(.*)');
+        const pattern = ext.replace(/\*/g, '(.*)');
         externals[pattern] = ext;
EOF
@@ -145,3 +145,3 @@
// Handle glob patterns like "@module-federation/*"
const pattern = ext.replace('*', '(.*)');
const pattern = ext.replace(/\*/g, '(.*)');
externals[pattern] = ext;
Copilot is powered by AI and may make mistakes. Always verify output.
@ScriptedAlchemy ScriptedAlchemy committed this autofix suggestion 2 days ago.
…ping or encoding

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ScriptedAlchemy ScriptedAlchemy merged commit 0b0c5da into main Jul 23, 2025
7 of 8 checks passed
@ScriptedAlchemy ScriptedAlchemy deleted the cursor/create-rslib-executor-for-nx-3342 branch July 23, 2025 00:12
@2heal1 2heal1 mentioned this pull request Jul 24, 2025
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