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

Added support to customizable the projectFileExtensions. #19550

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

oliveryasuna
Copy link
Contributor

Description

Please see the issue.

Fixes #19527

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended. NOT APPLICABLE?
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

@oliveryasuna oliveryasuna marked this pull request as draft June 11, 2024 01:12
@mcollovati mcollovati added the Contribution PRs coming from the community or external to the team label Jun 11, 2024
@mshabarov mshabarov requested review from mcollovati and removed request for mshabarov June 17, 2024 11:52
@vaadin-bot
Copy link
Collaborator

TC Format Checker Report - 03:56 - 18 - Jun

BLOCKER There are 2 files with format errors

  • To see a complete report of formatting issues, download the differences file

  • To fix the build, please run mvn formatter:format in your branch and commit the changes.

  • Optionally you might add the following line in your .git/hooks/pre-commit file:

    mvn formatter:format
    

Here is the list of files with format issues in your PR:

flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/FlowModeAbstractMojo.java
flow-server/src/main/java/com/vaadin/flow/server/frontend/Options.java

@caalador
Copy link
Contributor

The dev-bundle-plugin also needs to implement the new projectFileExtensions() method

Error:  /home/runner/work/flow/flow/flow-plugins/flow-dev-bundle-plugin/src/main/java/com/vaadin/flow/plugin/maven/BuildDevBundleMojo.java:[80,8] com.vaadin.flow.plugin.maven.BuildDevBundleMojo is not abstract and does not override abstract method projectFileExtensions() in com.vaadin.flow.plugin.base.PluginAdapterBase

Also it feels like the extensions should be an addition to the existing and not replacing the list of extensions.

Copy link
Collaborator

@mcollovati mcollovati left a comment

Choose a reason for hiding this comment

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

A couple of comments:

  • I agree with @caalador that the configurable extensions should be added to the default list and should not replace them.
  • it would be better to define the default extensions in a single place instead of having duplication in Maven and Gradle plugin. FrontendUtils class could be a good host.
  • I know that in the Vite configuration file, the constant is named projectFileExtensions, but IMO it doesn't sound like a good name for a plugin setting. What about frontendFileExtensions? Could it be a better name?

@oliveryasuna
Copy link
Contributor Author

A couple of comments:

* I agree with @caalador that the configurable extensions should be added to the default list and should not replace them.

* it would be better to define the default extensions in a single place instead of having duplication in Maven and Gradle plugin. `FrontendUtils` class could be a good host.

* I know that in the Vite configuration file, the constant is named `projectFileExtensions`, but IMO it doesn't sound like a good name for a plugin setting. What about `frontendFileExtensions`? Could it be a better name?

I agree with everything and will make changes later. Thanks for considering this!

@oliveryasuna oliveryasuna marked this pull request as ready for review June 24, 2024 13:11
Copy link
Collaborator

@mcollovati mcollovati left a comment

Choose a reason for hiding this comment

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

The implementation seems broken because of a missing comma in placeholder replacement.
I also suggest adding a couple of tests in TaskUpdateViteTest like the following one

    @Test
    public void generatedTemplate_extraFrontendExtension_addedToViteConfiguration()
            throws IOException {
        options.withExtraProjectFileExtensions(List.of(".svg", ".ico"));
        TaskUpdateVite task = new TaskUpdateVite(options, null);
        task.execute();

        File configFile = new File(temporaryFolder.getRoot(),
                FrontendUtils.VITE_GENERATED_CONFIG);

        String template = IOUtils.toString(configFile.toURI(),
                StandardCharsets.UTF_8);

        Assert.assertTrue(
                "Extra frontend extensions should be added to vite configuration, but was not.",
                template.contains(
                        "const projectFileExtensions = ['.js', '.js.map', '.ts', '.ts.map', '.tsx', '.tsx.map', '.css', '.css.map', '.svg', '.ico'];"));
    }

Comment on lines +139 to +140
return "'" + StringEscapeUtils.escapeJava(ext)
+ "'";
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like to me that StringEscapeUtils.escapeJava does not escape single quotes, that is the only replacement that we need (e.g. ext.replace("'", "\\'")).

} catch (Exception e) {
throw new RuntimeException(e);
}
}).collect(Collectors.joining(", ")));
Copy link
Collaborator

