dlemstra / magick-wasm

The WASM library for ImageMagick
Apache License 2.0
537 stars 34 forks source link

use "node" conditional exports to export ImageMagick that auto-initializes magick-wasm #167

Closed iambumblehead closed 3 months ago

iambumblehead commented 3 months ago

Is your feature request related to a problem? Please describe.

The current ImageMagick behaviour is "fine" but involves some ceremony loading and initializing magick.wasm.

Describe the solution you'd like

For node environments (and deno), it would be nice if ImageMagick would load and initialize "magick.wasm" itself. Scripts using ImageMagick could then use ImageMagick without any magick.wasm load-init ceremony.

https://nodejs.org/api/packages.html#conditional-export

Basically, to do this, the '@imagemagick/magick-wasm' package would export a node-specific file,

        ".": {
            "import": "./dist/index.js",
+           "node": "./dist/index.node.js",
            "require": "./dist/index.umd.cjs",
            "types": "./dist/index.d.ts"
        },

Then, inside the node-specific file, init and load "magick.wasm" wherever is best

Describe alternatives you've considered

No response

Additional context

thank you :)

dlemstra commented 3 months ago

I don't think that I want to add that. I would prefer it if the browser and node api remain similar to make it easier to test/document things.

iambumblehead commented 3 months ago

Politely closing this un-wanted issue. Thank you for considering it.

iambumblehead commented 3 months ago

It would be nice if magick.wasm-file-loading were simplified for all environments. Maybe the current interface could still be reduced to a simpler call such as this

MagickWasm.init(import.meta.resolve('@imagemagick/magick-wasm/magick.wasm'))

and maybe the wasm moduleId or url are optional, helping things to be smaller still

MagickWasm.init()
dlemstra commented 3 months ago

I also don't think I want to do that now. Maybe in the future but I also don't think it's such a hassle to use the current api.