module: implement the "module-sync" exports condition · nodejs/node@df8a045
@@ -665,6 +665,10 @@ specific to least specific as conditions should be defined:
665665 formats include CommonJS, JSON, native addons, and ES modules
666666 if `--experimental-require-module` is enabled. _Always mutually
667667 exclusive with `"import"`._
668+* `"module-sync"` - matches no matter the package is loaded via `import`,
669+`import()` or `require()`. The format is expected to be ES modules that does
670+ not contain top-level await in its module graph - if it does,
671+`ERR_REQUIRE_ASYNC_MODULE` will be thrown when the module is `require()`-ed.
668672* `"default"` - the generic fallback that always matches. Can be a CommonJS
669673 or ES module file. _This condition should always come last._
670674@@ -769,7 +773,7 @@ In node, conditions have very few restrictions, but specifically these include:
769773770774### Community Conditions Definitions
771775772-Condition strings other than the `"import"`, `"require"`, `"node"`,
776+Condition strings other than the `"import"`, `"require"`, `"node"`, `"module-sync"`,
773777`"node-addons"` and `"default"` conditions
774778[implemented in Node.js core](#conditional-exports) are ignored by default.
775779@@ -900,6 +904,17 @@ $ node other.js
900904901905## Dual CommonJS/ES module packages
902906907+<!-- This section should not be in the API documentation:
908+909+1. It teaches opinionated practices that some consider dangerous, see
910+ https://github.com/nodejs/node/issues/52174
911+2. It will soon be obsolete when we unflag --experimental-require-module.
912+3. It's difficult to understand a multi-file structure via long texts and snippets in
913+ a markdown document.
914+915+TODO(?): Move this section to its own repository with example folders.
916+-->
917+903918Prior to the introduction of support for ES modules in Node.js, it was a common
904919pattern for package authors to include both CommonJS and ES module JavaScript
905920sources in their package, with `package.json` [`"main"`][] specifying the
@@ -912,7 +927,7 @@ ignores) the top-level `"module"` field.
912927Node.js can now run ES module entry points, and a package can contain both
913928CommonJS and ES module entry points (either via separate specifiers such as
914929`'pkg'` and `'pkg/es-module'`, or both at the same specifier via [Conditional
915-exports][]). Unlike in the scenario where `"module"` is only used by bundlers,
930+exports][]). Unlike in the scenario where top-level `"module"` field is only used by bundlers,
916931or ES module files are transpiled into CommonJS on the fly before evaluation by
917932Node.js, the files referenced by the ES module entry point are evaluated as ES
918933modules.