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

module: package exports dot main support #29494

Closed
wants to merge 4 commits into from

Conversation

@guybedford
Copy link
Contributor

commented Sep 8, 2019

This reintroduces the dot main in exports as discussed in the previous Node.js modules meeting.

The implementation includes both CommonJS and ES module resolution with the associated documentation and resolver specification changes.

In addition to the dot main, "exports" as a string or direct fallback array is supported as well.

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

This comment has been minimized.

Copy link
Contributor Author

commented Sep 8, 2019

@guybedford guybedford requested a review from jkrems Sep 8, 2019

@ljharb
ljharb approved these changes Sep 8, 2019
doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
@GeoffreyBooth GeoffreyBooth referenced this pull request Sep 8, 2019
2 of 2 tasks complete
guybedford and others added 3 commits Sep 8, 2019
Update doc/api/esm.md
Co-Authored-By: Geoffrey Booth <GeoffreyBooth@users.noreply.github.com>
Update doc/api/esm.md
Co-Authored-By: Geoffrey Booth <GeoffreyBooth@users.noreply.github.com>
@benjamingr

This comment has been minimized.

Copy link
Member

commented Sep 8, 2019

Random governance question - who is supposed to approve these changes? Modules team members or core collaborators?

Has the TSC chartered the module team to make changes to this area of the code on its own or something similar?

(I am asking because I see two approvals by non-collaborator members and I am a bit confused if those LGTMs are "I agree with this change and it can land" "I agree with this change" or "This is what the team said" and if regular collaborators are expected to review those or not)

@devsnek

This comment has been minimized.

Copy link
Member

commented Sep 8, 2019

@guybedford

This comment has been minimized.

Copy link
Contributor Author

commented Sep 8, 2019

@benjamingr the standard Node.js core approval process applies since the modules group is not chartered. We typically seek consensus from the modules group before landing non-patch changes to the module system though.

@benjamingr

This comment has been minimized.

Copy link
Member

commented Sep 9, 2019

Thanks for explaining @guybedford!

src/module_wrap.cc Show resolved Hide resolved
@jkrems
jkrems approved these changes Sep 9, 2019
Copy link
Contributor

left a comment

LGTM in general but I'd prefer if we can remove the duplication between the code for . and other exports keys.

target =
exports_obj->Get(env->context(), dot_string).ToLocalChecked();
}
if (target->IsString()) {

This comment has been minimized.

Copy link
@jkrems

jkrems Sep 9, 2019

Contributor

Is there a way to reuse the existing logic for string/array in PackageExportsResolve?

This comment has been minimized.

Copy link
@guybedford

guybedford Sep 9, 2019

Author Contributor

That would be better, it's just a refactoring I haven't had the time for. Would you be ok with moving that to a follow-up?

This comment has been minimized.

Copy link
@jkrems

jkrems Sep 9, 2019

Contributor

Works for me.

@guybedford

This comment has been minimized.

Copy link
Contributor Author

commented Sep 10, 2019

It's worth noting here, that:

{
  "exports": "./esm-main.js"
}

is supported by this PR, but:

{
  "exports": "esm-main.js"
}

would not be supported and would throw an error that exports must start with ./.

This is based on various long-standing discussions, but still worth noting in how it deviates from "main".

@MylesBorins
Copy link
Member

left a comment

LGTM

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@jkrems

This comment has been minimized.

Copy link
Contributor

commented Sep 16, 2019

🍏

@Trott Trott force-pushed the nodejs:master branch from 1ecc406 to 49cf67e Sep 17, 2019

@Trott

This comment has been minimized.

Copy link
Member

commented Sep 18, 2019

Landed in 3f3ad38

@Trott Trott closed this Sep 18, 2019

Trott added a commit that referenced this pull request Sep 18, 2019
module: reintroduce package exports dot main
This reintroduces the dot main in exports as discussed in the previous
Node.js modules meeting.

The implementation includes both CommonJS and ES module resolution with
the associated documentation and resolver specification changes.

In addition to the dot main, "exports" as a string or direct fallback
array is supported as well.

Co-Authored-By: Geoffrey Booth <GeoffreyBooth@users.noreply.github.com>
PR-URL: #29494
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.