Skip to content

Conversation

@ndelangen
Copy link
Member

@ndelangen ndelangen commented Sep 19, 2025

What I did

When we dropped fs-extra and used native writeFile, it stopped having a newline at the end of package.json This causes issues during the release PRs

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Chores
    • Standardized package metadata file formatting by ensuring a trailing newline is added when version bump scripts update package.json, improving cross-tool compatibility and reducing noisy diffs.
  • Style
    • Enforced POSIX-style newline at end of package.json files generated by release scripts for consistent formatting across environments.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

Walkthrough

Adds a trailing newline to JSON writes in scripts/release/version.ts within bumpCodeVersion, bumpDeferred, and applyDeferredVersionBump. JSON content unchanged; only file termination gains a newline. No changes to control flow, logging, or exported interfaces.

Changes

Cohort / File(s) Summary
Release script JSON write formatting
scripts/release/version.ts
Append '\n' after JSON.stringify(...) when writing code/package.json in three functions: bumpCodeVersion, bumpDeferred, applyDeferredVersionBump. No logic changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

Hop, tap—newline at the end,
A tidy file, my faithful friend.
Carrots aligned, bytes in a row,
I nudge the JSON—then I go.
With one soft hop, I seal the deal:
A final newline—perfect feel. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately captures the primary change in the diff: adding a trailing newline to package.json output produced by the release/version scripts. The provided summaries show JSON.stringify(...) writes were changed to append '\n' in three locations, which matches the title. The phrasing is clear, specific, and appropriate for a commit/PR title that a teammate can quickly understand.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch norbert/add-end-of-file-newline-to-packagejson

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Comment @coderabbitai help to get the list of available commands and usage tips.

@ndelangen ndelangen changed the title Fix: Ensure newline at the end of JSON output in version bump scripts Release: Ensure newline at the end of package.json Sep 19, 2025
@ndelangen ndelangen added build Internal-facing build tooling & test updates ci:docs Run the CI jobs for documentation checks only. labels Sep 19, 2025
@ndelangen ndelangen self-assigned this Sep 19, 2025
@ndelangen ndelangen merged commit 50ed0dd into next Sep 19, 2025
12 of 19 checks passed
@ndelangen ndelangen deleted the norbert/add-end-of-file-newline-to-packagejson branch September 19, 2025 09:39
@nx-cloud
Copy link

nx-cloud bot commented Sep 19, 2025

View your CI Pipeline Execution ↗ for commit 98c9bc7

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 48s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-19 09:56:54 UTC

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
scripts/release/version.ts (4)

178-184: Inconsistent EOF behavior for other package.json files.

This path still writes JSON without a trailing newline, so most package.json files won’t get the intended LF. Align with the change above.

Apply this minimal fix:

-      await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
+      await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');

96-99: Type bug: ExactOptions.exact should be a version string, not semver.ReleaseType.

ReleaseType is 'major'|'minor'|… and doesn’t represent exact versions like "7.2.0". This can mask errors and breaks type safety where a string version is expected.

Apply:

-type ExactOptions = BaseOptions & {
-  exact: semver.ReleaseType;
+type ExactOptions = BaseOptions & {
+  exact: string;
   deferred?: boolean;
 };

80-86: Runtime crash risk in validation when --exact is used with --pre-id.

schema.releaseType can be undefined, so .startsWith('pre') can throw.

Use a safe check and keep the validation intent:

-if (schema.preId && !schema.releaseType.startsWith('pre')) {
+if (schema.preId && (!schema.releaseType || !schema.releaseType.startsWith('pre'))) {
   ctx.addIssue({
     code: z.ZodIssueCode.custom,
     message:
       'Using prerelease identifier requires one of release types: premajor, preminor, prepatch, prerelease',
   });
 }

153-186: Fix: ensure bumped package.json files end with LF

bumpAllPackageJsons writes JSON via JSON.stringify(...) and calls writeFile(...) without adding a trailing newline; verification shows 47 package.json files under code/ missing a trailing LF. Change the write to append \n, e.g. writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n').
Location: scripts/release/version.ts (lines 153–186).

🧹 Nitpick comments (2)
scripts/release/version.ts (2)

130-131: EOF newline addition looks good.

Appends a single LF to code/package.json writes. Consider centralizing this behavior to avoid future drift (see comments below).


124-133: Avoid repetition: introduce a tiny helper for JSON writes with EOF LF.

Reduces duplication and guarantees consistent newlines across all JSON outputs.

Example refactor:

 import { readFile, writeFile } from 'node:fs/promises';
+// Helper to ensure JSON files end with a single LF
+const writeJsonFile = (path: string, data: unknown) =>
+  writeFile(path, JSON.stringify(data, null, 2) + '\n');

@@
-  await writeFile(CODE_PACKAGE_JSON_PATH, JSON.stringify(codePkgJson, null, 2) + '\n');
+  await writeJsonFile(CODE_PACKAGE_JSON_PATH, codePkgJson);
@@
-      await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
+      await writeJsonFile(packageJsonPath, packageJson);
@@
-  await writeFile(CODE_PACKAGE_JSON_PATH, JSON.stringify(codePkgJson, null, 2) + '\n');
+  await writeJsonFile(CODE_PACKAGE_JSON_PATH, codePkgJson);
@@
-  await writeFile(CODE_PACKAGE_JSON_PATH, JSON.stringify(codePkgJson, null, 2) + '\n');
+  await writeJsonFile(CODE_PACKAGE_JSON_PATH, codePkgJson);

Optional: if you ever need CRLF normalization, gate the terminator behind a constant, but LF is typically preferred and enforced by .gitattributes/formatters.

Also applies to: 188-208, 210-236, 153-186

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c52fbf and 98c9bc7.

📒 Files selected for processing (1)
  • scripts/release/version.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
scripts/release/version.ts (1)
code/frameworks/svelte-vite/src/plugins/generateDocgen.ts (1)
  • writeFile (387-389)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: docs
  • GitHub Check: Danger JS
  • GitHub Check: get-parameters
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (2)
scripts/release/version.ts (2)

205-206: EOF newline addition for deferred write — LGTM.

Matches the intent and mirrors the earlier change.


227-228: EOF newline addition on apply — LGTM.

Consistent with other writes to code/package.json.

@github-actions github-actions bot mentioned this pull request Sep 19, 2025
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Internal-facing build tooling & test updates ci:docs Run the CI jobs for documentation checks only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants