Skip to content
Merged
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ bar/
- The word "default" has a special, and similar meaning in ES6 modules.
- Despite "default" being a common English word, "default.js" is not widely used as a file name.

In a random sampling of 25,000 NPM packages (10% of the total number of packages), "default.js" was only found one time in a package root. This particular "default.js" file was already an ES6 module. As a filename, "default.js" was found only 174 times. By contrast, "index.js" was found 22,607 times, and in the package root 10,282 times.
In a [search of all the filenames in the @latest NPM packages as of 2016-01-28](https://gist.github.com/bmeck/9b234011938cd9c1f552d41db97ad005), "default.js" was only found 23 times in a package root. This particular "default.js" file was already an ES6 module. As a filename, "default.js" was found 1968 times. By contrast, "index.js" was found 22,607 times, and in the package root 10,282 times.


## Running Modules from the Command Line

Expand All @@ -146,7 +147,11 @@ When a user executes
$ node my-module.js
```

from the command line, there is absolutely no way for Node to tell whether "my-module.js" is a legacy CJS module or an ES6 module. In the interest of backward compatibility, Node should probably attempt to load the file as a CJS module, and fallback to ES6 if there is a syntax error indicating the presence of `import` declarations. As people move away from CJS modules in general, future Node versions can assume that the file is an ES6 module.
from the command line, there is absolutely no way for Node to tell whether "my-module.js" is a legacy CJS module or an ES6 module. Due to the need of this knowledge for various interactive scenarios such as the entry file being provided over STDIN, node will support a `--module` flag.

```sh
$ node --module my-module.js
```

## Lookup Algorithm Psuedo-Code

Expand Down