From fde16f89fbd8776873828a5ac7e96a48b82b0446 Mon Sep 17 00:00:00 2001 From: Maksim Sinik Date: Thu, 20 Aug 2020 15:44:38 +0200 Subject: [PATCH 1/5] doc: fixes ESM/CJS wrapper example --- doc/api/esm.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 551eef604eac0e..ab9b0316478fcb 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -665,11 +665,10 @@ CommonJS entry point for `require`. ```js // ./node_modules/pkg/package.json { - "type": "module", - "main": "./index.cjs", + "main": "./index.js", "exports": { "import": "./wrapper.mjs", - "require": "./index.cjs" + "require": "./index.js" } } ``` @@ -727,10 +726,9 @@ stateless): ```js // ./node_modules/pkg/package.json { - "type": "module", - "main": "./index.cjs", + "main": "./index.js", "exports": { - ".": "./index.cjs", + ".": "./index.js", "./module": "./wrapper.mjs" } } From f38a85e089581be807a0c80a660c5f60381b8865 Mon Sep 17 00:00:00 2001 From: Maksim Sinik Date: Fri, 21 Aug 2020 09:46:12 +0200 Subject: [PATCH 2/5] Reverts wrapper snippet and adds a warning note --- doc/api/esm.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index ab9b0316478fcb..5a136267ef60b5 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -665,13 +665,15 @@ CommonJS entry point for `require`. ```js // ./node_modules/pkg/package.json { - "main": "./index.js", + "type": "module", + "main": "./index.cjs", "exports": { "import": "./wrapper.mjs", - "require": "./index.js" + "require": "./index.cjs" } } ``` +Note that the above example uses explicit extensions `.mjs` and `.cjs`. If your files use the `.js` extension, note that `"type": "module"` will cause such files to be treated as ES modules, just as `"type": "commonjs"` would cause them to be treated as CommonJS. See [Enabling](https://nodejs.org/api/esm.html#esm_enabling). ```js // ./node_modules/pkg/index.cjs @@ -726,9 +728,10 @@ stateless): ```js // ./node_modules/pkg/package.json { - "main": "./index.js", + "type": "module", + "main": "./index.cjs", "exports": { - ".": "./index.js", + ".": "./index.cjs", "./module": "./wrapper.mjs" } } From 1a2312a250f48ddaf6c1a3ebb3f9c5607d6b64a0 Mon Sep 17 00:00:00 2001 From: Maksim Sinik Date: Fri, 21 Aug 2020 09:54:06 +0200 Subject: [PATCH 3/5] Fixes md lint issues --- doc/api/esm.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 5a136267ef60b5..c94065f712404f 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -673,7 +673,11 @@ CommonJS entry point for `require`. } } ``` -Note that the above example uses explicit extensions `.mjs` and `.cjs`. If your files use the `.js` extension, note that `"type": "module"` will cause such files to be treated as ES modules, just as `"type": "commonjs"` would cause them to be treated as CommonJS. See [Enabling](https://nodejs.org/api/esm.html#esm_enabling). +The above example uses explicit extensions `.mjs` and `.cjs`. +If your files use the `.js` extension, `"type": "module"` will cause such files +to be treated as ES modules, just as `"type": "commonjs"` would cause them +to be treated as CommonJS. +See [Enabling](https://nodejs.org/api/esm.html#esm_enabling). ```js // ./node_modules/pkg/index.cjs From 06e581fc5d30a58206b14f067c00f9c3fae1f42e Mon Sep 17 00:00:00 2001 From: Maksim Sinik Date: Fri, 21 Aug 2020 10:00:31 +0200 Subject: [PATCH 4/5] Removes trailing space --- 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 c94065f712404f..d677ab0120dbfc 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -673,7 +673,7 @@ CommonJS entry point for `require`. } } ``` -The above example uses explicit extensions `.mjs` and `.cjs`. +The above example uses explicit extensions `.mjs` and `.cjs`. If your files use the `.js` extension, `"type": "module"` will cause such files to be treated as ES modules, just as `"type": "commonjs"` would cause them to be treated as CommonJS. From d16973d3231f0653290249b51a6ccee8377b94d4 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 22 Aug 2020 09:14:05 -0700 Subject: [PATCH 5/5] fixup! Removes trailing space --- doc/api/esm.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index d677ab0120dbfc..357226d7a690e4 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -673,11 +673,12 @@ CommonJS entry point for `require`. } } ``` + The above example uses explicit extensions `.mjs` and `.cjs`. If your files use the `.js` extension, `"type": "module"` will cause such files to be treated as ES modules, just as `"type": "commonjs"` would cause them to be treated as CommonJS. -See [Enabling](https://nodejs.org/api/esm.html#esm_enabling). +See [Enabling](#esm_enabling). ```js // ./node_modules/pkg/index.cjs