[0.74] Improve new project name(space) validation and cleaning #13616
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport PR #13566 to 0.74.
Description
This PR moves all of the logic concerning validating and cleaning project names when creating new projects (via the
init-windows
CLI command or the soon to be deprecatedreact-native-windows-init
command) into one shared location with unit tests. It also updates the cleaning logic to handle package scopes (i.e.@org/package
) and better apply cleaning to packages with hyphens (i.e.my-package
).Going forward, when creating (new or old arch) projects with
init-windows
, the flow will still to adhere the following rules:--name
or--namespace
is valid, or else error out.package.json
, etc., and clean that value if necessary.When using
react-native-windows-init
, (which still only lets you specify the--namespace
, and always figures out name frompackage.json
, etc.), the flow will be mostly the same as before, where both name and namespace will be cleaned automatically if invalid, rather than erroring out. (However the consolidated cleaning logic should mean an improvement when using tools other than the RN CLI for creating your initial RN project).Type of Change
Why
The rules for what constitutes a "valid" name for a RN project has changed over the years with each of the different tools that are used to create RN projects. This PR is an attempt to both broaden the number of supported new project tools while also ensuring RNW still produces usable native code.
Closes #13558
Closes #13426
What
Moved all name(space) logic into a new
nameHelpers
module, exposed them to existing callers, and created unit tests.Screenshots
N/A
Testing
Add new tests for nameHelpers.
Changelog
Should this change be included in the release notes: yes
[0.74] Improve new project name(space) validation and cleaning
Microsoft Reviewers: Open in CodeFlow