Skip to content

Conversation

@chenjiahan
Copy link
Member

@chenjiahan chenjiahan commented Sep 15, 2025

Summary

Load typescript via require instead of import to avoid cjs-module-lexer overhead and improve startup performance.

The same as web-infra-dev/rsbuild#5673.

Before

Screenshot 2025-09-15 at 19 10 19

After

Screenshot 2025-09-15 at 19 10 02

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings September 15, 2025 11:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves startup performance by loading TypeScript via require instead of import to avoid cjs-module-lexer overhead. Since TypeScript only provides a CommonJS bundle, using require eliminates the need for Node.js to parse it with cjs-module-lexer during module loading.

Key changes:

  • Replace TypeScript default import with type-only imports and a require-based loader
  • Add createRequire setup to enable CommonJS loading in ESM context
  • Export the required TypeScript instance for use across the codebase

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/plugin-dts/src/utils.ts Implements the require-based TypeScript loader and exports ts instance
packages/plugin-dts/src/tsc.ts Updates to use type-only imports and the shared ts instance
packages/plugin-dts/src/index.ts Updates to use type-only imports and the shared ts instance

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Timeless0911 Timeless0911 merged commit d09f7d6 into main Sep 15, 2025
21 of 22 checks passed
@Timeless0911 Timeless0911 deleted the require_typescript_0915 branch September 15, 2025 12:20
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.

3 participants