Skip to content
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

feat: 支持ts-checker #956

Merged
merged 11 commits into from
Apr 16, 2024
Merged

feat: 支持ts-checker #956

merged 11 commits into from
Apr 16, 2024

Conversation

ctts
Copy link
Contributor

@ctts ctts commented Mar 18, 2024

使用 parseConfigFileTextToJson parseJsonConfigFileContent 解析和读取tsconfig,传入tsc,读取其中的报错信息
写在node层,触发时机在 build 完成之后,在子进程中执行,不影响构建速度
config.forkTsChecker 设为 true 开启功能

Summary by CodeRabbit

  • New Features
    • Added a new configuration option to enable TypeScript type checking during the build process.
    • Introduced a ForkTsChecker class to run type checking in a child process for TypeScript projects.
    • Implemented functionality to perform TypeScript type checking using a TypeChecker class.
    • Updated mako package to include a dev dependency on TypeScript version 5.4.3.
    • Added an optional property in the ExtraBuildParams interface to enable running type checking in a child process.
  • Documentation
    • Updated documentation in the config.md file to include information about the new forkTsChecker configuration option.

packages/bundler-okam/package.json Outdated Show resolved Hide resolved
packages/bundler-okam/index.js Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
packages/bundler-okam/plugins/fork-ts-checker/index.js Outdated Show resolved Hide resolved
@ctts ctts requested a review from sorrycc March 21, 2024 11:48
@stormslowly stormslowly deleted the dev-for-ts-checker branch March 25, 2024 05:24
@stormslowly stormslowly restored the dev-for-ts-checker branch March 25, 2024 05:39
@stormslowly stormslowly reopened this Mar 25, 2024
Copy link
Member

@sorrycc sorrycc left a comment

Choose a reason for hiding this comment

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

看了下实现,子进程跑的功能还没开发完吗?

docs/config.md Outdated Show resolved Hide resolved
packages/bundler-okam/index.js Outdated Show resolved Hide resolved
@@ -5,6 +5,7 @@ const assert = require('assert');
const { createProxy, createHttpsServer } = require('@umijs/bundler-utils');
const lodash = require('lodash');
const chalk = require('chalk');
const { ForkTsChecker } = require('./plugins/fork-ts-checker/index');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const { ForkTsChecker } = require('./plugins/fork-ts-checker/index');
const { ForkTsChecker } = require('./fork-ts-checker/index');

不要 plugins 目录,因为实际上 bundler-okam 层没有 plugin 机制。

await typeChecker.check();
}

