

// Open a supplied HTML file and record whatever's going on to an MP4. | |
// | |
// Usage: node recorder.cjs <path_to_html_file> | |
// Dependencies: npm install puppeteer fluent-ffmpeg | |
// (and yes, you need ffmpeg installed) | |
// | |
// It expects a <canvas> element to be on the page as it waits for | |
// that to load in first, but you can edit the code below if you | |
// don't want that. | |
// |
[EDIT: I've added a part 2 to this blog post, to address some of the feedback that has come up: https://gist.github.com/getify/706e5e10822a298375da40f9cc1fa295]
Recently, this article on "The JavaScript Block Statement" came out, and it received some good discussion in a reddit thread. But the general reaction seems to be against this approach. That saddens me.
Fwiw, the past couple of weeks I've been working on supporting import assertions and CSS/JSON modules in our app at work, I thought it might be worth to share the experience and also prompted by this, maybe its helpful to someone looking into doing the same.
We currently transform our app to Systemjs. My initial thought was to start using es-module-shims, for several reasons:
I initially thought that bundling from ESM to ESM would be at least somewhat noticeably faster than bundling from ESM to Systemjs, because of the code transform, but after running some benchmarks in our pipeline, it seemed to not make a significant difference.
// Sometimes you want to run parent effects before those of the children. E.g. when setting | |
// something up or binding document event listeners. By passing the effect to the first child it | |
// will run before any effects by later children. | |
export function Effect({ effect }) { | |
useEffect(() => effect?.(), [effect]); | |
return null; | |
} | |
// |
Years ago, some smart folks that worked on JS engines realized that not all JS that's loaded into a page/app initially is needed right away. They implemented JIT to optimize this situation.
JIT means Just-In-Time, which means essentially that the engine can defer processing (parsing, compiling) certain parts of a JS program until a later time, for example when the function in question is actually needed. This deferral means the engine is freer to spend the important cycles right now on the code that's going to run right now. This is a really good thing for JS performance.
Some time later, some JS engine devs realized that they needed to get some hints from the code as to which functions would run right away, and which ones wouldn't. In technical speak, these hints are called heuristics.
So they realized that one very common pattern for knowing that a function was going to run right away is if the first character before the function
keyword was a (
, because that usually m
Follow-up to Top-level await is a footgun – maybe read that first
Here are some things I believe to be true:
require(...)
or await import(...)
).await
is such a construct.This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:
(async main(){...}())
as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problemsI'll leave the rest of this document unedited, for archaeological
composable("composites.Range", function (require, global) { | |
"use strict"; | |
require("environment_extended_introspective_core"); |
My current editor of choice for all things related to Javascript and Node is VS Code, which I highly recommend. The other day I needed to hunt down a bug in one of my tests written in ES6, which at time of writing is not fully supported in Node. Shortly after, I found myself down the rabbit hole of debugging in VS Code and realized this isn't as straightforward as I thought initially. This short post summarizes the steps I took to make debugging ES6 in VS Code frictionless.
My first approach was a launch configuration in launch.json
mimicking tape -r babel-register ./path/to/testfile.js
with babel configured to create inline sourcemaps in my package.json
. The debugging started but breakpoints and stepping through the code in VS Code were a complete mess. Apparently, ad-hoc transpilation via babel-require-hook and inline sourcemaps do not work in VS Code. The same result for
attaching (instead of launch) to `babel-node