Monkey patch 🐒, Conditional exports 🚱, blocking EL đ–Šč, import specifiers đŸ“„, NodeNext 🟱

By Prajwal Haniya

Techletter #78 | June 22, 2024

What is monkey patching in JS?

Monkey patch is a technique that involves dynamically modifying or adding functionality to an existing object or function at runtime, without changing the source code.

Some of the use cases of monkey patching:

Example of monkey patch

const log = console.log;
console.log = function() {
   log.apply(console, [(new Date()).toString()].concat(arguments));
};

console.log("test");

// output
Fri Jun 21 2024 16:26:36 GMT+0000 (Coordinated Universal Time) [Arguments] { '0': 'test' }


What do you mean by conditional exports in js?

Conditional exports in the package.json file allows you to specify different module entry points depending on the environment or module system used. So, basically with conditional exports you specify entry points if you are using ES Modules, or entry point if you using commonJS.

{
  "name": "my-package",
  "version": "1.0.0",
  "exports": {
    "import": "./main.mjs",
    "require": "./main.cjs"
  }
}

What events can block the event loop?


What are the different kinds of import specifiers?

The below excerpt is from the nodejs documentaion

There are three types of specifiers:


What does moduleResolution: NodeNext in tsconfig.json?


What are triple-slash directives?

Triple-slash directives are special comments in TypeScript that provide instructions to the compiler about how to process a file. These directives begin with three consecutive slashes (///) and are typically placed at the top of a TypeScript file. They have no effect on the runtime behavior of the code but influence how the compiler handles the file during compilation.