dlemstra/magick-wasm

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

Closed this issue · 4 comments

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 :)

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.

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

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()

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.