IntegerAlex / IntegerAlex/hasty-server

Migrate to Pure ES Modules and Drop CommonJS Support

Open
#89 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
15
Forks
19
PR merge metrics
No merged PRs in 30d

Description

## Background
Currently, Hasty Server supports both CommonJS (`require()`) and ES Modules (`import`) module systems. While this dual support is helpful for compatibility, maintaining both systems increases complexity and goes against the Node.js ecosystem's direction towards ES Modules as the standard.

## Current State
- The project currently supports both module systems
- Package can be imported using both `require()` and `import`
- Examples in documentation show both syntaxes
- No clear preference is indicated in the documentation

## Proposed Changes
1. **Package Structure Updates:**
- Convert all source files to use `.mjs` extension
- Update `package.json` to include `"type": "module"`
- Remove CommonJS-specific code paths

2. **Documentation Updates:**
- Update all code examples to use ES Module syntax
- Add migration guide for users moving from CommonJS
- Update installation and usage instructions

3. **Implementation Details:**
- Replace `module.exports` with `export default`
- Convert any `require()` calls to `import` statements
- Update test files to use ES Module syntax
- Implement proper error messages for CommonJS usage attempts

## Benefits
- Aligned with Node.js future direction
- Simplified codebase maintenance
- Better tree-shaking support
- Cleaner syntax and improved developer experience
- Better compatibility with modern JavaScript tools and bundlers

## Breaking Changes
This will be a breaking change requiring a major version bump:
- Users will need to update their import statements
- Projects using CommonJS will need to migrate
- Minimum Node.js version requirement may need to be updated

## Implementation Plan
1. Create new branch for ES Module migration
2. Update source files one at a time
3. Update tests to ensure functionality remains intact
4. Update documentation and examples
5. Create comprehensive migration guide
6. Release as major version update (e.g., v1.0.0)

## Questions to Consider
- What should be the minimum supported Node.js version?
- Should we provide a transition period with both systems?
- How can we best support users during migration?

Would appreciate feedback on this proposal, especially regarding the implementation plan and transition strategy.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.