Skip to content

Commit 6b4b308

Browse files
committed
node-api: preserve URL filenames without conversion
1 parent 641653b commit 6b4b308

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/node_api.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,13 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
722722
filename_js->IsString()) {
723723
node::Utf8Value filename(node_env->isolate(), filename_js);
724724

725-
// Turn the absolute path into a URL. Currently the absolute path is always
726-
// a file system path.
727-
// TODO(gabrielschulhof): Pass the `filename` through unchanged if/when we
728-
// receive it as a URL already.
729-
module_filename = node::url::FromFilePath(filename.ToStringView());
725+
std::string_view filename_str(filename.out(), filename.length());
726+
if (filename_str.find("://") != std::string_view::npos) {
727+
// Already a URL, use it directly
728+
module_filename = filename_str;
729+
} else {
730+
module_filename = node::url::FromFilePath(filename.ToStringView());
731+
}
730732
}
731733

732734
// Create a new napi_env for this specific module.

0 commit comments

Comments
 (0)