-
-
Notifications
You must be signed in to change notification settings - Fork 232
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 compile
option to enable rerun of transpilation for react templates
#1177
Conversation
compile
option to enable rerun of transpilation for react templates
lib/generator.js
Outdated
@@ -391,7 +393,7 @@ class Generator { | |||
*/ | |||
async configureTemplate() { | |||
if (isReactTemplate(this.templateConfig)) { | |||
await configureReact(this.templateDir, this.templateContentDir, TRANSPILED_TEMPLATE_LOCATION); | |||
await configureReact(this.templateDir, this.templateContentDir, TRANSPILED_TEMPLATE_LOCATION, this.compile); |
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.
I'm wondering if it makes sense to modify configureReact
or maybe better just do conditional here, like
if (isReactTemplate(this.templateConfig) && this.compile) {
await configureReact(this.templateDir, this.templateContentDir, TRANSPILED_TEMPLATE_LOCATION);
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.
I have added conditional transpilation
Quality Gate passedIssues Measures |
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.
ok, we need to add a proper new integration test here, without proper test, feature development will be based on just our intuition
there are some integration tests already, that use https://github.com/asyncapi/html-template template
we just need another test, also using https://github.com/asyncapi/html-template but fixed to use version 2.3.0
where __transpiled
folder was added to package.
there are 2 test scenarios:
- with
compile
flagfalse
you run html template generation with debug flag
console.log message should contain something aboutBabel
- with
compile
flagtrue
you run html template generation with debug flag
console.log message should not contain something aboutBabel
Why? We know html-template as some big files and babel warns about it in logs, when transpilation runs. Now, we also know that we do not need to run transpilation as __transpiled
dir is there. This is why we can, with such integrations test, confirm if transpilation is triggered only if compile
is true
makes sense?
looks alright |
@utnim2 ok then, ping me when ready for another review |
@utnim2 do you continue with this one? |
currently i am having my semester exam, will continue working on it after my exams are over |
/update |
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.
since last time, there were changes in integration tests and we should not rely on html-template anymore, you need to use https://github.com/asyncapi/generator/tree/master/test/test-templates/react-template
and yeah, in that template there are no babel logs we can rely on.
so maybe the best will be to simply extend configureReact
with a log message (only if debug flag) that basically drops log like "Transpilation of files DIR into OUTPUT_DIR started"
then probably enough is to add just unit test in generator.test.js, check but probably integration test is not needed
one more problem, compile
as you put in title, should rerun transpilation. So if someone makes some modification in template and needs to refresh __transpiled
dir, they need to pass this flag.
so compilation always runs by default if __transpiled
dir is not present
we need to have this also documented then in template-development.md (maybe other docs too):
- that when people publish templates based on react, they should include
__transpiled
dir in the package - that during development they need to pass the flag to run
compile
explicitly to refresh__transpiled
dir when needed
lib/renderer/react.js
Outdated
@@ -13,6 +13,7 @@ const reactExport = module.exports; | |||
* @param {string} templateLocation located for thetemplate | |||
* @param {string} templateContentDir where the template content are located | |||
* @param {string} transpiledTemplateLocation folder for the transpiled code | |||
* @param {Boolean} compile Whether to compile the template files or used the cached transpiled version provided by the template in the '__transpiled' folder |
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.
did you do some changes in below code? cause now this jsdoc is not reflecting reality 🤔
test/integration.test.js
Outdated
debug: true, | ||
}); | ||
|
||
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); |
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.
to be consistent in project, for spying on console, please follow the same approach we have in generator.test.js
log.debug = jest.fn();
expect(log.debug).toHaveBeenCalledWith("redacted for brevity));
test/integration.test.js
Outdated
const outputDir = generateFolderName(); | ||
const generator = new Generator('@asyncapi/html-template@2.3.0', outputDir, { | ||
forceWrite: true, | ||
compile: false, |
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.
it is false by default, so in test you should also not pass it
Quality Gate passedIssues Measures |
i am confused here, so do we need to add integration test or do we just need to add test in cc @derberg |
Quality Gate passedIssues Measures |
just try with suggestion to add log and test for it - if it will work, no integration test is needed |
@derberg any idea why workflow is failing? (idk why test seems to fail) |
Hey @derberg when i run locally, with |
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.
left few comments, some things we talked about during meeting - you did not take into account
also, you as contributor and maintainer need to proactively check and see that PR tests are failing. Me as maintainer, if I see tests are failing, I do not even start review as my assumption is PR is not ready for review (I reviewed this time only because we talked about PR and I saw you did some commits after)
@Gmin2 your tests are still failing |
🦋 Changeset detectedLatest commit: 834b3cc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@Gmin2 any progress? |
apps/generator/lib/logMessages.js
Outdated
@@ -59,5 +63,7 @@ module.exports = { | |||
templateSuccessfullyInstalled, | |||
relativeSourceFileNotGenerated, | |||
conditionalFilesMatched, | |||
compileEnabled, | |||
compileEnabled, |
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.
doubled export
apps/generator/cli.js
Outdated
@@ -84,6 +84,7 @@ program | |||
}) | |||
.option('-d, --disable-hook [hooks...]', 'disable a specific hook type or hooks from given hook type', disableHooksParser) | |||
.option('--debug', 'enable more specific errors in the console') | |||
.option('--compile', 'compile the template files before rendering') |
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.
after all works remember to remove compile flag from here as we do not enable new flags in local cli
test: update tests
Quality Gate passedIssues Measures |
@Gmin2 all good, I just improved the changeset a bit to make it clear what this release is all about. Please have a look for future education |
/rtm |
Description
The PR introduces a new option
compile
in theGenerator
class contructor which is by defaulttrue
,by default theReact
template files are transpiled. When setting thecompile
options tofalse
the transpilation process does not takes place.I have also added/updated test for it. Below are the result
Related issue(s)
Closes #521
which added this functionality