Skip to content

Instantly share code, notes, and snippets.

View jkrems's full-sized avatar
Modules. Modules everywhere.

Jan Olaf Martin jkrems

Modules. Modules everywhere.
View GitHub Profile
> make -j4
/Applications/Xcode-beta.app/Contents/Developer/usr/bin/make -C out BUILDTYPE=Release V=0
LD_LIBRARY_PATH=/Users/jkrems/Projects/node/node/out/Release/lib.host:/Users/jkrems/Projects/node/node/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../.; mkdir -p /Users/jkrems/Projects/node/node/out/Release/obj/gen; python tools/js2c.py lib/internal/bootstrap/environment.js lib/internal/bootstrap/loaders.js lib/internal/bootstrap/node.js lib/internal/bootstrap/pre_execution.js lib/internal/per_context/primordials.js lib/internal/per_context/setup.js lib/internal/per_context/domexception.js lib/async_hooks.js lib/assert.js lib/buffer.js lib/child_process.js lib/console.js lib/constants.js lib/crypto.js lib/cluster.js lib/dgram.js lib/dns.js lib/domain.js lib/events.js lib/fs.js lib/http.js lib/http2.js lib/_http_agent.js lib/_http_client.js lib/_http_common.js lib/_http_incoming.js lib/_http_outgoing.js lib/_http_server.js lib/https.js lib/inspector.js lib/module.js lib/net.js lib/os.j
@jkrems
jkrems / index-original.js
Last active November 17, 2018 17:49
TypeScript as a Linter
'use strict';
function calculate(expression) {
// [...]
}
@jkrems
jkrems / pkg-import.md
Last active November 6, 2018 21:54
Module Resolution & Format Lookup

Module Resolution & Format Lookup

Motivating Examples

  • A package (react-dom) has a dedicated entrypoint `react-dom/server for code that isn't compatible with a browser environment.
  • A package (angular) exposes multiple independent APIs, modeled via import paths like angular/common/http.
  • A package (lodash) allows to import individual functions, e.g. lodash/map.
  • A package is exclusively exposing an ESM interface.
  • A package is exclusively exposing a CJS interface.
  • A package is exposing both an ESM and a CJS interface.
@jkrems
jkrems / async-to-async.md
Last active June 27, 2018 18:30
require('async') → async/await

Moving to async/await

waterfall

function before(cb) {
  waterfall(
    f1,
    f2,
 cb
@jkrems
jkrems / background-json-parse.js
Created March 6, 2018 16:59
JSON.parse w/o blocking main thread
'use strict';
const ivm = require('isolated-vm');
function handleParseJob(code) {
return new ivm.ExternalCopy(JSON.parse(code), { transferOut: true });
}
function transferInExternalCopy(copy) {
return copy.copy({ transferIn: true });
@jkrems
jkrems / es-module-history.md
Last active March 16, 2025 13:43
History of ES modules

Modules - History & Future

History

@jkrems
jkrems / .gitignore
Last active December 9, 2017 03:49
dynamic-import-require
node_modules
// V8 6.2 required
'use strict';
const fs = require('fs');
const { Session } = require('inspector');
const { promisify } = require('util');
const session = new Session();
if (session != null) {
session.connect();

Getting seconds or milliseconds since January 1, 1970, 00:00:00 GMT in various languages

Second-Native

C (1972)

// ms
struct timespec spec;
clock_gettime(CLOCK_REALTIME, &spec);
@jkrems
jkrems / local-react-native.md
Created May 11, 2016 20:47
Local react-native

Installing project specific tools like react-native globally is yucky. Even when it's just thin CLI wrappers. Unfortunately react-native actively breaks local npm binaries by forcing a broken bin stub into each project. So if you added ./node_modules/.bin to your $PATH, every attempt of running react-native inside of a project will fail with an annoying (and wrong) claim that you installed react-native globally.

The easiest solution I found so far:

  • npm install --save react-native-cli in your React Native project