Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions 002-es6-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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';
Expand All @@ -224,24 +230,46 @@ import './foo';
// does not search:
// /bar.js
// /bar/index.js
// /bar/index.mjs
// /bar/package.json
// etc.
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:
Expand Down Expand Up @@ -309,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
Expand Down