Created
January 13, 2026 19:28
-
-
Save examosa/aaa2d94a19441527b9afccd596497610 to your computer and use it in GitHub Desktop.
Node.js HTTPS ESM Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Adds support for importing ES modules from the web. | |
| */ | |
| export function load(url, _context, nextLoad) { | |
| if (!url.startsWith("https://")) { | |
| return nextLoad(url); | |
| } | |
| return fetch(url) | |
| .then((res) => res.text()) | |
| .then((source) => ({ format: "module", shortCircuit: true, source })); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| mapfile -t register <<JS | |
| import { register } from "node:module"; | |
| import { pathToFileURL } from "node:url"; | |
| register("$XDG_DATA_HOME/node/https-loader.mjs", pathToFileURL(".")); | |
| JS | |
| exec node --import "data:text/javascript,${register[*]}" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment