Skip to content

Commit

Permalink
chore: set npm as default package manager to init (#2503)
Browse files Browse the repository at this point in the history
* set npm as default package manager to init

* update docs
  • Loading branch information
TMisiukiewicz authored Sep 23, 2024
1 parent a414d98 commit 90945e6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
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 @@ function createCustomTemplateFiles() {

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 @@ test('init skips installation of dependencies with --skip-install', () => {

expect(dirFiles).toEqual(
customTemplateCopiedFiles.filter(
(file) => !['node_modules', 'yarn.lock'].includes(file),
(file) => !['node_modules', 'package-lock.json'].includes(file),
),
);
});
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 @@ -19,7 +19,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 @@ -207,8 +207,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 the project with the name already has cache, remove the cache to avoid problems with pods installation
Expand Down

0 comments on commit 90945e6

Please sign in to comment.