From e7bb5ab42c9a9281ac050dd89532b91f81fcbfe9 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Thu, 4 Feb 2021 09:13:28 -0800 Subject: [PATCH] prefix with file:// --- src/node_api.cc | 7 ++++++- test/node-api/test_general/test.js | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/node_api.cc b/src/node_api.cc index 1f1a5b4f0831c1..8dbf48d466dfe1 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -577,7 +577,12 @@ void napi_module_register_by_symbol(v8::Local 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. diff --git a/test/node-api/test_general/test.js b/test/node-api/test_general/test.js index 90b89e7af6eddf..dd409f010a3ada 100644 --- a/test/node-api/test_general/test.js +++ b/test/node-api/test_general/test.js @@ -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],