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: add compile option to enable rerun of transpilation for react templates #1177

Merged
merged 45 commits into from
Aug 26, 2024

Conversation

Gmin2
Copy link
Collaborator

@Gmin2 Gmin2 commented Apr 4, 2024

Description

The PR introduces a new option compile in the Generator class contructor which is by default true ,by default the React template files are transpiled. When setting the compile options to false the transpilation process does not takes place.

I have also added/updated test for it. Below are the result

image

Related issue(s)
Closes #521

image

which added this functionality

@derberg derberg changed the title feat: added a compile option to enable skipping default transpilation in react feat: add compile option to enable rerun of transpilation for react templates Apr 9, 2024
lib/generator.js Outdated Show resolved Hide resolved
lib/renderer/react.js Outdated Show resolved Hide resolved
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);
Copy link
Member

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);

Copy link
Collaborator Author

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

lib/renderer/react.js Outdated Show resolved Hide resolved
lib/renderer/react.js Outdated Show resolved Hide resolved
lib/generator.js Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Apr 10, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@derberg derberg left a 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 flag false
    you run html template generation with debug flag
    console.log message should contain something about Babel
  • with compile flag true
    you run html template generation with debug flag
    console.log message should not contain something about Babel

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?

@Gmin2
Copy link
Collaborator Author

Gmin2 commented Apr 11, 2024

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 flag false
    you run html template generation with debug flag
    console.log message should contain something about Babel
  • with compile flag true
    you run html template generation with debug flag
    console.log message should not contain something about Babel

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

@derberg
Copy link
Member

derberg commented Apr 16, 2024

@utnim2 ok then, ping me when ready for another review

@derberg
Copy link
Member

derberg commented Apr 22, 2024

@utnim2 do you continue with this one?

@Gmin2
Copy link
Collaborator Author

Gmin2 commented Apr 22, 2024

@utnim2 do you continue with this one?

currently i am having my semester exam, will continue working on it after my exams are over
cc @derberg

@Gmin2
Copy link
Collaborator Author

Gmin2 commented May 18, 2024

Hey @derberg, i guess compile flag is not working as expected

image

the integration test fails here and logs does not contain something about Babel, and generating react-template test also failing currently investgating it

reference of test taken from this

@derberg
Copy link
Member

derberg commented May 20, 2024

/update

Copy link
Member

@derberg derberg left a 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

@@ -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
Copy link
Member

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 🤔

debug: true,
});

const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
Copy link
Member

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));

const outputDir = generateFolderName();
const generator = new Generator('@asyncapi/html-template@2.3.0', outputDir, {
forceWrite: true,
compile: false,
Copy link
Member

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

Copy link

sonarcloud bot commented May 22, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@Gmin2
Copy link
Collaborator Author

Gmin2 commented May 22, 2024

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

i am confused here, so do we need to add integration test or do we just need to add test in generator.test.js

cc @derberg

Copy link

sonarcloud bot commented Jun 20, 2024

@derberg
Copy link
Member

derberg commented Jun 24, 2024

i am confused here, so do we need to add integration test or do we just need to add test in generator.test.js

just try with suggestion to add log and test for it - if it will work, no integration test is needed

@Gmin2
Copy link
Collaborator Author

Gmin2 commented Jun 29, 2024

@derberg any idea why workflow is failing? (idk why test seems to fail)

@Gmin2
Copy link
Collaborator Author

Gmin2 commented Jul 1, 2024

Hey @derberg when i run locally, with compile true then it works perfectly
image

but dont know why test is failing
image

Copy link
Member

@derberg derberg left a 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)

apps/generator/lib/renderer/react.js Outdated Show resolved Hide resolved
apps/generator/test/generator.test.js Outdated Show resolved Hide resolved
apps/generator/test/generator.test.js Outdated Show resolved Hide resolved
apps/generator/test/integration.test.js Outdated Show resolved Hide resolved
apps/generator/test/integration.test.js Outdated Show resolved Hide resolved
@derberg
Copy link
Member

derberg commented Jul 29, 2024

@Gmin2 your tests are still failing

Copy link

changeset-bot bot commented Jul 31, 2024

🦋 Changeset detected

Latest commit: 834b3cc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/generator Minor

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

@derberg
Copy link
Member

derberg commented Aug 11, 2024

@Gmin2 any progress?

@@ -59,5 +63,7 @@ module.exports = {
templateSuccessfullyInstalled,
relativeSourceFileNotGenerated,
conditionalFilesMatched,
compileEnabled,
compileEnabled,
Copy link
Member

Choose a reason for hiding this comment

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

doubled export

@@ -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')
Copy link
Member

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

Copy link

sonarcloud bot commented Aug 26, 2024

@derberg
Copy link
Member

derberg commented Aug 26, 2024

@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

@derberg
Copy link
Member

derberg commented Aug 26, 2024

/rtm

@asyncapi-bot asyncapi-bot merged commit 46114d8 into asyncapi:master Aug 26, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Archive
Development

Successfully merging this pull request may close these issues.

React templates make generation process longer
4 participants