From 44652ff16bd82b84fbb7597d7f0f4f30b3d35756 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Tue, 5 Nov 2024 16:19:40 +0000 Subject: [PATCH] esm: add `import.meta.require` --- doc/api/esm.md | 14 ++++++++ .../modules/esm/initialize_import_meta.js | 16 +++++++++ test/es-module/test-esm-import-meta.mjs | 12 ++++++- test/es-module/test-import-meta-require.mjs | 34 +++++++++++++++++++ .../fixtures/es-modules/cjs-module-exports.js | 4 +++ test/fixtures/es-modules/foobar.json | 4 +++ 6 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 test/es-module/test-import-meta-require.mjs create mode 100644 test/fixtures/es-modules/cjs-module-exports.js create mode 100644 test/fixtures/es-modules/foobar.json diff --git a/doc/api/esm.md b/doc/api/esm.md index 4d257c37bf01ff..e8622ada5adc12 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -384,6 +384,19 @@ import { readFileSync } from 'node:fs'; const buffer = readFileSync(new URL('./data.proto', import.meta.url)); ``` +### `import.meta.require(id)` + + + +> Stability: 1.1 - Active development + +* `id` {string} The module name or path. +* Returns: {any} The module exports. + +Alias for [`module.createRequire(import.meta.url)(id)`][]. + ### `import.meta.resolve(specifier)`