Skip to content

refactor: replace ms with in-house formatMs/parseDuration#5641

Merged
chronark merged 6 commits intomainfrom
refactor/replace-ms
Apr 13, 2026
Merged

refactor: replace ms with in-house formatMs/parseDuration#5641
chronark merged 6 commits intomainfrom
refactor/replace-ms

Conversation

@chronark
Copy link
Copy Markdown
Collaborator

@chronark chronark commented Apr 7, 2026

Summary

Replace the ms npm package (+ @types/ms) with two focused utilities:

  • lib/ms.tsformatMs(n, { long? }) for displaying durations (86400000"1d" or "1 day")
  • lib/duration.tsparseDuration(s) for parsing strings like "24h"86400000

The original ms package is 163 lines with an overloaded ms() function that does both parsing and formatting. Splitting into two explicit functions makes the intent clear at each call site.

5 files updated:

  • cancel-alert.tsxformatMs(timeRemaining, { long: true })
  • overrides-table.tsxformatMs(override.duration)
  • override-indicator.tsxformatMs(log.override.duration)
  • namespace-card.tsxformatMs(Date.now() - timestamp, { long: true })
  • use-deployments.tsparseDuration(values.at(0))

Also removes ms from the migrate tool where it was listed but never imported.

Test plan

  • pnpm build succeeds
  • Rate limit pages display durations correctly
  • Billing cancellation shows correct time remaining
  • Deployment "since" filter works

chronark added 3 commits April 7, 2026 21:46
Remove dead dependencies that are listed in package.json but never imported:
- @ant-design/plots, d3-array, react-is, svix, @vercel/og, free-email-domains (dashboard)
- @mendable/firecrawl-js, ai (billing)
- @axiomhq/js, ts-semaphore (migrate)
- knip, cz-conventional-changelog (root)
- @dagger.io/dagger (clickhouse)
- eslint, eslint-config-next (dashboard)

Also removes dead code:
- axiom.ts migration script (dead)
- k6 load testing tool (unused)
- eslint config + lint script
- commitizen config
- Slack alerting from WorkOS webhook (unused)
Replace the slugify npm package with a simple 8-line utility in
lib/slugify.ts. Consolidates two implementations (one was already
hand-rolled in use-workspace-step.tsx) into a single shared function.
Replace the ms npm package with two focused utilities:
- lib/ms.ts: formatMs(n) for displaying durations ("1d", "2 hours")
- lib/duration.ts: parseDuration(s) for parsing strings like "24h" to ms

Also removes @types/ms and ms from the migrate tool.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview, Comment Apr 13, 2026 10:03am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The pull request removes the ms npm package dependency and replaces its usage with custom utility functions. Two new utility modules are introduced (parseDuration and formatMs), which replace all existing library calls across multiple dashboard components. The ms package is removed from package.json files in the dashboard and migrate tool directories.

Changes

Cohort / File(s) Summary
Duration Utilities
lib/duration.ts, lib/ms.ts
Added two new utility modules. duration.ts provides parseDuration() to convert duration strings (e.g., "5m", "2h") to milliseconds. ms.ts provides formatMs() to format milliseconds as human-readable strings with support for long-form and short-form output.
Component Usage Updates
app/(app)/[workspaceSlug]/projects/[projectId]/(overview)/deployments/hooks/use-deployments.ts, app/(app)/[workspaceSlug]/ratelimits/[namespaceId]/_overview/components/table/components/override-indicator.tsx, app/(app)/[workspaceSlug]/ratelimits/[namespaceId]/overrides/overrides-table.tsx, app/(app)/[workspaceSlug]/ratelimits/_components/list/namespace-card.tsx, app/(app)/[workspaceSlug]/settings/billing/components/cancel-alert.tsx
Replaced ms library calls with custom parseDuration or formatMs helpers. Import statements updated accordingly.
Dependency Removal
package.json (web/apps/dashboard), package.json (web/tools/migrate)
Removed ms and @types/ms dependencies from package.json files.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description covers the summary, implementation details, affected files, and includes a test plan, but does not follow the required template structure with issue tracking or formal checklist sections. Fill out the complete template including issue number, type of change checkboxes, comprehensive test instructions, and required checklist items for consistency with repository standards.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: replacing the ms library with in-house formatMs and parseDuration utilities.

✏️ 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 refactor/replace-ms

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

Copy link
Copy Markdown
Collaborator Author

chronark commented Apr 7, 2026

Base automatically changed from refactor/replace-slugify to main April 8, 2026 09:49
@chronark chronark enabled auto-merge April 13, 2026 10:00
@socket-security
Copy link
Copy Markdown

socket-security bot commented Apr 13, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​tailwindcss/​aspect-ratio@​0.4.210010010083100
Addednpm/​@​tailwindcss/​container-queries@​0.1.11001009983100

View full report

@chronark chronark added this pull request to the merge queue Apr 13, 2026
@chronark chronark removed this pull request from the merge queue due to a manual request Apr 13, 2026
@chronark chronark merged commit d8afc67 into main Apr 13, 2026
13 of 14 checks passed
@chronark chronark deleted the refactor/replace-ms branch April 13, 2026 10:05
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