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

fix(cli): change to lowercase the project name type by the user #6540

Conversation

javiersantossanchez
Copy link

for the project generator, when the user uses a project name with uppercase letters, the project can not be created because npm packages have validation to no allow create packages with uppercase letters

The prompt was updated to add a function to transform the values typed by the user to the lowercase version and use this value as the project name

Fixes #1663
#1663

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

Signed-off-by: javier santos javier.david.santos@gmail.com

@bajtos
Copy link
Member

bajtos commented Oct 12, 2020

@javiersantossanchez thank you for the pull request. Please add a test to verify the new behavior.

Could you also please fix the commit message to follow our Commit message guidelines? Travis CI is complaining about too long lines:

https://travis-ci.com/github/strongloop/loopback-next/jobs/397830225#L232

⧗   input: fix(cli): change to lowercase the project name type by the user

for the project generator, when the user use a project name with uppercase letters, the project can not be create because npm packages has a validation to no allow create packages with uppercase letters.
The prompt was update to add a function to transform the values typed by the user to lowercase version and use this value as the project name.

Signed-off-by: javier santos <javier.david.santos@gmail.com>
✖   body's lines must not be longer than 100 characters [body-max-line-length]

If you are not familiar with history rewriting, you want to run git commit --amend to edit the commit message and then git push --force-with-lease to rewrite the history on GitHub. See also https://loopback.io/doc/en/lb4/submitting_a_pr.html#9-final-rebase-and-squashing-of-commits

I'll leave it up to code owners (@emonddr @agnes512) to review your proposed changes and merge the pull request once is ready.

for the project generator, when the user use a project name with uppercase letters,
the project can not be create because npm packages has a validation to no allow create packages
with uppercase letters, the prompt was update to add a function to transform the values typed
by the user to lowercase version and use this value as the project name.

Signed-off-by: javier santos <javier.david.santos@gmail.com>
@javiersantossanchez javiersantossanchez force-pushed the fix-avoid-use-of-uppercase-on-project-generator branch from 983a82a to e707abd Compare October 12, 2020 14:57
@javiersantossanchez
Copy link
Author

@bajtos, I update the commit message, and now there is no warning on the validation. Thank you for your comment about how to update the commit message.

I tried to create some unit tests, But I do not find a way to implement a unit test to evaluate functions on prompts using yeoman-generators.

If you can help me to understand how I can test my changes. I would be happy to add some tests.

@agnes512
Copy link
Contributor

Thank you for the PR! Could you add a test to verify the changes? I think this file is a good place for it.

@javiersantossanchez
Copy link
Author

javiersantossanchez commented Oct 13, 2020

