Skip to content

Commit fa77014

Browse files
dannyhwdanstepanov
authored andcommitted
fix: generating projects with yarn
1 parent 6bb3254 commit fa77014

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

.changeset/cold-rivers-tell.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'create-expo-stack': patch
3+
'rn-new': patch
4+
---
5+
6+
fixes for yarn project generations

bun.lockb

136 Bytes
Binary file not shown.

cli/src/templates/base/package.json.ejs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,8 @@
186186
<% if (props.navigationPackage?.name !== "expo-router") { %>
187187
"main": "node_modules/expo/AppEntry.js",
188188
<% } %>
189-
"private": true
189+
"private": true,
190+
<% if (props.packageManager === "yarn"){ %>
191+
"packageManager": "[email protected]"
192+
<% } %>
190193
}

cli/src/utilities/getPackageManager.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ export function getDefaultPackageManagerVersion() {
8383
}
8484

8585
export function getVersionForPackageManager(packageManager: PackageManager): string {
86-
const version = require('child_process').execSync(`${packageManager} --version`);
86+
try {
87+
const version = require('child_process').execSync(`${packageManager} --version`);
8788

88-
return version.toString().replace('\n', '');
89+
return version.toString().replace('\n', '');
90+
} catch (_error) {
91+
// this happens with yarn because its dumb
92+
console.log(`Error getting version for package manager ${packageManager}`);
93+
return 'unknown';
94+
}
8995
}

cli/src/utilities/printOutput.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { outro, spinner } from '@clack/prompts';
22
import { Toolbox } from 'gluegun/build/types/domain/toolbox';
3+
import os from 'os';
34
import { AvailablePackages, CliResults } from '../types';
45
import { copyBaseAssets } from './copyBaseAssets';
6+
import { generateNWUI } from './generateNWUI';
57
import { getPackageManager, getPackageManagerRunnerX } from './getPackageManager';
68
import { easConfigure } from './runEasConfigure';
79
import { ONLY_ERRORS, runSystemCommand } from './systemCommand';
8-
import { generateNWUI } from './generateNWUI';
9-
import os from 'os';
10+
import { appendFile, writeFile } from 'fs/promises';
11+
12+
const yarnRcFixes = `
13+
enableGlobalCache: false
14+
15+
nodeLinker: node-modules`;
1016

1117
export async function printOutput(
1218
cliResults: CliResults,
@@ -47,6 +53,21 @@ export async function printOutput(
4753

4854
const additionalFlags = isNpm ? '--silent --no-audit --progress=false --legacy-peer-deps' : '--silent';
4955

56+
if (packageManager === 'yarn') {
57+
// create empty yarn.lock to stop yarn from complaining
58+
await writeFile(`${projectName}/yarn.lock`, '');
59+
60+
// apply fixes to .yarnrc.yml to stop issues with PnP and caching
61+
await appendFile(`${projectName}/.yarnrc.yml`, yarnRcFixes);
62+
63+
await runSystemCommand({
64+
toolbox,
65+
command: `cd ${projectName} && yarn set version stable`,
66+
stdio: ONLY_ERRORS,
67+
errorMessage: 'Error setting yarn version'
68+
});
69+
}
70+
5071
await runSystemCommand({
5172
toolbox,
5273
command: `cd ${projectName} && ${packageManager} install ${additionalFlags}`,

0 commit comments

Comments
 (0)