Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--type=auto #55

Open
wants to merge 47 commits into
base: modules-lkgr
from

Conversation

Projects
None yet
6 participants
@GeoffreyBooth
Copy link
Contributor

GeoffreyBooth commented Mar 9, 2019

This implements --type=auto per the entry points proposal.

For potentially ambiguous initial entry points (.js or extensionless files in a package scope with no "type" field, string input via --eval or --print or STDIN), --type=auto tells Node to tokenize the source code to look for import or export statements. If any are found, the initial entry point is treated as if the user had specified --type=module; otherwise like --type=commonjs.

I’m using the Acorn tokenizer because its full parser lacks support for import() expressions. The tokenizer is also faster, and can exit early as soon as the first import or export statement is found. Acorn is already a part of the Node codebase, and I’m not loading it unless --type=auto is specified.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

guybedford and others added some commits Aug 28, 2018

esm: remove .json support
Refs: nodejs/modules#180

PR-URL: #6
Reviewed-By: Myles Borins <MylesBorins@google.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
esm: remove .node support
Refs: nodejs/modules#180

PR-URL: #6
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
esm: remove .js support
Refs: nodejs/modules#180

PR-URL: #6
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
esm: remove node specifier resolution algorithm
Refs: nodejs/modules#180

PR-URL: #6
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
doc: document minimal kernel
PR-URL: #6
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
esm: Remove --loader.
PR-URL: #6
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Myles Borins <mylesborins@google.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>

@GeoffreyBooth GeoffreyBooth force-pushed the type-auto branch from 1125984 to 9f42d1b Mar 9, 2019

@GeoffreyBooth

This comment has been minimized.

Copy link
Contributor Author

GeoffreyBooth commented Mar 9, 2019

@ljharb and @devsnek I think I’ve addressed all your notes, aside from -a. Is there anything else?

I can split off -a into a separate PR. That way, this can land without it and then -a can be debated separately. Would that be acceptable?

@MylesBorins MylesBorins force-pushed the modules-lkgr branch from bec588f to ea59221 Mar 11, 2019

@nodejs-ci nodejs-ci force-pushed the modules-lkgr branch 3 times, most recently from 9301a06 to e721cd2 Mar 12, 2019

@MylesBorins MylesBorins force-pushed the modules-lkgr branch 2 times, most recently from 484d1fb to 7efc53d Mar 18, 2019

@nodejs-ci nodejs-ci force-pushed the modules-lkgr branch 3 times, most recently from c7fa700 to d69f765 Mar 19, 2019

@MylesBorins MylesBorins force-pushed the modules-lkgr branch 5 times, most recently from 335d584 to 9a343ce Mar 21, 2019

@nodejs-ci nodejs-ci force-pushed the modules-lkgr branch 2 times, most recently from 871b78b to 3a00b51 Mar 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.