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

Choosing a marker to customize default exports returned by require(esm) #1622

Merged
merged 20 commits into from
Oct 2, 2024

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Sep 20, 2024

When a user have an existing CommonJS package like this:

// foo package:
module.exports = function foo () { };

// ESM users get...
import foo from 'foo';
// CommmonJS users get..
const foo = require('foo');

Now that require(esm) is possible and they can ship ESM to their CommonJS users without breaking them, they would try something like this:

// foo package
export default function foo () { };

// ESM users get...
import foo from 'foo';
// CommmonJS users get..
const foo = require('foo').default;   // <--- This is now different!

As you can see, for CommonJS consumers this will not be exactly equivalent. Since in ESM the default exports is a property of the name space, they need to access .default from the result returned by
require(esm). So the idea is that Node.js can take a marker from package authors to directly customize what require(esm) returns in this case.
To keep const foo = require('foo') working, the two proposed markers are:

export default function foo () { };
export const __cjsUnwrapDefault = true;

or

export default function foo () { };
export { foo as "module.exports" };

Further to this vote, there is a follow-on proposal to reuse this marker on namespaces representing CJS modules imported into ESM, where attaching this marker would effectively define a scheme for converting CJS into ESM that would retain full transitive interop semantics allowing arbitrary CJS to be converted into ESM as a non-breaking change.

Under this follow-on marking, when importing some CJS module bar into ESM:

  module.exports = 'bar';

Users importing with console.log(await import('bar')) would obtain a namespace object either of the form ModuleNamespace { __cjsUnwrapDefault: true, default: 'bar' } or ModuleNamespace { default: 'bar', 'module.exports': 'bar' } depending on which option is chosen for this first PR.

The vote should stay open for 7 days, or until all TSC voting members have cast a ballot.

Vote instructions:

To close the vote, at least 3 secret holder(s)1 must run the following command: git node vote https://github.com/nodejs/TSC/pull/1622 --decrypt-key-part --post-comment

/cc @nodejs/tsc

Current estimated participation: 89.47%

Footnotes

  1. secret holders are folks who have access to the private key associated with a public key on hkps://keys.openpgp.org that references an email address listed on the TSC voting member list at the time of the opening of the vote.

@aduh95
Copy link
Contributor

aduh95 commented Sep 25, 2024

@nodejs/tsc Friendly ping, there's still half of us who haven't cast a ballot. The vote should close by EOW so there's enough time to implement the winning proposal before the v23.x cutoff.

@guybedford
Copy link

Can we conclude this vote?

@ShogunPanda
Copy link
Contributor

I will try to vote tomorrow. Sorry for the long wait.

@joyeecheung
Copy link
Member

@joyeecheung
Copy link
Member

(Although, apparently I didn't start it right, somehow. Maybe @aduh95 knows how to do it properly)

@aduh95
Copy link
Contributor

aduh95 commented Sep 28, 2024

(Although, apparently I didn't start it right, somehow. Maybe @aduh95 knows how to do it properly)

Looks like there's a typo in the workflow file: #1624

However, to close the vote, we still need (at least) 3 secret holders to reveal their key part as indicated in the PR description:

To close the vote, at least 3 secret holder(s) must run the following command: git node vote https://github.com/nodejs/TSC/pull/1622 --decrypt-key-part --post-comment.

Waiting for Paolo's vote SGTM (I'm also OK not waiting if the timing is too tight).

@aduh95
Copy link
Contributor

aduh95 commented Sep 29, 2024

I would like to close this vote, and for this effect, I'm revealing my key part:

-----BEGIN SHAMIR KEY PART-----
twU17ULeSU8PjrJHWFgItCugsSdRj74xMLpfKcuTHasB
-----END SHAMIR KEY PART-----

@richardlau
Copy link
Member

I would like to close this vote, and for this effect, I'm revealing my key part:

-----BEGIN SHAMIR KEY PART-----
EGv+9rNCzj0LVo0hj4ufrCcTnxOwKQKaO9GukpFejX8O
-----END SHAMIR KEY PART-----

@targos
Copy link
Member

targos commented Sep 30, 2024

I would like to close this vote, and for this effect, I'm revealing my key part:

-----BEGIN SHAMIR KEY PART-----
OuDKgiwvqy/K85yMTj0pCMQk2PmiWWENRa3BkPZpvmQS
-----END SHAMIR KEY PART-----

Copy link
Contributor Author

Election results

Subject: Choosing a marker to customize default exports returned by require(esm)
End date: 2024-09-30T12:19:45.128Z
Participation: 84.21%

Results

Winning candidate: export { foo as "module.exports" };

Table of results

Candidate Number of won duels
export { foo as "module.exports" }; 1
export const __cjsUnwrapDefault = true; 0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rJp6vVkh8vO5U
9H31Y5R3hr9NLrKaLUADbkqakJ89HWkvjXC0rHvn8wH2V8moIIzhBeYVpn0Rc9SP
BN5vswq7PQKBgAPr6DfRAoHBvgiYZ2D68YDCBdjAPQgkR44uC5cKWGWWqKLaAhDH
gsz0+4l/SATpQhDVOWoTw/WzJZTXT1Y5PkJamOhwsgwp/C/5u66nuhZzc3e6ru3w
bBpWBmdscZQx8+Air+FLQhJZIQ3lt5DTZ90jqCbxun25Ab35l7mnFARnAoGAJxZA
9gMJnIPq7kim9sxwUMupZXUNpMyWYbyZK1S1CjGWeFyHe+52SDoEkUFPGC/0P5X4
Xn3umBPbBya270hX46NtiCLpxRjWU3KCW/OdSFT9tV9igRRPCnd4u4VMrfp0IpFB
4pnL/DEOauD1BGe/y7Kwkz5FR0f7FNBFFMxR520CgYBABsTJpnoX6mocfDTiJ0gV
57Q1uXe4oMRxc5CahWOQO6KJzPobZZSkOhlKgKiPP9X/tQEZ4Z5yn2vC2i21t0IY
noEDUDrhxTvXeswR9lTZiQiemLFJEj2xQwNRgtdkJbq8ni7f8WIRA6TBkPe5LDK5
i09s1XopVbJdBq+qHOTq2w==
-----END PRIVATE KEY-----
Discarded commits

Some commits have not been taken into account when counting the ballots:

[
  {
    "commitInfo": {
      "sha": "f60348115185aaeeec8b14d30d82b8807ddee336",
      "signatureStatus": "E",
      "author": "James M Snell <jasnell@gmail.com>",
      "files": [
        "votes/76d8966e-bd27-4e30-a13d-48200a34004a/jasnell"
      ]
    },
    "reason": "A more recent vote commit from this author has already been counted."
  }
]

Footnotes

  1. Voted for export { foo as "module.exports" };.

  2. Abstained.

  3. Voted for export { foo as "module.exports" };.

  4. Voted for export { foo as "module.exports" };.

  5. Voted for export const __cjsUnwrapDefault = true;.

  6. Voted for export { foo as "module.exports" };.

  7. Voted for export { foo as "module.exports" };.

  8. Voted for export { foo as "module.exports" };.

  9. Voted for export { foo as "module.exports" };.

  10. Voted for export const __cjsUnwrapDefault = true;.

  11. Voted for export { foo as "module.exports" };.

  12. Voted for export { foo as "module.exports" };.

  13. Voted for export const __cjsUnwrapDefault = true;.

  14. Voted for export { foo as "module.exports" };.

  15. Voted for export { foo as "module.exports" };.

  16. Voted for export const __cjsUnwrapDefault = true;.

@joyeecheung
Copy link
Member

Should it be merged by pushing the merge button or is there a workflow for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.