-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
base: master
Are you sure you want to change the base?
Conversation
This reverts commit df75c79.
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
…asyncapi-site into script-migration-2
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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
@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.
.eslintrc
Outdated
"files": ["scripts/**/*"], | ||
"rules": { | ||
"import/no-extraneous-dependencies": "off", | ||
"no-console": "off" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
Description
Related issue(s)
Related to #3187