ASN1.js icon indicating copy to clipboard operation
ASN1.js copied to clipboard

Feature/esmbuild

Open Hexagon opened this issue 4 years ago • 4 comments

  • Create bundled es-module build/asn1.bundle.mjs for simple browser usage, and Deno support.

  • Add basic installation instructions

  • ~Include build/* in repo for certain cdn-providers, e.g. deno.land/x or jsdeliver/gh~

Hexagon avatar Apr 18 '22 19:04 Hexagon

I don't like the idea of keeping bundled (compiled) files in repo.

unpkg cdn-provider allows to use this module without minification

import * as asn1js from "https://unpkg.com/asn1js?module";

microshine avatar Apr 18 '22 20:04 microshine

Unpkg works great for me, thanks again for the tip.

Having a "standardised" bundle in repo would serve a purpose anyways, enabling all cdn providers to serve the bundle.

If that's not interesting, maybe we can revert the gitignore change but still build the bundle? (and let npm be the source of choice for Deno, and simplify browser usage)

That would make this work:

import { x } from "https://cdn.jsdelivr.net/npm/asn1js@2/build/asn1.bundle.mjs";

Edit: Force pushed a new version of this pull request, without repo-inclusion of build/.

Hexagon avatar Apr 18 '22 20:04 Hexagon

I've published [email protected]. Please try it.

HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script type="module">
    import * as asn1js from "https://unpkg.com/asn1js?module";

    const asn = new asn1js.Utf8String({
      value: "Hello world",
    });

    console.log(asn.toString()); // ascii
    console.log(asn.toString("hex"));
  </script>
</body>

</html>

Console

UTF8String : 'Hello world'
index.html:20 0c0b48656c6c6f20776f726c64

I don't like the idea of keeping the bundle file with included external dependencies in the NPM registry. I guess it's better to compile a bundle file on application later with env requirements.

microshine avatar May 12 '22 08:05 microshine

@microshine

Upgraded fido2-lib @ https://github.com/webauthn-open-source/fido2-lib/pull/85 . Works fine!

Hexagon avatar May 12 '22 21:05 Hexagon