Skip to content

Commit 6b8607c

Browse files
authored
fix: remove automatic config file generation (#2203)
1 parent 772880f commit 6b8607c

File tree

4 files changed

+2
-115
lines changed

4 files changed

+2
-115
lines changed

__e2e__/__snapshots__/config.test.ts.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ exports[`shows up current config without unnecessary output 1`] = `
8181
},
8282
"project": {
8383
"ios": {
84-
"sourceDir": "<<REPLACED_ROOT>>/TestProject/ios",
85-
"automaticPodsInstallation": true
84+
"sourceDir": "<<REPLACED_ROOT>>/TestProject/ios"
8685
},
8786
"android": {
8887
"sourceDir": "<<REPLACED_ROOT>>/TestProject/android",

__e2e__/config.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,12 @@ beforeAll(() => {
5252
writeFiles(DIR, {});
5353

5454
// Initialise React Native project
55-
runCLI(DIR, ['init', 'TestProject']);
55+
runCLI(DIR, ['init', 'TestProject', '--install-pods']);
5656

5757
// Link CLI to the project
5858
spawnScript('yarn', ['link', ...addRNCPrefix(packages)], {
5959
cwd: path.join(DIR, 'TestProject'),
6060
});
61-
62-
// Install pods after linking packages because Podfile uses `use_native_modules` function that executes `config` command. In case there was introduce breaking change in `cli-config` package, it will fail since it will be using old version of the package.
63-
spawnScript('pod', ['install'], {
64-
cwd: path.join(DIR, 'TestProject', 'ios'),
65-
});
6661
});
6762

6863
afterAll(() => {

__e2e__/init.test.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const customTemplateCopiedFiles = [
2626
'file',
2727
'node_modules',
2828
'package.json',
29-
'react-native.config.js',
3029
'yarn.lock',
3130
];
3231

@@ -194,41 +193,3 @@ test('init --platform-name should work for out of tree platform', () => {
194193

195194
expect(dirFiles.length).toBeGreaterThan(0);
196195
});
197-
198-
test('should not create custom config file if installed version is below 0.73', () => {
199-
createCustomTemplateFiles();
200-
201-
runCLI(DIR, ['init', PROJECT_NAME, '--skip-install', '--version', '0.72.0']);
202-
203-
let dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME));
204-
205-
expect(dirFiles).not.toContain('react-native.config.js');
206-
});
207-
208-
test('should create custom config file if installed version is latest (starting from 0.73)', () => {
209-
createCustomTemplateFiles();
210-
211-
runCLI(DIR, ['init', PROJECT_NAME, '--skip-install']);
212-
213-
let dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME));
214-
215-
expect(dirFiles).toContain('react-native.config.js');
216-
const fileContent = fs.readFileSync(
217-
path.join(DIR, PROJECT_NAME, 'react-native.config.js'),
218-
'utf8',
219-
);
220-
221-
const configFileContent = `
222-
module.exports = {
223-
project: {
224-
ios: {
225-
automaticPodsInstallation: true
226-
}
227-
}
228-
}`;
229-
230-
//normalize all white-spaces for easier comparision
231-
expect(fileContent.replace(/\s+/g, '')).toEqual(
232-
configFileContent.replace(/\s+/g, ''),
233-
);
234-
});

packages/cli/src/commands/init/init.ts

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import {getNpmVersionIfAvailable} from '../../tools/npm';
2929
import {getYarnVersionIfAvailable} from '../../tools/yarn';
3030
import {createHash} from 'crypto';
3131
import createGitRepository from './createGitRepository';
32-
import deepmerge from 'deepmerge';
33-
import semver from 'semver';
3432

3533
const DEFAULT_VERSION = 'latest';
3634

@@ -114,7 +112,6 @@ async function createFromTemplate({
114112
skipInstall,
115113
packageName,
116114
installCocoaPods,
117-
version,
118115
}: TemplateOptions) {
119116
logger.debug('Initializing new project');
120117
logger.log(banner);
@@ -178,15 +175,6 @@ async function createFromTemplate({
178175
packageName,
179176
});
180177

181-
const coerceRnVersion = semver.valid(semver.coerce(version));
182-
183-
if (
184-
version === 'latest' ||
185-
(coerceRnVersion && semver.satisfies(coerceRnVersion, '>=0.73.0'))
186-
) {
187-
createDefaultConfigFile(projectDirectory, loader);
188-
}
189-
190178
const {postInitScript} = templateConfig;
191179
if (postInitScript) {
192180
loader.info('Executing post init script ');
@@ -289,62 +277,6 @@ function createTemplateUri(options: Options, version: string): string {
289277
return options.template || `${platform}@${version}`;
290278
}
291279

292-
//remove quotes from object keys to match the linter rules of the template
293-
function sanitizeConfigFile(fileContent: string) {
294-
return fileContent.replace(/"([^"]+)":/g, '$1:');
295-
}
296-
297-
/*
298-
Starting from 0.73, react-native.config.js is created by CLI during the init process.
299-
It contains automaticPodsInstallation flag set to true by default.
300-
This flag is used by CLI to determine whether to install CocoaPods dependencies when running ios commands or not.
301-
It's created by CLI rather than being a part of a template to avoid displaying this file in the Upgrade Helper,
302-
as it might bring confusion for existing projects where this change might not be applicable.
303-
For more details, see https://github.com/react-native-community/cli/blob/main/docs/projects.md#projectiosautomaticpodsinstallation
304-
*/
305-
function createDefaultConfigFile(directory: string, loader: Loader) {
306-
const cliConfigContent = {
307-
project: {
308-
ios: {
309-
automaticPodsInstallation: true,
310-
},
311-
},
312-
};
313-
const configFileContent = `module.exports = ${JSON.stringify(
314-
cliConfigContent,
315-
null,
316-
2,
317-
)}`;
318-
const filepath = 'react-native.config.js';
319-
try {
320-
if (!doesDirectoryExist(path.join(directory, filepath))) {
321-
fs.writeFileSync(filepath, sanitizeConfigFile(configFileContent), {
322-
encoding: 'utf-8',
323-
});
324-
} else {
325-
const existingConfigFile = require(path.join(directory, filepath));
326-
327-
const mergedConfig = deepmerge(existingConfigFile, cliConfigContent);
328-
const output = `module.exports = ${JSON.stringify(
329-
mergedConfig,
330-
null,
331-
2,
332-
)};`;
333-
334-
fs.writeFileSync(filepath, sanitizeConfigFile(output), {
335-
encoding: 'utf-8',
336-
});
337-
}
338-
loader.succeed();
339-
} catch {
340-
loader.warn(
341-
`Could not create custom ${chalk.bold(
342-
'react-native.config.js',
343-
)} file. You can create it manually in your project's root folder with the following content: \n\n${configFileContent}`,
344-
);
345-
}
346-
}
347-
348280
async function createProject(
349281
projectName: string,
350282
directory: string,

0 commit comments

Comments
 (0)