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

react-native-windows-init generates invalid namespace names in idl files when app has - in name #13426

Closed
acoates-ms opened this issue Jul 9, 2024 · 3 comments · Fixed by #13566
Assignees
Labels
Area: CLI Developer First Experience Issues that are going to be hit by a new developer as they first try out RNW enhancement
Milestone

Comments

@acoates-ms
Copy link
Contributor

Hit this while starting from a default expo app, which is named: my-app.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) label Jul 9, 2024
@acoates-ms
Copy link
Contributor Author

We should also look at making react-native-windows-init handle expo apps. The steps are relatively minor:

Add a separate package.json script for "start-windows": "react-native start" (Runs the normal non-expo bundler)

Add a devDependency for: (Exact version to use will depend on RN version)
"@react-native/metro-config": "0.74.85"

Ensure the ComponentName in MainPage.xaml gets set to something (it ended up blank in my experiements)

Create a index.windows.tsx file at the root with something like (use same component name as used in MainPage.xaml:

import React from 'react';
import {AppRegistry, Text, View} from 'react-native';
 
const App = () => {
    return (<View><Text style={{color:"red"}}>Hello world</Text></View>);
}
 
AppRegistry.registerComponent('MyApp', () => App);

@chrisglein chrisglein added enhancement Area: CLI Developer First Experience Issues that are going to be hit by a new developer as they first try out RNW labels Jul 11, 2024
@jonthysell jonthysell self-assigned this Jul 18, 2024
@jonthysell jonthysell removed the Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) label Jul 18, 2024
@jonthysell jonthysell added this to the Next milestone Jul 18, 2024
@jonthysell
Copy link
Contributor

react-native-windows-init is going to be deprecated - does it repro with init-windows?

@jonthysell jonthysell added the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Jul 18, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the no-recent-activity Issue/PR has gone stale and may be closed (label applied by bot) label Jul 25, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed this from the Next milestone Aug 1, 2024
@jonthysell
Copy link
Contributor

Re-activating this as I think my PR will actually fix it.

@jonthysell jonthysell reopened this Aug 13, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-recent-activity Issue/PR has gone stale and may be closed (label applied by bot) label Aug 13, 2024
@jonthysell jonthysell added this to the 0.75 milestone Aug 13, 2024
@jonthysell jonthysell removed the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Aug 13, 2024
jonthysell added a commit to jonthysell/react-native-windows that referenced this issue Aug 26, 2024
Backport PR microsoft#13566 to 0.75.

## 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 deprecated `react-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:
1. Verify that a string specified with `--name` or `--namespace` is valid, or else error out.
2. If an item isn't specified, do our best to determine the value from `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 from `package.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
- Bug fix (non-breaking change which fixes an issue)

### 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 microsoft#13558
Closes microsoft#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.75] Improve new project name(space) validation and cleaning
jonthysell added a commit to jonthysell/react-native-windows that referenced this issue Aug 26, 2024
Backport PR microsoft#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 deprecated `react-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:
1. Verify that a string specified with `--name` or `--namespace` is valid, or else error out.
2. If an item isn't specified, do our best to determine the value from `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 from `package.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
- Bug fix (non-breaking change which fixes an issue)

### 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 microsoft#13558
Closes microsoft#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
jonthysell added a commit that referenced this issue Aug 27, 2024
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 deprecated `react-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:
1. Verify that a string specified with `--name` or `--namespace` is valid, or else error out.
2. If an item isn't specified, do our best to determine the value from `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 from `package.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
- Bug fix (non-breaking change which fixes an issue)

### 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
jonthysell added a commit that referenced this issue Aug 27, 2024
Backport PR #13566 to 0.75.

## 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 deprecated `react-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:
1. Verify that a string specified with `--name` or `--namespace` is valid, or else error out.
2. If an item isn't specified, do our best to determine the value from `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 from `package.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
- Bug fix (non-breaking change which fixes an issue)

### 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.75] Improve new project name(space) validation and cleaning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CLI Developer First Experience Issues that are going to be hit by a new developer as they first try out RNW enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants