diff options
author | 2023-10-02 15:24:38 -0700 | |
---|---|---|
committer | 2023-10-02 15:24:38 -0700 | |
commit | 0160772d25105f302f84013e892fe07f9eeb6f91 (patch) | |
tree | ae69b9edf6bdbfeab84055e5fd4f93be5b46dbbd /src/js/builtins/Module.ts | |
parent | abbe3916ed5d7b6adb5a4b376e5c563d36e07d31 (diff) | |
download | bun-0160772d25105f302f84013e892fe07f9eeb6f91.tar.gz bun-0160772d25105f302f84013e892fe07f9eeb6f91.tar.zst bun-0160772d25105f302f84013e892fe07f9eeb6f91.zip |
Diffstat (limited to 'src/js/builtins/Module.ts')
-rw-r--r-- | src/js/builtins/Module.ts | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/js/builtins/Module.ts b/src/js/builtins/Module.ts index b074d3488..3c9c2f1a0 100644 --- a/src/js/builtins/Module.ts +++ b/src/js/builtins/Module.ts @@ -9,7 +9,7 @@ export function require(this: CommonJSModuleRecord, id: string) { // overridableRequire can be overridden by setting `Module.prototype.require` export function overridableRequire(this: CommonJSModuleRecord, id: string) { - const existing = $requireMap.$get(id) || $requireMap.$get((id = $resolveSync(id, this.path, false))); + const existing = $requireMap.$get(id) || $requireMap.$get((id = $resolveSync(id, this?.path ?? ".", false))); if (existing) { // Scenario where this is necessary: // @@ -46,8 +46,7 @@ export function overridableRequire(this: CommonJSModuleRecord, id: string) { // // Note: we do not need to wrap this in a try/catch, if it throws the C++ code will // clear the module from the map. - // - var out = this.$require(id, mod); + var out = mod.$require(id, this?.id); // -1 means we need to lookup the module from the ESM registry. if (out === -1) { @@ -86,3 +85,13 @@ export function requireNativeModule(id: string) { } return $requireESM(id).default; } + +/** require('node:module')._load */ +export function moduleLoad(request: string, parentPath: CommonJSModuleRecord, isMain: string) { + // TODO: `isMain` does four things in node + // - sets `process.mainModule` + // - sets `module.require.main` + // - sets `module.id` to "." + // - would pass true to the third argument of _resolveFilename if overridden + return $overridableRequire.$call(parentPath, request); +} |