Skip to content

fix npx invocation#901

Merged
kibertoad merged 1 commit intomainfrom
fix/npx-invocation
Mar 28, 2026
Merged

fix npx invocation#901
kibertoad merged 1 commit intomainfrom
fix/npx-invocation

Conversation

@kibertoad
Copy link
Copy Markdown
Collaborator

Changes

correctly handle multi-arg npx invocation

Checklist

  • Apply one of following labels; major, minor, patch or skip-release
  • I've updated the documentation, or no changes were necessary
  • I've updated the tests, or no changes were necessary

AI Assistance Tracking

We're running a metric to understand where AI assists our engineering work. Please select exactly one of the options below:

Mark "Yes" if AI helped in any part of this work, for example: generating code, refactoring, debugging support,
explaining something, reviewing an idea, or suggesting an approach.

  • Yes, AI assisted with this PR
  • No, AI did not assist with this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Documentation

    • Updated CLI invocation documentation with multiple command format options for mark-migrations-applied.
  • Bug Fixes

    • Fixed CLI argument parsing to correctly handle npx-style invocations with additional positional arguments.

Walkthrough

This pull request updates documentation and CLI behavior for the mark-migrations-applied command in the drizzle-utils package. README and migration guide examples are revised to show multiple invocation methods: using the command directly when installed as a project dependency, and using npx -p @lokalise/drizzle-utils`` when not installed. The CLI argument parsing was modified to select the configuration path from the last positional argument instead of the first, accommodating cases where npx prepends the bin name as an additional positional. Tests were added to verify this behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~9 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix npx invocation' is concise and directly related to the main changeset focus—improving CLI argument parsing to handle npx's multi-argument invocation pattern.
Description check ✅ Passed The PR description includes all required sections: a clear 'Changes' statement, completed checklist with all required items marked, and AI assistance tracking properly indicated.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/npx-invocation

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

@kibertoad kibertoad merged commit d6fb35b into main Mar 28, 2026
7 of 8 checks passed
@kibertoad kibertoad deleted the fix/npx-invocation branch March 28, 2026 22:46
Copy link
Copy Markdown

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/app/drizzle-utils/src/cli/markMigrationsApplied.ts`:
- Around line 112-116: The CLI currently treats the last positional (const
configPath = positionals.at(-1)) as the config path even when npx injects only
the bin name; update the check to treat a single injected positional as
"missing" by verifying positionals.length > 1 before accepting configPath —
i.e., if !configPath or positionals.length === 1 then call printUsage(1).
Reference the existing variables positionals, configPath and the function
printUsage to locate and update the logic in markMigrationsApplied.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: lokalise/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f1aa3f81-d94f-40de-96e8-e68067c7d10e

📥 Commits

Reviewing files that changed from the base of the PR and between d09c089 and 90b6e42.

📒 Files selected for processing (4)
  • packages/app/drizzle-utils/README.md
  • packages/app/drizzle-utils/docs/migrating-from-prisma.md
  • packages/app/drizzle-utils/src/cli/markMigrationsApplied.test.ts
  • packages/app/drizzle-utils/src/cli/markMigrationsApplied.ts

Comment on lines +112 to 116
// When invoked via `npx @lokalise/drizzle-utils mark-migrations-applied ./config.ts`,
// npx passes the bin name as a positional arg too. Use the last positional to be resilient.
const configPath = positionals.at(-1)
if (!configPath) {
printUsage(1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Treat lone injected bin positional as “missing config path”.

If invocation is npx @lokalise/drizzle-utils mark-migrations-applied (no config path), Line 114 resolves the bin name as configPath, and the CLI later fails with an import error instead of usage output.

💡 Proposed fix
 function parseCliArgs(): { configPath: string } {
   const { values, positionals } = parseArgs({
@@
   if (values.help) {
     printUsage(0)
   }
 
+  const normalizedPositionals =
+    positionals[0] === 'mark-migrations-applied' ? positionals.slice(1) : positionals
+
   // When invoked via `npx `@lokalise/drizzle-utils` mark-migrations-applied ./config.ts`,
   // npx passes the bin name as a positional arg too. Use the last positional to be resilient.
-  const configPath = positionals.at(-1)
+  const configPath = normalizedPositionals.at(-1)
   if (!configPath) {
     printUsage(1)
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// When invoked via `npx @lokalise/drizzle-utils mark-migrations-applied ./config.ts`,
// npx passes the bin name as a positional arg too. Use the last positional to be resilient.
const configPath = positionals.at(-1)
if (!configPath) {
printUsage(1)
const normalizedPositionals =
positionals[0] === 'mark-migrations-applied' ? positionals.slice(1) : positionals
// When invoked via `npx `@lokalise/drizzle-utils` mark-migrations-applied ./config.ts`,
// npx passes the bin name as a positional arg too. Use the last positional to be resilient.
const configPath = normalizedPositionals.at(-1)
if (!configPath) {
printUsage(1)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/app/drizzle-utils/src/cli/markMigrationsApplied.ts` around lines 112
- 116, The CLI currently treats the last positional (const configPath =
positionals.at(-1)) as the config path even when npx injects only the bin name;
update the check to treat a single injected positional as "missing" by verifying
positionals.length > 1 before accepting configPath — i.e., if !configPath or
positionals.length === 1 then call printUsage(1). Reference the existing
variables positionals, configPath and the function printUsage to locate and
update the logic in markMigrationsApplied.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants