Skip to content

Commit 932858a

Browse files
Revert "Prevent 'yarnpkg not found' error from displaying to users."
This reverts commit a52eac9. Reset last commit
1 parent ef41178 commit 932858a

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

create-react-native-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-react-native-app",
3-
"version": "0.0.6",
3+
"version": "0.0.5",
44
"description": "Create React Native apps with no build configuration.",
55
"license": "BSD-3-Clause",
66
"keywords": ["react-native", "react"],

create-react-native-app/src/index.js

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,6 @@ if (commands.length === 0) {
4040

4141
createApp(commands[0], !!argv.verbose, argv['scripts-version']).then(() => {});
4242

43-
// use yarn if it's available, otherwise use npm
44-
function shouldUseYarn() {
45-
try {
46-
const result = spawn.sync('yarnpkg', ['--version'], { stdio: 'ignore' });
47-
if (result.error || result.status !== 0) {
48-
return false;
49-
}
50-
return true;
51-
} catch (e) {
52-
return false;
53-
}
54-
}
55-
5643
async function createApp(name: string, verbose: boolean, version: ?string): Promise<void> {
5744
const root = path.resolve(name);
5845
const appName = path.basename(root);
@@ -91,37 +78,45 @@ function install(
9178
verbose: boolean,
9279
callback: (code: number, command: string, args: Array<string>) => Promise<void>
9380
): void {
94-
const useYarn = shouldUseYarn();
95-
let args, cmd, result;
96-
97-
if (useYarn) {
98-
cmd = 'yarnpkg';
99-
args = ['add'];
81+
let args = ['add', '--dev', '--exact', '--ignore-optional', packageToInstall];
82+
const proc = spawn('yarnpkg', args, { stdio: 'inherit' });
10083

101-
if (verbose) {
102-
args.push('--verbose');
84+
let yarnExists = true;
85+
proc.on('error', function(err) {
86+
if (err.code === 'ENOENT') {
87+
yarnExists = false;
10388
}
89+
});
10490

105-
args = args.concat(['--dev', '--exact', '--ignore-optional', packageToInstall]);
106-
result = spawn.sync(cmd, args, { stdio: 'inherit' });
107-
} else {
91+
proc.on('close', function(code) {
92+
if (yarnExists) {
93+
callback(code, 'yarnpkg', args).then(
94+
() => {},
95+
e => {
96+
throw e;
97+
}
98+
);
99+
return;
100+
}
101+
// No Yarn installed, continuing with npm.
108102
args = ['install'];
109103

110104
if (verbose) {
111105
args.push('--verbose');
112106
}
113-
cmd = 'npm';
114-
args = args.concat(['--save-dev', '--save-exact', packageToInstall]);
115107

116-
result = spawn.sync(cmd, args, { stdio: 'inherit' });
117-
}
108+
args = args.concat(['--save-dev', '--save-exact', packageToInstall]);
118109

119-
callback(result.status, cmd, args).then(
120-
() => {},
121-
e => {
122-
throw e;
123-
}
124-
);
110+
const npmProc = spawn('npm', args, { stdio: 'inherit' });
111+
npmProc.on('close', function(code) {
112+
callback(code, 'npm', args).then(
113+
() => {},
114+
e => {
115+
throw e;
116+
}
117+
);
118+
});
119+
});
125120
}
126121

127122
async function run(

0 commit comments

Comments
 (0)