From 6047ab7fd901036d1676a9fc8c926f9c2544932a Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Tue, 23 Jan 2024 16:56:25 +0100 Subject: [PATCH 1/2] feat(init): add `--yarn-config-options` option --- packages/cli/src/commands/init/index.ts | 13 +++++++++++++ packages/cli/src/commands/init/init.ts | 5 +++++ packages/cli/src/commands/init/template.ts | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/packages/cli/src/commands/init/index.ts b/packages/cli/src/commands/init/index.ts index 54e81700d..28b4273a4 100644 --- a/packages/cli/src/commands/init/index.ts +++ b/packages/cli/src/commands/init/index.ts @@ -60,5 +60,18 @@ export default { name: '--replace-directory [boolean]', description: 'Replaces the directory if it already exists.', }, + { + name: '--yarn-config-options ', + description: + 'Passes extra options that will be added to `.yarnrc.yml` file, format: key=value,key2=value2.', + parse: (val: string): Record => { + return Object.fromEntries( + val.split(',').map((option) => { + const [key, value] = option.split('='); + return [key, value]; + }), + ); + }, + }, ], }; diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 5d3ac8fe5..0d912c6b3 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -52,6 +52,7 @@ type Options = { platformName?: string; skipGitInit?: boolean; replaceDirectory?: string | boolean; + yarnConfigOptions?: Record; }; interface TemplateOptions { @@ -67,6 +68,7 @@ interface TemplateOptions { installCocoaPods?: string | boolean; version?: string; replaceDirectory?: string | boolean; + yarnConfigOptions?: Record; } interface TemplateReturnType { @@ -199,6 +201,7 @@ async function createFromTemplate({ packageName, installCocoaPods, replaceDirectory, + yarnConfigOptions, }: TemplateOptions): Promise { logger.debug('Initializing new project'); // Only print out the banner if we're not in a CI @@ -244,6 +247,7 @@ async function createFromTemplate({ templateUri, templateSourceDir, packageManager, + yarnConfigOptions, ); loader.succeed(); @@ -419,6 +423,7 @@ async function createProject( installCocoaPods: options.installPods, version, replaceDirectory: options.replaceDirectory, + yarnConfigOptions: options.yarnConfigOptions, }); } diff --git a/packages/cli/src/commands/init/template.ts b/packages/cli/src/commands/init/template.ts index a3b6d9987..ee2adb537 100644 --- a/packages/cli/src/commands/init/template.ts +++ b/packages/cli/src/commands/init/template.ts @@ -20,6 +20,7 @@ export async function installTemplatePackage( templateName: string, root: string, packageManager: PackageManager.PackageManager, + yarnConfigOptions?: Record, ) { logger.debug(`Installing template from ${templateName}`); @@ -47,6 +48,13 @@ export async function installTemplatePackage( ['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); + } + } } return PackageManager.install([templateName], { From 36bdf2ae2e81bb5dff59b06286dc9082f88879d8 Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Tue, 23 Jan 2024 17:03:37 +0100 Subject: [PATCH 2/2] docs: mention `--yarn-config-options` --- docs/commands.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/commands.md b/docs/commands.md index 9c845f6d7..8d783128a 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -126,6 +126,10 @@ Skip git repository initialization. Replaces the directory if it already exists +#### `--yarn-config-options ` + +Passes extra options that will be added to `.yarnrc.yml` file, format: key=value,key2=value2. + ### `upgrade` Usage: