Skip to content

Commit

Permalink
Improves yarn init (#6703)
Browse files Browse the repository at this point in the history
## What's the problem this PR addresses?

I often find myself doing the same things in every project I create, I
figure some of them could be improved in `yarn init`.

## How did you fix it?

- Widens the editorconfig configuration (otherwise it doesn't cover ts,
tsx, jsx, css, less, etc).
- Add `node_modules` as a gitignored path, regardless whether we're in
PnP mode or not.
- Add `--deps` and `--dev-deps` to add specific dependencies directly
during the project init.

## 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.
  • Loading branch information
arcanis authored Feb 26, 2025
1 parent 547a669 commit 47bca70
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 33 deletions.
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

0 comments on commit 47bca70

Please sign in to comment.