Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves yarn init #6703

Merged
merged 5 commits into from
Feb 26, 2025
Merged
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
34 changes: 17 additions & 17 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions .pnp.loader.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions .yarn/versions/b075d05f.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
releases:
"@yarnpkg/cli": minor
"@yarnpkg/plugin-init": minor

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/pnp"
24 changes: 19 additions & 5 deletions packages/plugin-init/sources/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export default class InitCommand extends BaseCommand {
description: `Initialize a package with the given name`,
});

initializer = Option.String({
required: false,
});

// Options that only mattered on v1
usev2 = Option.Boolean(`-2`, false, {hidden: true});
yes = Option.Boolean(`-y,--yes`, {hidden: true});
Expand Down Expand Up @@ -180,6 +184,10 @@ export default class InitCommand extends BaseCommand {
`!.yarn/sdks`,
`!.yarn/versions`,
``,
`# Whether you use PnP or not, the node_modules folder is often used to store`,
`# build artifacts that should be gitignored`,
`node_modules`,
``,
`# Swap the comments on the following lines if you wish to use zero-installs`,
`# In that case, don't forget to run \`yarn config set enableGlobalCache false\`!`,
`# Documentation here: https://yarnpkg.com/features/caching#zero-installs`,
Expand Down Expand Up @@ -217,13 +225,11 @@ export default class InitCommand extends BaseCommand {

const editorConfigProperties = {
[`*`]: {
endOfLine: `lf`,
insertFinalNewline: true,
},
[`*.{js,json,yml}`]: {
charset: `utf-8`,
indentStyle: `space`,
endOfLine: `lf`,
indentSize: 2,
indentStyle: `space`,
insertFinalNewline: true,
},
};

Expand All @@ -248,6 +254,14 @@ export default class InitCommand extends BaseCommand {
quiet: true,
});

if (this.initializer) {
this.context.stdout.write(`\n`);

await this.cli.run([`dlx`, this.initializer], {
quiet: true,
});
}

if (!xfs.existsSync(ppath.join(this.context.cwd, `.git`))) {
await execUtils.execvp(`git`, [`init`], {
cwd: this.context.cwd,
Expand Down
Loading
Loading