From d0f7c9ba0a4a812db5ae696c4daf5d15247d63df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Wed, 13 Dec 2023 10:09:00 +0100 Subject: [PATCH] fix: remove automatic config file generation --- __e2e__/init.test.ts | 38 -------------- packages/cli/src/commands/init/init.ts | 68 -------------------------- 2 files changed, 106 deletions(-) diff --git a/__e2e__/init.test.ts b/__e2e__/init.test.ts index 9804c32ed7..d5c4391cc1 100644 --- a/__e2e__/init.test.ts +++ b/__e2e__/init.test.ts @@ -194,41 +194,3 @@ test('init --platform-name should work for out of tree platform', () => { expect(dirFiles.length).toBeGreaterThan(0); }); - -test('should not create custom config file if installed version is below 0.73', () => { - createCustomTemplateFiles(); - - runCLI(DIR, ['init', PROJECT_NAME, '--skip-install', '--version', '0.72.0']); - - let dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME)); - - expect(dirFiles).not.toContain('react-native.config.js'); -}); - -test('should create custom config file if installed version is latest (starting from 0.73)', () => { - createCustomTemplateFiles(); - - runCLI(DIR, ['init', PROJECT_NAME, '--skip-install']); - - let dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME)); - - expect(dirFiles).toContain('react-native.config.js'); - const fileContent = fs.readFileSync( - path.join(DIR, PROJECT_NAME, 'react-native.config.js'), - 'utf8', - ); - - const configFileContent = ` - module.exports = { - project: { - ios: { - automaticPodsInstallation: true - } - } - }`; - - //normalize all white-spaces for easier comparision - expect(fileContent.replace(/\s+/g, '')).toEqual( - configFileContent.replace(/\s+/g, ''), - ); -}); diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 46c81a3d2e..ee68fbf0a7 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -29,8 +29,6 @@ import {getNpmVersionIfAvailable} from '../../tools/npm'; import {getYarnVersionIfAvailable} from '../../tools/yarn'; import {createHash} from 'crypto'; import createGitRepository from './createGitRepository'; -import deepmerge from 'deepmerge'; -import semver from 'semver'; const DEFAULT_VERSION = 'latest'; @@ -114,7 +112,6 @@ async function createFromTemplate({ skipInstall, packageName, installCocoaPods, - version, }: TemplateOptions) { logger.debug('Initializing new project'); logger.log(banner); @@ -178,15 +175,6 @@ async function createFromTemplate({ packageName, }); - const coerceRnVersion = semver.valid(semver.coerce(version)); - - if ( - version === 'latest' || - (coerceRnVersion && semver.satisfies(coerceRnVersion, '>=0.73.0')) - ) { - createDefaultConfigFile(projectDirectory, loader); - } - const {postInitScript} = templateConfig; if (postInitScript) { loader.info('Executing post init script '); @@ -289,62 +277,6 @@ function createTemplateUri(options: Options, version: string): string { return options.template || `${platform}@${version}`; } -//remove quotes from object keys to match the linter rules of the template -function sanitizeConfigFile(fileContent: string) { - return fileContent.replace(/"([^"]+)":/g, '$1:'); -} - -/* -Starting from 0.73, react-native.config.js is created by CLI during the init process. -It contains automaticPodsInstallation flag set to true by default. -This flag is used by CLI to determine whether to install CocoaPods dependencies when running ios commands or not. -It's created by CLI rather than being a part of a template to avoid displaying this file in the Upgrade Helper, -as it might bring confusion for existing projects where this change might not be applicable. -For more details, see https://github.com/react-native-community/cli/blob/main/docs/projects.md#projectiosautomaticpodsinstallation -*/ -function createDefaultConfigFile(directory: string, loader: Loader) { - const cliConfigContent = { - project: { - ios: { - automaticPodsInstallation: true, - }, - }, - }; - const configFileContent = `module.exports = ${JSON.stringify( - cliConfigContent, - null, - 2, - )}`; - const filepath = 'react-native.config.js'; - try { - if (!doesDirectoryExist(path.join(directory, filepath))) { - fs.writeFileSync(filepath, sanitizeConfigFile(configFileContent), { - encoding: 'utf-8', - }); - } else { - const existingConfigFile = require(path.join(directory, filepath)); - - const mergedConfig = deepmerge(existingConfigFile, cliConfigContent); - const output = `module.exports = ${JSON.stringify( - mergedConfig, - null, - 2, - )};`; - - fs.writeFileSync(filepath, sanitizeConfigFile(output), { - encoding: 'utf-8', - }); - } - loader.succeed(); - } catch { - loader.warn( - `Could not create custom ${chalk.bold( - 'react-native.config.js', - )} file. You can create it manually in your project's root folder with the following content: \n\n${configFileContent}`, - ); - } -} - async function createProject( projectName: string, directory: string,