From 6d456d25264c1749206d9d9cecd5bb01ef75ac0f Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Sat, 6 Sep 2025 00:21:44 -0400 Subject: [PATCH 1/3] feat: add ESM build support with dual CommonJS/ESM exports - Add separate TypeScript configs for ESM and CommonJS builds - Configure package.json with proper dual exports - Add build script to fix ESM imports with .js extensions - Support both import and require syntax - Add CONTRIBUTING.md with contribution guidelines --- CONTRIBUTING.md | 73 ++++++++++++++++++++++++++++++++++++++ package.json | 68 ++++++++++++++++++++++------------- scripts/fix-esm-imports.js | 46 ++++++++++++++++++++++++ tsconfig.cjs.json | 9 +++++ tsconfig.esm.json | 10 ++++++ 5 files changed, 182 insertions(+), 24 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 scripts/fix-esm-imports.js create mode 100644 tsconfig.cjs.json create mode 100644 tsconfig.esm.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..2a1f047 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,73 @@ +# Contributing to DevMe SDK JS + +Thank you for your interest in contributing to DevMe SDK JS! We welcome contributions from the community. + +## Getting Started + +1. Fork the repository +2. Clone your fork locally +3. Create a new branch for your feature or fix +4. Make your changes +5. Push to your fork +6. Submit a pull request to the `master` branch + +## Development Setup + +```bash +# Install dependencies +npm install + +# Run tests +npm test + +# Run linter +npm run lint + +# Run type checking +npm run typecheck + +# Build the project +npm run build +``` + +## Code Style + +- Follow the existing code style in the project +- Use TypeScript for all new code +- Ensure all tests pass before submitting +- Run linter and fix any issues +- Ensure type checking passes + +## Commit Messages + +- Use clear and descriptive commit messages +- Follow conventional commit format when possible: + - `feat:` for new features + - `fix:` for bug fixes + - `docs:` for documentation changes + - `refactor:` for code refactoring + - `test:` for test additions or changes + - `chore:` for maintenance tasks + +## Pull Request Process + +1. Update the README.md with details of changes if applicable +2. Ensure all tests pass +3. Update documentation as needed +4. Request review from maintainers +5. Address any feedback provided + +## Reporting Issues + +- Use GitHub Issues to report bugs +- Provide clear reproduction steps +- Include relevant system information +- Attach any relevant logs or screenshots + +## Questions? + +Feel free to open an issue for any questions about contributing. + +## License + +By contributing, you agree that your contributions will be licensed under the same license as the project. \ No newline at end of file diff --git a/package.json b/package.json index 7b7d072..7a9cef1 100644 --- a/package.json +++ b/package.json @@ -28,39 +28,55 @@ }, "license": "MIT", "author": "DEV.ME (https://dev.me)", - "main": "./dist/index.js", - "types": "./dist/index.d.ts", - "typings": "./dist/index.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/cjs/index.d.ts", + "typings": "./dist/cjs/index.d.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "require": "./dist/index.js", - "import": "./dist/index.js", - "default": "./dist/index.js" + "types": { + "import": "./dist/esm/index.d.ts", + "require": "./dist/cjs/index.d.ts" + }, + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js", + "default": "./dist/cjs/index.js" }, "./api": { - "types": "./dist/api.d.ts", - "require": "./dist/api.js", - "import": "./dist/api.js", - "default": "./dist/api.js" + "types": { + "import": "./dist/esm/api.d.ts", + "require": "./dist/cjs/api.d.ts" + }, + "import": "./dist/esm/api.js", + "require": "./dist/cjs/api.js", + "default": "./dist/cjs/api.js" }, "./configuration": { - "types": "./dist/configuration.d.ts", - "require": "./dist/configuration.js", - "import": "./dist/configuration.js", - "default": "./dist/configuration.js" + "types": { + "import": "./dist/esm/configuration.d.ts", + "require": "./dist/cjs/configuration.d.ts" + }, + "import": "./dist/esm/configuration.js", + "require": "./dist/cjs/configuration.js", + "default": "./dist/cjs/configuration.js" }, "./base": { - "types": "./dist/base.d.ts", - "require": "./dist/base.js", - "import": "./dist/base.js", - "default": "./dist/base.js" + "types": { + "import": "./dist/esm/base.d.ts", + "require": "./dist/cjs/base.d.ts" + }, + "import": "./dist/esm/base.js", + "require": "./dist/cjs/base.js", + "default": "./dist/cjs/base.js" }, "./common": { - "types": "./dist/common.d.ts", - "require": "./dist/common.js", - "import": "./dist/common.js", - "default": "./dist/common.js" + "types": { + "import": "./dist/esm/common.d.ts", + "require": "./dist/cjs/common.d.ts" + }, + "import": "./dist/esm/common.js", + "require": "./dist/cjs/common.js", + "default": "./dist/cjs/common.js" }, "./package.json": "./package.json" }, @@ -72,7 +88,11 @@ "package.json" ], "scripts": { - "build": "rm -rf dist && tsc -p .", + "build": "rm -rf dist && yarn build:cjs && yarn build:esm && yarn build:fix-esm && yarn build:package-json", + "build:cjs": "tsc -p tsconfig.cjs.json", + "build:esm": "tsc -p tsconfig.esm.json", + "build:fix-esm": "node scripts/fix-esm-imports.js", + "build:package-json": "echo '{\"type\": \"module\"}' > dist/esm/package.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json", "lint": "biome check .", "lint:fix": "biome check --write .", "format": "biome format --write .", diff --git a/scripts/fix-esm-imports.js b/scripts/fix-esm-imports.js new file mode 100644 index 0000000..cfb1b24 --- /dev/null +++ b/scripts/fix-esm-imports.js @@ -0,0 +1,46 @@ +const fs = require('fs'); +const path = require('path'); + +function addJsExtensions(dir) { + const files = fs.readdirSync(dir, { withFileTypes: true }); + + for (const file of files) { + const filePath = path.join(dir, file.name); + + if (file.isDirectory()) { + addJsExtensions(filePath); + } else if (file.name.endsWith('.js')) { + let content = fs.readFileSync(filePath, 'utf8'); + + // Fix relative imports to add .js extension + content = content.replace( + /from\s+['"](\.\/[^'"]+)(? Date: Sat, 6 Sep 2025 00:23:17 -0400 Subject: [PATCH 2/3] chore: update --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7cd5837..828d877 100644 --- a/README.md +++ b/README.md @@ -616,12 +616,12 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) f ## 🆘 Support - 📧 Email: [support@dev.me](mailto:support@dev.me) -- 📚 Documentation: [dev.me/docs](https://dev.me/docs) -- 🐦 Twitter: [@devmedotme](https://twitter.com/devmedotme) +- 📚 Documentation: [dev.me/documentation](https://dev.me/documentation) +- 🐦 Twitter: [@devhq](https://x.com/devhq) ## 🔗 Links -- [API Documentation](https://dev.me/docs) +- [API Documentation](https://dev.me/documentation) - [Pricing](https://dev.me/pricing) - [Blog](https://dev.me/blog) - [Changelog](CHANGELOG.md) From b56b4f56e3f491438cbdca46d5b86928f9e07558 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Sat, 6 Sep 2025 00:24:51 -0400 Subject: [PATCH 3/3] chore: update --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6015867..bdabb9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,26 @@ ## [Unreleased] +## v1.2.1 + ### Added +- ESM build support with dual CommonJS/ESM exports +- Separate TypeScript configurations for ESM and CommonJS builds +- Build script to fix ESM imports with .js extensions +- Support for both import and require syntax +- CONTRIBUTING.md with contribution guidelines - Enhanced package.json exports field for better module resolution - Support for subpath exports allowing cleaner imports (e.g., `@devmehq/sdk-js/api`) - Proper TypeScript types exports for all subpaths - Files field in package.json to optimize npm package size +### Changed + +- Updated SDK types and client structure +- Improved API structure and code formatting +- Enhanced linting configuration + ### Fixed - Corrected main and types paths to point to dist directory