Skip to content

Conversation

@nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Dec 23, 2025

This fixes a regression introduced in #2778 - stable sort is required for deterministic builds, but we can safely preserve order for the user package.json during package updates

@changeset-bot
Copy link

changeset-bot bot commented Dec 23, 2025

🦋 Changeset detected

Latest commit: 969145c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
trigger.dev Patch
d3-chat Patch
references-d3-openai-agents Patch
references-nextjs-realtime Patch
references-realtime-hooks-test Patch
references-realtime-streams Patch
references-telemetry Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/python Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/sdk Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/zod-worker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

Walkthrough

This PR adds functionality to preserve JSON key ordering when writing files in the CLI. It introduces two new utility functions—writeJSONFile for deterministic key ordering via stable stringification and writeJSONFilePreserveOrder to maintain original key order—and updates the update command to use the order-preserving variant when modifying package.json files during backup, update, and revert operations. A changeset documents the CLI fix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete. It lacks the required checklist, testing steps, and changelog sections specified in the repository template. Add the complete description template with filled-in sections for checklist, testing, and changelog to match repository standards.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing the update command to preserve package.json key order, which directly aligns with the changeset and file modifications.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/update-command-preserve-packagejson-order

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

🧹 Nitpick comments (2)
packages/cli-v3/src/utilities/fileSystem.ts (2)

162-170: Consider adding a trailing newline for better POSIX compliance.

The implementation is correct, but many tools and editors expect text files to end with a newline character. Consider appending \n to the stringified content.

🔎 Suggested enhancement
 export async function writeJSONFile(path: string, json: any, pretty = false) {
-  await safeWriteFile(path, stringify(json, pretty ? { space: 2 } : undefined) ?? "");
+  const content = stringify(json, pretty ? { space: 2 } : undefined) ?? "";
+  await safeWriteFile(path, content + (content ? "\n" : ""));
 }

172-180: Consider adding a trailing newline for consistency.

The implementation correctly preserves key order using native JSON.stringify. However, the same trailing newline consideration from writeJSONFile applies here for better POSIX compliance.

🔎 Suggested enhancement
 export async function writeJSONFilePreserveOrder(path: string, json: any, pretty = false) {
-  await safeWriteFile(path, JSON.stringify(json, undefined, pretty ? 2 : undefined));
+  const content = JSON.stringify(json, undefined, pretty ? 2 : undefined);
+  await safeWriteFile(path, content + "\n");
 }
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52e9bae and 969145c.

📒 Files selected for processing (3)
  • .changeset/cool-elephants-carry.md
  • packages/cli-v3/src/commands/update.ts
  • packages/cli-v3/src/utilities/fileSystem.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects instead

Files:

  • packages/cli-v3/src/utilities/fileSystem.ts
  • packages/cli-v3/src/commands/update.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use function declarations instead of default exports

Files:

  • packages/cli-v3/src/utilities/fileSystem.ts
  • packages/cli-v3/src/commands/update.ts
**/*.{js,ts,jsx,tsx,json,md,css,scss}

📄 CodeRabbit inference engine (AGENTS.md)

Format code using Prettier

Files:

  • packages/cli-v3/src/utilities/fileSystem.ts
  • packages/cli-v3/src/commands/update.ts
🧠 Learnings (2)
📚 Learning: 2025-11-27T16:27:48.109Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-27T16:27:48.109Z
Learning: Use pnpm for package management in this monorepo

Applied to files:

  • packages/cli-v3/src/commands/update.ts
📚 Learning: 2025-11-27T16:26:44.496Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/executing-commands.mdc:0-0
Timestamp: 2025-11-27T16:26:44.496Z
Learning: Execute most monorepo commands using `pnpm run` from the root directory, with `--filter` flag for specific packages (e.g., `pnpm run dev --filter webapp`)

Applied to files:

  • packages/cli-v3/src/commands/update.ts
🧬 Code graph analysis (2)
packages/cli-v3/src/utilities/fileSystem.ts (1)
packages/core/src/v3/apps/http.ts (1)
  • json (65-75)
packages/cli-v3/src/commands/update.ts (1)
packages/cli-v3/src/utilities/fileSystem.ts (1)
  • writeJSONFilePreserveOrder (178-180)
⏰ 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). (23)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
.changeset/cool-elephants-carry.md (1)

1-5: LGTM!

The changeset properly documents this patch-level fix with a clear description that matches the PR objectives.

packages/cli-v3/src/commands/update.ts (2)

4-4: LGTM! Import changes are correct.

The removal of the unused basename import and the switch to writeJSONFilePreserveOrder properly align with the PR objectives to preserve package.json key ordering.

Also applies to: 9-9


230-230: Excellent fix! All package.json operations now preserve key order.

The three usages correctly apply writeJSONFilePreserveOrder to:

  1. Backup the original package.json
  2. Write the updated package.json
  3. Revert to the original package.json

This properly addresses the regression while maintaining the user's preferred key ordering.

Also applies to: 244-244, 247-247

@vibe-kanban-cloud
Copy link

Review Complete

Your review story is ready!

View Story

Comment !reviewfast on this PR to re-generate the story.

@nicktrn nicktrn merged commit 7a54a84 into main Dec 23, 2025
31 checks passed
@nicktrn nicktrn deleted the fix/update-command-preserve-packagejson-order branch December 23, 2025 12:52
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