agilgur5 / agilgur5/trim-canvas

ESM entry alongside the existing UMD build

Open
#11 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
74
Forks
5
PR merge metrics
No merged PRs in 30d

Description

I realize this package is approaching 9 years since it was last published, but any chance an ESM entry could be added to package.json? The package already ships an ES module file (`index.es6`), so this is mostly a matter of renaming or copying it to `index.mjs` and pointing an `exports` map at it, no source changes needed.

The motivation: `react-signature-canvas` has a proper [`module` and `exports` listing](https://github.com/agilgur5/react-signature-canvas/blob/f6c0b64cf3416681ba959cdaa4eaf2cb4dd87c5e/package.json#L7-L12), so modern bundlers handle it cleanly. The interop fails one layer down on `trim-canvas`, with a runtime "...is not a function" the first time the wrapped function is called. A proper ESM entry would let bundlers consume `trim-canvas` as ESM directly and skip the CJS/ESM interop layer that's currently misbehaving on the published UMD bundle due to:

1. `module.exports = t()` is buried inside an IIFE behind a ternary, so no top-level CJS export is statically visible.
2. `Object.defineProperty(t, "__esModule", { value: true })` is set at runtime inside the inner factory. Interop layers only honor `__esModule` when it's set statically at the top of the file.

Thanks for your consideration.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.