Skip to content

Add WinterTC compatibility ESLint rule#2715

Merged
jar-stripe merged 9 commits into
masterfrom
jar/wintertc-eslint-rule
May 15, 2026
Merged

Add WinterTC compatibility ESLint rule#2715
jar-stripe merged 9 commits into
masterfrom
jar/wintertc-eslint-rule

Conversation

@jar-stripe

@jar-stripe jar-stripe commented May 13, 2026

Copy link
Copy Markdown
Contributor

Why?

stripe-node must run across Node.js, browsers, Deno, Bun, and Cloudflare Workers. Today there's no automated way to catch Node.js-specific API usage leaking into shared code. This adds a lint rule based on the WinterTC Minimum Common Web Platform API spec (ECMA-429) to flag these issues at development time.

No existing ESLint plugin covers this spec — we searched npm, GitHub, and the WinterTC55 org. This is a custom rule.

What?

New ESLint rule (eslint-rules/wintertc-compat.js):

  • Flags imports from Node.js built-in modules (http, crypto, events, etc.)
  • Flags Node.js-specific globals (Buffer, process, __dirname, __filename, global, require, module, exports)
  • Flags NodeJS.* type references (NodeJS.Timeout, NodeJS.ReadableStream, etc.)
  • Enabled for src/**/*.ts, disabled for Node-specific platform files (Node*.ts, stripe.*.node.ts)
  • Added --rulesdir eslint-rules to the lint command in the Justfile

Fixes (non-breaking):

  • Replace NodeJS.Timeout with ReturnType<typeof setTimeout> (portable across runtimes)
  • Remove Buffer from FileData union type (Buffer extends Uint8Array, so callers are unaffected)
  • Move process-dependent code (emitWarning, detectAIAgent, determineProcessUserAgentProperties) into platform functions via Stripe.initialize(). Also fixes an existing bug where emitWarning would crash on non-Node runtimes.
  • Add emitWarning(), getEnv(), getRuntimeVersion() to PlatformFunctions base class with cross-runtime defaults

Deferred to next major (public API types):

  • NodeJS.ReadableStream in StripeStreamResponse and HttpClient (DEVSDK-3112)
  • EventEmitter in StreamingFile and PlatformFunctions (DEVSDK-3113)
  • http.Agent in StripeConfig (DEVSDK-3114)

These are suppressed with eslint-disable + TODO comments referencing the tickets.

Other:

  • Downgrade no-warning-comments from error to warn so TODO comments don't block CI
  • DEVSDK-3111: Follow-up to implement getEnv()/getRuntimeVersion() for Deno, Bun, and Workers

See Also

jar-stripe and others added 9 commits May 13, 2026 14:40
…ed code

stripe-node must run across Node.js, browsers, Deno, Bun, and Cloudflare
Workers. This adds a custom ESLint rule that enforces the WinterTC Minimum
Common Web Platform API spec (ECMA-429) by flagging Node.js built-in module
imports, Node-specific globals (Buffer, process, etc.), and NodeJS.* type
references in shared source files.

Node-specific platform files (Node*.ts, stripe.*.node.ts) are excluded.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
This type is portable across all runtimes — it resolves to
NodeJS.Timeout on Node and number elsewhere.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
Buffer extends Uint8Array, so removing it from the union is
type-compatible — Node.js callers passing a Buffer still satisfy
the Uint8Array branch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
- Add emitWarning(), getEnv(), getRuntimeVersion() to PlatformFunctions
  base class with cross-runtime defaults (console.warn, null, null)
- NodePlatformFunctions overrides with process.emitWarning, process.env,
  process.version
- Move aiAgent/USER_AGENT initialization from static class properties
  into Stripe.initialize(), which receives the platform functions instance
- Remove emitWarning and determineProcessUserAgentProperties from utils.ts
- RequestSender calls emitWarning through platform functions
- Fixes existing bug: emitWarning would crash on non-Node runtimes because
  it checked typeof process.emitWarning without first checking typeof process

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
These Node.js types are part of the public API surface and cannot be
removed without a major version bump:

- http.Agent in StripeConfig (DEVSDK-3114)
- EventEmitter in StreamingFile and PlatformFunctions (DEVSDK-3113)
- NodeJS.ReadableStream in StripeStreamResponse and HttpClient (DEVSDK-3112)

Each suppression has a TODO referencing the Jira ticket for the next
major version.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
- Rename origAI_AGENT to origAiAgentStatic (naming-convention rule)
- Remove TODO prefix from DEVSDK ticket comments (no-warning-comments rule)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
@jar-stripe jar-stripe marked this pull request as ready for review May 13, 2026 22:43
@jar-stripe jar-stripe requested a review from a team as a code owner May 13, 2026 22:43
@jar-stripe jar-stripe requested review from Copilot and prathmesh-stripe and removed request for a team and Copilot May 13, 2026 22:43
@jar-stripe jar-stripe enabled auto-merge (squash) May 14, 2026 15:03
@jar-stripe jar-stripe requested a review from xavdid May 15, 2026 19:00
Comment thread src/lib.ts

@prathmesh-stripe prathmesh-stripe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just one comment, rest of this look great! Thanks for adding this.

@jar-stripe jar-stripe merged commit 044c68e into master May 15, 2026
11 checks passed
@jar-stripe jar-stripe deleted the jar/wintertc-eslint-rule branch May 15, 2026 20:29
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