From 45c502fb1c125759a27ba63d2660e6850b2aebb9 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Thu, 28 Apr 2016 21:11:23 -0700 Subject: [PATCH 1/2] 002 - explicit note about inner package behavior being preserved - thanks @ljharb for finding this, was not explicitly stated --- 002-es6-modules.md | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/002-es6-modules.md b/002-es6-modules.md index 6fbfdf8..bfce974 100644 --- a/002-es6-modules.md +++ b/002-es6-modules.md @@ -199,11 +199,16 @@ ES `import` statements will not perform non-exact searches on relative or absolute paths, unlike `require()`. This means that no file extensions, or index files will be searched for when using relative or absolute paths. -`node_modules` based paths will continue to use searching for both -compatibility and to not limit the ability to have `package.json` support both -ES and CJS entry points in a single codebase. `node_modules` based behavior -will continue to be unchanged and look to parent `node_modules` directories -recursively as well. +`node_modules` based paths (sometimes called "bare" paths) will continue to use +searching for both compatibility and to not limit the ability to have +`package.json` support both ES and CJS entry points in a single +codebase.`node_modules` based behavior will continue to be unchanged and look +to parent `node_modules` directories recursively as well. This searching +behavior explicitly includes inner package searching such ass `foo/bar`. + +Any entry into `node_modules` via paths not starting with "/", "./", or "../" +will be using the same mechanism of searching while resolving their **entry +point** as `require()`. In summary so far: @@ -213,6 +218,7 @@ In summary so far: // does not search: // ./foo.js // ./foo/index.js +// ./foo/index.mjs // ./foo/package.json // etc. import './foo'; @@ -224,6 +230,7 @@ import './foo'; // does not search: // /bar.js // /bar/index.js +// /bar/index.mjs // /bar/package.json // etc. import '/bar'; @@ -231,17 +238,38 @@ import '/bar'; ```javascript // continues to *search*: +// ./node_modules/baz.mjs // ./node_modules/baz.js // ./node_modules/baz/package.json +// ./node_modules/baz/index.mjs // ./node_modules/baz/index.js // and parent node_modules: +// ../node_modules/baz.mjs // ../node_modules/baz.js // ../node_modules/baz/package.json +// ../node_modules/baz/index.mjs // ../node_modules/baz/index.js // etc. import 'baz'; ``` +```javascript +// continues to *search*: +// ./node_modules/abc/123.mjs +// ./node_modules/abc/123.js +// ./node_modules/abc/123/package.json +// ./node_modules/abc/123/index.mjs +// ./node_modules/abc/123/index.js +// and parent node_modules: +// ../node_modules/abc/123.mjs +// ../node_modules/abc/123.js +// ../node_modules/abc/123/package.json +// ../node_modules/abc/123/index.mjs +// ../node_modules/abc/123/index.js +// etc. +import 'abc/123'; +``` + #### Removal of non-local dependencies All of the following will not be supported by the `import` statement: From 4bec00cf4de6176cb4eec7665b2fd49e0b826259 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Wed, 4 May 2016 19:05:13 -0500 Subject: [PATCH 2/2] include note about `this` value in ES modules being different --- 002-es6-modules.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/002-es6-modules.md b/002-es6-modules.md index bfce974..47a2989 100644 --- a/002-es6-modules.md +++ b/002-es6-modules.md @@ -337,6 +337,12 @@ Since `main` in `package.json` is entirely optional even inside of npm packages, some people may prefer to exclude main entirely in the case of using `./index` as that is still in the node module search algorithm. +### `this` in ES modules + +Unlike CJS, ES modules will have a `this` value set to the global scope. This +is a breaking change, CJS modules have a this value set to their `module` +binding. + ### ES consuming CommonJS #### default imports