Skip to content

feat: declare generated Node.js version - #9

Open
teleginzhenya wants to merge 5 commits into
mainfrom
feat/generate-nvmrc
Open

feat: declare generated Node.js version#9
teleginzhenya wants to merge 5 commits into
mainfrom
feat/generate-nvmrc

Conversation

@teleginzhenya

@teleginzhenya teleginzhenya commented Jul 29, 2026

Copy link
Copy Markdown

Summary

  • generate a .nvmrc file with Node.js v24 for every scaffolded project
  • declare "engines": {"node": "24.x"} in the generated package.json
  • derive both values from one shared Node.js major-version constant
  • document the new generated file
  • cover the generated Node.js version with a unit test

Testing

  • npm test (85 tests)
  • npx tsc --noEmit
  • npm run lint -- --fix
  • npm run lint:prettier
  • npm run knip
  • npm run build
  • packaged CLI dry run

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

@teleginzhenya
teleginzhenya requested a review from ogonkov as a code owner July 29, 2026 09:45
@sourcery-ai

sourcery-ai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR updates the base project generator to always scaffold a .nvmrc file pinned to Node.js v24, documents the new file in the generated project layout, and adds a unit test plus a Handlebars template to ensure the Node version is written consistently.

File-Level Changes

Change Details Files
Base generator now writes a .nvmrc file containing Node.js v24 for every scaffolded project.
  • Import a new .nvmrc Handlebars template into the base generator.
  • Write a .nvmrc file to the project root during base generation using the template.
src/generators/base.ts
src/generators/templates/.nvmrc.hbs
Added test coverage to verify .nvmrc generation and contents.
  • Add a test ensuring the base generator creates .nvmrc.
  • Assert that .nvmrc content is exactly 'v24\n' to match the repository's Node.js version.
src/generators/base.test.ts
Documented .nvmrc in the scaffolded project layout.
  • Include .nvmrc in the README’s scaffolded file tree.
  • Update the README Handlebars template so generated documentation also lists .nvmrc.
README.md
scripts/readme/readme.hbs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The Node.js version is hardcoded in both the .nvmrc template (v24) and the test ('v24\n'); consider sourcing this from a single shared constant or config (e.g., a central version module or package.json engines field) to avoid future drift.
  • Ensure the .nvmrc template matches the exact formatting asserted in tests (including trailing newline), or update the test to read the desired output via the same render helper, so formatting changes in one place don’t silently diverge.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The Node.js version is hardcoded in both the `.nvmrc` template (`v24`) and the test (`'v24\n'`); consider sourcing this from a single shared constant or config (e.g., a central version module or `package.json` engines field) to avoid future drift.
- Ensure the `.nvmrc` template matches the exact formatting asserted in tests (including trailing newline), or update the test to read the desired output via the same render helper, so formatting changes in one place don’t silently diverge.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ogonkov

ogonkov commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

In initial rfc @korvin89 asked to remove nvmrc generation step

@teleginzhenya

Copy link
Copy Markdown
Author

we can discuss it here, now it is not obvious which node version is should be used. it is described only in https://github.com/gravity-ui/create#requirements, however this might be requirements for this repo. i see no issue about adding .nvmrc, also there is no engines in package.json

@teleginzhenya teleginzhenya changed the title feat: generate Node version file feat: declare generated Node.js version Jul 29, 2026
@korvin89

Copy link
Copy Markdown

In initial rfc @korvin89 asked to remove nvmrc generation step

To be honest, I don't remember saying that, but if I did, I don't remember the reasons anymore. It seems like a good suggestion

Comment thread src/generators/base.ts Outdated
private: true,
...(isModule ? {type: 'module'} : {}),
engines: {
node: `${NODE_VERSION_MAJOR}.x`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use just ^${NODE_VERSION_MAJOR}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/utils/constants.ts Outdated
@@ -1 +1,2 @@
export const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org/';
export const NODE_VERSION_MAJOR = 24;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to add additional step with prompt for user to input nodejs version

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we need minimum version here, and maybe add validation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ogonkov ogonkov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to test validation of passing generic string as --node-version value like --node-version=foobar24

Comment thread src/cli/schema.ts Outdated
),

'node-version': z
.enum(SUPPORTED_NODE_VERSIONS)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it string, i don't think we want to maintain all future Node majors

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants