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

Conversation

@misund
Copy link
Owner

@misund misund commented Oct 10, 2025

⚠️ BREAKING CHANGE

This PR converts the package to ESM-only. 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:

  • ESLint 9 with flat config
  • ESM module format (breaking change)
  • TypeScript 5.9.2
  • tsx for test execution
  • Node.js 20, 22, 24 support
  • get-relative-luminance@2.0.0-1 (ESM version)

Changes

ESLint 9 with flat config

  • ✅ Upgrade ESLint 8.25.0 → 9.32.0
  • ✅ Create eslint.config.mjs with modern flat config format
  • ✅ Remove old .eslintrc.json
  • ✅ Upgrade @typescript-eslint/eslint-plugin 5.62.0 → 7.18.0
  • ✅ Upgrade @typescript-eslint/parser 5.62.0 → 7.18.0
  • ✅ Upgrade eslint-config-prettier already at 10.1.8
  • ✅ Upgrade eslint-plugin-import already at 2.32.0

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-relative-luminance dependency from 2.0.0-0 to 2.0.0-1

Build system improvements

  • ✅ TypeScript already at 5.9.2
  • ✅ Replace ts-node with tsx for running tests
  • ✅ Update .mocharc.json to use tsx with --import flag
  • ✅ Add skipLibCheck to tsconfig for better compatibility
  • ✅ Mocha already at 11.7.1
  • ✅ Upgrade np 9.2.0 → 10.2.0
  • ✅ Add @types/node for better type support
  • ✅ Update @types/mocha 9.1.1 → 10.0.10

CI/CD improvements

  • ✅ Modernize GitHub Actions workflow
  • ✅ Test on Node.js 20, 22, 24 (current supported versions)
  • ✅ Update to actions/checkout@v4 and actions/setup-node@v4 (already done)
  • ✅ Add explicit build verification step

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 getContrastRatio = require('get-contrast-ratio')

// ✅ Option 1: Convert to ESM
import getContrastRatio from 'get-contrast-ratio'

// ✅ Option 2: Use dynamic import
const { default: getContrastRatio } = await import('get-contrast-ratio')

For consumers already using ESM:

No changes needed - the package now properly exports ESM.

Test plan

  • Build succeeds (yarn build)
  • Linting passes (yarn lint)
  • All tests pass (yarn test)
  • All 7 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**. 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:
- **ESLint 9** with flat config
- **ESM** module format (breaking change)
- **TypeScript 5.9.2**
- **tsx** for test execution
- **Node.js 20, 22, 24** support
- **get-relative-luminance@2.0.0-1** (ESM version)

## Changes

### ESLint 9 with flat config
- ✅ Upgrade ESLint 8.25.0 → 9.32.0
- ✅ Create `eslint.config.mjs` with modern flat config format
- ✅ Remove old `.eslintrc.json`
- ✅ Upgrade @typescript-eslint/eslint-plugin 5.62.0 → 7.18.0
- ✅ Upgrade @typescript-eslint/parser 5.62.0 → 7.18.0
- ✅ Upgrade eslint-config-prettier already at 10.1.8
- ✅ Upgrade eslint-plugin-import already at 2.32.0

### 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-relative-luminance dependency from 2.0.0-0 to 2.0.0-1

### Build system improvements
- ✅ TypeScript already at 5.9.2
- ✅ Replace ts-node with tsx for running tests
- ✅ Update .mocharc.json to use tsx with --import flag
- ✅ Add skipLibCheck to tsconfig for better compatibility
- ✅ Mocha already at 11.7.1
- ✅ Upgrade np 9.2.0 → 10.2.0
- ✅ Add @types/node for better type support
- ✅ Update @types/mocha 9.1.1 → 10.0.10

### CI/CD improvements
- ✅ Modernize GitHub Actions workflow
- ✅ Test on Node.js 20, 22, 24 (current supported versions)
- ✅ Update to actions/checkout@v4 and actions/setup-node@v4 (already done)
- ✅ Add explicit build verification step

### 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 getContrastRatio = require('get-contrast-ratio')

// ✅ Option 1: Convert to ESM
import getContrastRatio from 'get-contrast-ratio'

// ✅ Option 2: Use dynamic import
const { default: getContrastRatio } = await import('get-contrast-ratio')
```

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

## Test plan
- [x] Build succeeds (`yarn build`)
- [x] Linting passes (`yarn lint`)
- [x] All tests pass (`yarn test`)
- [x] All 7 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 marked this pull request as ready for review October 10, 2025 22:16
@misund misund merged commit 3b80b56 into main Oct 10, 2025
3 checks passed
@misund misund deleted the upgrade-eslint-esm branch October 10, 2025 22:16
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