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 e2a7626 commit ecddc20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 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

0 comments on commit ecddc20

Please sign in to comment.