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

chore: set npm as default package manager to init #2503

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions __e2e__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@

const customTemplateCopiedFiles = [
'.git',
'.yarn',
'.yarnrc.yml', // .yarnrc.yml for Yarn versions >= 2.0.0
'dir',
'file',
'node_modules',
'package-lock.json',
'package.json',
'yarn.lock',
];

beforeEach(() => {
Expand Down Expand Up @@ -150,7 +147,7 @@

expect(dirFiles).toEqual(
customTemplateCopiedFiles.filter(
(file) => !['node_modules', 'yarn.lock'].includes(file),
(file) => !['node_modules', 'package-lock.json'].includes(file),
),
);
});
Expand Down Expand Up @@ -194,7 +191,7 @@
});

// react-native-macos stopped shipping `template.config.js` for 0.75, so this test is disabled. in future releases we should re-enable once `template.config.js` will be there again.
test.skip('init --platform-name should work for out of tree platform', () => {

Check warning on line 194 in __e2e__/init.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Disabled test
createCustomTemplateFiles();
const outOfTreePlatformName = 'react-native-macos';

Expand Down
6 changes: 3 additions & 3 deletions docs/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ There are couple of ways to initialize new React Native projects.
npx react-native@latest init ProjectName
```

> Note: If you have both `yarn` and `npm` installed on your machine, React Native CLI will always try to use `yarn`, so even if you use `npx` utility, only `react-native` executable will be installed using `npm` and the rest of the work will be delegated to `yarn`. You can force usage of `npm` adding `--pm npm` flag to the command.
> Note: If you have both `yarn` and `npm` installed on your machine, React Native CLI will always try to use `npm`. You can force usage of `yarn` by adding `--pm yarn` flag to the command.

> Note: for Yarn users, `yarn dlx` command similar to `npx` will be featured in Yarn 2.0: <https://github.com/yarnpkg/berry/pull/40> so we'll be able to use it in a similar fashion.

Expand Down Expand Up @@ -49,10 +49,10 @@ npx react-native@latest init ProjectName --template ${TEMPLATE_NAME}
npx react-native@${VERSION} init ProjectName --template ${TEMPLATE_NAME}
```

You can force usage of `npm` if you have both `yarn` and `npm` installed on your machine:
You can force usage of `yarn` if you have both `yarn` and `npm` installed on your machine:

```sh
npx react-native@latest init ProjectName --pm npm
npx react-native@latest init ProjectName --pm yarn
```

## Creating custom template
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
{
name: '--pm <string>',
description:
'Use specific package manager to initialize the project. Available options: `yarn`, `npm`, `bun`. Default: `yarn`',
'Use specific package manager to initialize the project. Available options: `yarn`, `npm`, `bun`. Default: `npm`',
},
{
name: '--directory <string>',
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ async function createFromTemplate({
packageManager = pm;
} else {
const userAgentPM = userAgentPackageManager();
// if possible, use the package manager from the user agent. Otherwise fallback to default (yarn)
packageManager = userAgentPM || 'yarn';
// if possible, use the package manager from the user agent. Otherwise fallback to default (npm)
packageManager = userAgentPM || 'npm';
}

if (npm) {
Expand Down
Loading