Skip to content

Commit 64d6a82

Browse files
authored
Adds support for argument passing to "yarn init <initializer>" (#6709)
## What's the problem this PR addresses? The `yarn init <package>` syntax works, but not `yarn init <package> [...options]`. ## How did you fix it? I split the `init` command in two, with the second one having a proxy option to consume whatever follows the first required positional argument. ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent 32184d9 commit 64d6a82

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

.yarn/versions/11405fb3.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-init": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-interactive-tools"
11+
- "@yarnpkg/plugin-nm"
12+
- "@yarnpkg/plugin-npm-cli"
13+
- "@yarnpkg/plugin-pack"
14+
- "@yarnpkg/plugin-patch"
15+
- "@yarnpkg/plugin-pnp"
16+
- "@yarnpkg/plugin-pnpm"
17+
- "@yarnpkg/plugin-stage"
18+
- "@yarnpkg/plugin-typescript"
19+
- "@yarnpkg/plugin-version"
20+
- "@yarnpkg/plugin-workspace-tools"
21+
- "@yarnpkg/builder"
22+
- "@yarnpkg/core"
23+
- "@yarnpkg/doctor"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {Option} from 'clipanion';
2+
3+
import InitCommand from './init';
4+
5+
// eslint-disable-next-line arca/no-default-export
6+
export default class InitInitializerCommand extends InitCommand {
7+
static paths = [
8+
[`init`],
9+
];
10+
11+
initializer = Option.String();
12+
argv = Option.Proxy();
13+
14+
async initialize() {
15+
this.context.stdout.write(`\n`);
16+
17+
await this.cli.run([`dlx`, this.initializer, ...this.argv], {
18+
quiet: true,
19+
});
20+
}
21+
}

packages/plugin-init/sources/commands/init.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ export default class InitCommand extends BaseCommand {
5555
description: `Initialize a package with the given name`,
5656
});
5757

58-
initializer = Option.String({
59-
required: false,
60-
});
61-
6258
// Options that only mattered on v1
6359
usev2 = Option.Boolean(`-2`, false, {hidden: true});
6460
yes = Option.Boolean(`-y,--yes`, {hidden: true});
@@ -117,6 +113,9 @@ export default class InitCommand extends BaseCommand {
117113
});
118114
}
119115

116+
async initialize() {
117+
}
118+
120119
async executeRegular(configuration: Configuration) {
121120
let existingProject: Project | null = null;
122121
try {
@@ -254,13 +253,7 @@ export default class InitCommand extends BaseCommand {
254253
quiet: true,
255254
});
256255

257-
if (this.initializer) {
258-
this.context.stdout.write(`\n`);
259-
260-
await this.cli.run([`dlx`, this.initializer], {
261-
quiet: true,
262-
});
263-
}
256+
await this.initialize();
264257

265258
if (!xfs.existsSync(ppath.join(this.context.cwd, `.git`))) {
266259
await execUtils.execvp(`git`, [`init`], {

packages/plugin-init/sources/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {Plugin, SettingsType} from '@yarnpkg/core';
22

3+
import InitInitializerCommand from './commands/init-initializer';
34
import InitCommand from './commands/init';
45

5-
export {InitCommand};
6+
export {InitCommand, InitInitializerCommand};
67

78
declare module '@yarnpkg/core' {
89
interface ConfigurationValueMap {
@@ -38,6 +39,7 @@ const plugin: Plugin = {
3839
},
3940
commands: [
4041
InitCommand,
42+
InitInitializerCommand,
4143
],
4244
};
4345

0 commit comments

Comments
 (0)