ForestAdmin / lumber

Install Forest Admin in minutes.
https://www.forestadmin.com
MIT License
2.08k stars 106 forks source link

[*] Command Generate - Validate and fix the package name in `package.json` to prevent error on generated server startup #371

Closed rap2hpoutre closed 4 years ago

rap2hpoutre commented 4 years ago

Description

This fix avoids an error on project startup when project name is not allowed as a package name.

It uses the official validate-npm-package-name created by NPM team to validate the project name. If the validation fails, it tries to transform the string to something that works (since slugify is not sufficient and I did not found a lib, I created a grumpy transformer that disallow almost everything when validation fails).

Side note about tests

(see: https://forestadmin.slack.com/archives/GAZF5Q5RV/p1577712751015700)

I can not have created a unit test about the new created function in a utils directory because it's already used by tests' utils; migrating the existing system is not that simple (see Slack discussion). We have to find a way to do that, but since we don't like to mix subject in one PR, I have to postpone this one. That's why I named the test file test/utils-to-valid-package-name.test.js (it should have been test/utils/to-valid-package-name.test.js). See this Trello card about this side note: https://trello.com/c/FaSVaFbY/2169-lumber-move-test-helpers-out-of-test-utils-folder

rap2hpoutre commented 4 years ago

P2 - Lumber - An "invalid" project name prevent the generated server to start.