Skip to content

Commit

Permalink
prefix with file://
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed Feb 7, 2021
1 parent 96caf11 commit 8860718
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/node_api.cc
Expand Up @@ -577,7 +577,12 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
modobj->Get(context, node_env->filename_string()).ToLocal(&filename_js) &&
filename_js->IsString()) {
node::Utf8Value filename(node_env->isolate(), filename_js); // Cast
module_filename = *filename;

// Turn the absolute path into a URL. Currently the absolute path is always
// a file system path.
// TODO(gabrielschulhof): Pass the `filename` through unchanged if/when we
// receive it as a URL already.
module_filename = std::string("file://") + (*filename);
}

// Create a new napi_env for this specific module.
Expand Down
4 changes: 3 additions & 1 deletion test/node-api/test_general/test.js
Expand Up @@ -5,7 +5,9 @@ const filename = require.resolve(`./build/${common.buildType}/test_general`);
const test_general = require(filename);
const assert = require('assert');

assert.strictEqual(test_general.filename, filename);
// TODO(gabrielschulhof): This test may need updating if/when the filename
// becomes a full-fledged URL.
assert.strictEqual(test_general.filename, `file://${filename}`);

const [ major, minor, patch, release ] = test_general.testGetNodeVersion();
assert.strictEqual(process.version.split('-')[0],
Expand Down
4 changes: 2 additions & 2 deletions test/node-api/test_general/test_general.c
Expand Up @@ -25,8 +25,8 @@ static napi_value GetFilename(napi_env env, napi_callback_info info) {
const char* filename;
napi_value result;

NAPI_CALL(env, node_api_get_module_file_name(env, &filename));
NAPI_CALL(env,
NODE_API_CALL(env, node_api_get_module_file_name(env, &filename));
NODE_API_CALL(env,
napi_create_string_utf8(env, filename, NAPI_AUTO_LENGTH, &result));

return result;
Expand Down

0 comments on commit 8860718

Please sign in to comment.