Skip to content

Replace color dependencies with Node.js built-in util.styleText#143

Merged
yamcodes merged 6 commits intomainfrom
copilot/fix-135
Sep 12, 2025
Merged

Replace color dependencies with Node.js built-in util.styleText#143
yamcodes merged 6 commits intomainfrom
copilot/fix-135

Conversation

Copy link
Contributor

Copilot AI commented Sep 11, 2025

This PR eliminates external color dependencies by using Node.js built-in util.styleText to reduce ArkEnv's bundle size while maintaining identical functionality.

Changes Made

  • Core package: Removed yoctocolors: ^2.1.2 dependency from packages/arkenv/package.json
  • Error formatting: Updated imports and function calls in src/errors.ts to use Node.js built-in util.styleText
  • Tests: Updated test files to use util.styleText for error message verification
  • Examples: Updated the Bun example to use util.styleText for pretty-printing
  • Documentation: Updated README and website docs to reflect zero external dependencies

Benefits

  • Zero external dependencies: Completely eliminated external color dependency
  • Further bundle size optimization: Using Node.js built-in utilities instead of third-party packages
  • Zero breaking changes: Identical API for all color functions used (red, yellow, cyan, blue, green, bold)
  • Maintained functionality: All error formatting and pretty-printing works exactly the same

Before/After Comparison

- import { red, yellow, cyan } from "yoctocolors";
+ import { styleText } from "node:util";

- red(message)
+ styleText('red', message)

Node.js Version Requirement

This change requires Node.js 20.12.0+ due to the use of util.styleText which 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

    • Replaced Chalk-based coloring with Node’s built-in util.styleText across core and tests; output behavior unchanged.
  • Chores

    • Removed Chalk from dependencies, reducing external runtime dependencies and bundle footprint.
  • Documentation

    • Updated “Lightweight” claims to “Zero dependencies/tiny bundle size” in docs and README.
  • Examples

    • with-bun: Migrated terminal styling to util.styleText and removed Chalk dependency.
    • with-vite-react-ts: Added “start” script (vite).
  • Tests

    • Updated color assertions to use util.styleText.

@changeset-bot
Copy link

changeset-bot bot commented Sep 11, 2025

⚠️ No Changeset found

Latest commit: d15890a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link

vercel bot commented Sep 11, 2025

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

Project Deployment Preview Comments Updated (UTC)
arkenv Ready Ready Preview Comment Sep 11, 2025 8:14pm

Co-authored-by: yamcodes <2014360+yamcodes@users.noreply.github.com>
Copilot AI changed the title [WIP] Switch to yoctocolors Switch from chalk to yoctocolors for reduced bundle size Sep 11, 2025
Copilot AI requested a review from yamcodes September 11, 2025 05:09
@yamcodes
Copy link
Owner

@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>
Copy link
Contributor Author

Copilot AI commented Sep 11, 2025

@copilot actually we can just switch to util.styleText from node and avoid any dep altogether.

Done! I've replaced yoctocolors with Node.js built-in util.styleText to completely eliminate external dependencies. All tests pass and functionality remains identical. The change requires Node.js 20.12.0+ but aligns with modern LTS requirements. Commit: 37b17ed

Copilot AI changed the title Switch from chalk to yoctocolors for reduced bundle size Replace color dependencies with Node.js built-in util.styleText Sep 11, 2025
@yamcodes
Copy link
Owner

@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>
Copy link
Contributor Author

Copilot AI commented Sep 11, 2025

@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)

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:

  • Main README.md features section
  • Website documentation (apps/www/content/docs/index.mdx)
  • Copilot instructions file

All documentation now correctly states "Zero external dependencies" which accurately reflects the elimination of color dependencies by using Node.js built-in util.styleText. Commit: 5cf6189

@github-actions github-actions bot added docs Improvements or additions to documentation arkenv Changes to the `arkenv` npm package. example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) www Improvements or additions to arkenv.js.org tests This issue or PR is about adding, removing or changing tests labels Sep 11, 2025
- 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.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 11, 2025

Walkthrough

This 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

Cohort / File(s) Summary
Docs: “Lightweight/Zero deps” copy updates
.github/copilot-instructions.md, apps/www/content/docs/index.mdx, packages/arkenv/README.md
Updated “Lightweight”/“Key features” bullet to state zero external dependencies and tiny bundle size.
Bun example: drop Chalk, use util.styleText
examples/with-bun/index.ts, examples/with-bun/package.json
Replaced Chalk styling with node:util styleText; removed chalk from dependencies; adjusted log styling (host/port/env) and cast port to string.
ArkEnv package: remove Chalk and switch styling
packages/arkenv/package.json, packages/arkenv/src/errors.ts, packages/arkenv/src/create-env.test.ts
Deleted runtime chalk dependency; replaced Chalk with node:util styleText in error formatting and tests; no API changes.
Vite React TS example script
examples/with-vite-react-ts/package.json
Added "start": "vite" script.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Move readme #132 — Also edits packages/arkenv/README.md; overlapping documentation change.
  • Star us button #133 — Updates the same “Lightweight” docs in packages/arkenv/README.md and apps/www/content/docs/index.mdx.

Pre-merge checks (4 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning Most edits are on-topic (dependency removal, code/tests, and docs updates), but there are unrelated modifications present: examples/with-vite-react-ts/package.json adds a new "start" script that is not referenced in the PR objectives, and .github/copilot-instructions.md contains a wording change with a likely typo ("tinyt") that appears unrelated to the linked issue. These indicate out-of-scope changes that should be verified. Remove or justify the "start" script addition and revert or correct the copilot-instructions.md edit; if those changes are intentional, move them into a separate PR and fix the typo before merging.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely describes the primary change—replacing external color dependencies with Node's util.styleText—and aligns with the PR scope (code, tests, examples, docs). It is specific, on-topic, and clear for teammates scanning history.
Linked Issues Check ✅ Passed The PR meets the intent of linked issue #135 by removing an external color package and updating code, tests, examples, and documentation to use Node's built-in util.styleText, achieving zero runtime color dependencies and reduced bundle size. Although the issue suggested switching to yoctocolors, the PR's approach satisfies the same objective of avoiding an added dependency. Please ensure the Node.js 20.12.0+ runtime requirement is documented for consumers.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

I nibbled through Chalk, a colorful trail,
Swapped it for styleText—built-in, no bloat to hail.
Docs now whisper, “zero deps” with glee,
Examples shine bright, as light as can be.
Thump-thump—tiny bundles, faster hops for me! 🐇✨

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.

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/fix-135

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.

- Revised wording in copilot-instructions.md and arkenv README.md to emphasize zero dependencies and minimal bundle size.
@yamcodes yamcodes marked this pull request as ready for review September 11, 2025 20:14
@yamcodes
Copy link
Owner

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 11, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 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 given arktype is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 87225fc and d15890a.

⛔ Files ignored due to path filters (2)
  • examples/with-bun/bun.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is 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 engines

util.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.0

Wrap 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
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
- **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.

@yamcodes yamcodes merged commit 29761e0 into main Sep 12, 2025
8 checks passed
@yamcodes yamcodes deleted the copilot/fix-135 branch September 12, 2025 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arkenv Changes to the `arkenv` npm package. docs Improvements or additions to documentation example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch to yoctocolors

2 participants