mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
[bun.js] Implement import.meta.require
This allows synchronous dynamic loading of `.node`, `.json`, and `.toml` files. It is not a CommonJS require, but it can be used that way so long as the content is not JavaScript.
This commit is contained in:
@@ -1173,7 +1173,7 @@ JSC::JSObject* GlobalObject::moduleLoaderCreateImportMetaProperties(JSGlobalObje
|
||||
auto index = view.reverseFind('/', view.length());
|
||||
if (index != WTF::notFound) {
|
||||
metaProperties->putDirect(vm, clientData->builtinNames().dirPublicName(),
|
||||
JSC::jsSubstring(globalObject, keyString, 0, index));
|
||||
JSC::jsSubstring(globalObject, keyString, 0, index + 1));
|
||||
metaProperties->putDirect(
|
||||
vm, clientData->builtinNames().filePublicName(),
|
||||
JSC::jsSubstring(globalObject, keyString, index + 1, keyString->length() - index - 1));
|
||||
@@ -1191,6 +1191,9 @@ JSC::JSObject* GlobalObject::moduleLoaderCreateImportMetaProperties(JSGlobalObje
|
||||
WTF::String("resolveSync"_s), functionImportMeta__resolveSync),
|
||||
JSC::PropertyAttribute::Function | 0);
|
||||
|
||||
metaProperties->putDirectBuiltinFunction(vm, globalObject, clientData->builtinNames().requirePublicName(),
|
||||
jsZigGlobalObjectRequireCodeGenerator(vm),
|
||||
JSC::PropertyAttribute::Builtin | 0);
|
||||
}
|
||||
|
||||
metaProperties->putDirect(vm, clientData->builtinNames().pathPublicName(), key);
|
||||
|
||||
Reference in New Issue
Block a user