Created
December 13, 2024 16:36
-
-
Save gabrielschulhof/ea87a65fdc0dab22385415e03060a88c to your computer and use it in GitHub Desktop.
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
const Module = require('node:module') | |
const path = require('node:path') | |
const load = Module._load | |
const aliases = [['myawesomemodule', path.dirname(require.resolve('./myawesomemodule/'))]] | |
Module._load = function (request, parent) { | |
const alias = aliases.find(([module]) => request.startsWith(module)) | |
return alias | |
? require(request.replace(new RegExp(`^${alias[0]}`), alias[1])) | |
: load.apply(this, arguments) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment