From 71775aa6a46267277e08e32b7319fd61f324349a Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 27 Jan 2022 13:37:07 -0800 Subject: [PATCH 1/5] doc: clarify that import also uses main --- doc/api/packages.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/api/packages.md b/doc/api/packages.md index e75549256bf2fc..fb5389c2a8241a 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -1094,8 +1094,7 @@ added: v0.4.0 ``` The `"main"` field defines the script that is used when the [package directory -is loaded via `require()`](modules.md#folders-as-modules). Its value -is a path. +is loaded](modules.md#folders-as-modules). Its value is a path. ```cjs require('./path/to/directory'); // This resolves to ./path/to/directory/main.js. From c2d3f441c55cb7a57071cc4c6d866b26b2b55e44 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 27 Jan 2022 20:08:48 -0800 Subject: [PATCH 2/5] reword --- doc/api/packages.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/api/packages.md b/doc/api/packages.md index fb5389c2a8241a..edf495e975d04d 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -1093,8 +1093,11 @@ added: v0.4.0 } ``` -The `"main"` field defines the script that is used when the [package directory -is loaded](modules.md#folders-as-modules). Its value is a path. +The `"main"` field defines the CommonJS or ESM script that is used as the +package entry point. + +When the value is a directory, [it may only be loaded via +`require()`](modules.md#folders-as-modules). ```cjs require('./path/to/directory'); // This resolves to ./path/to/directory/main.js. From fd21495cadbe8ffd438a628711f6c91ee6d1e336 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 28 Jan 2022 08:27:59 -0800 Subject: [PATCH 3/5] Update doc/api/packages.md Co-authored-by: Antoine du Hamel --- doc/api/packages.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/api/packages.md b/doc/api/packages.md index edf495e975d04d..53612252f15768 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -1093,8 +1093,11 @@ added: v0.4.0 } ``` -The `"main"` field defines the CommonJS or ESM script that is used as the -package entry point. +The `"main"` field defines the entry point of a package when +imported by name via a `node_modules` lookup. Its value +is a path. +When a package has an [`"exports"`][] field, this will take precedence over the +`"main"` field when importing the package by name. When the value is a directory, [it may only be loaded via `require()`](modules.md#folders-as-modules). From 1f964a5c6c4c953ff665e3edcea0ca13b079e0ce Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 28 Jan 2022 08:28:26 -0800 Subject: [PATCH 4/5] Update doc/api/packages.md Co-authored-by: Antoine du Hamel --- doc/api/packages.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/packages.md b/doc/api/packages.md index 53612252f15768..0c551bee7f5619 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -1099,8 +1099,8 @@ is a path. When a package has an [`"exports"`][] field, this will take precedence over the `"main"` field when importing the package by name. -When the value is a directory, [it may only be loaded via -`require()`](modules.md#folders-as-modules). +It also defines the script that is used when the [package directory +is loaded via `require()`](modules.md#folders-as-modules). ```cjs require('./path/to/directory'); // This resolves to ./path/to/directory/main.js. From d4140a165024eae8485825915d4d4177795fbba5 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 28 Jan 2022 09:36:00 -0800 Subject: [PATCH 5/5] remove duplicate paragraph --- doc/api/packages.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/doc/api/packages.md b/doc/api/packages.md index 0c551bee7f5619..a6cfa4e6acd679 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -1093,22 +1093,19 @@ added: v0.4.0 } ``` -The `"main"` field defines the entry point of a package when -imported by name via a `node_modules` lookup. Its value -is a path. +The `"main"` field defines the entry point of a package when imported by name +via a `node_modules` lookup. Its value is a path. + When a package has an [`"exports"`][] field, this will take precedence over the `"main"` field when importing the package by name. -It also defines the script that is used when the [package directory -is loaded via `require()`](modules.md#folders-as-modules). +It also defines the script that is used when the [package directory is loaded +via `require()`](modules.md#folders-as-modules). ```cjs require('./path/to/directory'); // This resolves to ./path/to/directory/main.js. ``` -When a package has an [`"exports"`][] field, this will take precedence over the -`"main"` field when importing the package by name. - ### `"packageManager"`