From 300eb8786128c164674538941a58285bad52ef34 Mon Sep 17 00:00:00 2001 From: Aziz Becha Date: Fri, 26 Dec 2025 07:59:10 +0100 Subject: [PATCH 1/4] chore: bump husky --- .husky/pre-commit | 3 --- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 5a182ef10..372362317 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - yarn lint-staged diff --git a/package.json b/package.json index 30bfa7a88..d016882f9 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "eslint-plugin-import": "^2.25.3", "execa": "^5.0.0", "fast-glob": "^3.3.2", - "husky": "^8.0.2", + "husky": "^9.1.7", "jest": "^26.6.2", "jest-circus": "^26.6.2", "jest-snapshot-serializer-raw": "^1.1.0", diff --git a/yarn.lock b/yarn.lock index 1a746bc1c..09cccd258 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5609,10 +5609,10 @@ humanize-ms@^1.2.1: dependencies: ms "^2.0.0" -husky@^8.0.2: - version "8.0.2" - resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.2.tgz#5816a60db02650f1f22c8b69b928fd6bcd77a236" - integrity sha512-Tkv80jtvbnkK3mYWxPZePGFpQ/tT3HNSs/sasF9P2YfkMezDl3ON37YN6jUUI4eTg5LcyVynlb6r4eyvOmspvg== +husky@^9.1.7: + version "9.1.7" + resolved "https://registry.yarnpkg.com/husky/-/husky-9.1.7.tgz#d46a38035d101b46a70456a850ff4201344c0b2d" + integrity sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA== iconv-lite@0.4.24, iconv-lite@^0.4.24: version "0.4.24" From 7f3e5ccbcbb783356a2506e1cbc7d4c56f1c8852 Mon Sep 17 00:00:00 2001 From: Aziz Becha Date: Fri, 26 Dec 2025 08:18:22 +0100 Subject: [PATCH 2/4] fix: add leading newline to Cocoapods installation error message --- packages/cli/src/commands/init/init.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 954afb0c7..c84df80b3 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -321,7 +321,7 @@ async function createFromTemplate({ } } catch (error) { logger.error( - `Installing Cocoapods failed. This doesn't affect project initialization and you can safely proceed. However, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n\nError: ${ + `\nInstalling Cocoapods failed. This doesn't affect project initialization and you can safely proceed. However, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n\nError: ${ (error as Error).message as string }\n`, ); From c4a04a9b9da1cf815fb179810efd11add0994155 Mon Sep 17 00:00:00 2001 From: Aziz Becha Date: Fri, 26 Dec 2025 08:23:02 +0100 Subject: [PATCH 3/4] fix: separate Cocoapods installation error message to avoid conflict --- packages/cli/src/commands/init/init.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index c84df80b3..efa36bda6 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -321,10 +321,9 @@ async function createFromTemplate({ } } catch (error) { logger.error( - `\nInstalling Cocoapods failed. This doesn't affect project initialization and you can safely proceed. However, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n\nError: ${ - (error as Error).message as string - }\n`, + `\nInstalling Cocoapods failed. This doesn't affect project initialization and you can safely proceed. However, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n`, ); + logger.error((error as Error).message as string); } } } else { From 57ac6a7ec5e62b2f5a318b092f38a30e5a6a3bef Mon Sep 17 00:00:00 2001 From: Aziz Becha Date: Fri, 26 Dec 2025 09:57:03 +0100 Subject: [PATCH 4/4] fix: support specifying --pm yarn and --skip-install together --- .gitignore | 1 + __e2e__/init.test.ts | 38 ++++++++++++++++++++++ package.json | 2 +- packages/cli/src/commands/init/init.ts | 11 ++++--- packages/cli/src/commands/init/template.ts | 14 ++++---- 5 files changed, 55 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 86a849d07..a028a7858 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ build/ coverage *.env .parcel-cache +.yarn/ \ No newline at end of file diff --git a/__e2e__/init.test.ts b/__e2e__/init.test.ts index 8d8564e13..b337056ad 100644 --- a/__e2e__/init.test.ts +++ b/__e2e__/init.test.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import path from 'path'; +import execa from 'execa'; import {runCLI, getTempDirectory, cleanup, writeFiles} from '../jest/helpers'; import slash from 'slash'; @@ -43,6 +44,15 @@ if (process.platform === 'win32') { templatePath = `file://${templatePath}`; } +function isYarnAvailable() { + try { + execa.sync('yarn', ['--version'], {stdio: 'pipe'}); + return true; + } catch (error) { + return false; + } +} + test('init fails if the directory already exists and --replace-directory false', () => { fs.mkdirSync(path.join(DIR, PROJECT_NAME)); @@ -152,6 +162,34 @@ test('init skips installation of dependencies with --skip-install', () => { ); }); +test('init supports --pm yarn together with --skip-install', () => { + if (!isYarnAvailable()) { + return; + } + + createCustomTemplateFiles(); + + const {stdout, stderr} = runCLI(DIR, [ + 'init', + '--template', + templatePath, + PROJECT_NAME, + '--pm', + 'yarn', + '--skip-install', + ]); + + expect(stderr).not.toContain(`Couldn't find the "`); + expect(stdout).toContain('Run instructions'); + + const dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME)).sort(); + const expectedFiles = customTemplateCopiedFiles + .filter((file) => !['node_modules', 'package-lock.json'].includes(file)) + .concat(['.yarn', '.yarnrc.yml']) + .sort(); + expect(dirFiles).toEqual(expectedFiles); +}); + // 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', () => { createCustomTemplateFiles(); diff --git a/package.json b/package.json index d016882f9..9c2769c63 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "link-packages": "node ./scripts/linkPackages.js", "publish": "yarn build-clean-all && yarn install && lerna publish --force-publish", "publish:next": "yarn build-clean-all && yarn install && lerna publish --force-publish --dist-tag next", - "prepare": "husky install" + "prepare": "husky" }, "devDependencies": { "@babel/core": "^7.0.0", diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index efa36bda6..20be2d731 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -281,12 +281,12 @@ async function createFromTemplate({ if (process.platform === 'darwin') { const installPodsValue = String(installCocoaPods); - const reactNativePath = path.dirname( - require.resolve('react-native', {paths: [projectDirectory]}), - ); try { if (installPodsValue === 'true') { + const reactNativePath = path.dirname( + require.resolve('react-native', {paths: [projectDirectory]}), + ); didInstallPods = true; await runCodegen({ root: projectDirectory, @@ -308,6 +308,9 @@ async function createFromTemplate({ didInstallPods = installCocoapods; if (installCocoapods) { + const reactNativePath = path.dirname( + require.resolve('react-native', {paths: [projectDirectory]}), + ); await runCodegen({ root: projectDirectory, platform: 'ios', @@ -321,7 +324,7 @@ async function createFromTemplate({ } } catch (error) { logger.error( - `\nInstalling Cocoapods failed. This doesn't affect project initialization and you can safely proceed. However, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n`, + '\nInstalling Cocoapods failed. This doesn\'t affect project initialization and you can safely proceed. However, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n', ); logger.error((error as Error).message as string); } diff --git a/packages/cli/src/commands/init/template.ts b/packages/cli/src/commands/init/template.ts index dcc21fd12..7ec4b9841 100644 --- a/packages/cli/src/commands/init/template.ts +++ b/packages/cli/src/commands/init/template.ts @@ -37,22 +37,24 @@ export async function installTemplatePackage( }; // React Native doesn't support PnP, so we need to set nodeLinker to node-modules. Read more here: https://github.com/react-native-community/cli/issues/27#issuecomment-1772626767 - executeCommand( + await executeCommand( 'yarn', ['config', 'set', 'nodeLinker', 'node-modules'], options, ); - executeCommand( + await executeCommand( 'yarn', ['config', 'set', 'nmHoistingLimits', 'workspaces'], options, ); - for (let key in yarnConfigOptions) { - if (yarnConfigOptions.hasOwnProperty(key)) { - let value = yarnConfigOptions[key]; - executeCommand('yarn', ['config', 'set', key, value], options); + if (yarnConfigOptions) { + for (let key in yarnConfigOptions) { + if (Object.prototype.hasOwnProperty.call(yarnConfigOptions, key)) { + const value = yarnConfigOptions[key]; + await executeCommand('yarn', ['config', 'set', key, value], options); + } } } }