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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

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 <noreply@anthropic.com>
Copy link

changeset-bot bot commented Jul 3, 2025

⚠️ No Changeset found

Latest commit: 0b7845d

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 failed. Why did it fail? →

Name Link
🔨 Latest commit 0b7845d
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/68675ac18fd25c0008e5afc4

const args = ['rslib', 'build'];

if (options.configFile && options.configFile !== 'rslib.config.ts') {
args.push('--config', options.configFile);

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input Medium

This array element which depends on
library input
is later used in a
shell command
.

Copilot Autofix

AI 9 days ago

To fix the issue, we should avoid constructing the shell command as a single string and instead use a safer API like execFile, which accepts the command and its arguments as separate parameters. This approach prevents the shell from interpreting special characters in the input. Specifically:

  1. Replace the use of exec with execFile.
  2. Pass the args array directly to execFile as the command arguments.
  3. Ensure that the options.configFile value is properly validated or sanitized before being added to the args array.

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
@@ -1,3 +1,3 @@
 import type { ExecutorContext } from '@nx/devkit';
-import { exec } from 'child_process';
+import { execFile } from 'child_process';
 import { promisify } from 'util';
@@ -46,9 +46,7 @@
 
-  const command = args.join(' ');
-
   try {
-    console.info(`Running: ${command}`);
+    console.info(`Running: ${args.join(' ')}`);
     console.info(`Working directory: ${join(context.root, projectRoot)}`);
 
-    const { stdout, stderr } = await promisify(exec)(command, {
+    const { stdout, stderr } = await promisify(execFile)(args[0], args.slice(1), {
       cwd: join(context.root, projectRoot),
EOF
@@ -1,3 +1,3 @@
import type { ExecutorContext } from '@nx/devkit';
import { exec } from 'child_process';
import { execFile } from 'child_process';
import { promisify } from 'util';
@@ -46,9 +46,7 @@

const command = args.join(' ');

try {
console.info(`Running: ${command}`);
console.info(`Running: ${args.join(' ')}`);
console.info(`Working directory: ${join(context.root, projectRoot)}`);

const { stdout, stderr } = await promisify(exec)(command, {
const { stdout, stderr } = await promisify(execFile)(args[0], args.slice(1), {
cwd: join(context.root, projectRoot),
Copilot is powered by AI and may make mistakes. Always verify output.
ScriptedAlchemy and others added 5 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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
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