From a546cdd79091bf01a70ebf0946921529bb55ac1f Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 18 Sep 2023 11:57:11 +0200 Subject: [PATCH 1/2] esm: fix return type of `import.meta.resolve` --- lib/internal/modules/esm/initialize_import_meta.js | 2 +- test/es-module/test-esm-import-meta-resolve.mjs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/internal/modules/esm/initialize_import_meta.js b/lib/internal/modules/esm/initialize_import_meta.js index f55f60a5b7647a..d2beeac326b662 100644 --- a/lib/internal/modules/esm/initialize_import_meta.js +++ b/lib/internal/modules/esm/initialize_import_meta.js @@ -32,7 +32,7 @@ function createImportMetaResolve(defaultParentURL, loader, allowParentURL) { case 'ERR_MODULE_NOT_FOUND': ({ url } = error); if (url) { - return url; + return `${url}`; } } throw error; diff --git a/test/es-module/test-esm-import-meta-resolve.mjs b/test/es-module/test-esm-import-meta-resolve.mjs index 8495c161312822..a6435655750c88 100644 --- a/test/es-module/test-esm-import-meta-resolve.mjs +++ b/test/es-module/test-esm-import-meta-resolve.mjs @@ -9,10 +9,8 @@ const fixtures = dirname.slice(0, dirname.lastIndexOf('/', dirname.length - 2) + assert.strictEqual(import.meta.resolve('./test-esm-import-meta.mjs'), dirname + 'test-esm-import-meta.mjs'); -const notFound = import.meta.resolve('./notfound.mjs'); -assert.strictEqual(new URL(notFound).href, new URL('./notfound.mjs', import.meta.url).href); -const noExtension = import.meta.resolve('./asset'); -assert.strictEqual(new URL(noExtension).href, new URL('./asset', import.meta.url).href); +assert.strictEqual(import.meta.resolve('./notfound.mjs'), new URL('./notfound.mjs', import.meta.url).href); +assert.strictEqual(import.meta.resolve('./asset'), new URL('./asset', import.meta.url).href); try { import.meta.resolve('does-not-exist'); assert.fail(); From 177ba36ec1de3791a592990b23f6ee282e9b8ca8 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 19 Sep 2023 00:38:26 +0200 Subject: [PATCH 2/2] update error.input type --- lib/internal/errors.js | 2 +- lib/internal/modules/esm/initialize_import_meta.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index e84b9f6c851205..a8c2a9ea15db04 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -1450,7 +1450,7 @@ E('ERR_MISSING_ARGS', E('ERR_MISSING_OPTION', '%s is required', TypeError); E('ERR_MODULE_NOT_FOUND', function(path, base, exactUrl) { if (exactUrl) { - lazyInternalUtil().setOwnProperty(this, 'url', exactUrl); + lazyInternalUtil().setOwnProperty(this, 'url', `${exactUrl}`); } return `Cannot find ${ exactUrl ? 'module' : 'package'} '${path}' imported from ${base}`; diff --git a/lib/internal/modules/esm/initialize_import_meta.js b/lib/internal/modules/esm/initialize_import_meta.js index d2beeac326b662..f55f60a5b7647a 100644 --- a/lib/internal/modules/esm/initialize_import_meta.js +++ b/lib/internal/modules/esm/initialize_import_meta.js @@ -32,7 +32,7 @@ function createImportMetaResolve(defaultParentURL, loader, allowParentURL) { case 'ERR_MODULE_NOT_FOUND': ({ url } = error); if (url) { - return `${url}`; + return url; } } throw error;