Skip to content

Instantly share code, notes, and snippets.

View bmeck's full-sized avatar

Bradley Farias bmeck

View GitHub Profile
console.log('hi');
module.exports = 123;
{
async resolve() {
const dep = vm.Module('export let a = 0; ({set a(v) {a = v;} get a() {return a;}})');
dep.onEvaluated((ns, reflect) => {
setInterval(() => reflect.a++, 1000);
});
return dep;
}
}
<!doctype html>
<html>
<style>
.screenreader-only {
position: absolute;
display: block;
left: -1px;
top: -1px;
width: 1px;
height: 1px;
@bmeck
bmeck / construction-private.md
Last active March 29, 2018 13:32
some simple examples of out of class private. It can be used only lexically and cannot be stored into a variable. EVERYTHING HERE IS BIKESHED
// allocate a private field key
private #constructedHere;

export let create = () => {
  return {
    // cannot be used in computed properties
    // #constructedHere is not a variable with a reified value
    #constructedHere: true
 };

ESM do not have a way to setup modules that are aliases of other modules

ESM in in browsers cannot reliably use export * from to act as an alias since it may alter the shape of the namespace they are importing, nor can they use HTTP redirects which are treated as new module records.

Adding default to the list of exports from export * from has been revisted and rejected. I have to take extra effort to use export * reliably as a means to create pass through modules. Typically involving resolving, fetching, and parsing the source text of a dependency outside of VM control. This can be seen in projects where I am invoking http/file access and parsing to AST to figure out if the module being delegated to has a default.

In addition using export * is also not suitable to be used

File API

** bikeshed **

fs.getFile(url) - https://developer.mozilla.org/en-US/docs/Web/API/File

Can be used by loaders/servers if they wish to request information about the file's MIME as file.type.

It will get the .type by checking the context for the current MIME DB, falling back to the globally MIME DB.

@bmeck
bmeck / a.mjs
Last active December 28, 2017 18:01
creates a cycle to intentionally ensure only `a` can run `b`
import {ran} from 'b';
let ready;
// this function can be saved to a variable, but blows up if `b` has not run yet
export function onlyAvailableIfBHasRun() {
ready;
ran;
// ...
};
@bmeck
bmeck / actors.js
Last active December 6, 2017 15:14
90% sure this is buggy somewhere, but its a PoC
class LockingActor {
constructor(buffer, offset, bytes) {
let needle = offset;
// if our lock isn't aligned
if (needle % 4 !== 0) {
// align
needle += 4 - (needle % 4);
}
this.state = new Transitions(buffer, needle);
needle += this.lock.byteLength;

Various command line applications use an Interpreter Directive to define how they should be run.

#! js -m foo
#! node foo
@bmeck
bmeck / proposal-no-path-searching.md
Last active February 6, 2018 17:20
Removal of path searching / defining a hook for migration.

Problem

There has been no progress in working towards a single cohesive story for path resolution between Servers and Web. Notable discussion points relevant to this are:

  1. Node has a path searching algorithm.
  2. Web has not been able to gather support for any of the following:
    1. Build tooling as part of UX expectations (lack of interest)
    2. Smarter static web servers (lack of interest). PoC example at https://github.com/bmeck/esm-http-server
  3. A resolve based hook. (interest shown with desire for ~6 months of userland experimentation)