ASN1.js
ASN1.js copied to clipboard
Publish as ESM?
This module is authored in ESM but then transpiles that to CJS, then finally uses rollup to create a big code blob.
Image from https://esbuild.github.io/analyze/ :
The tsc config could be updated to just publish ESM and rollup could be removed.
This would make it easier to do tree shaking to remove unused code from bundles.
The same change could be made to pvutils and pvtsutils.
@microshine I can open some PRs if you'd fine this useful?
The situation is such that when publishing npm modules, I compile the code into two formats: CommonJS (cjs) and ECMAScript modules (esm). I utilize Rollup to generate bundled files as well as to create the index.d.ts file. In certain instances, modules (like @peculiar/x509) may include additional settings for compiling the final files for browser use. I am aware that the standard TypeScript compiler can be used to produce various module formats, but it generates JavaScript files with the same structure as the TypeScript files, resulting in a multitude of files with redundant imports. Conversely, when using Rollup, the compiled code appears much more succinct.
Regarding the asn1js module, I'm not confident that it can be made significantly more compact through tree shaking since all the structure classes are utilized in the fromBER method, which is used by applications. The only code that might not be used in the asn1js module is the compareSchema function. However, if an application is written without using this function, it would be excluded from the bundle file during the build process. Here is an example of a simple application. From the screenshot, it is apparent that the application file includes the asn1js module, but the compareSchema function is not present.
Example of the application:
import * as asn1js from "asn1js";
const asn = asn1js.fromBER(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]));
console.log(asn);
Additionally, I tried using the esbuild bundler, and it also successfully omitted the compareSchema function from the output file.