Yeah, been there, done that in JavaScript world.
I used jQuery a lot before reading the source code and seeing querySelectorAll()
; in addition to jQuery, at that time, failing Promises/A+ tests.
So I dove in to JavaScript itself.
That same with packages build exclusively depedning on Node.js 5 or 10 years ago are not still trying to reconcile CommonJS.
I read all of the time, or used to before I got banned from Reddit, of all places, people in r/learnjavascript asking stuff like, what else should I learn before moving on to React?
Well, I ask, have they mastered resizable ArrayBuffer
, TypedArray
, DataView
, bitwise operators?
The only thing React can do is wrap code around what is shipped in the given browser - an abstraction.
My observation is that, generally, the base library, engine, runtime, whatever, contains the capabilities to achieve most any programming goal, without any libraries or dependencies.
This is what I had to do by hand to refactor code written exclusively for Node.js, the 2d time - after the maintainers updated to Integrity Block Sign Version 2. Now, if they had written the code in a runtime agnostic manner, without the idea that any external dependencies were necessary, or the code would only be run by Node.js, I wouldn't have had to write that code and debug line by line by hand. I'm alright with that though. I kind of understand where to go to adjust the code by hand the next time the maintainers make a breaking change.
In the process I decided to write a WebSocket and HTTP server from scratch - borrowing from somebody elses code who also originally wrote the code only for Node.js Build/rebuild wbn-bundle.js
from webbundle-plugins/packages/rollup-plugin-webbundle/src/index.ts
with bun
git clone https://github.com/GoogleChromeLabs/webbundle-plugins
cd webbundle-plugins/packages/rollup-plugin-webbundle
bun install -p
- In
src/index.ts
comment line 18, : EnforcedPlugin
, line 32 const opts = await getValidatedOptionsWithDefaults(rawOpts);
and lines 65-121, because I will not be using Rollup
- Bundle with Bun
bun build --target=node --format=esm --sourcemap=none --outfile=webpackage-bundle.js ./webbundle-plugins/packages/rollup-plugin-webbundle/src/index.ts
- Create reference to Web Cryptography API that will be used in the code in the bundled script instead of
node:crypto
directly import { webcrypto } from "node:crypto";
- In
/node_modules/wbn-sign/lib/utils/utils.js
use switch (key.algorithm.name) {
getRawPublicKey
becomes an async
function for substituting const exportedKey = await webcrypto.subtle.exportKey("spki", publicKey);
for publicKey.export({ type: "spki", format: "der" });
- In
/node_modules/wbn-sign/lib/signers/integrity-block-signer.js
use const publicKey = await signingStrategy.getPublicKey();
and [getPublicKeyAttributeName(publicKey)]: await getRawPublicKey(publicKey)
; verifySignature()
also becomes an async
function where const algorithm = { name: "Ed25519" }; const isVerified = await webcrypto.subtle.verify(algorithm, publicKey, signature, data);
is substituted for const isVerified = crypto2.verify(undefined, data, publicKey, signature);
- In
/node_modules/wbn-sign/lib/web-bundle-id.js
serialize()
function becomes async
for return base32Encode(new Uint8Array([...await getRawPublicKey(this.key), ...this.typeSuffix]), "RFC4648", { padding: false }).toLowerCase();
; and serializeWithIsolatedWebAppOrigin()
becomes an async
function for return ${this.scheme}${await this.serialize()}/;
; toString()
becomes an async
function for return Web Bundle ID: ${await this.serialize()} Isolated Web App Origin: ${await this.serializeWithIsolatedWebAppOrigin()};
- In
src/index.ts
export {WebBundleId, bundleIsolatedWebApp};
- In
index.js
, the entry point for how I am creating the SWBN and IWA I get the public and private keys created with Web Cryptography API, and use Web Cryptography API to sign and verify
Now, I'm banned from WICG as a whole, too, for questioning Web Speech API specification, years ago. They still link to the above repository because, I suppose, nobody else had yet dug in to create runtime agnostic code implementing a server in the browser that works. Wasn't a simple matter of throwing some line on a command line. I had to create other workarounds while the maintainers were trying, for whatever reasons they had, to stop me from exploiting the technology the way I wanted to, for my own purposes GitHub - guest271314/isolated-web-app-utilities: Isolated Web App Utilities.
So, I don't mind digging in to the minutae if necessary.
I'm highly skeptical of "best practices" and oceans of dependencies. Make it work with the base library itself, only if you can't depend on somebody elses code, that can change at the maintainers' whim.