Skip to content

(v1) Move log helpers to @repo/utils and finish console.* migration #1237

Description

@yamcodes

Problem

ArkEnv still has scattered ad-hoc console.* calls and manually-prefixed log strings in several production packages. PR #1294 introduced shared log helpers in @arkenv/build/log.ts, but that placement creates an unnecessary dependency footprint (e.g. pulling chokidar into @arkenv/bun-plugin consumers) and splits formatting utilities away from @repo/utils where styleText, indent, and ArkEnvError already live.

Already done (do not redo)

Scope — Phase 1 (v1)

1. Relocate log helpers to @repo/utils

Move log helper functions from @arkenv/build/log.ts to @repo/utils (e.g. log-helpers.ts):

  • BUILD_PREFIX, WATCHER_PREFIX
  • formatBuildError, logBuildWarning, logBuildError, logWatcherError
  • Extend with any helpers needed for remaining call sites (e.g. logging a secondary error detail line)

Delete @arkenv/build/log entirely — no re-exports. The ./log subpath was added in #1294 (@arkenv/build@0.0.1), has no external consumers, and is safe to remove pre-v1.0 release.

2. Per-package migration rules

Package Approach
@arkenv/bun-plugin Bundle log helpers from @repo/utils via alwaysBundle. Zero runtime deps — do not depend on @arkenv/build.
@arkenv/nextjs Bundle log helpers from @repo/utils via alwaysBundle. Update imports currently using @arkenv/build or @arkenv/build/log.
@arkenv/nuxt Bundle log helpers from @repo/utils via alwaysBundle. Update imports currently using @arkenv/build.
@arkenv/build Import log helpers directly from @repo/utils internally. Remove log.ts entry point and ./log export from package.json.
arkenv CLI LoggerPort only. Instantiate a barebones TextReporter/LoggerPort fallback for unhandled rejections in index.ts when no global logger exists. Never import from @arkenv/build.
Scaffold generated script Leave console.error. Generated user-run scripts should stay vanilla Node.

3. Remaining call sites to migrate

Build / integration packages

  • @arkenv/bun-plugin — schema load failure uses raw console.error
  • @arkenv/nextjs — validation failure still prints error body via raw console.error after logBuildError header

CLI (arkenv package)

  • injection.ts — dts append failure uses raw console.error
  • index.ts — unhandled rejection/exception fallbacks when no global logger is set
  • node-project-scanner.adapter.ts — git-not-installed message uses raw console.debug

Explicitly excluded

  • scaffold/executor.ts — generated script console.error stays as-is

Constraints

  • Do not change ArkEnvError throw formatting or the EnvIssue system.
  • Do not introduce a new logging package — use existing @repo/utils.
  • Do not add @arkenv/build as a runtime dependency to @arkenv/bun-plugin or arkenv CLI.

Implementation order

  1. Add log helpers to @repo/utils (+ tests)
  2. Switch @arkenv/build to utils, delete ./log export
  3. Migrate nextjs, nuxt, bun-plugin call sites
  4. CLI LoggerPort fallback + remaining paths

Out of scope — Phase 2

Tracked in #1300 (v1): injectable logger API, log levels, silent mode, unified abstraction across packages.

Acceptance criteria

  • Log helpers live in @repo/utils and are exported from its index
  • @arkenv/build/log subpath deleted — no re-exports, log.ts entry removed from tsdown config and package.json exports
  • @arkenv/build watcher paths import log helpers from @repo/utils
  • @arkenv/bun-plugin, @arkenv/nextjs, @arkenv/nuxt bundle log helpers from @repo/utils — no @arkenv/build dependency added for logging
  • No raw [ArkEnv] or [ArkEnv Watcher] string literals outside @repo/utils log helpers
  • @arkenv/nextjs validation failure output uses log helpers end-to-end (no raw console.error for the error body)
  • CLI paths (injection.ts, index.ts, node-project-scanner.adapter.ts) route through LoggerPort — no ad-hoc console.*
  • Scaffold generated script unchanged (console.error preserved)
  • Existing tests pass; add/update tests if helper signatures change
  • Changesets for affected published packages

Agent brief

See the single consolidated agent brief comment on this issue for the authoritative implementation spec.

Target branch

v1

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvementready for agentFully specified, ready for an AI agent to implement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions