From 71bcd05232b4fc21db20e5acf019f97780050568 Mon Sep 17 00:00:00 2001 From: Jan Krems Date: Mon, 19 Aug 2019 20:59:25 -0700 Subject: module: resolve self-references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the ability to `import` or `require` a package from within its own source code. This allows tests and examples to be written using the package name, making them easier to reuse by consumers of the package. Assuming the `name` field in `package.json` is set to `my-pkg`, its test could use `require('my-pkg')` or `import 'my-pkg'` even if there's no `node_modules/my-pkg` while testing the package itself. An important difference between this and relative specifiers like `require('../')` is that self-references use the public interface of the package as defined in the `exports` field while relative specifiers don't. This behavior is guarded by a new experimental flag (`--experimental-resolve-self`). PR-URL: https://github.com/nodejs/node/pull/29327 Reviewed-By: Guy Bedford Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso --- src/node_options.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/node_options.cc') diff --git a/src/node_options.cc b/src/node_options.cc index c9fade140d..ac44a758dc 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -331,6 +331,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "experimental ES Module support and caching modules", &EnvironmentOptions::experimental_modules, kAllowedInEnvironment); + AddOption("--experimental-resolve-self", + "experimental support for require/import of the current package", + &EnvironmentOptions::experimental_resolve_self, + kAllowedInEnvironment); AddOption("--experimental-wasm-modules", "experimental ES Module support for webassembly modules", &EnvironmentOptions::experimental_wasm_modules, -- cgit v1.2.3