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

feat: allow initialising project with custom package name with init --package-name #1808

Merged

Conversation

TMisiukiewicz
Copy link
Collaborator

Summary:

Closes #1269
Relates to #1111

Added --package-name option to init command, which allows initialising project with custom package name for Android and iOS.

Test Plan:

Use init command with --package-name option:

  1. If package name is incorrect e.g. it contains any special chars except dots or have only one segment it should end up with error. Examples: example, [email protected]
  2. Initialise project with --package-name example.app - project should be initialised with com.example.app Android package name and iOS bundleID
  3. Initialise project with --package-name com.example.app - project should be initialised with com.example.app Android package name and iOS bundleID

For 2. and 3., app should be installed on the device/emulator named by project name - not package name.

@thymikee
Copy link
Member

Can we have some tests for this?

name: '--package-name <string>',
description:
'Inits a project with a custom package name (Android) and bundle ID (iOS), e.g. com.example.app',
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add this to docs 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done ✅

Copy link
Collaborator

@szymonrybczak szymonrybczak left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@github-actions github-actions bot added the docs Documentation change label Jan 25, 2023
@TMisiukiewicz
Copy link
Collaborator Author

Can we have some tests for this?

tests added ✅

Copy link
Collaborator

@adamTrz adamTrz left a comment

Choose a reason for hiding this comment

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

🚀

Comment on lines 134 to 147
fs.rename(
`${filePath}/${segmentsList.join('.')}`,
`${filePath}/${segmentsList[segmentsList.length - 1]}`,
);

for (const segment of segmentsList) {
fs.mkdirSync(segment);
process.chdir(segment);
}

fs.rename(
`${filePath}/${segmentsList[segmentsList.length - 1]}`,
process.cwd(),
);
Copy link
Member

Choose a reason for hiding this comment

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

Those renames can fail and createAndroidPackagePaths also isn't guarded by try/catch, so the user would be left blind when fs.rename throws. Please make sure to guard this case

@thymikee thymikee changed the title feat: allow initialising project with custom package name feat: allow initialising project with custom package name with init --package-name Jan 27, 2023
Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Left one comment and looks good. Thanks for the test! :)

@TMisiukiewicz TMisiukiewicz merged commit 309be23 into react-native-community:main Jan 30, 2023
@TMisiukiewicz TMisiukiewicz deleted the feat/package-name branch January 30, 2023 09:34
@bryanprimus
Copy link

can we have an example for this?

I tried this

npx react-native@latest init [APP_NAME] --package-name [PACKAGE_NAME] --title [APP_TITLE]

but it doesn't work

@szymonrybczak
Copy link
Collaborator

Hey @bryanltobing, what error you get if you try this command? And also could you please provide output from npx react-native@latest -v just to make sure that you're working on correct version 😅

@bryanprimus
Copy link

it does work now. sorry for the inconvenient

@javier8340
Copy link

packages only can start by "com"? can be changed as user sets? for example if domain start with "org" or by country domain

@TMisiukiewicz
Copy link
Collaborator Author

hi @javier8340, it was fixed in #1915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation change feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for bundleid/packagename when initializing a new app
6 participants