Skip to content

Commit

Permalink
--type=auto simpler algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Mar 6, 2019
1 parent 21aa2bb commit 497ab46
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 61 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,10 @@ node --type=commonjs --eval 'const { sep } = require("path"); console.log(sep)'

### `--type=auto` flag

The command line flags `--type=auto` and `-a` tell Node to detect the module format for potentially ambiguous entry points (`.js` and extensionless files, string input via `--eval` or `STDIN`). The algorithm for this in broad terms is as follows:
The command line flags `--type=auto` and `-a` tell Node to detect the module format for potentially ambiguous entry points (`.js` and extensionless files, string input via `--eval` or `STDIN`). The algorithm for this is as follows:

1. Parse the source code of the initial entry point.

2. If the source code is unambiguously ESM (has `import` or `export` statements, etc.) evaluate as ESM. *Else:*

3. If the source code is unambiguously CommonJS (references global `require`, `module`, `exports`, `__filename`, or `__dirname`, etc.) evaluate as CommonJS. *Else:*

4. Throw an error that the initial entry point is ambiguous and the type cannot be automatically detected.

The detailed algorithm for this is [here](./type-auto-algorithm.md).
3. Evaluate as CommonJS.
55 changes: 0 additions & 55 deletions type-auto-algorithm.md

This file was deleted.

0 comments on commit 497ab46

Please sign in to comment.