Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ build/
coverage
*.env
.parcel-cache
.yarn/
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
38 changes: 38 additions & 0 deletions __e2e__/init.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 8 additions & 6 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -321,10 +324,9 @@ 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: ${
(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 {
Expand Down
14 changes: 8 additions & 6 deletions packages/cli/src/commands/init/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down