GLOKON / guacamole-common-js

Guacamole JS Library, with TypeScript
Other
2 stars 1 forks source link

ESM named exports #7

Closed codebling closed 2 months ago

codebling commented 2 months ago

Adds named exports to ESM build.

All changes are restricted to the esm build file, to avoid changing the upgrade/maintenance process.

Doing so also happens to be the extremely lazy/easy way of doing things: we dynamically import the ESM file that was just generated by the ESM build, we enumerate all of the objects in the default export, append this to the string contents of the ESM file, and rewrite the file.

This results in the addition of the following at the end of the file:

const ArrayBufferReader = Guacamole.ArrayBufferReader;
const ArrayBufferWriter = Guacamole.ArrayBufferWriter;
//...
const VideoPlayer = Guacamole.VideoPlayer;
export {
    ArrayBufferReader,
    ArrayBufferWriter,
//...
    VideoPlayer,
};

I have tested this and it seems to be working. If this is not merged, consider changing the README, whose example implies named exports:

import { Client, Tunnel } from '@glokon/guacamole-common-js';

DanielMcAssey commented 2 months ago

Thats fantastic, thank you, I was originally going to use Rollup, but this is just simple and ingenious! Many thanks!