Skip to content

Conversation

@AaronDDM
Copy link
Collaborator

@AaronDDM AaronDDM commented Sep 10, 2025

What did you do?

  • To maintain full backwards compatibility, we introduced a new cjs-wrapper with it's own fixed typed exports (CUST-4757)

License

I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@playerzero-ai
Copy link

playerzero-ai bot commented Sep 10, 2025

Pull Request Summary

The pull request introduces several changes aimed at improving the compatibility and developer experience for users of the Nylas SDK, particularly those using CommonJS (CJS) modules. Here are the key changes:

  • CommonJS Compatibility Enhancements:

    • Added cjs-wrapper.d.ts and cjs-wrapper.js to provide TypeScript typings and CJS compatibility, respectively. This ensures that both default and named exports are accessible for CJS users.
    • Improved interoperability for Node/CommonJS consumers by aligning with typical CJS expectations.
  • Developer Experience Improvements:

    • Introduced a new example (examples/cjs-only/index.js) demonstrating how to use the SDK with CommonJS, including error handling and logging practices.
    • Added a logger utility (examples/cjs-only/utils/logger.js) for enhanced console output, including colorized and timestamped logs, and a function to mask sensitive information.
  • TypeScript Configuration Updates:

    • Updated tsconfig.cjs.json and tsconfig.json to enable better interoperability between ES modules and CommonJS, reducing import-related errors and improving developer ergonomics.
    • Changes include enabling esModuleInterop and allowSyntheticDefaultImports, which facilitate smoother module imports.
  • Code Structure Adjustments:

    • Modified the export style of the Nylas class in src/nylas.ts for clearer module structure, though this does not affect runtime behavior or the public API.

Overall, these changes aim to enhance the developer experience, particularly for those using CommonJS, by providing better type information, improved logging, and more robust examples, while ensuring compatibility and reducing potential errors during development.

Files Changed

File Name Summary
cjs-wrapper.d.ts New TypeScript declaration for the CommonJS wrapper. Re-exports model types from ./lib/types/models/index.js, imports Nylas type and declares const nylasExport: typeof Nylas; then export = nylasExport; — typing-only, no runtime changes.
cjs-wrapper.js New CommonJS wrapper that requires ./lib/cjs/nylas.js, sets module.exports to the module default and uses Object.assign to copy named exports onto it; enables require() consumers to get default and named exports.
examples/cjs-only/index.js New CommonJS example: loads .env, validates NYLAS_API_KEY and NYLAS_GRANT_ID (fail-fast), initializes client (optional NYLAS_API_URI), masks API key in logs, lists messages and logs only id+subject; exits with code 1 on errors.
examples/cjs-only/utils/logger.js New CJS logger utility: timestamped, colorized levels (info/success/warn/error/debug), JSON-stringifies non-strings, provides maskSecret helper; exports { logger, maskSecret }.
tsconfig.cjs.json Compiler tweaks for CJS build: "esModuleInterop": true, "allowSyntheticDefaultImports": true, "moduleResolution": "node" — improves ES/CJS import ergonomics and Node-style resolution; may emit TS interop helpers.
tsconfig.json Flipped "esModuleInterop" false → true. Improves default-import interop with CommonJS modules; changes emitted import helpers/shape, so run tests/verify artifacts.
src/nylas.ts Export style changed: class declared first then export default Nylas; (instead of inline export default class ...). No internal code or runtime behavior changed.

View more in PlayerZero
updated: Sep 10 @ 02:26 PM UTC

@codecov
Copy link

codecov bot commented Sep 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.87%. Comparing base (bc4bbb0) to head (17fd3eb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #665   +/-   ##
=======================================
  Coverage   94.87%   94.87%           
=======================================
  Files          35       35           
  Lines         781      781           
  Branches       66       66           
=======================================
  Hits          741      741           
  Misses         33       33           
  Partials        7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AaronDDM AaronDDM merged commit cd02642 into main Sep 10, 2025
7 checks passed
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.

3 participants