Skip to content

Conversation

azu
Copy link
Member

@azu azu commented Jul 23, 2025

Summary

  • Fix process is not defined error when building @textlint/kernel with Vite
  • Add browser environment detection to timing utility
  • Disable timing functionality in browser environments while preserving Node.js compatibility

Problem

When building @textlint/kernel with Vite for browser environments, it throws Uncaught ReferenceError: process is not defined at runtime because the timing utility uses Node.js-specific process object.

Solution

  • Added browser environment detection using typeof process === "undefined"
  • Modified timing functions to return original functions unchanged in browser environments
  • Preserved full timing functionality in Node.js environments
  • Updated TypeScript types for better compatibility

Test plan

  • Build @textlint/kernel successfully with TypeScript
  • Verify timing functionality still works in Node.js environments
  • Test that browser builds no longer throw process-related errors

🤖 Generated with Claude Code

- Fix 'process is not defined' error when building with Vite
- Add browser environment detection
- Disable timing functionality in browser environments
- Preserve Node.js timing functionality when process is available
- Update function type signatures for better TypeScript compatibility

This change allows @textlint/kernel to work in browser environments
while maintaining full compatibility with Node.js environments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Copilot Copilot AI review requested due to automatic review settings July 23, 2025 23:59
Copy link
Contributor

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

This PR fixes browser compatibility issues in the timing utility by adding environment detection to handle the absence of Node.js-specific APIs in browser environments.

  • Adds browser environment detection using typeof process === "undefined"
  • Disables timing functionality in browsers while preserving Node.js behavior
  • Updates function types to better reflect return value constraints

Comment on lines +116 to +119
function time<T extends unknown[]>(
key: string,
fn: (...args: T) => void | Promise<void>
): (...args: T) => void | Promise<void> {
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

The function type has been narrowed from unknown to void | Promise<void>, but this could be a breaking change if callers expect return values from the wrapped functions. Consider preserving the original return type or using a generic type parameter.

Suggested change
function time<T extends unknown[]>(
key: string,
fn: (...args: T) => void | Promise<void>
): (...args: T) => void | Promise<void> {
function time<T extends unknown[], R>(
key: string,
fn: (...args: T) => R
): (...args: T) => R {

Copilot uses AI. Check for mistakes.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@azu azu added the Type: Bug Bug or Bug fixes label Jul 24, 2025
@azu azu self-assigned this Jul 24, 2025
@azu azu enabled auto-merge (squash) July 24, 2025 00:03
@azu azu merged commit 4f9aa15 into master Jul 24, 2025
17 checks passed
@azu azu deleted the fix/browser-compatibility-timing branch July 24, 2025 00:05
@github-actions github-actions bot mentioned this pull request Jul 24, 2025
azu added a commit that referenced this pull request Jul 24, 2025
<!-- Release notes generated using configuration in .github/release.yml
at master -->

## What's Changed
### Bug Fixes
* fix(kernel): add browser compatibility for timing utility by @azu in
#1663
### Documentation
* docs: add Claude Code setup instructions to MCP documentation by @azu
in #1652
### CI
* chore(deps): update github/codeql-action action to v3.29.2 by
@renovate[bot] in #1638
* chore(deps): update rossjrw/pr-preview-action action to v1.6.2 by
@renovate[bot] in #1648
### Dependency Updates
* chore(deps): update dependency lerna to ^8.2.3 by @renovate[bot] in
#1637
* chore(deps): update eslint to ^8.35.1 (patch) by @renovate[bot] in
#1639
* chore(deps): update dependency globals to ^16.3.0 by @renovate[bot] in
#1640
* chore(deps): update dependency @eslint/js to ^9.30.1 by @renovate[bot]
in #1641
* fix(deps): update patch updates (patch) by @renovate[bot] in
#1642
* chore(deps): update dependency @types/node to ^22.16.0 by
@renovate[bot] in #1643
* fix(deps): update dependency @babel/core to ^7.28.0 by @renovate[bot]
in #1644
* fix(deps): update babel monorepo to ^7.28.0 (minor) by @renovate[bot]
in #1645
* fix(deps): update dependency zod to ^3.25.71 by @renovate[bot] in
#1646
* fix(deps): update dependency @modelcontextprotocol/sdk to ^1.15.0 by
@renovate[bot] in #1649
* fix(deps): update dependency zod to ^3.25.73 by @renovate[bot] in
#1650
* fix(deps): update dependency zod to ^3.25.74 by @renovate[bot] in
#1651
* fix(deps): update dependency zod to ^3.25.75 by @renovate[bot] in
#1653
* chore(deps): update eslint to ^8.36.0 (patch) by @renovate[bot] in
#1654
* fix(deps): update dependency zod to ^3.25.76 by @renovate[bot] in
#1655
* chore(deps): update patch updates (patch) by @renovate[bot] in
#1656
* chore(deps): update pnpm to v10.13.1 by @renovate[bot] in
#1657
* fix(deps): update patch updates (patch) by @renovate[bot] in
#1658
* chore(deps): update dependency @eslint/js to ^9.31.0 by @renovate[bot]
in #1659
* chore(deps): update eslint to ^8.37.0 (minor) by @renovate[bot] in
#1661
* chore(deps): update patch updates (patch) by @renovate[bot] in
#1662
### Other Changes
* feat(mcp): add debug logging support for MCP server by @azu in
#1636


**Full Changelog**:
v15.2.0...v15.2.1

Co-authored-by: azu <azu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant