Skip to content

Commit af8c021

Browse files
authoredJan 23, 2024
feat(init): add --yarn-config-options option (#2273)
* feat(init): add `--yarn-config-options` option * docs: mention `--yarn-config-options`
1 parent 42acc27 commit af8c021

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed
 

‎docs/commands.md

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ Skip git repository initialization.
126126

127127
Replaces the directory if it already exists
128128

129+
#### `--yarn-config-options <string>`
130+
131+
Passes extra options that will be added to `.yarnrc.yml` file, format: key=value,key2=value2.
132+
129133
### `upgrade`
130134

131135
Usage:

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

+13
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,18 @@ export default {
6060
name: '--replace-directory [boolean]',
6161
description: 'Replaces the directory if it already exists.',
6262
},
63+
{
64+
name: '--yarn-config-options <string>',
65+
description:
66+
'Passes extra options that will be added to `.yarnrc.yml` file, format: key=value,key2=value2.',
67+
parse: (val: string): Record<string, string> => {
68+
return Object.fromEntries(
69+
val.split(',').map((option) => {
70+
const [key, value] = option.split('=');
71+
return [key, value];
72+
}),
73+
);
74+
},
75+
},
6376
],
6477
};

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

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type Options = {
5252
platformName?: string;
5353
skipGitInit?: boolean;
5454
replaceDirectory?: string | boolean;
55+
yarnConfigOptions?: Record<string, string>;
5556
};
5657

5758
interface TemplateOptions {
@@ -67,6 +68,7 @@ interface TemplateOptions {
6768
installCocoaPods?: string | boolean;
6869
version?: string;
6970
replaceDirectory?: string | boolean;
71+
yarnConfigOptions?: Record<string, string>;
7072
}
7173

7274
interface TemplateReturnType {
@@ -199,6 +201,7 @@ async function createFromTemplate({
199201
packageName,
200202
installCocoaPods,
201203
replaceDirectory,
204+
yarnConfigOptions,
202205
}: TemplateOptions): Promise<TemplateReturnType> {
203206
logger.debug('Initializing new project');
204207
// Only print out the banner if we're not in a CI
@@ -244,6 +247,7 @@ async function createFromTemplate({
244247
templateUri,
245248
templateSourceDir,
246249
packageManager,
250+
yarnConfigOptions,
247251
);
248252

249253
loader.succeed();
@@ -419,6 +423,7 @@ async function createProject(
419423
installCocoaPods: options.installPods,
420424
version,
421425
replaceDirectory: options.replaceDirectory,
426+
yarnConfigOptions: options.yarnConfigOptions,
422427
});
423428
}
424429

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

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export async function installTemplatePackage(
2020
templateName: string,
2121
root: string,
2222
packageManager: PackageManager.PackageManager,
23+
yarnConfigOptions?: Record<string, string>,
2324
) {
2425
logger.debug(`Installing template from ${templateName}`);
2526

@@ -47,6 +48,13 @@ export async function installTemplatePackage(
4748
['config', 'set', 'nmHoistingLimits', 'workspaces'],
4849
options,
4950
);
51+
52+
for (let key in yarnConfigOptions) {
53+
if (yarnConfigOptions.hasOwnProperty(key)) {
54+
let value = yarnConfigOptions[key];
55+
executeCommand('yarn', ['config', 'set', key, value], options);
56+
}
57+
}
5058
}
5159

5260
return PackageManager.install([templateName], {

0 commit comments

Comments
 (0)
Please sign in to comment.