Skip to content

Instantly share code, notes, and snippets.

View caridy's full-sized avatar

Caridy Patiño caridy

  • Salesforce, Inc.
  • Miami, FL.
  • X @caridy
View GitHub Profile

Modules Harmony Simplification Effort

Disclaimer: This text is exclusively focused on the existing capabilities of the language, and does not weight into additional capabilities like wasm, or virtual modules, or compartments. Those can be discussed later on.

MVP to create a module graph

The bare minimum mechanism to create a module graph that matches ESM requires few main pieces:

  1. A portable (serializable) structure that represents the source text of the module. ModuleSource must be portable across processes and across realms.
  2. A realm based Module that closes over a ModuleSource.
@caridy
caridy / about.md
Last active April 7, 2022 19:07 — forked from rauschma/about.md
Transferring objects between a ShadowRealm and an incubator realm

Transferring objects between a ShadowRealm and an incubator realm

Material:

@caridy
caridy / evaluator.ts
Last active February 12, 2020 07:02
evaluator api proposal
interface EvaluatorInit {
importHook(name, referrer): Promise<ParsedModule>;
isDirectEvalHook(evalFunctionRef: any): boolean;
randomHook(): number; // Use for Math.random()
nowHook(): number; // Use for both Date.now() and new Date(),
localeHook(): string; // e.g.: 'fr-FR' - Affects appropriate ECMA-402 APIs within Realm
LocalTZAHook(): string; // This is important to be able to override for deterministic testing and such
canCompileStringsHook(source: String): boolean; // mimic CSP including nounces
thisValue?: object;
}
@caridy
caridy / a.js
Last active February 3, 2017 23:28 — forked from dherman/a.js
a tiny userland registry, using a "parse" and "link" primitive
import {b} from "./b.js";
import $ from "jquery";
export function a() {
// ...
}

Updated (Aug 2nd, 2016)

API Refinements:

  • The default global scope when creating a new realm has no extra capabilities, it is confusing, we can remove it.
  • The realm object is the real power object, and users can decide to share it or not via endowments.
  • In a realm, you can create as many global scopes as you want via realmObj.createNewGlobalScope().
  • No more proxy-like API at the realm level, if you want to proxy a global, that should be used when creating a new global scope.

The API proposal:

@caridy
caridy / export-syntax.js
Last active January 15, 2022 14:22
ES6 Module Syntax Table
// default exports
export default 42;
export default {};
export default [];
export default foo;
export default function () {}
export default class {}
export default function foo () {}
export default class foo {}
/* global HackToInferCallerFilename */
'use strict';
var REGEX_CALLER_FILENAME = /\(([^:]+)\:\d+\:\d+\)/g;
module.exports = function () {
var filename;
try {
HackToInferCallerFilename;

Proposal for Extending Express Apps

Creating npm packages which extend the functionality of Express apps has become a major thing we've been doing. There are several approaches we can take, from messing with the Express object prototypes, to creating a function in which an express app is passed in. After trying the former, I'm now a fan of the latter.

The Issues with Extending Express

Extending the Express object prototypes has issues. The running Node.js process may have multiple versions of express, and in order to extend the prototypes you need to require('express'). This means that you might get a different express module instance than the one the main app is created from.

Both approaches suffer from extending something more than once. Similar to how there may be multiple version of express in the running Node.js process, there can also be multiple copies of the extension modules. If the app developer needs to rely on a different version of an Express ext

@caridy
caridy / README.md
Last active December 20, 2015 23:39
requiring optional client side dependencies on common dependencies

What is this?

This is a gist to showcase how to have client affinity modules that are required by common affinity modules without breaking the app when trying to use the common affinity modules on the server side.

Instalation

npm install
node app.js
@caridy
caridy / README.md
Last active December 20, 2015 18:59
how to deal with vendor scripts when using `express-yui`

What is this?

This is a gist to showcase how to deal with vendor scripts when using express-yui, in this particular case, loading jquery as a yui module.

Instalation

npm install
node app.js