这是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 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
  • 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-contrast-ratio@1.0.0-1 (ESM version)
  • GitHub Actions replacing Travis CI

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
  • ✅ Fix typo in JSDoc: "wich" → "which"

ESLint 9 with flat config

  • ✅ Upgrade ESLint 6.6.0 → 9.32.0
  • ✅ Create eslint.config.mjs with modern flat config format
  • ✅ Remove old .eslintrc.json
  • ✅ Add @eslint/eslintrc 3.3.1 and @eslint/js 9.32.0
  • ✅ Add @typescript-eslint/eslint-plugin 7.18.0
  • ✅ Add @typescript-eslint/parser 7.18.0
  • ✅ Upgrade eslint-config-prettier to 10.1.8
  • ✅ Upgrade eslint-plugin-import to 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-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 old Babel packages with modern tooling
  • ✅ Replace @babel/register with tsx for running tests
  • ✅ Create .mocharc.json to use tsx with --import flag
  • ✅ Add skipLibCheck to tsconfig for better compatibility
  • ✅ Upgrade Mocha 6.2.2 → 11.7.1
  • ✅ Upgrade np 5.1.3 → 10.2.0
  • ✅ Add @types/node 22.10.5
  • ✅ Add @types/mocha 10.0.10

CI/CD improvements

  • ✅ Replace Travis CI with GitHub Actions
  • ✅ Test on Node.js 20, 22, 24 (current supported versions)
  • ✅ Use actions/checkout@v4 and actions/setup-node@v4
  • ✅ 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 getBestContrastColor = require('get-best-contrast-color')

// ✅ Option 1: Convert to ESM
import getBestContrastColor from 'get-best-contrast-color'

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

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

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).

This PR modernizes the build tooling to current standards:
- **Convert from JavaScript to TypeScript**
- **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-contrast-ratio@1.0.0-1** (ESM version)
- **GitHub Actions** replacing Travis CI

- ✅ 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
- ✅ Fix typo in JSDoc: "wich" → "which"

- ✅ Upgrade ESLint 6.6.0 → 9.32.0
- ✅ Create eslint.config.mjs with modern flat config format
- ✅ Remove old .eslintrc.json
- ✅ Add @eslint/eslintrc 3.3.1 and @eslint/js 9.32.0
- ✅ Add @typescript-eslint/eslint-plugin 7.18.0
- ✅ Add @typescript-eslint/parser 7.18.0
- ✅ Upgrade eslint-config-prettier to 10.1.8
- ✅ Upgrade eslint-plugin-import to 2.32.0

- ✅ 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

- ✅ Replace Babel with TypeScript compiler
- ✅ Replace old Babel packages with modern tooling
- ✅ Replace @babel/register with tsx for running tests
- ✅ Create .mocharc.json to use tsx with --import flag
- ✅ Add skipLibCheck to tsconfig for better compatibility
- ✅ Upgrade Mocha 6.2.2 → 11.7.1
- ✅ Upgrade np 5.1.3 → 10.2.0
- ✅ Add @types/node 22.10.5
- ✅ Add @types/mocha 10.0.10

- ✅ Replace Travis CI with GitHub Actions
- ✅ Test on Node.js 20, 22, 24 (current supported versions)
- ✅ Use actions/checkout@v4 and actions/setup-node@v4
- ✅ Add explicit build verification step

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

```javascript
// ❌ No longer works
const getBestContrastColor = require('get-best-contrast-color')

// ✅ Option 1: Convert to ESM
import getBestContrastColor from 'get-best-contrast-color'

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

No changes needed - the package now properly exports ESM.

- [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-eslint-esm branch from 4cac981 to f2fef78 Compare October 10, 2025 23:05
@misund misund marked this pull request as ready for review October 10, 2025 23:11
@misund misund merged commit 0d94f15 into master Oct 10, 2025
3 checks passed
@misund misund deleted the upgrade-eslint-esm branch October 10, 2025 23:11
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