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

fix: improve flow in init command on higher Yarn versions #1931

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as PackageManager from '../../tools/packageManager';
import {installPods} from '@react-native-community/cli-doctor';
import banner from './banner';
import TemplateAndVersionError from './errors/TemplateAndVersionError';
import addNodeLinker from '../../tools/addNodeLinker';

const DEFAULT_VERSION = 'latest';

Expand Down Expand Up @@ -163,6 +164,10 @@ async function installDependencies({
}) {
loader.start('Installing dependencies');

if (!npm) {
addNodeLinker(root);
}

szymonrybczak marked this conversation as resolved.
Show resolved Hide resolved
await PackageManager.installAll({
preferYarn: !npm,
silent: true,
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/commands/init/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import copyFiles from '../../tools/copyFiles';
import replacePathSepForRegex from '../../tools/replacePathSepForRegex';
import fs from 'fs';
import chalk from 'chalk';
import addNodeLinker from '../../tools/addNodeLinker';

export type TemplateConfig = {
placeholderName: string;
Expand All @@ -27,6 +28,10 @@ export async function installTemplatePackage(
root,
});

if (!npm) {
addNodeLinker(root);
}

return PackageManager.install([templateName], {
preferYarn: !npm,
silent: true,
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/tools/addNodeLinker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from 'path';
import fs from 'fs';

/**
Creates a `.yarnrc.yml` file in the root of the project to force Yarn to use the `node-modules` linker, because React Native doesn't support the Plug'n'Play node linker.
*/

const addNodeLinker = (root: string) => {
const yarnrcFileContent = 'nodeLinker: node-modules\n';

fs.writeFileSync(path.join(root, '.yarnrc.yml'), yarnrcFileContent, {
szymonrybczak marked this conversation as resolved.
Show resolved Hide resolved
encoding: 'utf8',
flag: 'w',
});
};

export default addNodeLinker;