From e6224746c68ef43a62c92d8164883e66f2d71344 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Tue, 26 Nov 2019 22:30:11 +1100 Subject: [PATCH 1/5] doc: clarify required flag for extensionless esm Fixes: https://github.com/nodejs/node/issues/30655 --- doc/api/esm.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/api/esm.md b/doc/api/esm.md index caaecaa0b41498..44cdb3e1c0ef00 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -92,6 +92,9 @@ if the nearest parent `package.json` contains `"type": "module"`. ```js // my-app.js, part of the same example as above import './startup.js'; // Loaded as ES module because of package.json + +// Extensionless. Requires 'node --es-module-specifier-resolution=node' +import './startup'; // Loaded as ES module because of package.json ``` Package authors should include the `"type"` field, even in packages where all From 26b4cb9a05ca05c9569b6abcfc764d23f1a6985d Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Tue, 3 Dec 2019 22:41:43 +1100 Subject: [PATCH 2/5] doc: clarify extensionless file imports --- doc/api/esm.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 44cdb3e1c0ef00..8337e3d7e8493d 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -84,7 +84,8 @@ If the nearest parent `package.json` lacks a `"type"` field, or contains `"type": "commonjs"`, extensionless and `.js` files are treated as CommonJS. If the volume root is reached and no `package.json` is found, Node.js defers to the default, a `package.json` with no `"type"` -field. +field. Note that "extensionless" refers to file names which do not contain +an extension. It does not refer to the import specifier. `import` statements of `.js` and extensionless files are treated as ES modules if the nearest parent `package.json` contains `"type": "module"`. @@ -92,9 +93,6 @@ if the nearest parent `package.json` contains `"type": "module"`. ```js // my-app.js, part of the same example as above import './startup.js'; // Loaded as ES module because of package.json - -// Extensionless. Requires 'node --es-module-specifier-resolution=node' -import './startup'; // Loaded as ES module because of package.json ``` Package authors should include the `"type"` field, even in packages where all From bb49307ee92992f54dbc6b28cb34cfbadc806d25 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Thu, 5 Dec 2019 18:03:37 +1100 Subject: [PATCH 3/5] doc: reword extensionless definition Co-Authored-By: Myles Borins --- 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 8337e3d7e8493d..57ab303c1b0386 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -84,7 +84,7 @@ If the nearest parent `package.json` lacks a `"type"` field, or contains `"type": "commonjs"`, extensionless and `.js` files are treated as CommonJS. If the volume root is reached and no `package.json` is found, Node.js defers to the default, a `package.json` with no `"type"` -field. Note that "extensionless" refers to file names which do not contain +field. Note that "extensionless" refers to file paths which do not contain an extension. It does not refer to the import specifier. `import` statements of `.js` and extensionless files are treated as ES modules From e05c65142cb61c72a3ef6421d97b1562fb722133 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Sat, 7 Dec 2019 12:43:10 +1100 Subject: [PATCH 4/5] doc: reword clarification Co-Authored-By: Myles Borins --- 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 57ab303c1b0386..831b6d6fb3a74e 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -85,7 +85,7 @@ If the nearest parent `package.json` lacks a `"type"` field, or contains If the volume root is reached and no `package.json` is found, Node.js defers to the default, a `package.json` with no `"type"` field. Note that "extensionless" refers to file paths which do not contain -an extension. It does not refer to the import specifier. +an extension as opposed to optionally dropping a file extension in a specifier. `import` statements of `.js` and extensionless files are treated as ES modules if the nearest parent `package.json` contains `"type": "module"`. From ff75ccb6e8ef07239fcb6d68e126966e7eb1242c Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Tue, 17 Dec 2019 10:03:41 +1100 Subject: [PATCH 5/5] doc: remove "note that" Co-Authored-By: Myles Borins --- 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 831b6d6fb3a74e..a0b99736129171 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -84,7 +84,7 @@ If the nearest parent `package.json` lacks a `"type"` field, or contains `"type": "commonjs"`, extensionless and `.js` files are treated as CommonJS. If the volume root is reached and no `package.json` is found, Node.js defers to the default, a `package.json` with no `"type"` -field. Note that "extensionless" refers to file paths which do not contain +field. "Extensionless" refers to file paths which do not contain an extension as opposed to optionally dropping a file extension in a specifier. `import` statements of `.js` and extensionless files are treated as ES modules