Skip to content

feat!: migrate to TypeScript with Vite build system (v4.0.0)#70

Open
starak wants to merge 8 commits intomainfrom
ts-rewrite-v1
Open

feat!: migrate to TypeScript with Vite build system (v4.0.0)#70
starak wants to merge 8 commits intomainfrom
ts-rewrite-v1

Conversation

@starak
Copy link
Owner

@starak starak commented Feb 16, 2026

BREAKING CHANGES:

  • Requires Node.js >= 18
  • ESM-first architecture (CommonJS via bundled output)
  • chalk upgraded to v5 (ESM-only)
  • Custom tokens with colors require chalk-template

Added:

  • Full TypeScript rewrite with type declarations
  • Dual ESM + CommonJS output via Vite library mode
  • Vitest test framework
  • CHANGELOG.md documenting migration

Changed:

  • Build system from raw JS to Vite
  • Test framework from Jest to Vitest
  • Examples converted to ESM syntax
  • CI updated for Node 18/20/22 matrix

BREAKING CHANGES:
- Requires Node.js >= 18
- ESM-first architecture (CommonJS via bundled output)
- chalk upgraded to v5 (ESM-only)
- Custom tokens with colors require chalk-template

Added:
- Full TypeScript rewrite with type declarations
- Dual ESM + CommonJS output via Vite library mode
- Vitest test framework
- CHANGELOG.md documenting migration

Changed:
- Build system from raw JS to Vite
- Test framework from Jest to Vitest
- Examples converted to ESM syntax
- CI updated for Node 18/20/22 matrix
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates console-stamp to a TypeScript + Vite (library mode) build with dual ESM/CJS outputs, updates dependencies (notably chalk v5 + chalk-template), and replaces Jest with Vitest while updating docs/examples for the v4 breaking changes.

Changes:

  • Rewrites the library into src/ TypeScript with new types, defaults, tokens, and console patching logic.
  • Introduces Vite build + DTS generation and Vitest-based test suite; updates CI to Node 18/20/22.
  • Updates README/CHANGELOG/examples for ESM-first usage and chalk-template color syntax.

Reviewed changes

Copilot reviewed 35 out of 39 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vitest.config.ts Adds Vitest configuration for TS test discovery/node env.
vite.config.ts Adds Vite library build config + type generation plugin.
tsconfig.json Adds strict TS config for ESM/bundler resolution + declarations.
tokens/msg.js Removes legacy CommonJS token (migrated to TS).
tokens/label.js Removes legacy CommonJS token (migrated to TS).
tokens/date.js Removes legacy CommonJS token (migrated to TS).
test/utils.test.ts Migrates utils tests from Jest/CJS to Vitest/ESM+TS.
test/tools/SpyStream.js Removes legacy SpyStream helper (replaced by TS version).
test/tokens.test.ts Adds TS token unit tests under Vitest.
test/tokens.test.js Removes legacy Jest token tests.
test/index.test.ts Adds TS integration tests for console patching under Vitest.
test/index.test.js Removes legacy Jest integration tests.
test/helpers/SpyStream.ts Adds TS SpyStream helper for capturing output in tests.
src/utils.ts Adds TS utilities for config resolution, token parsing, prefix generation, and streams.
src/types.ts Adds public TS types for options, token contexts, and patched console.
src/tokens/msg.ts Adds TS implementation of :msg token.
src/tokens/label.ts Adds TS implementation of :label token.
src/tokens/index.ts Re-exports default tokens from a single module.
src/tokens/date.ts Adds TS implementation of :date token using dateformat.
src/index.ts Adds TS main entry that patches console methods and supports reset.
src/defaults.ts Adds TS defaults for format/include/levels/tokens.
src/dateformat.d.ts Adds local module typing for dateformat dependency.
package.json Updates to v4 packaging (exports map), dependencies, scripts, and engines.
lib/utils.js Removes legacy CommonJS build artifact.
lib/defaults.js Removes legacy CommonJS build artifact.
index.js Removes legacy CommonJS entrypoint (replaced by build output).
examples/workers/worker.js Updates example to ESM and imports from dist/.
examples/workers/index.js Updates worker example to ESM and fixes __dirname usage.
examples/index.js Updates example loader to ESM + top-level await for dynamic imports.
examples/custom-method/index.js Updates example to ESM + new import path (dist/).
examples/custom-date-token/index.js Updates example to ESM and improves token implementation.
examples/custom-console/index.js Updates example to ESM and uses TS-built dist output.
examples/colored-message/index.js Updates example to use chalk-template instead of chalk tagged templates.
README.md Documents v4 breaking changes + migration guidance and ESM/CJS usage.
CHANGELOG.md Adds v4.0.0 changelog entry describing the migration.
AGENTS.md Adds repo/tooling guidelines for agent contributors (TS/ESM/Vite/Vitest).
.gitignore Ignores dist output, TS build info, and coverage.
.github/workflows/nodejs.yml Updates CI matrix to Node 18/20/22 and adds typecheck/build steps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Changed require.types from ./dist/index.d.cts to ./dist/index.d.ts
since vite-plugin-dts only emits index.d.ts
Methods not present in the levels map (e.g., table, dir, trace) now
default to the 'log' level priority instead of becoming no-ops.

Added tests for unknown method handling.
Added outro to CJS build that assigns default export to module.exports,
enabling require('console-stamp')(console) pattern to work correctly.

Bumped to 4.0.0-rc.2
Added interop: 'auto' to Rollup CJS output configuration to properly
handle ESM-only dependencies (dateformat, chalk-template) when
required from CommonJS.

The :date token now works correctly in both ESM and CJS environments.

Bumped to 4.0.0-rc.3
When dual: true, log output is written to both custom streams (e.g., file)
and process.stdout/process.stderr for terminal visibility.

- Add dual option to ConsoleStampOptions and ResolvedConfig types
- Add selectProcessStream() utility function
- Add dual output logic to consoleStamp patching
- Add tests for dual output behavior
- Add dual-output example
- Update README with documentation
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.

2 participants