Choose a reason for hiding this comment

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

The result of this string seems not correct; it will be appended to the existing list without a coma.

const projectFileExtensions = ['.js', '.js.map', '.ts', '.ts.map', '.tsx', '.tsx.map', '.css', '.css.map''.svg', '.ico'];

An option could be the following, for example

        String extraExtension = "";
        if (options.getExtraProjectFileExtensions() != null
                && !options.getExtraProjectFileExtensions().isEmpty()) {
            extraExtension = 
                    Optional.ofNullable(options.getExtraProjectFileExtensions())
                            .orElse(Collections.emptyList()).stream()
                            .map(ext -> ext.replace("'", "\\'"))
                            .collect(Collectors.joining("', '", ", '", "'"));
        }
        template = template.replace("#extraProjectFileExtensions#", extraExtension);

* Hashes are calculated for these files as part of detecting if a new prod
* bundle should be generated.
*/
public abstract val extraProjectFileExtensions: ListProperty<String>
Copy link
Collaborator

@mcollovati mcollovati Jul 1, 2024

Choose a reason for hiding this comment

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

I'm still not convinced by the setting name. It still seems too generic to me.
I mean, the purpose is to add extension for frontend files that should be considered, not overall project files.
I propose something like frontendExtraFileExtensions or frontendAdditionalFileExtensions

@mshabarov what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

frontendExtraFileExtensions sounds like a good name, or frontendBuildExtraFileExtensions may be even more descriptive for developer.

Copy link
Collaborator

@mcollovati mcollovati left a comment

Choose a reason for hiding this comment

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

Additional note: it would probably make sense that configuration setting does not require the extension to start with a dot. I would prefer a configuration like

<extraProjectFileExtensions>
   <extraProjectFileExtension>svg</extraProjectFileExtension>
   <extraProjectFileExtension>ico</extraProjectFileExtension>
</extraProjectFileExtensions>

rather than

<extraProjectFileExtensions>
   <extraProjectFileExtension>.svg</extraProjectFileExtension>
   <extraProjectFileExtension>.ico</extraProjectFileExtension>
</extraProjectFileExtensions>

It would be better if the dot would be automatically added at runtime, if not already defined in configuration.

Comment on lines +331 to +333
* Get the list of project file extensions.
*
* @return list of project file extensions
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add a note on the expected extension format here (e.g. no initial dot) with a simple example list.

@@ -232,6 +233,9 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo
@Parameter(property = InitParameters.REACT_ENABLE, defaultValue = "${null}")
private Boolean reactEnable;

@Parameter(defaultValue = "${null}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add a property attribute named for example frontend.extraFileExtensions so that it could be specified also on the command line

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, the field needs Javadoc. IIRC they are used for maven goal documentation

* The list of extra file extensions that are considered project files.
* Hashes are calculated for these files as part of detecting if a new prod
* bundle should be generated.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add a note on expected extension format and a simple example list.


/**
* Sets the extra project file extensions.
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to provide additional detail on the expected extension format and perhaps a simple example

@mcollovati
Copy link
Collaborator

@oliveryasuna let me know if you need help in setting up the tests or if you have any doubts

@mshabarov mshabarov self-requested a review August 5, 2024 11:48
@mshabarov mshabarov removed their request for review September 9, 2024 06:26
@mcollovati
Copy link
Collaborator

@oliveryasuna are you still interested in/do you have time to complete this PR?
Otherwise, the Flow team can take care of and mention you as a co-author.

@oliveryasuna
Copy link
Contributor Author

@oliveryasuna are you still interested in/do you have time to complete this PR? Otherwise, the Flow team can take care of and mention you as a co-author.

Hey @mcollovati, sorry, it is completely fell off my radar. If the flow team could finish it off, that would be great! This will allow us and many to simplify our build process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contribution PRs coming from the community or external to the team +0.0.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include .scss and .sass in stats.json hashes
5 participants