runTypeCheckInChildProcess() {
Copy link
Member

Choose a reason for hiding this comment

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

没有走子进程的这个逻辑吗?

Copy link
Contributor

coderabbitai bot commented Mar 26, 2024

Walkthrough:

The changes revolve around enhancing TypeScript type checking capabilities in the build process. New configuration options and classes are introduced to enable type checking using ForkTsChecker in child processes for TypeScript projects, boosting build efficiency and error detection.

Changes:

File(s) Change Summary
docs/config.md Added forkTsChecker config option for TypeScript type checking during build.
packages/bundler-okam/index.js Updated to use ForkTsChecker import and forkTsChecker in getOkamConfig function.
packages/bundler-okam/fork-ts-checker/ Introduces child_process_fork.js to run type checking in child process based on args.
packages/bundler-okam/fork-ts-checker/index.js Added ForkTsChecker class for type checking in child process with logging based on exit code.
packages/bundler-okam/fork-ts-checker/ts-checker.js Introduced TypeChecker class for TypeScript type checking based on tsconfig.json.
packages/mako/binding.d.ts Removed TransformOutput interface and adjusted JsHooks interface.
packages/mako/package.json Updated dev dependency to TypeScript version 5.4.3.
packages/mako/src/forkTSChecker/ Added childProcessFork.ts and index.ts for running type checking in child processes.
packages/mako/src/forkTSChecker/tsChecker.ts Introduced TypeChecker class for TypeScript type checking based on tsconfig.json.
packages/mako/src/index.ts Added import for ForkTsChecker and forkTsChecker property in ExtraBuildParams interface.

Poem:

In TypeScript's realm, where rabbits play,
ForkTsChecker joins the fray.
Child processes dance and sing,
Errors caught on type-checking wing.
Build anew, with TypeScript's zing!

Note

Pull Request Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://coderabbit.ai


Commits Files that changed from the base of the PR and between 9d94ff1 and 7955788.
Files selected for processing (1)
  • packages/mako/src/forkTSChecker/index.ts (1 hunks)

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a46de03 and 89a5c8c.
Files ignored due to path filters (2)
  • packages/bundler-okam/package.json is excluded by: !**/*.json
  • pnpm-lock.yaml is excluded by: !**/*.yaml
Files selected for processing (5)
  • docs/config.md (2 hunks)
  • packages/bundler-okam/fork-ts-checker/child_process_fork.js (1 hunks)
  • packages/bundler-okam/fork-ts-checker/index.js (1 hunks)
  • packages/bundler-okam/fork-ts-checker/ts-checker.js (1 hunks)
  • packages/bundler-okam/index.js (4 hunks)
Additional comments: 9
packages/bundler-okam/fork-ts-checker/child_process_fork.js (3)
  • 1-1: The comment next to the import statement is in Chinese. For consistency and broader understanding, consider translating it to English.
  • 5-8: The runTypeCheck function is well-defined and correctly uses async/await for handling asynchronous operations. Good job!
  • 10-17: The promise chain for handling the outcome of the type checking process is correctly implemented, effectively communicating success or failure to the calling process.
packages/bundler-okam/fork-ts-checker/index.js (3)
  • 1-2: The import statements are correctly used and necessary for the functionality of the ForkTsChecker class.
  • 4-22: The ForkTsChecker class is well-defined and effectively manages the spawning of a child process for type checking. The use of stdio: 'inherit' is a good choice for ensuring visibility of the child process's output.
  • 25-25: The export statement is correctly implemented, making the ForkTsChecker class available for use in other modules.
packages/bundler-okam/fork-ts-checker/ts-checker.js (3)
  • 1-3: The import statements are correctly used and necessary for the functionality of the TypeChecker class. The use of fs.promises for asynchronous file operations is a modern and efficient approach.
  • 5-94: The TypeChecker class is well-defined and effectively performs TypeScript type checking. The comprehensive error handling and the use of standard TypeScript APIs for reading tsconfig.json, creating a program, and reporting diagnostics are commendable.
  • 97-97: The export statement is correctly implemented, making the TypeChecker class available for use in other modules.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 49cd6a7 and 03c56d8.
Files ignored due to path filters (2)
  • packages/bundler-okam/package.json is excluded by: !**/*.json
  • pnpm-lock.yaml is excluded by: !**/*.yaml
Files selected for processing (5)
  • docs/config.md (2 hunks)
  • packages/bundler-okam/fork-ts-checker/child_process_fork.js (1 hunks)
  • packages/bundler-okam/fork-ts-checker/index.js (1 hunks)
  • packages/bundler-okam/fork-ts-checker/ts-checker.js (1 hunks)
  • packages/bundler-okam/index.js (4 hunks)
Files skipped from review as they are similar to previous changes (5)
  • docs/config.md
  • packages/bundler-okam/fork-ts-checker/child_process_fork.js
  • packages/bundler-okam/fork-ts-checker/index.js
  • packages/bundler-okam/fork-ts-checker/ts-checker.js
  • packages/bundler-okam/index.js

@ctts ctts requested a review from sorrycc March 26, 2024 07:36
@sorrycc sorrycc merged commit 9032489 into master Apr 16, 2024
4 checks passed
@delete-merged-branch delete-merged-branch bot deleted the dev-for-ts-checker branch April 16, 2024 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants