-
-
Notifications
You must be signed in to change notification settings - Fork 239
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: add TypeScript support for hooks and filters #519
Conversation
9f1ab5f
to
785b3f4
Compare
2e1997a
to
a96962d
Compare
I'm afraid this is introducing much more complexity to the Generator, especially the transpilation process. What need exactly is driving this PR? |
@fmvilas How complexity? It only transpiles TS code on the fly when we import hooks or filters in |
Oh, ok 👍 I was missing that context. Thanks! |
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.
@magicmatatjahu great work, only few comments, all docs related
docs/authoring.md
Outdated
- Installing the `typescript` package and creating the` tsconfig.json` file isn't necessary. | ||
- Source code of the hook/filter must have `.ts` extension. | ||
- Each package related with the typings for TypeScript like `@types/node` must be installed in the template under `dependencies` array. This is because the Generator transpiles the TypeScript code on-the-fly while rendering the template, so cannot uses packages under `devDependencies`. | ||
- Each package should have installed `@types/node` package to support typings for 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.
what package?
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.
Sorry, here should be template
-> Each template...
lib/hooksRegistry.js
Outdated
@@ -98,6 +98,11 @@ async function registerConfigHooks(hooks, templateDir, templateConfig) { | |||
* @param {Array} config List of hooks configured in template configuration | |||
*/ | |||
function addHook(hooks, mod, config) { | |||
// for ESM `export default {}` |
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.
what does it mean, what esm has to do with this part?
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.
For example. If you write export for hooks in CommonJS, then you have:
module.exports = {
'generate:before': (generator) => {
}
};
But if you are using ESM in TS, you can write:
export default {
'generate:before': (generator) => {
}
}
Unfortunately, then it is transpiled to:
module.exports = {
default: {
'generate:before': (generator) => {
}
}
};
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.
oh, ok, you just made a comment to explain the if
. Can you make it more descriptive 🙏🏼 I totally didn't map it in my head, probably because I use ESM very rarely. So please write this comment for people like me too 😄
Co-authored-by: Lukasz Gornicki <[email protected]>
Co-authored-by: Lukasz Gornicki <[email protected]>
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
🎉 This PR is included in version 1.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Add TypeScript supports in hooks and Nunjucks's filters:
ts-node
,typescript
andsource-map
packages in generator.Related issue(s)
Resolve #455