Replace color dependencies with Node.js built-in util.styleText#143
Replace color dependencies with Node.js built-in util.styleText#143
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: yamcodes <2014360+yamcodes@users.noreply.github.com>
|
@copilot actually we can just switch to util.styleText from node and avoid any dep altogether. |
Co-authored-by: yamcodes <2014360+yamcodes@users.noreply.github.com>
Done! I've replaced yoctocolors with Node.js built-in |
|
@copilot the fact that it has no dependencies should be reflected in the docs. at least in the readme, and the appropriate section within the docs (in www) |
Co-authored-by: yamcodes <2014360+yamcodes@users.noreply.github.com>
Documentation updated! I've updated the README and website docs to reflect that ArkEnv now has zero external dependencies instead of "only a single dependency". The changes highlight this improvement in:
All documentation now correctly states "Zero external dependencies" which accurately reflects the elimination of color dependencies by using Node.js built-in |
- Removed chalk dependency from bun.lock. - Adjusted import order in index.ts for clarity. - Added a start script to package.json for vite-react-ts example. - Standardized string formatting in create-env.test.ts and errors.ts for consistency.
WalkthroughThis PR removes Chalk usage, replaces it with Node’s util.styleText for terminal coloring, updates docs to claim zero external dependencies, removes Chalk from package manifests, adjusts tests accordingly, and adds a “start” script to a Vite React TS example. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant Example as with-bun example
participant Node as node:util.styleText
User->>Example: Run example
Example->>Node: styleText("blue"/"green"/"red", text)
Node-->>Example: Styled strings
Example-->>User: Console output (colored)
note right of Example: Replaces Chalk with util.styleText
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Pre-merge checks (4 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Poem
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.
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. ✨ Finishing touches
🧪 Generate unit tests
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. Comment |
- Revised wording in copilot-instructions.md and arkenv README.md to emphasize zero dependencies and minimal bundle size.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
examples/with-vite-react-ts/package.json (1)
8-8: Use “start” for preview or drop it to avoid duplication.“dev” already runs Vite. If you want a conventional production start, point to preview.
- "start": "vite", + "start": "vite preview"apps/www/content/docs/index.mdx (1)
16-16: Clarify dependency wording to avoid confusion with peer deps.Recommend “Zero runtime dependencies” and mention built-in coloring source.
- - 🪶 **Lightweight**: Zero external dependencies ([see size](https://bundlephobia.com/package/arkenv)) + - 🪶 **Lightweight**: Zero runtime dependencies (colors via Node’s `util.styleText`) ([see size](https://bundlephobia.com/package/arkenv))packages/arkenv/README.md (1)
87-87: “Zero dependencies” is misleading givenarktypeis a peer.Prefer “Zero runtime dependencies (ArkType is a peer)”.
-- 🪶 **Lightweight**: Zero dependencies, [tiny bundle size](https://bundlephobia.com/package/arkenv) +- 🪶 **Lightweight**: Zero runtime dependencies (ArkType is a peer), [tiny bundle size](https://bundlephobia.com/package/arkenv)Also consider adding a Requirements bullet for the minimum Node.js version introduced by this change. I can draft that if you confirm the version target.
examples/with-bun/index.ts (1)
1-1: Avoid array styles; use nested calls for broader compatibility.Some runtimes/build tools may not accept an array for
styleText. Nesting is safest.-import { styleText } from "node:util"; +import { styleText } from "node:util"; @@ - `🚀 Server running at ${styleText(["blue", "bold"], env.HOST)}:${styleText(["green", "bold"], String(env.PORT))} in ${styleText( - "bold", - env.NODE_ENV === "production" - ? styleText("red", env.NODE_ENV) - : styleText("blue", env.NODE_ENV), - )} mode`, + `🚀 Server running at ${styleText("bold", styleText("blue", env.HOST))}:${styleText( + "bold", + styleText("green", String(env.PORT)), + )} in ${styleText( + "bold", + env.NODE_ENV === "production" ? styleText("red", env.NODE_ENV) : styleText("blue", env.NODE_ENV), + )} mode`,Also confirm Bun supports
util.styleText(see comment in examples/with-bun/package.json). If not, we should either revert the example to plain text or add a tiny local helper that no-ops when unavailable.Also applies to: 13-18
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
examples/with-bun/bun.lockis excluded by!**/*.lockpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
.github/copilot-instructions.md(1 hunks)apps/www/content/docs/index.mdx(1 hunks)examples/with-bun/index.ts(2 hunks)examples/with-bun/package.json(1 hunks)examples/with-vite-react-ts/package.json(1 hunks)packages/arkenv/README.md(1 hunks)packages/arkenv/package.json(0 hunks)packages/arkenv/src/create-env.test.ts(2 hunks)packages/arkenv/src/errors.ts(3 hunks)
💤 Files with no reviewable changes (1)
- packages/arkenv/package.json
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-09-09T17:37:19.650Z
Learnt from: yamcodes
PR: yamcodes/arkenv#132
File: packages/arkenv/README.md:13-14
Timestamp: 2025-09-09T17:37:19.650Z
Learning: For yamcodes/arkenv project: Runtime support documentation should link to specific examples: Node.js (examples/basic), Bun (examples/with-bun), Vite (examples/with-vite-react-ts).
Applied to files:
packages/arkenv/README.md.github/copilot-instructions.md
📚 Learning: 2025-09-10T19:35:18.144Z
Learnt from: yamcodes
PR: yamcodes/arkenv#136
File: .changeset/vast-bananas-win.md:2-3
Timestamp: 2025-09-10T19:35:18.144Z
Learning: The arkenv package is currently in v0.x.x (pre-1.0) development phase, where breaking changes are acceptable in minor version bumps according to semantic versioning conventions.
Applied to files:
examples/with-bun/package.json
📚 Learning: 2025-09-10T19:39:49.841Z
Learnt from: CR
PR: yamcodes/arkenv#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-10T19:39:49.841Z
Learning: Applies to **/*.test.ts : Use Vitest's describe/it structure in tests
Applied to files:
packages/arkenv/src/create-env.test.ts
🔇 Additional comments (3)
examples/with-bun/package.json (1)
12-12: LGTM — dependency cleanup aligns with the migration.Confirmed Bun implements node:util.styleText (added in Bun v1.0.31), so the example is safe.
packages/arkenv/src/create-env.test.ts (1)
1-1: Require Node >=20.12.0 in CI and package enginesutil.styleText was added in Node v20.12.0; ensure CI and package engines require that version. (nodejs.org)
- Add "engines": { "node": ">=20.12.0" } to packages/arkenv/package.json (engines are currently missing).
- Ensure .github/workflows/tests.yml and .github/workflows/release.yml matrix.node-version includes 20.x (they currently use ${{ matrix.node-version }} — confirm the matrix includes 20.x).
packages/arkenv/src/errors.ts (1)
1-1: Gate ANSI styling behind TTY/NO_COLOR and require Node >= 20.12.0Wrap direct util.styleText calls with a color() guard that respects NO_COLOR, FORCE_COLOR, and stdout.isTTY; update packages/arkenv/package.json engines to ">=20.12.0" and document that util.styleText was introduced in Node v20.12.0.
-import { styleText } from "node:util"; +import { styleText } from "node:util"; +const useColor = + process.env.NO_COLOR !== "1" && + process.env.FORCE_COLOR !== "0" && + Boolean(process.stdout?.isTTY); +const color = (style: string | string[], text: string) => + useColor ? styleText(style as any, text) : text; @@ - `"(was ${styleText("cyan", `"${valueMatch[1]}"`)})`, + `"(was ${color("cyan", `"${valueMatch[1]}"`)})`, @@ - return `${styleText("yellow", path)}${formattedMessage}`; + return `${color("yellow", path)}${formattedMessage}`; @@ - super(`${styleText("red", message)}\n${indent(formatErrors(errors))}\n`); + super(`${color("red", message)}\n${indent(formatErrors(errors))}\n`);
| - **Runtime validation**: Catch missing or invalid environment variables early | ||
| - **Powered by ArkType**: Leverage ArkType's powerful type system | ||
| - **Lightweight**: Single dependency with minimal bundle size | ||
| - **Lightweight**: Zero external,tinyt bundle size |
There was a problem hiding this comment.
Fix typo and punctuation in key feature.
User-facing docs: “tinyt” + stray comma.
- - **Lightweight**: Zero external,tinyt bundle size
+ - **Lightweight**: Zero external dependencies, tiny bundle size📝 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.
| - **Lightweight**: Zero external,tinyt bundle size | |
| - **Lightweight**: Zero external dependencies, tiny bundle size |
🤖 Prompt for AI Agents
In .github/copilot-instructions.md around line 11, the "Lightweight" bullet
contains a typo and stray punctuation ("Zero external,tinyt bundle size"); fix
it by removing the stray comma, correcting "tinyt" to "tiny", and ensure spacing
is correct so the line reads something like "Zero external, tiny bundle size" or
better "Zero external dependencies, tiny bundle size" depending on intended
meaning.
This PR eliminates external color dependencies by using Node.js built-in
util.styleTextto reduce ArkEnv's bundle size while maintaining identical functionality.Changes Made
yoctocolors: ^2.1.2dependency frompackages/arkenv/package.jsonsrc/errors.tsto use Node.js built-inutil.styleTextutil.styleTextfor error message verificationutil.styleTextfor pretty-printingBenefits
red,yellow,cyan,blue,green,bold)Before/After Comparison
Node.js Version Requirement
This change requires Node.js 20.12.0+ due to the use of
util.styleTextwhich was introduced in that version. This aligns with modern Node.js LTS requirements.All tests continue to pass (52/52) and the colored output remains visually identical. This change completely eliminates external dependencies for color formatting while maintaining all functionality.
Fixes #135.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Summary by CodeRabbit
Refactor
Chores
Documentation
Examples
Tests