Mango Juicy
Explore posts from serversTTCTheo's Typesafe Cult
•Created by Mango Juicy on 10/29/2024 in #questions
Recommended abstract syntax tree for JavaScript/TypeScript
For context, I'm trying to create a Eslint plugin to detect JavaScript runtime compatibility issues.
So I need to keep track of variable types - a bit like how TypeScript keeps track of types.
I find the way Eslint exposes the AST to be quite limiting.
4 replies
Cloudflare worker presigned url S3, R2
How do you generate presigned urls or S3 or R2... from cloudflare workers?
Solution:
Use
aws4fetch
package which is designed to work on cloudflare workers:
https://developers.cloudflare.com/r2/examples/aws/aws4fetch/
Do not use @aws-sdk/s3-request-presigner
as this depends on a @smithy
package that requires node:fs
, which is unsupported on Cloudflare. Calling a node:fs
will result in a is not a function
error
PS: I've already found a solution. Though I'd put this here for anybody facing the same issue.1 replies
Client side singleton for heavy resource allocation
Is there a way to create a global singleton for client side without initialising again on page loads?
In my case, I'm preloading a synthesizer on the web, which takes time to load.
Disabling SSR and using only client side routing for subroutes could work.
But how would you do that?
2 replies
Precache service worker
Is there any way to implement service worker for content precaching?
For context I'm creating a website with a midi player. It would be great to precache large (1 to 21 MB ish) SoundFont files.
I've tried using VitePWA plugin in Vinxi. It doesn't appear to register any service workers though.
app.config.ts:
19 replies
createAsync different values on client and server SSR issue
I'm trying to conditionally render components based on auth - think paywalled content.
I have a server function that detects if user has logged in:
However, createAsync returns undefined leading nothing to be rendered on the server:
Server:
Client returns the expected value:
16 replies
TTCTheo's Typesafe Cult
•Created by Mango Juicy on 7/12/2024 in #questions
NPM library best practices?
I was creating my own NPM library, @menglinmaker/soundfont3 but there are so many technical decisions:
- So many bundlers to choose from: esbuild, webpack, rollup, snowpack, tsup...
- Do I bundle to 1 file? Tree-shake?
- So many testing frameworks too: jest, vitest...
- So many eslint plugins.
- How do I even test if ESM and CJS imported correctly?
Attempt:
I decided to take inspiration from a few GitHub repos like vuejs/core, solidjs/solid, mrdoob/three.js.
This is what I pickup up on:
- Use script "preinstall" to force the use of "pnpm" for development. Very opinionated decision, but improves consistency with setup and CI.
- Use script "postinstall" to ensure git hooks are installed.
- Lint and format at least every pre-commit.
- Use "eslint-plugin-compat" to detect browser compatibility issues for web apis.
Areas for improvement in JS ecosystem:
- Lack of runtime compatibility linting - does api exist on Node, Deno, Bun, Cloudflare worker...?
TLDR:
Mostly unsure what bundler + config and testing library to use.
Eg: Apparently it's possible to unit test on a browser?
Boilerplate repo:
https://github.com/MengLinMaker/npm-library-boilerplate
11 replies