Hi @agnes512 agnes512. Yes, I am trying to test my changes on the prompt configuration. Actually what I did was add a filter and transformer function (as is defined in the api https://github.com/SBoudrias/Inquirer.js). My approach was to add those functions to change any value enter by the used to uppercase value, the output of the prompt is already a lowercase value.
the problem is that the unit test using yeoman-test library looks like there is a missing feature with the test of the prompt. you can use mock to set values as user imput. but the functions defined on the prompt like (validate, filter or transformer ) are no executed (I found 2 links talking about it yeoman/yeoman-test#1 , yeoman/generator#775). The approach proposed is to create the functions in a separate object and testing separately. In this case, the library used for the lowercase is https://github.com/blakeembrey/change-case/tree/master/packages/lower-case . and the library has a unit test for the function used.

Actually I try to add this test. but the transformer function is no called. the idea is verify that when the user type "fooBar" the output should be "foobar"

 describe('promptProjectName', () => {
      it('Change to lowercase the project name', () => {
        const gen = testUtils.testSetUpGen(projGenerator);
        return testPrompt(
          gen,
          {
            name: 'fooBar',
            description: 'foobar description',
          },
          'promptProjectName',
        ).then(() => {
          gen.prompt.restore();
          assert(gen.projectInfo.name);
          assert(gen.projectInfo.name === 'foobar');
        });
      });
    });

I not sure if there is something more I can do, to complete the test. I feel that a test is missing to verify that the prompt resturns the right value when the user key uppercase letters.

@bajtos
Copy link
Member

bajtos commented Oct 13, 2020

I am trying to test my changes on the prompt configuration. Actually what I did was add a filter and transformer function (as is defined in the api https://github.com/SBoudrias/Inquirer.js). My approach was to add those functions to change any value enter by the used to uppercase value, the output of the prompt is already a lowercase value.
the problem is that the unit test using yeoman-test library looks like there is a missing feature with the test of the prompt. you can use mock to set values as user imput. but the functions defined on the prompt like (validate, filter or transformer ) are no executed (I found 2 links talking about it yeoman/yeoman-test#1 , yeoman/generator#775). The approach proposed is to create the functions in a separate object and testing separately. In this case, the library used for the lowercase is https://github.com/blakeembrey/change-case/tree/master/packages/lower-case . and the library has a unit test for the function used.

Oh, I forgot again how difficult it is to test Yeoman prompts 😠 (Ref #844).

I am fine to land these changes with no automated tests then.

@bajtos
Copy link
Member

bajtos commented Oct 13, 2020

@javiersantossanchez I ran your feature branch and it seems like your solution is not fixing the problem. Does it work as intended on your machine?

$ lb4 app
? Project name: FooBarAsd
>> Invalid npm package name: FooBarAsd

@javiersantossanchez javiersantossanchez force-pushed the fix-avoid-use-of-uppercase-on-project-generator branch from 8223d70 to 570eaea Compare October 13, 2020 14:26
@javiersantossanchez
Copy link
Author

javiersantossanchez commented Oct 13, 2020

@javiersantossanchez I ran your feature branch and it seems like your solution is not fixing the problem. Does it work as intended on your machine?

$ lb4 app
? Project name: FooBarAsd
>> Invalid npm package name: FooBarAsd

Hi @bajtos , Yes I tested :-( . I think that I test my initial approach (use a regular toLower() function) then I change to use the lowerCase function on utils.js file, maybe I do not clean my test and I just run my previous approach. Sorry about it.

Well, you are right, my commit was not working, I found a problem with the import of lowerCase function. I fix it on the utils.js, I found no one else is using this function.

And sorry again for my mistake in testing my change.

the lowercase function is no exported on change-case package
as the official documentation https://github.com/blakeembrey/change-case shows

Signed-off-by: javier santos <javier.david.santos@gmail.com>
@javiersantossanchez javiersantossanchez force-pushed the fix-avoid-use-of-uppercase-on-project-generator branch from 60901d2 to 6d3e764 Compare October 14, 2020 04:44
method created for tes on development

Signed-off-by: javier santos <javier.david.santos@gmail.com>
@javiersantossanchez javiersantossanchez force-pushed the fix-avoid-use-of-uppercase-on-project-generator branch from 6d3e764 to ae40a85 Compare October 14, 2020 05:17
Copy link
Contributor

@agnes512 agnes512 left a comment

Choose a reason for hiding this comment

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

Tested on my machine, and it works 👍 I have one suggestion in terms of UX. Would it be better to have a hint that the project name will be transformed to lowercase? In case some users are not 100% familiar with npm/yarn. Feel free to ignore though 😄

@dhmlau
Copy link
Member

dhmlau commented Oct 24, 2020

Would it be better to have a hint that the project name will be transformed to lowercase?

+1. When trying out this new CLI behavior, I have to confess that I didn't look through the code and expecting I'll receive an warning (as mentioned in #6540 (comment)). Personally I'd prefer to have CLI giving warning about invalid name or case.

@stale
Copy link

stale bot commented Dec 25, 2020

This pull request has been marked stale because it has not seen activity within two months. It will be closed within 14 days of being stale unless there is new activity.

@stale stale bot added the stale label Dec 25, 2020
@agnes512 agnes512 removed the stale label Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CLI] lb4 does not create app with uppercase letters
4 participants