这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@misund
Copy link
Owner

@misund misund commented Oct 11, 2025

⚠️ BREAKING CHANGE

This PR converts the package to ESM-only and TypeScript. Projects using require() will need to migrate to ESM or use dynamic imports.

After this PR CommonJS is no longer supported. See ESM Module FAQ.

Summary

This PR modernizes the build tooling to current standards:

  • Convert from JavaScript to TypeScript
  • ESM module format (breaking change)
  • TypeScript 5.9.2
  • tsx for test execution
  • Node.js 20, 22, 24 support
  • get-contrast-ratio@1.0.0-1 (ESM version)

Changes

TypeScript conversion

  • ✅ Convert src/index.js → src/index.ts with proper type annotations
  • ✅ Convert test/test.js → test/test.ts
  • ✅ Add TypeScript 5.9.2 with ES2022 target
  • ✅ Create tsconfig.json
  • ✅ Add return type annotations for all exported functions
  • ✅ Fix typo in package.json description: "if a to colors" → "if two colors"

ESLint improvements

  • ✅ Update eslint.config.mjs to match other packages in cluster
  • ✅ Add TypeScript-specific linting rules
  • ✅ Add @typescript-eslint/eslint-plugin 7.18.0
  • ✅ Add @typescript-eslint/parser 7.18.0
  • ✅ Add eslint-config-prettier 10.1.8

ESM conversion (⚠️ Breaking Change)

  • ✅ Add "type": "module" to package.json
  • ✅ Add exports field for proper ESM support
  • ✅ Update tsconfig.json to output ES2022 modules
  • ✅ Update test imports to use .js extension for ESM compatibility
  • ✅ Update get-contrast-ratio dependency from 0.2.1 to 1.0.0-1
  • ✅ Replace Babel with TypeScript compiler

Build system improvements

  • ✅ Replace Babel with TypeScript compiler
  • ✅ Replace @babel/register with tsx for running tests
  • ✅ Create .mocharc.json to use tsx with --import flag
  • ✅ Add skipLibCheck to tsconfig for better compatibility
  • ✅ Add @types/node 22.10.5
  • ✅ Add @types/mocha 10.0.10

CI/CD improvements

  • ✅ Update CI workflow to test on Node.js 20, 22, 24 (removing EOL Node 18)
  • ✅ Add explicit build verification step to workflow

Testing improvements

  • ✅ Tests now run against TypeScript source directly (faster iteration)
  • ✅ Added test to verify built ESM output works correctly

Migration Guide

For consumers using CommonJS (require):

// ❌ No longer works
const { passesWcagAa } = require('passes-wcag')

// ✅ Option 1: Convert to ESM
import { passesWcagAa } from 'passes-wcag'

// ✅ Option 2: Use dynamic import
const { passesWcagAa } = await import('passes-wcag')

For consumers already using ESM:

No changes needed - the package now properly exports ESM with full TypeScript types.

Test plan

  • Build succeeds (yarn build)
  • Linting passes (yarn lint)
  • All tests pass (yarn test)
  • All 9 test cases passing (including new build output test)
  • Built ESM output verified to work correctly

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

## ⚠️ BREAKING CHANGE

This PR converts the package to **ESM-only** and **TypeScript**. Projects using `require()` will need to migrate to ESM or use dynamic imports.

After this PR CommonJS is no longer supported. See [ESM Module FAQ](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).

## Summary
This PR modernizes the build tooling to current standards:
- **Convert from JavaScript to TypeScript**
- **ESM** module format (breaking change)
- **TypeScript 5.9.2**
- **tsx** for test execution
- **Node.js 20, 22, 24** support
- **get-contrast-ratio@1.0.0-1** (ESM version)

## Changes

### TypeScript conversion
- ✅ Convert src/index.js → src/index.ts with proper type annotations
- ✅ Convert test/test.js → test/test.ts
- ✅ Add TypeScript 5.9.2 with ES2022 target
- ✅ Create tsconfig.json
- ✅ Add return type annotations for all exported functions
- ✅ Fix typo in package.json description: "if a to colors" → "if two colors"

### ESLint improvements
- ✅ Update eslint.config.mjs to match other packages in cluster
- ✅ Add TypeScript-specific linting rules
- ✅ Add @typescript-eslint/eslint-plugin 7.18.0
- ✅ Add @typescript-eslint/parser 7.18.0
- ✅ Add eslint-config-prettier 10.1.8

### ESM conversion (⚠️ Breaking Change)
- ✅ Add "type": "module" to package.json
- ✅ Add exports field for proper ESM support
- ✅ Update tsconfig.json to output ES2022 modules
- ✅ Update test imports to use .js extension for ESM compatibility
- ✅ Update get-contrast-ratio dependency from 0.2.1 to 1.0.0-1
- ✅ Replace Babel with TypeScript compiler

### Build system improvements
- ✅ Replace Babel with TypeScript compiler
- ✅ Replace @babel/register with tsx for running tests
- ✅ Create .mocharc.json to use tsx with --import flag
- ✅ Add skipLibCheck to tsconfig for better compatibility
- ✅ Add @types/node 22.10.5
- ✅ Add @types/mocha 10.0.10

### CI/CD improvements
- ✅ Update CI workflow to test on Node.js 20, 22, 24 (removing EOL Node 18)
- ✅ Add explicit build verification step to workflow

### Testing improvements
- ✅ Tests now run against TypeScript source directly (faster iteration)
- ✅ Added test to verify built ESM output works correctly

## Migration Guide

### For consumers using CommonJS (require):
```javascript
// ❌ No longer works
const { passesWcagAa } = require('passes-wcag')

// ✅ Option 1: Convert to ESM
import { passesWcagAa } from 'passes-wcag'

// ✅ Option 2: Use dynamic import
const { passesWcagAa } = await import('passes-wcag')
```

### For consumers already using ESM:
No changes needed - the package now properly exports ESM with full TypeScript types.

## Test plan
- [x] Build succeeds (yarn build)
- [x] Linting passes (yarn lint)
- [x] All tests pass (yarn test)
- [x] All 9 test cases passing (including new build output test)
- [x] Built ESM output verified to work correctly

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

Co-Authored-By: Claude <noreply@anthropic.com>
@misund misund force-pushed the upgrade-typescript-esm branch from 6e86b81 to d946163 Compare October 11, 2025 00:42
@misund misund changed the title upgrade typescript esm BREAKING: Convert to ESM-only, TypeScript, and upgrade build tools Oct 11, 2025
@misund misund marked this pull request as ready for review October 11, 2025 00:45
@misund misund merged commit 6d999a6 into main Oct 11, 2025
3 checks passed
@misund misund deleted the upgrade-typescript-esm branch October 11, 2025 00:46
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