From 19db749d70db91f0b7d11ba9847c8cda784c4242 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 10 Jul 2020 23:37:20 -0700 Subject: [PATCH 1/3] doc: clarify conditional exports guidance --- doc/api/esm.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index d705e2d8efdfda..d894258ede0e6f 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -456,7 +456,7 @@ Conditional exports can also be extended to exports subpaths, for example: "exports": { ".": "./main.js", "./feature": { - "browser": "./feature-browser.js", + "node": "./feature-node.js", "default": "./feature.js" } } @@ -464,8 +464,16 @@ Conditional exports can also be extended to exports subpaths, for example: ``` Defines a package where `require('pkg/feature')` and `import 'pkg/feature'` -could provide different implementations between the browser and Node.js, -given third-party tool support for a `"browser"` condition. +could provide different implementations between Node.js and other JS +environments. + +Whenever using environment branches, it is highly recommended to always include +a `"defaut"` condition where possible. Always providing a `"default"` condition +ensures that any unknown JS environments are able to use a universal +implementation where possible, which helps avoid JS environments from having to +pretend to be existing environments to support packages with conditional +exports. Where possible, `"node"` and `"default"` conditions can be preferable +to `"browser"` conditions. #### Nested conditions @@ -479,11 +487,11 @@ use in Node.js but not the browser: { "main": "./main.js", "exports": { - "browser": "./feature-browser.mjs", "node": { "import": "./feature-node.mjs", "require": "./feature-node.cjs" - } + }, + "default": "./feature.mjs", } } ``` From d0f8926282875666ec6496c343c1f6b73ac3ea02 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 10 Jul 2020 23:55:14 -0700 Subject: [PATCH 2/3] Update doc/api/esm.md Co-authored-by: Rich Trott --- doc/api/esm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index d894258ede0e6f..134d9224b93305 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -467,7 +467,7 @@ Defines a package where `require('pkg/feature')` and `import 'pkg/feature'` could provide different implementations between Node.js and other JS environments. -Whenever using environment branches, it is highly recommended to always include +When using environment branches, include a `"defaut"` condition where possible. Always providing a `"default"` condition ensures that any unknown JS environments are able to use a universal implementation where possible, which helps avoid JS environments from having to From d7f1f4ee79cd081d58a25339d067bb9d3a5fe1d9 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 13 Jul 2020 03:30:14 -0700 Subject: [PATCH 3/3] rewording --- doc/api/esm.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 134d9224b93305..c9bb7473a8e689 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -467,13 +467,13 @@ Defines a package where `require('pkg/feature')` and `import 'pkg/feature'` could provide different implementations between Node.js and other JS environments. -When using environment branches, include -a `"defaut"` condition where possible. Always providing a `"default"` condition -ensures that any unknown JS environments are able to use a universal -implementation where possible, which helps avoid JS environments from having to -pretend to be existing environments to support packages with conditional -exports. Where possible, `"node"` and `"default"` conditions can be preferable -to `"browser"` conditions. +When using environment branches, always include a `"default"` condition where +possible. Providing a `"default"` condition ensures that any unknown JS +environments are able to use this universal implementation, which helps avoid +these JS environments from having to pretend to be existing environments in +order to support packages with conditional exports. For this reason, using +`"node"` and `"default"` condition branches is usually preferable to using +`"node"` and `"browser"` condition branches. #### Nested conditions