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

refactor: migrate build script to typescript #3423

Draft
wants to merge 62 commits into
base: master
Choose a base branch
from

Conversation

JeelRajodiya
Copy link
Contributor

Description

  • The PR migrates the build scripts to Typescript

Related issue(s)
Related to #3187

Copy link

coderabbitai bot commented Nov 22, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

.eslintrc Show resolved Hide resolved
package.json Outdated
"scripts": {
"dev": "npm run build-scripts && next dev",
"build": "npm run build-scripts && next build",
"test": "jest --passWithNoTests",
"build:pages": "node scripts/build-pages.js && npm run format:mdx",
"build:posts": "node scripts/index.js",
"build:pages": "node --loader ts-node/esm scripts/build-pages.ts && npm run format:mdx",
Copy link
Member

Choose a reason for hiding this comment

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

We discussed to use tsx as well. Why you again moved to ts-node?

Copy link
Contributor Author

@JeelRajodiya JeelRajodiya Nov 27, 2024

Choose a reason for hiding this comment

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

Problems with ts-node

I was getting the error Cannot use import outside a module. To resolve this, I added the type: "module" configuration in the package.json file. However, this caused another error: .ts is not a recognized file extension. When type is set to module, Node.js expects the files to have specific extensions (e.g., .cjs, .mjs, or .js).

I was able to resolve this issue by setting the "module": "CommonJS" option in the tsconfig.json file and avoiding the use of "type": "module" in the package.json file. However, I believe setting "module": "CommonJS" might not be ideal, as it allows mixed usage of import and require within a single file.


Using the esm loader

We can use the --loader ts-node/esm option with node.js to run the typescript files. This solution was suggested here on stackoverflow. All the scripts are executing without any errors.


Using tsx

Another option is to use tsx. While I was finding solution for the unknown file extension error, there were several answers suggesting to use tsx (i.e. this one). And regarding the underlying version used by tsx, Tsx uses the node.js version which we have installed (source)

image


@akshatnema currently we can think of two options, use node js with esm loader (currently used in this PR) or we can use tsx. Please let me know your thoughts on which one to use.

package.json Show resolved Hide resolved
pages/_document.tsx Outdated Show resolved Hide resolved
scripts/build-rss.ts Outdated Show resolved Hide resolved
.eslintrc Outdated
"files": ["scripts/**/*"],
"rules": {
"import/no-extraneous-dependencies": "off",
"no-console": "off"
Copy link
Member

Choose a reason for hiding this comment

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

Can we refactor the code to remove the warning or use minimalistic console messages instead of turning off the rule?

Copy link
Contributor Author

@JeelRajodiya JeelRajodiya Nov 27, 2024

Choose a reason for hiding this comment

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

@akshatnema
The scripts have console.log statements to give feedbacks on the CLI, so we need to keep the them in the scripts. I don't think there are many redundant console logs.

I think I might need to remove most of the eslint warnings by adding a comment to ignore eslint warning before each of the log statement,

I have added the rule to avoid adding so many comments to ignore the eslint rule.

@akshatnema Should I remove the rule from the config and add comments (to ignore the warning) on each of log statement anyways?

image

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